Changeset 84:e0f1ec7fe73a

Show
Ignore:
Timestamp:
08/31/08 10:59:17 (4 months ago)
Author:
Diggory Hardy <diggory.hardy@gmail.com>
Parents:

82:ac1e3fd07275 83:2813ac68576f

branch:
default
Message:

Merge plus a few tweaks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • codeDoc/jobs.txt

    r80 r84  
    19193   Update scheduler as outlined in FIXME. 
    20203   Windows building/compatibility (currently partial) - tango/sys/win32/SpecialPath.d 
     212   Why does mde.events need to be imported before mde.setup.Init to make fonts display properly? Analysis of static CTORs doesn't seem to have helped. 
    21222   Remove ability to scan, then load, mergetag sections. Not so necessary with section creator callback and allows "sliding window" type partial buffering. 
    22232   Options need a "level": simple options, for advanced users, for debugging only, etc. 
  • codeDoc/jobs.txt

    r80 r84  
    19193   Update scheduler as outlined in FIXME. 
    20203   Windows building/compatibility (currently partial) - tango/sys/win32/SpecialPath.d 
     212   Why does mde.events need to be imported before mde.setup.Init to make fonts display properly? Analysis of static CTORs doesn't seem to have helped. 
    21222   Remove ability to scan, then load, mergetag sections. Not so necessary with section creator callback and allows "sliding window" type partial buffering. 
    22232   Options need a "level": simple options, for advanced users, for debugging only, etc. 
  • mde/font/font.d

    r81 r84  
    6565            FT_Int maj, min, patch; 
    6666            FT_Library_Version (library, &maj, &min, &patch); 
    67             if (maj != 2 || min != 3) 
     67            if (maj != 2 || min != 3) { 
    6868                logger.warn ("Using an untested FreeType version: {}.{}.{}", maj, min, patch); 
     69                logger.info ("The only tested version of freetype is 2.3.5"); 
     70            } 
    6971             
    7072            // Set LCD filtering method if LCD rendering is enabled. 
  • mde/font/font.d

    r83 r84  
    2222import mde.font.exception; 
    2323 
    24 import mde.mergetag.Reader; 
    25 import mde.mergetag.DataSet; 
    26 import mde.mergetag.exception; 
     24import mde.file.mergetag.Reader; 
     25import mde.file.mergetag.DataSet; 
    2726import mde.setup.paths; 
    2827 
     
    3029import derelict.opengl.gl; 
    3130 
    32 import mde.mergetag.deserialize; 
     31import mde.file.deserialize; 
    3332import tango.stdc.stringz; 
    3433import Util = tango.text.Util; 
     
    6059        private const fileName = "fonts"; 
    6160        void initialize () { 
    62             if (!confDir.exists (fileName)) 
    63                 throw new fontException ("No font settings file (fonts.[mtt|mtb])"); 
    64              
    6561            if (FT_Init_FreeType (&library)) 
    6662                throw new fontException ("error initialising the FreeType library"); 
     
    113109                    throw new fontException ("No fallback font style specified"); 
    114110                fallbackName = *p; 
    115             } 
    116             catch (MTException e) { 
    117                 throw new fontException ("Mergetag exception: "~e.msg); 
     111            } catch (NoFileException) { 
     112                throw new fontException ("No font settings file (fonts.[mtt|mtb])"); 
     113            } catch (Exception e) { 
     114                throw new fontException ("Reading font settings failed: "~e.msg); 
    118115            } 
    119116             
  • mde/gui/WidgetManager.d

    r81 r84  
    6363    this (char[] file) { 
    6464        super(file); 
    65          
     65    } 
     66     
     67    // NOTE - temporarily here to allow CTOR to run safely during static this 
     68    // called during init 
     69    void init () { 
    6670        // Events we want to know about: 
    6771        imde.input.addMouseClickCallback(&clickEvent); 
  • mde/gui/WidgetManager.d

    r80 r84  
    6363    this (char[] file) { 
    6464        super(file); 
    65          
     65    } 
     66     
     67    // NOTE - temporarily here to allow CTOR to run safely during static this 
     68    // called during init 
     69    void init () { 
    6670        // Events we want to know about: 
    6771        imde.input.addMouseClickCallback(&clickEvent); 
     
    188192import mde.gui.widget.createWidget; 
    189193 
    190 import mde.mergetag.Reader; 
    191 import mde.mergetag.Writer; 
     194import mde.file.mergetag.Reader; 
     195import mde.file.mergetag.Writer; 
    192196import mde.setup.paths; 
    193197 
     
    221225        if (allLoaded || (defaultDesign !is null && allDesigns == false)) 
    222226            return; // test if already loaded 
    223              
    224             if (!confDir.exists (fileName)) { 
    225                 logger.error ("Unable to load GUI: no config file!"); 
    226                 return; // not a fatal error (so long as the game can run without a GUI!) 
    227             } 
    228227             
    229228            // Set up a reader 
     
    267266            } else 
    268267                reader.read([defaultDesign]); 
     268        } catch (NoFileException) { 
     269            logger.error ("Unable to load GUI: no config file!"); 
     270            // just return: not a fatal error (so long as the game can run without a GUI!) 
    269271        } catch (Exception e) { 
    270272            logger.error ("Unable to load GUI: errors parsing config file ("~confDir.getFileName(fileName,PRIORITY.HIGH_LOW)~"):"); 
  • mde/input/Config.d

    r82 r84  
    117117    static Config[char[]] configs;  /// All configs loaded by load(). 
    118118    private static TreeBag!(char[]) loadedFiles;    // all filenames load tried to read 
    119      
    120119    private static Logger logger; 
    121     static this() { 
    122         logger = Log.getLogger ("mde.input.Config"); 
    123     } 
    124120     
    125121//BEGIN File loading/saving code 
    126122    static this () { 
     123        logger = Log.getLogger ("mde.input.Config"); 
    127124        loadedFiles = new TreeBag!(char[]); 
    128125    } 
  • mde/input/Config.d

    r79 r84  
    1919import mde.input.exception; 
    2020 
    21 import MT = mde.mergetag.Reader; 
     21import MT = mde.file.mergetag.Reader; 
    2222import mde.setup.paths; 
    23 import mde.mergetag.deserialize; 
    24 debug import mde.mergetag.serialize; 
     23import mde.file.deserialize; 
     24debug import mde.file.serialize; 
    2525 
    2626import tango.util.log.Log : Log, Logger; 
     
    117117    static Config[char[]] configs;  /// All configs loaded by load(). 
    118118    private static TreeBag!(char[]) loadedFiles;    // all filenames load tried to read 
    119      
    120119    private static Logger logger; 
    121     static this() { 
    122         logger = Log.getLogger ("mde.input.config.Config"); 
    123     } 
    124120     
    125121//BEGIN File loading/saving code 
    126122    static this () { 
     123        logger = Log.getLogger ("mde.input.Config"); 
    127124        loadedFiles = new TreeBag!(char[]); 
    128125    } 
  • mde/lookup/Options.d

    r82 r84  
    1515 
    1616/** This module handles stored options, currently all except input maps. 
    17 
    18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI 
    19 * and ease saving and loading of values. The Options class is only really designed around handling 
    20 * small numbers of variables for now. 
    21 */ 
     17 * 
     18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI 
     19 * and ease saving and loading of values. The Options class is only really designed around handling 
     20 * small numbers of variables for now. 
     21 * 
     22 * Note: This module uses some non-spec functionality, which "works for me", but may need to be 
     23 * changed if it throws up problems. Specifically: templated virtual functions (Options.set, get 
     24 * and list), and accessing private templates from an unrelated class (Options.TName, TYPES). 
     25 * OptionChanges used to have a templated set member function (used by Options.set), which caused 
     26 * linker problems when the module wasn't compiled from scratch. 
     27 */ 
    2228module mde.lookup.Options; 
    2329 
     
    5157* have been changed, is merged with options from the user conf dir and saved on exit. 
    5258*/ 
     59/* An idea for potentially extending Options, but which doesn't seem necessary now: 
     60Move static code from Options to an OptionSet class, which may be sub-classed. These sub-classes 
     61may be hooked in to the master OptionSet class to shadow all Options classes and be notified of 
     62changes, and may or may not have values loaded from files during init. Change-sets could be 
     63rewritten to use this. 
     64However, only the changesets should need to be notified of each change (gui interfaces could simply 
     65be notified that a change occured and redraw everything; users of options can just re-take their 
     66values every time they use them). */ 
    5367class Options : IDataSection 
    5468{ 
     69    protected this() {}   /// Do not instantiate directly. 
     70     
    5571    // All supported types, for generic handling via templates. It should be possible to change 
    5672    // the supported types simply by changing this list now (untested). 
  • mde/lookup/Options.d

    r80 r84  
    1515 
    1616/** This module handles stored options, currently all except input maps. 
    17 
    18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI 
    19 * and ease saving and loading of values. The Options class is only really designed around handling 
    20 * small numbers of variables for now. 
    21 */ 
     17 * 
     18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI 
     19 * and ease saving and loading of values. The Options class is only really designed around handling 
     20 * small numbers of variables for now. 
     21 * 
     22 * Note: This module uses some non-spec functionality, which "works for me", but may need to be 
     23 * changed if it throws up problems. Specifically: templated virtual functions (Options.set, get 
     24 * and list), and accessing private templates from an unrelated class (Options.TName, TYPES). 
     25 * OptionChanges used to have a templated set member function (used by Options.set), which caused 
     26 * linker problems when the module wasn't compiled from scratch. 
     27 */ 
    2228module mde.lookup.Options; 
    2329 
     
    2531import mde.exception; 
    2632 
    27 import mde.mergetag.Reader; 
    28 import mde.mergetag.Writer; 
    29 import mde.mergetag.DataSet; 
    30 import mde.mergetag.exception; 
    31 import mde.mergetag.serialize; 
     33import mde.file.mergetag.Reader; 
     34import mde.file.mergetag.Writer; 
     35import mde.file.mergetag.DataSet; 
     36import mde.file.serialize; 
    3237 
    3338import tango.core.Exception : ArrayBoundsException; 
     
    5257* have been changed, is merged with options from the user conf dir and saved on exit. 
    5358*/ 
     59/* An idea for potentially extending Options, but which doesn't seem necessary now: 
     60Move static code from Options to an OptionSet class, which may be sub-classed. These sub-classes 
     61may be hooked in to the master OptionSet class to shadow all Options classes and be notified of 
     62changes, and may or may not have values loaded from files during init. Change-sets could be 
     63rewritten to use this. 
     64However, only the changesets should need to be notified of each change (gui interfaces could simply 
     65be notified that a change occured and redraw everything; users of options can just re-take their 
     66values every time they use them). */ 
    5467class Options : IDataSection 
    5568{ 
     69    protected this() {}   /// Do not instantiate directly. 
     70     
    5671    // All supported types, for generic handling via templates. It should be possible to change 
    5772    // the supported types simply by changing this list now (untested). 
     
    135150        private const fileName = "options"; 
    136151        void load () { 
    137         // Check it exists (if not it should still be created on exit). 
    138         // Don't bother checking it's not a folder, because it could still be a block or something. 
    139             if (!confDir.exists (fileName)) return; 
    140          
    141152            try { 
    142153                IReader reader; 
     
    149160                }; 
    150161                reader.read; 
    151             } catch (MTException e) { 
    152                 logger.fatal ("Loading options aborted:"); 
    153                 logger.fatal (e.msg); 
    154                 throw new optionsLoadException ("Mergetag exception (see above message)"); 
     162            } catch (NoFileException e) { 
     163                // Just return. Options file will be created on exit. 
     164            } catch (Exception e) { 
     165                logger.warn ("Loading options failed: "~e.msg); 
     166                logger.warn ("If warning persists, delete the offending file.");        // FIXME - delete the bad file somehow 
    155167            } 
    156168        } 
     
    171183            } catch (NoFileException) { 
    172184                // No user file exists; not an error. 
    173             } catch (MTException e) { 
     185            } catch (Exception e) { 
    174186                // Log a message and continue, overwriting the file: 
    175                 logger.error ("Loading options aborted:"); 
    176                 logger.error (e.msg); 
     187                logger.error ("Loading options aborted: " ~ e.msg); 
    177188            } 
    178189         
     
    181192                writer = confDir.makeMTWriter (fileName, ds); 
    182193                writer.write(); 
    183             } catch (MTException e) { 
    184                 logger.error ("Saving options aborted! Reason:"); 
    185                 logger.error (e.msg); 
     194            } catch (Exception e) { 
     195                logger.error ("Saving options aborted: "~e.msg); 
    186196            } 
    187197        } 
     
    189199        private Logger logger; 
    190200        static this() { 
    191             logger = Log.getLogger ("mde.options"); 
     201            logger = Log.getLogger ("mde.lookup.Options"); 
    192202        } 
    193203    } 
     
    196206     
    197207    //BEGIN Non-static 
     208    /+ NOTE: according to spec: "Templates cannot be used to add non-static members or virtual 
     209    functions to classes." However, this appears to work (but linking problems did occur). 
     210    Alternative: use mixins. From OptionsChanges: 
     211        // setT (used to be a template, but: 
     212        // Templates cannot be used to add non-static members or virtual functions to classes. ) 
     213        template setMixin(A...) { 
     214            static if (A.length) { 
     215                const char[] setMixin = `void set`~TName!(A[0])~` (ID id, `~A[0].stringof~` x) { 
     216                    `~TName!(T)~`s[id] = x; 
     217                } 
     218                ` ~ setMixin!(A[1..$]); 
     219            } else 
     220                const char[] setMixin = ``; 
     221        }+/ 
    198222    /** Set option symbol of an Options sub-class to val. 
    199223     * 
     
    204228        static assert (TIsIn!(T,TYPES), "Options does not support type "~T.stringof); 
    205229         
    206         mixin (`alias opts`~TName!(T)~` optsVars;`); 
    207          
    208230        changed = true;     // something got set (don't bother checking this isn't what it already was) 
    209231         
    210232        try { 
    211             *(optsVars[cast(ID) symbol]) = val
    212             optionChanges.set!(T) (cast(ID) symbol, val); 
     233            mixin (`*(opts`~TName!(T)~`[cast(ID) symbol]) = val;`)
     234            mixin (`optionChanges.`~TName!(T)~`s[symbol] = val;`); 
    213235        } catch (ArrayBoundsException) { 
    214236            // log and ignore: 
     
    405427                const char[] writeAllMixin = ``; 
    406428        } 
    407          
    408429    } 
    409430    //END Templates 
     
    413434     
    414435    this () {} 
    415      
    416     void set(T) (ID id, T x) { 
    417         static assert (Options.TIsIn!(T,TYPES), "Options does not support type "~T.stringof); 
    418          
    419         mixin (`alias `~TName!(T)~`s vars;`); 
    420         vars[id] = x; 
    421     } 
    422436     
    423437    //BEGIN Mergetag loading/saving code 
  • mde/mde.d

    r82 r84  
    1616/** Modular D Engine 
    1717 * 
    18  * This module contains main(), which calls Init and runs the main loop. 
     18 * This module contains a minimal main() function. Practically, it is useful for running unittests 
     19 * and some other testing. It also serves as a basic example program. 
    1920 */ 
    2021module mde.mde; 
    2122 
    22 // Comment to show use, where only used minimally: 
    23  
    2423import mde.imde;                        // this module's interface for external modules 
    25 import mde.events;                      // pollEvents 
     24import mde.events;      // pollEvents() // NOTE: Must be imported before Init, otherwise fonts don't display properly (why??) 
     25import mde.setup.Init;                  // initialization 
    2626import mde.lookup.Options;              // pollInterval option 
    27  
     27import mde.scheduler.Scheduler;         // mainSchedule 
    2828import gl = mde.gl.draw;                // gl.draw() 
    29 import mde.input.Input;                 // new Input() 
    30  
    31 import mde.setup.Init; 
    32 import mde.scheduler.Scheduler;         // Scheduler.run() 
    33 import mde.setup.exception;             // InitException 
    3429 
    3530import tango.core.Thread : Thread;  // Thread.sleep() 
     
    4338int main(char[][] args) 
    4439{ 
    45     //BEGIN Initialisation 
    46     Logger logger = Log.getLogger ("mde.mde"); 
     40    // If compiled with unittests, notify that they completed and exit: 
    4741    debug (mdeUnitTest) { 
     42        Logger logger = Log.getLogger ("mde.mde"); 
    4843        logger.info ("Compiled unittests have completed; terminating."); 
    4944        return 0; 
    5045    } 
    5146     
    52     scope Init init; 
    53     try { 
    54         init = new Init(args);  // initialisation 
    55     } catch (InitException e) { 
    56         logger.fatal ("Initialisation failed: " ~ e.msg); 
    57         return 1; 
    58     } 
     47    scope Init init = new Init(args);   // initialize mde 
    5948     
     49    // Make sure pollInterval has a sane value. FIXME: get Options class to enforce range 
    6050    if (miscOpts.pollInterval !<= 1.0 || miscOpts.pollInterval !>= 0.0) 
    6151        miscOpts.set!(double) ("pollInterval", 0.01); 
    62     //END Initialisation 
    6352     
    6453    //BEGIN Main loop setup 
  • mde/mde.d

    r83 r84  
    2222 
    2323import mde.imde;                        // this module's interface for external modules 
     24import mde.events;      // pollEvents() // NOTE: Must be imported before Init, otherwise fonts don't display properly (why??) 
    2425import mde.setup.Init;                  // initialization 
    2526import mde.lookup.Options;              // pollInterval option 
    2627import mde.scheduler.Scheduler;         // mainSchedule 
    27 import mde.events;                      // pollEvents() 
    2828import gl = mde.gl.draw;                // gl.draw() 
    2929 
     
    3131import tango.time.Clock;                // Clock.now() 
    3232import tango.util.log.Log : Log, Logger; 
     33debug (mdeUnitTest) { 
     34    import mde.file.ssi; 
     35    import mde.file.mergetag.mdeUT; 
     36} 
    3337 
    3438int main(char[][] args) 
  • mde/setup/init2.d

    r75 r84  
    5353    try { 
    5454        font.FontStyle.initialize; 
     55        gui.init; 
    5556        gui.loadDesign(); 
    5657        cleanup.addFunc (&guiSave, "guiSave"); 
  • mde/setup/init2.d

    r75 r84  
    5353    try { 
    5454        font.FontStyle.initialize; 
     55        gui.init; 
    5556        gui.loadDesign(); 
    5657        cleanup.addFunc (&guiSave, "guiSave");