changeset 84:e0f1ec7fe73a

Merge plus a few tweaks.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sun, 31 Aug 2008 15:59:17 +0100
parents ac1e3fd07275 (current diff) 2813ac68576f (diff)
children 56c0ddd90193
files codeDoc/jobs.txt codeDoc/staticCtors.txt mde/font/font.d mde/gui/WidgetManager.d mde/input/Config.d mde/lookup/Options.d mde/mde.d mde/setup/init2.d
diffstat 9 files changed, 109 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/codeDoc/jobs.txt	Sat Aug 30 09:37:35 2008 +0100
+++ b/codeDoc/jobs.txt	Sun Aug 31 15:59:17 2008 +0100
@@ -18,6 +18,7 @@
 3   Scheduler for drawing only windows which need redrawing.
 3   Update scheduler as outlined in FIXME.
 3   Windows building/compatibility (currently partial) - tango/sys/win32/SpecialPath.d
+2   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.
 2   Remove ability to scan, then load, mergetag sections. Not so necessary with section creator callback and allows "sliding window" type partial buffering.
 2   Options need a "level": simple options, for advanced users, for debugging only, etc.
 2   Command-line options for paths to by-pass normal path finding functionality.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeDoc/staticCtors.txt	Sun Aug 31 15:59:17 2008 +0100
