diff --git a/Bin/Settings/PLACEHOLDER b/Bin/Content/Models/PLACEHOLDER similarity index 100% rename from Bin/Settings/PLACEHOLDER rename to Bin/Content/Models/PLACEHOLDER diff --git a/Code/Network/NetworkDependencies/main.cpp b/Bin/Content/Textures/PLACEHOLDER similarity index 100% rename from Code/Network/NetworkDependencies/main.cpp rename to Bin/Content/Textures/PLACEHOLDER diff --git a/Bin/Content/crate.obj b/Bin/Content/crate.obj new file mode 100644 index 00000000..027fd2cd --- /dev/null +++ b/Bin/Content/crate.obj @@ -0,0 +1,233 @@ +# This file uses centimeters as units for non-parametric coordinates. + +mtllib crate.mtl +g default +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 0.500000 +v -0.500000 0.500000 -0.500000 +v 0.500000 0.500000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v 0.500000 0.500000 0.500000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 -0.500000 +v -0.500000 0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v -0.479379 0.522314 0.479379 +v 0.479379 0.522314 0.479379 +v 0.479379 0.522314 -0.479379 +v -0.479379 0.522314 -0.479379 +v -0.470939 -0.528599 -0.470939 +v 0.470939 -0.528599 -0.470939 +v 0.470939 -0.528599 0.470939 +v -0.470939 -0.528599 0.470939 +v 0.520103 -0.460610 -0.460610 +v 0.520103 -0.460610 0.460610 +v 0.520103 0.460610 -0.460610 +v 0.520103 0.460610 0.460610 +v -0.522559 -0.464751 -0.464751 +v -0.522559 -0.464751 0.464751 +v -0.522559 0.464751 0.464751 +v -0.522559 0.464751 -0.464751 +v -0.460954 -0.460954 0.522335 +v 0.460954 -0.460954 0.522335 +v 0.460954 0.460954 0.522335 +v -0.460954 0.460954 0.522335 +v -0.466507 0.466507 -0.525017 +v 0.466507 0.466507 -0.525017 +v 0.466507 -0.466507 -0.525017 +v -0.466507 -0.466507 -0.525017 +vt 0.995838 0.004695 +vt 0.999640 -0.003712 +vt 0.003809 -0.000160 +vt -0.000796 1.000526 +vt 0.003809 0.003892 +vt 0.999640 0.995671 +vt 0.003809 0.007944 +vt 0.999640 0.999723 +vt 0.003809 1.003774 +vt 0.999640 1.003774 +vt 0.995035 0.004695 +vt 0.995035 1.000526 +vt 0.000007 0.004695 +vt 0.000007 1.000526 +vt 0.999640 0.007944 +vt -0.000796 0.004695 +vt 0.003809 0.999723 +vt 0.003809 -0.003712 +vt 0.999640 0.003892 +vt 0.003809 0.995671 +vt 0.999640 0.992119 +vt 0.999640 -0.000160 +vt 0.003809 0.992119 +vt 0.995838 1.000526 +vt 0.003809 -0.003712 +vt 0.999640 -0.003712 +vt 0.999640 0.992119 +vt 0.003809 0.992119 +vt 0.003809 -0.000160 +vt 0.999640 -0.000160 +vt 0.999640 0.995671 +vt 0.003809 0.995671 +vt 0.003809 0.003892 +vt 0.999640 0.003892 +vt 0.999640 0.999723 +vt 0.003809 0.999723 +vt 0.003809 0.007944 +vt 0.999640 0.007944 +vt 0.999640 1.003774 +vt 0.003809 1.003774 +vt -0.000796 0.004695 +vt 0.995035 0.004695 +vt 0.995035 1.000526 +vt -0.000796 1.000526 +vt 0.000007 0.004695 +vt 0.995838 0.004695 +vt 0.995838 1.000526 +vt 0.000007 1.000526 +vt 0.003809 -0.000160 +vt 0.999640 -0.000160 +vt 0.999640 0.995671 +vt 0.003809 0.995671 +vt 0.003809 0.007944 +vt 0.999640 0.007944 +vt 0.999640 1.003774 +vt 0.003809 1.003774 +vt -0.000796 0.004695 +vt 0.995035 0.004695 +vt 0.995035 1.000526 +vt -0.000796 1.000526 +vt 0.000007 0.004695 +vt 0.995838 0.004695 +vt 0.995838 1.000526 +vt 0.000007 1.000526 +vt 0.003809 -0.003712 +vt 0.999640 -0.003712 +vt 0.999640 0.992119 +vt 0.003809 0.992119 +vt 0.003809 0.003892 +vt 0.999640 0.003892 +vt 0.999640 0.999723 +vt 0.003809 0.999723 +vn -0.031209 -0.033799 0.998941 +vn 0.033799 -0.031209 0.998941 +vn -0.033799 0.031209 0.998941 +vn 0.031209 0.033799 0.998941 +vn -0.030245 0.999045 0.031527 +vn 0.031527 0.999045 0.030245 +vn -0.031527 0.999045 -0.030245 +vn 0.030245 0.999045 -0.031527 +vn -0.034614 0.037052 -0.998714 +vn 0.037051 0.034614 -0.998714 +vn -0.037051 -0.034614 -0.998714 +vn 0.034614 -0.037052 -0.998714 +vn -0.038824 -0.998397 -0.041174 +vn 0.041174 -0.998397 -0.038824 +vn -0.041174 -0.998397 0.038824 +vn 0.038824 -0.998397 0.041174 +vn 0.999134 -0.030589 0.028224 +vn 0.999134 -0.028224 -0.030589 +vn 0.999134 0.028224 0.030589 +vn 0.999134 0.030589 -0.028224 +vn -0.998933 -0.033811 -0.031470 +vn -0.998933 -0.031470 0.033811 +vn -0.998933 0.031470 -0.033811 +vn -0.998933 0.033811 0.031470 +vn 0.577350 0.577350 -0.577350 +vn 0.577350 -0.577350 -0.577350 +vn -0.577350 0.577350 -0.577350 +vn -0.577350 -0.577350 -0.577350 +vn 0.577350 -0.577350 0.577350 +vn -0.577350 -0.577350 0.577350 +vn 0.577350 0.577350 0.577350 +vn -0.577350 0.577350 0.577350 +vn -0.608285 0.469952 0.639637 +vn 0.633500 0.454555 0.626145 +vn 0.657522 0.474071 -0.585595 +vn -0.626276 0.491669 -0.605013 +vn -0.608373 -0.534484 -0.586694 +vn 0.635292 -0.520408 -0.570596 +vn 0.616200 -0.500955 0.607735 +vn -0.589957 -0.516183 0.620891 +s 1 +g meshCrate +usemtl matCrateSG +f 33/65/1 34/66/2 36/68/3 +f 36/68/3 34/66/2 35/67/4 +f 17/49/5 18/50/6 20/52/7 +f 20/52/7 18/50/6 19/51/8 +f 37/69/9 38/70/10 40/72/11 +f 40/72/11 38/70/10 39/71/12 +f 21/53/13 22/54/14 24/56/15 +f 24/56/15 22/54/14 23/55/16 +f 26/57/17 25/58/18 28/60/19 +f 28/60/19 25/58/18 27/59/20 +f 29/61/21 30/62/22 32/64/23 +f 32/64/23 30/62/22 31/63/24 +s 7 +f 1/25/25 3/28/26 2/26/27 +f 2/26/27 3/28/26 4/27/28 +f 3/29/26 5/32/29 4/30/28 +f 4/30/28 5/32/29 6/31/30 +f 5/33/29 7/36/31 6/34/30 +f 6/34/30 7/36/31 8/35/32 +f 7/37/31 1/40/25 8/38/32 +f 8/38/32 1/40/25 2/39/27 +f 2/41/27 4/44/28 8/42/32 +f 8/42/32 4/44/28 6/43/30 +f 7/45/31 5/48/29 1/46/25 +f 1/46/25 5/48/29 3/47/26 +s 1 +f 12/3/33 11/22/34 17/49/5 +f 17/49/5 11/22/34 18/50/6 +f 11/22/34 13/6/35 18/50/6 +f 18/50/6 13/6/35 19/51/8 +f 13/6/35 14/20/36 19/51/8 +f 19/51/8 14/20/36 20/52/7 +f 14/20/36 12/3/33 20/52/7 +f 20/52/7 12/3/33 17/49/5 +f 16/7/37 15/15/38 21/53/13 +f 21/53/13 15/15/38 22/54/14 +f 15/15/38 10/10/39 22/54/14 +f 22/54/14 10/10/39 23/55/16 +f 10/10/39 9/9/40 23/55/16 +f 23/55/16 9/9/40 24/56/15 +f 9/9/40 16/7/37 24/56/15 +f 24/56/15 16/7/37 21/53/13 +f 10/16/39 15/11/38 26/57/17 +f 26/57/17 15/11/38 25/58/18 +f 15/11/38 13/12/35 25/58/18 +f 25/58/18 13/12/35 27/59/20 +f 13/12/35 11/4/34 27/59/20 +f 27/59/20 11/4/34 28/60/19 +f 11/4/34 10/16/39 28/60/19 +f 28/60/19 10/16/39 26/57/17 +f 16/13/37 9/1/40 29/61/21 +f 29/61/21 9/1/40 30/62/22 +f 9/1/40 12/24/33 30/62/22 +f 30/62/22 12/24/33 31/63/24 +f 12/24/33 14/14/36 31/63/24 +f 31/63/24 14/14/36 32/64/23 +f 14/14/36 16/13/37 32/64/23 +f 32/64/23 16/13/37 29/61/21 +f 9/18/40 10/2/39 33/65/1 +f 33/65/1 10/2/39 34/66/2 +f 10/2/39 11/21/34 34/66/2 +f 34/66/2 11/21/34 35/67/4 +f 11/21/34 12/23/33 35/67/4 +f 35/67/4 12/23/33 36/68/3 +f 12/23/33 9/18/40 36/68/3 +f 36/68/3 9/18/40 33/65/1 +f 14/5/36 13/19/35 37/69/9 +f 37/69/9 13/19/35 38/70/10 +f 13/19/35 15/8/38 38/70/10 +f 38/70/10 15/8/38 39/71/12 +f 15/8/38 16/17/37 39/71/12 +f 39/71/12 16/17/37 40/72/11 +f 16/17/37 14/5/36 40/72/11 +f 40/72/11 14/5/36 37/69/9 diff --git a/Bin/Content/tex_crate.png b/Bin/Content/tex_crate.png new file mode 100644 index 00000000..a7b0b1ef Binary files /dev/null and b/Bin/Content/tex_crate.png 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/GameLogic_x64D.pdb b/Bin/DLL/GameLogic_x64D.pdb new file mode 100644 index 00000000..6cf648dd Binary files /dev/null and b/Bin/DLL/GameLogic_x64D.pdb differ diff --git a/Bin/DLL/GamePhysics_x64D.pdb b/Bin/DLL/GamePhysics_x64D.pdb new file mode 100644 index 00000000..cafb4598 Binary files /dev/null and b/Bin/DLL/GamePhysics_x64D.pdb differ diff --git a/Bin/DLL/LightPass.cso b/Bin/DLL/LightPass.cso deleted file mode 100644 index 1764d62a..00000000 Binary files a/Bin/DLL/LightPass.cso and /dev/null 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..39d11475 Binary files /dev/null and b/Bin/DLL/NetworkAPI_x86D.pdb differ diff --git a/Bin/DLL/OysterGraphics_x64.pdb b/Bin/DLL/OysterGraphics_x64.pdb new file mode 100644 index 00000000..bb6604e9 Binary files /dev/null and b/Bin/DLL/OysterGraphics_x64.pdb differ diff --git a/Bin/DLL/OysterGraphics_x64D.pdb b/Bin/DLL/OysterGraphics_x64D.pdb new file mode 100644 index 00000000..a11ee38a Binary files /dev/null and b/Bin/DLL/OysterGraphics_x64D.pdb differ 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 2e047aee..894caec6 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -23,13 +23,26 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OysterNetworkServer", "Netw EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkDependencies", "Network\NetworkDependencies\NetworkDependencies.vcxproj", "{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameLogic", "GameLogic\GameLogic.vcxproj", "{B1195BB9-B3A5-47F0-906C-8DEA384D1520}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GamePhysics", "GamePhysics\GamePhysics.vcxproj", "{104FA3E9-94D9-4E1D-A941-28A03BC8A095}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tester", "Tester\Tester.vcxproj", "{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasGame", "DanBiasGame\DanBiasGame.vcxproj", "{2A1BC987-AF42-4500-802D-89CD32FC1309}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasGame", "Game\DanBiasGame\DanBiasGame.vcxproj", "{2A1BC987-AF42-4500-802D-89CD32FC1309}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Game", "Game", "{20720CA7-795C-45AD-A302-9383A6DD503A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameLogic", "Game\GameLogic\GameLogic.vcxproj", "{B1195BB9-B3A5-47F0-906C-8DEA384D1520}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServer", "Game\DanBiasServer\DanBiasServer.vcxproj", "{52380DAA-0F4A-4D97-8E57-98DF39319CAF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasLauncher", "Game\DanBiasLauncher\DanBiasLauncher.vcxproj", "{8690FDDF-C5B7-4C42-A337-BD5243F29B85}" + ProjectSection(ProjectDependencies) = postProject + {52380DAA-0F4A-4D97-8E57-98DF39319CAF} = {52380DAA-0F4A-4D97-8E57-98DF39319CAF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkAPI", "Network\NetworkAPI\NetworkAPI.vcxproj", "{460D625F-2AC9-4559-B809-0BA89CEAEDF4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameProtocols", "Game\GameProtocols\GameProtocols.vcxproj", "{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -41,139 +54,128 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.Build.0 = Release|Win32 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.Build.0 = Release|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Win32.ActiveCfg = Release|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Win32.Build.0 = Release|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|x64.ActiveCfg = Release|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|x64.Build.0 = Release|x64 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.Build.0 = Release|Win32 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.Build.0 = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Win32.ActiveCfg = Release|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Win32.Build.0 = Release|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|x64.ActiveCfg = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|x64.Build.0 = Release|x64 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.Build.0 = Release|Win32 + {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.Build.0 = Release|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Win32.ActiveCfg = Release|Win32 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Win32.Build.0 = Release|Win32 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|x64.ActiveCfg = Release|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|x64.Build.0 = Release|x64 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.Build.0 = Release|Win32 + {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.Build.0 = Release|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Win32.ActiveCfg = Release|Win32 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Win32.Build.0 = Release|Win32 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|x64.ActiveCfg = Release|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|x64.Build.0 = Release|x64 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.Build.0 = Release|Win32 + {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.Build.0 = Release|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Win32.ActiveCfg = Release|Win32 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Win32.Build.0 = Release|Win32 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|x64.ActiveCfg = Release|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|x64.Build.0 = Release|x64 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.Build.0 = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Win32.ActiveCfg = Debug|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Win32.Build.0 = Debug|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|x64.ActiveCfg = Debug|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|x64.Build.0 = Debug|x64 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.Build.0 = Release|Win32 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.Build.0 = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Win32.ActiveCfg = Release|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Win32.Build.0 = Release|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|x64.ActiveCfg = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|x64.Build.0 = Release|x64 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.Build.0 = Release|Win32 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.Build.0 = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Win32.ActiveCfg = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Win32.Build.0 = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|x64.ActiveCfg = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|x64.Build.0 = Release|x64 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.Build.0 = Release|Win32 + {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.Build.0 = Release|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Win32.ActiveCfg = Release|Win32 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Win32.Build.0 = Release|Win32 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|x64.ActiveCfg = Release|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|x64.Build.0 = Release|x64 - {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.Build.0 = Release|Win32 + {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.Build.0 = Release|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Win32.ActiveCfg = Release|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Win32.Build.0 = Release|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|x64.ActiveCfg = Release|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|x64.Build.0 = Release|x64 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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|Win32 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.Build.0 = Release|Win32 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.Build.0 = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Win32.ActiveCfg = Release|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Win32.Build.0 = Release|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|x64.ActiveCfg = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|x64.Build.0 = Release|x64 - {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 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.Build.0 = Release|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.ActiveCfg = Release|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.Build.0 = Release|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|x64.ActiveCfg = Release|Win32 - {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {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 @@ -182,16 +184,14 @@ Global {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Mixed Platforms.Build.0 = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Win32.ActiveCfg = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Win32.Build.0 = Release|Win32 - {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|x64.ActiveCfg = Release|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|x64.ActiveCfg = Release|x64 + {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|x64 + {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|Mixed Platforms.Build.0 = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Win32.ActiveCfg = Release|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Win32.Build.0 = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|x64.ActiveCfg = Release|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.Build.0 = Debug|Win32 @@ -205,6 +205,65 @@ Global {2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Win32.Build.0 = Release|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|x64.ActiveCfg = Release|x64 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|x64.Build.0 = Release|x64 + {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 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.Build.0 = Release|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.ActiveCfg = Release|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.Build.0 = Release|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|x64.ActiveCfg = Release|x64 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|x64.Build.0 = Release|x64 + {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 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Mixed Platforms.Build.0 = Release|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Win32.ActiveCfg = Release|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Win32.Build.0 = Release|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|x64.ActiveCfg = Release|x64 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|x64.Build.0 = Release|x64 + {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 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Mixed Platforms.Build.0 = Release|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Win32.ActiveCfg = Release|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Win32.Build.0 = Release|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|x64.ActiveCfg = Release|x64 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|x64.Build.0 = Release|x64 + {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 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Mixed Platforms.Build.0 = Release|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Win32.ActiveCfg = Release|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Win32.Build.0 = Release|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|x64.ActiveCfg = Release|x64 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|x64.Build.0 = Release|x64 + {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 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Mixed Platforms.Build.0 = Release|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Win32.ActiveCfg = Release|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Win32.Build.0 = Release|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -213,5 +272,11 @@ Global {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8} = {C27B926E-B3EF-4990-8822-47580E43A0BE} {6A066806-F43F-4B31-A4E3-57179674F460} = {C27B926E-B3EF-4990-8822-47580E43A0BE} {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50} = {C27B926E-B3EF-4990-8822-47580E43A0BE} + {460D625F-2AC9-4559-B809-0BA89CEAEDF4} = {C27B926E-B3EF-4990-8822-47580E43A0BE} + {2A1BC987-AF42-4500-802D-89CD32FC1309} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {B1195BB9-B3A5-47F0-906C-8DEA384D1520} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {52380DAA-0F4A-4D97-8E57-98DF39319CAF} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A} EndGlobalSection EndGlobal diff --git a/Code/Game/DanBiasGame/DLLMain.cpp b/Code/Game/DanBiasGame/DLLMain.cpp new file mode 100644 index 00000000..e2d438ba --- /dev/null +++ b/Code/Game/DanBiasGame/DLLMain.cpp @@ -0,0 +1,8 @@ +#define NOMINMAX +#include + +BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ) +{ + //MessageBox(0, L"DanBiasGame Loaded", 0, 0); + return TRUE; +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj new file mode 100644 index 00000000..ff05bc23 --- /dev/null +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -0,0 +1,220 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {2A1BC987-AF42-4500-802D-89CD32FC1309} + Win32Proj + DanBiasGame + + + + DynamicLibrary + true + v110 + Unicode + + + DynamicLibrary + true + v110 + Unicode + + + DynamicLibrary + false + v110 + true + Unicode + + + DynamicLibrary + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\Bin\DLL\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath) + + + true + $(SolutionDir)..\Bin\DLL\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\External\Include\;$(IncludePath) + + + false + $(SolutionDir)..\Bin\DLL\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\External\Include\;$(IncludePath) + + + false + $(SolutionDir)..\Bin\DLL\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\External\Include\;$(IncludePath) + + + + + + Level3 + Disabled + DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;%(AdditionalIncludeDirectories) + + + Windows + true + OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + + + + + + + Level3 + Disabled + DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + + + Windows + true + GameProtocols_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + + + + + Level3 + + + MaxSpeed + true + true + DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + + + Windows + true + true + true + GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) + OysterGraphics_x86.dll;%(DelayLoadDLLs) + + + + + Level3 + + + MaxSpeed + true + true + DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + + + Windows + true + true + true + GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) + OysterGraphics_x86.dll;%(DelayLoadDLLs) + + + + + {7e3990d2-3d94-465c-b58d-64a74b3ecf9b} + + + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + + {460d625f-2ac9-4559-b809-0ba89ceaedf4} + + + {0ec83e64-230e-48ef-b08c-6ac9651b4f82} + + + {f10cbc03-9809-4cba-95d8-327c287b18ee} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp new file mode 100644 index 00000000..15e799bf --- /dev/null +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -0,0 +1,331 @@ +#define NOMINMAX +#include +#include "Include\DanBiasGame.h" +#include "DllInterfaces/GFXAPI.h" +#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 +{ + __int64 DanBiasGame::cntsPerSec = 0; + __int64 DanBiasGame::prevTimeStamp = 0; + float DanBiasGame::secsPerCnt = 0; + 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* protocolData; + switch (pType) + { + case protocol_PlayerNavigation: + + break; + case protocol_PlayerPosition: + protocolData = new Client::GameClientState::PlayerPos; + for(int i = 0; i< 3; i++) + { + ((Client::GameClientState::PlayerPos*)protocolData)->playerPos[i] = p[i].value.netFloat; + } + gameClientState->Protocol(protocolData); + delete protocolData; + protocolData = NULL; + break; + + + case protocol_ObjectPosition: + protocolData = new Client::GameClientState::ObjPos; + for(int i = 0; i< 16; i++) + { + ((Client::GameClientState::ObjPos*)protocolData)->worldPos[i] = p[i].value.netFloat; + } + gameClientState->Protocol(protocolData); + delete protocolData; + protocolData = NULL; + break; + + default: + break; + } + } + }; + class DanBiasGamePrivateData + { + + public: + DanBiasGamePrivateData() + { + + } + ~DanBiasGamePrivateData() + { + + } + + public: + Client::GameClientState* gameClientState; + InputClass* inputObj; + MyRecieverObject* r; + + } data; +#pragma endregion + + + DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData(); + + //-------------------------------------------------------------------------------------- + // Interface API functions + //-------------------------------------------------------------------------------------- + DanBiasClientReturn DanBiasGame::Initiate(DanBiasGameDesc& desc) + { + if( FAILED( InitWindow( desc.hinst, desc.nCmdShow ) )) + return DanBiasClientReturn_Error; + + if( FAILED( InitDirect3D() ) ) + return DanBiasClientReturn_Error; + + if( FAILED( InitInput() ) ) + return DanBiasClientReturn_Error; + + cntsPerSec = 0; + QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec); + secsPerCnt = 1.0f / (float)cntsPerSec; + + prevTimeStamp = 0; + QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp); + + m_data->r = new MyRecieverObject; + m_data->r->nwClient = new Oyster::Network::NetworkClient(); + m_data->r->nwClient->Connect(desc.port, desc.IP); + if (!m_data->r->nwClient->IsConnected()) + { + // failed to connect + return DanBiasClientReturn_Error; + } + // Start in lobby state + m_data->gameClientState = new Client::LobbyState(); + m_data->gameClientState->Init(m_data->r->nwClient); + + + return DanBiasClientReturn_Sucess; + } + + DanBiasClientReturn DanBiasGame::Run() + { + // Main message loop + MSG msg = {0}; + while(WM_QUIT != msg.message) + { + if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) ) + { + TranslateMessage( &msg ); + DispatchMessage( &msg ); + } + else + { + __int64 currTimeStamp = 0; + QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp); + float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt; + + //render + if(Update(dt) != S_OK) + return DanBiasClientReturn_Error; + if(Render(dt) != S_OK) + return DanBiasClientReturn_Error; + + prevTimeStamp = currTimeStamp; + } + } + return DanBiasClientReturn_Sucess; + } + + void DanBiasGame::Release() + { + CleanUp(); + } + + + //-------------------------------------------------------------------------------------- + // Register class and create window + //-------------------------------------------------------------------------------------- + HRESULT DanBiasGame::InitWindow( HINSTANCE hInstance, int nCmdShow ) + { + // Register class + WNDCLASSEX wcex; + wcex.cbSize = sizeof(WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = 0; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = L"BTH_D3D_Template"; + wcex.hIconSm = 0; + if( !RegisterClassEx(&wcex) ) + return E_FAIL; + + // Adjust and create window + g_hInst = hInstance; + RECT rc = { 0, 0, 1024, 768 }; + AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); + + if(!(g_hWnd = CreateWindow( + L"BTH_D3D_Template", + L"BTH - Direct3D 11.0 Template", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + rc.right - rc.left, + rc.bottom - rc.top, + NULL, + NULL, + hInstance, + NULL))) + { + return E_FAIL; + } + ShowWindow( g_hWnd, nCmdShow ); + + return S_OK; + } + + //-------------------------------------------------------------------------------------- + // Create Direct3D with Oyster Graphics + //-------------------------------------------------------------------------------------- + HRESULT DanBiasGame::InitDirect3D() + { + if(Oyster::Graphics::API::Init(g_hWnd, false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess) + return E_FAIL; + return S_OK; + } + + //-------------------------------------------------------------------------------------- + // Init the input + //------------------------------------------------------------------------------------- + HRESULT DanBiasGame::InitInput() + { + 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; + } + return S_OK; + } + + HRESULT DanBiasGame::Update(float deltaTime) + { + m_data->inputObj->Update(); + + DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same; + state = m_data->gameClientState->Update(deltaTime, m_data->inputObj); + + if(state != Client::GameClientState::ClientState_Same) + { + m_data->gameClientState->Release(); + delete m_data->gameClientState; + m_data->gameClientState = NULL; + + switch (state) + { + case Client::GameClientState::ClientState_Lobby: + m_data->gameClientState = new Client::LobbyState(); + break; + case Client::GameClientState::ClientState_Game: + m_data->gameClientState = new Client::GameState(); + break; + default: + return E_FAIL; + break; + } + m_data->gameClientState->Init(m_data->r->nwClient); // send game client + + } + return S_OK; + } + + HRESULT DanBiasGame::Render(float deltaTime) + { + int isPressed = 0; + if(m_data->inputObj->IsKeyPressed(DIK_A)) + { + isPressed = 1; + } + + wchar_t title[255]; + swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed)); + SetWindowText(g_hWnd, title); + + m_data->gameClientState->Render(); + + return S_OK; + } + + HRESULT DanBiasGame::CleanUp() + { + m_data->gameClientState->Release(); + delete m_data->gameClientState; + delete m_data->inputObj; + delete m_data; + + + Oyster::Graphics::API::Clean(); + return S_OK; + } + + //-------------------------------------------------------------------------------------- + // Called every time the application receives a message + //-------------------------------------------------------------------------------------- + LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) + { + PAINTSTRUCT ps; + HDC hdc; + + switch (message) + { + case WM_PAINT: + hdc = BeginPaint(hWnd, &ps); + EndPaint(hWnd, &ps); + break; + + case WM_DESTROY: + PostQuitMessage(0); + break; + + case WM_KEYDOWN: + + switch(wParam) + { + case VK_ESCAPE: + PostQuitMessage(0); + break; + } + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + + return 0; + } + +} //End namespace DanBias \ No newline at end of file diff --git a/Code/DanBiasGame/DanBiasMaincpp.cpp b/Code/Game/DanBiasGame/DanBiasMaincpp.cpp similarity index 92% rename from Code/DanBiasGame/DanBiasMaincpp.cpp rename to Code/Game/DanBiasGame/DanBiasMaincpp.cpp index 23c1a119..0b7ea666 100644 --- a/Code/DanBiasGame/DanBiasMaincpp.cpp +++ b/Code/Game/DanBiasGame/DanBiasMaincpp.cpp @@ -9,7 +9,7 @@ #include #include "DllInterfaces/GFXAPI.h" -#include "IGame.h" +//#include "IGame.h" #include "L_inputClass.h" @@ -28,7 +28,7 @@ HINSTANCE g_hInst = NULL; HWND g_hWnd = NULL; -GameLogic::IGame* game; +//GameLogic::IGame* game; InputClass* inputObj; @@ -205,34 +205,34 @@ HRESULT InitGame() MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK); return false; } - game = new GameLogic::IGame(); + /*game = new GameLogic::IGame(); game->Init(); game->StartGame(); - + */ return S_OK; } HRESULT Update(float deltaTime) { inputObj->Update(); - GameLogic::keyInput key = GameLogic::keyInput_none; + //GameLogic::keyInput key = GameLogic::keyInput_none; - if(inputObj->IsKeyPressed(DIK_W)) - { - key = GameLogic::keyInput_W; - } - else if(inputObj->IsKeyPressed(DIK_A)) - { - key = GameLogic::keyInput_A; - } - else if(inputObj->IsKeyPressed(DIK_S)) - { - key = GameLogic::keyInput_S; - } - else if(inputObj->IsKeyPressed(DIK_D)) - { - key = GameLogic::keyInput_D; - } + //if(inputObj->IsKeyPressed(DIK_W)) + //{ + // key = GameLogic::keyInput_W; + //} + //else if(inputObj->IsKeyPressed(DIK_A)) + //{ + // key = GameLogic::keyInput_A; + //} + //else if(inputObj->IsKeyPressed(DIK_S)) + //{ + // key = GameLogic::keyInput_S; + //} + //else if(inputObj->IsKeyPressed(DIK_D)) + //{ + // key = GameLogic::keyInput_D; + //} float pitch = 0; float yaw = 0; @@ -243,7 +243,7 @@ HRESULT Update(float deltaTime) yaw = inputObj->GetYaw(); //} - game->Update(key, pitch, yaw); + //game->Update(key, pitch, yaw); return S_OK; @@ -258,7 +258,7 @@ HRESULT Render(float deltaTime) //std::cout<<"test"; } - game->Render(); + //game->Render(); wchar_t title[255]; swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed)); SetWindowText(g_hWnd, title); @@ -271,11 +271,11 @@ HRESULT Render(float deltaTime) HRESULT CleanUp() { - if(game) + /*if(game) { - delete game; - game = NULL; - } + delete game; + game = NULL; + }*/ return S_OK; } //-------------------------------------------------------------------------------------- diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.cpp b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp new file mode 100644 index 00000000..840e6267 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp @@ -0,0 +1,4 @@ +#include "C_Object.h" +using namespace DanBias::Client; + + diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.h b/Code/Game/DanBiasGame/GameClientState/C_Object.h new file mode 100644 index 00000000..8bfecdb9 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.h @@ -0,0 +1,28 @@ +#ifndef DANBIAS_CLIENT_COBJECT_H +#define DANBIAS_CLIENT_COBJECT_H +#include "DllInterfaces/GFXAPI.h" +namespace DanBias +{ + namespace Client + { + + struct ModelInitData + { + std::wstring modelPath; + Oyster::Math::Float4x4 world; + bool visible; + }; + +class C_Object +{ +private: + +public: + + virtual void Init(ModelInitData modelInit) = 0; + virtual void setPos() = 0; + + virtual void Render() = 0; + virtual void Release() = 0; +};};}; +#endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp new file mode 100644 index 00000000..686bbca9 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp @@ -0,0 +1,42 @@ +#include "C_DynamicObj.h" +#include "DllInterfaces/GFXAPI.h" +using namespace DanBias::Client; +struct C_DynamicObj::myData +{ + myData(){} + Oyster::Graphics::Model::Model *model; + // light + // sound + // effect +}privData; +C_DynamicObj::C_DynamicObj(void) +{ +} + + +C_DynamicObj::~C_DynamicObj(void) +{ + +} +void C_DynamicObj::Init(ModelInitData modelInit) +{ + // load models + privData = new myData(); + privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); + privData->model->WorldMatrix = modelInit.world; + privData->model->Visible = modelInit.visible; +} +void C_DynamicObj::setPos() +{ + +} + +void C_DynamicObj::Render() +{ + Oyster::Graphics::API::RenderModel(*(privData->model)); +} +void C_DynamicObj::Release() +{ + Oyster::Graphics::API::DeleteModel(privData->model); + delete privData; +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h new file mode 100644 index 00000000..ca0f3b8c --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h @@ -0,0 +1,22 @@ +#ifndef DANBIAS_CLIENT_CDYNAMICOBJECT_H +#define DANBIAS_CLIENT_CDYNAMICOBJECT_H +#include "../C_Object.h" +namespace DanBias +{ + namespace Client + { +class C_DynamicObj : public C_Object +{ +private: + struct myData; + myData* privData; +public: + C_DynamicObj(void); + virtual ~C_DynamicObj(void); + void Init(ModelInitData modelInit); + void setPos(); + + void Render(); + void Release(); +};};}; +#endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp new file mode 100644 index 00000000..e47d98ef --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp @@ -0,0 +1,46 @@ +#include "C_Player.h" +#include "DllInterfaces/GFXAPI.h" +using namespace DanBias::Client; + +struct C_Player::myData +{ + myData(){} + Oyster::Math3D::Float4x4 view; + Oyster::Math3D::Float4x4 proj; + Oyster::Graphics::Model::Model *model; +}privData; + +C_Player::C_Player(void) +{ +} + + +C_Player::~C_Player(void) +{ + +} + +void C_Player::Init(ModelInitData modelInit) +{ + // load models + privData = new myData(); + privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); + privData->model->WorldMatrix = modelInit.world; + privData->model->Visible = modelInit.visible; + + +} +void C_Player::setPos() +{ + +} + +void C_Player::Render() +{ + Oyster::Graphics::API::RenderModel(*(privData->model)); +} +void C_Player::Release() +{ + Oyster::Graphics::API::DeleteModel(privData->model); + delete privData; +} diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h new file mode 100644 index 00000000..5d9c9d59 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h @@ -0,0 +1,25 @@ +#ifndef DANBIAS_CLIENT_CPLAYER_H +#define DANBIAS_CLIENT_CPLAYER_H +#include "../C_Object.h" +namespace DanBias +{ + namespace Client + { +class C_Player : public C_Object +{ +private: + struct myData; + myData* privData; + //Oyster::Graphics:: LIght +public: + C_Player(void); + ~C_Player(void); + void Init(ModelInitData modelInit); + void setPos(); + + void Render(); + void Release(); + +};};}; +#endif + diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp new file mode 100644 index 00000000..54c36c2a --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp @@ -0,0 +1,45 @@ + +#include "C_StaticObj.h" +#include "DllInterfaces/GFXAPI.h" +using namespace DanBias::Client; + +struct C_StaticObj::myData +{ + myData(){} + Oyster::Graphics::Model::Model *model; + // light + // sound + // effect +}privData; +C_StaticObj::C_StaticObj(void) +{ +} + + +C_StaticObj::~C_StaticObj(void) +{ + +} +void C_StaticObj::Init(ModelInitData modelInit) +{ + // load models + privData = new myData(); + privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); + privData->model->WorldMatrix = modelInit.world; + privData->model->Visible = modelInit.visible; + +} +void C_StaticObj::setPos() +{ + +} + +void C_StaticObj::Render() +{ + Oyster::Graphics::API::RenderModel(*(privData->model)); +} +void C_StaticObj::Release() +{ + Oyster::Graphics::API::DeleteModel(privData->model); + delete privData; +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h new file mode 100644 index 00000000..768344f0 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h @@ -0,0 +1,22 @@ +#ifndef DANBIAS_CLIENT_CSTATICOBJECT_H +#define DANBIAS_CLIENT_CSTATICOBJECT_H +#include "../C_Object.h" +namespace DanBias +{ + namespace Client + { +class C_StaticObj : public C_Object +{ +private: + struct myData; + myData* privData; +public: + C_StaticObj(void); + virtual ~C_StaticObj(void); + void Init(ModelInitData modelInit); + void setPos(); + + void Render(); + void Release(); +};};}; +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp new file mode 100644 index 00000000..b07ec6fa --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp @@ -0,0 +1,43 @@ +#include "C_UIobject.h" +#include "DllInterfaces/GFXAPI.h" +using namespace DanBias::Client; + +struct C_UIobject::myData +{ + myData(){} + Oyster::Math3D::Float4x4 view; + Oyster::Math3D::Float4x4 proj; + Oyster::Graphics::Model::Model *model; +}privData; + +C_UIobject::C_UIobject(void) +{ +} + + +C_UIobject::~C_UIobject(void) +{ +} +void C_UIobject::Init(ModelInitData modelInit) +{ + // load models + privData = new myData(); + privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); + privData->model->WorldMatrix = modelInit.world; + privData->model->Visible = modelInit.visible; + +} +void C_UIobject::setPos() +{ + +} + +void C_UIobject::Render() +{ + Oyster::Graphics::API::RenderModel(*(privData->model)); +} +void C_UIobject::Release() +{ + Oyster::Graphics::API::DeleteModel(privData->model); + delete privData; +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h new file mode 100644 index 00000000..203b5398 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h @@ -0,0 +1,22 @@ +#ifndef DANBIAS_CLIENT_CUIOBJECT_H +#define DANBIAS_CLIENT_CUIOBJECT_H +#include "../C_Object.h" +namespace DanBias +{ + namespace Client + { + class C_UIobject : public C_Object + { + private: + struct myData; + myData* privData; + public: + C_UIobject(void); + virtual ~C_UIobject(void); + void Init(ModelInitData modelInit); + void setPos(); + + void Render(); + void Release(); +};};}; +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.cpp b/Code/Game/DanBiasGame/GameClientState/GameClientState.cpp new file mode 100644 index 00000000..1fffc85e --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.cpp @@ -0,0 +1,12 @@ +#include "GameClientState.h" + +using namespace DanBias::Client; + +GameClientState::GameClientState(void) +{ +} + + +GameClientState::~GameClientState(void) +{ +} diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.h b/Code/Game/DanBiasGame/GameClientState/GameClientState.h new file mode 100644 index 00000000..368fca6a --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.h @@ -0,0 +1,55 @@ +#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H +#define DANBIAS_CLIENT_GAMECLIENTSTATE_H + +#define NOMINMAX +#include "L_inputClass.h" +#include "NetworkClient.h" + +namespace DanBias +{ +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, + ClientState_Game, + ClientState_Same, + }; + +public: + GameClientState(void); + virtual ~GameClientState(void); + virtual bool Init(Oyster::Network::NetworkClient* nwClient) = 0; + virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0; + virtual bool Render() = 0; + virtual bool Release() = 0; + virtual void Protocol(ProtocolStruct* protocolStruct) = 0; + +}; +}; +}; +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp new file mode 100644 index 00000000..588e6ab8 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -0,0 +1,180 @@ +#include "GameState.h" +#include "DllInterfaces/GFXAPI.h" +#include "C_obj/C_Player.h" +#include "C_obj/C_DynamicObj.h" +#include "NetworkClient.h" +#include "PlayerProtocols.h" + +using namespace DanBias::Client; + +struct GameState::myData +{ + myData(){} + Oyster::Math3D::Float4x4 view; + Oyster::Math3D::Float4x4 proj; + C_Object* object[3]; + int modelCount; + Oyster::Network::NetworkClient* nwClient; + gameStateState state; + +}privData; + +GameState::GameState(void) +{ +} + + +GameState::~GameState(void) +{ + +} +bool GameState::Init(Oyster::Network::NetworkClient* nwClient) +{ + // load models + privData = new myData(); + privData->state = gameStateState_loading; + privData->nwClient = nwClient; + privData->state = LoadGame(); + return true; +} +GameState::gameStateState GameState::LoadGame() +{ + LoadModels(L"map"); + InitCamera(Oyster::Math::Float3(0,0,5.4f)); + return gameStateState_playing; +} +bool GameState::LoadModels(std::wstring mapFile) +{ + // open file + // read file + // init models + privData->modelCount = 2; + + ModelInitData modelData; + + modelData.world = Oyster::Math3D::Float4x4::identity; + modelData.visible = true; + modelData.modelPath = L"worldDummy"; + // load models + privData->object[0] = new C_Player(); + privData->object[0]->Init(modelData); + + Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); + modelData.world = modelData.world * translate; + modelData.modelPath = L"crate"; + + privData->object[1] = new C_DynamicObj(); + privData->object[1]->Init(modelData); + return true; +} +bool GameState::InitCamera(Oyster::Math::Float3 startPos) +{ + privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000); + //privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000); + Oyster::Graphics::API::SetProjection(privData->proj); + + privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos); + privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); + return true; +} + +GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput) +{ + switch (privData->state) + { + case gameStateState_loading: + // load map + // wait for all players + LoadGame(); + privData->state = gameStateState_playing; + break; + case gameStateState_playing: + // read server data + // update objects + // Client.send(obj); + { + GameLogic::Protocol_PlayerMovement movePlayer; + movePlayer.bForward = false; + movePlayer.bBackward = false; + movePlayer.bStrafeLeft = false; + movePlayer.bStrafeRight = false; + movePlayer.bTurnLeft = false; + movePlayer.bTurnRight = false; + + + if(KeyInput->IsKeyPressed(DIK_W)) + { + movePlayer.bForward = true; + } + if(KeyInput->IsKeyPressed(DIK_S)) + { + movePlayer.bBackward = true; + } + if(KeyInput->IsKeyPressed(DIK_A)) + { + movePlayer.bStrafeLeft = true; + } + if(KeyInput->IsKeyPressed(DIK_D)) + { + movePlayer.bStrafeRight = true; + } + + + privData->nwClient->Send(movePlayer); + + if(KeyInput->IsKeyPressed(DIK_L)) + privData->state = GameState::gameStateState_end; + } + break; + case gameStateState_end: + return ClientState_Lobby; + break; + default: + break; + } + + // send key input to server. + return ClientState_Same; +} +bool GameState::Render() +{ + Oyster::Graphics::API::SetView(privData->view); + Oyster::Graphics::API::SetProjection(privData->proj); + Oyster::Graphics::API::NewFrame(); + for (int i = 0; i < privData->modelCount; i++) + { + privData->object[i]->Render(); + } + Oyster::Graphics::API::EndFrame(); + return true; +} +bool GameState::Release() +{ + for (int i = 0; i < privData->modelCount; i++) + { + privData->object[i]->Release(); + delete privData->object[i]; + privData->object[i] = NULL; + } + + delete privData; + privData = NULL; + return true; +} + +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 new file mode 100644 index 00000000..05f9ac3d --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -0,0 +1,41 @@ +#ifndef DANBIAS_CLIENT_GAMESTATE_H +#define DANBIAS_CLIENT_GAMESTATE_H +#include "GameClientState.h" +#include "OysterMath.h" +#include +namespace DanBias +{ +namespace Client +{ +class GameState : public GameClientState +{ + enum gameStateState + { + gameStateState_loading, + gameStateState_playing, + gameStateState_end, + }; +private: + + struct myData; + myData* privData; +public: + GameState(void); + ~GameState(void); + bool Init(Oyster::Network::NetworkClient* nwClient); + GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override; + bool LoadModels(std::wstring mapFile) ; + bool InitCamera(Oyster::Math::Float3 startPos) ; + gameStateState LoadGame(); + + bool Render()override; + bool Release()override; + + void Protocol(ProtocolStruct* pos)override; + void PlayerPosProtocol(PlayerPos* pos); + void ObjectPosProtocol(ObjPos* pos); + //void Protocol(LightPos pos); +}; +}; +}; +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp new file mode 100644 index 00000000..2c07c27f --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -0,0 +1,131 @@ +#include "LobbyState.h" +#include "DllInterfaces/GFXAPI.h" +#include "OysterMath.h" +#include "C_obj/C_Player.h" +#include "C_obj/C_StaticObj.h" +#include "C_obj/C_DynamicObj.h" + +using namespace DanBias::Client; + +struct LobbyState::myData +{ + myData(){} + Oyster::Math3D::Float4x4 view; + Oyster::Math3D::Float4x4 proj; + C_Object* object[2]; + int modelCount; + // UI object + // game client* +}privData; + +LobbyState::LobbyState(void) +{ + +} + +LobbyState::~LobbyState(void) +{ + +} + +bool LobbyState::Init(Oyster::Network::NetworkClient* nwClient) +{ + privData = new myData(); + + // load models + LoadModels(L"UImodels.txt"); + InitCamera(Oyster::Math::Float3(0,0,5.4f)); + return true; +} +bool LobbyState::LoadModels(std::wstring file) +{ + // open file + // read file + // init models + privData->modelCount = 2; + + ModelInitData modelData; + + modelData.world = Oyster::Math3D::Float4x4::identity; + modelData.visible = true; + modelData.modelPath = L"crate"; + // load models + privData->object[0] = new C_StaticObj(); + privData->object[0]->Init(modelData); + + Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); + modelData.world = modelData.world * translate; + + privData->object[1] = new C_DynamicObj(); + privData->object[1]->Init(modelData); + return true; +} + +bool LobbyState::InitCamera(Oyster::Math::Float3 startPos) +{ + privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000); + //privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000); + Oyster::Graphics::API::SetProjection(privData->proj); + + privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos); + privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); + return true; +} +GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* KeyInput) +{ + // picking + // mouse events + // different menus + // play sounds + // update animation + // send data to server + // check data from server + + if( KeyInput->IsKeyPressed(DIK_G)) + return ClientState_Game; + return ClientState_Same; +} +bool LobbyState::Render() +{ + + Oyster::Graphics::API::SetView(privData->view); + Oyster::Graphics::API::SetProjection( privData->proj); + + + Oyster::Graphics::API::NewFrame(); + // render objects + for (int i = 0; i < privData->modelCount; i++) + { + privData->object[i]->Render(); + } + + // render effects + + // render lights + + Oyster::Graphics::API::EndFrame(); + return true; +} +bool LobbyState::Release() +{ + for (int i = 0; i < privData->modelCount; i++) + { + privData->object[i]->Release(); + delete privData->object[i]; + privData->object[i] = NULL; + } + + 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 new file mode 100644 index 00000000..e7cb7b8c --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.h @@ -0,0 +1,39 @@ +#ifndef DANBIAS_CLIENT_LOBBYSTATE_H +#define DANBIAS_CLIENT_LOBBYSTATE_H + +#include "GameClientState.h" +#include "OysterMath.h" +#include +namespace DanBias +{ + namespace Client + { + +class LobbyState : public GameClientState +{ +private: + struct myData; + myData* privData; +public: + LobbyState(void); + ~LobbyState(void); + bool Init(Oyster::Network::NetworkClient* nwClient); + bool LoadModels(std::wstring file); + bool InitCamera(Oyster::Math::Float3 startPos); + ClientState Update(float deltaTime, InputClass* KeyInput); + // create session lobby + // join session lobby + // set name + // set rules + // set map + // ready + // chat + // kick + + 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 new file mode 100644 index 00000000..f146f343 --- /dev/null +++ b/Code/Game/DanBiasGame/Include/DanBiasGame.h @@ -0,0 +1,73 @@ +#ifndef DANBIASGAME_DANBIASGAME_H +#define DANBIASGAME_DANBIASGAME_H + +#define DANBIAS_CLIENT + +#if defined (DANBIAS_GAME_DLL_EXPORT) + #define DANBIAS_GAME_DLL __declspec(dllexport) +#else + #define DANBIAS_GAME_DLL __declspec(dllimport) +#endif + +#define NOMINMAX +#include + + + +namespace DanBias +{ + extern "C" + { + + enum DanBiasClientReturn + { + DanBiasClientReturn_Error, + DanBiasClientReturn_Sucess, + }; + + struct DanBiasGameDesc + { + //Stuff goes here... + int port; + const char* IP; + HINSTANCE hinst; + int nCmdShow; + + }; + LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); + class DanBiasGamePrivateData; + class DANBIAS_GAME_DLL DanBiasGame + { + public: + //-------------------------------------------------------------------------------------- + // Interface API functions + //-------------------------------------------------------------------------------------- + static DanBiasClientReturn Initiate(DanBiasGameDesc& desc); + static DanBiasClientReturn Run(); + static void Release(); + + private: + + static HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow); + static HRESULT InitDirect3D(); + static HRESULT InitInput(); + + static HRESULT Update(float deltaTime); + static HRESULT Render(float deltaTime); + static HRESULT CleanUp(); + + private: + static __int64 cntsPerSec; + static __int64 prevTimeStamp; + static float secsPerCnt; + + static HINSTANCE g_hInst; + static HWND g_hWnd; + static DanBiasGamePrivateData* m_data; + }; + + + }//End Extern "C" +} //End namespace DanBias + +#endif // !DANBIASGAME_DANBIASGAME_H diff --git a/Code/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj similarity index 67% rename from Code/DanBiasGame/DanBiasGame.vcxproj rename to Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj index 88181e55..3650d06a 100644 --- a/Code/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj @@ -19,9 +19,9 @@ - {2A1BC987-AF42-4500-802D-89CD32FC1309} + {8690FDDF-C5B7-4C42-A337-BD5243F29B85} Win32Proj - DanBiasGame + DanBiasLauncher @@ -71,28 +71,32 @@ $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(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 - C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(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) - C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(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) - C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(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) @@ -101,14 +105,13 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - $(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows true - OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies) - OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -118,14 +121,13 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - $(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows true - OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies) - OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasServer_$(PlatformShortName)D.dll;DanBiasGame_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -137,16 +139,15 @@ true true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - $(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies) - OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs) + DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) @@ -158,34 +159,24 @@ true true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - $(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include Windows true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies) - OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs) + DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) - - {b1195bb9-b3a5-47f0-906c-8dea384d1520} - - - {7e3990d2-3d94-465c-b58d-64a74b3ecf9b} - - - {f10cbc03-9809-4cba-95d8-327c287b18ee} - - - {4285bd3f-3c6c-4670-b7af-a29afef5f6a8} - + - + + {2a1bc987-af42-4500-802d-89cd32fc1309} + diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp new file mode 100644 index 00000000..8ae0f29c --- /dev/null +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -0,0 +1,45 @@ +///////////////////////////////////////////////// +// Launcher to launch Danbias server or client // +///////////////////////////////////////////////// +#define NOMINMAX +#include +#include + + +//#include "DanBiasServerAPI.h" +#include "DanBiasGame.h" + + +int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) +{ +#if defined(DANBIAS_SERVER) + if(SetDllDirectory(L"..\\DLL") == FALSE) + { + return cmdShow; + } + if( DanBias::DanBiasServerAPI::Initiate() == DanBias::DanBiasServerReturn_Sucess) + { + DanBias::DanBiasServerAPI::Run(); + DanBias::DanBiasServerAPI::Release(); + } +#elif defined(DANBIAS_CLIENT) + if(SetDllDirectory(L"..\\DLL") == FALSE) + { + return cmdShow; + } + // Game client starter code goes here + DanBias::DanBiasGameDesc gameDesc; + gameDesc.port = 1; + gameDesc.IP = "10.1010.303"; + gameDesc.hinst = hinst; + gameDesc.nCmdShow = cmdShow; + + if( DanBias::DanBiasGame::Initiate(gameDesc) == DanBias::DanBiasClientReturn_Sucess) + { + DanBias::DanBiasGame::Run(); + DanBias::DanBiasGame::Release(); + } +#endif + + return cmdShow; +} \ No newline at end of file diff --git a/Code/Game/DanBiasServer/DLLMain.cpp b/Code/Game/DanBiasServer/DLLMain.cpp new file mode 100644 index 00000000..41d71e2e --- /dev/null +++ b/Code/Game/DanBiasServer/DLLMain.cpp @@ -0,0 +1,8 @@ +#define NOMINMAX +#include + +BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ) +{ + + return TRUE; +} \ No newline at end of file diff --git a/Code/Game/DanBiasServer/DanBiasServer.vcxproj b/Code/Game/DanBiasServer/DanBiasServer.vcxproj new file mode 100644 index 00000000..af26345b --- /dev/null +++ b/Code/Game/DanBiasServer/DanBiasServer.vcxproj @@ -0,0 +1,214 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {52380DAA-0F4A-4D97-8E57-98DF39319CAF} + Win32Proj + DanBiasServer + + + + DynamicLibrary + true + v110 + Unicode + false + + + DynamicLibrary + true + v110 + Unicode + true + + + DynamicLibrary + false + v110 + true + Unicode + + + DynamicLibrary + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\Bin\DLL\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName)D + $(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\;$(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\;$(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\;$(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) + + + + + + Level3 + Disabled + DANBIAS_SERVER_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + + + Windows + true + GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll + NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + DANBIAS_SERVER_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + + + Windows + true + GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll + NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + DANBIAS_SERVER_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + + + Windows + true + true + true + GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName).dll + NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + DANBIAS_SERVER_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + + + Windows + true + true + true + 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} + + + + + + \ No newline at end of file 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/Include/DanBiasServerAPI.cpp b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.cpp new file mode 100644 index 00000000..e897a6dd --- /dev/null +++ b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.cpp @@ -0,0 +1,28 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "DanBiasServerAPI.h" +#include "..\GameServer.h" + +namespace DanBias +{ + +#pragma region Server Data + static GameServer server; +#pragma endregion + + + DanBiasServerReturn DanBiasServerAPI::Initiate() + { + return server.Create(); + } + DanBiasServerReturn DanBiasServerAPI::Run() + { + return server.Run(); + } + DanBiasServerReturn DanBiasServerAPI::Release() + { + return server.Release(); + } + +} //End namspace DanBias \ No newline at end of file diff --git a/Code/Game/DanBiasServer/Include/DanBiasServerAPI.h b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.h new file mode 100644 index 00000000..1165ba48 --- /dev/null +++ b/Code/Game/DanBiasServer/Include/DanBiasServerAPI.h @@ -0,0 +1,37 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#ifndef DANBIAS_SERVER_DANBIAS_SERVER_H +#define DANBIAS_SERVER_DANBIAS_SERVER_H + +#include + +#define DANBIAS_SERVER + +#ifdef DANBIAS_SERVER_DLL_EXPORT + #define DANBIAS_SERVER_DLL __declspec(dllexport) +#else + #define DANBIAS_SERVER_DLL __declspec(dllimport) +#endif + +namespace DanBias +{ + enum DanBiasServerReturn + { + DanBiasServerReturn_Error, + DanBiasServerReturn_Sucess, + }; + + extern "C" + { + class DANBIAS_SERVER_DLL DanBiasServerAPI + { + public: + static DanBiasServerReturn Initiate(); + static DanBiasServerReturn Run(); + static DanBiasServerReturn Release(); + };//End class DanBiasServer + }//End Extern "C" +} //End namspace DanBias + +#endif // !DANBIAS_SERVER_DANBIAS_SERVER_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..638d8237 --- /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::NetEvent _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..7a69eb94 --- /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..97033790 --- /dev/null +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp @@ -0,0 +1,44 @@ +#include "MainLobby.h" +#include + +namespace DanBias +{ + MainLobby::MainLobby() + { + + } + MainLobby::~MainLobby() + { + + } + void MainLobby::Release() + { + this->DetachClient(); + } + + void MainLobby::Frame() + { + ParseEvents(); + } + +//////// Private + void MainLobby::ParseEvents() + { + if(!this->box.IsEmpty()) + { + NetEvent &e = this->box.Fetch(); + + 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..c78f70e2 --- /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 ParseEvents(); + + }; +}//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 new file mode 100644 index 00000000..b7687acb --- /dev/null +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -0,0 +1,73 @@ +#include "AttatchmentMassDriver.h" +#include "PhysicsAPI.h" + +using namespace GameLogic; + +struct AttatchmentMassDriver::PrivateData +{ + PrivateData() + { + + } + + ~PrivateData() + { + + } + +}myData; + + +AttatchmentMassDriver::AttatchmentMassDriver(void) +{ + myData = new PrivateData(); + this->owner = 0; +} + +AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) +{ + myData = new PrivateData(); + this->owner = &owner; +} + + +AttatchmentMassDriver::~AttatchmentMassDriver(void) +{ + delete myData; +} + +/******************************************************** +* Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used +********************************************************/ +void AttatchmentMassDriver::UseAttatchment(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 new file mode 100644 index 00000000..2fac7be4 --- /dev/null +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -0,0 +1,30 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// +#ifndef ATTATCHMENTMASSDRIVER_H +#define ATTATCHMENTMASSDRIVER_H +#include "IAttatchment.h" +namespace GameLogic +{ + + class AttatchmentMassDriver : public IAttatchment + { + public: + AttatchmentMassDriver(void); + AttatchmentMassDriver(Player &owner); + ~AttatchmentMassDriver(void); + + + void UseAttatchment(const WEAPON_FIRE &fireInput); + + private: + void ForcePush(const WEAPON_FIRE &fireInput); + void ForcePull(const WEAPON_FIRE &fireInput); + + private: + struct PrivateData; + PrivateData *myData; + }; +} +#endif + diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp new file mode 100644 index 00000000..288a1a4e --- /dev/null +++ b/Code/Game/GameLogic/AttatchmentSocket.cpp @@ -0,0 +1,52 @@ +#include "AttatchmentSocket.h" +#include "IAttatchment.h" +using namespace GameLogic; + +struct AttatchmentSocket::PrivateData +{ + PrivateData() + { + + } + + ~PrivateData() + { + + } + + IAttatchment *attatchment; + + +}myData; + +AttatchmentSocket::AttatchmentSocket(void) +{ +} + + +AttatchmentSocket::~AttatchmentSocket(void) +{ +} + +IAttatchment* AttatchmentSocket::GetAttatchment() +{ + 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 new file mode 100644 index 00000000..2257dd7a --- /dev/null +++ b/Code/Game/GameLogic/AttatchmentSocket.h @@ -0,0 +1,26 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// + +#ifndef ATTATCHMENTSOCKET_H +#define ATTATCHMENTSOCKET_H +#include "IAttatchment.h" +namespace GameLogic +{ + + class AttatchmentSocket + { + public: + AttatchmentSocket(void); + ~AttatchmentSocket(void); + + IAttatchment* GetAttatchment(); + void SetAttatchment(IAttatchment *attatchment); + void RemoveAttatchment(); + + private: + struct PrivateData; + PrivateData *myData; + }; +} +#endif \ No newline at end of file diff --git a/Code/GameLogic/Camera.cpp b/Code/Game/GameLogic/Camera.cpp similarity index 100% rename from Code/GameLogic/Camera.cpp rename to Code/Game/GameLogic/Camera.cpp diff --git a/Code/GameLogic/Camera.h b/Code/Game/GameLogic/Camera.h similarity index 100% rename from Code/GameLogic/Camera.h rename to Code/Game/GameLogic/Camera.h diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp new file mode 100644 index 00000000..3d1af2a1 --- /dev/null +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -0,0 +1,59 @@ +#include "CollisionManager.h" +#include "PhysicsAPI.h" +#include "Object.h" +#include "DynamicObject.h" +#include "Player.h" + +using namespace Oyster; + +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*)(rigidBodyPlayer->gameObjectRef)); + Object *realObj = (Object*)obj->gameObjectRef; + + switch (realObj->GetType()) + { + case OBJECT_TYPE_BOX: + PlayerVBox(*player,(*(DynamicObject*) realObj)); + break; + case OBJECT_TYPE_PLAYER: + + break; + } + + return Physics::ICustomBody::SubscriptMessage_none; + } + + void PlayerVBox(Player &player, DynamicObject &box) + { + player.DamageLife(20); + } + + Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) + { + DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef; + Object *realObj = (Object*)obj->gameObjectRef; + + switch (realObj->GetType()) + { + case OBJECT_TYPE_BOX: + + break; + case OBJECT_TYPE_PLAYER: + //PlayerVBox(*(Player*)realObj,*box); + break; + } + + return Physics::ICustomBody::SubscriptMessage_none; + } + } +} \ No newline at end of file diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h new file mode 100644 index 00000000..d19ce8e3 --- /dev/null +++ b/Code/Game/GameLogic/CollisionManager.h @@ -0,0 +1,25 @@ +#ifndef COLLISIONMANAGER_H +#define COLLISIONMANAGER_H + +#include "Object.h" +#include "PhysicsAPI.h" + +namespace GameLogic +{ + + namespace CollisionManager + { + //these are the main collision functions + //typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); + Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj); + 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); + + }; + +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp new file mode 100644 index 00000000..a8ea1ab4 --- /dev/null +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -0,0 +1,23 @@ +#include "DynamicObject.h" +#include "CollisionManager.h" + +using namespace GameLogic; + + +DynamicObject::DynamicObject() + :Object() +{ + +} + +DynamicObject::DynamicObject(void* collisionFunc, OBJECT_TYPE type) + :Object(collisionFunc, type) +{ + +} + + +DynamicObject::~DynamicObject(void) +{ + +} \ No newline at end of file diff --git a/Code/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h similarity index 78% rename from Code/GameLogic/DynamicObject.h rename to Code/Game/GameLogic/DynamicObject.h index 2d6ffdc8..70bb8c11 100644 --- a/Code/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -1,11 +1,8 @@ ////////////////////////////////////////////////// //Created by Erik and Linda of the GameLogic team ////////////////////////////////////////////////// - - #ifndef DYNAMICOBJECT_H #define DYNAMICOBJECT_H - #include "Object.h" namespace GameLogic @@ -16,10 +13,11 @@ namespace GameLogic { public: - DynamicObject(void); + DynamicObject(); + DynamicObject(void* collisionFunc, OBJECT_TYPE type); ~DynamicObject(void); - void Update(); + private: }; diff --git a/Code/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp similarity index 73% rename from Code/GameLogic/Game.cpp rename to Code/Game/GameLogic/Game.cpp index b4095130..636b152c 100644 --- a/Code/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -1,4 +1,5 @@ #include "Game.h" + using namespace GameLogic; Game::Game(void) @@ -26,7 +27,13 @@ Game::~Game(void) void Game::Init() { - player = new Player(); + //Oyster::Physics::API::SetSubscription("remove object"); + + player = new Player(L"worldDummy"); + + box = new DynamicObject(L"crate"); + //poi + //box = new physcTestObj("box"); camera = new Camera(); } void Game::StartGame() @@ -60,9 +67,13 @@ void Game::Update(keyInput keyPressed, float pitch, float yaw) camera->Walk(0.1); } camera->UpdateViewMatrix(); + //poi Oyster::Physics::API::Update(); } void Game::Render() { - Oyster::Graphics::API::NewFrame(camera->View(), camera->Proj()); + Oyster::Graphics::API::SetView(camera->View()); + Oyster::Graphics::API::SetProjection(camera->Proj()); + Oyster::Graphics::API::NewFrame(); player->Render(); + box->Render(); } \ No newline at end of file diff --git a/Code/GameLogic/Game.h b/Code/Game/GameLogic/Game.h similarity index 86% rename from Code/GameLogic/Game.h rename to Code/Game/GameLogic/Game.h index 0a8a031a..708c01e3 100644 --- a/Code/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -5,6 +5,7 @@ #include "Player.h" #include "IGame.h" #include "Camera.h" +#include "DynamicObject.h" namespace GameLogic { @@ -21,6 +22,7 @@ namespace GameLogic private: Level* level; + DynamicObject* box; Player* player; Camera* camera; }; diff --git a/Code/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj similarity index 67% rename from Code/GameLogic/GameLogic.vcxproj rename to Code/Game/GameLogic/GameLogic.vcxproj index 236258d2..e0614e29 100644 --- a/Code/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -69,38 +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.lib;%(AdditionalDependencies) + GamePhysics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -108,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) @@ -123,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) @@ -140,68 +143,56 @@ 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) - + {104fa3e9-94d9-4e1d-a941-28a03bc8a095} - false - true - false - false - false - - {7e3990d2-3d94-465c-b58d-64a74b3ecf9b} - - + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} - - {0ec83e64-230e-48ef-b08c-6ac9651b4f82} - - + {f10cbc03-9809-4cba-95d8-327c287b18ee} - + {4285bd3f-3c6c-4670-b7af-a29afef5f6a8} - + + - + - + - - + + - - + - - 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 new file mode 100644 index 00000000..3e72647e --- /dev/null +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -0,0 +1,48 @@ +#ifndef GAMELOGICSTATES_H +#define GAMELOGICSTATES_H + + +namespace GameLogic +{ + enum PLAYER_STATE + { + PLAYER_STATE_JUMPING = 0, + PLAYER_STATE_WALKING = 1, + PLAYER_STATE_IDLE = 2, + }; + + enum PLAYER_MOVEMENT + { + PLAYER_MOVEMENT_FORWARD = 0, + PLAYER_MOVEMENT_BACKWARD = 1, + PLAYER_MOVEMENT_LEFT = 2, + PLAYER_MOVEMENT_RIGHT = 4, + PLAYER_MOVEMENT_JUMP = 8, + }; + + enum WEAPON_FIRE + { + WEAPON_USE_PRIMARY_PRESS = 0, + WEAPON_USE_PRIMARY_RELEASE = 1, + WEAPON_USE_SECONDARY_PRESS = 2, + WEAPON_USE_SECONDARY_RELEASE = 4, + WEAPON_USE_UTILLITY_PRESS = 8, + WEAPON_USE_UTILLITY_RELEASE = 16, + }; + + enum WEAPON_STATE + { + WEAPON_STATE_FIREING = 0, + 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/GameMode.cpp b/Code/Game/GameLogic/GameMode.cpp new file mode 100644 index 00000000..bcd87de5 --- /dev/null +++ b/Code/Game/GameLogic/GameMode.cpp @@ -0,0 +1,30 @@ +#include "GameMode.h" + +using namespace GameLogic; + + +struct GameMode::PrivateData +{ + PrivateData() + { + + } + + ~PrivateData() + { + + } + +}myData; + + +GameMode::GameMode() +{ + myData = new PrivateData(); +} + + +GameMode::~GameMode(void) +{ + delete myData; +} diff --git a/Code/GameLogic/GameMode.h b/Code/Game/GameLogic/GameMode.h similarity index 81% rename from Code/GameLogic/GameMode.h rename to Code/Game/GameLogic/GameMode.h index 42273946..865f07c3 100644 --- a/Code/GameLogic/GameMode.h +++ b/Code/Game/GameLogic/GameMode.h @@ -15,7 +15,8 @@ namespace GameLogic GameMode(void); ~GameMode(void); private: - //variabels that control what game rules the level runs on + struct PrivateData; + PrivateData *myData; }; } diff --git a/Code/Game/GameLogic/IAttatchment.cpp b/Code/Game/GameLogic/IAttatchment.cpp new file mode 100644 index 00000000..4b0b1961 --- /dev/null +++ b/Code/Game/GameLogic/IAttatchment.cpp @@ -0,0 +1,13 @@ +#include "IAttatchment.h" +#include "AttatchmentSocket.h" + +using namespace GameLogic; + +IAttatchment::IAttatchment(void) +{ +} + + +IAttatchment::~IAttatchment(void) +{ +} diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h new file mode 100644 index 00000000..2192ffcf --- /dev/null +++ b/Code/Game/GameLogic/IAttatchment.h @@ -0,0 +1,31 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// + +#ifndef IATTATCHMENT_H +#define IATTATCHMENT_H +#include "GameLogicStates.h" +#include "Player.h" + +namespace GameLogic +{ + + + class IAttatchment + { + + public: + + IAttatchment(void); + ~IAttatchment(void); + + virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0; + + private: + + protected: + Player *owner; + + }; +} +#endif diff --git a/Code/GameLogic/IGame.cpp b/Code/Game/GameLogic/IGame.cpp similarity index 100% rename from Code/GameLogic/IGame.cpp rename to Code/Game/GameLogic/IGame.cpp diff --git a/Code/GameLogic/IGame.h b/Code/Game/GameLogic/IGame.h similarity index 100% rename from Code/GameLogic/IGame.h rename to Code/Game/GameLogic/IGame.h diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp new file mode 100644 index 00000000..835062c1 --- /dev/null +++ b/Code/Game/GameLogic/Level.cpp @@ -0,0 +1,48 @@ +#include "Level.h" +#include "StaticObject.h" +#include "DynamicObject.h" +#include "GameMode.h" +#include "Player.h" + +using namespace GameLogic; + +struct Level::PrivateData +{ + PrivateData() + { + + } + ~PrivateData() + { + } + + Player *players; + int nrOfPlayers; + + StaticObject** staticObjects; + int nrOfStaticObjects; + + DynamicObject** dynamicObjects; + int nrOfDynamicObjects; + + GameMode* gameMode; + +}myData; + +Level::Level(void) +{ + myData = new PrivateData(); +} + + +Level::~Level(void) +{ + delete myData; +} + +void Level::InitiateLevel(std::string levelPath) +{ + +} + + diff --git a/Code/GameLogic/Level.h b/Code/Game/GameLogic/Level.h similarity index 55% rename from Code/GameLogic/Level.h rename to Code/Game/GameLogic/Level.h index b43f193d..7177531b 100644 --- a/Code/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -1,14 +1,9 @@ ////////////////////////////////////////////////// //Created by Erik and Linda of the GameLogic team ////////////////////////////////////////////////// - - #ifndef LEVEL_H #define LEVEL_H - -#include "StaticObject.h" -#include "DynamicObject.h" -#include "GameMode.h" +#include namespace GameLogic { @@ -20,16 +15,11 @@ namespace GameLogic Level(void); ~Level(void); + void InitiateLevel(std::string levelPath); + private: - StaticObject** staticObjects; - int nrOfStaticObjects; - - DynamicObject** dynamicObjects; - int nrOfDynamicObjects; - - GameMode* gameMode; - - + struct PrivateData; + PrivateData *myData; }; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp new file mode 100644 index 00000000..dcd32bf1 --- /dev/null +++ b/Code/Game/GameLogic/Object.cpp @@ -0,0 +1,55 @@ +#include "Object.h" +#include "OysterMath.h" +#include "CollisionManager.h" + + +using namespace GameLogic; + +using namespace Oyster::Math; +using namespace Oyster::Physics; + +Object::Object() +{ + API::SimpleBodyDescription sbDesc; + //sbDesc.centerPosition = + + //poi + ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + + 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) +{ + + +} + +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 new file mode 100644 index 00000000..01864515 --- /dev/null +++ b/Code/Game/GameLogic/Object.h @@ -0,0 +1,35 @@ +////////////////////////////////////////////////// +//Created by Erik and Linda of the GameLogic team +////////////////////////////////////////////////// + + +#ifndef OBJECT_H +#define OBJECT_H + +#include "PhysicsAPI.h" +#include "GameLogicStates.h" +#include "GameLogicDef.h" + + +namespace GameLogic +{ + class DANBIAS_GAMELOGIC_DLL Object + { + public: + Object(); + Object(void* collisionFunc, OBJECT_TYPE type); + ~Object(void); + + OBJECT_TYPE GetType(); + + Oyster::Physics::ICustomBody* GetRigidBody(); + + private: + OBJECT_TYPE type; + protected: + Oyster::Physics::ICustomBody *rigidBody; + }; + +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp new file mode 100644 index 00000000..bae54e9a --- /dev/null +++ b/Code/Game/GameLogic/Player.cpp @@ -0,0 +1,139 @@ +#include "Player.h" +#include "OysterMath.h" +#include "CollisionManager.h" +#include "Weapon.h" + +using namespace GameLogic; +using namespace Oyster::Physics; + +struct Player::PrivateData +{ + PrivateData() + { + weapon = new Weapon(); + + life = 100; + playerState = PLAYER_STATE_IDLE; + + lookDir = Oyster::Math::Float3(1,0,0); + } + + ~PrivateData() + { + if (weapon) + { + delete weapon; + } + } + + int life; + Weapon *weapon; + PLAYER_STATE playerState; + Oyster::Math::Float3 lookDir; + +}myData; + +Player::Player() + :Object(CollisionManager::PlayerCollision, OBJECT_TYPE_PLAYER) +{ + myData = new PrivateData(); +} + +Player::~Player(void) +{ + delete myData; +} + +/******************************************************** +* Updates the player(is this function needed?) +********************************************************/ + +void Player::Update() +{ + +} + +/******************************************************** +* Moves the player based on client input +* Uses the physics to move the player by adding a force in the chosen direction +* Uses the Jump() function if the player is to jump, this is becuase jumping requires additional logic compared to normal movement +********************************************************/ +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: + break; + + case PLAYER_MOVEMENT_RIGHT: + break; + + case PLAYER_MOVEMENT_JUMP: + Jump(); + break; + } +} +/******************************************************** +* Uses the players weapon based on user input +********************************************************/ +void Player::UseWeapon(const WEAPON_FIRE &fireInput) +{ + myData->weapon->Use(fireInput); +} + +/******************************************************** +* Jumps if the player is currently not in a state of jumping +* Applies a force upwards(current upwards) +********************************************************/ +void Player::Jump() +{ + API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100); +} + +bool Player::IsWalking() +{ + return (myData->playerState == PLAYER_STATE_WALKING); +} +bool Player::IsJumping() +{ + return (myData->playerState == PLAYER_STATE_JUMPING); +} +bool Player::IsIdle() +{ + return (myData->playerState == PLAYER_STATE_IDLE); +} + +Oyster::Math::Float3 Player::GetPos() +{ + return rigidBody->GetCenter(); +} + +Oyster::Math::Float3 Player::GetLookDir() +{ + return myData->lookDir; +} + +/******************************************************** +* Respawns the player on a new chosen position +* This resets a set of variables such as life, ammo etcetc +********************************************************/ +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 new file mode 100644 index 00000000..af0bff50 --- /dev/null +++ b/Code/Game/GameLogic/Player.h @@ -0,0 +1,41 @@ +////////////////////////////////////////////////// +//Created by Erik and Linda of the GameLogic team +////////////////////////////////////////////////// +#ifndef PLAYER_H +#define PLAYER_H +#include "GameLogicStates.h" +#include "OysterMath.h" +#include "Object.h" +#include "GameLogicDef.h" + +namespace GameLogic +{ + class DANBIAS_GAMELOGIC_DLL Player : public Object + { + + public: + Player(void); + ~Player(void); + + void Update(); + void Move(const PLAYER_MOVEMENT &movement); + void UseWeapon(const WEAPON_FIRE &fireInput); + void Jump(); + + bool IsWalking(); + bool IsJumping(); + bool IsIdle(); + + Oyster::Math::Float3 GetPos(); + Oyster::Math::Float3 GetLookDir(); + + void Respawn(); + + void DamageLife(int damage); + + private: + struct PrivateData; + PrivateData *myData; + }; +} +#endif \ No newline at end of file diff --git a/Code/GameLogic/RefManager.cpp b/Code/Game/GameLogic/RefManager.cpp similarity index 66% rename from Code/GameLogic/RefManager.cpp rename to Code/Game/GameLogic/RefManager.cpp index a119898c..cb3d099f 100644 --- a/Code/GameLogic/RefManager.cpp +++ b/Code/Game/GameLogic/RefManager.cpp @@ -2,7 +2,7 @@ using namespace GameLogic; -typedef std::pair mapData; +typedef std::pair mapData; RefManager* RefManager::instance = 0; @@ -34,12 +34,12 @@ RefManager* RefManager::getInstance( ) return instance; } -Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body) +Object* RefManager::GetMap(const Oyster::Physics::ICustomBody &body) { return mapper[&body]; } -void RefManager::AddMapping(Oyster::Physics::ICustomBody &body, Object &obj) +void RefManager::AddMapping( const Oyster::Physics::ICustomBody &body, Object &obj) { mapper.insert(mapData(&body,&obj)); } diff --git a/Code/GameLogic/RefManager.h b/Code/Game/GameLogic/RefManager.h similarity index 52% rename from Code/GameLogic/RefManager.h rename to Code/Game/GameLogic/RefManager.h index b5fd91d2..fa4080c9 100644 --- a/Code/GameLogic/RefManager.h +++ b/Code/Game/GameLogic/RefManager.h @@ -8,7 +8,6 @@ #include #include "Object.h" -#include "PhysicsAPI.h" namespace GameLogic { @@ -23,13 +22,13 @@ namespace GameLogic void Release(); - Object* GetMap(Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler - void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value + Object* GetMap(const Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler + void AddMapping(const Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value private: static RefManager* instance; - std::map mapper; //mapper points a rigidBody to an actual game object + std::map mapper; //mapper points a rigidBody to an actual game object }; diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp new file mode 100644 index 00000000..155834fe --- /dev/null +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -0,0 +1,23 @@ +#include "StaticObject.h" + +using namespace GameLogic; + + + +StaticObject::StaticObject() + :Object() +{ + +} + +StaticObject::StaticObject(void* collisionFunc, OBJECT_TYPE type) + :Object(collisionFunc,type) +{ + +} + + +StaticObject::~StaticObject(void) +{ + +} diff --git a/Code/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h similarity index 78% rename from Code/GameLogic/StaticObject.h rename to Code/Game/GameLogic/StaticObject.h index 07d23311..31121447 100644 --- a/Code/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -15,9 +15,12 @@ namespace GameLogic { public: - StaticObject(void); + StaticObject(); + StaticObject(void* collisionFunc, OBJECT_TYPE type); ~StaticObject(void); - + + private: + }; } diff --git a/Code/GameLogic/TestGLMain.cpp b/Code/Game/GameLogic/TestGLMain.cpp similarity index 100% rename from Code/GameLogic/TestGLMain.cpp rename to Code/Game/GameLogic/TestGLMain.cpp diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp new file mode 100644 index 00000000..e620e0d6 --- /dev/null +++ b/Code/Game/GameLogic/Weapon.cpp @@ -0,0 +1,137 @@ +#include "Weapon.h" +#include "AttatchmentSocket.h" +#include "AttatchmentMassDriver.h" + +using namespace GameLogic; + +struct Weapon::PrivateData +{ + PrivateData() + { + weaponState = WEAPON_STATE_IDLE; + selectedAttatchment = 0; + currentNrOfAttatchments = 0; + selectedSocketID = 0; + maxNrOfSockets = 0; + } + + ~PrivateData() + { + } + + WEAPON_STATE weaponState; + + AttatchmentSocket **attatchmentSockets; + int maxNrOfSockets; + int currentNrOfAttatchments; + + IAttatchment *selectedAttatchment; + int selectedSocketID; + +}myData; + +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) +{ + delete myData; +} + +/******************************************************** +* Uses the weapon based on the input given and the current chosen attatchment +********************************************************/ +void Weapon::Use(const WEAPON_FIRE &fireInput) +{ + myData->selectedAttatchment->UseAttatchment(fireInput); +} + +/******************************************************** +* Specific weapon usage implementation +********************************************************/ + +/******************************************************** +* Get functions for states +********************************************************/ +bool Weapon::IsFireing() +{ + return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIREING); +} + +bool Weapon::IsIdle() +{ + return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_IDLE); +} + +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 new file mode 100644 index 00000000..cdd1a3b7 --- /dev/null +++ b/Code/Game/GameLogic/Weapon.h @@ -0,0 +1,46 @@ +////////////////////////////////////////////////// +//Created by Erik and Linda of the GameLogic team +////////////////////////////////////////////////// +#ifndef WEAPON_H +#define WEAPON_H +#include "GameLogicStates.h" +#include "IAttatchment.h" +#include "Player.h" + +namespace GameLogic +{ + + class Weapon + { + + public: + + + Weapon(void); + Weapon(int nrOfAttatchmentSockets); + ~Weapon(void); + + 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: + struct PrivateData; + PrivateData *myData; + }; + +} +#endif \ No newline at end of file diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj new file mode 100644 index 00000000..4b0d7c39 --- /dev/null +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78} + GameProtocols + + + + StaticLibrary + true + v110 + Unicode + + + StaticLibrary + true + v110 + Unicode + + + StaticLibrary + false + v110 + true + Unicode + + + StaticLibrary + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)Network\NetworkAPI\;$(IncludePath) + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)Network\NetworkAPI\;$(IncludePath) + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)Network\NetworkAPI\;$(IncludePath) + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)Network\NetworkAPI\;$(IncludePath) + + + + Level3 + Disabled + true + + + true + + + $(SolutionDir)..\Bin\DLL\;%(AdditionalLibraryDirectories) + NetworkAPI_$(PlatformShortName)D.lib;%(AdditionalDependencies) + + + + + Level3 + Disabled + true + + + true + + + $(SolutionDir)..\Bin\DLL\;%(AdditionalLibraryDirectories) + NetworkAPI_$(PlatformShortName)D.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + $(SolutionDir)..\Bin\DLL\;%(AdditionalLibraryDirectories) + NetworkAPI_$(PlatformShortName).lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + $(SolutionDir)..\Bin\DLL\;%(AdditionalLibraryDirectories) + NetworkAPI_$(PlatformShortName).lib;%(AdditionalDependencies) + + + + + + + + + + + + + \ No newline at end of file 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 new file mode 100644 index 00000000..f0464ffc --- /dev/null +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -0,0 +1,84 @@ +////////////////////////////////////////////////////////// +// Created 2013 // +// Dennis Andersen, Linda Andersson // +////////////////////////////////////////////////////////// + +#ifndef GAMELOGIC_PLAYER_PROTOCOLS_H +#define GAMELOGIC_PLAYER_PROTOCOLS_H + +#include +#include "ProtocolIdentificationID.h" + + + +namespace GameLogic +{ + struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject + { + int ProtocolID; + bool bForward; + bool bBackward; + bool bTurnLeft; + bool bTurnRight; + bool bStrafeRight; + bool bStrafeLeft; + + Protocol_PlayerMovement() + { + this->protocol[0].value = ProtocolID = protocol_Gamplay_PlayerNavigation; + + 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; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + 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: + Oyster::Network::CustomNetProtocol protocol; + }; + + struct Protocol_PlayerPosition :public Oyster::Network::CustomProtocolObject + { + float position[3]; + // look at dir + + Protocol_PlayerPosition() + { + this->protocol[0].value = protocol_Gamplay_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 new file mode 100644 index 00000000..cb90fa7f --- /dev/null +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -0,0 +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_Gamplay_PlayerNavigation 0 +#define protocol_Gamplay_PlayerPosition 1 +#define protocol_Gamplay_ObjectPosition 2 + +#define protocol_Lobby_Msg 100 + +#define protocol_General_Disconnect 200 +#define protocol_General_Ping 201 + +#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/GameLogic/CollisionManager.cpp b/Code/GameLogic/CollisionManager.cpp deleted file mode 100644 index f7868b79..00000000 --- a/Code/GameLogic/CollisionManager.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "CollisionManager.h" - - - -namespace GameLogic -{ - - namespace CollisionManager - { - - void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj) - { - Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyPlayer)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj); - - switch (realObj->GetType()) - { - case Object::OBJECT_TYPE_BOX: - PlayerVBox(*player,(*(DynamicObject*) realObj)); - break; - case Object::OBJECT_TYPE_PLAYER: - - break; - } - - //spela ljud? ta skada? etc etc - } - - void PlayerVBox(Player &player, DynamicObject &box) - { - //spela ljud? ta skada? etc etc - } - - void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj) - { - DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyBox)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj); - - switch (realObj->GetType()) - { - case Object::OBJECT_TYPE_BOX: - - break; - case Object::OBJECT_TYPE_PLAYER: - PlayerVBox(*(Player*)realObj,*box); - break; - } - } - } -} \ No newline at end of file diff --git a/Code/GameLogic/CollisionManager.h b/Code/GameLogic/CollisionManager.h deleted file mode 100644 index a650f595..00000000 --- a/Code/GameLogic/CollisionManager.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef COLLISIONMANAGER_H -#define COLLISIONMANAGER_H - -#include "Object.h" -#include "PhysicsAPI.h" -#include "RefManager.h" -#include "DynamicObject.h" -#include "Player.h" - -namespace GameLogic -{ - - namespace CollisionManager - { - //these are the main collision functions - void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj); - void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj); - - //these are the specific collision case functions - void PlayerVBox(Player &player, DynamicObject &box); - void BoxVBox(DynamicObject &box1, DynamicObject &box2); - - }; - -} - -#endif \ No newline at end of file diff --git a/Code/GameLogic/DynamicObject.cpp b/Code/GameLogic/DynamicObject.cpp deleted file mode 100644 index 14e0518d..00000000 --- a/Code/GameLogic/DynamicObject.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "DynamicObject.h" - -using namespace GameLogic; -using namespace Oyster::Physics; -using namespace Utility::DynamicMemory; - -DynamicObject::DynamicObject(void) - :Object() -{ -} - - -DynamicObject::~DynamicObject(void) -{ -} - -void DynamicObject::Update() -{ - //update object -} \ No newline at end of file diff --git a/Code/GameLogic/GameLogic.vcxproj.filters b/Code/GameLogic/GameLogic.vcxproj.filters deleted file mode 100644 index f2c5e978..00000000 --- a/Code/GameLogic/GameLogic.vcxproj.filters +++ /dev/null @@ -1,96 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/Code/GameLogic/GameMode.cpp b/Code/GameLogic/GameMode.cpp deleted file mode 100644 index 0eddb7f9..00000000 --- a/Code/GameLogic/GameMode.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "GameMode.h" - -using namespace GameLogic; - - -GameMode::GameMode(void) -{ - -} - - -GameMode::~GameMode(void) -{ - -} diff --git a/Code/GameLogic/Level.cpp b/Code/GameLogic/Level.cpp deleted file mode 100644 index 32fbe2d5..00000000 --- a/Code/GameLogic/Level.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "Level.h" - -using namespace GameLogic; - -Level::Level(void) -{ -} - - -Level::~Level(void) -{ -} diff --git a/Code/GameLogic/Object.cpp b/Code/GameLogic/Object.cpp deleted file mode 100644 index 33679058..00000000 --- a/Code/GameLogic/Object.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#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(void) -{ - - model = new Model(); - model = Oyster::Graphics::API::CreateModel(L"orca"); - - API::SimpleBodyDescription sbDesc; - //sbDesc.centerPosition = - - ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); - - GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); - -} - - -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() -{ - return this->type; -} diff --git a/Code/GameLogic/Object.h b/Code/GameLogic/Object.h deleted file mode 100644 index 767edb1f..00000000 --- a/Code/GameLogic/Object.h +++ /dev/null @@ -1,49 +0,0 @@ -////////////////////////////////////////////////// -//Created by Erik and Linda of the GameLogic team -////////////////////////////////////////////////// - - -#ifndef OBJECT_H -#define OBJECT_H - -#include "PhysicsAPI.h" -#include "DllInterfaces/GFXAPI.h" - -#include "Model/Model.h" -#include "Utilities.h" - - - -namespace GameLogic -{ - class Object - { - public: - - enum OBJECT_TYPE - { - OBJECT_TYPE_PLAYER, - OBJECT_TYPE_BOX, - }; - Object(void); - virtual ~Object(void); - - void Render(); - - OBJECT_TYPE GetType(); - - 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; - - }; - -} - -#endif \ No newline at end of file diff --git a/Code/GameLogic/Player.cpp b/Code/GameLogic/Player.cpp deleted file mode 100644 index 93a83506..00000000 --- a/Code/GameLogic/Player.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "Player.h" -#include "OysterMath.h" - -using namespace GameLogic; -using namespace Oyster::Physics; - -Player::Player(void) - :Object() -{ - life = 100; -} -Player::~Player(void) -{ - delete this->rigidBody; -} - -void Player::Update(keyInput keyPressed) -{ - if(keyPressed != keyInput_none) - { - Move(keyPressed); - } -} - -void Player::Move(keyInput keyPressed) -{ - if(keyPressed == keyInput_A) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.x -= 0.1; - rigidBody->SetCenter(pos); - } - if(keyPressed == keyInput_D) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.x += 0.1; - rigidBody->SetCenter(pos); - } - if(keyPressed == keyInput_S) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.y -= 0.1; - rigidBody->SetCenter(pos); - } - if(keyPressed == keyInput_W) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.y += 0.1; - rigidBody->SetCenter(pos); - } -} -void Player::Shoot() -{ - -} diff --git a/Code/GameLogic/Player.h b/Code/GameLogic/Player.h deleted file mode 100644 index 7c4045e3..00000000 --- a/Code/GameLogic/Player.h +++ /dev/null @@ -1,37 +0,0 @@ -////////////////////////////////////////////////// -//Created by Erik and Linda of the GameLogic team -////////////////////////////////////////////////// - - -#ifndef PLAYER_H -#define PLAYER_H - -#include "Object.h" -#include "Weapon.h" -#include "IGame.h" - - -namespace GameLogic -{ - class Player : public Object - { - - public: - Player(void); - ~Player(void); - - /******************************************************** - * Update the position of the rigid body - * This will be done with physics later - ********************************************************/ - void Update(keyInput keyPressed); - - void Move(keyInput keyPressed); - void Shoot(); - - private: - int life; - Weapon *weapon; - }; -} -#endif \ No newline at end of file diff --git a/Code/GameLogic/StaticObject.cpp b/Code/GameLogic/StaticObject.cpp deleted file mode 100644 index 855ef645..00000000 --- a/Code/GameLogic/StaticObject.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "StaticObject.h" - -using namespace GameLogic; - -StaticObject::StaticObject(void) -{ -} - - -StaticObject::~StaticObject(void) -{ -} diff --git a/Code/GameLogic/Weapon.cpp b/Code/GameLogic/Weapon.cpp deleted file mode 100644 index 2cbd4e71..00000000 --- a/Code/GameLogic/Weapon.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "Weapon.h" - -using namespace GameLogic; - -Weapon::Weapon(void) -{ -} - - -Weapon::~Weapon(void) -{ -} diff --git a/Code/GameLogic/Weapon.h b/Code/GameLogic/Weapon.h deleted file mode 100644 index e8d37a15..00000000 --- a/Code/GameLogic/Weapon.h +++ /dev/null @@ -1,26 +0,0 @@ -////////////////////////////////////////////////// -//Created by Erik and Linda of the GameLogic team -////////////////////////////////////////////////// - - -#ifndef WEAPON_H -#define WEAPON_H - -#include "Object.h" - -namespace GameLogic -{ - - class Weapon : public Object - { - - public: - Weapon(void); - ~Weapon(void); - - private: - - }; - -} -#endif \ 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/Input/L_inputClass.h b/Code/Input/L_inputClass.h index 129024c2..08358135 100644 --- a/Code/Input/L_inputClass.h +++ b/Code/Input/L_inputClass.h @@ -7,7 +7,6 @@ #ifndef _INPUTCLASS_H_ #define _INPUTCLASS_H_ - #define DIRECTINPUT_VERSION 0x0800 #pragma comment(lib, "dinput8.lib") 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..1e8dfb74 --- /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/Resource/OResourceHandler.cpp b/Code/Misc/Resource/OResourceHandler.cpp index f86c434c..918ecd1d 100644 --- a/Code/Misc/Resource/OResourceHandler.cpp +++ b/Code/Misc/Resource/OResourceHandler.cpp @@ -120,11 +120,12 @@ void OysterResource::Clean() //Remove all the references while (!OResource::Release(i->second)); - const wchar_t* temp = i->second->GetResourceFilename(); + std::wstring temp = i->second->GetResourceFilename(); delete resourcePrivate.resources[temp]; - resourcePrivate.resources.erase(temp); + } + resourcePrivate.resources.clear(); } void OysterResource::ReleaseResource(const OHRESOURCE& resourceData) { @@ -133,7 +134,7 @@ void OysterResource::ReleaseResource(const OHRESOURCE& resourceData) { if(OResource::Release(t)) { - const wchar_t* temp = t->GetResourceFilename(); + std::wstring temp = t->GetResourceFilename(); delete resourcePrivate.resources[temp]; resourcePrivate.resources.erase(temp); } @@ -146,7 +147,7 @@ void OysterResource::ReleaseResource(const wchar_t filename[]) { if(OResource::Release(t)) { - const wchar_t* temp = t->GetResourceFilename(); + std::wstring temp = t->GetResourceFilename(); delete resourcePrivate.resources[temp]; resourcePrivate.resources.erase(temp); } diff --git a/Code/Misc/Resource/OysterResource.h.orig b/Code/Misc/Resource/OysterResource.h.orig deleted file mode 100644 index 2ec147e8..00000000 --- a/Code/Misc/Resource/OysterResource.h.orig +++ /dev/null @@ -1,162 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// - -#ifndef MISC_OYSTER_RESOURCE_H -#define MISC_OYSTER_RESOURCE_H - - -namespace Oyster -{ - namespace Resource - { - struct CustomData; - /** A Resource handle representing various resources */ - typedef void* OHRESOURCE; - /** Typedef on a fuction required for custom unloading */ - typedef void(*CustomUnloadFunction)(void* loadedData); - /** Typedef on a fuction required for custom loading */ -<<<<<<< HEAD - typedef CustomData&(*CustomLoadFunction)(const wchar_t filename[]); -======= - typedef void(*CustomLoadFunction)(const wchar_t filename[], CustomData& outData); ->>>>>>> d08644e8e1ecc56f4d9dfa6a9aa33df94d9e655a - - /** An enum class representing all avalible resources that is supported. */ - enum ResourceType - { - //Byte - ResourceType_Byte_Raw, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_ANSI, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_UTF8, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_UNICODE, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_UTF16LE, /**< Handle can be interpeted as char[] or char* */ - - ResourceType_COUNT, /**< Not used. */ - - ResourceType_UNKNOWN = -1, /**< Handle can be interpeted as void* */ - ResourceType_INVALID = -2, /**< Invalid or non existing resource */ - }; - - /** A struct to fill when doing a custom resource Load. */ - struct CustomData - { - void* loadedData; // 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 { + bool isCreated; SmartPointer threadData; PrivateData() - :threadData(new ThreadData()) { + isCreated = false; + 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) + { + isCreated = o.isCreated; + 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 +92,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 +146,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 +189,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 +210,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 +233,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 +275,11 @@ bool OysterThread::IsActive() return false; } - +void OysterThread::SetPriority(OYSTER_THREAD_PRIORITY priority) +{ + this->privateData->threadData->prio = priority; +} +bool OysterThread::IsCreated() const +{ + return privateData->isCreated; +} diff --git a/Code/Misc/ThreadSafeQueue.h b/Code/Misc/ThreadSafeQueue.h index d0125f71..eedd9fd9 100644 --- a/Code/Misc/ThreadSafeQueue.h +++ b/Code/Misc/ThreadSafeQueue.h @@ -46,7 +46,7 @@ namespace Oyster Node *front; Node *back; int nrOfNodes; - OysterMutex mutex; + std::mutex stdMutex; }; @@ -68,7 +68,7 @@ namespace Oyster template < typename Type > ThreadSafeQueue::~ThreadSafeQueue() { - this->mutex.LockMutex(); + stdMutex.lock(); if(this->front != NULL) { @@ -87,16 +87,16 @@ namespace Oyster this->back = NULL; } - this->mutex.UnlockMutex(); + stdMutex.unlock(); } template < typename Type > void ThreadSafeQueue::Push(Type item) { + stdMutex.lock(); Node *e = new Node(item); - mutex.LockMutex(); if(this->front != NULL) { this->back->next = e; @@ -111,91 +111,86 @@ namespace Oyster this->nrOfNodes++; - mutex.UnlockMutex(); + stdMutex.unlock(); } template < typename Type > Type ThreadSafeQueue::Pop() { - mutex.LockMutex(); - if(this->front != NULL) - { - Type item = this->front->item; - Node *destroyer = this->front; - this->front = front->next; + stdMutex.lock(); - delete destroyer; - this->nrOfNodes--; + Type item = this->front->item; + Node *destroyer = this->front; + this->front = front->next; + + delete destroyer; + this->nrOfNodes--; - if(nrOfNodes == 0) - { - this->front = NULL; - this->back = NULL; - } - return item; + if(nrOfNodes == 0) + { + this->front = NULL; + this->back = NULL; } - mutex.UnlockMutex(); - - return NULL; + stdMutex.unlock(); + return item; } template < typename Type > Type ThreadSafeQueue::Front() { - mutex.LockMutex(); - if(front != NULL) - { - return this->front->item; - } - mutex.UnlockMutex(); - - return NULL; + stdMutex.lock(); + Type temp = this->front->item; + stdMutex.unlock(); + + return temp; + } template < typename Type > Type ThreadSafeQueue::Back() { - mutex.LockMutex(); - if(back != NULL) - { - return this->back->item; - } - mutex.UnlockMutex(); + stdMutex.lock(); + Type temp = this->back->item; + stdMutex.unlock(); - return NULL; + return temp; + } template < typename Type > int ThreadSafeQueue::Size() { - //? behövs denna låsas? - mutex.LockMutex(); - return this->nrOfNodes; - mutex.UnlockMutex(); + stdMutex.lock(); + int size = this->nrOfNodes; + stdMutex.unlock(); + + return size; + } template < typename Type > bool ThreadSafeQueue::IsEmpty() { - mutex.LockMutex(); - if(nrOfNodes == 0 && this->front == NULL) + stdMutex.lock(); + if(nrOfNodes == 0 || this->front == NULL) { - mutex.UnlockMutex(); + stdMutex.unlock(); return true; } else { - mutex.UnlockMutex(); + stdMutex.unlock(); } + return false; } template < typename Type > void ThreadSafeQueue::Swap(IQueue &queue ) { - mutex.LockMutex(); + stdMutex.lock(); int prevNrOfNodes = this->nrOfNodes; int size = queue.Size(); @@ -208,7 +203,7 @@ namespace Oyster { queue.Push(this->Pop()); } - mutex.UnlockMutex(); + stdMutex.unlock(); } 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 ec8b0229..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 new file mode 100644 index 00000000..1933d907 --- /dev/null +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -0,0 +1,91 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "CustomNetProtocol.h" +#include +#include "Translator.h" +using namespace Oyster::Network; + + +struct CustomNetProtocol::PrivateData +{ + std::map attributes; + + 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) + { + auto i = attributes.find(ID); + if(i == attributes.end()) return; + + switch (i->second.type) + { + case NetAttributeType_CharArray: + //delete [] i->second.value.netCharPtr; + i->second.value.netCharPtr = 0; + break; + } + } + + //Do network stuff +}; + + +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; +} +NetAttributeContainer& CustomNetProtocol::operator[](int ID) +{ + if(this->privateData->attributes.find(ID) == this->privateData->attributes.end()) + { + this->privateData->attributes[ID]; + this->privateData->attributes[ID].type = NetAttributeType_UNKNOWN; + memset(&this->privateData->attributes[ID].value, 0, sizeof(NetAttributeValue)); + } + + return this->privateData->attributes[ID]; +} \ No newline at end of file diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h new file mode 100644 index 00000000..d25c23e5 --- /dev/null +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -0,0 +1,113 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#ifndef NETWORK_CUSTOM_NETWORK_PROTOCOL_H +#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H + +#include +#include + +#ifdef CUSTOM_NET_PROTOCOL_EXPORT + #define NET_PROTOCOL_EXPORT __declspec(dllexport) +#else + #define NET_PROTOCOL_EXPORT __declspec(dllimport) +#endif + +namespace Oyster +{ + namespace Network + { + extern "C" + { + //Please don't create a type with a number higher than 127 for now. + //This may increase to 255 later on. + enum NetAttributeType + { + NetAttributeType_Bool, + NetAttributeType_Char, + NetAttributeType_UnsignedChar, + NetAttributeType_Short, + NetAttributeType_UnsignedShort, + NetAttributeType_Int, + NetAttributeType_UnsignedInt, + NetAttributeType_Int64, + NetAttributeType_UnsignedInt64, + NetAttributeType_Float, + NetAttributeType_Double, + NetAttributeType_CharArray, + NetAttributeType_UNKNOWN, + }; + union NetAttributeValue + { + bool netBool; + char netChar; + unsigned char netUChar; + short netShort; + unsigned short netUShort; + int netInt; + unsigned int netUInt; + __int64 netInt64; + unsigned __int64 netUInt64; + float netFloat; + double netDouble; + char* netCharPtr; + + NetAttributeValue(){ memset(this, 0, sizeof(NetAttributeValue)); } + NetAttributeValue(bool v) : netBool (v) {} + NetAttributeValue(char v) : netChar (v) {} + NetAttributeValue(unsigned char v) : netUChar (v) {} + NetAttributeValue(short v) : netShort (v) {} + NetAttributeValue(unsigned short v) : netUShort (v) {} + NetAttributeValue(int v) : netInt (v) {} + NetAttributeValue(unsigned int v) : netUInt (v) {} + NetAttributeValue(__int64 v) : netInt64 (v) {} + NetAttributeValue(unsigned __int64 v) : netUInt64 (v) {} + NetAttributeValue(float v) : netFloat (v) {} + NetAttributeValue(double v) : netDouble (v) {} + NetAttributeValue(char* v) : netCharPtr(v) {} + }; + struct NetAttributeContainer + { + NetAttributeType type; + NetAttributeValue value; + NetAttributeContainer() { type = NetAttributeType_UNKNOWN; } + }; + class CustomNetProtocol; + struct CustomProtocolObject + { + virtual CustomNetProtocol* GetProtocol() = 0; + }; + + class NET_PROTOCOL_EXPORT CustomNetProtocol + { + public: + CustomNetProtocol(); + ~CustomNetProtocol(); + CustomNetProtocol(const CustomNetProtocol& o); + const CustomNetProtocol& operator=(const CustomNetProtocol& o); + + NetAttributeContainer& operator[](int ID); + + private: + struct PrivateData; + PrivateData* privateData; + + friend class Translator; + }; + + }//End extern "C" + } //End namespace Network +} +#endif // !NETWORK_CUSTOM_NETWORK_PROTOCOL_H + + + + + + + + + + + + diff --git a/Code/Network/NetworkAPI/NetworkAPI.vcxproj b/Code/Network/NetworkAPI/NetworkAPI.vcxproj new file mode 100644 index 00000000..a53ef673 --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkAPI.vcxproj @@ -0,0 +1,185 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {460D625F-2AC9-4559-B809-0BA89CEAEDF4} + Win32Proj + NetworkAPI + NetworkAPI + + + + DynamicLibrary + true + v110 + Unicode + + + DynamicLibrary + true + v110 + Unicode + + + DynamicLibrary + false + v110 + true + Unicode + + + DynamicLibrary + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName)D + + + true + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName)D + + + false + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName) + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + + + false + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName) + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + + + + + + Level3 + Disabled + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + {c5aa09d0-6594-4cd3-bd92-1d380c7b3b50} + + + + + + \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkCallbackHelper.h b/Code/Network/NetworkAPI/NetworkCallbackHelper.h new file mode 100644 index 00000000..c99f2c5f --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkCallbackHelper.h @@ -0,0 +1,56 @@ +#ifndef NETWORK_API_NETWORK_CALLBACK_HELPER_H +#define NETWORK_API_NETWORK_CALLBACK_HELPER_H + +///////////////////////////////////// +// Created by Dennis Andersen 2013 // +///////////////////////////////////// + +#include + +namespace Oyster +{ + namespace Network + { + enum NetworkProtocolCallbackType + { + NetworkProtocolCallbackType_Function, + NetworkProtocolCallbackType_Object, + NetworkProtocolCallbackType_Unknown = -1, + }; + enum NetworkClientCallbackType + { + NetworkClientCallbackType_Function, + NetworkClientCallbackType_Object, + NetworkClientCallbackType_Unknown = -1, + }; + + class NetworkClient; + class CustomNetProtocol; + typedef void (*ClientConnectCallbackMethod)(NetworkClient); + typedef void(*ProtocolRecieverFunction)(CustomNetProtocol& protocol); + struct ClientConnectedObject + { + virtual void ClientConnectCallback(NetworkClient& client) = 0; + }; + struct ProtocolRecieverObject + { + virtual void ProtocolRecievedCallback(CustomNetProtocol& protocol) = 0; + }; + + union RecieverObject + { + ClientConnectCallbackMethod clientConnectFnc; // !< A function pointer for sending or recieving NetworkClient + ProtocolRecieverFunction protocolRecieverFnc; // !< A function pointer for sending or recieving CustomNetProtocol + ClientConnectedObject *clientConnectObject; // !< An object for sending or recieving NetworkClient + ProtocolRecieverObject *protocolRecievedObject; // !< An object for sending or recieving CustomNetProtocol + + RecieverObject() { memset(this, 0, sizeof(RecieverObject)); } + RecieverObject(ClientConnectCallbackMethod o) { clientConnectFnc = o; } + RecieverObject(ProtocolRecieverFunction o) { protocolRecieverFnc = o; } + RecieverObject(ClientConnectedObject* o) { clientConnectObject = o; } + RecieverObject(ProtocolRecieverObject* o) { protocolRecievedObject = o; } + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp new file mode 100644 index 00000000..924416aa --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -0,0 +1,265 @@ +#ifndef INCLUDE_WINSOCK_LIB +#define INCLUDE_WINSOCK_LIB + #pragma comment(lib, "ws2_32.lib") +#endif + +#include "NetworkClient.h" + +#include "Translator.h" +#include "CustomNetProtocol.h" + +#include "../NetworkDependencies/Connection.h" +#include "../NetworkDependencies/PostBox.h" +#include "../NetworkDependencies/WinsockFunctions.h" + +#include "../../Misc/Utilities.h" +#include "../../Misc/Thread/IThreadObject.h" +#include "../../Misc/Thread/OysterThread.h" + +using namespace Oyster::Network; +using namespace Oyster::Thread; +using namespace Utility::DynamicMemory; + +/************************************* + PrivateData +*************************************/ +struct ClientDataContainer +{ + Connection connection; + + SmartPointer> sendPostBox; + + RecieverObject recvObj; + NetworkProtocolCallbackType callbackType; + + Oyster::Thread::OysterThread thread; + std::mutex recvObjMutex; + std::mutex postBoxMutex; + + Translator translator; + + //ID + static unsigned int currID; + const unsigned int ID; + + ClientDataContainer(IThreadObject* o) + : ID(currID++) + { + InitWinSock(); + callbackType = NetworkProtocolCallbackType_Unknown; + sendPostBox = new PostBox(); + connection.SetBlockingMode(false); + connection.InitiateClient(); + } + ClientDataContainer(IThreadObject* o, unsigned int socket ) + :connection(socket), ID(currID++) + { + InitWinSock(); + callbackType = NetworkProtocolCallbackType_Unknown; + sendPostBox = new PostBox(); + connection.InitiateClient(); + 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; + } + +}; + + +/************************************* + NetworkClient +*************************************/ + +NetworkClient::NetworkClient() +{ + privateData = new PrivateData(); +} + +NetworkClient::NetworkClient(unsigned int socket) +{ + privateData = new PrivateData(socket); + this->privateData->data->thread.Create(this->privateData, true); +} + +NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type) +{ + privateData = new PrivateData(); + this->privateData->data->recvObj = SmartPointer(&recvObj);; +} + +NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type, unsigned int socket) +{ + privateData = new PrivateData(socket); + this->privateData->data->recvObj = SmartPointer(&recvObj); + this->privateData->data->callbackType = type; + this->privateData->data->thread.Create(this->privateData, true); +} + +NetworkClient::NetworkClient(const NetworkClient& obj) +{ + this->privateData = new PrivateData(*obj.privateData); +} + +NetworkClient& NetworkClient::operator =(const NetworkClient& obj) +{ + delete privateData; + this->privateData = new PrivateData(*obj.privateData); + return *this; +} + +NetworkClient::~NetworkClient() +{ + if(privateData) + { + delete privateData; + privateData = NULL; + } +} + +bool NetworkClient::Connect(unsigned short port, const char serverIP[]) +{ + int result = this->privateData->data->connection.Connect(port, serverIP); + + //Connect has succeeded + if(result == 0) + { + if(this->privateData->data->thread.IsCreated()) return false; + + this->privateData->data->thread.Create(this->privateData, true); + + return true; + } + + privateData->data->connection.SetBlockingMode(false); + + //Connect has failed + return false; +} + +void NetworkClient::Disconnect() +{ + privateData->data->connection.Disconnect(); +} + +bool NetworkClient::IsConnected() +{ + return privateData->data->connection.IsConnected(); +} + +void NetworkClient::Send(CustomProtocolObject& protocol) +{ + this->privateData->Send(protocol.GetProtocol()); +} + +void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type) +{ + 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->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 new file mode 100644 index 00000000..e77667a8 --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -0,0 +1,61 @@ +#ifndef NETWORK_API_NETWORK_CLIENT_H +#define NETWORK_API_NETWORK_CLIENT_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#ifdef CUSTOM_NET_PROTOCOL_EXPORT + #define NET_PROTOCOL_EXPORT __declspec(dllexport) +#else + #define NET_PROTOCOL_EXPORT __declspec(dllimport) +#endif + +#include "NetworkCallbackHelper.h" +//#include + +namespace Oyster +{ + namespace Network + { + extern "C" + { + struct CustomProtocolObject; + class NET_PROTOCOL_EXPORT NetworkClient + { + public: + NetworkClient(); + NetworkClient(unsigned int socket); + NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type); + NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type, unsigned int socket); + NetworkClient(const NetworkClient& obj); + + NetworkClient& operator =(const NetworkClient& obj); + virtual ~NetworkClient(); + + bool Connect(unsigned short port, const char serverIP[]); + void Disconnect(); + + bool IsConnected(); + + //Adds the protocol to the queue of protocols to be sent. + void Send(CustomProtocolObject& protocol); + + void SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type); + + //Compares the internal ID. + bool operator ==(const NetworkClient& obj); + bool operator ==(const int& ID); + + int Id() const; + + private: + struct PrivateData; + PrivateData* privateData; + + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkServer.cpp b/Code/Network/NetworkAPI/NetworkServer.cpp new file mode 100644 index 00000000..e7570281 --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkServer.cpp @@ -0,0 +1,227 @@ +#ifndef INCLUDE_WINSOCK_LIB +#define INCLUDE_WINSOCK_LIB + #pragma comment(lib, "ws2_32.lib") +#endif + +#include "NetworkServer.h" + +#include "../NetworkDependencies/Listener.h" +#include "../NetworkDependencies/PostBox.h" +#include "../NetworkDependencies/WinsockFunctions.h" + +#include "../../Misc/Utilities.h" +#include "../../Misc/Thread/OysterThread.h" + +using namespace Oyster::Network; +using namespace ::Server; +using namespace Utility::DynamicMemory; +using namespace Oyster::Thread; + +/************************************* + PrivateData +*************************************/ + +struct NetworkServer::PrivateData : public IThreadObject +{ + PrivateData(); + ~PrivateData(); + + bool Init(INIT_DESC& initDesc); + bool Start(); + void Stop(); + void Shutdown(); + + void CheckForNewClient(); + + bool DoWork(); + + // + IListener* listener; + INIT_DESC initDesc; + bool started; + + //Postbox for new clients + IPostBox *postBox; + + //Server thread + OysterThread thread; + +}; + +NetworkServer::PrivateData::PrivateData() +{ + listener = 0; + started = false; + postBox = new PostBox; +} + +NetworkServer::PrivateData::~PrivateData() +{ + Shutdown(); +} + +bool NetworkServer::PrivateData::Init(INIT_DESC& initDesc) +{ + //Check if it's a valid port + if(initDesc.port == 0) + { + return false; + } + + if(!InitWinSock()) + return false; + + this->initDesc = initDesc; + + //Initiate listener + listener = new Listener(postBox); + if(!((Listener*)listener)->Init(this->initDesc.port, false)) + { + return false; + } + + if(thread.Create(this, false) == OYSTER_THREAD_ERROR_FAILED) + { + return false; + } + + return true; +} + +bool NetworkServer::PrivateData::Start() +{ + //Start listener + if(!((Listener*)listener)->Start()) + { + return false; + } + + started = true; + + if(thread.Start() == OYSTER_THREAD_ERROR_FAILED) + { + return false; + } + + return true; +} + +void NetworkServer::PrivateData::Stop() +{ + if(listener) + { + ((Listener*)listener)->Stop(); + } + + started = false; + + thread.Stop(); +} + +void NetworkServer::PrivateData::Shutdown() +{ + //Stop server main thread + thread.Stop(); + + if(listener) + { + delete listener; + listener = NULL; + } + + if(postBox) + { + delete postBox; + postBox = NULL; + } + + started = false; + + ShutdownWinSock(); +} + +//Checks for new clients and sends them to the proc function. +void NetworkServer::PrivateData::CheckForNewClient() +{ + if(postBox->IsFull()) + { + int clientSocketNum = postBox->FetchMessage(); + + //Safety check that is probably not needed. + if(clientSocketNum == -1) + { + return; + } + + //Create client and Proc function if the pointer is not NULL + if(initDesc.callbackType == NetworkClientCallbackType_Function) + { + Oyster::Network::NetworkClient client(clientSocketNum); + initDesc.recvObj.clientConnectFnc(client); + } + else if(initDesc.callbackType == NetworkClientCallbackType_Object) + { + Oyster::Network::NetworkClient client(clientSocketNum); + initDesc.recvObj.clientConnectObject->ClientConnectCallback(client); + } + } +} + +bool NetworkServer::PrivateData::DoWork() +{ + CheckForNewClient(); + + return true; +} + +/************************************* + NetworkServer +*************************************/ + +NetworkServer::NetworkServer() +{ + privateData = new PrivateData(); +} + +NetworkServer::~NetworkServer() +{ + if(privateData) + { + delete privateData; + } +} + +bool NetworkServer::Init(INIT_DESC& initDesc) +{ + if(!privateData->Init(initDesc)) + { + return false; + } + + return true; +} + +bool NetworkServer::Start() +{ + if(!privateData->Start()) + { + return false; + } + + return true; +} + +void NetworkServer::Stop() +{ + privateData->Stop(); +} + +void NetworkServer::Shutdown() +{ + privateData->Shutdown(); +} + +bool NetworkServer::IsStarted() const +{ + return privateData->started; +} \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkServer.h b/Code/Network/NetworkAPI/NetworkServer.h new file mode 100644 index 00000000..8edc59ff --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkServer.h @@ -0,0 +1,54 @@ +#ifndef NETWORK_API_NETWORK_SERVER_H +#define NETWORK_API_NETWORK_SERVER_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#ifdef CUSTOM_NET_PROTOCOL_EXPORT + #define NET_PROTOCOL_EXPORT __declspec(dllexport) +#else + #define NET_PROTOCOL_EXPORT __declspec(dllimport) +#endif + +#include "NetworkClient.h" +#include "NetworkCallbackHelper.h" +#include + +namespace Oyster +{ + namespace Network + { + extern "C" + { + class NET_PROTOCOL_EXPORT NetworkServer + { + public: + struct INIT_DESC + { + unsigned short port; //Port the server should be accepting clients on. + + NetworkClientCallbackType callbackType; //The recieverObject type. Function or object. + RecieverObject recvObj; //The functions that is called when a new client has connected. + }; + + NetworkServer(); + virtual ~NetworkServer(); + + bool Init(INIT_DESC& initDesc); + bool Start(); + void Stop(); + void Shutdown(); + + bool IsStarted() const; + + private: + struct PrivateData; + PrivateData* privateData; + + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp new file mode 100644 index 00000000..75598b75 --- /dev/null +++ b/Code/Network/NetworkAPI/Translator.cpp @@ -0,0 +1,231 @@ +#include "Translator.h" + +#include +#include + +#include "CustomNetProtocol.h" + +#include "../NetworkDependencies/Messages/MessageHeader.h" +#include "../NetworkDependencies/OysterByte.h" + + +using namespace Oyster::Network; +using namespace ::Messages; +using namespace Utility::DynamicMemory; +using namespace std; + +struct MyCastingStruct +{ + std::map attributes; +}; + +// TODO: Check if the package has been packed correctly. +struct Translator::PrivateData +{ + PrivateData() + { + numberOfUnknownTypes = 0; + size = 0; + } + + //Packages a header with a size(int) and a string of characters(char) + void PackHeader(OysterByte &bytes, CustomNetProtocol& protocol) + { + auto it = ((MyCastingStruct*)protocol.privateData)->attributes.begin(); + auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end(); + + size = 4; //size(int) + message.PackInt(size, bytes); + + //Find all the data types + for(; it != end; it++) + { + headerString.push_back(it->second.type); + } + + message.PackShort(size, bytes); + size += 2; + + for(int i = 0; i < (int)headerString.size(); i++) + { + message.PackChar(headerString.at(i), bytes); + size++; + } + + message.SetSize(bytes); + } + + void PackMessage(OysterByte &bytes, CustomNetProtocol& protocol) + { + auto it = ((MyCastingStruct*)protocol.privateData)->attributes.begin(); + auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end(); + + for(int i = 0; i < (int)headerString.size(); i++, it++) + { + switch((int)headerString.at(i)) + { + case NetAttributeType_Bool: + message.PackBool(it->second.value.netBool, bytes); + break; + case NetAttributeType_Char: + message.PackChar(it->second.value.netChar, bytes); + break; + case NetAttributeType_UnsignedChar: + message.PackUnsignedChar(it->second.value.netUChar, bytes); + break; + case NetAttributeType_Short: + message.PackShort(it->second.value.netShort, bytes); + break; + case NetAttributeType_UnsignedShort: + message.PackUnsignedShort(it->second.value.netUShort, bytes); + break; + case NetAttributeType_Int: + message.PackInt(it->second.value.netInt, bytes); + break; + case NetAttributeType_UnsignedInt: + message.PackUnsignedInt(it->second.value.netUInt, bytes); + break; + case NetAttributeType_Int64: + message.PackInt64(it->second.value.netInt64, bytes); + break; + case NetAttributeType_UnsignedInt64: + message.PackUnsignedInt64(it->second.value.netUInt64, bytes); + break; + case NetAttributeType_Float: + message.PackFloat(it->second.value.netFloat, bytes); + break; + case NetAttributeType_Double: + message.PackDouble(it->second.value.netDouble, bytes); + break; + case NetAttributeType_CharArray: + message.PackStr(it->second.value.netCharPtr, bytes); + break; + default: + numberOfUnknownTypes++; + break; + } + } + + message.SetSize(bytes); + } + + bool UnpackHeader(CustomNetProtocol& protocol, OysterByte &bytes) + { + message.SetSize(0); + int packageSize = message.UnpackInt(bytes); + if(packageSize != bytes.GetSize()) + { + return false; + } + + short numberOfTypes = message.UnpackShort(bytes); + + for(int i = 0; i < numberOfTypes; i++) + { + char temp = message.UnpackChar(bytes); + headerString.push_back(temp); + } + + return true; + } + + void UnpackMessage(CustomNetProtocol& protocol, OysterByte &bytes) + { + for(int i = 0; i < (int)headerString.size(); i++) + { + protocol[i].type = (NetAttributeType)headerString.at(i); + switch(protocol[i].type) + { + case NetAttributeType_Bool: + protocol[i].value.netBool = message.UnpackBool(bytes); + break; + case NetAttributeType_Char: + protocol[i].value.netChar = message.UnpackChar(bytes); + break; + case NetAttributeType_UnsignedChar: + protocol[i].value.netUChar = message.UnpackUnsignedChar(bytes); + break; + case NetAttributeType_Short: + protocol[i].value.netShort = message.UnpackShort(bytes); + break; + case NetAttributeType_UnsignedShort: + protocol[i].value.netUShort = message.UnpackUnsignedShort(bytes); + break; + case NetAttributeType_Int: + protocol[i].value.netInt = message.UnpackInt(bytes); + break; + case NetAttributeType_UnsignedInt: + protocol[i].value.netUInt = message.UnpackUnsignedInt(bytes); + break; + case NetAttributeType_Int64: + protocol[i].value.netInt64 = message.UnpackInt64(bytes); + break; + case NetAttributeType_UnsignedInt64: + protocol[i].value.netUInt64 = message.UnpackUnsignedInt64(bytes); + break; + case NetAttributeType_Float: + protocol[i].value.netFloat = message.UnpackFloat(bytes); + break; + case NetAttributeType_Double: + protocol[i].value.netDouble = message.UnpackDouble(bytes); + break; + case NetAttributeType_CharArray: + protocol[i].value.netCharPtr = message.UnpackCStr(bytes); + break; + default: + numberOfUnknownTypes++; + break; + } + } + } + + MessageHeader message; + string headerString; + unsigned int size; + + int numberOfUnknownTypes; +}; + +Translator::Translator() +{ + privateData = new PrivateData(); +} + +Translator::~Translator() +{ + if(privateData) + { + delete privateData; + 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) +{ + privateData->headerString.clear(); + + privateData->PackHeader(bytes, protocol); + privateData->PackMessage(bytes, protocol); +} + +bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes) +{ + if(!privateData->UnpackHeader(protocol, bytes)) + { + return false; + } + + privateData->UnpackMessage(protocol, bytes); + + return true; +} \ No newline at end of file diff --git a/Code/Network/NetworkAPI/Translator.h b/Code/Network/NetworkAPI/Translator.h new file mode 100644 index 00000000..f413492e --- /dev/null +++ b/Code/Network/NetworkAPI/Translator.h @@ -0,0 +1,67 @@ +#ifndef NETWORK_DEPENDENCIES_TRANSLATOR_H +#define NETWORK_DEPENDENCIES_TRANSLATOR_H + +////////////////////////////////// +// Created by Sam Svensson 2013 // +// ----------------------------// +// Packs our dynamic protocols // +////////////////////////////////// + +/* + It packs a header in front of the actual message. + Header looks like this: + - Size of the entire package + - String containing all the types of data that is packed in the package. + +*/ + +/* + Possible optimizing: + If there are several of the same type of data in a row, + we can instead of saving a character for each type we can instead save a number and the character. + + Example: + If we are packing 100 floats. + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..." + Instead of that we can do this: + "100F" +*/ + +#ifdef CUSTOM_NET_PROTOCOL_EXPORT + #define NET_PROTOCOL_EXPORT __declspec(dllexport) +#else + #define NET_PROTOCOL_EXPORT __declspec(dllimport) +#endif + +#include "../../Misc/Utilities.h" + +namespace Oyster +{ + namespace Network + { + extern "C" + { + class OysterByte; + class CustomNetProtocol; + class NET_PROTOCOL_EXPORT Translator + { + public: + Translator (); + ~Translator(); + Translator(const Translator& obj); + const Translator& operator=(const Translator& obj); + + void Pack(OysterByte &bytes, CustomNetProtocol& protocol); + + //Returns false if it discovers any faulty stuff with the package. + bool Unpack(CustomNetProtocol& protocol, OysterByte &bytes); + + private: + struct PrivateData; + PrivateData* privateData; + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 3f303542..84a0cbcc 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -7,6 +7,20 @@ using namespace Oyster::Network; +Connection::Connection() +{ + this->socket = -1; + bool stillSending = false; + bool closed = true; +} + +Connection::Connection(int socket) +{ + this->socket = socket; + bool stillSending = false; + bool closed = true; +} + Connection::~Connection() { closesocket( this->socket ); @@ -30,6 +44,9 @@ int Connection::Connect(unsigned short port , const char serverName[]) return WSAGetLastError(); } + closed = false; + stillSending = true; + //connection succesfull! return 0; } @@ -63,6 +80,9 @@ int Connection::InitiateServer(unsigned short port) return errorCode; } + closed = false; + stillSending = true; + //Server started! return 0; } @@ -74,12 +94,17 @@ int Connection::InitiateClient() int Connection::Disconnect() { - closesocket(this->socket); + int result = closesocket(this->socket); - return WSAGetLastError(); + if(result == SOCKET_ERROR) + { + return WSAGetLastError(); + } + + return 0; } -int Connection::Send(OysterByte& bytes) +int Connection::Send(OysterByte &bytes) { int nBytes; @@ -92,14 +117,15 @@ int Connection::Send(OysterByte& bytes) return 0; } -int Connection::Recieve(OysterByte& bytes) +int Connection::Recieve(OysterByte &bytes) { int nBytes; - bytes.Clear(1000); - nBytes = recv(this->socket, bytes, 500, 0); + bytes.Resize(1000); + nBytes = recv(this->socket, bytes, 1000, 0); if(nBytes == SOCKET_ERROR) { + bytes.SetSize(0); return WSAGetLastError(); } else @@ -107,22 +133,52 @@ int Connection::Recieve(OysterByte& bytes) bytes.SetSize(nBytes); } - std::cout << "Size of the recieved data: " << nBytes << " bytes" << std::endl; - - //bytes.byteArray[nBytes] = '\0'; - return 0; } +//Listen will only return the correct socket or -1 for failure. int Connection::Listen() { int clientSocket; - if((clientSocket = accept(this->socket, NULL, NULL)) == INVALID_SOCKET) + if((clientSocket = (int)accept(this->socket, NULL, NULL)) == INVALID_SOCKET) + { + return (int)INVALID_SOCKET;//WSAGetLastError(); + } + + return clientSocket; +} + +bool Connection::IsSending() +{ + return stillSending; +} + +bool Connection::IsConnected() +{ + return !closed; +} + +int Connection::SetBlockingMode(bool blocking) +{ + DWORD nonBlocking; + + if(blocking) + { + nonBlocking = 0; + } + else + { + nonBlocking = 1; + } + + int result = ioctlsocket(this->socket, FIONBIO, &nonBlocking); + if(result != 0) { return WSAGetLastError(); } - return clientSocket; + //Success + return 0; } /////////////////////////////////////// @@ -130,24 +186,11 @@ int Connection::Listen() /////////////////////////////////////// int Connection::InitiateSocket() { - this->socket = ::socket(AF_INET, SOCK_STREAM, 0); + this->socket = (int)::socket(AF_INET, SOCK_STREAM, 0); if(this->socket == SOCKET_ERROR) { return WSAGetLastError(); } return 0; -} - -void Connection::SetBlockingMode(bool blocking) -{ - //TODO: Implement this function. Setting the socket to blocking or non-blocking. - if(blocking) - { - //fcntl(this->socket, F_SETFL, O_NONBLOCK); - } - else - { - - } } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index b46ccb02..ae76a3f7 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -16,28 +16,35 @@ namespace Oyster { public: - Connection() { this->socket = 0; }; - Connection( int socket ) { this->socket = socket; }; + Connection(); + Connection( int socket ); virtual ~Connection(); - virtual int InitiateServer( unsigned short port ); virtual int InitiateClient(); - virtual int Send( OysterByte& bytes ); - virtual int Recieve( OysterByte& bytes ); + virtual int Send( OysterByte &bytes ); + virtual int Recieve( OysterByte &bytes ); virtual int Disconnect(); virtual int Connect( unsigned short port , const char serverName[] ); virtual int Listen(); + bool IsSending(); + bool IsConnected(); + + //Setting the socket to blocking/non-blocking mode. + int SetBlockingMode( bool blocking ); + private: int InitiateSocket(); - void SetBlockingMode( bool blocking ); int socket; + bool stillSending; + bool closed; + }; } } diff --git a/Code/Network/NetworkDependencies/IConnection.h b/Code/Network/NetworkDependencies/IConnection.h index 5f88932b..76736071 100644 --- a/Code/Network/NetworkDependencies/IConnection.h +++ b/Code/Network/NetworkDependencies/IConnection.h @@ -5,6 +5,8 @@ // Created by Sam Svensson 2013 // ////////////////////////////////// +#include "../../Misc/Utilities.h" + namespace Oyster { namespace Network @@ -17,8 +19,8 @@ namespace Oyster //sends and recieve functions with bytearrays, //will send to the users connection via socket - virtual int Send( OysterByte& bytes ) = 0; - virtual int Recieve( OysterByte& bytes) = 0; + virtual int Send( OysterByte &bytes ) = 0; + virtual int Recieve( OysterByte &bytes) = 0; //initiates sockets and address for server and client virtual int InitiateServer( unsigned short port ) { return false; }; diff --git a/Code/Network/NetworkDependencies/IListener.h b/Code/Network/NetworkDependencies/IListener.h index f08cfb27..f88f23ea 100644 --- a/Code/Network/NetworkDependencies/IListener.h +++ b/Code/Network/NetworkDependencies/IListener.h @@ -14,6 +14,7 @@ namespace Oyster class IListener { public: + virtual ~IListener() {} virtual bool Init(unsigned int port) = 0; virtual int Accept() = 0; diff --git a/Code/Network/NetworkDependencies/IPostBox.h b/Code/Network/NetworkDependencies/IPostBox.h index 31c1bef7..93b1f7b4 100644 --- a/Code/Network/NetworkDependencies/IPostBox.h +++ b/Code/Network/NetworkDependencies/IPostBox.h @@ -15,7 +15,7 @@ namespace Oyster public: virtual ~IPostBox() {} virtual void PostMessage(T& message) = 0; - virtual void FetchMessage(T& message) = 0; + virtual T FetchMessage() = 0; virtual bool IsFull() = 0; }; diff --git a/Code/Network/NetworkDependencies/ITranslate.h b/Code/Network/NetworkDependencies/ITranslate.h index 80edc8b1..64c78763 100644 --- a/Code/Network/NetworkDependencies/ITranslate.h +++ b/Code/Network/NetworkDependencies/ITranslate.h @@ -5,18 +5,20 @@ // Created by Sam Svensson 2013 // ////////////////////////////////// +#include "../../Misc/Utilities.h" + namespace Oyster { namespace Network { + class CustomNetProtocol; class OysterByte; class ITranslate { - public: //packs and unpacks packages for sending or recieving over the connection - virtual void Pack (Protocols::ProtocolHeader &header, OysterByte& bytes) = 0; - virtual void Unpack (Protocols::ProtocolSet* set, OysterByte& bytes ) = 0; + virtual void Pack (Utility::DynamicMemory::SmartPointer &bytes, Oyster::Network::CustomNetProtocol* protocol); + virtual void Unpack (Oyster::Network::CustomNetProtocol* protocol, Utility::DynamicMemory::SmartPointer &bytes); }; } diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index c441d045..20d4c927 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -1,69 +1,118 @@ #include "Listener.h" using namespace Oyster::Network::Server; +using namespace Utility::DynamicMemory; +using namespace Oyster::Thread; Listener::Listener() { connection = NULL; } +Listener::Listener(Oyster::Network::IPostBox* postBox) +{ + connection = NULL; + this->postBox = postBox; +} + Listener::~Listener() { if(connection) { + this->thread.Terminate(); delete connection; + connection = 0; } } +//Starts the thread immediate bool Listener::Init(unsigned int port) { connection = new Connection(); - connection->InitiateServer(port); - thread.Create(this, true); + if(thread.Create(this, true) == OYSTER_THREAD_ERROR_FAILED) + { + return false; + } return true; } +bool Listener::Init(unsigned int port, bool start) +{ + connection = new Connection(); + if(connection->InitiateServer(port) != 0) + { + return false; + } + + if(thread.Create(this, start) == OYSTER_THREAD_ERROR_FAILED) + { + return false; + } + + return true; +} + +bool Listener::Start() +{ + if(thread.Start() == OYSTER_THREAD_ERROR_FAILED) + { + return false; + } + + return true; +} + +void Listener::Stop() +{ + thread.Stop(); +} + void Listener::Shutdown() { - thread.Terminate(); + thread.Stop(); } void Listener::SetPostBox(Oyster::Network::IPostBox* postBox) { - mutex.LockMutex(); + stdMutex.lock(); this->postBox = postBox; - mutex.UnlockMutex(); + stdMutex.unlock(); } int Listener::Accept() { - int clientSocket = 0; + int clientSocket = -1; clientSocket = connection->Listen(); - mutex.LockMutex(); - postBox->PostMessage(clientSocket); - mutex.UnlockMutex(); + if(clientSocket != -1) + { + stdMutex.lock(); + postBox->PostMessage(clientSocket); + stdMutex.unlock(); + } return clientSocket; } bool Listener::DoWork() { - Accept(); + int result = Accept(); + + if(result == -1) + { + //Do something? + } return true; } -#include void Listener::ThreadEntry() { - std::cout << "Thread started" << std::endl; } void Listener::ThreadExit() { - std::cout << "Thread stopped" << std::endl; } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index 8bb16a0f..93188c4c 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -6,10 +6,11 @@ ///////////////////////////////////// #include "IListener.h" -#include "../NetworkDependencies/Connection.h" +#include "Connection.h" +#include "IPostBox.h" #include "../../Misc/Thread/OysterThread.h" #include "../../Misc/Thread/OysterMutex.h" -#include "IPostBox.h" +#include "../../Misc/Utilities.h" namespace Oyster { @@ -17,32 +18,37 @@ namespace Oyster { namespace Server { - class Listener : public ::Oyster::Thread::IThreadObject + class Listener : public IListener, public ::Oyster::Thread::IThreadObject { public: Listener(); + Listener(Oyster::Network::IPostBox* postBox); ~Listener(); bool Init(unsigned int port); + bool Init(unsigned int port, bool start); + bool Start(); + void Stop(); + void Shutdown(); void SetPostBox(IPostBox* postBox); + private: //Thread functions bool DoWork(); void ThreadEntry(); void ThreadExit(); - private: //Function that runs in the thread. int Accept(); - private: ::Oyster::Network::Connection* connection; ::Oyster::Thread::OysterThread thread; OysterMutex mutex; + std::mutex stdMutex; IPostBox* postBox; diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp index 97acf526..d2823b62 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp @@ -41,77 +41,76 @@ void MessageHeader::Unpack(OysterByte& bytes, ProtocolHeader& header) void MessageHeader::PackBool(bool i, OysterByte& bytes) { - bytes.AddSize(1); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 1; + size += sizeof(i); } void MessageHeader::PackChar(char i, OysterByte& bytes) { - bytes.AddSize(1); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 1; + size += sizeof(i); } void MessageHeader::PackUnsignedChar(unsigned char i, OysterByte& bytes) { - bytes.AddSize(1); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 1; + size += sizeof(i); } void MessageHeader::PackShort(short i, OysterByte& bytes) { - bytes.AddSize(2); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 2; + size += sizeof(i); } void MessageHeader::PackUnsignedShort(unsigned short i, OysterByte& bytes) { - bytes.AddSize(2); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 2; + size += sizeof(i); } void MessageHeader::PackInt(int i, OysterByte& bytes) { - bytes.AddSize(4); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 4; + size += sizeof(i); } void MessageHeader::PackUnsignedInt(unsigned int i, OysterByte& bytes) { - bytes.AddSize(4); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 4; + size += sizeof(i); } void MessageHeader::PackInt64(__int64 i, OysterByte& bytes) { - bytes.AddSize(8); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 8; + size += sizeof(i); } void MessageHeader::PackUnsignedInt64(unsigned __int64 i, OysterByte& bytes) { - bytes.AddSize(8); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 8; + size += sizeof(i); } void MessageHeader::PackFloat(float i, OysterByte& bytes) { - bytes.AddSize(4); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 4; + size += sizeof(i); } void MessageHeader::PackFloat(float i[], unsigned int elementCount, OysterByte& bytes) { - bytes.AddSize(4); //Pack number of elements PackUnsignedInt(elementCount, bytes); @@ -124,14 +123,14 @@ void MessageHeader::PackFloat(float i[], unsigned int elementCount, OysterByte& void MessageHeader::PackDouble(double i, OysterByte& bytes) { - bytes.AddSize(8); + bytes.AddSize(sizeof(i)); Packing::Pack(&bytes.GetByteArray()[size], i); - size += 8; + size += sizeof(i); } void MessageHeader::PackStr(char str[], OysterByte& bytes) { - int totalSize = 2 + strlen(str); + int totalSize = sizeof(short) + (int)strlen(str); bytes.AddSize(totalSize); Packing::Pack(&bytes.GetByteArray()[size], str); size += totalSize; @@ -139,7 +138,7 @@ void MessageHeader::PackStr(char str[], OysterByte& bytes) void MessageHeader::PackStr(std::string str, OysterByte& bytes) { - int totalSize = 2 + str.length(); + int totalSize = sizeof(short) + (int)str.length(); bytes.AddSize(totalSize); Packing::Pack(&bytes.GetByteArray()[size], str); size += totalSize; @@ -152,70 +151,70 @@ void MessageHeader::PackStr(std::string str, OysterByte& bytes) bool MessageHeader::UnpackBool(OysterByte& bytes) { bool i = Packing::Unpackb(&bytes.GetByteArray()[size]); - size += 1; + size += sizeof(i); return i; } char MessageHeader::UnpackChar(OysterByte& bytes) { char i = Packing::Unpackc(&bytes.GetByteArray()[size]); - size += 1; + size += sizeof(i); return i; } unsigned char MessageHeader::UnpackUnsignedChar(OysterByte& bytes) { unsigned char i = Packing::UnpackC(&bytes.GetByteArray()[size]); - size += 1; + size += sizeof(i); return i; } short MessageHeader::UnpackShort(OysterByte& bytes) { short i = Packing::Unpacks(&bytes.GetByteArray()[size]); - size += 2; + size += sizeof(i); return i; } unsigned short MessageHeader::UnpackUnsignedShort(OysterByte& bytes) { unsigned short i = Packing::UnpackS(&bytes.GetByteArray()[size]); - size += 2; + size += sizeof(i); return i; } int MessageHeader::UnpackInt(OysterByte& bytes) { int i = Packing::Unpacki(&bytes.GetByteArray()[size]); - size += 4; + size += sizeof(i); return i; } unsigned int MessageHeader::UnpackUnsignedInt(OysterByte& bytes) { unsigned int i = Packing::UnpackI(&bytes.GetByteArray()[size]); - size += 4; + size += sizeof(i); return i; } __int64 MessageHeader::UnpackInt64(OysterByte& bytes) { __int64 i = Packing::Unpacki64(&bytes.GetByteArray()[size]); - size += 8; + size += sizeof(i); return i; } unsigned __int64 MessageHeader::UnpackUnsignedInt64(OysterByte& bytes) { unsigned __int64 i = Packing::UnpackI64(&bytes.GetByteArray()[size]); - size += 8; + size += sizeof(i); return i; } float MessageHeader::UnpackFloat(OysterByte& bytes) { float i = Packing::Unpackf(&bytes.GetByteArray()[size]); - size += 4; + size += sizeof(i); return i; } @@ -237,18 +236,30 @@ float* MessageHeader::UnpackFloat(unsigned int& elementCount, OysterByte& bytes) double MessageHeader::UnpackDouble(OysterByte& bytes) { double i = Packing::Unpackd(&bytes.GetByteArray()[size]); - size += 8; + size += sizeof(i); return i; } +char* MessageHeader::UnpackCStr(OysterByte& bytes) +{ + char* str = Packing::UnpackCStr(&bytes.GetByteArray()[size]); + size += sizeof(short) + (int)strlen(str); + return str; +} + std::string MessageHeader::UnpackStr(OysterByte& bytes) { std::string str = Packing::UnpackStr(&bytes.GetByteArray()[size]); - size += 2 + str.length(); + size += sizeof(short) + (int)str.length(); return str; } void MessageHeader::SetSize(OysterByte& bytes) { Packing::Pack(bytes, size); +} + +void MessageHeader::SetSize(unsigned int size) +{ + this->size = size; } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.h b/Code/Network/NetworkDependencies/Messages/MessageHeader.h index 095ebc1e..b7752401 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.h +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.h @@ -24,7 +24,6 @@ namespace Oyster virtual void Pack(Protocols::ProtocolHeader& header, OysterByte& bytes ); virtual void Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header); - protected: //Pack variables to messages void PackBool(bool i, OysterByte& bytes); @@ -47,9 +46,6 @@ namespace Oyster void PackStr(char str[], OysterByte& bytes); void PackStr(std::string str, OysterByte& bytes); - //TODO: Add Pack functions for Vec2, 3, 4 and maybe Matrix. Etc. - - //Unpack variables from message bool UnpackBool(OysterByte& bytes); @@ -69,14 +65,14 @@ namespace Oyster float* UnpackFloat(unsigned int& elementCount, OysterByte& bytes); double UnpackDouble(OysterByte& bytes); + char* UnpackCStr(OysterByte& bytes); std::string UnpackStr(OysterByte& bytes); - //TODO: Add Unpack functions for Vec2, 3, 4 and maybe Matrix. Etc. - - //Sets the this->size to the first position in msg void SetSize(OysterByte& bytes); + void SetSize(unsigned int size); + private: unsigned int size; diff --git a/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp new file mode 100644 index 00000000..673b586f --- /dev/null +++ b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp @@ -0,0 +1,30 @@ +#include "MessagePlayerPos.h" + +using namespace Oyster::Network; +using namespace Oyster::Network::Messages; +using namespace Oyster::Network::Protocols; + +MessagePlayerPos::MessagePlayerPos() +{ +} + +MessagePlayerPos::~MessagePlayerPos() +{ +} + +void MessagePlayerPos::Pack(Protocols::ProtocolHeader& header, OysterByte& bytes) +{ + MessageHeader::Pack(header, bytes); + + PackInt(static_cast(&header)->ID, bytes); + PackFloat(static_cast(&header)->matrix, static_cast(&header)->nrOfFloats, bytes); + SetSize(bytes); +} + +void MessagePlayerPos::Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header) +{ + MessageHeader::Unpack(bytes, header); + + static_cast(&header)->ID = UnpackInt(bytes); + static_cast(&header)->matrix = UnpackFloat(static_cast(&header)->nrOfFloats, bytes); +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h new file mode 100644 index 00000000..247e200e --- /dev/null +++ b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h @@ -0,0 +1,34 @@ +#ifndef NETWORK_DEPENDENCIES_MESSAGE_PLAYER_POS_H +#define NETWORK_DEPENDENCIES_MESSAGE_PLAYER_POS_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#include "MessageHeader.h" + +namespace Oyster +{ + namespace Network + { + namespace Messages + { + class MessagePlayerPos : public MessageHeader + { + public: + MessagePlayerPos(); + virtual ~MessagePlayerPos(); + + virtual void Pack(Protocols::ProtocolHeader& header, OysterByte& bytes); + virtual void Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header); + + private: + + + + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessagesInclude.h b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h index 8f4d41e3..8bdb5c8a 100644 --- a/Code/Network/NetworkDependencies/Messages/MessagesInclude.h +++ b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h @@ -7,5 +7,6 @@ #include "MessageHeader.h" #include "MessageTest.h" +#include "MessagePlayerPos.h" #endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index dfabbcba..4d2ad291 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -153,12 +153,12 @@ - + - + @@ -168,6 +168,7 @@ + @@ -175,7 +176,7 @@ - + diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 74cb9a56..eadbbeb3 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -2,30 +2,31 @@ - - - - - - + + + + + + + + + + + + - - - - - - - - + + + \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index ef7aa434..99c88d44 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -16,18 +16,37 @@ OysterByte::OysterByte(int cap) byteArray = new unsigned char[capacity]; } +OysterByte::OysterByte(const OysterByte& obj) +{ + this->byteArray = new unsigned char[obj.capacity]; + + for(int i = 0; i < (int)obj.size; i++) + { + this->byteArray[i] = obj.byteArray[i]; + } + this->size = obj.size; + this->capacity = obj.capacity; +} + OysterByte::~OysterByte() { delete[] byteArray; } -void OysterByte::Clear(unsigned int cap) +void OysterByte::Clear() { - delete[] byteArray; - byteArray = new unsigned char[cap]; size = 0; } +void OysterByte::Resize(unsigned int cap) +{ + if(capacity < cap) + { + delete[] byteArray; + byteArray = new unsigned char[cap]; + } +} + int OysterByte::GetSize() { return size; @@ -60,6 +79,21 @@ void OysterByte::SetSize(unsigned int size) this->size = size; } +OysterByte& OysterByte::operator =(const OysterByte& obj) +{ + delete[] this->byteArray; + this->byteArray = new unsigned char[obj.capacity]; + + for(int i = 0; i < (int)obj.size; i++) + { + this->byteArray[i] = obj.byteArray[i]; + } + this->size = obj.size; + this->capacity = obj.capacity; + + return *this; +} + OysterByte::operator char*() { return (char*)byteArray; diff --git a/Code/Network/NetworkDependencies/OysterByte.h b/Code/Network/NetworkDependencies/OysterByte.h index 87a0103c..e525095b 100644 --- a/Code/Network/NetworkDependencies/OysterByte.h +++ b/Code/Network/NetworkDependencies/OysterByte.h @@ -16,23 +16,33 @@ namespace Oyster public: OysterByte(); OysterByte(int cap); + OysterByte(const OysterByte& obj); virtual ~OysterByte(); - void Clear(unsigned int cap); + //Resets size to 0 + void Clear(); + + //Resizes the array with, it does not keep anything in it. + void Resize(unsigned int cap); int GetSize(); unsigned char* GetByteArray(); void AddSize(unsigned int size); void SetBytes(unsigned char* bytes); - void SetSize(unsigned int size); //Only sets the private variable 'size' + + //Only sets the private variable 'size' + void SetSize(unsigned int size); + + OysterByte& operator =(const OysterByte& obj); operator char*(); operator const char*(); operator unsigned char*(); - + private: - void IncreaseCapacity(unsigned int cap); //Expands the byteArray + //Expands the byteArray + void IncreaseCapacity(unsigned int cap); private: diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp index 7adc395c..b6903a0a 100644 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ b/Code/Network/NetworkDependencies/Packing.cpp @@ -87,7 +87,7 @@ namespace Oyster //floating point (32, 64-bit) void Pack(unsigned char buffer[], float i) { - int tempFloat = Pack754(i, 32, 8); + int tempFloat = (int)Pack754(i, 32, 8); Pack(buffer, tempFloat); } @@ -100,7 +100,7 @@ namespace Oyster //string void Pack(unsigned char buffer[], char str[]) { - short len = strlen(str); + short len = (short)strlen(str); Pack(buffer, len); buffer += 2; memcpy(buffer, str, len); @@ -108,7 +108,7 @@ namespace Oyster void Pack(unsigned char buffer[], std::string& str) { - short len = str.length(); + short len = (short)str.length(); Pack(buffer, len); buffer += 2; memcpy(buffer, str.c_str(), len); @@ -153,7 +153,7 @@ namespace Oyster fnorm = fnorm - 1.0; // calculate the binary form (non-float) of the significand data - significand = fnorm * ((1LL << significandbits) + 0.5f); + significand = (long long)(fnorm * ((1LL << significandbits) + 0.5f)); // get the biased exponent exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias @@ -169,7 +169,7 @@ namespace Oyster //bool (1-bit) bool Unpackb(unsigned char buffer[]) { - return (bool)buffer; + return buffer; } //char (8-bit) @@ -279,6 +279,20 @@ namespace Oyster } //string + char* UnpackCStr(unsigned char buffer[]) + { + short len = UnpackS(buffer); + char* str = new char[len]; + + buffer += 2; + for(int i = 0; i < len; i++) + { + str[i] = buffer[i]; + } + + return str; + } + std::string UnpackStr(unsigned char buffer[]) { short len = UnpackS(buffer); @@ -305,7 +319,7 @@ namespace Oyster return 0.0; // pull the significand - result = (i&((1LL << significandbits) - 1)); // mask + result = (long double)(i&((1LL << significandbits) - 1)); // mask result /= (1LL << significandbits); // convert back to float result += 1.0f; // add the one back on diff --git a/Code/Network/NetworkDependencies/Packing.h b/Code/Network/NetworkDependencies/Packing.h index 7a52c644..aaf3a1b8 100644 --- a/Code/Network/NetworkDependencies/Packing.h +++ b/Code/Network/NetworkDependencies/Packing.h @@ -73,6 +73,7 @@ namespace Oyster double Unpackd(unsigned char buffer[]); //string + char* UnpackCStr(unsigned char buffer[]); std::string UnpackStr(unsigned char buffer[]); long double Unpack754(unsigned __int64 i, unsigned bits, unsigned expbits); diff --git a/Code/Network/NetworkDependencies/PostBox.h b/Code/Network/NetworkDependencies/PostBox.h index b2e553f8..baaa8cc5 100644 --- a/Code/Network/NetworkDependencies/PostBox.h +++ b/Code/Network/NetworkDependencies/PostBox.h @@ -23,7 +23,7 @@ namespace Oyster virtual ~PostBox(); virtual void PostMessage(T& message); - virtual void FetchMessage(T& message); + virtual T FetchMessage(); virtual bool IsFull(); private: @@ -49,13 +49,9 @@ namespace Oyster } template - void PostBox::FetchMessage(T& message) + T PostBox::FetchMessage() { - if(IsFull()) - { - message = messages.Front(); - messages.Pop(); - } + return messages.Pop(); } template diff --git a/Code/Network/NetworkDependencies/Protocols.h b/Code/Network/NetworkDependencies/Protocols.h index 8defcfb3..adf7154e 100644 --- a/Code/Network/NetworkDependencies/Protocols.h +++ b/Code/Network/NetworkDependencies/Protocols.h @@ -22,7 +22,7 @@ namespace Oyster PackageType_header, PackageType_test, PackageType_input, - PackageType_update_position + PackageType_player_pos, }; struct ProtocolHeader @@ -45,6 +45,16 @@ namespace Oyster virtual ~ProtocolTest() { delete[] f; } }; + struct ProtocolPlayerPos : public ProtocolHeader + { + int ID; + unsigned int nrOfFloats; + float *matrix; + + ProtocolPlayerPos() { this->packageType = PackageType_player_pos; } + virtual ~ProtocolPlayerPos() { delete[] matrix; } + }; + //Holding every protocol in an union. //Used because we now don't have to type case our protocol when we recieve them. @@ -56,6 +66,7 @@ namespace Oyster { ProtocolHeader* pHeader; ProtocolTest *pTest; + ProtocolPlayerPos *pPlayerPos; }Protocol; @@ -75,6 +86,12 @@ namespace Oyster delete Protocol.pTest; } break; + case PackageType_player_pos: + if(Protocol.pPlayerPos) + { + delete Protocol.pPlayerPos; + } + break; } } }; diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp new file mode 100644 index 00000000..fc652f7f --- /dev/null +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -0,0 +1,153 @@ +#include "ThreadedClient.h" +#include "OysterByte.h" + +#include +using namespace Oyster::Network; +using namespace Oyster::Thread; +using namespace Utility::DynamicMemory; + +ThreadedClient::ThreadedClient() +{ + this->connection = new Connection(); + this->sendPostBox = new PostBox; + this->recvPostBox = NULL; + + connection->SetBlockingMode(false); +} + +ThreadedClient::ThreadedClient(unsigned int socket) +{ + this->connection = new Connection(socket); + this->sendPostBox = new PostBox; + this->recvPostBox = NULL; + + connection->SetBlockingMode(false); + + thread.Create(this, true); +} + +ThreadedClient::ThreadedClient(IPostBox* postBox, unsigned int socket) +{ + this->connection = new Connection(socket); + this->sendPostBox = new PostBox; + this->recvPostBox = postBox; + + connection->SetBlockingMode(false); + + thread.Create(this, true); +} + +ThreadedClient::~ThreadedClient() +{ + thread.Terminate(); + delete this->connection; + this->connection = NULL; + this->recvPostBox = NULL; + + if(sendPostBox != NULL) + { + delete sendPostBox; + this->sendPostBox = NULL; + } +} + +void ThreadedClient::Send(CustomNetProtocol* protocol) +{ + this->sendPostBox->PostMessage(protocol); +} + +bool ThreadedClient::IsConnected() +{ + return connection->IsConnected(); +} + +void ThreadedClient::Disconnect() +{ + connection->Disconnect(); +} + +int ThreadedClient::Send() +{ + int errorCode = 0; + + if(sendPostBox->IsFull()) + { + OysterByte temp; + sendPostBox->FetchMessage(); + //errorCode = this->connection->Send(temp); + } + + return errorCode; +} + +int ThreadedClient::Recv() +{ + int errorCode = -1; + + OysterByte temp; + errorCode = this->connection->Recieve(temp); + + if(errorCode == 0) + { + stdMutex.lock(); + //recvPostBox->PostMessage(temp); + stdMutex.unlock(); + } + + return errorCode; +} + +void ThreadedClient::ThreadEntry() +{ + std::cout<< "Client Thread started" << std::endl; +} + +void ThreadedClient::ThreadExit() +{ + std::cout << "Client Thread exit" << std::endl; +} + +#include + +bool ThreadedClient::DoWork() +{ + int errorCode; + errorCode = Send(); + /*if(errorCode != 0) + { + return false; + }*/ + + errorCode = Recv(); + /*if(errorCode != 0) + { + return false; + }*/ + Sleep(1); + return true; +} + +int ThreadedClient::Connect(unsigned short port, const char serverName[]) +{ + int errorCode; + + if((errorCode = connection->InitiateClient()) != 0) + { + return errorCode; + } + + else if((errorCode = connection->Connect(port, serverName)) != 0) + { + return errorCode; + } + + thread.Create(this, true); + return 0; +} + +void ThreadedClient::setRecvPostBox(IPostBox *postBox) +{ + stdMutex.lock(); + this->recvPostBox = postBox; + stdMutex.unlock(); +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h new file mode 100644 index 00000000..b125f401 --- /dev/null +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -0,0 +1,60 @@ +#ifndef NETWORK_DEPENDENCIES_THREADED_CLIENT_H +#define NETWORK_DEPENDENCIES_THREADED_CLIENT_H + +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "../../Misc/Thread/IThreadObject.h" +#include "PostBox.h" +#include "Connection.h" +#include "../../Misc/Thread/OysterThread.h" +#include "../../Misc/Utilities.h" + +#include + +namespace Oyster +{ + namespace Network + { + class CustomNetProtocol; + class OysterByte; + class ThreadedClient : public Thread::IThreadObject + { + public: + ThreadedClient(); + ThreadedClient(unsigned int socket); + ThreadedClient(IPostBox *postBox, unsigned int socket); + virtual ~ThreadedClient(); + + void Send(CustomNetProtocol* protocol); + + bool IsConnected(); + + int Connect(unsigned short port, const char serverName[]); + + void Disconnect(); + + void setRecvPostBox(IPostBox *postBox); + + protected: + virtual int Send(); + virtual int Recv(); + + //These functions should not be called by any other than the thread. + virtual void ThreadEntry(); + virtual void ThreadExit(); + virtual bool DoWork(); + + protected: + Connection* connection; + IPostBox *sendPostBox; + IPostBox *recvPostBox; + Oyster::Thread::OysterThread thread; + std::mutex stdMutex; + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Translator.cpp b/Code/Network/NetworkDependencies/Translator.cpp deleted file mode 100644 index 4bb739ca..00000000 --- a/Code/Network/NetworkDependencies/Translator.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "Translator.h" - -using namespace Oyster::Network; -using namespace ::Protocols; -using namespace ::Messages; - -void Translator::Pack( ProtocolHeader &header, OysterByte& bytes ) -{ - MessageHeader *message = NULL; - - switch(header.packageType) - { - case PackageType_header: - message = new MessageHeader(); - break; - - case PackageType_test: - message = new MessageTest(); - break; - } - - if(message != NULL) - { - message->Pack(header, bytes); - - delete message; - message = NULL; - } -} - -void Translator::Unpack(ProtocolSet* set, OysterByte& bytes ) -{ - ProtocolHeader *header = new ProtocolHeader(); - MessageHeader *message = new MessageHeader(); - - message->Unpack(bytes, *header); - delete message; - message = NULL; - - //Switch to the correct package. - set->type = (PackageType)header->packageType; - switch(set->type) - { - case PackageType_header: - message = new MessageHeader(); - set->Protocol.pHeader = new ProtocolHeader; - message->Unpack(bytes, *set->Protocol.pHeader); - break; - - case PackageType_test: - message = new MessageTest(); - set->Protocol.pTest = new ProtocolTest; - message->Unpack(bytes, *set->Protocol.pTest); - break; - } - - if(message) - { - delete message; - } - delete header; - - //return set; -} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Translator.h b/Code/Network/NetworkDependencies/Translator.h deleted file mode 100644 index 56459f72..00000000 --- a/Code/Network/NetworkDependencies/Translator.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NETWORK_DEPENDENCIES_TRANSLATOR_H -#define NETWORK_DEPENDENCIES_TRANSLATOR_H - -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "Messages/MessagesInclude.h" -#include "Protocols.h" -#include "ITranslate.h" -#include "OysterByte.h" - -namespace Oyster -{ - namespace Network - { - class Translator : public ITranslate - { - public: - Translator () { }; - ~Translator() { }; - - void Pack (Protocols::ProtocolHeader &header, OysterByte& bytes ); - void Unpack (Protocols::ProtocolSet* set, OysterByte& bytes ); - - private: - - }; - } -} - -#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/WinsockFunctions.cpp b/Code/Network/NetworkDependencies/WinsockFunctions.cpp index ea3c3b00..15ed2ef4 100644 --- a/Code/Network/NetworkDependencies/WinsockFunctions.cpp +++ b/Code/Network/NetworkDependencies/WinsockFunctions.cpp @@ -1,3 +1,8 @@ +#ifndef INCLUDE_WINSOCK_LIB +#define INCLUDE_WINSOCK_LIB + #pragma comment(lib, "ws2_32.lib") +#endif + #include "WinsockFunctions.h" #include @@ -17,14 +22,14 @@ std::wstring GetErrorMessage(int errorCode) LPWSTR lpMessage; std::wstring retVal(L"Succesful"); - DWORD bufLen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS , + DWORD bufLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS , NULL, errorCode , MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) , (LPWSTR)&lpMessage, 0 , NULL ); - + if(bufLen) { retVal = lpMessage; diff --git a/Code/Network/OysterNetworkClient/Client.cpp b/Code/Network/OysterNetworkClient/Client.cpp deleted file mode 100644 index daffe9b6..00000000 --- a/Code/Network/OysterNetworkClient/Client.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "Client.h" - -using namespace Oyster::Network::Client; - -Client::Client() -{ - connection = new Connection(); -} - -Client::~Client() -{ - delete this->connection; - connection = 0; -} - -int Client::Connect(unsigned int port, char filename[]) -{ - int errorCode; - - if((errorCode = connection->InitiateClient()) != 0) - { - return errorCode; - } - - if((errorCode = connection->Connect(port, filename)) != 0) - { - return errorCode; - } - - return 0; -} - -void Client::Send(Oyster::Network::OysterByte& bytes) -{ - connection->Send(bytes); -} - -void Client::Recv(Oyster::Network::OysterByte& bytes) -{ - connection->Recieve(bytes); -} \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/Client.h b/Code/Network/OysterNetworkClient/Client.h deleted file mode 100644 index 6e69e657..00000000 --- a/Code/Network/OysterNetworkClient/Client.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef NETWORK_CLIENT_CLIENT_H -#define NETWORK_CLIENT_CLIENT_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "../NetworkDependencies/Connection.h" -#include "../NetworkDependencies/OysterByte.h" - -namespace Oyster -{ - namespace Network - { - namespace Client - { - class Client - { - public: - Client(); - ~Client(); - - int Connect(unsigned int port, char filename[]); - - void Send(OysterByte& bytes); - void Recv(OysterByte& bytes); - - private: - ::Oyster::Network::Connection* connection; - }; - } - } -} - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index b8f1057f..31e499cc 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -2,19 +2,26 @@ #include #include #include "../NetworkDependencies/WinsockFunctions.h" -#include "..\NetworkDependencies\Translator.h" #include "..\NetworkDependencies\Protocols.h" #include "../NetworkDependencies/OysterByte.h" #include "../../Misc/ThreadSafeQueue.h" -#include "Client.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::Client; +using namespace Oyster::Network; +using namespace Utility; +using namespace Utility::DynamicMemory; -void chat(Client &client); +void proc(CustomNetProtocol& protocol) +{ + +} int main() { @@ -27,95 +34,29 @@ int main() cout << "Client" << endl; //Create Client - Client client; + NetworkClient client; //Connect to server - errorCode = client.Connect(9876, "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) + if(errorCode != 1) { - wstring errorTest = GetErrorMessage(errorCode); - wcout << "errorMessage: " << errorTest << endl; + printf("%d", errorCode); + cout << "FAILED" << endl; } + //client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); - chat(client); + cout << "Done" << endl; + + while(1) + { + + } ShutdownWinSock(); system("pause"); return 0; -} - -void chat(Client &client) -{ - Oyster::Network::Translator *t = new Oyster::Network::Translator(); - - Oyster::Network::OysterByte msgRecv; - string msgSend = ""; - - ProtocolSet* set = new ProtocolSet; - ProtocolTest test; - test.numOfFloats = 5; - test.f = new float[test.numOfFloats]; - float temp = 12345.5654f; - for(int i = 0; i < 5; i++) - { - test.f[i] = temp; - temp++; - } - - bool chatDone = false; - - while(!chatDone) - { - client.Recv(msgRecv); - - t->Unpack(set, msgRecv); - - switch(set->type) - { - case PackageType_header: - break; - case PackageType_test: - cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) - { - cout << set->Protocol.pTest->f[i] << ' ' ; - } - cout << endl; - break; - } - - set->Release(); - msgRecv.Clear(1000); - - /*std::getline(std::cin, msgSend); - - - - if( msgSend != "exit") - { - if(msgSend.length() < 1) - { - msgSend = "ERROR!"; - } - - test.textMessage = msgSend; - - t->Pack(test, msgRecv); - - client.Send(msgRecv); - } - - else - { - chatDone = true; - } - - cin.clear();*/ - - } - - delete t; - delete set; } \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj index f4e13099..bc491966 100644 --- a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj +++ b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj @@ -66,32 +66,32 @@ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath) + $(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + $(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\NetworkAPI;$(SolutionDir)..\Bin\DLL;C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(OutDir)..\DLL\ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath) + C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath);$(OutDir)..\DLL\ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath) + C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath);$(OutDir)..\DLL\ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath) + C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath);$(OutDir)..\DLL\ @@ -102,6 +102,9 @@ true + + + NetworkAPI_$(PlatformShortName)D.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -113,6 +116,7 @@ true + NetworkAPI_$(PlatformShortName)D.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -128,6 +132,7 @@ true true true + NetworkAPI_$(PlatformShortName)D.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -143,23 +148,23 @@ true true true + NetworkAPI_$(PlatformShortName)D.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + {460d625f-2ac9-4559-b809-0ba89ceaedf4} + {c5aa09d0-6594-4cd3-bd92-1d380c7b3b50} - - - - diff --git a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters index 2e5e9ef6..cd4a498b 100644 --- a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters +++ b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters @@ -18,13 +18,5 @@ Source Files - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.cpp b/Code/Network/OysterNetworkServer/Client.cpp deleted file mode 100644 index 5cc15eec..00000000 --- a/Code/Network/OysterNetworkServer/Client.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "Client.h" - -using namespace Oyster::Network; -using namespace Oyster::Network::Server; - -Client::Client(unsigned int socket) -{ - connection = new Connection(socket); -} - -Client::~Client() -{ - delete connection; -} - -void Client::Send(OysterByte& bytes) -{ - connection->Send(bytes); -} - -void Client::Recv(OysterByte& bytes) -{ - connection->Recieve(bytes); -} \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.h b/Code/Network/OysterNetworkServer/Client.h deleted file mode 100644 index 2c5ba35f..00000000 --- a/Code/Network/OysterNetworkServer/Client.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef NETWORK_SERVER_CLIENT_H -#define NETWORK_SERVER_CLIENT_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "../NetworkDependencies/Connection.h" -#include "../NetworkDependencies/OysterByte.h" - -namespace Oyster -{ - namespace Network - { - namespace Server - { - class Client - { - public: - Client(unsigned int socket); - ~Client(); - - void Send(OysterByte& bytes); - void Recv(OysterByte& bytes); - - private: - ::Oyster::Network::Connection* connection; - - }; - } - } -}; - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj index 65136729..089427f7 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj @@ -66,32 +66,32 @@ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath) + C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath);$(OutDir)..\DLL\ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath) + C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath);$(OutDir)..\DLL\ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath) + C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath);$(OutDir)..\DLL\ - $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath) + C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath);$(OutDir)..\DLL\ @@ -102,6 +102,9 @@ true + + + NetworkAPI_$(PlatformShortName)D.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -149,17 +152,16 @@ {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + {460d625f-2ac9-4559-b809-0ba89ceaedf4} + {c5aa09d0-6594-4cd3-bd92-1d380c7b3b50} - - - - diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters index 3cb5827c..f8025a15 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters @@ -18,13 +18,5 @@ Source Files - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 9dd0a0c1..7f78bc78 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -1,128 +1,46 @@ #include -#include #include #include #include "../NetworkDependencies/WinsockFunctions.h" -#include "../NetworkDependencies/Listener.h" -#include "../NetworkDependencies/Translator.h" -#include "Client.h" -#include "../NetworkDependencies/OysterByte.h" -#include "../NetworkDependencies/PostBox.h" -#include "../../Misc/WinTimer.h" +#include "../NetworkAPI/NetworkServer.h" -#pragma comment(lib, "ws2_32.lib") - -using namespace std; -using namespace Oyster::Network::Server; using namespace Oyster::Network; -using namespace ::Protocols; -using namespace Utility; +using namespace std; + +void proc(NetworkClient client) +{ + cout << "Hej" << endl; +} int main() { - OysterByte recvBuffer; - IPostBox* postBox = new PostBox(); + NetworkServer server; + Oyster::Network::NetworkServer::INIT_DESC desc; + desc.port = 15151; + desc.callbackType = NetworkClientCallbackType_Function; + desc.recvObj = proc; - cout << "Server" << endl; - Translator t; - int errorCode; - - if(!InitWinSock()) + if(!server.Init(desc)) { - cout << "errorMessage: unable to start winsock" << endl; + cout << "Init failed" << endl; + return 0; } - //Create socket - Listener listener; - listener.Init(9876); - listener.SetPostBox(postBox); - Sleep(1000); - - //Start listening - //Accept a client - ProtocolTest test; - test.clientID = 0; - test.size = 2; - test.textMessage = "hej"; - test.numOfFloats = 0; - test.f = new float[test.numOfFloats]; - float temp = 395.456f; - for(int i = 0; i < (int)test.numOfFloats; i++) + if(!server.Start()) { - test.f[i] = temp; - temp--; + cout << "Start failed" << endl; + return 0; } - t.Pack(test, recvBuffer); - - WinTimer timer; - - vector clients; - int client = -1; - while(1) - { - client = -1; - postBox->FetchMessage(client); - if(client != -1) - { - cout << "Client connected: " << client << endl; - clients.push_back(new Client(client)); - - clients.at(clients.size()-1)->Send(recvBuffer); - } - - //Send a message every 1 secounds to all clients. - if(timer.getElapsedSeconds() > 1) - { - cout << "Sending to " << clients.size() << " clients." << endl; - timer.reset(); - for(int i = 0; i < (int)clients.size(); i++) - { - clients.at(i)->Send(recvBuffer); - } - } - Sleep(100); - } - listener.Shutdown(); - - /* - ProtocolSet* set = new ProtocolSet; - - client1.Send(recvBuffer); + cout << "Server started" << endl; while(1) { - client1.Recv(recvBuffer); - t.Unpack(set, recvBuffer); - cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl; - cout << "Client1: " << set->Protocol.pTest->textMessage << endl; - for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++) - { - cout << set->Protocol.pTest->f[i] << ' '; - } - cout << endl; - set->Release(); - client2.Send(recvBuffer); - - client2.Recv(recvBuffer); - - t.Unpack(set, recvBuffer); - cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl; - cout << "Client2: " << set->Protocol.pTest->textMessage << endl; - for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++) - { - cout << set->Protocol.pTest->f[i] << ' '; - } - cout << endl; - set->Release(); - client1.Send(recvBuffer); } - ShutdownWinSock(); - delete set; - */ system("pause"); + return 0; -} +} \ No newline at end of file diff --git a/Code/OysterGraphics/Core/Init.cpp b/Code/OysterGraphics/Core/Init.cpp index c69b80b4..548615d2 100644 --- a/Code/OysterGraphics/Core/Init.cpp +++ b/Code/OysterGraphics/Core/Init.cpp @@ -32,7 +32,8 @@ namespace Oyster log << "DirectX running in debug mode.\n"; createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif - + + createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; D3D_FEATURE_LEVEL featureLevelsToTry[] = { diff --git a/Code/OysterGraphics/Core/ShaderManager.cpp b/Code/OysterGraphics/Core/ShaderManager.cpp index 94f7fd57..c4f1b38e 100644 --- a/Code/OysterGraphics/Core/ShaderManager.cpp +++ b/Code/OysterGraphics/Core/ShaderManager.cpp @@ -279,7 +279,7 @@ namespace Oyster void Core::ShaderManager::Clean() { - for(int i = 0; i < VData.size(); ++i) + for(int i = 0; i < (int)VData.size(); ++i) { delete[] VData[i].data; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index b5de4fda..fcb3481c 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -4,11 +4,18 @@ #include "../Render/Rendering/Render.h" #include "../FileLoader/ObjReader.h" #include "../../Misc/Resource/OysterResource.h" +#include "../FileLoader/GeneralLoader.h" namespace Oyster { namespace Graphics { + namespace + { + Math::Float4x4 View; + Math::Float4x4 Projection; + } + API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion) { Core::resolution = resulotion; @@ -26,16 +33,31 @@ namespace Oyster return API::Sucsess; } - void API::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection) + void API::SetProjection(Math::Float4x4& projection) + { + Projection = projection; + } + + void API::SetView(Math::Float4x4& view) + { + View = view; + } + + void API::NewFrame() { Render::Rendering::Basic::NewFrame(View, Projection); } - void API::RenderScene(Model::Model* models, int count) + void API::RenderScene(Model::Model models[], int count) { Render::Rendering::Basic::RenderScene(models,count); } + void API::RenderModel(Model::Model& m) + { + Render::Rendering::Basic::RenderScene(&m,1); + } + void API::EndFrame() { Render::Rendering::Basic::EndFrame(); @@ -52,9 +74,7 @@ namespace Oyster m->WorldMatrix = Oyster::Math::Float4x4::identity; m->Visible = true; - OBJReader or; - or.readOBJFile(filename); - m->info = or.toModel(); + m->info = Oyster::Resource::OysterResource::LoadResource(filename.c_str(),Oyster::Graphics::Loading::LoadOBJ); return m; } @@ -63,7 +83,7 @@ namespace Oyster { Model::ModelInfo* info = (Model::ModelInfo*)model->info; delete model; - info->Vertices->~Buffer(); + Oyster::Resource::OysterResource::ReleaseResource((Oyster::Resource::OHRESOURCE)info); } void API::Clean() @@ -72,6 +92,14 @@ namespace Oyster Oyster::Resource::OysterResource::Clean(); Oyster::Graphics::Core::ShaderManager::Clean(); Oyster::Graphics::Render::Resources::Clean(); + + SAFE_RELEASE(Core::depthStencil); + SAFE_RELEASE(Core::backBufferRTV); + SAFE_RELEASE(Core::backBufferUAV); + + SAFE_RELEASE(Core::swapChain); + SAFE_RELEASE(Core::deviceContext); + SAFE_RELEASE(Core::device); } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index e55a435f..f4c38076 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -4,13 +4,12 @@ #include "OysterMath.h" #include -#if defined GFX_DLL_EXPORT +#ifdef GFX_DLL_EXPORT #define GFX_DLL_USAGE __declspec(dllexport) #else - #define GFX_DLL_USAGE __declspec(dllimport) + #define GFX_DLL_USAGE #endif - namespace Oyster { namespace Graphics @@ -29,9 +28,14 @@ namespace Oyster static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); static void Clean(); - //! @brief from Oyster::Math Float4x4, expects corect methods - static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection); - static void RenderScene(Oyster::Graphics::Model::Model* models, int count); + + static void SetView(Oyster::Math::Float4x4& View); + static void SetProjection(Oyster::Math::Float4x4& Projection); + + //! @brief will internally use last values from SetView and SetProjection + static void NewFrame(); + static void RenderScene(Oyster::Graphics::Model::Model models[], int count); + static void RenderModel(Oyster::Graphics::Model::Model& model); static void EndFrame(); static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename); diff --git a/Code/OysterGraphics/FileLoader/GeneralLoader.h b/Code/OysterGraphics/FileLoader/GeneralLoader.h index fcce1e02..4eab570b 100644 --- a/Code/OysterGraphics/FileLoader/GeneralLoader.h +++ b/Code/OysterGraphics/FileLoader/GeneralLoader.h @@ -27,7 +27,8 @@ namespace Oyster void UnloadShaderD(void* loadedData); void LoadShaderD(const wchar_t filename[], Oyster::Resource::CustomData& out); - void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type); + void UnloadOBJ(void* loadedData); + void LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out); } } } \ No newline at end of file diff --git a/Code/OysterGraphics/FileLoader/TextureLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp similarity index 97% rename from Code/OysterGraphics/FileLoader/TextureLoader.cpp rename to Code/OysterGraphics/FileLoader/ModelLoader.cpp index 1c6ba263..0fe623a9 100644 --- a/Code/OysterGraphics/FileLoader/TextureLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -1,6 +1,7 @@ #include "GeneralLoader.h" #include "..\Core\Dx11Includes.h" #include "..\Core\Core.h" +#include "ObjReader.h" HRESULT CreateWICTextureFromFileEx( ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, @@ -35,6 +36,30 @@ void Oyster::Graphics::Loading::UnloadTexture(void* data) SAFE_RELEASE(srv); } +void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out) +{ + OBJReader obj; + obj.readOBJFile(filename); + Model::ModelInfo* info; + info = obj.toModel(); + out.loadedData = info; + out.resourceUnloadFnc = Oyster::Graphics::Loading::UnloadOBJ; +} + +void Oyster::Graphics::Loading::UnloadOBJ(void* data) +{ + Model::ModelInfo* info = (Model::ModelInfo*) data; + SAFE_DELETE(info->Vertices); + if(info->Indexed) + { + SAFE_DELETE(info->Indecies); + } + for(int i =0;iMaterial.size();++i) + { + Oyster::Resource::OysterResource::ReleaseResource(info->Material[i]); + } + delete info; +} #include #include diff --git a/Code/OysterGraphics/FileLoader/ObjReader.cpp b/Code/OysterGraphics/FileLoader/ObjReader.cpp index 7eb1e268..923f0747 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.cpp +++ b/Code/OysterGraphics/FileLoader/ObjReader.cpp @@ -95,7 +95,7 @@ void OBJReader::readOBJFile( std::wstring fileName ) inStream.close(); - Mat = Oyster::Resource::OysterResource::LoadResource((fileName + L".jpg").c_str(),Oyster::Graphics::Loading::LoadTexture); + Mat = Oyster::Resource::OysterResource::LoadResource((fileName + L".png").c_str(),Oyster::Graphics::Loading::LoadTexture); } Oyster::Graphics::Model::ModelInfo* OBJReader::toModel() diff --git a/Code/OysterGraphics/FileLoader/ShaderLoader.cpp b/Code/OysterGraphics/FileLoader/ShaderLoader.cpp index 5a7ba9e3..b3c8a0b7 100644 --- a/Code/OysterGraphics/FileLoader/ShaderLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ShaderLoader.cpp @@ -10,6 +10,8 @@ namespace Oyster { namespace Loading { + void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type); + void UnloadShaderP(void* loadedData) { ID3D11PixelShader* ps = ((ID3D11PixelShader*)loadedData); @@ -165,14 +167,16 @@ namespace Oyster data.data = new char[data.size]; memcpy(data.data,Shader->GetBufferPointer(),data.size); #else + std::ifstream stream; + stream.open(filename, std::ifstream::in | std::ifstream::binary); if(stream.good()) { stream.seekg(0, std::ios::end); - sd.size = size_t(stream.tellg()); - sd.data = new char[sd.size]; + data.size = size_t(stream.tellg()); + data.data = new char[data.size]; stream.seekg(0, std::ios::beg); - stream.read(&sd.data[0], sd.size); + stream.read(&data.data[0], data.size); stream.close(); } else @@ -180,7 +184,6 @@ namespace Oyster memset(&out,0,sizeof(out)); return; } - #endif out.loadedData = Core::ShaderManager::CreateShader(data, Core::ShaderManager::ShaderType(type)); } diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj b/Code/OysterGraphics/OysterGraphics.vcxproj index 0df3d45b..cd1a5670 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj +++ b/Code/OysterGraphics/OysterGraphics.vcxproj @@ -109,6 +109,7 @@ $(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso + 5.0 @@ -124,12 +125,13 @@ $(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso + 5.0 Level3 - MaxSpeed + Disabled true true true @@ -143,12 +145,14 @@ $(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso + true + 5.0 Level3 - MaxSpeed + Disabled true true true @@ -162,6 +166,8 @@ $(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso + true + 5.0 @@ -172,7 +178,7 @@ - + @@ -264,6 +270,8 @@ + + diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index 50e7f9f1..2edb318b 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -2,6 +2,8 @@ #include "../Resources/Resources.h" #include "../../Definitions/GraphicalDefinition.h" #include "../../Model/ModelInfo.h" +#include +#include namespace Oyster { @@ -60,7 +62,8 @@ namespace Oyster } void Basic::EndFrame() { - Core::swapChain->Present(0,0); + IDXGISwapChain* chain = Core::swapChain; + chain->Present(0,0); } } } diff --git a/Code/OysterGraphics/Render/Resources/Resources.cpp b/Code/OysterGraphics/Render/Resources/Resources.cpp index 2bda54e1..ceef5160 100644 --- a/Code/OysterGraphics/Render/Resources/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources/Resources.cpp @@ -3,7 +3,8 @@ // /Bin/Executable/Tester -> // /Code/OysterGraphics/Shader/HLSL -const std::wstring PathFromExeToHlsl = L"..\\..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\"; +const std::wstring PathFromExeToCso = L"..\\Content\\Shaders\\"; +const std::wstring PathFromExeToHlsl = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\"; const std::wstring VertexTransformDebug = L"TransformDebugVertex"; const std::wstring VertexDebug = L"DebugVertex"; const std::wstring PixelRed = L"DebugPixel"; @@ -42,6 +43,12 @@ namespace Oyster #else /** Load Vertex Shader with Precompiled */ + Core::ShaderManager::Init(PathFromExeToCso + L"DebugCameraVertex.cso",ShaderType::Vertex, VertexTransformDebug); + Core::ShaderManager::Init(PathFromExeToCso + L"DebugVertex.cso",ShaderType::Vertex, VertexDebug); + + /** Load Pixel Shader with Precompiled */ + Core::ShaderManager::Init(PathFromExeToCso + L"DebugPixel.cso",ShaderType::Pixel, PixelRed); + Core::ShaderManager::Init(PathFromExeToCso + L"TextureDebug.cso",ShaderType::Pixel, PixelTexture); #endif #pragma endregion @@ -152,10 +159,9 @@ namespace Oyster void Resources::Clean() { Resources::ModelData.~Buffer(); - Resources::VPData.~Buffer(); for(int i = 0; i < obj.CBuffers.Vertex.size(); ++i) { - //SAFE_RELEASE(obj.CBuffers.Vertex[i]); + obj.CBuffers.Vertex[i]->~Buffer(); } for(int i = 0; i < obj.CBuffers.Pixel.size(); ++i) { diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/Defines.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/Defines.hlsli index e5a2333f..3f9fd0bf 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/Defines.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/Defines.hlsli @@ -1,7 +1,31 @@ +#ifndef DEFINES +#define DEFINES + struct PointLight { - float3 Pos; - float Radius; + float4 PosRadius; + float4 ColorBright; +}; - float3 Color; -} \ No newline at end of file +struct DiffSpec +{ + float3 Diffuse; + float3 Specular; +}; + +cbuffer PointLights : register(b0) +{ + PointLight pl; +} + +cbuffer LightConstants : register(b1) +{ + float4x4 InvProj; + int2 Pixels; +} + +Texture2D DiffuseGlow : register(t0); +Texture2D NormalSpec : register(t1); +Texture2D DepthTexture : register(t2); + +#endif \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightCalc.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightCalc.hlsli new file mode 100644 index 00000000..88234de0 --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightCalc.hlsli @@ -0,0 +1,23 @@ +#include "Defines.hlsli" + +DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) +{ + DiffSpec output; + float4 normalSpec = NormalSpec[texCoord]; + float3 lightVec = pl.PosRadius.xyz - pos.xyz; + float d = length(lightVec); + lightVec = lightVec/d; + + float diffFactor = max(dot(lightVec, normalSpec.xyz), 0.0f); + float3 v = reflect(-lightVec, normalSpec.xyz); + float specFactor = pow(max(dot(v,normalize(-pos)), 0.0f),normalSpec.w); + //Check att later + float att = (max(d-pl.PosRadius.w,0)/pow(pl.PosRadius.w,2)); + + //fix Ilum calcs instead of PhongBlinn + output.Diffuse = pl.ColorBright.w * att * diffFactor * pl.ColorBright.xyz; + output.Specular = pl.ColorBright.w * att * specFactor * pl.ColorBright.xyz; + if(diffFactor == 0) + output.Specular * 0; + return output; +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightPass.hlsl index 8fdac3c8..3e544f2f 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightPass.hlsl @@ -1,11 +1,16 @@ - +#include "Defines.hlsli" +#include "LightCalc.hlsli" +#include "PosManipulation.hlsli" //todo //LightCulling //Calc Diff + Spec //Calc Ambience //Write Glow + [numthreads(1, 1, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { + float3 ViewPos = ToVpos(DTid.xy); + //DiffSpec LightCalc(pl, float3 pos) } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/PosManipulation.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/PosManipulation.hlsli new file mode 100644 index 00000000..ab44bd38 --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/PosManipulation.hlsli @@ -0,0 +1,21 @@ +#include "Defines.hlsli" + +//assumes ProperfloatTexCoords +float3 ToVpos(float2 texCoord) +{ + //Get proper UV + float2 UV = float2(texCoord) / float2(Pixels); + + float4 ViewPos; + // Get the depth value for this pixel + ViewPos.z= DepthTexture[texCoord].x; + //Get X/w + ViewPos.x = UV.x * 2 - 1; + //Get Y/w + ViewPos.y = 1 - 2 * UV.y; + ViewPos.w = 1; + + //Un project + ViewPos = mul(ViewPos, InvProj); + return ViewPos.xyz / ViewPos.w; +} \ 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/OysterPhysics3D.vcxproj b/Code/OysterPhysics3D/OysterPhysics3D.vcxproj index c36fded5..f24f23e4 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.vcxproj +++ b/Code/OysterPhysics3D/OysterPhysics3D.vcxproj @@ -69,21 +69,25 @@ $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D + .lib $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) + .lib $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D + .lib $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) + .lib 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/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index cbf563c6..3d55a0a7 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -18,6 +18,7 @@ HINSTANCE g_hInst = NULL; HWND g_hWnd = NULL; Oyster::Graphics::Model::Model* m = NULL; +Oyster::Graphics::Model::Model* m2 = NULL; Oyster::Math::Float4x4 V; Oyster::Math::Float4x4 P; @@ -41,7 +42,7 @@ HRESULT InitDirect3D(); int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) { - BOOL b = SetDllDirectoryW(L"..\\..\\DLL"); + BOOL b = SetDllDirectoryW(L"..\\DLL"); typedef struct tagLOADPARMS32 { LPSTR lpEnvAddress; // address of environment strings @@ -92,6 +93,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL } Oyster::Graphics::API::DeleteModel(m); + Oyster::Graphics::API::DeleteModel(m2); Oyster::Graphics::API::Clean(); return (int) msg.wParam; } @@ -186,11 +188,15 @@ HRESULT InitDirect3D() #pragma endregion #pragma region Obj - m = Oyster::Graphics::API::CreateModel(L"orca"); + m = Oyster::Graphics::API::CreateModel(L"crate"); + m2 = Oyster::Graphics::API::CreateModel(L"crate"); + m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); #pragma endregion P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000); + Oyster::Graphics::API::SetProjection(P); + P.Invert(); V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f)); V = Oyster::Math3D::InverseOrientationMatrix(V); @@ -203,14 +209,17 @@ HRESULT Update(float deltaTime) { angle += Oyster::Math::pi/30000; m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle); + m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,0,1)*-angle,Oyster::Math::Float3(0,4,0),Oyster::Math::Float3::null); return S_OK; } HRESULT Render(float deltaTime) { - Oyster::Graphics::API::NewFrame(V,P); + Oyster::Graphics::API::SetView(V); + Oyster::Graphics::API::NewFrame(); - Oyster::Graphics::API::RenderScene(m,1); + Oyster::Graphics::API::RenderModel(*m); + Oyster::Graphics::API::RenderModel(*m2); Oyster::Graphics::API::EndFrame(); diff --git a/Code/Tester/Tester.vcxproj b/Code/Tester/Tester.vcxproj index 3f48d244..80853c72 100644 --- a/Code/Tester/Tester.vcxproj +++ b/Code/Tester/Tester.vcxproj @@ -69,7 +69,7 @@ true $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(SolutionDir)..\Bin\Executable\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(ProjectName)_$(PlatformShortName)D C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath) C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath) @@ -77,7 +77,7 @@ true $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(SolutionDir)..\Bin\Executable\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(ProjectName)_$(PlatformShortName)D C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath) C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath) @@ -85,7 +85,7 @@ false $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(SolutionDir)..\Bin\Executable\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(ProjectName)_$(PlatformShortName) C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath) C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath) @@ -93,7 +93,7 @@ false $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(SolutionDir)..\Bin\Executable\$(ProjectName)\ + $(SolutionDir)..\Bin\Executable\ $(ProjectName)_$(PlatformShortName) C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath) C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath) @@ -113,7 +113,7 @@ true OysterGraphics_$(PlatformShortName)D.lib;%(AdditionalDependencies) $(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories) - OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + OysterGraphics_x86D.dll;%(DelayLoadDLLs) @@ -136,7 +136,6 @@ OysterGraphics_$(PlatformShortName)D.lib;%(AdditionalDependencies) $(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories) true - OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -144,9 +143,9 @@ Level3 - MaxSpeed + Disabled true - true + false WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true ..\OysterGraphics;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories) @@ -159,7 +158,7 @@ OysterGraphics_$(PlatformShortName).lib;%(AdditionalDependencies) $(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories) true - OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + OysterGraphics_x86.dll; @@ -167,7 +166,7 @@ Level3 - MaxSpeed + Disabled true true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) @@ -182,7 +181,6 @@ OysterGraphics_$(PlatformShortName).lib;%(AdditionalDependencies) $(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories) true - OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) diff --git a/Code/WindowManager/Example Usage.cpp b/Code/WindowManager/Example Usage.cpp index b9f46550..5b21c953 100644 --- a/Code/WindowManager/Example Usage.cpp +++ b/Code/WindowManager/Example Usage.cpp @@ -34,8 +34,14 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 100; break; + case WM_KEYDOWN: + if(wParam == VK_ESCAPE) + PostQuitMessage(0); + break; + default: return DefWindowProc(hwnd, msg, wParam, lParam); + } return 0; } @@ -84,39 +90,18 @@ int WINAPI WinMain( HINSTANCE hInst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh { _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - - /******************************************** * Description of a window * *******************************************/ - WindowShell::INIT_DESC_WINDOW wDesc; - wDesc.hInstance = hInst; - wDesc.windowName = L"Glare"; - wDesc.windowPosition = Point2D(50); - wDesc.windowSize = Point2D(1024, 800); + WindowShell::WINDOW_INIT_DESC wDesc; + //wDesc.hInstance = hInst; + wDesc.windowPosition.x = 50; + wDesc.windowPosition.y = 50; + wDesc.windowSize.x = 1024; + wDesc.windowSize.x = 800; wDesc.windowProcCallback = WndProc; - - -/******************************************** - * Description of a child window * - *******************************************/ - WindowShell::INIT_DESC_CHILD_WINDOW cDesc; - cDesc.name = L"Child"; - cDesc.style = WS_EX_RIGHTSCROLLBAR; - cDesc.topLeftPos = Point2D(); - cDesc.windowProcCallback = ChildWndProc; - cDesc.windowSize = Point2D(80); - - - -/************************************************************ - * Initializing main window and several children * - ************************************************************/ WindowShell::self()->createWin(wDesc); - WindowShell::self()->createChildWin(cDesc); - WindowShell::self()->createChildWin(cDesc); - WindowShell::self()->createChildWin(cDesc); @@ -134,7 +119,7 @@ int WINAPI WinMain( HINSTANCE hInst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh } else { - + } } diff --git a/Code/WindowManager/WindowManager.vcxproj b/Code/WindowManager/WindowManager.vcxproj index 1a193450..0acba3ad 100644 --- a/Code/WindowManager/WindowManager.vcxproj +++ b/Code/WindowManager/WindowManager.vcxproj @@ -24,30 +24,30 @@ - Application + StaticLibrary true v110 - MultiByte + Unicode - Application + StaticLibrary true v110 - MultiByte + Unicode StaticLibrary false v110 true - MultiByte + Unicode StaticLibrary false v110 true - MultiByte + Unicode @@ -138,6 +138,10 @@ + + + + diff --git a/Code/WindowManager/WindowManager.vcxproj.filters b/Code/WindowManager/WindowManager.vcxproj.filters index d7ef6a1a..a8263606 100644 --- a/Code/WindowManager/WindowManager.vcxproj.filters +++ b/Code/WindowManager/WindowManager.vcxproj.filters @@ -14,4 +14,14 @@ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + Source Files + + + + + Header Files + + \ No newline at end of file diff --git a/Code/WindowManager/WindowShell.cpp b/Code/WindowManager/WindowShell.cpp index 836a350c..b82a58f6 100644 --- a/Code/WindowManager/WindowShell.cpp +++ b/Code/WindowManager/WindowShell.cpp @@ -1,102 +1,103 @@ #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(INIT_DESC_WINDOW &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.hInstance) - { - MessageBox(0, L"No HINSTANCE was specified!" ,L"Error", 0); - return false; - } - if(desc.windowSize < 0) - { - MessageBox(0, L"Size specified for window is invalid!" ,L"Error", 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 WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.hIconSm = NULL; - wc.style = CS_HREDRAW | CS_VREDRAW; + wc.style = desc.windowClassStyle; 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) ) { @@ -109,168 +110,131 @@ bool WindowShell::createWin(INIT_DESC_WINDOW &desc) #pragma region Create window - pData->hWnd = CreateWindow( - L"MainWindowClass" , - desc.windowName.c_str(), - WS_OVERLAPPEDWINDOW, - 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(INIT_DESC_CHILD_WINDOW &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 267417be..5adb95d4 100644 --- a/Code/WindowManager/WindowShell.h +++ b/Code/WindowManager/WindowShell.h @@ -1,112 +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 -struct Point2D -{ - int x; - int y; - Point2D() - { - x = 0; - y = 0; - } - Point2D(int _x, int _y) - { - x = _x; - y = _y; - } - Point2D(int _p) - { - x = _p; - y = _p; - } - operator POINT() const - { - return Point2D(x, y); - } - bool operator<(int i) - { - bool a = x