view mde/scheduler/InitFunctions.d @ 31:baa87e68d7dc

GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup. Removed some circular dependencies which slipped in. As a result, the OpenGL code got separated into different files. Enabled widgets to recieve events. New IParentWidget interface allowing widgets to interact with their parents. New Widget base class. New WidgetDecoration class. New ButtonWidget class responding to events (in a basic way). committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 29 Apr 2008 18:10:58 +0100
parents 467c74d4804d
children
line wrap: on
line source

/* LICENSE BLOCK
Part of mde: a Modular D game-oriented Engine
Copyright © 2007-2008 Diggory Hardy

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation, either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */

/** This module is responsible for calling all init functions.
*
* It is also responsible for setting up all scheduled functions for now.

* Idea: change import direction so this module adds all init functions. All init functions are
* wrapped in another function before being run in a thread (i.e. run indirectly). Functions fail
* either by throwing an exception or by returning a boolean. Functions may take parameters, e.g.
* "out cleanupFunc[]". */
module mde.scheduler.InitFunctions;

/+ unused
import tango.util.log.Log : Log, Logger;
static this() {
    logger = Log.getLogger ("mde.scheduler.InitFunctions");
}+/

void setInitFailure () {    /// Call to indicate failure in an init function
    initFailure = true;
}

/** Represents all functions to be called for a particular init stage. */
struct InitStage
{
    struct InitFunction {
        void delegate() func;       // the actual function
        char[] name;                // it's name;
    }
    
    /** Add a function to be called during this init stage.
    *
    * Called in order added when not threaded (reverse order for cleanup).
    *
    * Exceptions should never be thrown, since each function may run as a thread, and catching
    * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return
    * instead. */
    void addFunc (void delegate() f, char[] name) {
        InitFunction s;
        s.func = f;
        s.name = name;
        funcs ~= s;
    }
    void addFunc (void function() f, char[] name) { /// ditto
        InitFunction s;
        s.func.funcptr = f;
        s.name = name;
        funcs ~= s;
    }
    
    InitFunction[] funcs = [];
}

InitStage init;     // all functions called during init (all should be thread-safe)
InitStage cleanup;  // all functions called during cleanup (all should be thread-safe)

package:
bool initFailure = false;   // set on failure (throwing through threads isn't a good idea)

private:
//Logger logger;