Changeset 918
- Timestamp:
- 03/14/10 03:49:25 (5 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 modified
-
client/client.vcproj (modified) (4 diffs)
-
client/Game2/GameApp.cpp (modified) (5 diffs)
-
client/Game2/GameApp.h (modified) (2 diffs)
-
client/Game2/GamePeer.cpp (added)
-
client/Game2/GamePeer.h (added)
-
client/Game2/SysConsole.cpp (modified) (4 diffs)
-
client/Game2/SysConsole.h (modified) (3 diffs)
-
include/config-win32.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/client.vcproj
r897 r918 69 69 Name="VCLinkerTool" 70 70 AdditionalOptions="/MACHINE:I386" 71 AdditionalDependencies="wsock32.lib winmm.lib version.lib comctl32.lib libcurld.lib LiteUnzip.lib intl.lib lua5.1D.lib OIS_d.lib"71 AdditionalDependencies="wsock32.lib winmm.lib version.lib comctl32.lib libcurld.lib LiteUnzip.lib intl.lib lua5.1D.lib luabindD.lib OIS_d.lib" 72 72 OutputFile="..\Debug\HoverRace.exe" 73 73 SuppressStartupBanner="true" … … 152 152 <Tool 153 153 Name="VCLinkerTool" 154 AdditionalDependencies="wsock32.lib winmm.lib version.lib comctl32.lib libcurl.lib LiteUnzip.lib intl.lib lua5.1.lib OIS.lib"154 AdditionalDependencies="wsock32.lib winmm.lib version.lib comctl32.lib libcurl.lib LiteUnzip.lib intl.lib lua5.1.lib luabind.lib OIS.lib" 155 155 OutputFile=".\..\Release\HoverRace.exe" 156 156 LinkIncremental="1" … … 294 294 </File> 295 295 <File 296 RelativePath=".\Game2\GamePeer.cpp" 297 > 298 </File> 299 <File 300 RelativePath=".\Game2\GamePeer.h" 301 > 302 </File> 303 <File 296 304 RelativePath=".\Game2\HighConsole.cpp" 297 305 > … … 669 677 Description="$(InputFileName)" 670 678 CommandLine="copy "$(InputPath)" $(OutDir)
" 679 Outputs="$(OutDir)\$(InputFileName)" 680 /> 681 </FileConfiguration> 682 </File> 683 <File 684 RelativePath="..\lib\luabind.dll" 685 > 686 <FileConfiguration 687 Name="Debug|Win32" 688 ExcludedFromBuild="true" 689 > 690 <Tool 691 Name="VCCustomBuildTool" 692 Description="$(InputFileName)" 693 CommandLine="copy "$(InputPath)" $(OutDir)" 694 Outputs="$(OutDir)\$(InputFileName)" 695 /> 696 </FileConfiguration> 697 <FileConfiguration 698 Name="Release|Win32" 699 > 700 <Tool 701 Name="VCCustomBuildTool" 702 Description="$(InputFileName)" 703 CommandLine="copy "$(InputPath)" $(OutDir)" 704 Outputs="$(OutDir)\$(InputFileName)" 705 /> 706 </FileConfiguration> 707 </File> 708 <File 709 RelativePath="..\lib\luabindD.dll" 710 > 711 <FileConfiguration 712 Name="Debug|Win32" 713 > 714 <Tool 715 Name="VCCustomBuildTool" 716 Description="$(InputFileName)" 717 CommandLine="copy "$(InputPath)" $(OutDir)" 718 Outputs="$(OutDir)\$(InputFileName)" 719 /> 720 </FileConfiguration> 721 <FileConfiguration 722 Name="Release|Win32" 723 ExcludedFromBuild="true" 724 > 725 <Tool 726 Name="VCCustomBuildTool" 727 Description="$(InputFileName)" 728 CommandLine="copy "$(InputPath)" $(OutDir)" 671 729 Outputs="$(OutDir)\$(InputFileName)" 672 730 /> -
trunk/client/Game2/GameApp.cpp
r910 r918 28 28 #include "FirstChoiceDialog.h" 29 29 #include "FullscreenTest.h" 30 #include "GamePeer.h" 30 31 #include "Controller.h" 31 32 #include "resource.h" … … 570 571 571 572 MR_GameApp::MR_GameApp(HINSTANCE pInstance, bool safeMode) : 572 introMovie(NULL), scripting(NULL), sysConsole(NULL)573 introMovie(NULL), scripting(NULL), gamePeer(NULL), sysConsole(NULL) 573 574 { 574 575 This = this; … … 613 614 delete sysConsole; 614 615 sysConsole = NULL; 616 } 617 if (gamePeer != NULL) { 618 delete gamePeer; 619 gamePeer = NULL; 615 620 } 616 621 if (scripting != NULL) { … … 1142 1147 // This allows the script to modify the configuration (e.g. for unit tests). 1143 1148 scripting = new Script::Core(); 1144 sysConsole = new SysConsole(scripting); 1149 GamePeer::Register(scripting); 1150 gamePeer = new GamePeer(scripting); 1151 sysConsole = new SysConsole(scripting, gamePeer); 1145 1152 if (!initScript.empty()) { 1146 1153 sysConsole->RunScript(initScript); … … 2007 2014 */ 2008 2015 case MR_WM_ON_INIT: 2009 This-> sysConsole->OnInit();2016 This->gamePeer->OnInit(); 2010 2017 break; 2011 2018 -
trunk/client/Game2/GameApp.h
r904 r918 32 32 namespace Client { 33 33 class FullscreenTest; 34 class GamePeer; 34 35 class HighConsole; 35 36 class IntroMovie; … … 87 88 HoverRace::Client::FullscreenTest *fullscreenTest; 88 89 HoverRace::Script::Core *scripting; 90 HoverRace::Client::GamePeer *gamePeer; 89 91 HoverRace::Client::SysConsole *sysConsole; 90 92 MR_ClientSession *mCurrentSession; -
trunk/client/Game2/SysConsole.cpp
r904 r918 28 28 #include <boost/filesystem/fstream.hpp> 29 29 #include <boost/format.hpp> 30 31 #include <luabind/luabind.hpp> 32 33 #include "GamePeer.h" 30 34 31 35 #include "SysConsole.h" … … 68 72 namespace Client { 69 73 70 SysConsole::SysConsole(Script::Core *scripting) : 71 SUPER(scripting), outHandle(scripting->AddOutput(boost::make_shared<LogStream>())) 74 SysConsole::SysConsole(Script::Core *scripting, GamePeer *gamePeer) : 75 SUPER(scripting), gamePeer(gamePeer), 76 outHandle(scripting->AddOutput(boost::make_shared<LogStream>())) 72 77 { 73 lua_State *state = scripting->GetState();74 75 scripting->PrintStack();76 77 // Initial table for callbacks.78 lua_newtable(state);79 onInitRef = luaL_ref(scripting->GetState(), LUA_REGISTRYINDEX);80 78 } 81 79 82 80 SysConsole::~SysConsole() 83 81 { 84 Script::Core *scripting = GetScripting(); 85 luaL_unref(scripting->GetState(), LUA_REGISTRYINDEX, onInitRef); 86 scripting->RemoveOutput(outHandle); 82 GetScripting()->RemoveOutput(outHandle); 87 83 } 88 84 89 85 void SysConsole::InitEnv() 90 86 { 87 using namespace luabind; 88 91 89 Script::Core *scripting = GetScripting(); 92 lua_State * state= scripting->GetState();90 lua_State *L = scripting->GetState(); 93 91 94 92 // Start with the standard global environment. 95 93 CopyGlobals(); 96 94 95 object env(from_stack(L, -1)); 96 env["game"] = gamePeer; 97 98 /* 97 99 lua_pushlightuserdata(state, this); // table this 98 100 lua_pushcclosure(state, SysConsole::LOnInit, 1); // table fn … … 106 108 lua_insert(state, -2); // table str fn 107 109 lua_rawset(state, -3); // table 110 */ 108 111 } 109 112 … … 152 155 } 153 156 154 /**155 * Executes all "on_init" callbacks.156 */157 void SysConsole::OnInit()158 {159 lua_State *state = GetScripting()->GetState();160 161 lua_rawgeti(state, LUA_REGISTRYINDEX, onInitRef); // table162 163 lua_pushnil(state); // table nil164 while (lua_next(state, -2) != 0) {165 // table key fn166 lua_call(state, 0, 0); // table key167 }168 // table169 lua_pop(state, 1);170 }171 172 int SysConsole::LOnInit(lua_State *state)173 {174 // function on_init(f)175 // Register a callback function for when the game starts up.176 SysConsole *self = static_cast<SysConsole*>(lua_touserdata(state, lua_upvalueindex(1)));177 178 if (!lua_isfunction(state, 1)) {179 lua_pushstring(state, "on_init requires a function.");180 return lua_error(state);181 }182 183 lua_rawgeti(state, LUA_REGISTRYINDEX, self->onInitRef); // table184 185 lua_pushinteger(state, lua_objlen(state, -1) + 1); // table key186 lua_pushvalue(state, 1); // table key fn187 lua_settable(state, -3); // table188 189 lua_pop(state, 1);190 191 return 0;192 }193 194 int SysConsole::LGetOnInit(lua_State *state)195 {196 // function get_on_init()197 // Returns the table of on_init callbacks (for debugging purposes).198 SysConsole *self = static_cast<SysConsole*>(lua_touserdata(state, lua_upvalueindex(1)));199 200 lua_rawgeti(state, LUA_REGISTRYINDEX, self->onInitRef); // table201 202 return 1;203 }204 205 157 } // namespace Client 206 158 } // namespace HoverRace -
trunk/client/Game2/SysConsole.h
r904 r918 27 27 28 28 namespace HoverRace { 29 namespace Client { 30 class GamePeer; 31 } 29 32 namespace Script { 30 33 class Core; … … 40 43 41 44 public: 42 SysConsole(Script::Core *scripting );45 SysConsole(Script::Core *scripting, GamePeer *gamePeer); 43 46 virtual ~SysConsole(); 44 47 … … 53 56 void RunScript(const std::string &filename); 54 57 55 public:56 void OnInit();57 58 58 private: 59 static int LOnInit(lua_State *state); 60 static int LGetOnInit(lua_State *state); 61 62 private: 59 GamePeer *gamePeer; 63 60 Script::Core::OutHandle outHandle; 64 int onInitRef;65 61 }; 66 62 -
trunk/include/config-win32.h
r871 r918 16 16 #define HAVE_LUA 1 17 17 18 #define HAVE_LUABIND 1 19 #define LUABIND_DYNAMIC_LINK 1 20 18 21 // Only enable DirectShow support if a recent Windows SDK is installed. 19 22 #if defined(VER_PRODUCTBUILD) && VER_PRODUCTBUILD >= 6001
