Changeset 880 – HoverRace

Changeset 880

Show
Ignore:
Timestamp:
02/28/10 23:41:33 (5 months ago)
Author:
zoogie
Message:

We can now specify a Lua script to run at startup. This script can then set callback functions to run in a special system context (currently, only "on_init" is supported).

Location:
trunk
Files:
2 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/client/client.vcproj

    r877 r880  
    459459            </File> 
    460460            <File 
     461                RelativePath=".\Game2\SysConsole.cpp" 
     462                > 
     463            </File> 
     464            <File 
     465                RelativePath=".\Game2\SysConsole.h" 
     466                > 
     467            </File> 
     468            <File 
    461469                RelativePath=".\Game2\TrackDownloadDialog.cpp" 
    462470                > 
  • trunk/client/Game2/GameApp.cpp

    r879 r880  
    3636#include "IntroMovie.h" 
    3737#include "Rulebook.h" 
     38#include "SysConsole.h" 
    3839#include "TrackSelect.h" 
    3940#include "TrackDownloadDialog.h" 
     
    100101#define MRM_RETURN2WINDOWMODE  1 
    101102#define MRM_EXIT_MENU_LOOP     2 
     103 
     104#define MR_WM_ON_INIT (WM_APP + 0x0042) 
    102105 
    103106#ifdef WITH_OPENAL 
     
    566569 
    567570MR_GameApp::MR_GameApp(HINSTANCE pInstance, bool safeMode) : 
    568     introMovie(NULL) 
     571    introMovie(NULL), sysConsole(NULL) 
    569572{ 
    570573    This = this; 
     
    606609MR_GameApp::~MR_GameApp() 
    607610{ 
     611    if (sysConsole != NULL) { 
     612        delete sysConsole; 
     613        sysConsole = NULL; 
     614    } 
     615 
    608616    delete controller; 
    609617 
     
    10971105    BOOL lReturnValue = TRUE; 
    10981106    Config *cfg = Config::GetInstance(); 
     1107    std::string &initScript = cfg->runtime.initScript; 
    10991108 
    11001109    InitCommonControls();                         // Allow some special and complex controls 
     
    11831192 
    11841193    // play the opening movie 
    1185     if(lReturnValue && cfg->misc.introMovie) { 
     1194    if(lReturnValue && cfg->misc.introMovie && initScript.empty()) { 
    11861195        introMovie = new IntroMovie(mMainWindow, mInstance); 
    11871196        introMovie->Play(); 
     
    12011210 
    12021211    // show "click OK to play on the internet" dialog 
    1203     if(lReturnValue && cfg->misc.displayFirstScreen) { 
     1212    if(lReturnValue && cfg->misc.displayFirstScreen && initScript.empty()) { 
    12041213        if (FirstChoiceDialog().ShowModal(mInstance, mMainWindow)) 
    12051214            SendMessage(mMainWindow, WM_COMMAND, ID_GAME_NETWORK_INTERNET, 0); 
     1215    } 
     1216 
     1217    // Create the system console and execute the init script. 
     1218    sysConsole = new SysConsole(); 
     1219    sysConsole->Init(); 
     1220    if (!initScript.empty()) { 
     1221        sysConsole->RunScript(initScript); 
    12061222    } 
    12071223 
     
    19821998               break; 
    19831999         */ 
     2000        case WM_CREATE: 
     2001            // Trigger the scripting "on_init" call later. 
     2002            PostMessage(pWindow, MR_WM_ON_INIT, 0, 0); 
     2003            break; 
     2004 
     2005        case MR_WM_ON_INIT: 
     2006            This->sysConsole->OnInit(); 
     2007            break; 
    19842008 
    19852009        case WM_DISPLAYCHANGE: 
  • trunk/client/Game2/GameApp.h

    r878 r880  
    3636        class Rulebook; 
    3737        typedef boost::shared_ptr<Rulebook> RulebookPtr; 
     38        class SysConsole; 
    3839    } 
    3940} 
     
    8283        HoverRace::Client::IntroMovie *introMovie; 
    8384        HoverRace::Client::FullscreenTest *fullscreenTest; 
     85        HoverRace::Client::SysConsole *sysConsole; 
    8486        MR_ClientSession *mCurrentSession; 
    8587        MR_GameThread *mGameThread; 
  • trunk/client/Game2/main.cpp

    r871 r880  
    4646using HoverRace::Util::OS; 
    4747 
     48static std::string initScript; 
    4849static bool debugMode = false; 
    4950static bool safeMode = false; 
     
    8081        if (strcmp("-D", arg) == 0) { 
    8182            debugMode = true; 
     83        } 
     84        else if (strcmp("--exec", arg) == 0) { 
     85            if (i < argc) { 
     86                initScript = argv[i++]; 
     87            } 
     88            else { 
     89                ShowMessage("Expected: --exec (script filename)"); 
     90                return false; 
     91            } 
    8292        } 
    8393        else if (strcmp("-L", arg) == 0) { 
     
    204214    cfg->runtime.aieeee = experimentalMode; 
    205215    cfg->runtime.showFramerate = showFramerate; 
     216    cfg->runtime.initScript = initScript; 
    206217 
    207218#ifdef ENABLE_NLS 
  • trunk/engine/Util/Config.h

    r828 r880  
    220220            bool showFramerate; 
    221221            bool enableConsole; 
     222            std::string initScript; 
    222223        } runtime; 
    223224};