view mde/mde.d @ 18:56a42ec95024

Changes to Init and logging. Moved an Init function; hence events now depends on Init rather than vice-versa. Paths and logging set up by Init's static this(). Logging location set at compile time. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 18 Mar 2008 17:51:52 +0000
parents 5f90774ea1ef
children 838577503598
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, version 2, as published by the Free Software Foundation.

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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */

/** Modular D Engine
 *
 * This module contains main().
 */
module mde.mde;

// Package imports
import mde.Init;
import global = mde.global;
import mde.events;
import mde.scheduler;
import mde.i18n.I18nTranslation;        // greeting message
import mde.exception;

// This module is ONLY imported because otherwise it wouldn't be compiled in:
import mde.SDL;

import mde.input.input;

// External library imports
import tango.core.Thread : Thread;	// for sleep
//import tango.io.Stdout;
import tango.time.Clock;
import tango.util.log.Log : Log, Logger;

import derelict.sdl.sdl;

int main()
{
    //BEGIN Initialisation
    Logger logger = Log.getLogger ("mde.mde");
    logger.info ("Starting mde...");
        
    try {
        init = new Init();	// initialisation
    } catch (InitException e) {
        logger.fatal ("Initialisation failed; error was:");
        logger.fatal (e.msg);
        return 1;
    }
    
    global.input.addButtonCallback (cast(Input.inputID) 0x0u, delegate void(Input.inputID i, bool b) {
        if (b) {
            logger.info ("Quiting...");
            global.run = false;
        }
    } );
    //END Initialisation
    
    /* Log a greeting message. Just a little test really, but it can stay until i18n finds a proper use. */
    I18nTranslation transl = I18nTranslation.load ("mde");
    logger.info (transl.getEntry ("greeting"));
    
    while (global.run) {
        Scheduler.run (Clock.now());
        
        Thread.sleep (0.050);	// sleep this many seconds
    }
    
    return 0;		// cleanup handled by init's DTOR
}