Mercurial > mm7
changeset 2052:71a814f4482a
Moved implementation to cpp
author | Nomad |
---|---|
date | Fri, 29 Nov 2013 12:20:07 +0200 |
parents | 29e16f184db8 |
children | 64e23bf9d27e |
files | Build/Visual Studio 2012/World of Might and Magic.vcxproj Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Events.cpp Game.cpp LuaClass.h LuaVM.cpp LuaVM.h OSWindow.cpp OSWindow.h lib/swig.bat mm7_2.cpp |
diffstat | 11 files changed, 115 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj Fri Nov 29 09:45:35 2013 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj Fri Nov 29 12:20:07 2013 +0200 @@ -226,6 +226,7 @@ <ClCompile Include="..\..\Vis.cpp" /> <ClCompile Include="..\..\Weather.cpp" /> <ClCompile Include="..\..\_deleted.cpp" /> + <ClCompile Include="LuaVM.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\Actor.h" /> @@ -325,7 +326,7 @@ <ClInclude Include="..\..\Lights.h" /> <ClInclude Include="..\..\LOD.h" /> <ClInclude Include="..\..\Log.h" /> - <ClInclude Include="..\..\LuaClass.h" /> + <ClInclude Include="..\..\LuaVM.h" /> <ClInclude Include="..\..\MapInfo.h" /> <ClInclude Include="..\..\MM7.h" /> <ClInclude Include="..\..\mm7_data.h" />
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Fri Nov 29 09:45:35 2013 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Fri Nov 29 12:20:07 2013 +0200 @@ -308,6 +308,7 @@ <Filter>NewUI\Core</Filter> </ClCompile> <ClCompile Include="..\..\Timer.cpp" /> + <ClCompile Include="LuaVM.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\Level\Decoration.h"> @@ -593,7 +594,7 @@ <ClInclude Include="..\..\TestClass.h" /> <ClInclude Include="..\..\OurMath.h" /> <ClInclude Include="..\..\Timer.h" /> - <ClInclude Include="..\..\LuaClass.h" /> + <ClInclude Include="..\..\LuaVM.h" /> </ItemGroup> <ItemGroup> <None Include="..\..\lib\legacy_dx\d3dvec.inl">
--- a/Events.cpp Fri Nov 29 09:45:35 2013 +0600 +++ b/Events.cpp Fri Nov 29 12:20:07 2013 +0200 @@ -33,7 +33,7 @@ #include "Log.h" #include "MM7.h" #include "Level/Decoration.h" -#include "LuaClass.h" +#include "LuaVM.h" @@ -431,7 +431,7 @@ dword_5B65C4_cancelEventProcessing = 0; if ( uEventID == 114 ) { - if ( pMM_lua->DoFile("out01.lua") ) + if (!lua->DoFile("out01.lua")) Log::Warning(L"Error opening out01.lua\n"); } if ( !uEventID )
--- a/Game.cpp Fri Nov 29 09:45:35 2013 +0600 +++ b/Game.cpp Fri Nov 29 12:20:07 2013 +0200 @@ -748,14 +748,11 @@ //----- (004645FA) -------------------------------------------------------- void Game::Deinitialize() { - struct tagRECT Rect; // [sp+0h] [bp-10h]@6 - - WriteWindowsRegistryInt("startinwindow", pRenderer->bWindowMode); - if ( GetWindowRect(window->GetApiHandle(), &Rect) && pRenderer->bWindowMode ) + if (pRenderer->bWindowMode) { - WriteWindowsRegistryInt("window X", Rect.left); - WriteWindowsRegistryInt("window Y", Rect.top); + WriteWindowsRegistryInt("window X", window->GetX()); + WriteWindowsRegistryInt("window Y", window->GetY()); } window->Delete(); WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
--- a/LuaClass.h Fri Nov 29 09:45:35 2013 +0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -#pragma once - -#include <lib/lua/lua.h> -#include <Log.h> -#include "OSAPI.h" - -extern "C" int luaopen_UIControl(lua_State *L); // declare the wrapped module - -class LuaVM -{ - public: - void Initialize() - { - L = luaL_newstate(); - if ( L == NULL ) - Log::Warning(L"Error creating Lua context.\n"); - luaL_openlibs(L); - if ( luaL_dofile(L,GetScriptFileLocation("script.lua"))) - Log::Warning(L"Error opening script.lua\n"); - // все нужные cxx - luaopen_UIControl(L); - } - - bool DoFile(const char *filename) - { - if (luaL_dofile(L, GetScriptFileLocation(filename))) - { - Log::Warning(L"Error opening %s", filename); - return 1; - } - return 0; - } - - protected: - lua_State *L; - - const char *GetScriptFileLocation(const char *script_name) - { - static char buf[2048]; - strcpy(buf, "Data/scripts/lua/core/"); - strcat(buf, script_name); - return buf; - } -}; - -extern LuaVM *pMM_lua; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LuaVM.cpp Fri Nov 29 12:20:07 2013 +0200 @@ -0,0 +1,53 @@ +#include "LuaVM.h" +#include "lib/lua/lua.h" +#include "Log.h" +#include "OSAPI.h" + +extern "C" int luaopen_UIControl(lua_State *L); // declare the wrapped module + +LuaVM *lua = nullptr; + +void LuaVM::Initialize() +{ + if (L) + Log::Warning(L"Overwriting previous Lua state"); + + L = luaL_newstate(); + if (!L) + Log::Warning(L"Error creating Lua context.\n"); + + // open default lua libs + luaL_openlibs(L); + + // open each cxx module + luaopen_UIControl(L); + + //if ( luaL_dofile(L,GetScriptFileLocation("script.lua"))) + // Log::Warning(L"Error opening script.lua\n"); +} + +bool LuaVM::DoFile(const char *filename) +{ + if (luaL_dofile(L, GetScriptFileLocation(filename))) + { + Log::Warning(L"Error opening script %s", filename); + return false; + } + return true; +} + +const char *LuaVM::GetScriptFileLocation(const char *script_name) +{ + static DWORD tls_index = TlsAlloc(); + + auto buf = (char *)TlsGetValue(tls_index); + if (!buf) + { + buf = new char[1024]; + TlsSetValue(tls_index, buf); + } + + strcpy(buf, "data/scripts/lua/core/"); + strcat(buf, script_name); + return buf; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LuaVM.h Fri Nov 29 12:20:07 2013 +0200 @@ -0,0 +1,14 @@ +#pragma once + +class LuaVM +{ + public: + void Initialize(); + bool DoFile(const char *filename); + + protected: + struct lua_State *L; + + const char *GetScriptFileLocation(const char *script_name); +}; +extern LuaVM *lua; \ No newline at end of file
--- a/OSWindow.cpp Fri Nov 29 09:45:35 2013 +0600 +++ b/OSWindow.cpp Fri Nov 29 12:20:07 2013 +0200 @@ -17,6 +17,7 @@ #include "AIL.h" #include "Bink_Smacker.h" #include "ErrorHandling.h" +#include "Log.h" bool OSWindow::OnMouseLeftClick(int x, int y) @@ -802,23 +803,25 @@ bool OSWindow::SetColorDepth(int bit) { - dm.dmSize = sizeof(DEVMODE); - if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm)) - { - printf("EnumDisplaySettings failed:%d\n", GetLastError()); - return false; - } - dm.dmBitsPerPel = bit; - dm.dmFields = DM_BITSPERPEL; - if (ChangeDisplaySettings(&dm, CDS_TEST) !=DISP_CHANGE_SUCCESSFUL) - { - printf("\nIllegal graphics mode: %d\n", GetLastError()); - return false; - } - if (ChangeDisplaySettings(&dm, 0) == DISP_CHANGE_SUCCESSFUL) - { - ChangedColorDepth = true; - } + DEVMODE dm; + if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm)) + { + Log::Warning(L"EnumDisplaySettings failed: %d\n", GetLastError()); + return false; + } + + dm.dmSize = sizeof(DEVMODE); + dm.dmBitsPerPel = bit; + dm.dmFields = DM_BITSPERPEL; + if (ChangeDisplaySettings(&dm, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) + { + Log::Warning(L"Illegal graphics mode: %d\n", GetLastError()); + return false; + } + if (ChangeDisplaySettings(&dm, 0) == DISP_CHANGE_SUCCESSFUL) + { + ChangedColorDepth = true; + } } void OSWindow::Delete()
--- a/OSWindow.h Fri Nov 29 09:45:35 2013 +0600 +++ b/OSWindow.h Fri Nov 29 12:20:07 2013 +0200 @@ -6,13 +6,15 @@ { public: static OSWindow *Create(const wchar_t *title, int window_width, int window_height); - void Delete(); + void Delete(); void SetFullscreenMode(); void SetWindowedMode(int new_window_width, int new_window_height); void SetCursor(const char *cursor_name); inline HWND GetApiHandle() const {return api_handle;} + inline int GetX() const {RECT rc; GetWindowRect(api_handle, &rc); return rc.left;} + inline int GetY() const {RECT rc; GetWindowRect(api_handle, &rc); return rc.top;} inline unsigned int GetWidth() const {RECT rc; GetClientRect(api_handle, &rc); return rc.right - rc.left;} inline unsigned int GetHeight() const {RECT rc; GetClientRect(api_handle, &rc); return rc.bottom - rc.top;} @@ -42,11 +44,10 @@ bool SetColorDepth(int bit); bool WinApiMessageProc(UINT msg, WPARAM wparam, LPARAM lparam, LRESULT *result); - HWND api_handle; - DEVMODE dm; + HWND api_handle; private: - bool ChangedColorDepth; + bool ChangedColorDepth; static LPARAM __stdcall WinApiMsgRouter(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); HMENU CreateDebugMenuPanel();
--- a/lib/swig.bat Fri Nov 29 09:45:35 2013 +0600 +++ b/lib/swig.bat Fri Nov 29 12:20:07 2013 +0200 @@ -1,15 +1,16 @@ -echo 1 %1 -echo 2 %2 -echo 3 %3 -echo 4 %4 -echo 5 %5 -echo 6 %6 +@echo off +rem echo 1 %1 +rem echo 2 %2 +rem echo 3 %3 +rem echo 4 %4 +rem echo 5 %5 +rem echo 6 %6 -echo xcopy %4 "../../lib/swig/swigwin-2.0.11" /y +rem echo xcopy %4 "../../lib/swig/swigwin-2.0.11" /y xcopy %4 "../../lib/swig/swigwin-2.0.11" /y cd ../../lib/swig/swigwin-2.0.11 swig -c++ -lua %3 -echo xcopy "%6" %5"%2" /y +rem echo xcopy "%6" %5"%2" /y xcopy "%6" %5"%2" /y \ No newline at end of file
--- a/mm7_2.cpp Fri Nov 29 09:45:35 2013 +0600 +++ b/mm7_2.cpp Fri Nov 29 12:20:07 2013 +0200 @@ -67,17 +67,15 @@ #include "Lights.h" #include "NewUI/MainMenu.h" #include "Level/Decoration.h" - -#include "lib/lua/lua.h" -#include "LuaClass.h" +#include "LuaVM.h" + +//#include "lib/lua/lua.h" int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam); int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4); bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive); bool __fastcall Initialize(HINSTANCE hInst, char *pCmdLine); -class LuaVM *pMM_lua; - //----- (004A1780) mm6_chinese--------------------------------------------- __int64 fixpoint_div(int a1, int a2) { @@ -4320,8 +4318,8 @@ char test[1024]; sprintfex(test, "^Pi[%s]: знахар^R[ь;ка;]", "Золтан"); - pMM_lua = new LuaVM; - pMM_lua->Initialize(); + lua = new LuaVM; + lua->Initialize(); bool bNoMargareth = false; if (pCmdLine && *pCmdLine)