Changeset 86:79d816b3e2d2

Show
Ignore:
Timestamp:
09/12/08 12:36:14 (4 months ago)
Author:
Diggory Hardy <diggory.hardy@gmail.com>
branch:
default
Message:

New InitStage? system, Screen & Screen.Drawable, separate testing and guiDemo binaries.

This (and the previous) commit are the result of several quite significant changes to mde. All the unittests run, but it hasn't had a huge amount of testing so don't be surprised if bugs show up.

Files:

Legend:

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

    r85 r86  
    44 
    55In progress: 
    6 why is nothing drawn until a resize? seems to be working now (??) 
    7 why isn't font texture drawn in mde? 
    8 why does mde&guiDemo hang on exit, only if no resize occurred? 
    9 wierd things with options.mtt (font section getting output twice) 
     6Sometimes nothing is drawn until a resize, and fonts are blocks? External bug? 
    107CircularIterator 
    118unittest again! 
  • mde/file/deserialize.d

    r82 r86  
    526526        } catch (Exception e) { 
    527527            r = true; 
    528             logger.trace ("Exception caught: "~e.msg); 
    529528        } 
    530529        return r; 
  • mde/file/mergetag/Writer.d

    r85 r86  
    163163        _path = path; 
    164164        _dataset = ds; 
    165         foreach (i,s; _dataset.sec) 
    166             debug logger.trace ("sec ID length: {}", i.length); 
    167165    } 
    168166//END CTOR / DTOR 
     
    181179         
    182180        try { 
    183             debug logger.trace ("W.w: 1"); 
    184181            FileConduit conduit;    // actual conduit; don't use directly when there's content in the buffer 
    185182            IBuffer buffer;     // write strings directly to this (use opCall(void[]) ) 
    186183             
    187             debug logger.trace ("W.w: 2"); 
    188184            // Open a conduit on the file: 
    189185            conduit = new FileConduit (_path, FileConduit.WriteCreate); 
    190186            scope(exit) conduit.close(); 
    191187             
    192             debug logger.trace ("W.w: 3"); 
    193188            buffer = new Buffer(conduit);   // And a buffer 
    194189            scope(exit) buffer.flush(); 
    195190             
    196             debug logger.trace ("W.w: 4"); 
    197191            // Write the header: 
    198192            buffer ("{MT" ~ MTFormatVersion.CurrentString ~ "}" ~ Eol); 
    199             debug logger.trace ("W.w: 5"); 
    200193            if (_dataset.header !is null) writeSection (buffer, _dataset.header); 
    201194         
    202             debug logger.trace ("W.w: 6"); 
    203195            // Write the rest: 
    204196            foreach (ID id, IDataSection sec; _dataset.sec) { 
    205                 debug logger.trace ("W.w: 71"); 
    206197                writeSectionIdentifier (buffer, id); 
    207                 debug logger.trace ("W.w: 72"); 
    208198                writeSection (buffer, sec); 
    209199            } 
    210200             
    211             debug logger.trace ("W.w: 8"); 
    212201            buffer.flush(); 
    213202             
    214             debug logger.trace ("W.w: 9"); 
    215203        } 
    216204        catch (IOException e) { 
     
    223211         
    224212    private void writeSectionIdentifier (IBuffer buffer, ID id) { 
    225         debug logger.trace ("W.wSI: 0"); 
    226         debug logger.trace ("W.wSI: id ({})",id.length); 
    227         debug logger.trace ("W.wSI: Eol ({})",Eol.length); 
    228213        char[] tp = "{" ~ cast(char[])id ~ "}" ~ Eol; 
    229         debug logger.trace ("W.wSI: 0.1"); 
    230         debug logger.trace ("W.wSI: string ({}): {}",tp.length, tp); 
    231214        buffer (tp); 
    232         debug logger.trace ("W.wSI: 1"); 
    233215    } 
    234216     
  • mde/file/serialize.d

    r82 r86  
    312312        } catch (Exception e) { 
    313313            r = true; 
    314             logger.trace ("Exception caught: "~e.msg); 
    315314        } 
    316315        return r; 
  • mde/font/FontTexture.d

    r85 r86  
    330330        float[4] Cc = [ 1.0f, 1f, 1f, 1f ]; 
    331331        glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, Cc.ptr); 
    332         glColor3f (1f, 0f, 0f); 
    333332         
    334333        glBegin (GL_QUADS); 
  • mde/font/font.d

    r85 r86  
    131131        /** Cleanup: delete all fonts. */ 
    132132        StageState cleanup () { 
    133             // Clear loaded fonts
     133            // Clear loaded fonts (each has an FT_Face object needing to be freed)
    134134            foreach (fs; fonts) 
    135135                delete fs; 
    136             fonts = null; 
    137             delete fallback; 
    138              
    139             delete fontTex;     // clear texture 
     136             
    140137            FT_Done_FreeType (library); // free the library 
    141138             
     
    227224     * This function will only actually update the cache if it is invalid, caused either by the 
    228225     * font being changed or if cache.cacheVer < 0. */ 
    229     void updateBlock (char[] str, ref TextBlock cache) { 
     226    void updateBlock (char[] str, ref TextBlock cache) 
     227    in { 
     228        debug assert (face, "FontStyle: face is null"); 
     229    } body { 
    230230        try { 
    231231            fontTex.updateCache (face, str, cache); 
     
    260260     * of a text block is to use a TextBlock cache and update it, either with this function or with 
    261261     * the updateBlock function. */ 
    262     void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col) { 
     262    void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col) 
     263    in { 
     264        debug assert (face, "FontStyle: face is null"); 
     265    } body { 
    263266        try { 
    264267            fontTex.drawCache (face, str, cache, x, y, col); 
     
    268271    } 
    269272    /** ditto */ 
    270     void textBlock (int x, int y, char[] str, Colour col) { 
     273    void textBlock (int x, int y, char[] str, Colour col) 
     274    in { 
     275        debug assert (face, "FontStyle: face is null"); 
     276    } body { 
    271277        try { 
    272278            // Using the cache method for one-time use is slightly less than optimal, but doing so 
     
    284290     * Set the alpha by calling glColor*() first. See FontTexture.drawCacheA()'s documentation for 
    285291     * details. */ 
    286     void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col) { 
     292    void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col)  
     293    in { 
     294        debug assert (face, "FontStyle: face is null"); 
     295    } body { 
    287296        try { 
    288297            fontTex.drawCacheA (face, str, cache, x, y, col); 
     
    298307     
    299308    ~this () { 
    300         debug logger.trace ("{}.~this: start", this); 
    301309        FT_Done_Face (face); 
    302         debug logger.trace ("{}.~this: done", this); 
    303310    } 
    304311     
  • mde/gui/WidgetManager.d

    r85 r86  
    5151 * Aside from the IWidgetManager methods, this class should be thread-safe. 
    5252 *************************************************************************************************/ 
    53 class WidgetManager : WidgetLoader, Screen.Drawable { 
     53class WidgetManager : WidgetLoader, Screen.IDrawable { 
    5454    /** Construct a new widget manager. 
    5555     *  
     
    7575    /** Draw the gui. */ 
    7676    void draw() { 
    77         debug logger.trace ("drawing; w,h = {},{}",w,h); 
    7877        synchronized(mutex) 
    7978            if (child) 
     
    118117     
    119118     
    120     void sizeEvent (int nw, int nh) {   // Drawable function 
     119    void sizeEvent (int nw, int nh) {   // IDrawable function 
    121120        mutex.lock; 
    122121        scope(exit) mutex.unlock; 
  • mde/input/Config.d

    r85 r86  
    162162            else debug logger.error ("Ended up with DataSection of wrong type; this should never happen."); 
    163163        } 
    164          
    165         debug (MDE_CONFIG_DUMP) { 
    166             logger.trace ("Loaded {} config sections.", configs.length); 
    167             foreach (id, cfg; configs) { 
    168                 logger.trace ("Section " ~ id ~ 
    169                 ":\n\tbutton:\t\t" ~ parseFrom!(uint[][][uint])(cfg.button) ~ 
    170                 "\n\taxis:\t\t" ~ parseFrom!(uint[][][uint])(cfg.axis) ~ 
    171                 "\n\trelMotion:\t" ~ parseFrom!(uint[][][uint])(cfg.relMotion) ); 
    172             } 
    173         } 
    174164    } 
    175165     
  • mde/input/joystick.d

    r85 r86  
    5555    foreach (js; joysticks) { 
    5656        // FIXME: This sometimes causes a SIGSEGV (Address boundary error) when init fails. 
    57         debug logger.trace ("Closing joysticks (this sometimes fails when mde exits prematurely)"); 
    5857        if(js !is null) SDL_JoystickClose(js);  // only close if successfully opened 
    59         debug logger.trace ("Done closing joysticks"); 
    6058    } 
    6159    return StageState.INACTIVE; 
  • mde/lookup/Options.d

    r85 r86  
    137137            assert (((cast(ID) i) in subClasses) is null);  // Don't allow a silent replacement 
    138138        } body { 
    139             debug logger.trace ("Adding Options subClass: "~i); 
    140139            subClasses[cast(ID) i] = c; 
    141140        } 
     
    170169        void save () { 
    171170            if (!changed) return;   // no changes to save 
    172             // Types: 
    173             // interface IDataSection {...} 
    174             // class Options {...} 
    175             // alias char[] ID; 
    176             // IDataSection[ID] ds.sec; 
    177             // Options[ID] subClasses; 
     171            debug logger.trace ("Saving options..."); 
     172             
    178173            DataSet ds = new DataSet(); 
    179             foreach (id, subOpts; subClasses) { 
     174            foreach (id, subOpts; subClasses) 
    180175                ds.sec[id] = subOpts.optionChanges; 
    181                 debug logger.trace ("Saving options section: "~id); 
    182             } 
    183             foreach (i,s; ds.sec) 
    184                 debug logger.trace ("sec ID length: {}", i.length); 
    185             debug logger.trace ("0"); 
    186176             
    187177            // Read locally-stored options 
     
    190180                reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY, ds); 
    191181                reader.dataSecCreator = delegate IDataSection(ID id) { 
    192                     debug logger.trace ("New section to save ignored: "~id); 
     182                    debug logger.warn ("New section appearing in options.mtt during save (ignored & overwritten): "~id); 
    193183                    return null;    // All recognised sections are already in the dataset. 
    194184                }; 
     
    202192         
    203193            try { 
    204                 debug logger.trace ("1"); 
    205194                IWriter writer; 
    206                 foreach (i,s; ds.sec) 
    207                     debug logger.trace ("sec ID length: {}", i.length); 
    208                 debug logger.trace ("2"); 
    209                 writer = confDir.makeMTWriter (fileName, ds);   // FIXME - sometimes SIGSEGV 
    210                 debug logger.trace ("3"); 
    211                 writer.write(); // FIXME - this is causing hang at exit! 
    212                 debug logger.trace ("4"); 
     195                writer = confDir.makeMTWriter (fileName, ds); 
     196                writer.write(); 
    213197            } catch (Exception e) { 
    214198                logger.error ("Saving options aborted: "~e.msg); 
  • mde/mde.d

    r85 r86  
    3131import tango.time.Clock;                // Clock.now() 
    3232import tango.util.log.Log : Log, Logger; 
    33 debug (mdeUnitTest) { 
     33debug (mdeUnitTest) {                   // These modules contain unittests which wouldn't be run otherwise. 
    3434    import mde.file.ssi; 
    3535    import mde.file.mergetag.mdeUT; 
    3636} 
    3737 
     38//BEGIN A simple drawable to print a message in the window. 
     39import mde.font.font; 
     40class SimpleDrawable : Screen.IDrawable { 
     41    this () { 
     42        msg = "Welcome to mde.\nThis executable is only for testing, and\nas such doesn't do anything interesting."; 
     43        debug msg ~= "\nRunning in debug mode."; 
     44        font = FontStyle.get("default");// get the default or fallback font 
     45    } 
     46    void sizeEvent (int,int) {};        // Don't care what the size is 
     47    void draw () { 
     48        font.textBlock (16,32, msg, textCache, Colour.WHITE); 
     49    } 
     50    char[] msg; 
     51    FontStyle font; 
     52    TextBlock textCache; 
     53} 
     54//END A simple drawable to print a message in the window. 
     55 
     56 
    3857int main(char[][] args) 
    3958{ 
     59    Logger logger = Log.getLogger ("mde.mde"); 
     60     
    4061    // If compiled with unittests, notify that they completed and exit: 
    4162    debug (mdeUnitTest) { 
    42         Logger logger = Log.getLogger ("mde.mde"); 
    4363        logger.info ("Compiled unittests have completed; terminating."); 
    4464        return 0; 
     
    4666     
    4767    scope Init init = new Init(args);   // initialize mde 
     68     
     69    // Note: must create the drawable after init, since it uses font (initialized in init). 
     70    Screen.addDrawable (new SimpleDrawable);    // a drawable to print a message. 
    4871     
    4972    // Make sure pollInterval has a sane value. FIXME: get Options class to enforce range 
  • mde/setup/Init.d

    r85 r86  
    258258            } 
    259259        } 
    260         debug logger.trace ("Added {} init/cleanup stages", toRun.size); 
    261260        int numWorking = miscOpts.numThreads; 
    262261        bool abortInit = false; 
     
    276275         * When notified, threads start at 1. */ 
    277276        void initThreadFct () { 
    278             debug logger.trace ("initThreadFct: starting"); 
    279277            try {       // created as a thread - must not throw exceptions 
    280278            InitStage* stage; 
     
    347345            } 
    348346            toRunC.notifyAll(); // Most likely if we're exiting, we should make sure others aren't waiting. 
    349             debug logger.trace ("initThreadFct: returning"); 
    350347            return; 
    351348        } 
     
    397394     
    398395    debug (mdeUnitTest) unittest { 
    399         logger.trace ("Starting unittest"); 
    400          
    401396        auto realInit = stages;         // backup the real init stages 
    402397        stages = new typeof(stages);    // an empty test-bed 
  • mde/setup/Screen.d

    r85 r86  
    3636    // TYPES (these mustn't be static): 
    3737    /** Interface for anything hooking into the screen for drawing, etc. */ 
    38     interface Drawable { 
     38    interface IDrawable { 
    3939        /** Called on window creation and whenever the window manager resizes the window, before 
    4040         * the new size is set. The new size is passed. 
     
    6464            throw new InitException ("SDL Initialization failed"); 
    6565        } 
    66         debug logger.trace ("SDL initialised"); 
    6766        return StageState.ACTIVE; 
    6867    } 
     
    10099         
    101100        // Open a window 
    102         debug logger.trace ("Opening a window (this can crash if the libraries are messed up)"); 
    103101        if (setWindow (w, h)) { 
    104102            throw new InitException ("Failed to open a window"); 
     
    170168    } 
    171169     
    172     /** Add a drawable element to the screen (see Drawable interface). 
     170    /** Add a drawable element to the screen (see IDrawable interface). 
    173171     * 
    174      * Should be called before Init to get initial size. Currently no means to remove drawables, 
    175      * and not really designed for more than one. */ 
    176     void addDrawable (Drawable d) { 
     172     * Should be called before Init to get the initial size (sizeEvent is only called when the size 
     173     * is set). Currently no means to remove drawables, and not really designed for more than one. 
     174     */ 
     175    void addDrawable (IDrawable d) { 
    177176        drawables ~= d; 
    178177    } 
     
    182181        glClear(GL_COLOR_BUFFER_BIT); 
    183182         
    184         foreach (Drawable d; drawables) 
     183        foreach (IDrawable d; drawables) 
    185184            d.draw; 
    186185         
    187         debug (drawGlyphCache) { 
    188             logger.trace ("Drawing font texture"); 
    189             FontStyle.drawTexture; 
    190         } 
     186        debug (drawGlyphCache) FontStyle.drawTexture; 
    191187         
    192188        // Error check: 
     
    207203            d.sizeEvent (w,h); 
    208204         
    209         debug logger.trace ("Setting video mode {}x{}, 32-bit, flags: {}", w,h,flags); 
     205        //debug logger.trace ("Setting video mode {}x{}, 32-bit, flags: {}", w,h,flags); 
    210206        if (SDL_SetVideoMode (w, h, 32, flags) is null) { 
    211207            logger.fatal ("Unable to set video mode:"); 
     
    264260private: 
    265261    uint flags = 0; 
    266     Drawable[] drawables; 
     262    IDrawable[] drawables; 
    267263    Logger logger; 
    268264    OptionsVideo vidOpts;