diff --git a/Bin/Content/Shaders/DebugVertex.cso b/Bin/Content/Shaders/DebugVertex.cso new file mode 100644 index 00000000..4783f8a6 Binary files /dev/null and b/Bin/Content/Shaders/DebugVertex.cso differ diff --git a/Bin/Content/Shaders/TextureDebug.cso b/Bin/Content/Shaders/TextureDebug.cso new file mode 100644 index 00000000..6a324d8d Binary files /dev/null and b/Bin/Content/Shaders/TextureDebug.cso differ diff --git a/Bin/DLL/DanBiasServer_x64.pdb b/Bin/DLL/DanBiasServer_x64.pdb new file mode 100644 index 00000000..4a457347 Binary files /dev/null and b/Bin/DLL/DanBiasServer_x64.pdb differ diff --git a/Bin/DLL/NetworkAPI_x64.pdb b/Bin/DLL/NetworkAPI_x64.pdb new file mode 100644 index 00000000..2aa321fb Binary files /dev/null and b/Bin/DLL/NetworkAPI_x64.pdb differ diff --git a/Bin/DLL/NetworkAPI_x64D.pdb b/Bin/DLL/NetworkAPI_x64D.pdb new file mode 100644 index 00000000..39a6662a Binary files /dev/null and b/Bin/DLL/NetworkAPI_x64D.pdb differ diff --git a/Bin/DLL/NetworkAPI_x86.pdb b/Bin/DLL/NetworkAPI_x86.pdb new file mode 100644 index 00000000..aacce35f Binary files /dev/null and b/Bin/DLL/NetworkAPI_x86.pdb differ diff --git a/Bin/DLL/NetworkAPI_x86D.pdb b/Bin/DLL/NetworkAPI_x86D.pdb new file mode 100644 index 00000000..6173afe2 Binary files /dev/null and b/Bin/DLL/NetworkAPI_x86D.pdb differ 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..315bd416 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -57,6 +57,7 @@ Global {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.Build.0 = Release|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.ActiveCfg = Debug|Win32 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.Build.0 = Debug|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.ActiveCfg = Debug|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.Build.0 = Debug|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -68,6 +69,7 @@ Global {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.Build.0 = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.ActiveCfg = Debug|Win32 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.Build.0 = Debug|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.ActiveCfg = Debug|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.Build.0 = Debug|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -79,6 +81,7 @@ Global {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.Build.0 = Release|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Win32.ActiveCfg = Debug|Win32 + {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Win32.Build.0 = Debug|Win32 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|x64.ActiveCfg = Debug|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|x64.Build.0 = Debug|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -90,6 +93,7 @@ Global {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.Build.0 = Release|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Win32.ActiveCfg = Debug|Win32 + {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Win32.Build.0 = Debug|Win32 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|x64.ActiveCfg = Debug|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|x64.Build.0 = Debug|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -101,6 +105,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 @@ -124,6 +129,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 @@ -135,6 +141,7 @@ Global {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.Build.0 = Release|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Win32.ActiveCfg = Debug|Win32 + {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Win32.Build.0 = Debug|Win32 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|x64.ActiveCfg = Debug|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|x64.Build.0 = Debug|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -146,6 +153,7 @@ Global {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.Build.0 = Release|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Win32.ActiveCfg = Debug|Win32 + {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Win32.Build.0 = Debug|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|x64.ActiveCfg = Debug|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|x64.Build.0 = Debug|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -157,6 +165,7 @@ Global {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.ActiveCfg = Debug|Win32 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.Build.0 = Debug|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.ActiveCfg = Debug|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.Build.0 = Debug|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -168,6 +177,7 @@ Global {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.ActiveCfg = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.Build.0 = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.ActiveCfg = Debug|Win32 + {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.Build.0 = Debug|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.ActiveCfg = Debug|x64 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.Build.0 = Debug|x64 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Mixed Platforms.ActiveCfg = Release|Win32 @@ -178,6 +188,7 @@ Global {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|x64.Build.0 = Release|x64 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Mixed Platforms.ActiveCfg = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Win32.ActiveCfg = Debug|Win32 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Win32.Build.0 = Debug|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|x64.ActiveCfg = Debug|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Mixed Platforms.ActiveCfg = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Win32.ActiveCfg = Release|Win32 @@ -196,6 +207,7 @@ Global {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Win32.ActiveCfg = Debug|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Win32.Build.0 = Debug|Win32 {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.ActiveCfg = Debug|x64 {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.Build.0 = Debug|x64 {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.ActiveCfg = Release|Win32 @@ -207,6 +219,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 @@ -218,6 +231,7 @@ Global {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Win32.ActiveCfg = Debug|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Win32.Build.0 = Debug|Win32 {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|x64.ActiveCfg = Debug|x64 {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|x64.Build.0 = Debug|x64 {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Mixed Platforms.ActiveCfg = Release|Win32 @@ -229,6 +243,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 +255,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/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 1784ca35..c4ad8f96 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -72,7 +72,7 @@ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) - $(SolutionDir)..\External\Include\;$(IncludePath) + $(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath) true @@ -104,15 +104,15 @@ Level3 Disabled - DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;%(AdditionalIncludeDirectories) Windows true OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) - OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -121,14 +121,14 @@ Level3 Disabled - DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) Windows true - OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + GameProtocols_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -140,16 +140,16 @@ MaxSpeed true true - DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) Windows true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) + GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) OysterGraphics_x86.dll;%(DelayLoadDLLs) @@ -161,16 +161,16 @@ MaxSpeed true true - DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) Windows true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) + GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) OysterGraphics_x86.dll;%(DelayLoadDLLs) @@ -181,6 +181,9 @@ {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + {460d625f-2ac9-4559-b809-0ba89ceaedf4} + {0ec83e64-230e-48ef-b08c-6ac9651b4f82} diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 535256f9..1729708d 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -5,6 +5,10 @@ #include "GameClientState/GameClientState.h" #include "GameClientState\GameState.h" #include "GameClientState\LobbyState.h" +#include "PlayerProtocols.h" +#include "NetworkClient.h" + +#include "L_inputClass.h" #include "vld.h" namespace DanBias @@ -12,11 +16,57 @@ namespace DanBias __int64 DanBiasGame::cntsPerSec = 0; __int64 DanBiasGame::prevTimeStamp = 0; float DanBiasGame::secsPerCnt = 0; - InputClass* DanBiasGame::inputObj = NULL; HINSTANCE DanBiasGame::g_hInst = NULL; HWND DanBiasGame::g_hWnd = NULL; #pragma region Game Data + + + struct MyRecieverObject :public Oyster::Network::ProtocolRecieverObject + { + Oyster::Network::NetworkClient* nwClient; + Client::GameClientState* gameClientState; + + void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& p) override + { + + int pType = p[0].value.netInt; + Client::GameClientState::ProtocolStruct* protocol; + switch (pType) + { + case protocol_PlayerNavigation: + + break; + case protocol_PlayerPosition: + protocol = new Client::GameClientState::PlayerPos; + for(int i = 0; i< 3; i++) + { + ((Client::GameClientState::PlayerPos*)protocol)->playerPos[i] = p[i].value.netFloat; + } + gameClientState->Protocol(protocol); + delete protocol; + protocol = NULL; + break; + + + case protocol_ObjectPosition: + protocol = new Client::GameClientState::ObjPos; + for(int i = 0; i< 16; i++) + { + ((Client::GameClientState::ObjPos*)protocol)->worldPos[i] = p[i].value.netFloat; + } + gameClientState->Protocol(protocol); + delete protocol; + protocol = NULL; + break; + + default: + break; + } + + + } + }; class DanBiasGamePrivateData { @@ -30,12 +80,15 @@ namespace DanBias } - public: - Client::GameClientState* gameClientState; - // gameClient; + public: + Client::GameClientState* gameClientState; + InputClass* inputObj; + MyRecieverObject* r; } data; #pragma endregion + + DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData(); //-------------------------------------------------------------------------------------- @@ -63,6 +116,9 @@ namespace DanBias // Start in lobby state m_data->gameClientState = new Client::LobbyState(); m_data->gameClientState->Init(); + m_data->r = new MyRecieverObject; + m_data->r->nwClient = new Oyster::Network::NetworkClient(); + return DanBiasClientReturn_Sucess; } @@ -163,8 +219,8 @@ namespace DanBias //------------------------------------------------------------------------------------- HRESULT DanBiasGame::InitInput() { - inputObj = new InputClass; - if(!inputObj->Initialize(g_hInst, g_hWnd, 1024, 768)) + m_data->inputObj = new InputClass; + if(!m_data->inputObj->Initialize(g_hInst, g_hWnd, 1024, 768)) { MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK); return E_FAIL; @@ -174,10 +230,10 @@ namespace DanBias HRESULT DanBiasGame::Update(float deltaTime) { - inputObj->Update(); + m_data->inputObj->Update(); DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same; - state = m_data->gameClientState->Update(deltaTime, inputObj); + state = m_data->gameClientState->Update(deltaTime, m_data->inputObj); if(state != Client::GameClientState::ClientState_Same) { @@ -206,7 +262,7 @@ namespace DanBias HRESULT DanBiasGame::Render(float deltaTime) { int isPressed = 0; - if(inputObj->IsKeyPressed(DIK_A)) + if(m_data->inputObj->IsKeyPressed(DIK_A)) { isPressed = 1; } @@ -224,8 +280,9 @@ namespace DanBias { m_data->gameClientState->Release(); delete m_data->gameClientState; + delete m_data->inputObj; delete m_data; - delete inputObj; + Oyster::Graphics::API::Clean(); return S_OK; diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.h b/Code/Game/DanBiasGame/GameClientState/GameClientState.h index 5277996d..4e0d723b 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameClientState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.h @@ -12,6 +12,26 @@ namespace Client class GameClientState { public: + struct ProtocolStruct + { + + }; + struct ObjPos :public ProtocolStruct + { + float worldPos[16]; + }; + struct PlayerPos :public ProtocolStruct + { + float playerPos[3]; + }; + struct PlayerMove :public ProtocolStruct + { + float playerPos[3]; + }; + struct PlayerName :public ProtocolStruct + { + char name[255]; + }; enum ClientState { ClientState_Lobby, @@ -26,6 +46,8 @@ public: virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0; virtual bool Render() = 0; virtual bool Release() = 0; + virtual void Protocol(ProtocolStruct* protocolStruct) = 0; + }; }; }; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index fb81e23a..64b1babb 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -2,6 +2,8 @@ #include "DllInterfaces/GFXAPI.h" #include "Obj/C_Player.h" #include "Obj/C_DynamicObj.h" +#include "NetworkClient.h" +#include "PlayerProtocols.h" using namespace DanBias::Client; @@ -12,7 +14,9 @@ struct GameState::myData Oyster::Math3D::Float4x4 proj; C_Object* object[3]; int modelCount; + Oyster::Network::NetworkClient* nwClient; gameStateState state; + }privData; GameState::GameState(void) @@ -32,7 +36,7 @@ bool GameState::Init() privData->state = LoadGame(); return true; } -GameState::gameStateState GameState::LoadGame() +GameState::gameStateState GameState::LoadGame() { LoadModels(L"map"); InitCamera(Oyster::Math::Float3(0,0,5.4f)); @@ -86,8 +90,15 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI case gameStateState_playing: // read server data // update objects + // Client.send(obj); + { + GameLogic::Protocol_PlayerMovement movePlayer; + + //privData->nwClient->Send(movePlayer); + if(KeyInput->IsKeyPressed(DIK_L)) privData->state = GameState::gameStateState_end; + } break; case gameStateState_end: return ClientState_Lobby; @@ -123,4 +134,21 @@ bool GameState::Release() delete privData; privData = NULL; return true; -} \ No newline at end of file +} + +void GameState::Protocol(ProtocolStruct* pos) +{ + if((ObjPos*)pos) + ObjectPosProtocol((ObjPos*)pos); + else if((PlayerPos*)pos) + PlayerPosProtocol((PlayerPos*)pos); +} +void GameState::PlayerPosProtocol(PlayerPos* pos) +{ + +} +void GameState::ObjectPosProtocol(ObjPos* pos) +{ + +} +//void GameState::Protocol(LightPos pos); \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index 5ae6aa49..26ec0caa 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -23,13 +23,18 @@ public: GameState(void); ~GameState(void); bool Init(); - GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput); - bool LoadModels(std::wstring mapFile); - bool InitCamera(Oyster::Math::Float3 startPos); + GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override; + bool LoadModels(std::wstring mapFile) ; + bool InitCamera(Oyster::Math::Float3 startPos) ; gameStateState LoadGame(); - bool Render(); - bool Release(); + bool Render()override; + bool Release()override; + + void Protocol(ProtocolStruct* pos)override; + void PlayerPosProtocol(PlayerPos* pos); + void ObjectPosProtocol(ObjPos* pos); + //void Protocol(LightPos pos); }; }; }; diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index b107883f..8d54bd24 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -118,4 +118,14 @@ bool LobbyState::Release() delete privData; privData = NULL; return true; +} +void LobbyState::Protocol(ProtocolStruct* protocol) +{ + if((PlayerName*)protocol) + PlayerJoinProtocol((PlayerName*)protocol); + +} +void LobbyState::PlayerJoinProtocol(PlayerName* name) +{ + } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.h b/Code/Game/DanBiasGame/GameClientState/LobbyState.h index 7498d448..c00a3b8f 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.h +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.h @@ -32,5 +32,8 @@ public: bool Render(); bool Release(); + void Protocol(ProtocolStruct* protocol)override; + void PlayerJoinProtocol(PlayerName* name); + };};}; #endif // ! DANBIAS_CLIENT_GAMECLIENTSTATE_H diff --git a/Code/Game/DanBiasGame/Include/DanBiasGame.h b/Code/Game/DanBiasGame/Include/DanBiasGame.h index 0f9b83eb..a8d1a96f 100644 --- a/Code/Game/DanBiasGame/Include/DanBiasGame.h +++ b/Code/Game/DanBiasGame/Include/DanBiasGame.h @@ -1,6 +1,8 @@ #ifndef DANBIASGAME_DANBIASGAME_H #define DANBIASGAME_DANBIASGAME_H +#define DANBIAS_CLIENT_L + #if defined (DANBIAS_GAME_DLL_EXPORT) #define DANBIAS_GAME_DLL __declspec(dllexport) #else @@ -11,8 +13,6 @@ #include -#include "L_inputClass.h" - namespace DanBias { @@ -25,8 +25,6 @@ namespace DanBias DanBiasClientReturn_Sucess, }; - - struct DanBiasGameDesc { //Stuff goes here... @@ -56,11 +54,12 @@ namespace DanBias static HRESULT Update(float deltaTime); static HRESULT Render(float deltaTime); static HRESULT CleanUp(); + private: static __int64 cntsPerSec; static __int64 prevTimeStamp; static float secsPerCnt; - static InputClass* inputObj; + static HINSTANCE g_hInst; static HWND g_hWnd; static DanBiasGamePrivateData* m_data; diff --git a/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj index 6e5f099c..3650d06a 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\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(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\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(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\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(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\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(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.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + 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..0efd5e2e 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -3,16 +3,12 @@ ///////////////////////////////////////////////// #define NOMINMAX #include - -//#define DANBIAS_SERVER -#define DANBIAS_CLIENT +#include -#if defined(DANBIAS_SERVER) -#include "IDanBiasServer.h" -#elif defined(DANBIAS_CLIENT) -#include "DanBiasGame.h" -#endif +#include "DanBiasServerAPI.h" +//#include "DanBiasGame.h" + int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) { @@ -21,16 +17,12 @@ 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) +#elif defined(DANBIAS_CLIENT_L) if(SetDllDirectory(L"..\\DLL") == FALSE) { return cmdShow; 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..41d71e2e 100644 --- a/Code/Game/DanBiasServer/DLLMain.cpp +++ b/Code/Game/DanBiasServer/DLLMain.cpp @@ -1,8 +1,8 @@ - +#define NOMINMAX #include 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..af26345b 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)Game\GameLogic\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)OysterMath\;$(SolutionDir)GamePhysics\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)OysterPhysics3D\;$(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)Game\GameLogic\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)OysterMath\;$(SolutionDir)GamePhysics\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)OysterPhysics3D\;$(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)Game\GameLogic\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)OysterMath\;$(SolutionDir)GamePhysics\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)OysterPhysics3D\;$(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)Game\GameLogic\;$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)OysterMath\;$(SolutionDir)GamePhysics\;$(SolutionDir)Misc\;$(SolutionDir)WindowManager\;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)OysterPhysics3D\;$(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) + GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll + NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(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) + GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll + NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -134,15 +142,17 @@ 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 true true true - GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs) + GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName).dll + NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies) @@ -153,32 +163,50 @@ 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 true true true - GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs) + GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName).dll + NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies) - + - + + + + + + - - - - + + + + + + + + + + + {104fa3e9-94d9-4e1d-a941-28a03bc8a095} + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + {f10cbc03-9809-4cba-95d8-327c287b18ee} + diff --git a/Code/Game/DanBiasServer/GameServer.cpp b/Code/Game/DanBiasServer/GameServer.cpp new file mode 100644 index 00000000..c0601b30 --- /dev/null +++ b/Code/Game/DanBiasServer/GameServer.cpp @@ -0,0 +1,113 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#define NOMINMAX +#include +#include +#include + +#include "GameServer.h" +#include "Utilities.h" +#include "ServerInitReader.h" +#include +#include +#include "ServerObjects\ClientObject.h" + +namespace DanBias +{ + using namespace Oyster::Network; + + + void GameServer::ClientConnectCallback(NetworkClient& client) + { + printf("Client connected!\n"); + + Utility::DynamicMemory::SmartPointer c = new ClientObject(client); + this->mainLobby->AttachClient(c); + } + 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; + this->maxClients = data.clients; + serverDesc.port = data.port; + serverDesc.recvObj = this; + serverDesc.callbackType = Oyster::Network::NetworkClientCallbackType_Object; + + if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error; + if(!WindowShell::CreateConsoleWindow()) 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; + + if(!this->server->Start()) return DanBiasServerReturn_Error; + + while (true) + { + if(!WindowShell::Frame()) break; + + this->mainLobby->Frame(); + } + + return DanBiasServerReturn_Sucess; + } + DanBiasServerReturn GameServer::Release() + { + this->server->Shutdown(); + delete this->server; + delete this->mainLobby; + 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..4045295f --- /dev/null +++ b/Code/Game/DanBiasServer/GameServer.h @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#ifndef DANBIASSERVER_GAME_SERVER_H +#define DANBIASSERVER_GAME_SERVER_H + +#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..1165ba48 100644 --- a/Code/Game/DanBiasServer/Include/IDanBiasServer.h +++ b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.h @@ -4,8 +4,11 @@ #ifndef DANBIAS_SERVER_DANBIAS_SERVER_H #define DANBIAS_SERVER_DANBIAS_SERVER_H +#include -#if defined (DANBIAS_SERVER_DLL_EXPORT) +#define DANBIAS_SERVER + +#ifdef DANBIAS_SERVER_DLL_EXPORT #define DANBIAS_SERVER_DLL __declspec(dllexport) #else #define DANBIAS_SERVER_DLL __declspec(dllimport) @@ -13,28 +16,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..907b68c8 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp @@ -0,0 +1,39 @@ +#include "ClientObject.h" + +using namespace DanBias; + +ClientObject::ClientObject(const Oyster::Network::NetworkClient& client) +{ + this->client = client; + this->client.SetRecieverObject(this, Oyster::Network::NetworkProtocolCallbackType_Object); + this->box = 0; +} +ClientObject::~ClientObject() +{ + this->client.Disconnect(); +} + +void ClientObject::SetPostbox(Oyster::PostBox* box) +{ + this->box = box; +} +GameLogic::Player* ClientObject::Logic_Object() +{ + return &this->logicPlayer; +} +Oyster::Network::NetworkClient* ClientObject::NetClient_Object() +{ + return &this->client; +} + +void ClientObject::ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) +{ + if(!this->box) return; + + NetworkSession::ClientEvent _event; + _event.protocol = protocol; + _event.reciever = this; + + this->box->Post(_event); +} + diff --git a/Code/Game/DanBiasServer/ServerObjects/ClientObject.h b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h new file mode 100644 index 00000000..83327d1b --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h @@ -0,0 +1,34 @@ +#ifndef DANBIASSERVER_CLIENT_OBJECT_H +#define DANBIASSERVER_CLIENT_OBJECT_H + + +#include "NetworkSession.h" +#include "NetworkClient.h" +#include +#include + +namespace DanBias +{ + class ClientObject + :public Oyster::Network::ProtocolRecieverObject + { + public: + ClientObject(const Oyster::Network::NetworkClient& client); + ~ClientObject(); + + void SetPostbox(Oyster::PostBox* box); + + GameLogic::Player* Logic_Object(); + Oyster::Network::NetworkClient* NetClient_Object(); + + /** This method is NOT threadsafe. */ + virtual void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override; + + private: + GameLogic::Player logicPlayer; + Oyster::Network::NetworkClient client; + Oyster::IPostBox* box; + }; + +}//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..c4a0718c --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/GameLobby.h @@ -0,0 +1,21 @@ +#ifndef DANBIASSERVER_GAMELOBBY_H +#define DANBIASSERVER_GAMELOBBY_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..e7edddd4 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp @@ -0,0 +1,43 @@ +#include "MainLobby.h" +#include + +namespace DanBias +{ + MainLobby::MainLobby() + { + + } + MainLobby::~MainLobby() + { + + } + void MainLobby::Release() + { + this->DetachClient(); + } + + void MainLobby::Frame() + { + if(!this->box.IsEmpty()) + { + NetEvent &e = this->box.Fetch(); + ParseEvent(e); + } + } + +//////// Private + void MainLobby::ParseEvent(NetEvent& e) + { + static const short i = MAXSHORT; + if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return; + + short f = e.protocol[0].value.netShort; + + switch (f) + { + default: + break; + } + } + +}//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..8e8b520a --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h @@ -0,0 +1,22 @@ +#ifndef DANBIASSERVER_MAINLOBBY_H +#define DANBIASSERVER_MAINLOBBY_H + +#include "..\NetworkSession.h" + +namespace DanBias +{ + class MainLobby :public NetworkSession + { + public: + MainLobby(); + ~MainLobby(); + void Release(); + + void Frame(); + + private: + void ParseEvent(NetEvent& e); + + }; +}//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..c33af5e0 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp @@ -0,0 +1,73 @@ + +#include "ClientObject.h" +#include "NetworkSession.h" +#include + +namespace DanBias +{ + NetworkSession::NetworkSession() + { + + } + NetworkSession::~NetworkSession() + { + + } + + void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer client) + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + if(!this->clients[i]) + { + this->clients[i] = client; + this->clients[i]->SetPostbox(&this->box); + return; + } + } + this->clients.push_back(client); + } + + void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client) + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + if(this->clients[0]->NetClient_Object()->Id() == client->Id()) + this->clients[i] = 0; + } + } + void NetworkSession::DetachClient(ClientObject* client) + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + if(this->clients[0]->NetClient_Object()->Id() == client->NetClient_Object()->Id()) + this->clients[i] = 0; + } + + } + void NetworkSession::DetachClient(short ID) + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + if(this->clients[0]->NetClient_Object()->Id() == ID) + this->clients[i] = 0; + } + + } + void NetworkSession::DetachClient() + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + this->clients[i] = 0; + } + } + + void NetworkSession::Kick() + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + this->clients[i]->NetClient_Object()->Disconnect(); + this->clients[i] = 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..9ff9b016 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h @@ -0,0 +1,50 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#ifndef DANBIASSERVER_NETWORK_SESSION_H +#define DANBIASSERVER_NETWORK_SESSION_H + +#define NOMINMAX +#include "Utilities.h" +#include +#include +#include +#include + +namespace DanBias +{ + class ClientObject; + class NetworkSession + { + public: + struct NetEvent + { + ClientObject* reciever; + Oyster::Network::CustomNetProtocol protocol; + }; + + public: + NetworkSession(); + ~NetworkSession(); + + void AttachClient(Utility::DynamicMemory::SmartPointer client); + + void DetachClient(Oyster::Network::NetworkClient* client); + void DetachClient(ClientObject* client); + void DetachClient(short ID); + void DetachClient(); + + void Kick(); + + void Send(Oyster::Network::CustomNetProtocol& protocol); + void Send(Oyster::Network::CustomNetProtocol& protocol, int ID); + + //TODO: Do more lobby features + //virtual void + + protected: + std::vector> clients; + Oyster::PostBox box; + }; +}//End namespace DanBias +#endif // !DANBIASSERVER_NETWORK_SESSION_H diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 18324149..b7687acb 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,4 +1,5 @@ #include "AttatchmentMassDriver.h" +#include "PhysicsAPI.h" using namespace GameLogic; @@ -19,11 +20,20 @@ struct AttatchmentMassDriver::PrivateData AttatchmentMassDriver::AttatchmentMassDriver(void) { + myData = new PrivateData(); + this->owner = 0; +} + +AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) +{ + myData = new PrivateData(); + this->owner = &owner; } AttatchmentMassDriver::~AttatchmentMassDriver(void) { + delete myData; } /******************************************************** @@ -31,15 +41,33 @@ AttatchmentMassDriver::~AttatchmentMassDriver(void) ********************************************************/ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput) { - ForcePush(fireInput); -} - -/******************************************************** -* This is a specific functionallity of the weapon -********************************************************/ -void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) -{ + //switch case to determin what functionallity to use in the attatchment + switch (fireInput) + { + case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: + ForcePush(fireInput); + break; + case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: + ForcePull(fireInput); + break; + } } +/******************************************************** +* Pushes objects in a cone in front of the weapon when fired +********************************************************/ +void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) +{ + //create coneRigidBody that will then collide with object and push them in the aimed direction +} + +/******************************************************** +* Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack) +********************************************************/ +void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &fireInput) +{ + Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100); +} + diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index bc95c327..2fac7be4 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -1,3 +1,6 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// #ifndef ATTATCHMENTMASSDRIVER_H #define ATTATCHMENTMASSDRIVER_H #include "IAttatchment.h" @@ -8,6 +11,7 @@ namespace GameLogic { public: AttatchmentMassDriver(void); + AttatchmentMassDriver(Player &owner); ~AttatchmentMassDriver(void); @@ -15,6 +19,7 @@ namespace GameLogic private: void ForcePush(const WEAPON_FIRE &fireInput); + void ForcePull(const WEAPON_FIRE &fireInput); private: struct PrivateData; diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp index 86e0850b..288a1a4e 100644 --- a/Code/Game/GameLogic/AttatchmentSocket.cpp +++ b/Code/Game/GameLogic/AttatchmentSocket.cpp @@ -14,7 +14,7 @@ struct AttatchmentSocket::PrivateData } - IAttatchment *Attatchment; + IAttatchment *attatchment; }myData; @@ -30,5 +30,23 @@ AttatchmentSocket::~AttatchmentSocket(void) IAttatchment* AttatchmentSocket::GetAttatchment() { - return myData->Attatchment; + return myData->attatchment; +} + +void AttatchmentSocket::SetAttatchment(IAttatchment *attatchment) +{ + if (myData->attatchment) + { + delete myData->attatchment; + } + + myData->attatchment = attatchment; +} + +void AttatchmentSocket::RemoveAttatchment() +{ + if (myData->attatchment) + { + delete myData->attatchment; + } } diff --git a/Code/Game/GameLogic/AttatchmentSocket.h b/Code/Game/GameLogic/AttatchmentSocket.h index 1067e339..2257dd7a 100644 --- a/Code/Game/GameLogic/AttatchmentSocket.h +++ b/Code/Game/GameLogic/AttatchmentSocket.h @@ -1,3 +1,7 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// + #ifndef ATTATCHMENTSOCKET_H #define ATTATCHMENTSOCKET_H #include "IAttatchment.h" @@ -11,6 +15,8 @@ namespace GameLogic ~AttatchmentSocket(void); IAttatchment* GetAttatchment(); + void SetAttatchment(IAttatchment *attatchment); + void RemoveAttatchment(); private: struct PrivateData; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 52eaa4f3..3d1af2a1 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -1,4 +1,8 @@ #include "CollisionManager.h" +#include "PhysicsAPI.h" +#include "Object.h" +#include "DynamicObject.h" +#include "Player.h" using namespace Oyster; @@ -8,42 +12,44 @@ namespace GameLogic namespace CollisionManager { + void PlayerVBox(Player &player, DynamicObject &box); + + Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) { - Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyPlayer)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); + Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef)); + Object *realObj = (Object*)obj->gameObjectRef; switch (realObj->GetType()) { - case Object::OBJECT_TYPE_BOX: + case OBJECT_TYPE_BOX: PlayerVBox(*player,(*(DynamicObject*) realObj)); break; - case Object::OBJECT_TYPE_PLAYER: + case OBJECT_TYPE_PLAYER: break; } - //spela ljud? ta skada? etc etc return Physics::ICustomBody::SubscriptMessage_none; } void PlayerVBox(Player &player, DynamicObject &box) { - //spela ljud? ta skada? etc etc + player.DamageLife(20); } Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) { - DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyBox)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); + DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef; + Object *realObj = (Object*)obj->gameObjectRef; switch (realObj->GetType()) { - case Object::OBJECT_TYPE_BOX: + case OBJECT_TYPE_BOX: break; - case Object::OBJECT_TYPE_PLAYER: - PlayerVBox(*(Player*)realObj,*box); + case OBJECT_TYPE_PLAYER: + //PlayerVBox(*(Player*)realObj,*box); break; } diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index f88404cc..d19ce8e3 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -3,9 +3,6 @@ #include "Object.h" #include "PhysicsAPI.h" -#include "RefManager.h" -#include "DynamicObject.h" -#include "Player.h" namespace GameLogic { @@ -18,8 +15,8 @@ namespace GameLogic Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); //these are the specific collision case functions - void PlayerVBox(Player &player, DynamicObject &box); - void BoxVBox(DynamicObject &box1, DynamicObject &box2); + //void PlayerVBox(Player &player, DynamicObject &box); + //void BoxVBox(DynamicObject &box1, DynamicObject &box2); }; diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 8786255c..a8ea1ab4 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -1,29 +1,23 @@ #include "DynamicObject.h" +#include "CollisionManager.h" using namespace GameLogic; -struct DynamicObject::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - -}myData; - DynamicObject::DynamicObject() + :Object() { - myData = new PrivateData(); + +} + +DynamicObject::DynamicObject(void* collisionFunc, OBJECT_TYPE type) + :Object(collisionFunc, type) +{ + } DynamicObject::~DynamicObject(void) { - delete myData; + } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index ecf1e905..70bb8c11 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -1,27 +1,24 @@ ////////////////////////////////////////////////// //Created by Erik and Linda of the GameLogic team ////////////////////////////////////////////////// - - #ifndef DYNAMICOBJECT_H #define DYNAMICOBJECT_H +#include "Object.h" namespace GameLogic { - class DynamicObject + class DynamicObject : public Object { public: DynamicObject(); + DynamicObject(void* collisionFunc, OBJECT_TYPE type); ~DynamicObject(void); - void Update(); - private: - struct PrivateData; - PrivateData *myData; + }; } diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 03430feb..e0614e29 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -69,39 +69,39 @@ $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;$(LibraryPath) .dll $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;$(LibraryPath) $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;$(LibraryPath) $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;$(LibraryPath) Level3 Disabled true - $(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) - GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) + $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) + DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) true - OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GamePhysics_$(PlatformShortName)D.lib;%(AdditionalDependencies) - GamePhysics_$(PlatformShortName)D.dll + GamePhysics_$(PlatformShortName)D.lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -109,12 +109,13 @@ Level3 Disabled true - $(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) - GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) + $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) + DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) true - OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GamePhysics_$(PlatformShortName)D.lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName)D.lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -124,14 +125,15 @@ true true true - $(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) - GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) + $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) + DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GamePhysics_$(PlatformShortName).lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName).lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName).dll;%(DelayLoadDLLs) @@ -141,14 +143,15 @@ true true true - $(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) - GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) + $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories) + DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GamePhysics_$(PlatformShortName).lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName).lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName).dll;%(DelayLoadDLLs) @@ -168,22 +171,20 @@ - + - - @@ -191,7 +192,6 @@ - diff --git a/Code/Game/GameLogic/GameLogicDef.h b/Code/Game/GameLogic/GameLogicDef.h new file mode 100644 index 00000000..fa6a9a82 --- /dev/null +++ b/Code/Game/GameLogic/GameLogicDef.h @@ -0,0 +1,14 @@ +#ifndef GAMELOGIC_GAMELOGICDEF_H +#define GAMELOGIC_GAMELOGICDEF_H + +#ifndef DANBIAS_GAMELOGIC + #define DANBIAS_GAMELOGIC +#endif + +#ifdef DANBIAS_GAMELOGIC_DLL_EXPORT + #define DANBIAS_GAMELOGIC_DLL __declspec(dllexport) +#else + #define DANBIAS_GAMELOGIC_DLL __declspec(dllimport) +#endif + +#endif // !GAMELOGIC_GAMELOGICDEF_H diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 3c2b9997..3e72647e 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -36,6 +36,13 @@ namespace GameLogic WEAPON_STATE_IDLE = 1, WEAPON_STATE_RELOADING = 2, }; -} + + enum OBJECT_TYPE + { + OBJECT_TYPE_PLAYER = 0, + OBJECT_TYPE_BOX = 1, + OBJECT_TYPE_UNKNOWN = 2, + }; +}; #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/IAttatchment.cpp b/Code/Game/GameLogic/IAttatchment.cpp index c1e2a997..4b0b1961 100644 --- a/Code/Game/GameLogic/IAttatchment.cpp +++ b/Code/Game/GameLogic/IAttatchment.cpp @@ -3,22 +3,6 @@ using namespace GameLogic; -struct IAttatchment::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - - - -}myData; - IAttatchment::IAttatchment(void) { } diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h index c134026f..2192ffcf 100644 --- a/Code/Game/GameLogic/IAttatchment.h +++ b/Code/Game/GameLogic/IAttatchment.h @@ -1,6 +1,11 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// + #ifndef IATTATCHMENT_H #define IATTATCHMENT_H #include "GameLogicStates.h" +#include "Player.h" namespace GameLogic { @@ -16,9 +21,10 @@ namespace GameLogic virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0; - private: - struct PrivateData; - PrivateData *myData; + private: + + protected: + Player *owner; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index c83056c6..835062c1 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -2,6 +2,7 @@ #include "StaticObject.h" #include "DynamicObject.h" #include "GameMode.h" +#include "Player.h" using namespace GameLogic; @@ -9,16 +10,14 @@ struct Level::PrivateData { PrivateData() { - gameMode = new GameMode(); + } ~PrivateData() { - if (gameMode) - { - delete gameMode; - } } + Player *players; + int nrOfPlayers; StaticObject** staticObjects; int nrOfStaticObjects; @@ -40,3 +39,10 @@ Level::~Level(void) { delete myData; } + +void Level::InitiateLevel(std::string levelPath) +{ + +} + + diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 217a60e4..7177531b 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -3,6 +3,7 @@ ////////////////////////////////////////////////// #ifndef LEVEL_H #define LEVEL_H +#include namespace GameLogic { @@ -14,6 +15,8 @@ namespace GameLogic Level(void); ~Level(void); + void InitiateLevel(std::string levelPath); + private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 67385874..dcd32bf1 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -1,48 +1,55 @@ #include "Object.h" #include "OysterMath.h" -#include "DllInterfaces\GFXAPI.h" #include "CollisionManager.h" using namespace GameLogic; using namespace Oyster::Math; -using namespace Oyster::Graphics::Model; - -using namespace Utility::DynamicMemory; using namespace Oyster::Physics; -Object::Object(std::wstring objFile) -{ - - //model = new Model(); - model = Oyster::Graphics::API::CreateModel(objFile); - +Object::Object() +{ API::SimpleBodyDescription sbDesc; //sbDesc.centerPosition = //poi ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); - GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); + rigidBody->gameObjectRef = this; + this->type = OBJECT_TYPE_UNKNOWN; + +} + +Object::Object(void* collisionFunc, OBJECT_TYPE type) +{ + API::SimpleBodyDescription sbDesc; + //sbDesc.centerPosition = + + //poi + ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + + rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); + + rigidBody->gameObjectRef = this; + + this->type = type; } Object::~Object(void) { - Oyster::Graphics::API::DeleteModel(model); } -void Object::Render() -{ - this->rigidBody->GetOrientation(model->WorldMatrix); - Oyster::Graphics::API::RenderScene(model, 1); -} - -Object::OBJECT_TYPE Object::GetType() +OBJECT_TYPE Object::GetType() { return this->type; } + +Oyster::Physics::ICustomBody* Object::GetRigidBody() +{ + return this->rigidBody; +} diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 1c1c2830..01864515 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -7,41 +7,27 @@ #define OBJECT_H #include "PhysicsAPI.h" -#include "DllInterfaces/GFXAPI.h" - -#include "Model/Model.h" -#include "Utilities.h" - +#include "GameLogicStates.h" +#include "GameLogicDef.h" namespace GameLogic { - class Object + class DANBIAS_GAMELOGIC_DLL Object { public: - - enum OBJECT_TYPE - { - OBJECT_TYPE_PLAYER, - OBJECT_TYPE_BOX, - }; - Object(std::wstring objFile ); - virtual ~Object(void); - - void Render(); + Object(); + Object(void* collisionFunc, OBJECT_TYPE type); + ~Object(void); OBJECT_TYPE GetType(); + Oyster::Physics::ICustomBody* GetRigidBody(); + private: OBJECT_TYPE type; - protected: - //either a model pointer or an ID to an arraypos filled with models that are to be rendered - //rigidBody - Oyster::Physics::ICustomBody *rigidBody; - Oyster::Graphics::Model::Model *model; - }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 9bc9d752..bae54e9a 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -15,8 +15,7 @@ struct Player::PrivateData life = 100; playerState = PLAYER_STATE_IDLE; - rigidBody->SetSubscription(CollisionManager::PlayerCollision); - + lookDir = Oyster::Math::Float3(1,0,0); } ~PrivateData() @@ -30,16 +29,16 @@ struct Player::PrivateData int life; Weapon *weapon; PLAYER_STATE playerState; - - ICustomBody *rigidBody; + Oyster::Math::Float3 lookDir; }myData; Player::Player() + :Object(CollisionManager::PlayerCollision, OBJECT_TYPE_PLAYER) { myData = new PrivateData(); - } + Player::~Player(void) { delete myData; @@ -61,12 +60,16 @@ void Player::Update() ********************************************************/ void Player::Move(const PLAYER_MOVEMENT &movement) { + Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity(); + switch(movement) { case PLAYER_MOVEMENT_FORWARD: + API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100); break; case PLAYER_MOVEMENT_BACKWARD: + API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100); break; case PLAYER_MOVEMENT_LEFT: @@ -83,9 +86,9 @@ void Player::Move(const PLAYER_MOVEMENT &movement) /******************************************************** * Uses the players weapon based on user input ********************************************************/ -void Player::Shoot(const WEAPON_FIRE &fireInput) +void Player::UseWeapon(const WEAPON_FIRE &fireInput) { - myData->weapon->UseWeapon(fireInput); + myData->weapon->Use(fireInput); } /******************************************************** @@ -94,7 +97,7 @@ void Player::Shoot(const WEAPON_FIRE &fireInput) ********************************************************/ void Player::Jump() { - + API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100); } bool Player::IsWalking() @@ -112,7 +115,12 @@ bool Player::IsIdle() Oyster::Math::Float3 Player::GetPos() { - return myData->rigidBody->GetCenter(); + return rigidBody->GetCenter(); +} + +Oyster::Math::Float3 Player::GetLookDir() +{ + return myData->lookDir; } /******************************************************** @@ -123,3 +131,9 @@ void Player::Respawn() { } + + +void Player::DamageLife(int damage) +{ + myData->life -= damage; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 20fc8de6..af0bff50 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -5,10 +5,12 @@ #define PLAYER_H #include "GameLogicStates.h" #include "OysterMath.h" +#include "Object.h" +#include "GameLogicDef.h" namespace GameLogic { - class Player + class DANBIAS_GAMELOGIC_DLL Player : public Object { public: @@ -17,7 +19,7 @@ namespace GameLogic void Update(); void Move(const PLAYER_MOVEMENT &movement); - void Shoot(const WEAPON_FIRE &fireInput); + void UseWeapon(const WEAPON_FIRE &fireInput); void Jump(); bool IsWalking(); @@ -25,8 +27,12 @@ namespace GameLogic bool IsIdle(); Oyster::Math::Float3 GetPos(); + Oyster::Math::Float3 GetLookDir(); + void Respawn(); + void DamageLife(int damage); + private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/RefManager.h b/Code/Game/GameLogic/RefManager.h index a184e220..fa4080c9 100644 --- a/Code/Game/GameLogic/RefManager.h +++ b/Code/Game/GameLogic/RefManager.h @@ -8,7 +8,6 @@ #include #include "Object.h" -#include "PhysicsAPI.h" namespace GameLogic { diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index c58fb83c..155834fe 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -2,28 +2,22 @@ using namespace GameLogic; -struct StaticObject::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - -}myData; StaticObject::StaticObject() + :Object() { - myData = new PrivateData(); + +} + +StaticObject::StaticObject(void* collisionFunc, OBJECT_TYPE type) + :Object(collisionFunc,type) +{ + } StaticObject::~StaticObject(void) { - delete myData; + } diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index 2f292795..31121447 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -11,16 +11,16 @@ namespace GameLogic { - class StaticObject + class StaticObject : public Object { public: StaticObject(); + StaticObject(void* collisionFunc, OBJECT_TYPE type); ~StaticObject(void); private: - struct PrivateData; - PrivateData *myData; + }; } diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 2a575039..e620e0d6 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -9,20 +9,24 @@ struct Weapon::PrivateData PrivateData() { weaponState = WEAPON_STATE_IDLE; - SelectedAttatchment = new AttatchmentMassDriver(); + selectedAttatchment = 0; + currentNrOfAttatchments = 0; + selectedSocketID = 0; + maxNrOfSockets = 0; } ~PrivateData() { - delete SelectedAttatchment; } WEAPON_STATE weaponState; AttatchmentSocket **attatchmentSockets; - int nrOfAttatchmentSockets; + int maxNrOfSockets; + int currentNrOfAttatchments; - IAttatchment *SelectedAttatchment; + IAttatchment *selectedAttatchment; + int selectedSocketID; }myData; @@ -31,6 +35,17 @@ Weapon::Weapon() myData = new PrivateData(); } +Weapon::Weapon(int MaxNrOfSockets) +{ + myData = new PrivateData(); + myData->maxNrOfSockets = MaxNrOfSockets; + myData->attatchmentSockets = new AttatchmentSocket*[MaxNrOfSockets]; + for (int i = 0; i < MaxNrOfSockets; i++) + { + myData->attatchmentSockets[i] = new AttatchmentSocket(); + } +} + Weapon::~Weapon(void) { @@ -40,9 +55,9 @@ Weapon::~Weapon(void) /******************************************************** * Uses the weapon based on the input given and the current chosen attatchment ********************************************************/ -void Weapon::UseWeapon(const WEAPON_FIRE &fireInput) +void Weapon::Use(const WEAPON_FIRE &fireInput) { - myData->SelectedAttatchment->UseAttatchment(fireInput); + myData->selectedAttatchment->UseAttatchment(fireInput); } /******************************************************** @@ -67,3 +82,56 @@ bool Weapon::IsReloading() return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING); } +bool Weapon::IsValidSocket(int socketID) +{ + if(socketID < myData->maxNrOfSockets && socketID >= 0) + { + if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0) + { + return true; + } + } + + return false; +} + +int Weapon::GetCurrentSocketID() +{ + return myData->selectedSocketID; +} + + +void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner) +{ + if(myData->currentNrOfAttatchments < myData->maxNrOfSockets) + { + myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment); + myData->currentNrOfAttatchments++; + } +} + +void Weapon::SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner) +{ + if (IsValidSocket(socketID)) + { + myData->attatchmentSockets[socketID]->SetAttatchment(attatchment); + } +} + +void Weapon::RemoveAttatchment(int socketID) +{ + if (IsValidSocket(socketID)) + { + myData->attatchmentSockets[socketID]->RemoveAttatchment(); + } +} + +void Weapon::SelectAttatchment(int socketID) +{ + if (IsValidSocket(socketID)) + { + myData->selectedAttatchment = myData->attatchmentSockets[socketID]->GetAttatchment(); + myData->selectedSocketID = socketID; + } + +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h index 74a408e9..cdd1a3b7 100644 --- a/Code/Game/GameLogic/Weapon.h +++ b/Code/Game/GameLogic/Weapon.h @@ -4,6 +4,8 @@ #ifndef WEAPON_H #define WEAPON_H #include "GameLogicStates.h" +#include "IAttatchment.h" +#include "Player.h" namespace GameLogic { @@ -15,14 +17,24 @@ namespace GameLogic Weapon(void); + Weapon(int nrOfAttatchmentSockets); ~Weapon(void); - void UseWeapon(const WEAPON_FIRE &fireInput); + void Use(const WEAPON_FIRE &fireInput); + void AddNewAttatchment(IAttatchment *attatchment, Player *owner); + void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner); + void RemoveAttatchment(int socketID); + + void SelectAttatchment(int socketID); bool IsFireing(); bool IsIdle(); bool IsReloading(); + bool IsValidSocket(int socketID); + + int GetCurrentSocketID(); + private: diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj index 629ecf72..4b0d7c39 100644 --- a/Code/Game/GameProtocols/GameProtocols.vcxproj +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -154,8 +154,11 @@ + + + diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h new file mode 100644 index 00000000..101c5f42 --- /dev/null +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -0,0 +1,67 @@ +#ifndef GAMELOGIC_PLAYER_PROTOCOLS_H +#define GAMELOGIC_PLAYER_PROTOCOLS_H + +#include +#include "ProtocolIdentificationID.h" + + + +namespace GameLogic +{ + struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject + { + float worldMatrix[16]; + // look at dir + + Protocol_ObjectPosition() + { + this->protocol[0].value = protocol_PlayerPosition; + this->protocol[0].type = Oyster::Network::NetAttributeType_Int; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[3].type = Oyster::Network::NetAttributeType_Float; + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; + this->protocol[5].type = Oyster::Network::NetAttributeType_Float; + this->protocol[6].type = Oyster::Network::NetAttributeType_Float; + this->protocol[7].type = Oyster::Network::NetAttributeType_Float; + this->protocol[8].type = Oyster::Network::NetAttributeType_Float; + this->protocol[9].type = Oyster::Network::NetAttributeType_Float; + this->protocol[10].type = Oyster::Network::NetAttributeType_Float; + this->protocol[11].type = Oyster::Network::NetAttributeType_Float; + this->protocol[12].type = Oyster::Network::NetAttributeType_Float; + this->protocol[13].type = Oyster::Network::NetAttributeType_Float; + this->protocol[14].type = Oyster::Network::NetAttributeType_Float; + this->protocol[15].type = Oyster::Network::NetAttributeType_Float; + this->protocol[16].type = Oyster::Network::NetAttributeType_Float; + + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + + this->protocol[1].value = worldMatrix[0]; + this->protocol[2].value = worldMatrix[1]; + this->protocol[3].value = worldMatrix[2]; //Forgot? + this->protocol[4].value = worldMatrix[4]; //Forgot? + this->protocol[5].value = worldMatrix[5]; + this->protocol[6].value = worldMatrix[6]; + this->protocol[7].value = worldMatrix[7]; + this->protocol[8].value = worldMatrix[8]; + this->protocol[9].value = worldMatrix[9]; + this->protocol[10].value = worldMatrix[10]; + this->protocol[11].value = worldMatrix[11]; + this->protocol[12].value = worldMatrix[12]; + this->protocol[13].value = worldMatrix[13]; + this->protocol[14].value = worldMatrix[14]; + this->protocol[15].value = worldMatrix[15]; + this->protocol[16].value = worldMatrix[16]; + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + +} + +#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index b091ba34..d620af81 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -1,14 +1,19 @@ +////////////////////////////////////////////////////////// +// Created 2013 // +// Dennis Andersen, Linda Andersson // +////////////////////////////////////////////////////////// + #ifndef GAMELOGIC_PLAYER_PROTOCOLS_H #define GAMELOGIC_PLAYER_PROTOCOLS_H -#include "CustomNetProtocol.h" +#include #include "ProtocolIdentificationID.h" namespace GameLogic { - struct Protocol_PlayerMovement :public Network::CustomProtocolObject + struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject { int ProtocolID; bool bForward; @@ -20,31 +25,60 @@ 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 = Oyster::Network::NetAttributeType_Int; + this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[4].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[5].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[6].type = Oyster::Network::NetAttributeType_Bool; } - Network::CustomNetProtocol* GetProtocol() override + Oyster::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; } private: - Network::CustomNetProtocol protocol; + Oyster::Network::CustomNetProtocol protocol; }; + + struct Protocol_PlayerPosition :public Oyster::Network::CustomProtocolObject + { + float position[3]; + // look at dir + + Protocol_PlayerPosition() + { + this->protocol[0].value = protocol_PlayerPosition; + this->protocol[0].type = Oyster::Network::NetAttributeType_Int; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[3].type = Oyster::Network::NetAttributeType_Float; + + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + + this->protocol[1].value = position[0]; + this->protocol[2].value = position[1]; + this->protocol[3].value = position[2]; + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + } #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 1af8c920..09f1aeed 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -1,8 +1,21 @@ +///////////////////////////////////////////////////////////////////// +// Created 2013 by: +// [Dennis Andersen], [Linda Andersson] +///////////////////////////////////////////////////////////////////// #ifndef GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H #define GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -#define protocol_PlayerNavigation 0; +#define protocol_PlayerNavigation 0 +#define protocol_PlayerPosition 1 +#define protocol_ObjectPosition 2 + +#define protocol_Lobby_Msg 60 + +#define protocol_General_Disconnect 100 +#define protocol_General_Ping 101 + +#define PROTOCOL_TEST 1000 #endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H diff --git a/Code/Game/GameProtocols/TEST_PROTOCOLS.h b/Code/Game/GameProtocols/TEST_PROTOCOLS.h new file mode 100644 index 00000000..df171c1f --- /dev/null +++ b/Code/Game/GameProtocols/TEST_PROTOCOLS.h @@ -0,0 +1,35 @@ +#ifndef GAMESERVER_TEST_H +#define GAMESERVER_TEST_H + +#include +#include "ProtocolIdentificationID.h" + + + +namespace GameLogic +{ + struct Protocol_TEST :public Oyster::Network::CustomProtocolObject + { + int ProtocolID; + char text; + + Protocol_TEST() + { + this->protocol[0].value = ProtocolID = PROTOCOL_TEST; + + this->protocol[0].type = Oyster::Network::NetAttributeType_Int; + this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value = text; + + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; +} + +#endif // !GAMESERVER_TEST_H \ No newline at end of file diff --git a/Code/GamePhysics/GamePhysics.vcxproj b/Code/GamePhysics/GamePhysics.vcxproj index 540002a1..06e64fd1 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj +++ b/Code/GamePhysics/GamePhysics.vcxproj @@ -91,9 +91,12 @@ Disabled $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true + + @@ -102,9 +105,12 @@ Disabled $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true + + @@ -115,11 +121,14 @@ true $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true true true + + @@ -130,11 +139,14 @@ true $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true true true + + @@ -154,6 +166,8 @@ + + diff --git a/Code/GamePhysics/GamePhysics.vcxproj.filters b/Code/GamePhysics/GamePhysics.vcxproj.filters index 694a8ec7..15221691 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj.filters +++ b/Code/GamePhysics/GamePhysics.vcxproj.filters @@ -36,6 +36,12 @@ Header Files\Implementation + + Header Files\Include + + + Header Files\Include + diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index 1da6045b..b841b49d 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -39,7 +39,7 @@ void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef) data.next = NULL; data.prev = NULL; data.customBodyRef = customBodyRef; - this->mapReferences.insert(std::pair (customBodyRef, this->leafData.size())); + this->mapReferences.insert(std::pair (data.customBodyRef, this->leafData.size())); this->leafData.push_back(data); /*if(tempPtr != NULL) @@ -184,6 +184,7 @@ unsigned int Octree::GetTemporaryReferenceOf( const ICustomBody* objRef ) const void Octree::SetAsAltered( unsigned int tempRef ) { + this->leafData[tempRef].container = this->leafData[tempRef].customBodyRef->GetBoundingSphere(); //! @todo TODO: implement stub } diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 3d3080da..46b3369c 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -20,36 +20,36 @@ namespace float deltaWhen; Float3 worldWhere; - if( deuter->Intersects(*deuter, 1.0f, deltaWhen, worldWhere) ) + if( proto->Intersects(*deuter, 1.0f, deltaWhen, worldWhere) ) { proto->CallSubscription( proto, deuter ); } } } -Float4x4 & MomentOfInertia::CreateSphereMatrix( const Float mass, const Float radius) +Float4x4 & MomentOfInertia::CreateSphereMatrix( const Float mass, const Float radius, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::Sphere(mass, radius); + return targetMem = Formula::MomentOfInertia::Sphere(mass, radius); } -Float4x4 & MomentOfInertia::CreateHollowSphereMatrix( const Float mass, const Float radius) +Float4x4 & MomentOfInertia::CreateHollowSphereMatrix( const Float mass, const Float radius, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::HollowSphere(mass, radius); + return targetMem = Formula::MomentOfInertia::HollowSphere(mass, radius); } -Float4x4 & MomentOfInertia::CreateCuboidMatrix( const Float mass, const Float height, const Float width, const Float depth ) +Float4x4 & MomentOfInertia::CreateCuboidMatrix( const Float mass, const Float height, const Float width, const Float depth, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::Cuboid(mass, height, width, depth); + return targetMem = Formula::MomentOfInertia::Cuboid(mass, height, width, depth); } -Float4x4 & MomentOfInertia::CreateCylinderMatrix( const Float mass, const Float height, const Float radius ) +Float4x4 & MomentOfInertia::CreateCylinderMatrix( const Float mass, const Float height, const Float radius, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::Cylinder(mass, height, radius); + return targetMem = Formula::MomentOfInertia::Cylinder(mass, height, radius); } -Float4x4 & MomentOfInertia::CreateRodMatrix( const Float mass, const Float length ) +Float4x4 & MomentOfInertia::CreateRodMatrix( const Float mass, const Float length, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::RodCenter(mass, length); + return targetMem = Formula::MomentOfInertia::RodCenter(mass, length); } API & API::Instance() diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 70bc6938..80e352ea 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -42,6 +42,23 @@ UniquePointer SimpleRigidBody::Clone() const return new SimpleRigidBody( *this ); } +SimpleRigidBody::State SimpleRigidBody::GetState() const +{ + return State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targetMem ) const +{ + return targetMem = State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) +{ /** @todo TODO: temporary solution! Need to know it's occtree */ + this->rigid.box.boundingOffset = state.GetReach(); + this->rigid.box.center = state.GetCenterPosition(); + this->rigid.box.rotation = state.GetRotation(); +} + void SimpleRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) { this->collisionAction( proto, deuter ); @@ -107,6 +124,12 @@ Float4x4 & SimpleRigidBody::GetView( Float4x4 &targetMem ) const return targetMem = this->rigid.GetView(); } +Float3 SimpleRigidBody::GetRigidLinearVelocity() const +{ + return this->rigid.GetLinearVelocity(); +} + + UpdateState SimpleRigidBody::Update( Float timeStepLength ) { this->rigid.Update_LeapFrog( timeStepLength ); @@ -177,4 +200,9 @@ void SimpleRigidBody::SetOrientation( const Float4x4 &orientation ) void SimpleRigidBody::SetSize( const Float3 &size ) { this->rigid.SetSize( size ); +} + +void SimpleRigidBody::SetMomentum( const Float3 &worldG ) +{ + this->rigid.SetLinearMomentum( worldG ); } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h index a674a20d..9eefeb48 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -15,6 +15,11 @@ namespace Oyster { namespace Physics ::Utility::DynamicMemory::UniquePointer Clone() const; + State GetState() const; + State & GetState( State &targetMem ) const; + void SetState( const State &state ); + ::Oyster::Math::Float3 GetRigidLinearVelocity() const; + void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ); bool IsAffectedByGravity() const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; @@ -41,6 +46,7 @@ namespace Oyster { namespace Physics void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); void SetSize( const ::Oyster::Math::Float3 &size ); + void SetMomentum( const ::Oyster::Math::Float3 &worldG ); private: ::Oyster::Physics3D::RigidBody rigid; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index c741a68a..364d7454 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -44,6 +44,23 @@ UniquePointer SphericalRigidBody::Clone() const return new SphericalRigidBody( *this ); } +SphericalRigidBody::State SphericalRigidBody::GetState() const +{ + return State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +SphericalRigidBody::State & SphericalRigidBody::GetState( SphericalRigidBody::State &targetMem ) const +{ + return targetMem = State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +void SphericalRigidBody::SetState( const SphericalRigidBody::State &state ) +{ /** @todo TODO: temporary solution! Need to know it's occtree */ + this->rigid.box.boundingOffset = state.GetReach(); + this->rigid.box.center = state.GetCenterPosition(); + this->rigid.box.rotation = state.GetRotation(); +} + void SphericalRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) { this->collisionAction( proto, deuter ); @@ -109,6 +126,11 @@ Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const return targetMem = this->rigid.GetView(); } +Float3 SphericalRigidBody::GetRigidLinearVelocity() const +{ + return this->rigid.GetLinearVelocity(); +} + UpdateState SphericalRigidBody::Update( Float timeStepLength ) { this->rigid.Update_LeapFrog( timeStepLength ); @@ -183,4 +205,9 @@ void SphericalRigidBody::SetSize( const Float3 &size ) { this->rigid.SetSize( size ); this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )? +} + +void SphericalRigidBody::SetMomentum( const Float3 &worldG ) +{ + this->rigid.SetLinearMomentum( worldG ); } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index 37263e91..4d003f99 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -16,6 +16,11 @@ namespace Oyster { namespace Physics ::Utility::DynamicMemory::UniquePointer Clone() const; + State GetState() const; + State & GetState( State &targetMem = State() ) const; + void SetState( const State &state ); + ::Oyster::Math::Float3 GetRigidLinearVelocity() const; + void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ); bool IsAffectedByGravity() const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; @@ -42,6 +47,7 @@ namespace Oyster { namespace Physics void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); void SetSize( const ::Oyster::Math::Float3 &size ); + void SetMomentum( const ::Oyster::Math::Float3 &worldG ); private: ::Oyster::Physics3D::RigidBody rigid; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 29014214..84a3d639 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -17,6 +17,13 @@ namespace Oyster class API; class ICustomBody; + namespace Struct + { + struct SimpleBodyDescription; + struct SphericalBodyDescription; + struct CustomBodyState; + } + enum UpdateState { UpdateState_resting, @@ -31,22 +38,22 @@ namespace Oyster class PHYSICS_DLL_USAGE MomentOfInertia { public: - static ::Oyster::Math::Float4x4 & CreateSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius); - - static ::Oyster::Math::Float4x4 & CreateHollowSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius); + static ::Oyster::Math::Float4x4 & CreateSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); + + static ::Oyster::Math::Float4x4 & CreateHollowSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - static ::Oyster::Math::Float4x4 & CreateCuboidMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth ); + static ::Oyster::Math::Float4x4 & CreateCuboidMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - static ::Oyster::Math::Float4x4 & CreateCylinderMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius ); + static ::Oyster::Math::Float4x4 & CreateCylinderMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - static ::Oyster::Math::Float4x4 & CreateRodMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length ); + static ::Oyster::Math::Float4x4 & CreateRodMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); }; class PHYSICS_DLL_USAGE API { public: - struct SimpleBodyDescription; - struct SphericalBodyDescription; + typedef Struct::SimpleBodyDescription SimpleBodyDescription; + typedef Struct::SphericalBodyDescription SphericalBodyDescription; typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer proto ); @@ -236,7 +243,15 @@ namespace Oyster SubscriptMessage_ignore_collision_response }; + /******************************************************** + * @param gameObjectRef: a pointer to the object in the game owning the rigid body. + ********************************************************/ + void* gameObjectRef; + typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); + typedef Struct::SimpleBodyDescription SimpleBodyDescription; + typedef Struct::SphericalBodyDescription SphericalBodyDescription; + typedef Struct::CustomBodyState State; virtual ~ICustomBody() {}; @@ -251,6 +266,26 @@ namespace Oyster ********************************************************/ virtual void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) = 0; + /******************************************************** + * @todo TODO: need doc + ********************************************************/ + virtual State GetState() const = 0; + + /******************************************************** + * @todo TODO: need doc + ********************************************************/ + virtual State & GetState( State &targetMem ) const = 0; + + /******************************************************** + * @return the linear velocity of the rigid body in a vector. + ********************************************************/ + virtual Math::Float3 GetRigidLinearVelocity() const = 0; + + /******************************************************** + * @todo TODO: need doc + ********************************************************/ + virtual void SetState( const State &state ) = 0; + /******************************************************** * @return true if Engine should apply gravity on this object. ********************************************************/ @@ -390,49 +425,16 @@ namespace Oyster * Use API::SetSize(...) ********************************************************/ virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0; - }; - struct API::SimpleBodyDescription - { - ::Oyster::Math::Float4x4 rotation; - ::Oyster::Math::Float3 centerPosition; - ::Oyster::Math::Float3 size; - ::Oyster::Math::Float mass; - ::Oyster::Math::Float4x4 inertiaTensor; - ICustomBody::EventAction_Collision subscription; - bool ignoreGravity; - - SimpleBodyDescription() - { - this->rotation = ::Oyster::Math::Float4x4::identity; - this->centerPosition = ::Oyster::Math::Float3::null; - this->size = ::Oyster::Math::Float3( 1.0f ); - this->mass = 12.0f; - this->inertiaTensor = ::Oyster::Math::Float4x4::identity; - this->subscription = NULL; - this->ignoreGravity = false; - } - }; - - struct API::SphericalBodyDescription - { - ::Oyster::Math::Float4x4 rotation; - ::Oyster::Math::Float3 centerPosition; - ::Oyster::Math::Float radius; - ::Oyster::Math::Float mass; - ICustomBody::EventAction_Collision subscription; - bool ignoreGravity; - - SphericalBodyDescription() - { - this->rotation = ::Oyster::Math::Float4x4::identity; - this->centerPosition = ::Oyster::Math::Float3::null; - this->radius = 0.5f; - this->mass = 10.0f; - this->subscription = NULL; - this->ignoreGravity = false; - } + /******************************************************** + * To not be called if is in Engine + * Use API::?? @todo TODO: + ********************************************************/ + virtual void SetMomentum( const ::Oyster::Math::Float3 &worldG ) = 0; }; } } + +#include "PhysicsStructs.h" + #endif \ No newline at end of file diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h new file mode 100644 index 00000000..3de46ee2 --- /dev/null +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -0,0 +1,117 @@ +#ifndef PHYSICS_STRUCTS_IMPL_H +#define PHYSICS_STRUCTS_IMPL_H + +#include "PhysicsStructs.h" + +namespace Oyster { namespace Physics +{ + namespace Struct + { + inline SimpleBodyDescription::SimpleBodyDescription() + { + this->rotation = ::Oyster::Math::Float4x4::identity; + this->centerPosition = ::Oyster::Math::Float3::null; + this->size = ::Oyster::Math::Float3( 1.0f ); + this->mass = 12.0f; + this->inertiaTensor = ::Oyster::Math::Float4x4::identity; + this->subscription = NULL; + this->ignoreGravity = false; + } + + inline SphericalBodyDescription::SphericalBodyDescription() + { + this->rotation = ::Oyster::Math::Float4x4::identity; + this->centerPosition = ::Oyster::Math::Float3::null; + this->radius = 0.5f; + this->mass = 10.0f; + this->subscription = NULL; + this->ignoreGravity = false; + } + + + inline CustomBodyState::CustomBodyState( const ::Oyster::Math::Float3 &reach, const ::Oyster::Math::Float3 ¢erPos, const ::Oyster::Math::Float3 &rotation ) + { + this->reach = ::Oyster::Math::Float4( reach, 0.0f ); + this->centerPos = ::Oyster::Math::Float4( centerPos, 1.0f ); + this->angularAxis = ::Oyster::Math::Float4( rotation, 0.0f ); + this->isSpatiallyAltered = this->isDisturbed = false; + } + + inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state ) + { + this->reach = state.reach; + this->centerPos = state.centerPos; + this->angularAxis = state.angularAxis; + + this->isSpatiallyAltered = state.isSpatiallyAltered; + this->isDisturbed = state.isDisturbed; + return *this; + } + + inline const ::Oyster::Math::Float4 & CustomBodyState::GetReach() const + { + return this->reach; + } + + inline ::Oyster::Math::Float4 CustomBodyState::GetSize() const + { + return 2.0f * this->GetReach(); + } + + inline const ::Oyster::Math::Float4 & CustomBodyState::GetCenterPosition() const + { + return this->centerPos; + } + + inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularAxis() const + { + return this->angularAxis; + } + + inline ::Oyster::Math::Float4x4 CustomBodyState::GetRotation() const + { + return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis().xyz ); + } + + inline void CustomBodyState::SetSize( const ::Oyster::Math::Float3 &size ) + { + this->SetReach( 0.5f * size ); + } + + inline void CustomBodyState::SetReach( const ::Oyster::Math::Float3 &halfSize ) + { + this->reach.xyz = halfSize; + this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float4::null ); + this->isSpatiallyAltered = this->isDisturbed = true; + } + + inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos ) + { + this->centerPos.xyz = centerPos; + this->isSpatiallyAltered = this->isDisturbed = true; + } + + inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float3 &angularAxis ) + { + this->angularAxis.xyz = angularAxis; + this->isSpatiallyAltered = this->isDisturbed = true; + } + + inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4x4 &rotation ) + { + this->SetRotation( ::Oyster::Math3D::AngularAxis(rotation).xyz ); + } + + inline bool CustomBodyState::IsSpatiallyAltered() const + { + return this->isSpatiallyAltered; + } + + inline bool CustomBodyState::IsDisturbed() const + { + return this->isDisturbed; + } + } +} } + +#endif \ No newline at end of file diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h new file mode 100644 index 00000000..c1f74640 --- /dev/null +++ b/Code/GamePhysics/PhysicsStructs.h @@ -0,0 +1,70 @@ +#ifndef PHYSICS_STRUCTS_H +#define PHYSICS_STRUCTS_H + +#include "OysterMath.h" +#include "PhysicsAPI.h" + +namespace Oyster { namespace Physics +{ + namespace Struct + { + struct SimpleBodyDescription + { + ::Oyster::Math::Float4x4 rotation; + ::Oyster::Math::Float3 centerPosition; + ::Oyster::Math::Float3 size; + ::Oyster::Math::Float mass; + ::Oyster::Math::Float4x4 inertiaTensor; + ::Oyster::Physics::ICustomBody::EventAction_Collision subscription; + bool ignoreGravity; + + SimpleBodyDescription(); + }; + + struct SphericalBodyDescription + { + ::Oyster::Math::Float4x4 rotation; + ::Oyster::Math::Float3 centerPosition; + ::Oyster::Math::Float radius; + ::Oyster::Math::Float mass; + ::Oyster::Physics::ICustomBody::EventAction_Collision subscription; + bool ignoreGravity; + + SphericalBodyDescription(); + }; + + struct CustomBodyState + { + public: + CustomBodyState( const ::Oyster::Math::Float3 &reach = ::Oyster::Math::Float3::null, + const ::Oyster::Math::Float3 ¢erPos = ::Oyster::Math::Float3::null, + const ::Oyster::Math::Float3 &rotation = ::Oyster::Math::Float3::null ); + + CustomBodyState & operator = ( const CustomBodyState &state ); + + const ::Oyster::Math::Float4 & GetReach() const; + ::Oyster::Math::Float4 GetSize() const; + const ::Oyster::Math::Float4 & GetCenterPosition() const; + const ::Oyster::Math::Float4 & GetAngularAxis() const; + ::Oyster::Math::Float4x4 GetRotation() const; + + void SetSize( const ::Oyster::Math::Float3 &size ); + void SetReach( const ::Oyster::Math::Float3 &halfSize ); + void SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos ); + void SetRotation( const ::Oyster::Math::Float3 &angularAxis ); + void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); + + bool IsSpatiallyAltered() const; + bool IsDisturbed() const; + + private: + ::Oyster::Math::Float4 reach, centerPos, angularAxis; + + bool isSpatiallyAltered, isDisturbed; + }; + } +} } + +#include "PhysicsStructs-Impl.h" + +#endif \ No newline at end of file diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 8cb234da..7d3074d3 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -157,6 +157,8 @@ + + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index 7151e26a..d6fea6e9 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -86,5 +86,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Code/Misc/PostBox/IPostBox.h b/Code/Misc/PostBox/IPostBox.h new file mode 100644 index 00000000..30ae170e --- /dev/null +++ b/Code/Misc/PostBox/IPostBox.h @@ -0,0 +1,22 @@ +#ifndef NETWORK_DEPENDENCIES_I_POST_BOX_H +#define NETWORK_DEPENDENCIES_I_POST_BOX_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +namespace Oyster +{ + template + class IPostBox + { + public: + virtual ~IPostBox() {} + virtual void Post(T message) = 0; + virtual T Fetch() = 0; + virtual bool IsEmpty() = 0; + + }; +} + +#endif \ No newline at end of file diff --git a/Code/Misc/PostBox/PostBox.h b/Code/Misc/PostBox/PostBox.h new file mode 100644 index 00000000..c01eeead --- /dev/null +++ b/Code/Misc/PostBox/PostBox.h @@ -0,0 +1,61 @@ +#ifndef NETWORK_DEPENDENCIES_POST_BOX_H +#define NETWORK_DEPENDENCIES_POST_BOX_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#include "IPostBox.h" +#include "../ThreadSafeQueue.h" + +namespace Oyster +{ + //With this class you can post items to it and then fetch them somewhere else. + //It is thread safe beacause of the ThreadSafeQueue. + template + class PostBox : public IPostBox + { + public: + PostBox(); + virtual ~PostBox(); + + virtual void Post(T message); + virtual T Fetch(); + virtual bool IsEmpty(); + + private: + Oyster::Queue::ThreadSafeQueue messages; + + }; + + //Implementation of PostBox + template + PostBox::PostBox() + { + } + + template + PostBox::~PostBox() + { + } + + template + void PostBox::Post(T message) + { + messages.Push(message); + } + + template + T PostBox::Fetch() + { + return messages.Pop(); + } + + template + bool PostBox::IsEmpty() + { + return !messages.IsEmpty(); + } +} + +#endif \ No newline at end of file diff --git a/Code/Misc/Resource/Loaders/CustomLoader.cpp.orig b/Code/Misc/Resource/Loaders/CustomLoader.cpp.orig deleted file mode 100644 index a37c0a76..00000000 --- a/Code/Misc/Resource/Loaders/CustomLoader.cpp.orig +++ /dev/null @@ -1,73 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// - -#include "..\OResource.h" -#include "..\..\Utilities.h" - -#include - -using namespace Oyster::Resource; - - -OResource* OResource::CustomLoader(const wchar_t filename[], CustomLoadFunction fnc) -{ -<<<<<<< HEAD - CustomData &data = fnc(filename); - - if(!data.loadedData) return 0; - if(!data.resourceUnloadFnc) return 0; - OHRESOURCE n = (OHRESOURCE)data.loadedData; - OResource *resource = new OResource(n, ResourceType_UNKNOWN, 0, 0, filename); - - resource->customData = new CustomResourceData(); - resource->customData->unloadingFunction = data.resourceUnloadFnc; - //resource->resourceData = (OHRESOURCE)data.loadedData; -======= - CustomData data; - memset(&data, 0, sizeof(CustomData)); - - fnc(filename, data); - - if(!data.loadedData) - { - return 0; - } - if(!data.resourceUnloadFnc) - { - return 0; - } - /** For some wierd reason that i don't understand when trying to send data.loadedData directly as a - * parameter to OResource constructor, the value is changed when it arrives in the constructor. - * Doing it like this, storing in a temporary variable, the value stays correct. (What the fuck! I must be overloking something...)*/ - //OHRESOURCE temp = data.loadedData; - OResource *resource = new OResource(data.loadedData, ResourceType_UNKNOWN, 0, 0, filename); - - resource->customData = new CustomResourceData(); - resource->customData->unloadingFunction = data.resourceUnloadFnc; ->>>>>>> d08644e8e1ecc56f4d9dfa6a9aa33df94d9e655a - resource->customData->loadingFunction = fnc; - - return resource; -} -void OResource::CustomUnloader() -{ - this->customData->unloadingFunction(this->resourceData); -} -OResource* OResource::CustomReloader() -{ - CustomUnloader(); - - CustomData data; - memset(&data, 0, sizeof(CustomData)); - - this->customData->loadingFunction(this->resourceFilename.c_str(), data); - this->resourceData = (OHRESOURCE)data.loadedData; - - if(data.resourceUnloadFnc) - { - this->customData->unloadingFunction = data.resourceUnloadFnc; - } - return this; -} - diff --git a/Code/Misc/Thread/IThreadObject.h b/Code/Misc/Thread/IThreadObject.h index b21c942e..f6b4d638 100644 --- a/Code/Misc/Thread/IThreadObject.h +++ b/Code/Misc/Thread/IThreadObject.h @@ -26,7 +26,9 @@ namespace Oyster */ virtual void ThreadExit() { } /** - * This function is required to get threading working. + * This function is required to get threading working. + * Note that this function is NOT thread safe. + * OBS! Do not highjack the looping. */ virtual bool DoWork ( ) = 0; }; diff --git a/Code/Misc/Thread/OysterThread.h b/Code/Misc/Thread/OysterThread.h index 05a9f8ad..805dea3b 100644 --- a/Code/Misc/Thread/OysterThread.h +++ b/Code/Misc/Thread/OysterThread.h @@ -15,6 +15,12 @@ namespace Oyster OYSTER_THREAD_ERROR_FAILED, OYSTER_THREAD_ERROR_SUCCESS, }; + enum OYSTER_THREAD_PRIORITY + { + OYSTER_THREAD_PRIORITY_1, //!< High + OYSTER_THREAD_PRIORITY_2, //!< Medium + OYSTER_THREAD_PRIORITY_3, //!< Low + }; class OysterThread { @@ -30,16 +36,17 @@ namespace Oyster OYSTER_THREAD_ERROR Create(IThreadObject* worker, bool start); OYSTER_THREAD_ERROR Start(); - void Stop(); + void Stop(bool wait = false); void Pause(); void Pause(int mSec); void Resume(); OYSTER_THREAD_ERROR Reset(IThreadObject* worker = 0); - void Terminate(); + void Terminate(bool wait = false); void Wait(); void Wait(int mSec); OYSTER_THREAD_ERROR Swap(const OysterThread* other); bool IsActive(); + void SetPriority(OYSTER_THREAD_PRIORITY priority); }; } } diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index 9605dd78..ab829adf 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -31,43 +31,57 @@ using namespace Utility::DynamicMemory; struct ThreadData { - std::atomic state; // workerThread; // msec; //owner = 0; + this->state = OYSTER_THREAD_STATE_DEAD; + + if(this->workerThread) + { + //@todo TODO: Make detatch avalible. + if(this->workerThread->joinable()) + this->workerThread->detach(); + } + } + ThreadData(const ThreadData&) + {}; + const ThreadData& operator =(const ThreadData& o) + {}; }; struct OysterThread::PrivateData { SmartPointer threadData; PrivateData() - :threadData(new ThreadData()) { + threadData = new ThreadData(); + threadData->first = true; threadData->owner = 0; threadData->workerThread = 0; threadData->callingThread; threadData->state = OYSTER_THREAD_STATE_STOPED; + threadData->prio = OYSTER_THREAD_PRIORITY_3; } PrivateData(const PrivateData& o) { threadData = o.threadData; } + const PrivateData& operator=(const PrivateData& o) + { + threadData = o.threadData; + } ~PrivateData() { - //@todo TODO: Make detatch avalible. - this->threadData->workerThread->detach(); - - this->threadData->owner = 0; - - this->threadData->state = OYSTER_THREAD_STATE_DEAD; + threadData.Release(); } }; @@ -75,77 +89,47 @@ using namespace Utility::DynamicMemory; #pragma endregion -int tempId = 0; -std::vector IDS; static void ThreadingFunction(SmartPointer &origin) { - bool shouldContinue; + bool shouldContinue = true; SmartPointer w = origin; theBegining: - while(w->state == OYSTER_THREAD_STATE_STOPED) + while(w->state == OYSTER_THREAD_STATE_STOPED) std::this_thread::yield(); + + if(w->owner) w->owner->ThreadEntry(); + w->first = false; + while (w->state != OYSTER_THREAD_STATE_STOPED && w->state != OYSTER_THREAD_STATE_DEAD && shouldContinue) { - std::this_thread::yield(); - } - -// w->mutexLock.LockMutex(); - if(w->owner) - { - w->owner->ThreadEntry(); - } -// w->mutexLock.UnlockMutex(); - - while (w->state != OYSTER_THREAD_STATE_STOPED && w->state != OYSTER_THREAD_STATE_DEAD) - { -// w->mutexLock.LockMutex(); + switch (w->prio) { - if(w->owner) - { - shouldContinue = w->owner->DoWork(); - } - } -// w->mutexLock.UnlockMutex(); - - if(!shouldContinue) - { - goto theEnd; - } - if(w->state == OYSTER_THREAD_STATE_DEAD) - { - goto theEnd; - } - else if(w->state == OYSTER_THREAD_STATE_RESET) - { - goto theBegining; - } - else if(w->msec > 0) - { - std::this_thread::sleep_for(std::chrono::milliseconds(w->msec)); - } - - while (w->state == OYSTER_THREAD_STATE_PAUSED) - { - std::this_thread::yield(); + case Oyster::Thread::OYSTER_THREAD_PRIORITY_2: + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + break; + case Oyster::Thread::OYSTER_THREAD_PRIORITY_3: + std::this_thread::yield(); + break; } + if(w->owner) shouldContinue = w->owner->DoWork(); + + if(w->state == OYSTER_THREAD_STATE_RESET) goto theBegining; + else if(w->msec > 0) std::this_thread::sleep_for(std::chrono::milliseconds(w->msec)); + + while (w->state == OYSTER_THREAD_STATE_PAUSED) std::this_thread::yield(); } if(w->state == OYSTER_THREAD_STATE_DEAD) { - w->workerThread->detach(); + if(w->workerThread->joinable()) w->workerThread->detach(); + return; } -theEnd: - -// w->mutexLock.LockMutex(); - if(w->owner) - { - w->owner->ThreadExit(); - } -// w->mutexLock.UnlockMutex(); - +//theEnd: + + if(w->owner) w->owner->ThreadExit(); w->state = OYSTER_THREAD_STATE_DEAD; } @@ -159,6 +143,8 @@ OysterThread::OysterThread(const OysterThread& original) } const OysterThread& OysterThread::operator=(const OysterThread& original) { + delete this->privateData; + this->privateData = new PrivateData(*original.privateData); return *this; } OysterThread::~OysterThread() @@ -200,7 +186,7 @@ OYSTER_THREAD_ERROR OysterThread::Start() this->privateData->threadData->state = OYSTER_THREAD_STATE_RUNNING; return OYSTER_THREAD_ERROR_SUCCESS; } -void OysterThread::Stop() +void OysterThread::Stop(bool wait) { //this->privateData->threadData->mutexLock.LockMutex(); this->privateData->threadData->state = OYSTER_THREAD_STATE_STOPED; @@ -221,10 +207,8 @@ void OysterThread::Pause(int msec) } else { - //this->privateData->threadData->mutexLock.LockMutex(); this->privateData->threadData->state = OYSTER_THREAD_STATE_PAUSED; this->privateData->threadData->msec = msec; - //this->privateData->threadData->mutexLock.UnlockMutex(); } } void OysterThread::Resume() @@ -246,26 +230,35 @@ OYSTER_THREAD_ERROR OysterThread::Reset(IThreadObject* worker) return OYSTER_THREAD_ERROR_SUCCESS; } -void OysterThread::Terminate() +void OysterThread::Terminate(bool wait) { this->privateData->threadData->state = OYSTER_THREAD_STATE_DEAD; } void OysterThread::Wait() { if(this->privateData->threadData->state == OYSTER_THREAD_STATE_DEAD) - { - return; - } + { return; } - if(this->privateData->threadData->workerThread->get_id() == std::this_thread::get_id()) return; + if( this->privateData->threadData->workerThread + && + this->privateData->threadData->workerThread->get_id() == std::this_thread::get_id()) + return; - this->privateData->threadData->workerThread->join(); + //if(this->privateData->threadData->state == OYSTER_THREAD_STATE_STOPED) + if(this->privateData->threadData->first) + { return; } + + if(this->privateData->threadData->workerThread) + if(this->privateData->threadData->workerThread->joinable()) + this->privateData->threadData->workerThread->join(); } void OysterThread::Wait(int msec) { if(this->privateData->threadData->workerThread->get_id() == std::this_thread::get_id()) return; - std::this_thread::sleep_for(std::chrono::milliseconds(msec)); + //TODO: Sync with thread. + + //std::this_thread::sleep_for(std::chrono::milliseconds(msec)); } OYSTER_THREAD_ERROR OysterThread::Swap(const OysterThread* other) { @@ -279,4 +272,8 @@ bool OysterThread::IsActive() return false; } +void OysterThread::SetPriority(OYSTER_THREAD_PRIORITY priority) +{ + this->privateData->threadData->prio = priority; +} diff --git a/Code/Misc/Utilities-Impl.h b/Code/Misc/Utilities-Impl.h index cc82c959..6567d9eb 100644 --- a/Code/Misc/Utilities-Impl.h +++ b/Code/Misc/Utilities-Impl.h @@ -208,6 +208,12 @@ namespace Utility template SmartPointer::SmartPointer() :_rc(0), _ptr(0) { } + template SmartPointer::SmartPointer(UniquePointer& p) + :_ptr(p.Release()) + { + this->_rc = new ReferenceCount(); + this->_rc->Incref(); + } template SmartPointer::SmartPointer(T* p) :_ptr(p) { @@ -222,10 +228,7 @@ namespace Utility } template SmartPointer::~SmartPointer() { - if (this->_rc && this->_rc->Decref() == 0) - { - Destroy(); - } + this->Release(); } template SmartPointer& SmartPointer::operator= (const SmartPointer& p) { @@ -244,6 +247,30 @@ namespace Utility } return *this; } + template SmartPointer& SmartPointer::operator= (UniquePointer& p) + { + //Last to go? + if(this->_rc) + { + if(this->_rc->Decref() == 0) + { + //Call child specific + Destroy(); + this->_rc = new ReferenceCount(); + } + } + else + { + if(p) this->_rc = new ReferenceCount(); + } + + if(this->_rc) + this->_rc->Incref(); + + this->_ptr = p.Release(); + + return *this; + } template SmartPointer& SmartPointer::operator= (T* p) { if (this->_ptr != p) @@ -266,27 +293,51 @@ namespace Utility } return *this; } - template inline bool SmartPointer::operator== (const SmartPointer& d) + template inline bool SmartPointer::operator== (const SmartPointer& d) const { return d._ptr == this->_ptr; } - template inline bool SmartPointer::operator== (const T& p) + template inline bool SmartPointer::operator== (const T& p) const { return &p == this->_ptr; } + template inline bool SmartPointer::operator!= (const SmartPointer& d) const + { + return d._ptr != this->_ptr; + } + template inline bool SmartPointer::operator!= (const T& p) const + { + return &p != this->_ptr; + } template inline T& SmartPointer::operator* () { return *this->_ptr; } + template inline const T& SmartPointer::operator* () const + { + return *this->_ptr; + } template inline T* SmartPointer::operator-> () { return this->_ptr; } - template inline SmartPointer::operator T* () + template inline const T* SmartPointer::operator-> () const { return this->_ptr; } - template inline SmartPointer::operator bool() + template inline SmartPointer::operator T* () const + { + return this->_ptr; + } + template inline SmartPointer::operator const T* () const + { + return this->_ptr; + } + template inline SmartPointer::operator T& () const + { + return *this->_ptr; + } + template inline SmartPointer::operator bool() const { return (this->_ptr != 0); } @@ -294,7 +345,21 @@ namespace Utility { return this->_ptr; } - template inline bool SmartPointer::IsValid() + template inline T* SmartPointer::Get() const + { + return this->_ptr; + } + template int SmartPointer::Release() + { + int returnVal = 0; + + if(this->_rc && ((returnVal = this->_rc->Decref()) == 0)) + { + Destroy(); + } + return returnVal; + } + template inline bool SmartPointer::IsValid() const { return (this->_ptr != NULL) ? true : false; } diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index 6112bea1..e427d0b3 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -205,27 +205,41 @@ namespace Utility public: SmartPointer(); + SmartPointer(UniquePointer& up); SmartPointer(T* p); SmartPointer(const SmartPointer& d); virtual~SmartPointer(); SmartPointer& operator= (const SmartPointer& p); + SmartPointer& operator= (UniquePointer& p); SmartPointer& operator= (T* p); - bool operator== (const SmartPointer& d); - bool operator== (const T& p); + bool operator== (const SmartPointer& d) const; + bool operator== (const T& p) const; + bool operator!= (const SmartPointer& d) const; + bool operator!= (const T& p) const; T& operator* (); + const T& operator* () const; T* operator-> (); - operator T* (); - operator bool(); + const T* operator-> () const; + operator T* () const; + operator const T* () const; + operator T& () const; + operator bool() const; /** * Returns the connected pointer */ T* Get(); + T* Get() const; + + /** + * Releases one reference of the pointer and set value to null, making the current SmartPointer invalid. + */ + int Release(); /** Checks if the pointer is valid (not NULL) * Returns true for valid, else false. */ - bool IsValid(); + bool IsValid() const; }; } diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index 6160d674..1933d907 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -13,12 +13,34 @@ struct CustomNetProtocol::PrivateData PrivateData() { } + PrivateData( const CustomNetProtocol::PrivateData& o) + { + for (auto i = o.attributes.begin(); i != o.attributes.end(); i++) + { + if(i->second.type == NetAttributeType_CharArray) + { + size_t size = strlen(i->second.value.netCharPtr); + if(size == 0) continue; + + attributes[i->first]; + attributes[i->first].value.netCharPtr = new char[size + 1]; + //strcpy_s(attributes[i->first].value.netCharPtr, size + 1, i->second.value.netCharPtr); + memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1); + } + else + { + attributes[i->first] = i->second; + } + } + attributes = o.attributes; + } ~PrivateData() { for (auto i = attributes.begin(); i != attributes.end(); i++) { RemoveAttribute(i->first); } + attributes.clear(); } void RemoveAttribute(int ID) { @@ -28,7 +50,8 @@ struct CustomNetProtocol::PrivateData switch (i->second.type) { case NetAttributeType_CharArray: - delete [] i->second.value.netCharPtr; + //delete [] i->second.value.netCharPtr; + i->second.value.netCharPtr = 0; break; } } @@ -41,6 +64,16 @@ CustomNetProtocol::CustomNetProtocol() { this->privateData = new PrivateData(); } +CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o) +{ + this->privateData = new PrivateData(*o.privateData); +} +const CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o) +{ + delete this->privateData; + this->privateData = new PrivateData(*o.privateData); + return *this; +} CustomNetProtocol::~CustomNetProtocol() { delete this->privateData; diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index c1678cf9..d25c23e5 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -5,6 +5,7 @@ #define NETWORK_CUSTOM_NETWORK_PROTOCOL_H #include +#include #ifdef CUSTOM_NET_PROTOCOL_EXPORT #define NET_PROTOCOL_EXPORT __declspec(dllexport) @@ -82,6 +83,8 @@ namespace Oyster public: CustomNetProtocol(); ~CustomNetProtocol(); + CustomNetProtocol(const CustomNetProtocol& o); + const CustomNetProtocol& operator=(const CustomNetProtocol& o); NetAttributeContainer& operator[](int ID); diff --git a/Code/Network/NetworkAPI/NetworkCallbackHelper.h b/Code/Network/NetworkAPI/NetworkCallbackHelper.h index e4f6bc9f..c99f2c5f 100644 --- a/Code/Network/NetworkAPI/NetworkCallbackHelper.h +++ b/Code/Network/NetworkAPI/NetworkCallbackHelper.h @@ -30,7 +30,7 @@ namespace Oyster typedef void(*ProtocolRecieverFunction)(CustomNetProtocol& protocol); struct ClientConnectedObject { - virtual void ClientConnectCallback(NetworkClient &client) = 0; + virtual void ClientConnectCallback(NetworkClient& client) = 0; }; struct ProtocolRecieverObject { diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 590a6aa2..aed1046f 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -23,28 +23,13 @@ using namespace Utility::DynamicMemory; /************************************* PrivateData *************************************/ - -struct NetworkClient::PrivateData : public IThreadObject +struct ClientDataContainer { - PrivateData(); - PrivateData(unsigned int socket); - ~PrivateData(); - - void Start(); - - void Send(CustomNetProtocol& protocol); //Is called from the outside to add messages to send. - - //Called on from the thread - int Send(); - int Recv(); - - bool DoWork(); - - SmartPointer connection; + Connection connection; SmartPointer> sendPostBox; - SmartPointer recvObj; + RecieverObject recvObj; NetworkProtocolCallbackType callbackType; Oyster::Thread::OysterThread thread; @@ -56,125 +41,116 @@ struct NetworkClient::PrivateData : public IThreadObject //ID static unsigned int currID; const unsigned int ID; + + ClientDataContainer(IThreadObject* o) + : ID(currID++) + { + InitWinSock(); + callbackType = NetworkProtocolCallbackType_Unknown; + sendPostBox = new PostBox(); + connection.SetBlockingMode(false); + } + ClientDataContainer(IThreadObject* o, unsigned int socket ) + :connection(socket), ID(currID++) + { + InitWinSock(); + callbackType = NetworkProtocolCallbackType_Unknown; + sendPostBox = new PostBox(); + connection.SetBlockingMode(false); + } + ~ClientDataContainer() + { + thread.Stop(); + thread.Wait(); + connection.Disconnect(); + callbackType = NetworkProtocolCallbackType_Unknown; + + ShutdownWinSock(); + } + +}; +unsigned int ClientDataContainer::currID = 0; + +struct NetworkClient::PrivateData : public IThreadObject +{ + Utility::DynamicMemory::SmartPointer data; + + PrivateData() { this->data = new ClientDataContainer(this); } + PrivateData(unsigned int socket) { this->data = new ClientDataContainer(this, socket); } + ~PrivateData() { } + + bool DoWork() + { + if(!this->data)return true; + if(!this->data->connection.IsConnected()) return true; + + Send(); + Recv(); + + return true; + } + + void Send(CustomNetProtocol* protocol) + { + if(!data) return; + + this->data->postBoxMutex.lock(); + this->data->sendPostBox->PostMessage(*protocol); + this->data->postBoxMutex.unlock(); + } + + int Send() + { + int errorCode = 0; + if(!data) return -1; + + this->data->postBoxMutex.lock(); + if(this->data->sendPostBox->IsFull()) + { + SmartPointer temp = new OysterByte(); + this->data->translator.Pack(temp, this->data->sendPostBox->FetchMessage()); + errorCode = this->data->connection.Send(temp); + } + this->data->postBoxMutex.unlock(); + + return errorCode; + } + + int Recv() + { + int errorCode = -1; + + if(this->data->callbackType == NetworkProtocolCallbackType_Function) + { + OysterByte temp = OysterByte(); + errorCode = this->data->connection.Recieve(temp); + + if(errorCode == 0) + { + CustomNetProtocol protocol; + bool ok = this->data->translator.Unpack(protocol, temp); + + //Check if the protocol was unpacked correctly + if(ok) + { + this->data->recvObjMutex.lock(); + if(this->data->callbackType == NetworkProtocolCallbackType_Function) + { + this->data->recvObj.protocolRecieverFnc(protocol); + } + else if(this->data->callbackType == NetworkProtocolCallbackType_Object) + { + this->data->recvObj.protocolRecievedObject->ProtocolRecievedCallback(protocol); + } + this->data->recvObjMutex.unlock(); + } + } + } + return errorCode; + } + }; -unsigned int NetworkClient::PrivateData::currID = 0; - -NetworkClient::PrivateData::PrivateData() : ID(currID++) -{ - InitWinSock(); - - callbackType = NetworkProtocolCallbackType_Unknown; - - connection = new Connection(); - sendPostBox = new PostBox; - this->thread.Create(this, false); - - Start(); -} - -NetworkClient::PrivateData::PrivateData(unsigned int socket) : ID(currID++) -{ - InitWinSock(); - - callbackType = NetworkProtocolCallbackType_Unknown; - - connection = new Connection(socket); - sendPostBox = new PostBox; - this->thread.Create(this, false); - - connection->SetBlockingMode(false); - - Start(); -} - -NetworkClient::PrivateData::~PrivateData() -{ - thread.Stop(); - - /*if(connection) - { - delete connection; - connection = NULL; - }*/ - - /*if(sendPostBox) - { - delete sendPostBox; - sendPostBox = NULL; - }*/ - - callbackType = NetworkProtocolCallbackType_Unknown; - - ShutdownWinSock(); -} - -bool NetworkClient::PrivateData::DoWork() -{ - Send(); - Recv(); - - return true; -} - -void NetworkClient::PrivateData::Send(CustomNetProtocol& protocol) -{ - postBoxMutex.lock(); - sendPostBox->PostMessage(protocol); - postBoxMutex.unlock(); -} - -int NetworkClient::PrivateData::Send() -{ - int errorCode = 0; - - postBoxMutex.lock(); - if(sendPostBox->IsFull()) - { - SmartPointer temp = new OysterByte; - this->translator.Pack(temp, sendPostBox->FetchMessage()); - errorCode = this->connection->Send(temp); - } - postBoxMutex.unlock(); - - return errorCode; -} - -int NetworkClient::PrivateData::Recv() -{ - int errorCode = -1; - - SmartPointer temp = new OysterByte; - errorCode = this->connection->Recieve(temp); - - if(errorCode == 0) - { - CustomNetProtocol protocol; - bool ok = translator.Unpack(protocol, temp); - - //Check if the protocol was unpacked correctly - if(ok) - { - recvObjMutex.lock(); - if(callbackType == NetworkProtocolCallbackType_Function) - { - recvObj->protocolRecieverFnc(protocol); - } - else if(callbackType == NetworkProtocolCallbackType_Object) - { - recvObj->protocolRecievedObject->ProtocolRecievedCallback(protocol); - } - recvObjMutex.unlock(); - } - } - - return errorCode; -} - -void NetworkClient::PrivateData::Start() -{ - this->thread.Start(); -} /************************************* NetworkClient @@ -193,28 +169,25 @@ NetworkClient::NetworkClient(unsigned int socket) NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type) { privateData = new PrivateData(); - this->privateData->recvObj = SmartPointer(&recvObj);; + this->privateData->data->recvObj = SmartPointer(&recvObj);; } NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type, unsigned int socket) { privateData = new PrivateData(socket); - this->privateData->recvObj = SmartPointer(&recvObj); - this->privateData->callbackType = type; + this->privateData->data->recvObj = SmartPointer(&recvObj); + this->privateData->data->callbackType = type; } NetworkClient::NetworkClient(const NetworkClient& obj) { - this->privateData = new PrivateData(); - - this->privateData = obj.privateData; + this->privateData = new PrivateData(*obj.privateData); } NetworkClient& NetworkClient::operator =(const NetworkClient& obj) { delete privateData; - this->privateData = new PrivateData(); - this->privateData = obj.privateData; + this->privateData = new PrivateData(*obj.privateData); return *this; } @@ -229,16 +202,16 @@ NetworkClient::~NetworkClient() bool NetworkClient::Connect(unsigned short port, const char serverIP[]) { - int result = this->privateData->connection->Connect(port, serverIP); + int result = this->privateData->data->connection.Connect(port, serverIP); //Connect has succeeded if(result == 0) { - privateData->Start(); + privateData->data->thread.Start(); return true; } - privateData->connection->SetBlockingMode(false); + privateData->data->connection.SetBlockingMode(false); //Connect has failed return false; @@ -246,28 +219,40 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[]) void NetworkClient::Disconnect() { - privateData->connection->Disconnect(); + privateData->data->connection.Disconnect(); } bool NetworkClient::IsConnected() { - return privateData->connection->IsConnected(); + return privateData->data->connection.IsConnected(); } void NetworkClient::Send(CustomProtocolObject& protocol) { - this->privateData->Send(*protocol.GetProtocol()); + this->privateData->Send(protocol.GetProtocol()); } void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type) { - privateData->recvObjMutex.lock(); - privateData->recvObj = SmartPointer(&recvObj); - privateData->callbackType = type; - privateData->recvObjMutex.unlock(); + if (type == NetworkProtocolCallbackType_Unknown) return; + + privateData->data->recvObjMutex.lock(); + privateData->data->recvObj = recvObj; + privateData->data->callbackType = type; + privateData->data->recvObjMutex.unlock(); } bool NetworkClient::operator ==(const NetworkClient& obj) { - return (this->privateData->ID == obj.privateData->ID); + return (this->privateData->data->ID == obj.privateData->data->ID); +} + +bool NetworkClient::operator ==(const int& ID) +{ + return this->privateData->data->ID == ID; +} + +int NetworkClient::Id() const +{ + return this->privateData->data->ID; } \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 7d4928f4..95463d1c 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -12,6 +12,7 @@ #endif #include "NetworkCallbackHelper.h" +#include namespace Oyster { @@ -44,6 +45,9 @@ namespace Oyster //Compares the internal ID. bool operator ==(const NetworkClient& obj); + bool operator ==(const int& ID); + + int Id() const; private: struct PrivateData; diff --git a/Code/Network/NetworkAPI/NetworkServer.h b/Code/Network/NetworkAPI/NetworkServer.h index 5f6f7f3c..8edc59ff 100644 --- a/Code/Network/NetworkAPI/NetworkServer.h +++ b/Code/Network/NetworkAPI/NetworkServer.h @@ -13,6 +13,7 @@ #include "NetworkClient.h" #include "NetworkCallbackHelper.h" +#include namespace Oyster { diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp index 28b62dd8..75598b75 100644 --- a/Code/Network/NetworkAPI/Translator.cpp +++ b/Code/Network/NetworkAPI/Translator.cpp @@ -17,28 +17,6 @@ using namespace std; struct MyCastingStruct { std::map attributes; - - /*MyCastingStruct() - { } - ~MyCastingStruct() - { - for (auto i = attributes.begin(); i != attributes.end(); i++) - { - RemoveAttribute(i->first); - } - } - void RemoveAttribute(int ID) - { - auto i = attributes.find(ID); - if(i == attributes.end()) return; - - switch (i->second.type) - { - case NetAttributeType_CharArray: - delete [] i->second.value.netCharPtr; - break; - } - }*/ }; // TODO: Check if the package has been packed correctly. @@ -221,6 +199,16 @@ Translator::~Translator() privateData = NULL; } } +Translator::Translator(const Translator& obj) +{ + this->privateData = new PrivateData(*obj.privateData); +} +const Translator& Translator::operator=(const Translator& obj) +{ + delete this->privateData; + this->privateData = new PrivateData(*obj.privateData); + return *this; +} void Translator::Pack(OysterByte &bytes, CustomNetProtocol& protocol) { diff --git a/Code/Network/NetworkAPI/Translator.h b/Code/Network/NetworkAPI/Translator.h index aed765f8..f413492e 100644 --- a/Code/Network/NetworkAPI/Translator.h +++ b/Code/Network/NetworkAPI/Translator.h @@ -48,6 +48,8 @@ namespace Oyster public: Translator (); ~Translator(); + Translator(const Translator& obj); + const Translator& operator=(const Translator& obj); void Pack(OysterByte &bytes, CustomNetProtocol& protocol); diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index bf0b108e..84a0cbcc 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -9,7 +9,7 @@ using namespace Oyster::Network; Connection::Connection() { - this->socket = 0; + this->socket = -1; bool stillSending = false; bool closed = true; } diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index b82694d3..20d4c927 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -19,7 +19,9 @@ Listener::~Listener() { if(connection) { + this->thread.Terminate(); delete connection; + connection = 0; } } diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index b2f4c4bd..45e59e3a 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -37,7 +37,11 @@ int main() NetworkClient client; //Connect to server - if(client.Connect(15151, "localhost")) + //errorCode = client->Connect(15151, "193.11.186.101"); + errorCode = client.Connect(15151, "127.0.0.1"); + client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); + + if(errorCode != 0) { cout << "FAILED" << endl; } diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp.BACKUP.7056.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp.BACKUP.7056.cpp new file mode 100644 index 00000000..581f41ad --- /dev/null +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp.BACKUP.7056.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include "../NetworkDependencies/WinsockFunctions.h" +#include "..\NetworkDependencies\Protocols.h" +#include "../NetworkDependencies/OysterByte.h" +#include "../../Misc/ThreadSafeQueue.h" +#include "../NetworkDependencies/ThreadedClient.h" +#include "../../Misc/WinTimer.h" +#include "../../Misc/Utilities.h" +#include "../NetworkAPI/NetworkClient.h" + +#pragma comment(lib, "ws2_32.lib") + +using namespace std; +using namespace Oyster::Network::Protocols; +using namespace Oyster::Network; +using namespace Utility; +using namespace Utility::DynamicMemory; + +void proc(CustomNetProtocol& protocol) +{ + +} + +int main() +{ + int errorCode; + + char msgRecv[255] = "\0"; + + InitWinSock(); + + cout << "Client" << endl; + + //Create Client + NetworkClient client; + + //Connect to server +<<<<<<< HEAD + if(client.Connect(15151, "localhost")) +======= + //errorCode = client->Connect(15151, "193.11.186.101"); + errorCode = client.Connect(15151, "127.0.0.1"); + client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); + + if(errorCode != 0) +>>>>>>> 9eb8fcba40e4dec4f338cd012ba69bc15d456cc9 + { + cout << "FAILED" << endl; + } + client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); + + cout << "Done" << endl; + + while(1) + { + + } + + ShutdownWinSock(); + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp.BASE.7056.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp.BASE.7056.cpp new file mode 100644 index 00000000..2b75c92d --- /dev/null +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp.BASE.7056.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include "../NetworkDependencies/WinsockFunctions.h" +#include "..\NetworkDependencies\Protocols.h" +#include "../NetworkDependencies/OysterByte.h" +#include "../../Misc/ThreadSafeQueue.h" +#include "../NetworkDependencies/ThreadedClient.h" +#include "../../Misc/WinTimer.h" +#include "../../Misc/Utilities.h" +#include "../NetworkAPI/NetworkClient.h" + +#pragma comment(lib, "ws2_32.lib") + +using namespace std; +using namespace Oyster::Network::Protocols; +using namespace Oyster::Network; +using namespace Utility; +using namespace Utility::DynamicMemory; + +void chat(ThreadedClient &client); +void PrintOutMessage(ProtocolSet* set); + +void proc(CustomNetProtocol& protocol) +{ + +} + +int main() +{ + int errorCode; + + char msgRecv[255] = "\0"; + + InitWinSock(); + + cout << "Client" << endl; + + //Create Client + NetworkClient client; + + //Connect to server + errorCode = client.Connect(15151, "193.11.186.101"); + client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); + + if(errorCode != 0) + { + wstring errorTest = GetErrorMessage(errorCode); + wcout << "errorMessage: " << errorTest << endl; + } + + while(1) + { + + } + + ShutdownWinSock(); + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp.LOCAL.7056.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp.LOCAL.7056.cpp new file mode 100644 index 00000000..b2f4c4bd --- /dev/null +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp.LOCAL.7056.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include "../NetworkDependencies/WinsockFunctions.h" +#include "..\NetworkDependencies\Protocols.h" +#include "../NetworkDependencies/OysterByte.h" +#include "../../Misc/ThreadSafeQueue.h" +#include "../NetworkDependencies/ThreadedClient.h" +#include "../../Misc/WinTimer.h" +#include "../../Misc/Utilities.h" +#include "../NetworkAPI/NetworkClient.h" + +#pragma comment(lib, "ws2_32.lib") + +using namespace std; +using namespace Oyster::Network::Protocols; +using namespace Oyster::Network; +using namespace Utility; +using namespace Utility::DynamicMemory; + +void proc(CustomNetProtocol& protocol) +{ + +} + +int main() +{ + int errorCode; + + char msgRecv[255] = "\0"; + + InitWinSock(); + + cout << "Client" << endl; + + //Create Client + NetworkClient client; + + //Connect to server + if(client.Connect(15151, "localhost")) + { + cout << "FAILED" << endl; + } + client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); + + cout << "Done" << endl; + + while(1) + { + + } + + ShutdownWinSock(); + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp.REMOTE.7056.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp.REMOTE.7056.cpp new file mode 100644 index 00000000..2274fb5e --- /dev/null +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp.REMOTE.7056.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include "../NetworkDependencies/WinsockFunctions.h" +#include "..\NetworkDependencies\Protocols.h" +#include "../NetworkDependencies/OysterByte.h" +#include "../../Misc/ThreadSafeQueue.h" +#include "../NetworkDependencies/ThreadedClient.h" +#include "../../Misc/WinTimer.h" +#include "../../Misc/Utilities.h" +#include "../NetworkAPI/NetworkClient.h" + +#pragma comment(lib, "ws2_32.lib") + +using namespace std; +using namespace Oyster::Network::Protocols; +using namespace Oyster::Network; +using namespace Utility; +using namespace Utility::DynamicMemory; + +void chat(ThreadedClient &client); +void PrintOutMessage(ProtocolSet* set); + +void proc(CustomNetProtocol& protocol) +{ + +} + +int main() +{ + int errorCode; + + char msgRecv[255] = "\0"; + + InitWinSock(); + + cout << "Client" << endl; + + //Create Client + NetworkClient client; + + //Connect to server + //errorCode = client->Connect(15151, "193.11.186.101"); + errorCode = client.Connect(15151, "127.0.0.1"); + client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); + + if(errorCode != 0) + { + wstring errorTest = GetErrorMessage(errorCode); + wcout << "errorMessage: " << errorTest << endl; + } + + while(1) + { + + } + + ShutdownWinSock(); + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index 0495939d..8bca1c19 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -11,6 +11,27 @@ #include "Quaternion.h" #include +namespace std +{ + template + inline ::LinearAlgebra::Vector2 asin( const ::LinearAlgebra::Vector2 &vec ) + { + return ::LinearAlgebra::Vector2( asin(vec.x), asin(vec.y) ); + } + + template + inline ::LinearAlgebra::Vector3 asin( const ::LinearAlgebra::Vector3 &vec ) + { + return ::LinearAlgebra::Vector3( asin(vec.x), asin(vec.y), asin(vec.z) ); + } + + template + inline ::LinearAlgebra::Vector4 asin( const ::LinearAlgebra::Vector4 &vec ) + { + return ::LinearAlgebra::Vector4( asin(vec.x), asin(vec.y), asin(vec.z), asin(vec.w) ); + } +} + // x2 template @@ -233,6 +254,18 @@ namespace LinearAlgebra2D namespace LinearAlgebra3D { + template + inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix ) + { + return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) ); + } + + template + inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix4x4 &rotationMatrix ) + { + return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) ); + } + template inline ::LinearAlgebra::Matrix4x4 & TranslationMatrix( const ::LinearAlgebra::Vector3 &position, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { @@ -286,7 +319,9 @@ namespace LinearAlgebra3D template inline ::LinearAlgebra::Matrix3x3 & RotationMatrix_AxisZ( const ScalarType &radian, ::LinearAlgebra::Matrix3x3 &targetMem = ::LinearAlgebra::Matrix3x3() ) - { return ::LinearAlgebra2D::RotationMatrix( radian, targetMem ); } + { + return ::LinearAlgebra2D::RotationMatrix( radian, targetMem ); + } template inline ::LinearAlgebra::Matrix4x4 & RotationMatrix_AxisZ( const ScalarType &radian, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) @@ -300,7 +335,21 @@ namespace LinearAlgebra3D } template - ::LinearAlgebra::Matrix4x4 & RotationMatrix( const ::LinearAlgebra::Vector3 &normalizedAxis, const ScalarType &radian, ::LinearAlgebra::Matrix4x4 &targetMem ) + inline ::LinearAlgebra::Matrix4x4 RotationMatrix( const ::LinearAlgebra::Vector3 &angularAxis ) + { + ScalarType radian = angularAxis.GetMagnitude(); + if( radian != 0 ) + { + return RotationMatrix( angularAxis / radian, radian ); + } + else + { + return ::LinearAlgebra::Matrix4x4::identity; + } + } + + template + ::LinearAlgebra::Matrix4x4 & RotationMatrix( const ::LinearAlgebra::Vector3 &normalizedAxis, const ScalarType &radian, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { /// TODO: not verified ScalarType r = radian * 0.5f, s = std::sin( r ), @@ -462,7 +511,7 @@ namespace LinearAlgebra3D ::LinearAlgebra::Matrix4x4 & ProjectionMatrix_Perspective( const ScalarType &vertFoV, const ScalarType &aspect, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ), - dDepth = farClip / (farClip - nearClip); + dDepth = farClip / (farClip - nearClip); return targetMem = ::LinearAlgebra::Matrix4x4( fov / aspect, 0, 0, 0, 0, fov, 0, 0, 0, 0, dDepth, -(dDepth * nearClip), @@ -473,7 +522,7 @@ namespace LinearAlgebra3D ::LinearAlgebra::Matrix4x4 & ProjectionMatrix_Perspective( const ScalarType &left, const ScalarType &right, const ScalarType &top, const ScalarType &bottom, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { /** @todo TODO: not tested */ ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ), - dDepth = farClip / (farClip - nearClip); + dDepth = farClip / (farClip - nearClip); return targetMem = ::LinearAlgebra::Matrix4x4( 2*nearClip/(right - left), 0, -(right + left)/(right - left), 0, 0, 2*nearClip/(top - bottom), -(top + bottom)/(top - bottom), 0, 0, 0, dDepth, -(dDepth * nearClip), diff --git a/Code/OysterMath/OysterMath.cpp b/Code/OysterMath/OysterMath.cpp index a82658ee..cf9fa8ae 100644 --- a/Code/OysterMath/OysterMath.cpp +++ b/Code/OysterMath/OysterMath.cpp @@ -81,20 +81,45 @@ namespace Oyster { namespace Math2D namespace Oyster { namespace Math3D { + Float4 AngularAxis( const Float3x3 &rotationMatrix ) + { + return ::LinearAlgebra3D::AngularAxis( rotationMatrix ); + } + + Float4 AngularAxis( const Float4x4 &rotationMatrix ) + { + return ::LinearAlgebra3D::AngularAxis( rotationMatrix ); + } + Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::TranslationMatrix( position, targetMem ); } + { + return ::LinearAlgebra3D::TranslationMatrix( position, targetMem ); + } Float4x4 & RotationMatrix_AxisX( const Float &radian, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix_AxisX( radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix_AxisX( radian, targetMem ); + } Float4x4 & RotationMatrix_AxisY( const Float &radian, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix_AxisY( radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix_AxisY( radian, targetMem ); + } Float4x4 & RotationMatrix_AxisZ( const Float &radian, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix_AxisZ( radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix_AxisZ( radian, targetMem ); + } + + Float4x4 & RotationMatrix( const Float3 &angularAxis, Float4x4 &targetMem ) + { + return targetMem = ::LinearAlgebra3D::RotationMatrix( angularAxis ); + } Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix( normalizedAxis, radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix( normalizedAxis, radian, targetMem ); + } Float3x3 & InverseRotationMatrix( const Float3x3 &rotation, Float3x3 &targetMem ) { @@ -103,7 +128,8 @@ namespace Oyster { namespace Math3D Float4x4 & InverseRotationMatrix( const Float4x4 &rotation, Float4x4 &targetMem ) { - return targetMem = ::LinearAlgebra3D::InverseRotationMatrix( rotation ); +// return targetMem = ::LinearAlgebra3D::InverseRotationMatrix( rotation ); + return targetMem = rotation.GetTranspose(); } Float4x4 & OrientationMatrix( const Float3x3 &rotation, const Float3 &translation, Float4x4 &targetMem ) diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index ab3b307f..72fe7478 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -147,6 +147,12 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized { using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace + //! Extracts the angularAxis from rotationMatrix + Float4 AngularAxis( const Float3x3 &rotationMatrix ); + + //! Extracts the angularAxis from rotationMatrix + Float4 AngularAxis( const Float4x4 &rotationMatrix ); + /// Sets and returns targetMem to a translationMatrix with position as translation. Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() ); @@ -159,6 +165,9 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized /// Sets and returns targetMem as an counterclockwise rotation matrix around the global Z-axis Float4x4 & RotationMatrix_AxisZ( const Float &radian, Float4x4 &targetMem = Float4x4() ); + /// Sets and returns targetMem as an counterclockwise rotation matrix around the angularAxis. + Float4x4 & RotationMatrix( const Float3 &angularAxis, Float4x4 &targetMem = Float4x4() ); + /// Sets and returns targetMem as an counterclockwise rotation matrix around the normalizedAxis. /// Please make sure normalizedAxis is normalized. Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem = Float4x4() ); diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 131cad62..5df9761c 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -393,8 +393,8 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const BoxAxisAligned &box, const Sphere &sphere ) { // by Dan Andersson - Float3 e = Max( box.minVertex - sphere.center, Float3::null ); - e += Max( sphere.center - box.maxVertex, Float3::null ); + Float4 e = Max( Float4(box.minVertex - sphere.center, 0.0f), Float4::null ); + e += Max( Float4(sphere.center - box.maxVertex, 0.0f), Float4::null ); if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false; return true; @@ -459,12 +459,12 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Box &box, const Sphere &sphere ) { // by Dan Andersson - Float3 e = sphere.center - box.center, - centerL = Float3( e.Dot(box.xAxis), e.Dot(box.yAxis), e.Dot(box.zAxis) ); - - e = Max( (box.boundingOffset + centerL)*=-1.0f, Float3::null ); - e += Max( centerL - box.boundingOffset, Float3::null ); - + // center: sphere's center in the box's view space + Float4 center = TransformVector( InverseRotationMatrix(box.rotation), Float4(sphere.center - box.center, 0.0f) ); + + Float4 e = Max( Float4(-box.boundingOffset, 0.0f) - center, Float4::null ); + e += Max( center - Float4(box.boundingOffset, 0.0f), Float4::null ); + if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false; return true; } diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index cf1186c9..d81c91a3 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -38,7 +38,7 @@ bool Point::Intersects( const ICollideable &target ) const case Type_universe: return true; case Type_point: return Utility::Intersect( *this, *(Point*)&target ); case Type_ray: return Utility::Intersect( *(Ray*)&target, *this, ((Ray*)&target)->collisionDistance ); - case Type_sphere: Utility::Intersect( *(Sphere*)&target, *this ); + case Type_sphere: return Utility::Intersect( *(Sphere*)&target, *this ); case Type_plane: return Utility::Intersect( *(Plane*)&target, *this ); //case Type_triangle: return false; // TODO: case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this ); diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp index 09fb13ec..79e4dbd5 100644 --- a/Code/OysterPhysics3D/Ray.cpp +++ b/Code/OysterPhysics3D/Ray.cpp @@ -60,7 +60,7 @@ bool Ray::Contains( const ICollideable &target ) const switch( target.type ) { case Type_point: return Utility::Intersect( *this, *(Point*)&target, this->collisionDistance ); - case Type_ray: Utility::Contains( *this, *(Ray*)&target ); + case Type_ray: return Utility::Contains( *this, *(Ray*)&target ); default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index 0cc8bc3b..4f6f76f7 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -35,7 +35,7 @@ bool Sphere::Intersects( const ICollideable &target ) const case Type_universe: return true; case Type_point: return Utility::Intersect( *this, *(Point*)&target ); case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance ); - case Type_sphere: Utility::Intersect( *this, *(Sphere*)&target ); + case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target ); case Type_plane: return Utility::Intersect( *(Plane*)&target, *this ); // case Type_triangle: return false; // TODO: case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this ); 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