@@ -0,0 +1,60 @@
+Map of what happens in static CTORs (excluding creating loggers):
+
+mde
+->  imde
+    ->  input.Input
+        ->  input.Config
+            
+
+* means shouldn't affect anything else done by static ctors
+
+imde {
+    input = new Input();
+    mainSchedule = new Scheduler;*
+}
+
+font.FontTexture.OptionsFont {*
+    fontOpts = new OptionsFont;
+    Options.addOptionsClass (fontOpts, "font");
+}
+
+gui.WidgetManager {*
+    gui = new WidgetManager ("gui");
+}
+
+input.Config.Config {*
+    loadedFiles = new TreeBag!(char[]);
+}
+
+input.Input.Input {*
+    es_b_fcts = [ ES_B.OUT : &es_b_out ];
+    es_a_fcts = [ ES_A.OUT : &es_a_out, ES_A.REVERSE : &es_a_reverse ];
+    es_m_fcts = [ ES_M.OUT : &es_m_out ];
+}
+
+lookup.Options.OptionsMisc {*
+    miscOpts = new OptionsMisc;
+    Options.addOptionsClass (miscOpts, "misc");
+}
+
+setup.Init {?
+    Logger root = Log.root;
+    debug root.level(Logger.Trace);
+    else  root.level(Logger.Info);
+    root.add(new AppendConsole);
+}
+
+setup.init2 {*
+    init.addFunc (&initInput, "initInput");
+    init.addFunc (&guiLoad, "guiLoad");
+}
+
+setup.sdl {*
+    init.addFunc (&initSdlAndGl, "initSdlAndGl");
+}
+
+setup.sdl.OptionsVideo {*
+    vidOpts = new OptionsVideo;
+    Options.addOptionsClass (vidOpts, "video");
+}
+
--- a/mde/font/FontTexture.d	Sat Aug 30 09:37:35 2008 +0100
+++ b/mde/font/FontTexture.d	Sun Aug 31 15:59:17 2008 +0100
@@ -301,7 +301,7 @@
             
             format = (fontOpts.renderMode & RENDER_LCD_BGR) ? GL_BGR : GL_RGB;
         } else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) {
-            // NOTE: Notes above apply. Only in this case converting the buffers seems essential.
+            // NOTE: Notes above apply. But in this case converting the buffers seems essential.
             buffer = new ubyte[b.width*b.rows];
             for (uint i = 0; i < b.rows; ++i)
                 for (uint j = 0; j < b.width; ++j)
@@ -456,12 +456,15 @@
 enum { RENDER_LCD_BGR = 1 << 30 }
 OptionsFont fontOpts;
 class OptionsFont : Options {
-    /* renderMode should be FT_LOAD_TARGET_NORMAL, FT_LOAD_TARGET_LIGHT, FT_LOAD_TARGET_LCD or
-     * FT_LOAD_TARGET_LCD_V, possibly with bit 31 set (see RENDER_LCD_BGR).
-     * FT_LOAD_TARGET_MONO is unsupported.
+    /* renderMode have one of the following values, possibly with bit 31 set (see RENDER_LCD_BGR):
+     * FT_LOAD_TARGET_NORMAL    (0x00000)
+     * FT_LOAD_TARGET_LIGHT     (0x10000)
+     * FT_LOAD_TARGET_LCD       (0x30000)
+     * FT_LOAD_TARGET_LCD_V     (0x40000)
+     * The mode FT_LOAD_TARGET_MONO (0x20000) is unsupported.
      *
      * lcdFilter should come from enum FT_LcdFilter:
-     * FT_LCD_FILTER_NONE = 0, FT_LCD_FILTER_DEFAULT = 1, FT_LCD_FILTER_LIGHT = 2 */
+     * FT_LCD_FILTER_NONE (0), FT_LCD_FILTER_DEFAULT (1), FT_LCD_FILTER_LIGHT (2) */
     mixin (impl!("int renderMode, lcdFilter;"));
     
     static this() {
--- a/mde/font/font.d	Sat Aug 30 09:37:35 2008 +0100
+++ b/mde/font/font.d	Sun Aug 31 15:59:17 2008 +0100
@@ -64,8 +64,10 @@
             // Check version
             FT_Int maj, min, patch;
             FT_Library_Version (library, &maj, &min, &patch);
-            if (maj != 2 || min != 3)
+            if (maj != 2 || min != 3) {
                 logger.warn ("Using an untested FreeType version: {}.{}.{}", maj, min, patch);
+                logger.info ("The only tested version of freetype is 2.3.5");
+            }
             
             // Set LCD filtering method if LCD rendering is enabled.
             const RMF = FT_LOAD_TARGET_LCD | FT_LOAD_TARGET_LCD_V;
--- a/mde/gui/WidgetManager.d	Sat Aug 30 09:37:35 2008 +0100
+++ b/mde/gui/WidgetManager.d	Sun Aug 31 15:59:17 2008 +0100
@@ -62,7 +62,11 @@
      */
     this (char[] file) {
         super(file);
-        
+    }
+    
+    // NOTE - temporarily here to allow CTOR to run safely during static this
+    // called during init
+    void init () {
         // Events we want to know about:
         imde.input.addMouseClickCallback(&clickEvent);
         imde.input.addMouseMotionCallback(&motionEvent);
--- a/mde/input/Config.d	Sat Aug 30 09:37:35 2008 +0100
+++ b/mde/input/Config.d	Sun Aug 31 15:59:17 2008 +0100
@@ -116,14 +116,11 @@
     
     static Config[char[]] configs;	/// All configs loaded by load().
     private static TreeBag!(char[]) loadedFiles;	// all filenames load tried to read
-    
     private static Logger logger;
-    static this() {
-        logger = Log.getLogger ("mde.input.Config");
-    }
     
 //BEGIN File loading/saving code
     static this () {
+        logger = Log.getLogger ("mde.input.Config");
         loadedFiles = new TreeBag!(char[]);
     }
     
--- a/mde/lookup/Options.d	Sat Aug 30 09:37:35 2008 +0100
+++ b/mde/lookup/Options.d	Sun Aug 31 15:59:17 2008 +0100
@@ -14,11 +14,17 @@
 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 /** This module handles stored options, currently all except input maps.
-*
-* The purpose of having all options centrally controlled is to allow generic handling by the GUI
-* and ease saving and loading of values. The Options class is only really designed around handling
-* small numbers of variables for now.
-*/
+ *
+ * The purpose of having all options centrally controlled is to allow generic handling by the GUI
+ * and ease saving and loading of values. The Options class is only really designed around handling
+ * small numbers of variables for now.
+ *
+ * Note: This module uses some non-spec functionality, which "works for me", but may need to be
+ * changed if it throws up problems. Specifically: templated virtual functions (Options.set, get
+ * and list), and accessing private templates from an unrelated class (Options.TName, TYPES).
+ * OptionChanges used to have a templated set member function (used by Options.set), which caused
+ * linker problems when the module wasn't compiled from scratch.
+ */
 module mde.lookup.Options;
 
 import mde.setup.paths;
@@ -50,8 +56,18 @@
 * Further to this, a generic class is used to store all options which have been changed, and if any
 * have been changed, is merged with options from the user conf dir and saved on exit.
 */
+/* An idea for potentially extending Options, but which doesn't seem necessary now:
+Move static code from Options to an OptionSet class, which may be sub-classed. These sub-classes
+may be hooked in to the master OptionSet class to shadow all Options classes and be notified of
+changes, and may or may not have values loaded from files during init. Change-sets could be
+rewritten to use this.
+However, only the changesets should need to be notified of each change (gui interfaces could simply
+be notified that a change occured and redraw everything; users of options can just re-take their
+values every time they use them). */
 class Options : IDataSection
 {
+    protected this() {}   /// Do not instantiate directly.
+    
     // All supported types, for generic handling via templates. It should be possible to change
     // the supported types simply by changing this list now (untested).
     template store(A...) { alias A store; }
--- a/mde/mde.d	Sat Aug 30 09:37:35 2008 +0100
+++ b/mde/mde.d	Sun Aug 31 15:59:17 2008 +0100
@@ -15,22 +15,17 @@
 
 /** Modular D Engine
  *
- * This module contains main(), which calls Init and runs the main loop.
+ * This module contains a minimal main() function. Practically, it is useful for running unittests
+ * and some other testing. It also serves as a basic example program.
  */
 module mde.mde;
 
-// Comment to show use, where only used minimally:
-
 import mde.imde;                        // this module's interface for external modules
-import mde.events;                      // pollEvents
+import mde.events;      // pollEvents() // NOTE: Must be imported before Init, otherwise fonts don't display properly (why??)
+import mde.setup.Init;                  // initialization
 import mde.lookup.Options;              // pollInterval option
-
+import mde.scheduler.Scheduler;         // mainSchedule
 import gl = mde.gl.draw;                // gl.draw()
-import mde.input.Input;                 // new Input()
-
-import mde.setup.Init;
-import mde.scheduler.Scheduler;         // Scheduler.run()
-import mde.setup.exception;             // InitException
 
 import tango.core.Thread : Thread;	// Thread.sleep()
 import tango.time.Clock;                // Clock.now()
@@ -42,24 +37,18 @@
 
 int main(char[][] args)
 {
-    //BEGIN Initialisation
-    Logger logger = Log.getLogger ("mde.mde");
+    // If compiled with unittests, notify that they completed and exit:
     debug (mdeUnitTest) {
+        Logger logger = Log.getLogger ("mde.mde");
         logger.info ("Compiled unittests have completed; terminating.");
         return 0;
     }
     
-    scope Init init;
-    try {
-        init = new Init(args);	// initialisation
-    } catch (InitException e) {
-        logger.fatal ("Initialisation failed: " ~ e.msg);
-        return 1;
-    }
+    scope Init init = new Init(args);	// initialize mde
     
+    // Make sure pollInterval has a sane value. FIXME: get Options class to enforce range
     if (miscOpts.pollInterval !<= 1.0 || miscOpts.pollInterval !>= 0.0)
         miscOpts.set!(double) ("pollInterval", 0.01);
-    //END Initialisation
     
     //BEGIN Main loop setup
     /* Note: the main loop is currently controlled by the scheduler. This is not really ideal,
--- a/mde/setup/init2.d	Sat Aug 30 09:37:35 2008 +0100
+++ b/mde/setup/init2.d	Sun Aug 31 15:59:17 2008 +0100
@@ -52,6 +52,7 @@
 void guiLoad () {   // init func
     try {
         font.FontStyle.initialize;
+        gui.init;
         gui.loadDesign();
         cleanup.addFunc (&guiSave, "guiSave");
     } catch (Exception e) {