From fd3776a53bca3a10284dcbe35b430236a9d2ea81 Mon Sep 17 00:00:00 2001 From: dean11 Date: Thu, 12 Dec 2013 09:33:59 +0100 Subject: [PATCH] GameLogic - Pre-network merge --- Bin/Settings/PLACEHOLDER | 0 Bin/Settings/ServerInit.ini | 2 + Bin/Settings/serversearchpath.ini | 4 + Code/DanBias.sln | 6 +- Code/Game/DanBiasGame/Include/DanBiasGame.h | 6 +- .../DanBiasLauncher/DanBiasLauncher.vcxproj | 50 +-- Code/Game/DanBiasLauncher/Launcher.cpp | 20 +- Code/Game/DanBiasServer/DBServer.cpp | 56 --- Code/Game/DanBiasServer/DBServer.h | 27 -- Code/Game/DanBiasServer/DLLMain.cpp | 2 +- Code/Game/DanBiasServer/DanBiasServer.vcxproj | 57 ++- Code/Game/DanBiasServer/GameServer.cpp | 103 +++++ Code/Game/DanBiasServer/GameServer.h | 46 +++ .../DanBiasServerAPI.cpp} | 14 +- .../{IDanBiasServer.h => DanBiasServerAPI.h} | 28 +- .../DanBiasServer/Include/ServerWrapper.h | 23 -- Code/Game/DanBiasServer/MainLobby.h | 17 - Code/Game/DanBiasServer/ServerInitReader.h | 41 ++ .../ServerObjects/ClientObject.cpp | 12 + .../ServerObjects/ClientObject.h | 19 + .../ServerObjects/GameSession.cpp | 9 + .../DanBiasServer/ServerObjects/GameSession.h | 19 + .../ServerObjects/Lobby/GameLobby.cpp | 18 + .../ServerObjects/Lobby/GameLobby.h | 21 + .../ServerObjects/Lobby/MainLobby.cpp | 18 + .../ServerObjects/Lobby/MainLobby.h | 22 + .../ServerObjects/NetworkSession.cpp | 36 ++ .../ServerObjects/NetworkSession.h | 37 ++ Code/Game/GameProtocols/PlayerProtocols.h | 35 +- .../GameProtocols/ProtocolIdentificationID.h | 2 +- Code/WindowManager/WindowShell.cpp | 383 ++++++++---------- Code/WindowManager/WindowShell.h | 123 +++--- 32 files changed, 736 insertions(+), 520 deletions(-) delete mode 100644 Bin/Settings/PLACEHOLDER create mode 100644 Bin/Settings/ServerInit.ini create mode 100644 Bin/Settings/serversearchpath.ini delete mode 100644 Code/Game/DanBiasServer/DBServer.cpp delete mode 100644 Code/Game/DanBiasServer/DBServer.h create mode 100644 Code/Game/DanBiasServer/GameServer.cpp create mode 100644 Code/Game/DanBiasServer/GameServer.h rename Code/Game/DanBiasServer/{IDanBiasServer.cpp => Include/DanBiasServerAPI.cpp} (51%) rename Code/Game/DanBiasServer/Include/{IDanBiasServer.h => DanBiasServerAPI.h} (64%) delete mode 100644 Code/Game/DanBiasServer/Include/ServerWrapper.h delete mode 100644 Code/Game/DanBiasServer/MainLobby.h create mode 100644 Code/Game/DanBiasServer/ServerInitReader.h create mode 100644 Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp create mode 100644 Code/Game/DanBiasServer/ServerObjects/ClientObject.h create mode 100644 Code/Game/DanBiasServer/ServerObjects/GameSession.cpp create mode 100644 Code/Game/DanBiasServer/ServerObjects/GameSession.h create mode 100644 Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.cpp create mode 100644 Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.h create mode 100644 Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp create mode 100644 Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h create mode 100644 Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp create mode 100644 Code/Game/DanBiasServer/ServerObjects/NetworkSession.h diff --git a/Bin/Settings/PLACEHOLDER b/Bin/Settings/PLACEHOLDER deleted file mode 100644 index e69de29b..00000000 diff --git a/Bin/Settings/ServerInit.ini b/Bin/Settings/ServerInit.ini new file mode 100644 index 00000000..a3b8f420 --- /dev/null +++ b/Bin/Settings/ServerInit.ini @@ -0,0 +1,2 @@ +port 15151 +clients 200 \ No newline at end of file diff --git a/Bin/Settings/serversearchpath.ini b/Bin/Settings/serversearchpath.ini new file mode 100644 index 00000000..6dc44cff --- /dev/null +++ b/Bin/Settings/serversearchpath.ini @@ -0,0 +1,4 @@ +ServerInit ..\Settings\ServerInit.ini +More a +more b +more c \ No newline at end of file diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 32915f21..e2ee84d0 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -101,6 +101,7 @@ Global {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.Build.0 = Release|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Win32.ActiveCfg = Debug|Win32 + {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Win32.Build.0 = Debug|Win32 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|x64.ActiveCfg = Debug|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|x64.Build.0 = Debug|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -112,7 +113,6 @@ Global {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.Build.0 = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Win32.ActiveCfg = Debug|Win32 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Win32.Build.0 = Debug|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|x64.ActiveCfg = Debug|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|x64.Build.0 = Debug|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -124,6 +124,7 @@ Global {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.Build.0 = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.ActiveCfg = Debug|Win32 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.Build.0 = Debug|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.ActiveCfg = Debug|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.Build.0 = Debug|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -207,6 +208,7 @@ Global {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Win32.ActiveCfg = Debug|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Win32.Build.0 = Debug|Win32 {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.ActiveCfg = Debug|x64 {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.Build.0 = Debug|x64 {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Mixed Platforms.ActiveCfg = Release|Win32 @@ -229,6 +231,7 @@ Global {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Win32.ActiveCfg = Debug|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Win32.Build.0 = Debug|Win32 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.ActiveCfg = Debug|x64 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.Build.0 = Debug|x64 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Mixed Platforms.ActiveCfg = Release|Win32 @@ -240,6 +243,7 @@ Global {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Win32.ActiveCfg = Debug|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Win32.Build.0 = Debug|Win32 {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|x64.ActiveCfg = Debug|x64 {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|x64.Build.0 = Debug|x64 {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Mixed Platforms.ActiveCfg = Release|Win32 diff --git a/Code/Game/DanBiasGame/Include/DanBiasGame.h b/Code/Game/DanBiasGame/Include/DanBiasGame.h index 0f9b83eb..519eda13 100644 --- a/Code/Game/DanBiasGame/Include/DanBiasGame.h +++ b/Code/Game/DanBiasGame/Include/DanBiasGame.h @@ -10,9 +10,7 @@ #define NOMINMAX #include - -#include "L_inputClass.h" - +#define DANBIAS_CLIENT namespace DanBias { @@ -25,8 +23,6 @@ namespace DanBias DanBiasClientReturn_Sucess, }; - - struct DanBiasGameDesc { //Stuff goes here... diff --git a/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj index 6e5f099c..7eacfd89 100644 --- a/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj +++ b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj @@ -71,32 +71,32 @@ $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath) - $(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL; + $(SolutionDir)..\External\Include\;$(IncludePath) + $(OutDir)..\DLL\;$(LibraryPath) true $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath) - $(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL; + $(SolutionDir)..\External\Include\;$(IncludePath) + $(OutDir)..\DLL\;$(LibraryPath) false $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath) - $(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL; + $(SolutionDir)..\External\Include\;$(IncludePath) + $(OutDir)..\DLL\;$(LibraryPath) false $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath) - $(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL; + $(SolutionDir)..\External\Include\;$(IncludePath) + $(OutDir)..\DLL\;$(LibraryPath) @@ -105,13 +105,13 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows true DanBiasServer_$(PlatformShortName)D.dll;DanBiasGame_$(PlatformShortName)D.dll;%(DelayLoadDLLs) - Input_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies) + DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -121,13 +121,13 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows true DanBiasServer_$(PlatformShortName)D.dll;DanBiasGame_$(PlatformShortName)D.dll;%(DelayLoadDLLs) - Input_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies) + DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -139,7 +139,7 @@ true true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows @@ -147,7 +147,7 @@ true true DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs) - Input_$(PlatformShortName).lib;DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) + DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) @@ -159,7 +159,7 @@ true true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows @@ -167,34 +167,16 @@ true true DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs) - Input_$(PlatformShortName).lib;DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) + DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) - - {104fa3e9-94d9-4e1d-a941-28a03bc8a095} - - - {7e3990d2-3d94-465c-b58d-64a74b3ecf9b} - - - {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} - - - {0ec83e64-230e-48ef-b08c-6ac9651b4f82} - - - {f10cbc03-9809-4cba-95d8-327c287b18ee} - {2a1bc987-af42-4500-802d-89cd32fc1309} - - {52380daa-0f4a-4d97-8e57-98df39319caf} - diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index 0440d973..1d42d16e 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -4,16 +4,10 @@ #define NOMINMAX #include -//#define DANBIAS_SERVER -#define DANBIAS_CLIENT +#include "DanBiasServerAPI.h" +//#include "DanBiasGame.h" -#if defined(DANBIAS_SERVER) -#include "IDanBiasServer.h" -#elif defined(DANBIAS_CLIENT) -#include "DanBiasGame.h" -#endif - int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) { #if defined(DANBIAS_SERVER) @@ -21,14 +15,10 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh { return cmdShow; } - // Server starter code goes here - DanBias::DanBiasServerDesc desc; - desc.port = 0; - - if( DanBias::DanBiasServer::Initiate(desc) == DanBias::DanBiasServerReturn_Sucess) + if( DanBias::DanBiasServerAPI::Initiate() == DanBias::DanBiasServerReturn_Sucess) { - DanBias::DanBiasServer::Run(); - DanBias::DanBiasServer::Release(); + DanBias::DanBiasServerAPI::Run(); + DanBias::DanBiasServerAPI::Release(); } #elif defined(DANBIAS_CLIENT) if(SetDllDirectory(L"..\\DLL") == FALSE) diff --git a/Code/Game/DanBiasServer/DBServer.cpp b/Code/Game/DanBiasServer/DBServer.cpp deleted file mode 100644 index db81f4da..00000000 --- a/Code/Game/DanBiasServer/DBServer.cpp +++ /dev/null @@ -1,56 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// -#include -#include "DBServer.h" -//#include "GameLogic\?" -#include "Utilities.h" - -using namespace DanBias; - -DBServer::DBServer() - : initiated(0) - , running(0) - , released(0) -{ -} -DBServer::~DBServer() -{ - -} -DanBiasServerReturn DBServer::Create(const DanBias::DanBiasServerDesc& desc) -{ - this->initiated = true; - return DanBiasServerReturn_Sucess; -} -DanBiasServerReturn DBServer::Run() -{ - - if(this->running) - { - return DanBiasServerReturn_Error; - } - if(this->released) - { - return DanBiasServerReturn_Error; - } - if(!this->initiated) - { - return DanBiasServerReturn_Error; - } - this->running = true; - while (this->running) - { - MessageBox(0, L"What to do here...", L"TYPELESS", 0); - - this->running = false; - } - return DanBiasServerReturn_Sucess; -} -DanBiasServerReturn DBServer::Release() -{ - this->released = true; - return DanBiasServerReturn_Sucess; -} - - diff --git a/Code/Game/DanBiasServer/DBServer.h b/Code/Game/DanBiasServer/DBServer.h deleted file mode 100644 index 261e62d5..00000000 --- a/Code/Game/DanBiasServer/DBServer.h +++ /dev/null @@ -1,27 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// -#ifndef DANBIASSERVER_DBSERVER_H -#define DANBIASSERVER_DBSERVER_H - -#include "Include\IDanBiasServer.h" - -namespace DanBias -{ - class DBServer - { - public: - DBServer(); - ~DBServer(); - - DanBiasServerReturn Create(const DanBias::DanBiasServerDesc& desc); - DanBiasServerReturn Run(); - DanBiasServerReturn Release(); - - private: - bool initiated; - bool running; - bool released; - }; -}// End namspace DanBias -#endif // !DANBIASSERVER_DBSERVER_H diff --git a/Code/Game/DanBiasServer/DLLMain.cpp b/Code/Game/DanBiasServer/DLLMain.cpp index 93409304..b088d800 100644 --- a/Code/Game/DanBiasServer/DLLMain.cpp +++ b/Code/Game/DanBiasServer/DLLMain.cpp @@ -3,6 +3,6 @@ BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ) { - MessageBox(0, L"DanBiasServer Loaded", 0, 0); + return TRUE; } \ No newline at end of file diff --git a/Code/Game/DanBiasServer/DanBiasServer.vcxproj b/Code/Game/DanBiasServer/DanBiasServer.vcxproj index ba85aaa5..b919dade 100644 --- a/Code/Game/DanBiasServer/DanBiasServer.vcxproj +++ b/Code/Game/DanBiasServer/DanBiasServer.vcxproj @@ -73,28 +73,32 @@ $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\External\Include\;$(IncludePath) + $(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir);$(SolutionDir)..\External\Lib\WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) true $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\External\Include\;$(IncludePath) + $(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir);$(SolutionDir)..\External\Lib\WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) false $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\External\Include\;$(IncludePath) + $(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir);$(SolutionDir)..\External\Lib\WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) false $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\External\Include\;$(IncludePath) + $(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir);$(SolutionDir)..\External\Lib\WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) @@ -102,13 +106,15 @@ Level3 Disabled - DANBIAS_SERVER;DANBIAS_SERVER_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Misc\;$(SolutionDir)Game\ + DANBIAS_SERVER_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + Windows true GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -117,13 +123,15 @@ Level3 Disabled - DANBIAS_SERVER;DANBIAS_SERVER_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Misc\;$(SolutionDir)Game\ + DANBIAS_SERVER_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + Windows true GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -134,8 +142,9 @@ MaxSpeed true true - DANBIAS_SERVER;DANBIAS_SERVER_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Misc\;$(SolutionDir)Game\ + DANBIAS_SERVER_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + Windows @@ -143,6 +152,7 @@ true true GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;%(AdditionalDependencies) @@ -153,8 +163,9 @@ MaxSpeed true true - DANBIAS_SERVER;DANBIAS_SERVER_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(SolutionDir)Misc\;$(SolutionDir)Game\ + DANBIAS_SERVER_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + Windows @@ -162,18 +173,28 @@ true true GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;%(AdditionalDependencies) - + - + + + + + + - - - - + + + + + + + + diff --git a/Code/Game/DanBiasServer/GameServer.cpp b/Code/Game/DanBiasServer/GameServer.cpp new file mode 100644 index 00000000..104841cd --- /dev/null +++ b/Code/Game/DanBiasServer/GameServer.cpp @@ -0,0 +1,103 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include +#include + +#include "GameServer.h" +#include "Utilities.h" +#include "ServerInitReader.h" + +namespace DanBias +{ + using namespace Oyster::Network; + + //void GameServer::ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient) + //{ + // if( + //} + void GameServer::ClientConnectCallback(NetworkClient &client) + { + + } + GameServer::GameServer() + : initiated(0) + , running(0) + , released(0) + , maxClients(0) + , mainLobby(0) + , server(0) + { + } + GameServer::~GameServer() + { + + } + DanBiasServerReturn GameServer::Create() + { + this->server = new NetworkServer(); + this->mainLobby = new MainLobby(); + + InitData data; + if(!LoadIniFile(data)) return DanBiasServerReturn_Error; + + NetworkServer::INIT_DESC serverDesc; + serverDesc.port = data.port; + this->maxClients = data.clients; + serverDesc.callback = this; + + if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error; + if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error; + if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error; + + this->initiated = true; + return DanBiasServerReturn_Sucess; + } + DanBiasServerReturn GameServer::Run() + { + if(this->running) return DanBiasServerReturn_Error; + if(this->released) return DanBiasServerReturn_Error; + if(!this->initiated) return DanBiasServerReturn_Error; + + this->running = true; + while (this->running) + { + if(!WindowShell::Frame()) + break; + } + + return DanBiasServerReturn_Sucess; + } + DanBiasServerReturn GameServer::Release() + { + this->released = true; + return DanBiasServerReturn_Sucess; + } + + bool GameServer::LoadIniFile(InitData& ini) + { + std::ifstream in; + std::string f = GetInitPath(InitPath_ServerIni); + in.open(f, std::ios::in); + if(!in.is_open()) return false; + + std::string buffer; + while (!in.eof()) + { + in >> buffer; + + if(buffer == "port") + { + in >> ini.port; + } + else if(buffer == "clients") + { + in >> ini.clients; + } + + } + + in.close(); + return true; + } +}//End namespace DanBias diff --git a/Code/Game/DanBiasServer/GameServer.h b/Code/Game/DanBiasServer/GameServer.h new file mode 100644 index 00000000..b46891db --- /dev/null +++ b/Code/Game/DanBiasServer/GameServer.h @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#ifndef DANBIASSERVER_GAME_SERVER_H +#define DANBIASSERVER_GAME_SERVER_H + +#include + +#include "Include\DanBiasServerAPI.h" +#include "ServerObjects\Lobby\MainLobby.h" +#include +#include + +namespace DanBias +{ + class GameServer :public Oyster::Network::ClientConnectedObject + { + public: + GameServer(); + ~GameServer(); + + DanBiasServerReturn Create(); + DanBiasServerReturn Run(); + DanBiasServerReturn Release(); + + private: + //static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient); + void ClientConnectCallback(Oyster::Network::NetworkClient &client) override; + + bool initiated; + bool running; + bool released; + int maxClients; + MainLobby *mainLobby; + Oyster::Network::NetworkServer *server; + + private: + struct InitData + { + int port; + int clients; + }; + bool LoadIniFile(InitData&); + }; +}// End namspace DanBias +#endif // !DANBIASSERVER_DBSERVER_H diff --git a/Code/Game/DanBiasServer/IDanBiasServer.cpp b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.cpp similarity index 51% rename from Code/Game/DanBiasServer/IDanBiasServer.cpp rename to Code/Game/DanBiasServer/Include/DanBiasServerAPI.cpp index bf0b52de..e897a6dd 100644 --- a/Code/Game/DanBiasServer/IDanBiasServer.cpp +++ b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.cpp @@ -1,26 +1,26 @@ ///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// -#include "Include\IDanBiasServer.h" -#include "DBServer.h" +#include "DanBiasServerAPI.h" +#include "..\GameServer.h" namespace DanBias { #pragma region Server Data - static DBServer server; + static GameServer server; #pragma endregion - DanBiasServerReturn DanBiasServer::Initiate(DanBiasServerDesc& desc) + DanBiasServerReturn DanBiasServerAPI::Initiate() { - return server.Create(desc); + return server.Create(); } - DanBiasServerReturn DanBiasServer::Run() + DanBiasServerReturn DanBiasServerAPI::Run() { return server.Run(); } - DanBiasServerReturn DanBiasServer::Release() + DanBiasServerReturn DanBiasServerAPI::Release() { return server.Release(); } diff --git a/Code/Game/DanBiasServer/Include/IDanBiasServer.h b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.h similarity index 64% rename from Code/Game/DanBiasServer/Include/IDanBiasServer.h rename to Code/Game/DanBiasServer/Include/DanBiasServerAPI.h index 681ea348..acf0d5d6 100644 --- a/Code/Game/DanBiasServer/Include/IDanBiasServer.h +++ b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.h @@ -4,8 +4,9 @@ #ifndef DANBIAS_SERVER_DANBIAS_SERVER_H #define DANBIAS_SERVER_DANBIAS_SERVER_H +#define DANBIAS_SERVER -#if defined (DANBIAS_SERVER_DLL_EXPORT) +#ifdef DANBIAS_SERVER_DLL_EXPORT #define DANBIAS_SERVER_DLL __declspec(dllexport) #else #define DANBIAS_SERVER_DLL __declspec(dllimport) @@ -13,28 +14,21 @@ namespace DanBias { + enum DanBiasServerReturn + { + DanBiasServerReturn_Error, + DanBiasServerReturn_Sucess, + }; + extern "C" { - enum DanBiasServerReturn - { - DanBiasServerReturn_Error, - DanBiasServerReturn_Sucess, - }; - - struct DanBiasServerDesc - { - //Stuff goes here... - int port; - }; - - class DANBIAS_SERVER_DLL DanBiasServer + class DANBIAS_SERVER_DLL DanBiasServerAPI { public: - static DanBiasServerReturn Initiate(DanBiasServerDesc& desc); + static DanBiasServerReturn Initiate(); static DanBiasServerReturn Run(); static DanBiasServerReturn Release(); - }; - + };//End class DanBiasServer }//End Extern "C" } //End namspace DanBias diff --git a/Code/Game/DanBiasServer/Include/ServerWrapper.h b/Code/Game/DanBiasServer/Include/ServerWrapper.h deleted file mode 100644 index 29829c17..00000000 --- a/Code/Game/DanBiasServer/Include/ServerWrapper.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef NETWORK_SERVER_WRAPPER_H -#define NETWORK_SERVER_WRAPPER_H - - -class SingletonServer -{ -public: - - struct INIT_DESC - { - bool l; - }; - void CreateServer(/*DATA*/); - void StartServer(/*DATA*/); - void StopServer(/*DATA*/); - void TerminateServer(/*DATA*/); - - void AttachLobby(/*LOBBY*/); - void DetachLobby(/*LOBBY*/); - void KickClient(/*CLIENT*/); -}; - -#endif // !NETWORK_SERVER_WRAPPER_H diff --git a/Code/Game/DanBiasServer/MainLobby.h b/Code/Game/DanBiasServer/MainLobby.h deleted file mode 100644 index 5807ab9c..00000000 --- a/Code/Game/DanBiasServer/MainLobby.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DANBIASGAME_GAMELOBBY_H -#define DANBIASGAME_GAMELOBBY_H - -#include "Include\ServerWrapper.h" - -class MainLobby :public SingletonServer -{ -public: - MainLobby(); - ~MainLobby(); - -private: - - -}; - -#endif // !DANBIASGAME_GAMELOBBY_H diff --git a/Code/Game/DanBiasServer/ServerInitReader.h b/Code/Game/DanBiasServer/ServerInitReader.h new file mode 100644 index 00000000..cf7cc4c7 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerInitReader.h @@ -0,0 +1,41 @@ +#ifndef DANBIASSERVER_SERVER_INIT_READER_H +#define DANBIASSERVER_SERVER_INIT_READER_H + +#include +#include + +namespace DanBias +{ + enum InitPath + { + InitPath_ServerIni, + }; + std::string GetInitPath(InitPath file) + { + std::string type = ""; + std::string path = ""; + std::string flag = ""; + + switch (file) + { + case DanBias::InitPath_ServerIni: + flag = "ServerInit"; + break; + } + + std::fstream in; + in.open("..\\Settings\\serversearchpath.ini", std::ios::in); + if(!in.is_open()) return ""; + + while (!in.eof() && type != flag) + { + in >> type; + in >> path; + } + + in.close(); + return path; + } +} + +#endif // !DANBIASSERVER_SERVER_INIT_READER_H diff --git a/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp b/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp new file mode 100644 index 00000000..acad56d3 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp @@ -0,0 +1,12 @@ +#include "ClientObject.h" + +using namespace DanBias; + +ClientObject::ClientObject() +{ +} +ClientObject::~ClientObject() +{ +} + + diff --git a/Code/Game/DanBiasServer/ServerObjects/ClientObject.h b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h new file mode 100644 index 00000000..55acdf6f --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h @@ -0,0 +1,19 @@ +#ifndef DANBIASSERVER_CLIENT_OBJECT_H +#define DANBIASSERVER_CLIENT_OBJECT_H + +#include "NetworkClient.h" + +namespace DanBias +{ + class ClientObject + { + public: + ClientObject(); + ~ClientObject(); + + private: + + }; + +}//End namespace DanBias +#endif // !DANBIASSERVER_CLIENT_OBJECT_H diff --git a/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp new file mode 100644 index 00000000..fced4e45 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp @@ -0,0 +1,9 @@ + + + + +namespace DanBias +{ + + +}//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/DanBiasServer/ServerObjects/GameSession.h b/Code/Game/DanBiasServer/ServerObjects/GameSession.h new file mode 100644 index 00000000..26ad5ec2 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/GameSession.h @@ -0,0 +1,19 @@ +#ifndef DANBIASSERVER_GAME_SESSION_H +#define DANBIASSERVER_GAME_SESSION_H + +#include "NetworkSession.h" + +namespace DanBias +{ + class GameSession :public NetworkSession + { + public: + GameSession(); + ~GameSession(); + + private: + + + };//End GameSession +}//End namespace DanBias +#endif // !DANBIASSERVER_GAME_SESSION_H \ No newline at end of file diff --git a/Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.cpp b/Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.cpp new file mode 100644 index 00000000..06efcb96 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.cpp @@ -0,0 +1,18 @@ +#include "GameLobby.h" + + +namespace DanBias +{ + GameLobby::GameLobby() + { + + } + GameLobby::~GameLobby() + { + + } + void GameLobby::Release() + { + + } +}//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.h b/Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.h new file mode 100644 index 00000000..b28d9b31 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.h @@ -0,0 +1,21 @@ +#ifndef DANBIASSERVER_GAME_LOBBY_H +#define DANBIASSERVER_GAME_LOBBY_H + +#include "..\NetworkSession.h" + +namespace DanBias +{ + class GameLobby :public NetworkSession + { + public: + GameLobby(); + ~GameLobby(); + void Release(); + + private: + + + }; +}//End namespace DanBias + +#endif // !DANBIASSERVER_GAME_LOBBY_H \ No newline at end of file diff --git a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp new file mode 100644 index 00000000..d518a0c7 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp @@ -0,0 +1,18 @@ +#include "MainLobby.h" + + +namespace DanBias +{ + MainLobby::MainLobby() + { + + } + MainLobby::~MainLobby() + { + + } + void MainLobby::Release() + { + + } +}//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h new file mode 100644 index 00000000..456eee9d --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h @@ -0,0 +1,22 @@ +#ifndef DANBIASGAME_GAMELOBBY_H +#define DANBIASGAME_GAMELOBBY_H + +#include "..\NetworkSession.h" +#include +#include + +namespace DanBias +{ + class MainLobby :public NetworkSession + { + public: + MainLobby(); + ~MainLobby(); + void Release(); + + private: + + + }; +}//End namespace DanBias +#endif // !DANBIASGAME_GAMELOBBY_H diff --git a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp new file mode 100644 index 00000000..569b8a0a --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp @@ -0,0 +1,36 @@ +#include "NetworkSession.h" + + +namespace DanBias +{ + NetworkSession::NetworkSession() + { + } + NetworkSession::~NetworkSession() + { + } + + void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer client) + { + } + void NetworkSession::DetachClient(Utility::DynamicMemory::SmartPointer client) + { + } + void NetworkSession::DetachClient(short ID) + { + + } + + void NetworkSession::Kick(Utility::DynamicMemory::SmartPointer client) + { + } + void NetworkSession::Kick() + { + + } + + Oyster::Network::NetworkClient* NetworkSession::operator[](int Identification) + { + return 0; + } +}//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h new file mode 100644 index 00000000..6653c297 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h @@ -0,0 +1,37 @@ +#ifndef DANBIASSERVER_NETWORK_SESSION_H +#define DANBIASSERVER_NETWORK_SESSION_H + +#include "Utilities.h" +#include "ClientObject.h" +#include +#include + +namespace DanBias +{ + class NetworkSession + { + public: + NetworkSession(); + ~NetworkSession(); + + void AttachClient(Utility::DynamicMemory::SmartPointer client); + + void DetachClient(Utility::DynamicMemory::SmartPointer client); + void DetachClient(short ID); + + void Kick(Utility::DynamicMemory::SmartPointer client); + void Kick(); + + void Send(Network::CustomNetProtocol& protocol); + void Send(Network::CustomNetProtocol& protocol, int ID); + + //TODO: Do more lobby features + + protected: + Oyster::Network::NetworkClient* operator[](int Identification); + + private: + std::vector> clients; + }; +}//End namespace DanBias +#endif // !DANBIASSERVER_NETWORK_SESSION_H diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index b091ba34..c579d701 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -1,7 +1,12 @@ +////////////////////////////////////////////////////////// +// Created 2013 // +// Dennis Andersen, Linda Andersson // +////////////////////////////////////////////////////////// + #ifndef GAMELOGIC_PLAYER_PROTOCOLS_H #define GAMELOGIC_PLAYER_PROTOCOLS_H -#include "CustomNetProtocol.h" +#include #include "ProtocolIdentificationID.h" @@ -20,24 +25,24 @@ namespace GameLogic Protocol_PlayerMovement() { - protocol[0]->value = ProtocolID = protocol_PlayerNavigation; + this->protocol[0].value = ProtocolID = protocol_PlayerNavigation; - protocol[0]->type = Network::NetAttributeType_Int; - protocol[1]->type = Network::NetAttributeType_Bool; - protocol[2]->type = Network::NetAttributeType_Bool; - protocol[3]->type = Network::NetAttributeType_Bool; - protocol[4]->type = Network::NetAttributeType_Bool; - protocol[5]->type = Network::NetAttributeType_Bool; - protocol[6]->type = Network::NetAttributeType_Bool; + this->protocol[0].type = Network::NetAttributeType_Int; + this->protocol[1].type = Network::NetAttributeType_Bool; + this->protocol[2].type = Network::NetAttributeType_Bool; + this->protocol[3].type = Network::NetAttributeType_Bool; + this->protocol[4].type = Network::NetAttributeType_Bool; + this->protocol[5].type = Network::NetAttributeType_Bool; + this->protocol[6].type = Network::NetAttributeType_Bool; } Network::CustomNetProtocol* GetProtocol() override { - protocol[1]->value = bForward; - protocol[2]->value = bBackward; - protocol[3]->value = bTurnLeft; - protocol[4]->value = bTurnRight; - protocol[5]->value = bStrafeRight; - protocol[6]->value = bStrafeRight; + this->protocol[1].value = bForward; + this->protocol[2].value = bBackward; + this->protocol[3].value = bTurnLeft; + this->protocol[4].value = bTurnRight; + this->protocol[5].value = bStrafeRight; + this->protocol[6].value = bStrafeRight; return &protocol; } diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 1af8c920..5890e9ff 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -3,6 +3,6 @@ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -#define protocol_PlayerNavigation 0; +#define protocol_PlayerNavigation 0 #endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H diff --git a/Code/WindowManager/WindowShell.cpp b/Code/WindowManager/WindowShell.cpp index 7f8e1481..b82a58f6 100644 --- a/Code/WindowManager/WindowShell.cpp +++ b/Code/WindowManager/WindowShell.cpp @@ -1,87 +1,87 @@ #include "WindowShell.h" #include +// debug window include +#include +#include +#include -struct ChildWin; -struct _PrSt; #pragma region Declarations - namespace - { - //Private data - static WindowShell* instance = NULL; - int childIdCounter = 0; - _PrSt *pData = NULL; - } - - struct ChildWin - { - int id; - HWND hWnd; - - ChildWin() - { - hWnd = NULL; - childIdCounter++; - id = childIdCounter; - } - int ID() const { return id; } - }; - struct _PrSt + struct _PrivateDataContainer { HINSTANCE hIns; HWND hWnd; - std::vector childWindows; + HWND parent; + bool consoleWindow; + WNDPROC callback; + const wchar_t* windowClassName; + _PrivateDataContainer() + : hIns(0) + , hWnd(0) + , parent(0) + , consoleWindow(0) + { } + ~_PrivateDataContainer() { if(this->consoleWindow) FreeConsole(); } - _PrSt() - { - hIns = NULL; - hWnd = NULL; - } - }; + } __windowShellData; #pragma endregion - - -WindowShell::WindowShell() +LRESULT CALLBACK DefaultWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l) { - pData = new _PrSt(); -} -WindowShell::~WindowShell() -{ - delete pData; + PAINTSTRUCT ps; + HDC hdc; + + switch (m) + { + case WM_PAINT: + hdc = BeginPaint(h, &ps); + EndPaint(h, &ps); + break; + + case WM_DESTROY: + PostQuitMessage(0); + break; + + case WM_KEYDOWN: + switch(w) + { + case VK_ESCAPE: + PostQuitMessage(0); + break; + } + break; + } + + return DefWindowProc(h, m, w, l); } - - -bool WindowShell::createWin(WINDOW_INIT_DESC &desc) +HINSTANCE WindowShell::GetHINSTANCE() { - if(pData->hWnd) - { - MessageBox(0, L"There is already a window registered\nPlease use child windows to create more windows!" ,L"Error", 0); - return false; - } - if(!desc.windowProcCallback) - { - MessageBox(0, L"No callback function for window messages was found!" ,L"Error", 0); - return false; - } - if(desc.windowSize.x < 0 || desc.windowSize.y < 0) - { - MessageBox(0, L"Size specified for window is invalid!" ,L"Error", 0); - return false; - } - - if(!desc.hInstance) - { - desc.hInstance = GetModuleHandle(0); - } - - - pData->hIns = desc.hInstance; + return __windowShellData.hIns; +} +HWND WindowShell::GetHWND() +{ + return __windowShellData.hWnd; +} +HWND WindowShell::GetParent() +{ + return __windowShellData.parent; +} +bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc) +{ + if(__windowShellData.hWnd) return false; + if(!desc.windowProcCallback) desc.windowProcCallback = DefaultWindowCallback; + if(!desc.hInstance) desc.hInstance = GetModuleHandle(0); + if(desc.windowSize.x <= 0) desc.windowSize.x = 50; + if(desc.windowSize.y <= 0) desc.windowSize.y = 50; + + __windowShellData.parent = desc.parent; + __windowShellData.hIns = desc.hInstance; + __windowShellData.windowClassName = L"MainWindowShellClassName"; #pragma region Register @@ -92,12 +92,12 @@ bool WindowShell::createWin(WINDOW_INIT_DESC &desc) wc.lpfnWndProc = desc.windowProcCallback; wc.cbClsExtra = 0; wc.cbWndExtra = 0; - wc.hInstance = pData->hIns; - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszMenuName = 0; - wc.lpszClassName = L"MainWindowClass"; + wc.hInstance = __windowShellData.hIns; + wc.hIcon = desc.icon; + wc.hCursor = desc.cursor; + wc.hbrBackground = desc.background; + wc.lpszMenuName = NULL; + wc.lpszClassName = __windowShellData.windowClassName; if( !RegisterClassEx(&wc) ) { @@ -110,168 +110,131 @@ bool WindowShell::createWin(WINDOW_INIT_DESC &desc) #pragma region Create window - pData->hWnd = CreateWindow( - L"MainWindowClass" , - desc.windowName.c_str(), - desc.windowStyle, - desc.windowPosition.x, - desc.windowPosition.y, - desc.windowSize.x, - desc.windowSize.y, - 0, - 0, - pData->hIns, - 0 - ); + RECT rectW; + int width; + int height; + DWORD style = desc.windowStyle; + bool windowed = false; + + width = desc.windowSize.x + GetSystemMetrics(SM_CXFIXEDFRAME)*2; + height = desc.windowSize.y + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION); + + rectW.left=(GetSystemMetrics(SM_CXSCREEN)-width)/2; + rectW.top=(GetSystemMetrics(SM_CYSCREEN)-height)/2; + rectW.right=rectW.left+width; + rectW.bottom=rectW.top+height; - if( !pData->hWnd ) + + if(__windowShellData.parent) { - MessageBox(0, L"Failed to create window", L"Error!", 0); + rectW.left = 0; + rectW.top = 0; + rectW.right = desc.windowSize.x; + rectW.bottom = desc.windowSize.y; + style = WS_CHILD | WS_VISIBLE; + windowed = true; + } + + if(windowed) + { + __windowShellData.hWnd = CreateWindowEx( + 0, + __windowShellData.windowClassName , + desc.windowName, + style, + rectW.left, + rectW.top, + rectW.right - rectW.left, + rectW.bottom - rectW.top, + __windowShellData.parent, + NULL, + __windowShellData.hIns, + NULL + ); + } + else + { + __windowShellData.hWnd = CreateWindowEx( + 0, + __windowShellData.windowClassName , + desc.windowName, + style, + desc.windowPosition.x, + desc.windowPosition.y, + desc.windowSize.x, + desc.windowSize.y, + 0, + 0, + __windowShellData.hIns, + 0 + ); + } + + if( !__windowShellData.hWnd ) + { + printf("Failed to create window handle : Code ( %ul )", GetLastError()); + //MessageBox(0, L"Failed to create window", L"Error!", 0); return false; } #pragma endregion - + //Show and update window - ShowWindow(pData->hWnd, SW_SHOW); - UpdateWindow(pData->hWnd); + ShowWindow(__windowShellData.hWnd, SW_SHOW); + UpdateWindow(__windowShellData.hWnd); return true; } -int WindowShell::createChildWin(CHILD_WINDOW_INIT_DESC &desc) +bool WindowShell::CreateConsoleWindow(bool redirectStdOut, const wchar_t* title) { - ChildWin win; + // allocate a console for this app + if(AllocConsole() == FALSE) return false; - - char idStr[3]; - _itoa_s(win.id, idStr, 10); - std::string next = idStr; - std::wstring str = std::wstring(next.begin(), next.end()); - std::wstring childClassName = L"ChildWindow_"; - childClassName += str; - - WNDCLASSEX wcex; - wcex.cbSize = sizeof(WNDCLASSEX); - wcex.style = CS_VREDRAW; - wcex.lpfnWndProc = desc.windowProcCallback; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = pData->hIns; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(0, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = childClassName.c_str(); - wcex.hIconSm = NULL; - - if(!RegisterClassEx(&wcex)) + if(redirectStdOut) { - MessageBox(0, L"", 0, 0); - } - - if(!desc.style) - desc.style = WS_EX_CLIENTEDGE; - - win.hWnd = CreateWindowEx - ( - desc.style, - childClassName.c_str(), - desc.name.c_str(), - WS_CAPTION | WS_SYSMENU , - desc.topLeftPos.x, desc.topLeftPos.y, - desc.windowSize.x, desc.windowSize.y, - pData->hWnd, - NULL, - pData->hIns, - NULL - ); - - - if (win.hWnd) - { - pData->childWindows.push_back(win); - ShowWindow(win.hWnd, 5); - UpdateWindow(win.hWnd); - } - else - { - DWORD err = GetLastError(); - MessageBox(0, L"Failed to create child window", L"Error!", MB_OK); - return false; - } - - return win.id; -} -bool WindowShell::removeChild(int id) -{ - for (int i = 0; i < (int)pData->childWindows.size(); i++) - { - if(id == pData->childWindows[i].id) + // redirect unbuffered STDOUT to the console + HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT); + FILE *fp = _fdopen( fileDescriptor, "w" ); + *stdout = *fp; + setvbuf( stdout, NULL, _IONBF, 0 ); + + + // give the console window a bigger buffer size + CONSOLE_SCREEN_BUFFER_INFO csbi; + if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) ) { - pData->childWindows.erase(pData->childWindows.begin() + i); - return true; + COORD bufferSize; + bufferSize.X = csbi.dwSize.X; + bufferSize.Y = 50; + SetConsoleScreenBufferSize(consoleHandle, bufferSize); } } - return false; + // give the console window a nicer title + SetConsoleTitle(title); + + return true; } -bool WindowShell::removeChild(HWND hwnd) +bool WindowShell::Frame() { - for (int i = 0; i < (int)pData->childWindows.size(); i++) + MSG msg = {0}; + while (true) { - if(hwnd == pData->childWindows[i].hWnd) + if(!__windowShellData.parent) { - pData->childWindows.erase(pData->childWindows.begin() + i); - return true; + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + if (msg.message == WM_QUIT) return false; + + DispatchMessage(&msg); + continue; + } } + + break; } - return false; + return true; } - - - -const HINSTANCE WindowShell::getHINSTANCE() const -{ - return pData->hIns; -} -const HWND WindowShell::getHWND() const -{ - return pData->hWnd; -} -const HWND WindowShell::getChildHWND(int id) const -{ - for(int i = 0; i<(int)pData->childWindows.size(); i++) - { - if(id == pData->childWindows[i].id) - return pData->childWindows[i].hWnd; - } - - return NULL; -} -const int WindowShell::getChildID(HWND hwnd) const -{ - for(int i = 0; i<(int)pData->childWindows.size(); i++) - { - if(hwnd == pData->childWindows[i].hWnd) - return pData->childWindows[i].id; - } - - return -1; -} - - - -WindowShell* WindowShell::self() -{ - if(!instance) - instance = new WindowShell(); - - return instance; -} -void WindowShell::destroy() -{ - delete instance; - instance = NULL; -} \ No newline at end of file diff --git a/Code/WindowManager/WindowShell.h b/Code/WindowManager/WindowShell.h index d29a3666..5adb95d4 100644 --- a/Code/WindowManager/WindowShell.h +++ b/Code/WindowManager/WindowShell.h @@ -1,85 +1,62 @@ -#ifndef GLARE_WINDOW_H -#define GLARE_WINDOW_H +////////////////////////////////////////////////////////// +// Created 2013 // +// Dennis Andersen, Linda Andersson // +////////////////////////////////////////////////////////// +#ifndef WINDOWMANAGER_WINDOWSHELL_H +#define WINDOWMANAGER_WINDOWSHELL_H #include -#include class WindowShell { - public: - struct WINDOW_INIT_DESC +public: + struct WINDOW_INIT_DESC + { + HWND parent; //!< Optional + HINSTANCE hInstance; //!< Optional + WNDPROC windowProcCallback; //!< Optional + + const wchar_t* windowName; //!< Optional + POINT windowSize; //!< Optional + POINT windowPosition; //!< Optional + + UINT windowClassStyle; //!< Optional + UINT windowStyle; //!< Optional + + HICON icon; //!< Optional + HCURSOR cursor; //!< Optional + HBRUSH background; //!< Optional + + WINDOW_INIT_DESC() { - HINSTANCE hInstance; - std::wstring windowName; - POINT windowSize; - POINT windowPosition; - WNDPROC windowProcCallback; - UINT windowClassStyle; - UINT windowStyle; - - WINDOW_INIT_DESC() - { - hInstance = NULL; - windowName = L"MADAFACKA"; - windowSize.x = 800; - windowSize.y = 600; - windowPosition.x = 0; - windowPosition.y = 0; - windowProcCallback = NULL; - windowClassStyle = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - windowStyle = WS_OVERLAPPEDWINDOW; - } - }; - struct CHILD_WINDOW_INIT_DESC - { - std::wstring name; - DWORD style; - POINT topLeftPos; - POINT windowSize; - WNDPROC windowProcCallback; + parent = 0; + hInstance = NULL; + windowName = L"MADAFACKA"; + windowSize.x = 800; + windowSize.y = 600; + windowPosition.x = 0; + windowPosition.y = 0; + windowProcCallback = NULL; + windowClassStyle = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + windowStyle = WS_POPUPWINDOW|WS_SYSMENU|WS_CAPTION; + //windowStyle = WS_OVERLAPPEDWINDOW; + icon = LoadIcon(0, IDI_APPLICATION); + cursor = LoadCursor(NULL, IDC_ARROW); + background = (HBRUSH)GetStockObject(BLACK_BRUSH); + //background = (HBRUSH)GetStockObject(BACKGROUND_BLUE);(HBRUSH)(COLOR_WINDOW+1); + } + }; - CHILD_WINDOW_INIT_DESC() - { - name = L"Child Window"; - style = WS_CHILD; - memset(&topLeftPos, 0, sizeof(POINT)); - windowSize.x = 300; - windowSize.y = 200; - windowProcCallback = NULL; - } - }; +public: + static HINSTANCE GetHINSTANCE (); + static HWND GetHWND (); + static HWND GetParent (); + static bool CreateWin (WINDOW_INIT_DESC&); + static bool CreateConsoleWindow (bool redirectStdOut = true, const wchar_t* title = L"Debug Output"); - - private: - WindowShell (); - WindowShell (const WindowShell&); - void operator= (const WindowShell&); - virtual~WindowShell (); - - public: - const HINSTANCE getHINSTANCE () const; - /* Returns NULL if no hwnd exists */ - const HWND getHWND () const; - /* Returns NULL if not found */ - const HWND getChildHWND (int id) const; - /* Returns -1 if not found */ - const int getChildID (HWND hwnd) const; - - /* Creates an empty window */ - bool createWin (WINDOW_INIT_DESC&); - /*Creates a child window and returns the id of child window or -1 if failed*/ - int createChildWin (CHILD_WINDOW_INIT_DESC&); - /* Removes a child window */ - bool removeChild (int id); - /* Removes a child window */ - bool removeChild (HWND hwnd); - - - /* Returns a pointer to this class, dont forget to destroy on exit */ - static WindowShell* self(); - /* Deletes the instance */ - static void destroy(); + /** Procces window messages if avalible. If the return value was false, the window was destroyed. */ + static bool Frame (); }; #endif \ No newline at end of file