Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic

Conflicts:
	Bin/Content/Shaders/DebugVertex.cso
This commit is contained in:
Erik Persson 2013-12-12 09:39:27 +01:00
commit 2424b51c3e
94 changed files with 2602 additions and 570 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

233
Bin/Content/crate.obj Normal file
View File

@ -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

BIN
Bin/Content/tex_crate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -57,6 +57,7 @@ Global
{0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.ActiveCfg = Release|x64
{0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.Build.0 = Release|x64
{0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.ActiveCfg = Debug|Win32
{0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.Build.0 = Debug|Win32
{0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.ActiveCfg = Debug|x64
{0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.Build.0 = Debug|x64
{0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.ActiveCfg = Release|x64
@ -68,6 +69,7 @@ Global
{F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.ActiveCfg = Release|x64
{F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.Build.0 = Release|x64
{F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.ActiveCfg = Debug|Win32
{F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.Build.0 = Debug|Win32
{F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.ActiveCfg = Debug|x64
{F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.Build.0 = Debug|x64
{F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.ActiveCfg = Release|x64
@ -79,6 +81,7 @@ Global
{4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.ActiveCfg = Release|x64
{4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.Build.0 = Release|x64
{4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Win32.ActiveCfg = Debug|Win32
{4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Win32.Build.0 = Debug|Win32
{4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|x64.ActiveCfg = Debug|x64
{4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|x64.Build.0 = Debug|x64
{4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.ActiveCfg = Release|x64
@ -90,6 +93,7 @@ Global
{34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.ActiveCfg = Release|x64
{34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.Build.0 = Release|x64
{34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Win32.ActiveCfg = Debug|Win32
{34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Win32.Build.0 = Debug|Win32
{34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|x64.ActiveCfg = Debug|x64
{34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|x64.Build.0 = Debug|x64
{34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.ActiveCfg = Release|x64
@ -101,6 +105,7 @@ Global
{35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.ActiveCfg = Release|x64
{35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.Build.0 = Release|x64
{35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Win32.ActiveCfg = Debug|Win32
{35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Win32.Build.0 = Debug|Win32
{35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|x64.ActiveCfg = Debug|x64
{35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|x64.Build.0 = Debug|x64
{35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.ActiveCfg = Release|x64
@ -124,6 +129,7 @@ Global
{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.ActiveCfg = Release|x64
{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.Build.0 = Release|x64
{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.ActiveCfg = Debug|Win32
{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.Build.0 = Debug|Win32
{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.ActiveCfg = Debug|x64
{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.Build.0 = Debug|x64
{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.ActiveCfg = Release|x64
@ -157,6 +163,7 @@ Global
{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Release|x64
{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Release|x64
{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.ActiveCfg = Debug|Win32
{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.Build.0 = Debug|Win32
{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.ActiveCfg = Debug|x64
{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.Build.0 = Debug|x64
{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.ActiveCfg = Release|x64
@ -168,6 +175,7 @@ Global
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.ActiveCfg = Release|Win32
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.Build.0 = Release|Win32
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.ActiveCfg = Debug|Win32
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.Build.0 = Debug|Win32
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.ActiveCfg = Debug|x64
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.Build.0 = Debug|x64
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Mixed Platforms.ActiveCfg = Release|Win32
@ -185,6 +193,7 @@ Global
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Win32.ActiveCfg = Debug|Win32
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Win32.Build.0 = Debug|Win32
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|x64.ActiveCfg = Debug|x64
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|x64.Build.0 = Debug|x64
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Mixed Platforms.ActiveCfg = Release|Win32
@ -196,6 +205,7 @@ Global
{B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Win32.ActiveCfg = Debug|Win32
{B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Win32.Build.0 = Debug|Win32
{B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.ActiveCfg = Debug|x64
{B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.Build.0 = Debug|x64
{B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.ActiveCfg = Release|Win32
@ -207,6 +217,7 @@ Global
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Win32.ActiveCfg = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Win32.Build.0 = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.ActiveCfg = Debug|x64
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.Build.0 = Debug|x64
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Mixed Platforms.ActiveCfg = Release|Win32
@ -218,6 +229,7 @@ Global
{8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Win32.ActiveCfg = Debug|Win32
{8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Win32.Build.0 = Debug|Win32
{8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|x64.ActiveCfg = Debug|x64
{8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|x64.Build.0 = Debug|x64
{8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Mixed Platforms.ActiveCfg = Release|Win32
@ -229,6 +241,7 @@ Global
{460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Win32.ActiveCfg = Debug|Win32
{460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Win32.Build.0 = Debug|Win32
{460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.ActiveCfg = Debug|x64
{460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.Build.0 = Debug|x64
{460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Mixed Platforms.ActiveCfg = Release|Win32
@ -240,6 +253,7 @@ Global
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Win32.ActiveCfg = Debug|Win32
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Win32.Build.0 = Debug|Win32
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|x64.ActiveCfg = Debug|x64
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|x64.Build.0 = Debug|x64
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Mixed Platforms.ActiveCfg = Release|Win32

View File

@ -71,15 +71,15 @@
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<LibraryPath>$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)Network/NetworkAPI;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -87,7 +87,7 @@
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -95,7 +95,7 @@
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -106,7 +106,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Game/GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -123,12 +123,12 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>GameProtocols_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
@ -142,14 +142,14 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>OysterGraphics_x86.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
@ -163,14 +163,14 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>OysterGraphics_x86.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
@ -178,16 +178,41 @@
<ProjectReference Include="..\..\Input\Input.vcxproj">
<Project>{7e3990d2-3d94-465c-b58d-64a74b3ecf9b}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Misc\Misc.vcxproj">
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Network\NetworkAPI\NetworkAPI.vcxproj">
<Project>{460d625f-2ac9-4559-b809-0ba89ceaedf4}</Project>
</ProjectReference>
<ProjectReference Include="..\..\OysterGraphics\OysterGraphics.vcxproj">
<Project>{0ec83e64-230e-48ef-b08c-6ac9651b4f82}</Project>
</ProjectReference>
<ProjectReference Include="..\..\OysterMath\OysterMath.vcxproj">
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="GameClientState\Obj\C_UIobject.cpp" />
<ClCompile Include="DanBiasGame_Impl.cpp" />
<ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameClientState\Obj\C_DynamicObj.cpp" />
<ClCompile Include="GameClientState\GameClientState.cpp" />
<ClCompile Include="GameClientState\GameState.cpp" />
<ClCompile Include="GameClientState\LobbyState.cpp" />
<ClCompile Include="GameClientState\Obj\C_Player.cpp" />
<ClCompile Include="GameClientState\Obj\C_StaticObj.cpp" />
<ClCompile Include="GameClientState\C_Object.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClientState\Obj\C_UIobject.h" />
<ClInclude Include="GameClientState\Obj\C_DynamicObj.h" />
<ClInclude Include="GameClientState\GameClientState.h" />
<ClInclude Include="GameClientState\GameState.h" />
<ClInclude Include="Include\DanBiasGame.h" />
<ClInclude Include="GameClientState\LobbyState.h" />
<ClInclude Include="GameClientState\Obj\C_Player.h" />
<ClInclude Include="GameClientState\Obj\C_StaticObj.h" />
<ClInclude Include="GameClientState\C_Object.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -1,17 +1,55 @@
#define NOMINMAX
#include <Windows.h>
#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;
InputClass* DanBiasGame::inputObj = NULL;
HINSTANCE DanBiasGame::g_hInst = NULL;
HWND DanBiasGame::g_hWnd = NULL;
#pragma region Game Data
struct MyRecieverObject // :public PontusRecieverObject
{
Oyster::Network::NetworkClient nwClient;
static void ProtocolRecieved(Network::CustomNetProtocol* p)
{
int pType = ((*p)[0]).value.netInt;
switch (pType)
{
case protocol_PlayerNavigation:
break;
case protocol_PlayerPosition:
//int x = ((*p)[1]).value.netInt;
//int y = ((*p)[2]).value.netInt;
//int z = ((*p)[3]).value.netInt;
break;
case protocol_ObjectPosition:
// DanBiasGame::protocolRecived();
break;
default:
break;
}
}
};
class DanBiasGamePrivateData
{
@ -26,10 +64,23 @@ namespace DanBias
}
public:
Client::GameClientState* gameClientState;
InputClass* inputObj;
GameLogic::Protocol_PlayerMovement player_move;
//Oyster::Network::NetworkClient nwClient;
MyRecieverObject r;
// gameClient;
} data;
#pragma endregion
DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData();
void DanBiasGame::protocolRecived()
{
//m_data->gameClientState.setPos()
}
//--------------------------------------------------------------------------------------
// Interface API functions
//--------------------------------------------------------------------------------------
@ -41,7 +92,7 @@ namespace DanBias
if( FAILED( InitDirect3D() ) )
return DanBiasClientReturn_Error;
if( FAILED( InitGame() ) )
if( FAILED( InitInput() ) )
return DanBiasClientReturn_Error;
cntsPerSec = 0;
@ -51,6 +102,10 @@ namespace DanBias
prevTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
// Start in lobby state
m_data->gameClientState = new Client::LobbyState();
m_data->gameClientState->Init();
return DanBiasClientReturn_Sucess;
}
@ -72,8 +127,10 @@ namespace DanBias
float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;
//render
Update(dt);
Render(dt);
if(Update(dt) != S_OK)
return DanBiasClientReturn_Error;
if(Render(dt) != S_OK)
return DanBiasClientReturn_Error;
prevTimeStamp = currTimeStamp;
}
@ -145,48 +202,76 @@ namespace DanBias
}
//--------------------------------------------------------------------------------------
// Init the input and the game
// Init the input
//-------------------------------------------------------------------------------------
HRESULT DanBiasGame::InitGame()
HRESULT DanBiasGame::InitInput()
{
inputObj = new InputClass;
if(!inputObj->Initialize(g_hInst, g_hWnd, 1024, 768))
m_data->inputObj = new InputClass;
if(!m_data->inputObj->Initialize(g_hInst, g_hWnd, 1024, 768))
{
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
return E_FAIL;
}
return S_OK;
}
HRESULT DanBiasGame::Update(float deltaTime)
{
inputObj->Update();
m_data->inputObj->Update();
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
state = m_data->gameClientState->Update(deltaTime, 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(); // send game client
}
return S_OK;
}
HRESULT DanBiasGame::Render(float deltaTime)
{
int isPressed = 0;
if(inputObj->IsKeyPressed(DIK_A))
if(m_data->inputObj->IsKeyPressed(DIK_A))
{
isPressed = 1;
}
Oyster::Graphics::API::NewFrame(Oyster::Math3D::Float4x4::null, Oyster::Math3D::Float4x4::null);
wchar_t title[255];
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
SetWindowText(g_hWnd, title);
Oyster::Graphics::API::EndFrame();
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;
}

View File

@ -0,0 +1,4 @@
#include "C_Object.h"
using namespace DanBias::Client;

View File

@ -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

View File

@ -0,0 +1,12 @@
#include "GameClientState.h"
using namespace DanBias::Client;
GameClientState::GameClientState(void)
{
}
GameClientState::~GameClientState(void)
{
}

View File

@ -0,0 +1,32 @@
#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H
#define DANBIAS_CLIENT_GAMECLIENTSTATE_H
#define NOMINMAX
#include "L_inputClass.h"
namespace DanBias
{
namespace Client
{
class GameClientState
{
public:
enum ClientState
{
ClientState_Lobby,
ClientState_Game,
ClientState_Same,
};
public:
GameClientState(void);
virtual ~GameClientState(void);
virtual bool Init() = 0;
virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0;
virtual bool Render() = 0;
virtual bool Release() = 0;
};
};
};
#endif

View File

@ -0,0 +1,129 @@
#include "GameState.h"
#include "DllInterfaces/GFXAPI.h"
#include "Obj/C_Player.h"
#include "Obj/C_DynamicObj.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()
{
// load models
privData = new myData();
privData->state = gameStateState_loading;
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);
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;
}

View File

@ -0,0 +1,36 @@
#ifndef DANBIAS_CLIENT_GAMESTATE_H
#define DANBIAS_CLIENT_GAMESTATE_H
#include "GameClientState.h"
#include "OysterMath.h"
#include <string>
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();
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput);
bool LoadModels(std::wstring mapFile);
bool InitCamera(Oyster::Math::Float3 startPos);
gameStateState LoadGame();
bool Render();
bool Release();
};
};
};
#endif

View File

@ -0,0 +1,121 @@
#include "LobbyState.h"
#include "DllInterfaces/GFXAPI.h"
#include "OysterMath.h"
#include "Obj/C_Player.h"
#include "Obj/C_StaticObj.h"
#include "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()
{
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;
}

View File

@ -0,0 +1,36 @@
#ifndef DANBIAS_CLIENT_LOBBYSTATE_H
#define DANBIAS_CLIENT_LOBBYSTATE_H
#include "GameClientState.h"
#include "OysterMath.h"
#include <string>
namespace DanBias
{
namespace Client
{
class LobbyState : public GameClientState
{
private:
struct myData;
myData* privData;
public:
LobbyState(void);
~LobbyState(void);
bool Init();
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();
};};};
#endif // ! DANBIAS_CLIENT_GAMECLIENTSTATE_H

View File

@ -10,8 +10,7 @@
#define NOMINMAX
#include <Windows.h>
#include "DllInterfaces/GFXAPI.h"
#include "L_inputClass.h"
namespace DanBias
{
@ -24,6 +23,8 @@ namespace DanBias
DanBiasClientReturn_Sucess,
};
struct DanBiasGameDesc
{
//Stuff goes here...
@ -33,7 +34,7 @@ namespace DanBias
};
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
class DanBiasGamePrivateData;
class DANBIAS_GAME_DLL DanBiasGame
{
public:
@ -48,18 +49,21 @@ namespace DanBias
static HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow);
static HRESULT InitDirect3D();
static HRESULT InitGame();
static HRESULT InitInput();
static HRESULT Update(float deltaTime);
static HRESULT Render(float deltaTime);
static HRESULT CleanUp();
static void protocolRecived();
private:
static __int64 cntsPerSec;
static __int64 prevTimeStamp;
static float secsPerCnt;
static InputClass* inputObj;
static HINSTANCE g_hInst;
static HWND g_hWnd;
static DanBiasGamePrivateData* m_data;
};

View File

@ -71,32 +71,32 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\Bin\DLL;</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\Bin\DLL;</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\Bin\DLL;</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath);$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;$(LibraryPath);$(SolutionDir)..\Bin\DLL;</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -105,13 +105,13 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>DanBiasServer_$(PlatformShortName)D.dll;DanBiasGame_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>Input_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>DanBiasServer_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -121,13 +121,13 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>GameLogic_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;DanBiasGame_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>Input_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>DanBiasServer_$(PlatformShortName)D.dll;DanBiasGame_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasServer_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -139,15 +139,15 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>GameLogic_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -159,36 +159,21 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)Include;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterGraphics\;$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>GameLogic_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Launcher.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GamePhysics\GamePhysics.vcxproj">
<Project>{104fa3e9-94d9-4e1d-a941-28a03bc8a095}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Input\Input.vcxproj">
<Project>{7e3990d2-3d94-465c-b58d-64a74b3ecf9b}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Misc\Misc.vcxproj">
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
</ProjectReference>
<ProjectReference Include="..\..\OysterGraphics\OysterGraphics.vcxproj">
<Project>{0ec83e64-230e-48ef-b08c-6ac9651b4f82}</Project>
</ProjectReference>
<ProjectReference Include="..\..\OysterMath\OysterMath.vcxproj">
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
</ProjectReference>
<ProjectReference Include="..\DanBiasGame\DanBiasGame.vcxproj">
<Project>{2a1bc987-af42-4500-802d-89cd32fc1309}</Project>
</ProjectReference>

View File

@ -71,7 +71,9 @@ void Game::Update(keyInput keyPressed, float pitch, float yaw)
}
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();
}

View File

@ -5,6 +5,7 @@
#include "Player.h"
#include "IGame.h"
#include "Camera.h"
#include "DynamicObject.h"
namespace GameLogic
{

View File

@ -172,7 +172,6 @@
<ClInclude Include="CollisionManager.h" />
<ClInclude Include="DynamicObject.h" />
<ClInclude Include="GameMode.h" />
<ClInclude Include="GameLogicStates.h" />
<ClInclude Include="IAttatchment.h" />
<ClInclude Include="Level.h" />
<ClInclude Include="Object.h" />

View File

@ -154,6 +154,7 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ObjectProtocols.h" />
<ClInclude Include="PlayerProtocols.h" />
<ClInclude Include="ProtocolIdentificationID.h" />
</ItemGroup>

View File

@ -0,0 +1,67 @@
#ifndef GAMELOGIC_PLAYER_PROTOCOLS_H
#define GAMELOGIC_PLAYER_PROTOCOLS_H
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
namespace GameLogic
{
struct Protocol_ObjectPosition :public Network::CustomProtocolObject
{
float worldMatrix[16];
// look at dir
Protocol_ObjectPosition()
{
this->protocol[0].value = protocol_PlayerPosition;
this->protocol[0].type = Network::NetAttributeType_Int;
this->protocol[1].type = Network::NetAttributeType_Float;
this->protocol[2].type = Network::NetAttributeType_Float;
this->protocol[3].type = Network::NetAttributeType_Float;
this->protocol[4].type = Network::NetAttributeType_Float;
this->protocol[5].type = Network::NetAttributeType_Float;
this->protocol[6].type = Network::NetAttributeType_Float;
this->protocol[7].type = Network::NetAttributeType_Float;
this->protocol[8].type = Network::NetAttributeType_Float;
this->protocol[9].type = Network::NetAttributeType_Float;
this->protocol[10].type = Network::NetAttributeType_Float;
this->protocol[11].type = Network::NetAttributeType_Float;
this->protocol[12].type = Network::NetAttributeType_Float;
this->protocol[13].type = Network::NetAttributeType_Float;
this->protocol[14].type = Network::NetAttributeType_Float;
this->protocol[15].type = Network::NetAttributeType_Float;
this->protocol[16].type = Network::NetAttributeType_Float;
}
Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = worldMatrix[0];
this->protocol[2].value = worldMatrix[1];
this->protocol[3].value = worldMatrix[2];
this->protocol[4].value = worldMatrix[4];
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:
Network::CustomNetProtocol protocol;
};
}
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -1,7 +1,7 @@
#ifndef GAMELOGIC_PLAYER_PROTOCOLS_H
#define GAMELOGIC_PLAYER_PROTOCOLS_H
#include "CustomNetProtocol.h"
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
@ -20,24 +20,24 @@ namespace GameLogic
Protocol_PlayerMovement()
{
protocol[0]->value = ProtocolID = protocol_PlayerNavigation;
this->protocol[0].value = ProtocolID = protocol_PlayerNavigation;
protocol[0]->type = Network::NetAttributeType_Int;
protocol[1]->type = Network::NetAttributeType_Bool;
protocol[2]->type = Network::NetAttributeType_Bool;
protocol[3]->type = Network::NetAttributeType_Bool;
protocol[4]->type = Network::NetAttributeType_Bool;
protocol[5]->type = Network::NetAttributeType_Bool;
protocol[6]->type = Network::NetAttributeType_Bool;
this->protocol[0].type = Network::NetAttributeType_Int;
this->protocol[1].type = Network::NetAttributeType_Bool;
this->protocol[2].type = Network::NetAttributeType_Bool;
this->protocol[3].type = Network::NetAttributeType_Bool;
this->protocol[4].type = Network::NetAttributeType_Bool;
this->protocol[5].type = Network::NetAttributeType_Bool;
this->protocol[6].type = Network::NetAttributeType_Bool;
}
Network::CustomNetProtocol* GetProtocol() override
{
protocol[1]->value = bForward;
protocol[2]->value = bBackward;
protocol[3]->value = bTurnLeft;
protocol[4]->value = bTurnRight;
protocol[5]->value = bStrafeRight;
protocol[6]->value = bStrafeRight;
this->protocol[1].value = bForward;
this->protocol[2].value = bBackward;
this->protocol[3].value = bTurnLeft;
this->protocol[4].value = bTurnRight;
this->protocol[5].value = bStrafeRight;
this->protocol[6].value = bStrafeRight;
return &protocol;
}
@ -45,6 +45,35 @@ namespace GameLogic
private:
Network::CustomNetProtocol protocol;
};
struct Protocol_PlayerPosition :public Network::CustomProtocolObject
{
float position[3];
// look at dir
Protocol_PlayerPosition()
{
this->protocol[0].value = protocol_PlayerPosition;
this->protocol[0].type = Network::NetAttributeType_Int;
this->protocol[1].type = Network::NetAttributeType_Float;
this->protocol[2].type = Network::NetAttributeType_Float;
this->protocol[3].type = Network::NetAttributeType_Float;
}
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:
Network::CustomNetProtocol protocol;
};
}
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -3,6 +3,8 @@
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */
#define protocol_PlayerNavigation 0;
#define protocol_PlayerNavigation 0
#define protocol_PlayerPosition 1
#define protocol_ObjectPosition 2
#endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H

View File

@ -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);
}

View File

@ -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<Type>::~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<Type>::Push(Type item)
{
stdMutex.lock();
Node *e = new Node(item);
mutex.LockMutex();
if(this->front != NULL)
{
this->back->next = e;
@ -111,15 +111,14 @@ namespace Oyster
this->nrOfNodes++;
mutex.UnlockMutex();
stdMutex.unlock();
}
template < typename Type >
Type ThreadSafeQueue<Type>::Pop()
{
mutex.LockMutex();
if(this->front != NULL)
{
stdMutex.lock();
Type item = this->front->item;
Node *destroyer = this->front;
this->front = front->next;
@ -132,70 +131,66 @@ namespace Oyster
this->front = NULL;
this->back = NULL;
}
stdMutex.unlock();
return item;
}
mutex.UnlockMutex();
return NULL;
}
template < typename Type >
Type ThreadSafeQueue<Type>::Front()
{
mutex.LockMutex();
if(front != NULL)
{
return this->front->item;
}
mutex.UnlockMutex();
stdMutex.lock();
Type temp = this->front->item;
stdMutex.unlock();
return temp;
return NULL;
}
template < typename Type >
Type ThreadSafeQueue<Type>::Back()
{
mutex.LockMutex();
if(back != NULL)
{
return this->back->item;
}
mutex.UnlockMutex();
stdMutex.lock();
Type temp = this->back->item;
stdMutex.unlock();
return temp;
return NULL;
}
template < typename Type >
int ThreadSafeQueue<Type>::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<Type>::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<Type>::Swap(IQueue<Type> &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();
}

View File

@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "CustomNetProtocol.h"
#include <map>
using namespace Network;
struct CustomNetProtocol::PrivateData
{
std::map<int, NetAttributeContainer> attributes;
PrivateData()
{ }
~PrivateData()
{
for (auto i = attributes.begin(); i != attributes.end(); i++)
{
RemoveAttribute(i->first);
}
}
void RemoveAttribute(int ID)
{
auto i = attributes.find(ID);
if(i == attributes.end()) return;
switch (i->second.type)
{
case NetAttributeType_CharArray:
delete [] i->second.value.netCharPtr;
break;
}
}
//Do network stuff
};
CustomNetProtocol::CustomNetProtocol()
{
this->privateData = new PrivateData();
}
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];
}

View File

@ -0,0 +1,103 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef NETWORK_CUSTOM_NETWORK_PROTOCOL_H
#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H
#include <string>
#ifdef CUSTOM_NET_PROTOCOL_EXPORT
#define NET_PROTOCOL_EXPORT __declspec(dllexport)
#else
#define NET_PROTOCOL_EXPORT __declspec(dllimport)
#endif
namespace Network
{
extern "C"
{
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();
NetAttributeContainer& operator[](int ID);
private:
struct PrivateData;
PrivateData* privateData;
};
}//End extern "C"
} //End namespace Network
#endif // !NETWORK_CUSTOM_NETWORK_PROTOCOL_H

View File

@ -0,0 +1,180 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{460D625F-2AC9-4559-B809-0BA89CEAEDF4}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>NetworkAPI</RootNamespace>
<ProjectName>NetworkAPI</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>CUSTOM_NET_PROTOCOL_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>CUSTOM_NET_PROTOCOL_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>CUSTOM_NET_PROTOCOL_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>CUSTOM_NET_PROTOCOL_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="CustomNetProtocol.cpp" />
<ClCompile Include="NetworkServer.cpp" />
<ClCompile Include="NetworkClient.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="CustomNetProtocol.h" />
<ClInclude Include="NetworkServer.h" />
<ClInclude Include="NetworkClient.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetworkDependencies\NetworkDependencies.vcxproj">
<Project>{c5aa09d0-6594-4cd3-bd92-1d380c7b3b50}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,41 @@
#include "NetworkClient.h"
using namespace Oyster::Network;
/*************************************
PrivateData
*************************************/
struct PrivateData
{
};
/*************************************
NetworkClient
*************************************/
NetworkClient::NetworkClient()
{
}
NetworkClient::~NetworkClient()
{
}
void NetworkClient::Disconnect()
{
}
bool NetworkClient::IsConnected()
{
return false;
}
void NetworkClient::Send()
{
}

View File

@ -0,0 +1,42 @@
#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
class RecieverObject;
namespace Oyster
{
namespace Network
{
extern "C"
{
class NET_PROTOCOL_EXPORT NetworkClient
{
public:
NetworkClient();
virtual ~NetworkClient();
virtual void Disconnect();
virtual bool IsConnected();
virtual void Send();
private:
struct PrivateData;
PrivateData* privateData;
};
}
}
}
#endif

View File

@ -0,0 +1,202 @@
#include "NetworkServer.h"
#include "NetworkClient.h"
#include "../NetworkDependencies/Listener.h"
#include "../NetworkDependencies/PostBox.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();
bool Stop();
bool Shutdown();
void CheckForNewClient();
virtual bool DoWork();
//
IListener* listener;
INIT_DESC initDesc;
bool started;
//Postbox for new clients
IPostBox<int> *postBox;
//Server thread
OysterThread thread;
};
NetworkServer::PrivateData::PrivateData()
{
listener = 0;
started = false;
postBox = new PostBox<int>;
}
NetworkServer::PrivateData::~PrivateData()
{
Shutdown();
}
bool NetworkServer::PrivateData::Init(INIT_DESC& initDesc)
{
//Check if it's a valid port
if(initDesc.port == 0)
{
return false;
}
this->initDesc = initDesc;
//Initiate listener
listener = new Listener(postBox);
((Listener*)listener)->Init(this->initDesc.port, false);
thread.Create(this, false);
return true;
}
bool NetworkServer::PrivateData::Start()
{
//Start listener
((Listener*)listener)->Start();
started = true;
thread.Start();
return true;
}
bool NetworkServer::PrivateData::Stop()
{
if(listener)
{
((Listener*)listener)->Stop();
}
started = false;
thread.Stop();
return true;
}
bool NetworkServer::PrivateData::Shutdown()
{
//Stop server main thread
thread.Stop();
if(listener)
{
delete listener;
listener = NULL;
}
if(postBox)
{
delete postBox;
postBox = NULL;
}
started = false;
return true;
}
//Checks for new clients and sends them to the proc function.
void NetworkServer::PrivateData::CheckForNewClient()
{
if(postBox->IsFull())
{
int clientSocketNum;
postBox->FetchMessage(clientSocketNum);
//Safety check that is probably not needed.
if(clientSocketNum == -1)
{
return;
}
//Create client and Proc function if the pointer is not NULL
if(initDesc.proc)
{
Oyster::Network::NetworkClient* client = new Oyster::Network::NetworkClient();
initDesc.proc((NetworkClient*)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)
{
privateData->Init(initDesc);
return true;
}
bool NetworkServer::Start()
{
privateData->Start();
return true;
}
bool NetworkServer::Stop()
{
privateData->Stop();
return true;
}
bool NetworkServer::Shutdown()
{
privateData->Shutdown();
return true;
}
bool NetworkServer::IsStarted() const
{
return privateData->started;
}

View File

@ -0,0 +1,56 @@
#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
#pragma comment(lib, "ws2_32.lib")
//#include "NetworkClient.h"
namespace Oyster
{
namespace Network
{
namespace Server
{
extern "C"
{
class NET_PROTOCOL_EXPORT NetworkServer
{
public:
class NetworkClient;
struct INIT_DESC
{
unsigned short port; //Port the server should be accepting clients on.
void (*proc)(NetworkClient*);
};
NetworkServer();
virtual ~NetworkServer();
virtual bool Init(INIT_DESC& initDesc);
virtual bool Start();
virtual bool Stop();
virtual bool Shutdown();
virtual bool IsStarted() const;
private:
struct PrivateData;
PrivateData* privateData;
};
}
}
}
}
#endif

View File

@ -7,6 +7,20 @@
using namespace Oyster::Network;
Connection::Connection()
{
this->socket = 0;
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;
}
@ -79,11 +99,11 @@ int Connection::Disconnect()
return WSAGetLastError();
}
int Connection::Send(OysterByte& bytes)
int Connection::Send(Utility::DynamicMemory::SmartPointer<OysterByte> &bytes)
{
int nBytes;
nBytes = send(this->socket, bytes, bytes.GetSize(), 0);
nBytes = send(this->socket, *bytes, bytes->GetSize(), 0);
if(nBytes == SOCKET_ERROR)
{
return WSAGetLastError();
@ -92,34 +112,32 @@ int Connection::Send(OysterByte& bytes)
return 0;
}
int Connection::Recieve(OysterByte& bytes)
int Connection::Recieve(Utility::DynamicMemory::SmartPointer<OysterByte> &bytes)
{
int nBytes;
bytes.Clear(1000);
nBytes = recv(this->socket, bytes, 500, 0);
bytes->Resize(1000);
nBytes = recv(this->socket, *bytes , 500, 0);
if(nBytes == SOCKET_ERROR)
{
return WSAGetLastError();
}
else
{
bytes.SetSize(nBytes);
bytes->SetSize(nBytes);
}
std::cout << "Size of the recieved data: " << nBytes << " bytes" << std::endl;
//bytes.byteArray[nBytes] = '\0';
return 0;
}
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 WSAGetLastError();
return (int)INVALID_SOCKET;//WSAGetLastError();
}
return clientSocket;
@ -130,7 +148,7 @@ 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();
@ -139,15 +157,24 @@ int Connection::InitiateSocket()
return 0;
}
void Connection::SetBlockingMode(bool blocking)
int Connection::SetBlockingMode(bool blocking)
{
//TODO: Implement this function. Setting the socket to blocking or non-blocking.
DWORD nonBlocking;
if(blocking)
{
//fcntl(this->socket, F_SETFL, O_NONBLOCK);
nonBlocking = 0;
}
else
{
nonBlocking = 1;
}
int result = ioctlsocket(this->socket, FIONBIO, &nonBlocking);
if(result != 0)
{
return WSAGetLastError();
}
return 0;
}

View File

@ -16,28 +16,32 @@ 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( Utility::DynamicMemory::SmartPointer<OysterByte> &bytes );
virtual int Recieve( Utility::DynamicMemory::SmartPointer<OysterByte> &bytes );
virtual int Disconnect();
virtual int Connect( unsigned short port , const char serverName[] );
virtual int Listen();
//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;
};
}
}

View File

@ -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( Utility::DynamicMemory::SmartPointer<OysterByte> &bytes ) = 0;
virtual int Recieve( Utility::DynamicMemory::SmartPointer<OysterByte> &bytes) = 0;
//initiates sockets and address for server and client
virtual int InitiateServer( unsigned short port ) { return false; };

View File

@ -14,6 +14,7 @@ namespace Oyster
class IListener
{
public:
virtual ~IListener() {}
virtual bool Init(unsigned int port) = 0;
virtual int Accept() = 0;

View File

@ -15,7 +15,7 @@ namespace Oyster
public:
virtual ~IPostBox() {}
virtual void PostMessage(T& message) = 0;
virtual void FetchMessage(T& message) = 0;
virtual bool FetchMessage(T& message) = 0;
virtual bool IsFull() = 0;
};

View File

@ -5,6 +5,8 @@
// Created by Sam Svensson 2013 //
//////////////////////////////////
#include "../../Misc/Utilities.h"
namespace Oyster
{
namespace Network
@ -15,8 +17,8 @@ namespace Oyster
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 (Protocols::ProtocolHeader &header, Utility::DynamicMemory::SmartPointer<OysterByte> &bytes) = 0;
virtual void Unpack (Protocols::ProtocolSet* set, Utility::DynamicMemory::SmartPointer<OysterByte> &bytes ) = 0;
};
}

View File

@ -1,12 +1,19 @@
#include "Listener.h"
using namespace Oyster::Network::Server;
using namespace Utility::DynamicMemory;
Listener::Listener()
{
connection = NULL;
}
Listener::Listener(Oyster::Network::IPostBox<int>* postBox)
{
connection = NULL;
this->postBox = postBox;
}
Listener::~Listener()
{
if(connection)
@ -15,10 +22,10 @@ Listener::~Listener()
}
}
//Starts the thread immediate
bool Listener::Init(unsigned int port)
{
connection = new Connection();
connection->InitiateServer(port);
thread.Create(this, true);
@ -26,26 +33,53 @@ bool Listener::Init(unsigned int port)
return true;
}
bool Listener::Init(unsigned int port, bool start)
{
connection = new Connection();
connection->InitiateServer(port);
thread.Create(this, start);
return true;
}
void Listener::Start()
{
thread.Start();
}
void Listener::Stop()
{
thread.Stop();
}
void Listener::Shutdown()
{
thread.Terminate();
thread.Stop();
}
void Listener::SetPostBox(Oyster::Network::IPostBox<int>* postBox)
{
mutex.LockMutex();
stdMutex.lock();
//mutex.LockMutex();
this->postBox = postBox;
mutex.UnlockMutex();
//mutex.UnlockMutex();
stdMutex.unlock();
}
int Listener::Accept()
{
int clientSocket = 0;
int clientSocket = -1;
clientSocket = connection->Listen();
mutex.LockMutex();
if(clientSocket != -1)
{
stdMutex.lock();
//mutex.LockMutex();
postBox->PostMessage(clientSocket);
mutex.UnlockMutex();
//mutex.UnlockMutex();
stdMutex.unlock();
}
return clientSocket;
}
@ -57,13 +91,10 @@ bool Listener::DoWork()
return true;
}
#include <iostream>
void Listener::ThreadEntry()
{
std::cout << "Thread started" << std::endl;
}
void Listener::ThreadExit()
{
std::cout << "Thread stopped" << std::endl;
}

View File

@ -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<int>* postBox);
~Listener();
bool Init(unsigned int port);
bool Init(unsigned int port, bool start);
void Start();
void Stop();
void Shutdown();
void SetPostBox(IPostBox<int>* 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<int>* postBox;

View File

@ -111,7 +111,6 @@ void MessageHeader::PackFloat(float i, OysterByte& bytes)
void MessageHeader::PackFloat(float i[], unsigned int elementCount, OysterByte& bytes)
{
bytes.AddSize(4);
//Pack number of elements
PackUnsignedInt(elementCount, bytes);
@ -131,7 +130,7 @@ void MessageHeader::PackDouble(double i, OysterByte& bytes)
void MessageHeader::PackStr(char str[], OysterByte& bytes)
{
int totalSize = 2 + strlen(str);
int totalSize = 2 + (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 = 2 + (int)str.length();
bytes.AddSize(totalSize);
Packing::Pack(&bytes.GetByteArray()[size], str);
size += totalSize;
@ -244,7 +243,7 @@ double MessageHeader::UnpackDouble(OysterByte& bytes)
std::string MessageHeader::UnpackStr(OysterByte& bytes)
{
std::string str = Packing::UnpackStr(&bytes.GetByteArray()[size]);
size += 2 + str.length();
size += 2 + (int)str.length();
return str;
}

View File

@ -47,6 +47,7 @@ namespace Oyster
void PackStr(char str[], OysterByte& bytes);
void PackStr(std::string str, OysterByte& bytes);
//Maybe
//TODO: Add Pack functions for Vec2, 3, 4 and maybe Matrix. Etc.
@ -71,6 +72,7 @@ namespace Oyster
std::string UnpackStr(OysterByte& bytes);
//Maybe
//TODO: Add Unpack functions for Vec2, 3, 4 and maybe Matrix. Etc.

View File

@ -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<ProtocolPlayerPos*>(&header)->ID, bytes);
PackFloat(static_cast<ProtocolPlayerPos*>(&header)->matrix, static_cast<ProtocolPlayerPos*>(&header)->nrOfFloats, bytes);
SetSize(bytes);
}
void MessagePlayerPos::Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header)
{
MessageHeader::Unpack(bytes, header);
static_cast<ProtocolPlayerPos*>(&header)->ID = UnpackInt(bytes);
static_cast<ProtocolPlayerPos*>(&header)->matrix = UnpackFloat(static_cast<ProtocolPlayerPos*>(&header)->nrOfFloats, bytes);
}

View File

@ -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

View File

@ -7,5 +7,6 @@
#include "MessageHeader.h"
#include "MessageTest.h"
#include "MessagePlayerPos.h"
#endif

View File

@ -153,11 +153,12 @@
<ItemGroup>
<ClCompile Include="Connection.cpp" />
<ClCompile Include="Listener.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Messages\MessageHeader.cpp" />
<ClCompile Include="Messages\MessagePlayerPos.cpp" />
<ClCompile Include="Messages\MessageTest.cpp" />
<ClCompile Include="OysterByte.cpp" />
<ClCompile Include="Packing.cpp" />
<ClCompile Include="ThreadedClient.cpp" />
<ClCompile Include="Translator.cpp" />
<ClCompile Include="WinsockFunctions.cpp" />
</ItemGroup>
@ -168,6 +169,7 @@
<ClInclude Include="IPostBox.h" />
<ClInclude Include="Listener.h" />
<ClInclude Include="Messages\MessageHeader.h" />
<ClInclude Include="Messages\MessagePlayerPos.h" />
<ClInclude Include="Messages\MessagesInclude.h" />
<ClInclude Include="Messages\MessageTest.h" />
<ClInclude Include="OysterByte.h" />
@ -175,6 +177,7 @@
<ClInclude Include="ITranslate.h" />
<ClInclude Include="PostBox.h" />
<ClInclude Include="Protocols.h" />
<ClInclude Include="ThreadedClient.h" />
<ClInclude Include="Translator.h" />
<ClInclude Include="WinsockFunctions.h" />
</ItemGroup>

View File

@ -2,30 +2,33 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="Connection.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Messages\MessageHeader.cpp" />
<ClCompile Include="Messages\MessageTest.cpp" />
<ClCompile Include="Packing.cpp" />
<ClCompile Include="Translator.cpp" />
<ClCompile Include="Listener.cpp" />
<ClCompile Include="WinsockFunctions.cpp" />
<ClCompile Include="Messages\MessageHeader.cpp" />
<ClCompile Include="Messages\MessagePlayerPos.cpp" />
<ClCompile Include="Messages\MessageTest.cpp" />
<ClCompile Include="OysterByte.cpp" />
<ClCompile Include="Packing.cpp" />
<ClCompile Include="ThreadedClient.cpp" />
<ClCompile Include="Translator.cpp" />
<ClCompile Include="WinsockFunctions.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Connection.h" />
<ClInclude Include="IConnection.h" />
<ClInclude Include="IListener.h" />
<ClInclude Include="IPostBox.h" />
<ClInclude Include="Listener.h" />
<ClInclude Include="Messages\MessageHeader.h" />
<ClInclude Include="Messages\MessagePlayerPos.h" />
<ClInclude Include="Messages\MessagesInclude.h" />
<ClInclude Include="Messages\MessageTest.h" />
<ClInclude Include="OysterByte.h" />
<ClInclude Include="Packing.h" />
<ClInclude Include="ITranslate.h" />
<ClInclude Include="Protocols.h" />
<ClInclude Include="Translator.h" />
<ClInclude Include="Messages\MessagesInclude.h" />
<ClInclude Include="Listener.h" />
<ClInclude Include="IListener.h" />
<ClInclude Include="WinsockFunctions.h" />
<ClInclude Include="OysterByte.h" />
<ClInclude Include="IPostBox.h" />
<ClInclude Include="PostBox.h" />
<ClInclude Include="Protocols.h" />
<ClInclude Include="ThreadedClient.h" />
<ClInclude Include="Translator.h" />
<ClInclude Include="WinsockFunctions.h" />
</ItemGroup>
</Project>

View File

@ -16,16 +16,36 @@ OysterByte::OysterByte(int cap)
byteArray = new unsigned char[capacity];
}
OysterByte::OysterByte(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;
}
OysterByte::~OysterByte()
{
delete[] byteArray;
}
void OysterByte::Clear(unsigned int cap)
void OysterByte::Clear()
{
size = 0;
}
void OysterByte::Resize(unsigned int cap)
{
if(capacity < cap)
{
delete[] byteArray;
byteArray = new unsigned char[cap];
size = 0;
}
}
int OysterByte::GetSize()
@ -60,6 +80,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;

View File

@ -16,9 +16,11 @@ namespace Oyster
public:
OysterByte();
OysterByte(int cap);
OysterByte(const OysterByte& obj);
virtual ~OysterByte();
void Clear(unsigned int cap);
void Clear(); //Resets size to 0
void Resize(unsigned int cap); //Resizes the array with, it does not keep anything in it.
int GetSize();
unsigned char* GetByteArray();
@ -27,6 +29,8 @@ namespace Oyster
void SetBytes(unsigned char* bytes);
void SetSize(unsigned int size); //Only sets the private variable 'size'
OysterByte& operator =(const OysterByte& obj);
operator char*();
operator const char*();
operator unsigned char*();

View File

@ -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)
@ -305,7 +305,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

View File

@ -23,7 +23,7 @@ namespace Oyster
virtual ~PostBox();
virtual void PostMessage(T& message);
virtual void FetchMessage(T& message);
virtual bool FetchMessage(T& message);
virtual bool IsFull();
private:
@ -49,13 +49,14 @@ namespace Oyster
}
template <class T>
void PostBox<T>::FetchMessage(T& message)
bool PostBox<T>::FetchMessage(T& message)
{
if(IsFull())
{
message = messages.Front();
messages.Pop();
message = messages.Pop();
return true;
}
return false;
}
template <class T>

View File

@ -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;
}
}
};

View File

@ -0,0 +1,143 @@
#include "ThreadedClient.h"
#include "OysterByte.h"
#include <iostream>
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace Utility::DynamicMemory;
ThreadedClient::ThreadedClient()
{
this->connection = new Connection();
this->sendPostBox = new PostBox<SmartPointer<OysterByte>>();
this->recvPostBox = NULL;
connection->SetBlockingMode(false);
}
ThreadedClient::ThreadedClient(unsigned int socket)
{
this->connection = new Connection(socket);
this->sendPostBox = new PostBox<SmartPointer<OysterByte>>();
this->recvPostBox = NULL;
connection->SetBlockingMode(false);
thread.Create(this, true);
}
ThreadedClient::ThreadedClient(IPostBox<Utility::DynamicMemory::SmartPointer<OysterByte>>* postBox, unsigned int socket)
{
this->connection = new Connection(socket);
this->sendPostBox = new PostBox<SmartPointer<OysterByte>>;
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(SmartPointer<OysterByte>& byte)
{
this->sendPostBox->PostMessage(byte);
}
int ThreadedClient::Send()
{
int errorCode = 0;
if(sendPostBox->IsFull())
{
SmartPointer<OysterByte> temp = new OysterByte;
sendPostBox->FetchMessage(temp);
errorCode = this->connection->Send(temp);
}
return errorCode;
}
int ThreadedClient::Recv()
{
int errorCode = -1;
SmartPointer<OysterByte> temp = new OysterByte;
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 <Windows.h>
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<SmartPointer<OysterByte>> *postBox)
{
stdMutex.lock();
this->recvPostBox = postBox;
stdMutex.unlock();
}

View File

@ -0,0 +1,55 @@
#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/Thread/OysterMutex.h"
#include "../../Misc/Utilities.h"
#include <mutex>
namespace Oyster
{
namespace Network
{
class OysterByte;
class ThreadedClient : public Thread::IThreadObject
{
public:
ThreadedClient();
ThreadedClient(unsigned int socket);
ThreadedClient(IPostBox<Utility::DynamicMemory::SmartPointer<OysterByte>> *postBox, unsigned int socket);
virtual ~ThreadedClient();
void Send(Utility::DynamicMemory::SmartPointer<OysterByte>& byte);
int Connect(unsigned short port, const char serverName[]);
void setRecvPostBox(IPostBox<Utility::DynamicMemory::SmartPointer<OysterByte>> *postBox);
private:
virtual int Send();
virtual int Recv();
virtual void ThreadEntry();
virtual void ThreadExit();
virtual bool DoWork();
private:
Connection* connection;
IPostBox<Utility::DynamicMemory::SmartPointer<OysterByte>> *sendPostBox;
IPostBox<Utility::DynamicMemory::SmartPointer<OysterByte>> *recvPostBox;
Oyster::Thread::OysterThread thread;
std::mutex stdMutex;
};
}
}
#endif

View File

@ -4,7 +4,7 @@ using namespace Oyster::Network;
using namespace ::Protocols;
using namespace ::Messages;
void Translator::Pack( ProtocolHeader &header, OysterByte& bytes )
void Translator::Pack( ProtocolHeader &header, Utility::DynamicMemory::SmartPointer<OysterByte> &bytes )
{
MessageHeader *message = NULL;
@ -17,23 +17,27 @@ void Translator::Pack( ProtocolHeader &header, OysterByte& bytes )
case PackageType_test:
message = new MessageTest();
break;
case PackageType_player_pos:
message = new MessagePlayerPos();
break;
}
if(message != NULL)
{
message->Pack(header, bytes);
message->Pack(header, *bytes);
delete message;
message = NULL;
}
}
void Translator::Unpack(ProtocolSet* set, OysterByte& bytes )
void Translator::Unpack(ProtocolSet* set, Utility::DynamicMemory::SmartPointer<OysterByte> &bytes)
{
ProtocolHeader *header = new ProtocolHeader();
MessageHeader *message = new MessageHeader();
message->Unpack(bytes, *header);
message->Unpack(*bytes, *header);
delete message;
message = NULL;
@ -44,13 +48,19 @@ void Translator::Unpack(ProtocolSet* set, OysterByte& bytes )
case PackageType_header:
message = new MessageHeader();
set->Protocol.pHeader = new ProtocolHeader;
message->Unpack(bytes, *set->Protocol.pHeader);
message->Unpack(*bytes, *set->Protocol.pHeader);
break;
case PackageType_test:
message = new MessageTest();
set->Protocol.pTest = new ProtocolTest;
message->Unpack(bytes, *set->Protocol.pTest);
message->Unpack(*bytes, *set->Protocol.pTest);
break;
case PackageType_player_pos:
message = new MessagePlayerPos();
set->Protocol.pPlayerPos = new ProtocolPlayerPos;
message->Unpack(*bytes, *set->Protocol.pPlayerPos);
break;
}

View File

@ -20,8 +20,8 @@ namespace Oyster
Translator () { };
~Translator() { };
void Pack (Protocols::ProtocolHeader &header, OysterByte& bytes );
void Unpack (Protocols::ProtocolSet* set, OysterByte& bytes );
void Pack (Protocols::ProtocolHeader &header, Utility::DynamicMemory::SmartPointer<OysterByte> &bytes );
void Unpack (Protocols::ProtocolSet* set, Utility::DynamicMemory::SmartPointer<OysterByte> &bytes );
private:

View File

@ -17,7 +17,7 @@ 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) ,

View File

@ -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);
}

View File

@ -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

View File

@ -6,15 +6,20 @@
#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"
#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 chat(ThreadedClient &client);
void PrintOutMessage(ProtocolSet* set);
int main()
{
@ -27,10 +32,10 @@ int main()
cout << "Client" << endl;
//Create Client
Client client;
ThreadedClient* client = new ThreadedClient;
//Connect to server
errorCode = client.Connect(9876, "localhost");
errorCode = client->Connect(9876, "localhost");
if(errorCode != 0)
{
@ -38,7 +43,8 @@ int main()
wcout << "errorMessage: " << errorTest << endl;
}
chat(client);
chat(*client);
delete client;
ShutdownWinSock();
@ -46,76 +52,79 @@ int main()
return 0;
}
void chat(Client &client)
void chat(ThreadedClient &client)
{
Oyster::Network::Translator *t = new Oyster::Network::Translator();
IPostBox< SmartPointer<OysterByte >> *postBox = new PostBox< SmartPointer<OysterByte >>;
Oyster::Network::OysterByte msgRecv;
string msgSend = "";
client.setRecvPostBox(postBox);
SmartPointer<OysterByte> msgRecv = new OysterByte();
SmartPointer<OysterByte> msgSend = new OysterByte();
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++)
ProtocolPlayerPos test;
test.ID = 5;
test.nrOfFloats = 5;
test.matrix = new float[test.nrOfFloats];
float temp = 10;
for(int i = 0; i < (int)test.nrOfFloats; i++)
{
test.f[i] = temp;
test.matrix[i] = temp;
temp++;
}
t->Pack(test, msgSend);
bool chatDone = false;
WinTimer timer;
while(!chatDone)
while(1)
{
//Fetch new messages from the postbox
if(postBox->FetchMessage(msgRecv))
{
client.Recv(msgRecv);
t->Unpack(set, msgRecv);
//PrintOutMessage(set);
set->Release();
}
//Send message to server each second
if(timer.getElapsedSeconds() > 1)
{
cout << "Sending to server." << endl;
timer.reset();
client.Send(msgSend);
}
Sleep(1);
}
delete postBox;
delete t;
delete set;
}
void PrintOutMessage(ProtocolSet* set)
{
switch(set->type)
{
case PackageType_header:
break;
case PackageType_test:
cout <<"Client 2: " << set->Protocol.pTest->textMessage <<endl;
for(int i = 0; i < set->Protocol.pTest->numOfFloats; i++)
for(int i = 0; i < (int)set->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")
case PackageType_player_pos:
cout << "ID " << set->Protocol.pPlayerPos->ID << endl;
for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++)
{
if(msgSend.length() < 1)
{
msgSend = "ERROR!";
cout << set->Protocol.pPlayerPos->matrix[i] << ' ';
}
test.textMessage = msgSend;
t->Pack(test, msgRecv);
client.Send(msgRecv);
cout << endl;
break;
}
else
{
chatDone = true;
}
cin.clear();*/
}
delete t;
delete set;
}

View File

@ -154,12 +154,8 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Client.cpp" />
<ClCompile Include="ClientMain.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Client.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -18,13 +18,5 @@
<ClCompile Include="ClientMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Client.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Client.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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);
}

View File

@ -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

View File

@ -149,16 +149,20 @@
<ProjectReference Include="..\..\Misc\Misc.vcxproj">
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
</ProjectReference>
<ProjectReference Include="..\NetworkAPI\NetworkAPI.vcxproj">
<Project>{460d625f-2ac9-4559-b809-0ba89ceaedf4}</Project>
</ProjectReference>
<ProjectReference Include="..\NetworkDependencies\NetworkDependencies.vcxproj">
<Project>{c5aa09d0-6594-4cd3-bd92-1d380c7b3b50}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Client.cpp" />
<ClCompile Include="ServerMain.cpp" />
<ClCompile Include="TestClass.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Client.h" />
<ClInclude Include="RecieverObject.h" />
<ClInclude Include="TestClass.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -18,12 +18,15 @@
<ClCompile Include="ServerMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Client.cpp">
<ClCompile Include="TestClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Client.h">
<ClInclude Include="RecieverObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>

View File

@ -0,0 +1,19 @@
#ifndef OYSTER_NETWORK_SERVER_RECIEVER_OBJECT_H
#define OYSTER_NETWORK_SERVER_RECIEVER_OBJECT_H
/////////////////////////////////////
// Created by Pontus Fransson 2013 //
/////////////////////////////////////
#include "../NetworkDependencies/Protocols.h"
#include "../NetworkDependencies/OysterByte.h"
#include "../../Misc/Utilities.h"
class RecieverObject
{
public:
virtual void ProcFunc(Utility::DynamicMemory::SmartPointer<Oyster::Network::OysterByte> msg) = 0;
};
#endif

View File

@ -3,126 +3,53 @@
#include <vector>
#include <vld.h>
#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"
#pragma comment(lib, "ws2_32.lib")
#include "TestClass.h"
using namespace std;
using namespace Oyster::Network::Server;
using namespace Oyster::Network;
using namespace ::Protocols;
using namespace Utility;
void clientProc(Oyster::Network::NetworkClient* client);
int main()
{
OysterByte recvBuffer;
IPostBox<int>* postBox = new PostBox<int>();
cout << "Server" << endl;
Translator t;
int errorCode;
if(!InitWinSock())
{
cout << "errorMessage: unable to start winsock" << endl;
}
//Create socket
Listener listener;
listener.Init(9876);
listener.SetPostBox(postBox);
Sleep(1000);
Test test;
//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++)
{
test.f[i] = temp;
temp--;
}
cout << "Server" << endl;
t.Pack(test, recvBuffer);
test.mainLoop();
WinTimer timer;
vector<Client*> 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.
//Fetch new clients from the postbox
/*
//Send a message every 1 seconds 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);
clients.at(i)->Send(sendBuffer);
}
}
Sleep(100);
}
listener.Shutdown();
}*/
/*
ProtocolSet* set = new ProtocolSet;
client1.Send(recvBuffer);
while(1)
/*//Fetch messages
if(recvPostBox->FetchMessage(recvBuffer))
{
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;
//PrintOutMessage(set);
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);
}*/
}
Sleep(1000);
ShutdownWinSock();
delete set;
*/
system("pause");
return 0;
}

View File

@ -0,0 +1,86 @@
#include "TestClass.h"
#include "../../Misc/WinTimer.h"
#include <iostream>
using namespace Oyster::Network;
using namespace ::Server;
using namespace ::Protocols;
using namespace Utility;
using namespace ::DynamicMemory;
using namespace std;
Test::Test()
{
recvPostBox = new PostBox<SmartPointer<OysterByte>>;
sendBuffer = new OysterByte;
recvBuffer = new OysterByte;
NetworkServer::INIT_DESC initDesc;
initDesc.port = 9876;
initDesc.proc = NULL;
server.Init(initDesc);
server.Start();
test.clientID = 0;
test.ID = 5;
test.nrOfFloats = 10;
test.matrix = new float[test.nrOfFloats];
for(int i = 0; i < (int)test.nrOfFloats; i++)
{
test.matrix[i] = (float)i;
}
t.Pack(test, sendBuffer);
}
Test::~Test()
{
for(int i = 0; i < (int)clients.size(); i++)
delete clients.at(i);
server.Stop();
}
void Test::ProcFunc(Utility::DynamicMemory::SmartPointer<Oyster::Network::OysterByte> msg)
{
return;
}
void Test::mainLoop()
{
WinTimer timer;
while(1)
{
}
}
void Test::PrintOutMessage(ProtocolSet* set)
{
switch(set->type)
{
case PackageType_header:
break;
case PackageType_test:
cout <<"Client 2: " << set->Protocol.pTest->textMessage <<endl;
for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++)
{
cout << set->Protocol.pTest->f[i] << ' ' ;
}
cout << endl;
break;
case PackageType_player_pos:
//cout << "ID " << set->Protocol.pPlayerPos->ID << endl;
for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++)
{
cout << set->Protocol.pPlayerPos->matrix[i] << ' ';
}
cout << endl;
break;
}
}

View File

@ -0,0 +1,37 @@
#ifndef TEST_CLASS_H
#define TEST_CLASS_H
#include "RecieverObject.h"
#include "../../Misc/Utilities.h"
#include "../NetworkDependencies/OysterByte.h"
#include "../NetworkDependencies/PostBox.h"
#include "../NetworkAPI/NetworkClient.h"
#include "../NetworkAPI/NetworkServer.h"
#include "../NetworkDependencies/Translator.h"
#include <vector>
class Test : public RecieverObject
{
public:
Test();
~Test();
void mainLoop();
virtual void ProcFunc(Utility::DynamicMemory::SmartPointer<Oyster::Network::OysterByte> msg);
void PrintOutMessage(Oyster::Network::Protocols::ProtocolSet* set);
private:
std::vector<Oyster::Network::NetworkClient*> clients;
Oyster::Network::IPostBox<Utility::DynamicMemory::SmartPointer<Oyster::Network::OysterByte>> *recvPostBox;
Oyster::Network::Translator t;
Oyster::Network::Protocols::ProtocolPlayerPos test;
Utility::DynamicMemory::SmartPointer<Oyster::Network::OysterByte> sendBuffer;
Utility::DynamicMemory::SmartPointer<Oyster::Network::OysterByte> recvBuffer;
Oyster::Network::Server::NetworkServer server;
};
#endif

View File

@ -33,6 +33,7 @@ namespace Oyster
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
D3D_FEATURE_LEVEL featureLevelsToTry[] =
{

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -4,10 +4,10 @@
#include "OysterMath.h"
#include <Windows.h>
#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
@ -28,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);

View File

@ -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);
}
}
}

View File

@ -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;i<info->Material.size();++i)
{
Oyster::Resource::OysterResource::ReleaseResource(info->Material[i]);
}
delete info;
}
#include <wrl.h>
#include <memory>

View File

@ -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()

View File

@ -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));
}

View File

@ -109,6 +109,7 @@
</ProjectReference>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -124,12 +125,13 @@
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
@ -143,12 +145,14 @@
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<EnableDebuggingInformation>true</EnableDebuggingInformation>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
@ -162,6 +166,8 @@
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<EnableDebuggingInformation>true</EnableDebuggingInformation>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemGroup>
@ -172,7 +178,7 @@
<ClCompile Include="DllInterfaces\GFXAPI.cpp" />
<ClCompile Include="FileLoader\ObjReader.cpp" />
<ClCompile Include="FileLoader\ShaderLoader.cpp" />
<ClCompile Include="FileLoader\TextureLoader.cpp" />
<ClCompile Include="FileLoader\ModelLoader.cpp" />
<ClCompile Include="Render\Preparations\BasicPreparations.cpp" />
<ClCompile Include="Render\Rendering\BasicRender.cpp" />
<ClCompile Include="Render\Resources\Resources.cpp" />
@ -264,6 +270,8 @@
<ItemGroup>
<None Include="Shader\HLSL\Deffered Shaders\GatherGBuffer\GBufferHeader.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\Defines.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\LightCalc.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\PosManipulation.hlsli" />
<None Include="Shader\HLSL\SimpleDebug\Debug.hlsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -2,6 +2,8 @@
#include "../Resources/Resources.h"
#include "../../Definitions/GraphicalDefinition.h"
#include "../../Model/ModelInfo.h"
#include <map>
#include <vector>
namespace Oyster
{
@ -60,7 +62,8 @@ namespace Oyster
}
void Basic::EndFrame()
{
Core::swapChain->Present(0,0);
IDXGISwapChain* chain = Core::swapChain;
chain->Present(0,0);
}
}
}

View File

@ -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)
{

View File

@ -1,7 +1,31 @@
#ifndef DEFINES
#define DEFINES
struct PointLight
{
float3 Pos;
float Radius;
float4 PosRadius;
float4 ColorBright;
};
float3 Color;
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

View File

@ -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;
}

View File

@ -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)
}

View File

@ -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;
}

View File

@ -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();

View File

@ -69,7 +69,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
@ -77,7 +77,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
@ -85,7 +85,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
@ -93,7 +93,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
@ -113,7 +113,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>OysterGraphics_x86D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<ProjectReference>
<LinkLibraryDependencies>
@ -136,7 +136,6 @@
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<PreventDllBinding>true</PreventDllBinding>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -144,9 +143,9 @@
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\OysterGraphics;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@ -159,7 +158,7 @@
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<PreventDllBinding>true</PreventDllBinding>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>OysterGraphics_x86.dll;</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -167,7 +166,7 @@
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -182,7 +181,6 @@
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<PreventDllBinding>true</PreventDllBinding>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemGroup>