Merge with Gamle Logic

This commit is contained in:
lindaandersson 2014-01-20 11:59:43 +01:00
commit a1128986d5
110 changed files with 2919 additions and 1131 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.1"> <diagram program="umlet" version="12.2">
<zoom_level>11</zoom_level> <zoom_level>11</zoom_level>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>726</x> <x>847</x>
<y>363</y> <y>363</y>
<w>132</w> <w>132</w>
<h>33</h> <h>33</h>
@ -15,7 +15,7 @@
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>440</x> <x>561</x>
<y>363</y> <y>363</y>
<w>132</w> <w>132</w>
<h>33</h> <h>33</h>
@ -26,19 +26,19 @@
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>550</x> <x>671</x>
<y>286</y> <y>209</y>
<w>132</w> <w>132</w>
<h>33</h> <h>33</h>
</coordinates> </coordinates>
<panel_attributes>Physics / Math</panel_attributes> <panel_attributes>Physics</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>737</x> <x>858</x>
<y>176</y> <y>132</y>
<w>121</w> <w>121</w>
<h>33</h> <h>33</h>
</coordinates> </coordinates>
@ -48,8 +48,8 @@
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>363</x> <x>484</x>
<y>286</y> <y>209</y>
<w>154</w> <w>154</w>
<h>33</h> <h>33</h>
</coordinates> </coordinates>
@ -59,8 +59,8 @@
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>385</x> <x>506</x>
<y>176</y> <y>132</y>
<w>121</w> <w>121</w>
<h>33</h> <h>33</h>
</coordinates> </coordinates>
@ -70,8 +70,8 @@
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>550</x> <x>671</x>
<y>154</y> <y>132</y>
<w>132</w> <w>132</w>
<h>33</h> <h>33</h>
</coordinates> </coordinates>
@ -81,7 +81,7 @@
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>583</x> <x>704</x>
<y>363</y> <y>363</y>
<w>132</w> <w>132</w>
<h>33</h> <h>33</h>
@ -92,86 +92,64 @@
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>550</x> <x>495</x>
<y>198</y>
<w>132</w>
<h>33</h>
</coordinates>
<panel_attributes>Threading</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>550</x>
<y>55</y> <y>55</y>
<w>132</w> <w>176</w>
<h>44</h> <h>44</h>
</coordinates> </coordinates>
<panel_attributes>DanBias <panel_attributes>DanBiasClientLauncher
bg=green</panel_attributes> bg=green</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>759</x> <x>880</x>
<y>176</y> <y>132</y>
<w>54</w> <w>54</w>
<h>208</h> <h>252</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;187;33;165;33;33</additional_attributes> <additional_attributes>33;231;33;209;33;33</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>462</x> <x>583</x>
<y>176</y> <y>132</y>
<w>351</w> <w>351</w>
<h>208</h> <h>252</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;187;33;165;330;165;330;33</additional_attributes> <additional_attributes>33;231;33;209;330;209;330;33</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>407</x> <x>528</x>
<y>176</y> <y>132</y>
<w>54</w> <w>54</w>
<h>131</h> <h>98</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;110;33;33</additional_attributes> <additional_attributes>33;77;33;33</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>649</x> <x>594</x>
<y>176</y> <y>110</y>
<w>153</w>
<h>142</h>
</coordinates>
<panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;121;132;121;132;33</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>473</x>
<y>143</y>
<w>98</w> <w>98</w>
<h>65</h> <h>54</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>77;33;44;33;44;44;33;44</additional_attributes> <additional_attributes>77;33;33;33</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>484</x> <x>605</x>
<y>264</y> <y>187</y>
<w>87</w> <w>87</w>
<h>54</h> <h>54</h>
</coordinates> </coordinates>
@ -181,76 +159,54 @@ bg=green</panel_attributes>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>616</x> <x>737</x>
<y>176</y> <y>132</y>
<w>197</w> <w>197</w>
<h>208</h> <h>252</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;187;33;165;176;165;176;33</additional_attributes> <additional_attributes>33;231;33;209;176;209;176;33</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>473</x> <x>770</x>
<y>165</y> <y>110</y>
<w>98</w>
<h>65</h>
</coordinates>
<panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>77;44;44;44;44;33;33;33</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>649</x>
<y>165</y>
<w>109</w> <w>109</w>
<h>65</h> <h>54</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;44;66;44;66;33;88;33</additional_attributes> <additional_attributes>33;33;88;33</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>649</x> <x>880</x>
<y>143</y> <y>66</y>
<w>109</w> <w>54</w>
<h>65</h> <h>87</h>
</coordinates>
<panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;33;66;33;66;44;88;44</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>649</x>
<y>33</y>
<w>164</w>
<h>164</h>
</coordinates> </coordinates>
<panel_attributes>lt=&gt;-</panel_attributes> <panel_attributes>lt=&gt;-</panel_attributes>
<additional_attributes>33;33;143;33;143;143</additional_attributes> <additional_attributes>33;33;33;66</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>407</x> <x>528</x>
<y>33</y> <y>66</y>
<w>164</w> <w>54</w>
<h>164</h> <h>87</h>
</coordinates> </coordinates>
<panel_attributes>lt=&gt;-</panel_attributes> <panel_attributes>lt=&gt;-</panel_attributes>
<additional_attributes>143;33;33;33;33;143</additional_attributes> <additional_attributes>33;33;33;66</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Package</type> <type>com.umlet.element.Package</type>
<coordinates> <coordinates>
<x>319</x> <x>440</x>
<y>22</y> <y>22</y>
<w>550</w> <w>550</w>
<h>385</h> <h>396</h>
</coordinates> </coordinates>
<panel_attributes>GameEngine</panel_attributes> <panel_attributes>GameEngine</panel_attributes>
<additional_attributes/> <additional_attributes/>
@ -258,7 +214,7 @@ bg=green</panel_attributes>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>759</x> <x>880</x>
<y>363</y> <y>363</y>
<w>54</w> <w>54</w>
<h>164</h> <h>164</h>
@ -269,7 +225,7 @@ bg=green</panel_attributes>
<element> <element>
<type>com.umlet.element.Package</type> <type>com.umlet.element.Package</type>
<coordinates> <coordinates>
<x>770</x> <x>891</x>
<y>506</y> <y>506</y>
<w>319</w> <w>319</w>
<h>220</h> <h>220</h>
@ -280,7 +236,7 @@ bg=green</panel_attributes>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>781</x> <x>902</x>
<y>539</y> <y>539</y>
<w>297</w> <w>297</w>
<h>176</h> <h>176</h>
@ -300,7 +256,7 @@ Release(resource :Model*) :void</panel_attributes>
<element> <element>
<type>com.umlet.element.Package</type> <type>com.umlet.element.Package</type>
<coordinates> <coordinates>
<x>440</x> <x>561</x>
<y>506</y> <y>506</y>
<w>308</w> <w>308</w>
<h>242</h> <h>242</h>
@ -311,7 +267,7 @@ Release(resource :Model*) :void</panel_attributes>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>528</x> <x>649</x>
<y>363</y> <y>363</y>
<w>142</w> <w>142</w>
<h>175</h> <h>175</h>
@ -322,7 +278,7 @@ Release(resource :Model*) :void</panel_attributes>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>451</x> <x>572</x>
<y>539</y> <y>539</y>
<w>286</w> <w>286</w>
<h>198</h> <h>198</h>
@ -343,7 +299,7 @@ Enable(Enable :bool) :void</panel_attributes>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>330</x> <x>451</x>
<y>363</y> <y>363</y>
<w>99</w> <w>99</w>
<h>33</h> <h>33</h>
@ -354,18 +310,18 @@ Enable(Enable :bool) :void</panel_attributes>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>341</x> <x>462</x>
<y>176</y> <y>132</y>
<w>472</w> <w>472</w>
<h>208</h> <h>252</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;187;33;165;451;165;451;33</additional_attributes> <additional_attributes>33;231;33;209;451;209;451;33</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Package</type> <type>com.umlet.element.Package</type>
<coordinates> <coordinates>
<x>55</x> <x>176</x>
<y>506</y> <y>506</y>
<w>374</w> <w>374</w>
<h>242</h> <h>242</h>
@ -376,7 +332,7 @@ Enable(Enable :bool) :void</panel_attributes>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>66</x> <x>187</x>
<y>539</y> <y>539</y>
<w>352</w> <w>352</w>
<h>121</h> <h>121</h>
@ -393,7 +349,7 @@ Release(Resource :ResourceHandle*) :void</panel_attributes>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>66</x> <x>187</x>
<y>693</y> <y>693</y>
<w>352</w> <w>352</w>
<h>44</h> <h>44</h>
@ -406,7 +362,7 @@ FMOD</panel_attributes>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>209</x> <x>330</x>
<y>627</y> <y>627</y>
<w>54</w> <w>54</w>
<h>87</h> <h>87</h>
@ -417,7 +373,7 @@ FMOD</panel_attributes>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>165</x> <x>286</x>
<y>363</y> <y>363</y>
<w>362</w> <w>362</w>
<h>175</h> <h>175</h>
@ -425,4 +381,60 @@ FMOD</panel_attributes>
<panel_attributes>lt=&lt;&lt;.</panel_attributes> <panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>341;33;341;88;253;88;253;154;33;154</additional_attributes> <additional_attributes>341;33;341;88;253;88;253;154;33;154</additional_attributes>
</element> </element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>781</x>
<y>55</y>
<w>198</w>
<h>44</h>
</coordinates>
<panel_attributes>DanBiasServerLauncher
bg=green</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>671</x>
<y>253</y>
<w>132</w>
<h>33</h>
</coordinates>
<panel_attributes>Math</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>770</x>
<y>132</y>
<w>153</w>
<h>164</h>
</coordinates>
<panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>33;143;132;143;132;33</additional_attributes>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>682</x>
<y>297</y>
<w>99</w>
<h>33</h>
</coordinates>
<panel_attributes>Misc</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>605</x>
<y>198</y>
<w>87</w>
<h>98</h>
</coordinates>
<panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>66;77;44;77;44;33;33;33</additional_attributes>
</element>
</diagram> </diagram>

View File

@ -0,0 +1,334 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.1">
<zoom_level>10</zoom_level>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>390</x>
<y>120</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>/C_Object/
</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>320</x>
<y>0</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>C_Player</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>440</x>
<y>0</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>C_StaticObj</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>200</x>
<y>0</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>C_DynamicObj</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>240</x>
<y>0</y>
<w>200</w>
<h>140</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;-</panel_attributes>
<additional_attributes>30;30;30;120;180;120</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>370</x>
<y>0</y>
<w>50</w>
<h>140</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;-</panel_attributes>
<additional_attributes>30;30;30;120</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>450</x>
<y>0</y>
<w>50</w>
<h>140</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;-</panel_attributes>
<additional_attributes>30;30;30;120</additional_attributes>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>210</x>
<y>220</y>
<w>100</w>
<h>100</h>
</coordinates>
<panel_attributes>GameState
--
C_Object*
GameState
Camera
Client*</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>360</x>
<y>330</y>
<w>160</w>
<h>50</h>
</coordinates>
<panel_attributes>/GameClientState/
Is eighter game or lobby </panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>570</x>
<y>220</y>
<w>100</w>
<h>100</h>
</coordinates>
<panel_attributes>LobbyState
--
C_Object*
Camera
Client*</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>380</x>
<y>440</y>
<w>120</w>
<h>120</h>
</coordinates>
<panel_attributes>DanBiasGame
--
Client
Input
GameClientState
Window</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>400</x>
<y>350</y>
<w>50</w>
<h>110</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes>
<additional_attributes>30;90;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>230</x>
<y>290</y>
<w>150</w>
<h>80</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;-</panel_attributes>
<additional_attributes>30;30;30;60;130;60</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>490</x>
<y>290</y>
<w>150</w>
<h>80</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;-</panel_attributes>
<additional_attributes>130;30;130;60;30;60</additional_attributes>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>560</x>
<y>0</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>C_UiObject</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>410</x>
<y>0</y>
<w>210</w>
<h>140</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;-</panel_attributes>
<additional_attributes>190;30;190;120;30;120</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>410</x>
<y>120</y>
<w>180</w>
<h>120</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-</panel_attributes>
<additional_attributes>160;100;30;100;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>280</x>
<y>120</y>
<w>170</w>
<h>120</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-</panel_attributes>
<additional_attributes>30;100;150;100;150;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>620</x>
<y>120</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>Light</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>340</x>
<y>640</y>
<w>100</w>
<h>40</h>
</coordinates>
<panel_attributes>NetworkAPI
--</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>230</x>
<y>640</y>
<w>100</w>
<h>40</h>
</coordinates>
<panel_attributes>GraphicsAPI
--
</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>230</x>
<y>530</y>
<w>170</w>
<h>130</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>30;110;30;30;150;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>360</x>
<y>530</y>
<w>50</w>
<h>130</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>30;110;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>460</x>
<y>640</y>
<w>100</w>
<h>40</h>
</coordinates>
<panel_attributes>Input
--</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>460</x>
<y>530</y>
<w>50</w>
<h>130</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>30;110;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>120</x>
<y>520</y>
<w>110</w>
<h>40</h>
</coordinates>
<panel_attributes>DanBiasLancher
--</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>580</x>
<y>640</y>
<w>110</w>
<h>40</h>
</coordinates>
<panel_attributes>WindowManager
--</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>470</x>
<y>530</y>
<w>190</w>
<h>130</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>170;110;170;30;30;30</additional_attributes>
</element>
</diagram>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.2">
<zoom_level>10</zoom_level>
</diagram>

View File

@ -423,14 +423,14 @@ INetworkSession</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>170</x> <x>150</x>
<y>400</y> <y>420</y>
<w>130</w> <w>160</w>
<h>90</h> <h>50</h>
</coordinates> </coordinates>
<panel_attributes>MapManager <panel_attributes>MapManager
-- --
Manages and makes sure maps are avalible to all clinents. Manages all map stuff.
elementstyle=wordwrap elementstyle=wordwrap
</panel_attributes> </panel_attributes>

View File

@ -0,0 +1,402 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.2">
<zoom_level>8</zoom_level>
<element>
<id>UMLClass</id>
<coordinates>
<x>680</x>
<y>592</y>
<w>136</w>
<h>40</h>
</coordinates>
<panel_attributes>CustomNetworkProtocol
--</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>560</x>
<y>688</y>
<w>152</w>
<h>40</h>
</coordinates>
<panel_attributes>NetworkServer
--
elementstyle=wordwrap</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>776</x>
<y>688</y>
<w>152</w>
<h>40</h>
</coordinates>
<panel_attributes>NetworkClient
--
elementstyle=wordwrap</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>720</x>
<y>448</y>
<w>40</w>
<h>160</h>
</coordinates>
<panel_attributes>lt=&gt;
fg=red</panel_attributes>
<additional_attributes>24;24;24;144</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>664</x>
<y>432</y>
<w>152</w>
<h>40</h>
</coordinates>
<panel_attributes>GameProtocols
--
elementstyle=wordwrap
bg=green</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>592</x>
<y>424</y>
<w>88</w>
<h>48</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>24;32;72;24</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>464</x>
<y>440</y>
<w>152</w>
<h>40</h>
</coordinates>
<panel_attributes>DanBiasServer
--
elementstyle=wordwrap
bg=green</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>880</x>
<y>440</y>
<w>152</w>
<h>40</h>
</coordinates>
<panel_attributes>DanBiasGame
--
elementstyle=wordwrap
bg=green</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>792</x>
<y>424</y>
<w>104</w>
<h>48</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>88;32;24;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>608</x>
<y>608</y>
<w>152</w>
<h>96</h>
</coordinates>
<panel_attributes>lt=&gt;
fg=blue</panel_attributes>
<additional_attributes>24;80;24;56;136;56;136;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>736</x>
<y>608</y>
<w>136</w>
<h>96</h>
</coordinates>
<panel_attributes>lt=&gt;
fg=blue</panel_attributes>
<additional_attributes>120;80;120;56;24;56;24;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>688</x>
<y>680</y>
<w>104</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;
fg=blue</panel_attributes>
<additional_attributes>88;24;24;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>512</x>
<y>456</y>
<w>64</w>
<h>264</h>
</coordinates>
<panel_attributes>lt=&gt;
fg=red</panel_attributes>
<additional_attributes>24;24;24;248;48;248</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>904</x>
<y>456</y>
<w>64</w>
<h>272</h>
</coordinates>
<panel_attributes>lt=&gt;
fg=red</panel_attributes>
<additional_attributes>48;24;48;256;24;256</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>504</x>
<y>456</y>
<w>288</w>
<h>304</h>
</coordinates>
<panel_attributes>lt=&gt;
fg=red</panel_attributes>
<additional_attributes>24;24;24;288;248;288;248;256;272;256</additional_attributes>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>544</x>
<y>568</y>
<w>400</w>
<h>168</h>
</coordinates>
<panel_attributes>bg=orange
NetworkAPI</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>720</x>
<y>240</y>
<w>40</w>
<h>208</h>
</coordinates>
<panel_attributes>lt=.
fg=red</panel_attributes>
<additional_attributes>24;24;24;192</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>520</x>
<y>168</y>
<w>120</w>
<h>56</h>
</coordinates>
<panel_attributes>ProtocolIdentificationID
--
/Collection of uniuqe/
/protocol identifications/
</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>824</x>
<y>176</y>
<w>120</w>
<h>48</h>
</coordinates>
<panel_attributes>GameProtocols
--
/Collects protocols/
</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>696</x>
<y>136</y>
<w>88</w>
<h>24</h>
</coordinates>
<panel_attributes>ControlProtocols
</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>696</x>
<y>168</y>
<w>88</w>
<h>24</h>
</coordinates>
<panel_attributes>LobbyProtocols
</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>696</x>
<y>200</y>
<w>88</w>
<h>24</h>
</coordinates>
<panel_attributes>ObjectProtocols</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>696</x>
<y>232</y>
<w>88</w>
<h>24</h>
</coordinates>
<panel_attributes>PlayerProtocols
</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>760</x>
<y>184</y>
<w>80</w>
<h>72</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>64;24;48;24;48;56;24;56</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>760</x>
<y>176</y>
<w>80</w>
<h>48</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>64;24;40;24;40;32;24;32</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>760</x>
<y>160</y>
<w>80</w>
<h>48</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>64;32;40;32;40;24;24;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>760</x>
<y>128</y>
<w>80</w>
<h>72</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>64;56;48;56;48;24;24;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>616</x>
<y>184</y>
<w>96</w>
<h>72</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>80;56;56;56;56;24;24;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>616</x>
<y>176</y>
<w>96</w>
<h>48</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>80;32;64;32;64;24;24;24</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>616</x>
<y>160</y>
<w>96</w>
<h>48</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>80;24;64;24;64;32;24;32</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>616</x>
<y>128</y>
<w>96</w>
<h>72</h>
</coordinates>
<panel_attributes>lt=&gt;</panel_attributes>
<additional_attributes>80;24;56;24;56;56;24;56</additional_attributes>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>512</x>
<y>112</y>
<w>440</w>
<h>152</h>
</coordinates>
<panel_attributes>bg=orange
GameProtocols</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>744</x>
<y>312</y>
<w>184</w>
<h>72</h>
</coordinates>
<panel_attributes>Protocols is created in a seperate module because both server and client needs to share the same protocols and the same protocol identifications.
elementstyle=wordwrap</panel_attributes>
<additional_attributes/>
</element>
</diagram>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.1"> <diagram program="umlet" version="12.2">
<zoom_level>12</zoom_level> <zoom_level>12</zoom_level>
<element> <element>
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>540</x> <x>540</x>
<y>456</y> <y>468</y>
<w>132</w> <w>336</w>
<h>36</h> <h>36</h>
</coordinates> </coordinates>
<panel_attributes>OysterThread</panel_attributes> <panel_attributes>OysterThread</panel_attributes>
@ -16,9 +16,9 @@
<type>com.umlet.element.Class</type> <type>com.umlet.element.Class</type>
<coordinates> <coordinates>
<x>372</x> <x>372</x>
<y>408</y> <y>396</y>
<w>120</w> <w>120</w>
<h>36</h> <h>48</h>
</coordinates> </coordinates>
<panel_attributes>/Some class/</panel_attributes> <panel_attributes>/Some class/</panel_attributes>
<additional_attributes/> <additional_attributes/>
@ -29,11 +29,11 @@
<x>336</x> <x>336</x>
<y>300</y> <y>300</y>
<w>228</w> <w>228</w>
<h>132</h> <h>120</h>
</coordinates> </coordinates>
<panel_attributes>lt=&gt;&gt;&gt;&gt;&gt;- <panel_attributes>lt=&gt;&gt;&gt;&gt;&gt;-
&lt;&lt;implements&gt;&gt;</panel_attributes> &lt;&lt;implements&gt;&gt;</panel_attributes>
<additional_attributes>96;108;96;60;204;60</additional_attributes> <additional_attributes>96;96;96;60;204;60</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
@ -41,52 +41,30 @@
<x>396</x> <x>396</x>
<y>408</y> <y>408</y>
<w>168</w> <w>168</w>
<h>96</h> <h>108</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;&lt;- <panel_attributes>lt=&lt;&lt;&lt;&lt;-
Creates&gt;&gt;</panel_attributes> Creates&gt;&gt;</panel_attributes>
<additional_attributes>36;36;36;72;132;72;144;72</additional_attributes> <additional_attributes>36;36;36;84;132;84;144;84</additional_attributes>
</element> </element>
<element> <element>
<type>com.umlet.element.Relation</type> <type>com.umlet.element.Relation</type>
<coordinates> <coordinates>
<x>564</x> <x>660</x>
<y>372</y> <y>384</y>
<w>60</w> <w>60</w>
<h>108</h> <h>108</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-</panel_attributes> <panel_attributes>lt=&lt;&lt;&lt;-</panel_attributes>
<additional_attributes>36;84;36;36</additional_attributes> <additional_attributes>36;84;36;36</additional_attributes>
</element> </element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>540</x>
<y>540</y>
<w>132</w>
<h>36</h>
</coordinates>
<panel_attributes>OysterMutex</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>564</x>
<y>456</y>
<w>60</w>
<h>108</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes>
<additional_attributes>36;36;36;84</additional_attributes>
</element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>540</x> <x>540</x>
<y>312</y> <y>312</y>
<w>336</w> <w>336</w>
<h>96</h> <h>108</h>
</coordinates> </coordinates>
<panel_attributes>/&lt;&lt;interface&gt;&gt;/ <panel_attributes>/&lt;&lt;interface&gt;&gt;/
IThreadObject IThreadObject
@ -123,16 +101,4 @@ bg=red</panel_attributes>
<panel_attributes>lt=-</panel_attributes> <panel_attributes>lt=-</panel_attributes>
<additional_attributes>36;36;36;108</additional_attributes> <additional_attributes>36;36;36;108</additional_attributes>
</element> </element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>336</x>
<y>408</y>
<w>228</w>
<h>168</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;.
uses</panel_attributes>
<additional_attributes>60;36;60;144;204;144</additional_attributes>
</element>
</diagram> </diagram>

View File

@ -3,6 +3,5 @@
BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ) BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved )
{ {
//MessageBox(0, L"DanBiasGame Loaded", 0, 0);
return TRUE; return TRUE;
} }

View File

@ -204,6 +204,7 @@
<ClCompile Include="GameClientState\C_Object.cpp" /> <ClCompile Include="GameClientState\C_Object.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="GameClientRecieverFunc.h" />
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" /> <ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
<ClInclude Include="GameClientState\C_obj\C_Player.h" /> <ClInclude Include="GameClientState\C_obj\C_Player.h" />
<ClInclude Include="GameClientState\C_obj\C_StaticObj.h" /> <ClInclude Include="GameClientState\C_obj\C_StaticObj.h" />

View File

@ -5,118 +5,20 @@
#include "GameClientState/GameClientState.h" #include "GameClientState/GameClientState.h"
#include "GameClientState\GameState.h" #include "GameClientState\GameState.h"
#include "GameClientState\LobbyState.h" #include "GameClientState\LobbyState.h"
#include <GameProtocols.h> #include <Protocols.h>
#include "NetworkClient.h" #include "NetworkClient.h"
#include "../WindowManager/WindowShell.h" #include "../WindowManager/WindowShell.h"
#include "L_inputClass.h" #include "L_inputClass.h"
#include "WinTimer.h" #include "WinTimer.h"
#include "vld.h" #include "vld.h"
#include "GameClientRecieverFunc.h"
namespace DanBias namespace DanBias
{ {
#pragma region Game Data #pragma region Game Data
struct MyRecieverObject :public Oyster::Network::ProtocolRecieverObject
{
Oyster::Network::NetworkClient* nwClient;
Client::GameClientState* gameClientState;
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
{
int pType = p[0].value.netInt;
switch (pType)
{
case protocol_General_Status:
{
GameLogic::Protocol_General_Status::States state;
state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort;
}
break;
case protocol_Gameplay_PlayerNavigation:
{
Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput;
for(int i = 0; i< 6; i++)
{
protocolData->key[i] = p[i+1].value.netBool;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_PlayerPosition:
{
Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos;
for(int i = 0; i< 3; i++)
{
protocolData->playerPos[i] = p[i].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_CreateObject:
{
Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj;
protocolData->object_ID = p[1].value.netInt;
protocolData->path = p[2].value.netCharPtr;
for(int i = 0; i< 16; i++)
{
protocolData->worldPos[i] = p[i+3].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_RemoveObject:
{
Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj;
protocolData->object_ID = p[1].value.netInt;
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_ObjectPosition:
{
Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos;
protocolData->object_ID = p[1].value.netInt;
for(int i = 0; i< 16; i++)
{
protocolData->worldPos[i] = p[i+2].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
default:
break;
}
}
};
class DanBiasGamePrivateData class DanBiasGamePrivateData
{ {
@ -134,13 +36,14 @@ namespace DanBias
WindowShell* window; WindowShell* window;
InputClass* inputObj; InputClass* inputObj;
Utility::WinTimer* timer; Utility::WinTimer* timer;
MyRecieverObject* recieverObj; GameRecieverObject* recieverObj;
} data; } data;
#pragma endregion #pragma endregion
DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData(); DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData();
float DanBiasGame::capFrame = 0;
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Interface API functions // Interface API functions
@ -157,9 +60,9 @@ namespace DanBias
if( FAILED( InitInput() ) ) if( FAILED( InitInput() ) )
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
m_data->recieverObj = new MyRecieverObject; m_data->recieverObj = new GameRecieverObject;
// m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object); m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object);
m_data->recieverObj->nwClient->Connect(desc.port, desc.IP); m_data->recieverObj->nwClient->Connect(desc.port, desc.IP);
if (!m_data->recieverObj->nwClient->IsConnected()) if (!m_data->recieverObj->nwClient->IsConnected())
@ -185,10 +88,16 @@ namespace DanBias
float dt = (float)m_data->timer->getElapsedSeconds(); float dt = (float)m_data->timer->getElapsedSeconds();
m_data->timer->reset(); m_data->timer->reset();
if(Update(dt) != S_OK) capFrame += dt;
return DanBiasClientReturn_Error; if(capFrame > 0.03)
if(Render(dt) != S_OK) {
return DanBiasClientReturn_Error; if(Update(dt) != S_OK)
return DanBiasClientReturn_Error;
if(Render(dt) != S_OK)
return DanBiasClientReturn_Error;
capFrame = 0;
}
} }
return DanBiasClientReturn_Sucess; return DanBiasClientReturn_Sucess;
} }

View File

@ -0,0 +1,113 @@
#ifndef DANBIAS_CLIENTRECIEVEROBJECT_H
#define DANBIAS_CLIENTRECIEVEROBJECT_H
namespace DanBias
{
struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
{
Oyster::Network::NetworkClient* nwClient;
Client::GameClientState* gameClientState;
// receiver function for server messages
// parsing protocols and sending it to the gameState
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
{
int pType = p[0].value.netInt;
switch (pType)
{
case protocol_General_Status:
{
GameLogic::Protocol_General_Status::States state;
state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort;
if( state == GameLogic::Protocol_General_Status::States_disconected)
{
// server disconnected
DanBiasGame::Release();
}
}
break;
case protocol_Gameplay_PlayerNavigation:
{
Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput;
for(int i = 0; i< 6; i++)
{
protocolData->key[i] = p[i+1].value.netBool;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_PlayerPosition:
{
Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos;
for(int i = 0; i< 3; i++)
{
protocolData->playerPos[i] = p[i].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_CreateObject:
{
Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj;
protocolData->object_ID = p[1].value.netInt;
protocolData->path = p[2].value.netCharPtr;
for(int i = 0; i< 16; i++)
{
protocolData->worldPos[i] = p[i+3].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete p[2].value.netCharPtr; //delete char array
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_RemoveObject:
{
Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj;
protocolData->object_ID = p[1].value.netInt;
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_ObjectPosition:
{
Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos;
protocolData->object_ID = p[1].value.netInt;
for(int i = 0; i< 16; i++)
{
protocolData->worldPos[i] = p[i+2].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
default:
break;
}
}
};
}
#endif

View File

@ -26,6 +26,7 @@ void C_DynamicObj::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_DynamicObj::setPos(Oyster::Math::Float4x4 world) void C_DynamicObj::setPos(Oyster::Math::Float4x4 world)
{ {

View File

@ -28,7 +28,7 @@ void C_Player::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_Player::setPos(Oyster::Math::Float4x4 world) void C_Player::setPos(Oyster::Math::Float4x4 world)

View File

@ -28,6 +28,7 @@ void C_StaticObj::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_StaticObj::setPos(Oyster::Math::Float4x4 world) void C_StaticObj::setPos(Oyster::Math::Float4x4 world)

View File

@ -24,6 +24,7 @@ void C_UIobject::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_UIobject::setPos(Oyster::Math::Float4x4 world) void C_UIobject::setPos(Oyster::Math::Float4x4 world)

View File

@ -2,7 +2,7 @@
#include "DllInterfaces/GFXAPI.h" #include "DllInterfaces/GFXAPI.h"
#include "C_obj/C_Player.h" #include "C_obj/C_Player.h"
#include "C_obj/C_DynamicObj.h" #include "C_obj/C_DynamicObj.h"
#include <GameProtocols.h> #include <Protocols.h>
#include "NetworkClient.h" #include "NetworkClient.h"
@ -18,10 +18,16 @@ struct GameState::myData
Oyster::Network::NetworkClient* nwClient; Oyster::Network::NetworkClient* nwClient;
gameStateState state; gameStateState state;
}privData; }privData;
GameState::GameState(void) GameState::GameState(void)
{ {
key_forward = false;
key_backward = false;
key_strafeRight = false;
key_strafeLeft = false;
} }
@ -40,6 +46,12 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
} }
GameState::gameStateState GameState::LoadGame() GameState::gameStateState GameState::LoadGame()
{ {
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(0,3,0);
plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 5;
plight.Bright = 2;
Oyster::Graphics::API::AddLight(plight);
LoadModels(L"map"); LoadModels(L"map");
InitCamera(Oyster::Math::Float3(0,0,5.4f)); InitCamera(Oyster::Math::Float3(0,0,5.4f));
return gameStateState_playing; return gameStateState_playing;
@ -54,20 +66,35 @@ bool GameState::LoadModels(std::wstring mapFile)
ModelInitData modelData; ModelInitData modelData;
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
modelData.world = modelData.world * translate;
modelData.visible = true; modelData.visible = true;
modelData.modelPath = L"..\\Content\\worldDummy"; modelData.modelPath = L"..\\Content\\worldDummy";
modelData.id = 0;
// load models // load models
C_Object* obj = new C_Player(); C_Object* obj = new C_Player();
privData->object.push_back(obj); privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData); privData->object[privData->object.size() -1 ]->Init(modelData);
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,2,2));
modelData.world = modelData.world * translate; modelData.world = modelData.world * translate;
modelData.modelPath = L"..\\Content\\worldDummy"; modelData.modelPath = L"..\\Content\\worldDummy";
modelData.id ++;
obj = new C_DynamicObj(); obj = new C_DynamicObj();
privData->object.push_back(obj); privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData); privData->object[privData->object.size() -1 ]->Init(modelData);
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
modelData.world = modelData.world * translate;
modelData.modelPath = L"..\\Content\\worldDummy";
modelData.id ++;
obj = new C_DynamicObj();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
return true; return true;
} }
bool GameState::InitCamera(Oyster::Math::Float3 startPos) bool GameState::InitCamera(Oyster::Math::Float3 startPos)
@ -111,24 +138,53 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
if(KeyInput->IsKeyPressed(DIK_W)) if(KeyInput->IsKeyPressed(DIK_W))
{ {
movePlayer.bForward = true;
send = true; if(!key_forward)
{
movePlayer.bForward = true;
send = true;
key_forward = true;
}
} }
else
key_forward = false;
if(KeyInput->IsKeyPressed(DIK_S)) if(KeyInput->IsKeyPressed(DIK_S))
{ {
movePlayer.bBackward = true; if(!key_backward)
send = true; {
movePlayer.bBackward = true;
send = true;
key_backward = true;
}
} }
else
key_backward = false;
if(KeyInput->IsKeyPressed(DIK_A)) if(KeyInput->IsKeyPressed(DIK_A))
{ {
movePlayer.bStrafeLeft = true; if(!key_strafeLeft)
send = true; {
movePlayer.bStrafeLeft = true;
send = true;
key_strafeLeft = true;
}
} }
else
key_strafeLeft = false;
if(KeyInput->IsKeyPressed(DIK_D)) if(KeyInput->IsKeyPressed(DIK_D))
{ {
movePlayer.bStrafeRight = true; if(!key_strafeRight)
send = true; {
movePlayer.bStrafeRight = true;
send = true;
key_strafeRight = true;
}
} }
else
key_strafeRight = false;
if (privData->nwClient->IsConnected() && send) if (privData->nwClient->IsConnected() && send)
{ {
@ -209,28 +265,35 @@ void GameState::Protocol( ObjPos* pos )
{ {
world[i] = pos->worldPos[i]; world[i] = pos->worldPos[i];
} }
for (int i = 0; i < privData->object.size(); i++) for (int i = 0; i < privData->object.size(); i++)
{ {
if(privData->object[i]->GetId() == pos->object_ID) if(privData->object[i]->GetId() == pos->object_ID)
{
privData->object[i]->setPos(world); privData->object[i]->setPos(world);
//privData->view = world;
//privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
}
} }
} }
void GameState::Protocol( NewObj* pos ) void GameState::Protocol( NewObj* newObj )
{ {
Oyster::Math::Float4x4 world; Oyster::Math::Float4x4 world;
for(int i = 0; i<16; i++) for(int i = 0; i<16; i++)
{ {
world[i] = pos->worldPos[i]; world[i] = newObj->worldPos[i];
} }
ModelInitData modelData; ModelInitData modelData;
modelData.world = world; modelData.world = world;
modelData.visible = true; modelData.visible = true;
modelData.id = pos->object_ID; modelData.id = newObj->object_ID;
//not sure if this is good parsing rom char* to wstring //not sure if this is good parsing rom char* to wstring
const char* path = pos->path; const char* path = newObj->path;
modelData.modelPath = std::wstring(path, path + strlen(path)); modelData.modelPath = std::wstring(path, path + strlen(path));
// load models // load models
C_Object* player = new C_Player(); C_Object* player = new C_Player();

View File

@ -17,6 +17,11 @@ class GameState : public GameClientState
}; };
private: private:
bool key_forward;
bool key_backward;
bool key_strafeRight;
bool key_strafeLeft;
struct myData; struct myData;
myData* privData; myData* privData;
public: public:

View File

@ -39,6 +39,12 @@ bool LobbyState::Init(Oyster::Network::NetworkClient* nwClient)
} }
bool LobbyState::LoadModels(std::wstring file) bool LobbyState::LoadModels(std::wstring file)
{ {
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(-2,3,0);
plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 10;
plight.Bright = 3;
Oyster::Graphics::API::AddLight(plight);
// open file // open file
// read file // read file
// init models // init models

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASGAME_DANBIASGAME_H #ifndef DANBIASGAME_DANBIASGAME_H
#define DANBIASGAME_DANBIASGAME_H #define DANBIASGAME_DANBIASGAME_H
@ -54,6 +57,8 @@ namespace DanBias
static HRESULT Render(float deltaTime); static HRESULT Render(float deltaTime);
static HRESULT CleanUp(); static HRESULT CleanUp();
static float capFrame;
private: private:
static DanBiasGamePrivateData* m_data; static DanBiasGamePrivateData* m_data;

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_ADMIN_INTERFACE_H #ifndef DANBIASSERVER_ADMIN_INTERFACE_H
#define DANBIASSERVER_ADMIN_INTERFACE_H #define DANBIASSERVER_ADMIN_INTERFACE_H

View File

@ -179,10 +179,13 @@
<ClCompile Include="DLLMain.cpp" /> <ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameServer.cpp" /> <ClCompile Include="GameServer.cpp" />
<ClCompile Include="GameSession\GameClient.cpp" /> <ClCompile Include="GameSession\GameClient.cpp" />
<ClCompile Include="GameSession\GameSession_Events.cpp" />
<ClCompile Include="GameSession\GameSession_General.cpp" />
<ClCompile Include="GameSession\GameSession_Network.cpp" />
<ClCompile Include="LobbySessions\INetworkSession.cpp" /> <ClCompile Include="LobbySessions\INetworkSession.cpp" />
<ClCompile Include="LobbySessions\LobbyClient.cpp" /> <ClCompile Include="LobbySessions\LobbyClient.cpp" />
<ClCompile Include="LobbySessions\GameLobby.cpp" /> <ClCompile Include="LobbySessions\GameLobby.cpp" />
<ClCompile Include="GameSession\GameSession.cpp" /> <ClCompile Include="GameSession\GameSession_Logic.cpp" />
<ClCompile Include="LobbySessions\MainLobby.cpp" /> <ClCompile Include="LobbySessions\MainLobby.cpp" />
<ClCompile Include="LobbySessions\NetworkSession.cpp" /> <ClCompile Include="LobbySessions\NetworkSession.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////
// Created by [Dennis Andersen] [2013] // Created by [Dennis Andersen] [2013] //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////
#ifndef DANBIAS_SERVER_DANBIAS_SERVER_H #ifndef DANBIAS_SERVER_DANBIAS_SERVER_H
#define DANBIAS_SERVER_DANBIAS_SERVER_H #define DANBIAS_SERVER_DANBIAS_SERVER_H

View File

@ -22,10 +22,12 @@ namespace DanBias
{ {
using namespace Oyster::Network; using namespace Oyster::Network;
GameServer* GameServer::instance = 0;
void GameServer::NetworkCallback(NetworkClient* client) void GameServer::NetworkCallback(NetworkClient* client)
{ {
static GameSession *myTest = 0; static bool myTest = false;
static int sessionId = -1;
printf("Client with ID [%i] connected.\n", client->GetID()); printf("Client with ID [%i] connected.\n", client->GetID());
if(!myTest) if(!myTest)
@ -36,10 +38,9 @@ namespace DanBias
desc.mapName = L"test"; desc.mapName = L"test";
desc.clients.Push(c); desc.clients.Push(c);
desc.exitDestionation = this->mainLobby; desc.exitDestionation = this->mainLobby;
int sessionId = 0;
if((sessionId = GameSessionManager::AddSession(desc, true)) == 0) if((sessionId = GameSessionManager::AddSession(desc, true)) == 0)
printf("Failed to create a game session"); printf("Failed to create a game session\n");
myTest = true;
//myTest = new GameSession(); //myTest = new GameSession();
// //
//DanBias::GameSession::GameSessionDescription desc; //DanBias::GameSession::GameSessionDescription desc;
@ -52,7 +53,7 @@ namespace DanBias
else else
{ {
Utility::DynamicMemory::SmartPointer<LobbyClient> c = new LobbyClient(client); Utility::DynamicMemory::SmartPointer<LobbyClient> c = new LobbyClient(client);
myTest->Join(c); GameSessionManager::JoinSession(sessionId, c);
} }
@ -68,7 +69,7 @@ namespace DanBias
, maxClients(0) , maxClients(0)
, mainLobby(0) , mainLobby(0)
, server(0) , server(0)
{ } { this->instance = this; }
GameServer::~GameServer() GameServer::~GameServer()
{ {
@ -89,7 +90,6 @@ namespace DanBias
if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error; if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error;
if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error; if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error;
//if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error;
this->initiated = true; this->initiated = true;
return DanBiasServerReturn_Sucess; return DanBiasServerReturn_Sucess;
@ -108,10 +108,9 @@ namespace DanBias
{ {
if(!WindowShell::Frame()) break; if(!WindowShell::Frame()) break;
this->mainLobby->Frame(); this->mainLobby->Frame();
if(GetAsyncKeyState(0x51)) if(GetAsyncKeyState(0x51)) //Q for exit
break; break;
} }
@ -119,6 +118,8 @@ namespace DanBias
} }
DanBiasServerReturn GameServer::Release() DanBiasServerReturn GameServer::Release()
{ {
GameSessionManager::CloseSession();
this->mainLobby->Release();
delete this->mainLobby; delete this->mainLobby;
this->server->Shutdown(); this->server->Shutdown();
delete this->server; delete this->server;
@ -126,6 +127,11 @@ namespace DanBias
return DanBiasServerReturn_Sucess; return DanBiasServerReturn_Sucess;
} }
NetworkSession* GameServer::MainLobbyInstance()
{
return GameServer::instance->mainLobby;
}
bool GameServer::LoadIniFile(InitData& ini) bool GameServer::LoadIniFile(InitData& ini)
{ {
std::ifstream in; std::ifstream in;

View File

@ -21,6 +21,8 @@ namespace DanBias
DanBiasServerReturn Run(); DanBiasServerReturn Run();
DanBiasServerReturn Release(); DanBiasServerReturn Release();
static NetworkSession* MainLobbyInstance();
private: private:
//static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient); //static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient);
void NetworkCallback(Oyster::Network::NetworkClient* client) override; void NetworkCallback(Oyster::Network::NetworkClient* client) override;
@ -31,6 +33,7 @@ namespace DanBias
int maxClients; int maxClients;
MainLobby *mainLobby; MainLobby *mainLobby;
Oyster::Network::NetworkServer *server; Oyster::Network::NetworkServer *server;
static GameServer* instance;
private: private:
struct InitData struct InitData

View File

@ -4,16 +4,21 @@
#include "GameClient.h" #include "GameClient.h"
#include "..\LobbySessions\NetworkSession.h" #include "..\LobbySessions\NetworkSession.h"
#include <GameProtocols.h> #include <Game.h>
#include <Protocols.h>
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
using namespace DanBias; using namespace DanBias;
using namespace GameLogic;
GameClient::GameClient(SmartPointer<LobbyClient> client, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value) static int gameClientIDCount = 1;
GameClient::GameClient(SmartPointer<LobbyClient> client, Game::PlayerData* player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
{ {
this->callbackValue = value; this->callbackValue = value;
this->client = client; this->client = client;
this->player = new GameLogic::Player(); this->id = gameClientIDCount++;
this->player = player;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c; Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.callbackType = Oyster::Callback::CallbackType_Object; c.callbackType = Oyster::Callback::CallbackType_Object;
c.value = this; c.value = this;
@ -22,8 +27,9 @@ GameClient::GameClient(SmartPointer<LobbyClient> client, Oyster::Callback::Oyste
} }
GameClient::~GameClient() GameClient::~GameClient()
{ {
this->client->Disconnect(); if(this->client) this->client->Disconnect();
this->player.Release(); this->player = 0;
this->id = -1;
} }
void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value) void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
@ -31,15 +37,30 @@ void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSessi
this->callbackValue = value; this->callbackValue = value;
} }
GameLogic::Player* GameClient::GetPlayer() GameLogic::Game::PlayerData* GameClient::GetPlayer()
{ {
return this->player.Get(); return this->player;
} }
LobbyClient* GameClient::GetClient() GameLogic::Game::PlayerData* GameClient::ReleasePlayer()
{
GameLogic::Game::PlayerData *temp = this->player;
this->player = 0;
return temp;
}
LobbyClient* GameClient::GetClient() const
{ {
return this->client; return this->client;
} }
Utility::DynamicMemory::SmartPointer<LobbyClient> GameClient::ReleaseClient()
{
SmartPointer<LobbyClient> temp = this->client;
this->client = 0;
return temp;
}
int GameClient::GetID() const
{
return this->id;
}
void GameClient::ObjectCallback(NetworkSession::NetEvent e) void GameClient::ObjectCallback(NetworkSession::NetEvent e)
{ {
e.gameClient = this; e.gameClient = this;

View File

@ -6,26 +6,33 @@
#include "..\LobbySessions\LobbyClient.h" #include "..\LobbySessions\LobbyClient.h"
#include <PostBox\PostBox.h> #include <PostBox\PostBox.h>
#include <Player.h> #include <Game.h>
namespace DanBias namespace DanBias
{ {
class GameClient: Oyster::Callback::CallbackObject<void, NetworkSession::NetEvent> class GameClient: Oyster::Callback::CallbackObject<void, NetworkSession::NetEvent>
{ {
public: public:
GameClient(Utility::DynamicMemory::SmartPointer<LobbyClient> client, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value); GameClient(Utility::DynamicMemory::SmartPointer<LobbyClient> client, GameLogic::Game::PlayerData* player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
virtual~GameClient(); virtual~GameClient();
void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value); void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
GameLogic::Player* GetPlayer(); /* */
LobbyClient* GetClient(); GameLogic::Game::PlayerData* GetPlayer();
GameLogic::Game::PlayerData* ReleasePlayer();
LobbyClient* GetClient() const;
Utility::DynamicMemory::SmartPointer<LobbyClient> ReleaseClient();
int GetID() const;
private: private:
Utility::DynamicMemory::SmartPointer<GameLogic::Player> player; //Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
GameLogic::Game::PlayerData* player;
Utility::DynamicMemory::SmartPointer<LobbyClient> client; Utility::DynamicMemory::SmartPointer<LobbyClient> client;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue; Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue;
int id;
void ObjectCallback(NetworkSession::NetEvent) override; void ObjectCallback(NetworkSession::NetEvent) override;
private: private:

View File

@ -1,319 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
void InsertObject(DynamicArray<SmartPointer<GameClient>>& clients, SmartPointer<GameClient> obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(!clients[i])
{
clients[i] = obj;
return;
}
}
}
void RemoveObject(DynamicArray<SmartPointer<GameClient>>& clients, DanBias::GameClient* obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(clients[i] && clients[i]->GetClient()->GetID() == obj->GetClient()->GetID())
{
clients[i] = 0;
return;
}
}
}
GameSession::GameSession()
{
this->owner = 0;
this->box = 0;
this->isCreated = false;
this->isRunning = false;
}
GameSession::~GameSession()
{
delete this->box;
this->box = 0;
this->owner = 0;
}
bool GameSession::Create(GameDescription& desc)
{
if(desc.clients.Size() == 0) return false;
if(!desc.owner) return false;
if(!desc.mapName.size()) return false;
if(this->isCreated) return false;
this->clients.Resize(desc.clients.Size());
this->box = new PostBox<NetworkSession::NetEvent>();
this->owner = desc.owner;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
this->clients[i] = new GameClient(desc.clients[i], c);
}
this->isCreated = true;
return true;
}
void GameSession::Run()
{
if(this->isRunning) return;
if(this->clients.Size() > 0)
{
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return;
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2);
this->isRunning = true;
}
}
bool GameSession::Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client)
{
if(!this->isCreated) return false;
Oyster::Callback::OysterCallback<void, DanBias::NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
SmartPointer<GameClient> obj = new GameClient(client, c);
InsertObject(this->clients, obj);
return true;
}
void GameSession::CloseSession(bool dissconnectClients)
{
this->worker.Stop(false);
//NetworkSession::CloseSession(dissconnectClients);
this->isCreated = false;
this->isRunning = false;
}
////private: //overriden Threading functions
bool GameSession::DoWork ( )
{
this->Frame();
return true;
}
#ifndef ERIK
////private:
void GameSession::Frame()
{
this->ParseEvents();
if(GetAsyncKeyState(VK_UP))
{
Protocol_General_Status p(Protocol_General_Status::States_ready);
Send(p.GetProtocol());
Sleep(100);
}
}
void GameSession::ParseEvents()
{
if( !this->box->IsEmpty() )
{
NetworkSession::NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGameplayEvent(e.protocol, e.gameClient);
if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGeneralEvent(e.protocol, e.gameClient);
}
}
void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
{
if(p[1].value.netBool) //bool bForward;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
//Oyster::Math::Float4x4 p;
Protocol_ObjectPosition op;//(c.GetPlayer()->GetRigidBody(), c.GetPlayer()->GetID());
//op.object_ID = c.GetPlayer()->GetID();
Send(op.GetProtocol());
}
break;
case protocol_Gameplay_PlayerMouseMovement:
break;
case protocol_Gameplay_PlayerPosition:
break;
case protocol_Gameplay_CreateObject:
break;
case protocol_Gameplay_ObjectPosition:
break;
}
}
void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_General_Status:
switch (p[1].value.netInt)
{
case GameLogic::Protocol_General_Status::States_bussy:
break;
case GameLogic::Protocol_General_Status::States_disconected:
printf("Client with ID [%i] dissconnected", c->GetClient()->GetID());
RemoveObject(this->clients, c);
break;
case GameLogic::Protocol_General_Status::States_idle:
break;
case GameLogic::Protocol_General_Status::States_ready:
break;
}
break;
case protocol_General_Text:
break;
}
}
void GameSession::Send(Oyster::Network::CustomNetProtocol* p)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i] && this->clients[i]->GetClient())
this->clients[i]->GetClient()->Send(p);
}
}
#else
#include "DynamicObject.h"
//#include "CollisionManager.h"
//#include "GameLogicStates.h"
//#include <GameProtocols.h>
/*
using namespace GameLogic;
//VARIABLES GOES HERE
DynamicObject* objectBox;
bool GameSession::Init(GameSessionDescription& desc)
{
if(desc.clients.Size() == 0) return false;
this->box = new PostBox<NetEvent>();
this->owner = desc.owner;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
desc.clients[i]->SetPostbox(this->box);
this->clients.Push(desc.clients[i]);
}
CollisionManager::BoxCollision(0,0);
objectBox = new DynamicObject(CollisionManager::BoxCollision, OBJECT_TYPE::OBJECT_TYPE_BOX);
Protocol_CreateObject objectCreation;
objectCreation.object_ID = objectBox->GetID();
objectCreation.path = "crate";
Oyster::Math::Float4x4 worldMat = objectBox->GetRigidBody()->GetOrientation();
for (int i = 0; i < 16; i++)
{
objectCreation.worldMatrix[i] = worldMat[i];
}
for (int i = 0; i < clients.Size(); i++)
{
clients[i]->NetClient_Object()->Send(objectCreation);
}
return true;
}
void GameSession::Frame()
{
}
void GameSession::ParseEvents()
{
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
ParseProtocol(e.protocol, *e.reciever);
}
}
void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c)
{
switch (p[0].value.netShort)
{
case protocol_Gamplay_PlayerNavigation:
{
if(p[1].value.netBool) //bool bForward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
}
break;
case protocol_Gamplay_PlayerMouseMovement:
break;
case protocol_Gamplay_PlayerPosition:
break;
case protocol_Gamplay_CreateObject:
break;
case protocol_Gamplay_ObjectPosition:
break;
}
}
*/
#endif
}//End namespace DanBias

View File

@ -4,12 +4,15 @@
#ifndef DANBIASSERVER_GAME_SESSION_H #ifndef DANBIASSERVER_GAME_SESSION_H
#define DANBIASSERVER_GAME_SESSION_H #define DANBIASSERVER_GAME_SESSION_H
//warning C4150: deletion of pointer to incomplete type, no destructor called //warning C4150: deletion of pointer to incomplete type, no destructor called, because of forward decleration and the use of smartpointer.
#pragma warning(disable: 4150) #pragma warning(disable: 4150)
#include "..\LobbySessions\NetworkSession.h" #include "..\LobbySessions\NetworkSession.h"
#include <WinTimer.h>
#include <PostBox\IPostBox.h> #include <PostBox\IPostBox.h>
#include <Thread\OysterThread.h> #include <Thread\OysterThread.h>
#include <Game.h>
#include <Queue.h>
namespace DanBias namespace DanBias
{ {
@ -18,6 +21,9 @@ namespace DanBias
class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession
{ {
public: public:
/**
* A container to use when initiating a new session
*/
struct GameDescription struct GameDescription
{ {
std::wstring mapName; std::wstring mapName;
@ -25,6 +31,19 @@ namespace DanBias
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients; Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
}; };
struct GameSessionEvent
{
union EventData
{
GameLogic::Game::PlayerData* player;
} data;
enum EventType
{
EventType_Player,
EventType_DynamicObject,
} value;
};
public: public:
GameSession(); GameSession();
virtual~GameSession(); virtual~GameSession();
@ -41,33 +60,48 @@ namespace DanBias
bool Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client); bool Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client);
/** /**
* * Closes the game session
* @param disconnectClients If set to true clients is dissconnected from the server, if false the clients is sent to the given owner of the session.
*/ */
void CloseSession(bool dissconnectClients = false); void CloseSession(bool disconnectClients = false);
inline bool IsCreated() const { return this->isCreated; } inline bool IsCreated() const { return this->isCreated; }
inline bool IsRunning() const { return this->isRunning; } inline bool IsRunning() const { return this->isRunning; }
//Private member functions
private: private:
void Frame(); //Handles all events recieved
void ParseEvents(); void ParseEvents();
//Handles all gameplay events
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c); void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Handles all general events
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c); void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Adds a client to the client list
void AddClient(Utility::DynamicMemory::SmartPointer<GameClient> obj);
//Removes a client from the client list
void RemoveClient(DanBias::GameClient* obj);
//Sends a protocol ta all clients in session
void Send(Oyster::Network::CustomNetProtocol* p); void Send(Oyster::Network::CustomNetProtocol* p);
//Frame function, derived from IThreadObject
private: //overriden Threading functions
bool DoWork ( ) override; bool DoWork ( ) override;
//Sends a client to the owner, if obj is NULL then all clients is sent
void SendToOwner(DanBias::GameClient* obj);
//Do a cleanup on all the private data
void Clean();
//Update game objects if needed
void UpdateGameObjects();
//Private member variables
private: private:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients; Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
NetworkSession* owner;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box; Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker; Oyster::Thread::OysterThread worker;
GameLogic::Game gameInstance;
NetworkSession* owner;
bool isCreated; bool isCreated;
bool isRunning; bool isRunning;
Utility::Container::Queue<GameSessionEvent> modifiedClient;
private: private:
friend class AdminInterface; friend class AdminInterface;

View File

@ -78,7 +78,7 @@ bool GameSessionManager::StartSession(int session)
bool GameSessionManager::JoinSession(int session, Utility::DynamicMemory::SmartPointer<LobbyClient> client) bool GameSessionManager::JoinSession(int session, Utility::DynamicMemory::SmartPointer<LobbyClient> client)
{ {
int i = -1; int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return false; if((i = gameSessionData.Existst(session)) == -1) return false;
gameSessionData.sessions[i]->Join(client); gameSessionData.sessions[i]->Join(client);
@ -97,6 +97,13 @@ void GameSessionManager::GetSessionInfo(int session, GameSessionInfo& data)
//data.numberOfPlayers = gameSessionData.sessions[i]-> //data.numberOfPlayers = gameSessionData.sessions[i]->
} }
void GameSessionManager::CloseSession()
{
for (unsigned int i = 0; i < gameSessionData.sessions.Size(); i++)
{
gameSessionData.sessions[i]->CloseSession();
}
}
void GameSessionManager::CloseSession(int session) void GameSessionManager::CloseSession(int session)
{ {
int i = -1; int i = -1;

View File

@ -64,6 +64,11 @@ namespace DanBias
*/ */
static void CloseSession(int session); static void CloseSession(int session);
/**
* Close all sessions.
*/
static void CloseSession();
/** /**
* Get total sessions running * Get total sessions running
* @return Returns the total sessions curently running. * @return Returns the total sessions curently running.

View File

@ -0,0 +1,120 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <Protocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <OysterMath.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
void GameSession::ParseEvents()
{
if( !this->box->IsEmpty() )
{
NetworkSession::NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGameplayEvent(e.protocol, e.gameClient);
if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGeneralEvent(e.protocol, e.gameClient);
}
}
void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
GameSessionEvent e;
e.data.player = c->GetPlayer();
e.value = GameSessionEvent::EventType_Player;
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
{
//Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity;
if(p[1].value.netBool) //bool bForward;
//world.v[3].x = 2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
//world.v[3].x = -2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
//world.v[3].y = 2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
//world.v[3].y = -2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
}
break;
case protocol_Gameplay_PlayerMouseMovement:
break;
case protocol_Gameplay_PlayerPosition:
break;
case protocol_Gameplay_CreateObject:
break;
case protocol_Gameplay_ObjectPosition:
break;
}
this->modifiedClient.Push(e);
}
void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_General_Status:
switch (p[1].value.netInt)
{
case GameLogic::Protocol_General_Status::States_bussy:
break;
case GameLogic::Protocol_General_Status::States_disconected:
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
this->RemoveClient(c);
break;
case GameLogic::Protocol_General_Status::States_idle:
break;
case GameLogic::Protocol_General_Status::States_ready:
break;
}
break;
case protocol_General_Text:
break;
}
}
}//End namespace DanBias

View File

@ -0,0 +1,170 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include "..\GameServer.h"
#include <Protocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
GameSession::GameSession()
{
this->owner = 0;
this->box = 0;
this->isCreated = false;
this->isRunning = false;
}
GameSession::~GameSession()
{
delete this->box;
this->box = 0;
this->owner = 0;
}
bool GameSession::Create(GameDescription& desc)
{
if(desc.clients.Size() == 0) return false;
if(!desc.owner) return false;
if(!desc.mapName.size()) return false;
if(this->isCreated) return false;
this->clients.Resize(desc.clients.Size());
this->box = new PostBox<NetworkSession::NetEvent>();
this->owner = desc.owner;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
this->clients[i] = new GameClient(desc.clients[i], gameInstance.CreatePlayer(), c);
}
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return false;
this->isCreated = true;
return true;
}
void GameSession::Run()
{
if(this->isRunning) return;
if(this->clients.Size() > 0)
{
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2);
this->isRunning = true;
}
}
bool GameSession::Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client)
{
if(!this->isCreated) return false;
Oyster::Callback::OysterCallback<void, DanBias::NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
SmartPointer<GameClient> obj = new GameClient(client, this->gameInstance.CreatePlayer(), c);
AddClient(obj);
return true;
}
void GameSession::CloseSession(bool dissconnectClients)
{
if(dissconnectClients)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->GetClient()->Disconnect();
}
}
else
{
this->SendToOwner(0); //Send all clients to the current owner
}
this->Clean();
}
void GameSession::AddClient(SmartPointer<GameClient> obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(!clients[i])
{
clients[i] = obj;
return;
}
}
clients.Push(obj);
}
void GameSession::RemoveClient(DanBias::GameClient* obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(clients[i] && clients[i]->GetID() == obj->GetID())
{
clients[i] = 0;
return;
}
}
}
void GameSession::SendToOwner(DanBias::GameClient* obj)
{
DanBias::NetworkSession *s = GameServer::MainLobbyInstance();
if(this->owner) s = this->owner;
if(obj)
{
s->Attach(obj->ReleaseClient());
RemoveClient(obj);
}
else
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i])
{
s->Attach(this->clients[i]->ReleaseClient());
RemoveClient(this->clients[i]);
}
}
}
}
void GameSession::Clean()
{
this->worker.Terminate();
this->clients.Clear();
delete this->box;
this->box = 0;
this->gameInstance;
this->owner = 0;
this->isCreated = false;
this->isRunning = false;
}
}//End namespace DanBias

View File

@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <Protocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
#include <OysterMath.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
bool GameSession::DoWork( )
{
if(GetAsyncKeyState(VK_UP))
{
Protocol_General_Status p(Protocol_General_Status::States_ready);
Send(p.GetProtocol());
Sleep(100);
}
if(GetAsyncKeyState(VK_DOWN))
{
Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity;
Protocol_CreateObject p(world, 2, "../Content/crate");
Send(p.GetProtocol());
Sleep(100);
}
this->ParseEvents();
this->gameInstance.NewFrame();
this->UpdateGameObjects();
return this->isRunning;
}
void GameSession::UpdateGameObjects()
{
while(!this->modifiedClient.IsEmpty())
{
//There is something that needs update
GameSessionEvent e = this->modifiedClient.Pop();
switch (e.value)
{
case GameSessionEvent::EventType_Player:
//e.data.player->GetOrientation();
break;
}
}
if(clients.Size() == 1)
{
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
Protocol_ObjectPosition p(world, 1);
Send(p.GetProtocol());
Sleep(100);
}
}
}//End namespace DanBias

View File

@ -0,0 +1,29 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <Protocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
void GameSession::Send(Oyster::Network::CustomNetProtocol* p)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i] && this->clients[i]->GetClient())
this->clients[i]->GetClient()->Send(p);
}
}
}//End namespace DanBias

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_LEVELMANAGER_H #ifndef DANBIASSERVER_LEVELMANAGER_H
#define DANBIASSERVER_LEVELMANAGER_H #define DANBIASSERVER_LEVELMANAGER_H

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_INETWORKSESSION_H #ifndef DANBIASSERVER_INETWORKSESSION_H
#define DANBIASSERVER_INETWORKSESSION_H #define DANBIASSERVER_INETWORKSESSION_H

View File

@ -1,5 +1,5 @@
#include "LobbyClient.h" #include "LobbyClient.h"
#include <GameProtocols.h> #include <Protocols.h>
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
using namespace Oyster::Network; using namespace Oyster::Network;

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_LOBBYCLIENT_H #ifndef DANBIASSERVER_LOBBYCLIENT_H
#define DANBIASSERVER_LOBBYCLIENT_H #define DANBIASSERVER_LOBBYCLIENT_H

View File

@ -19,11 +19,12 @@ namespace DanBias
} }
MainLobby::~MainLobby() MainLobby::~MainLobby()
{ {
delete this->box;
this->box = 0;
} }
void MainLobby::Release() void MainLobby::Release()
{ {
delete this->box;
this->box = 0;
this->CloseSession(true); this->CloseSession(true);
} }

View File

@ -6,7 +6,7 @@
#include "NetworkSession.h" #include "NetworkSession.h"
#include "GameLobby.h" #include "GameLobby.h"
#include <GameProtocols.h> #include <Protocols.h>
#include <PostBox\IPostBox.h> #include <PostBox\IPostBox.h>
namespace DanBias namespace DanBias

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Launcher to launch Danbias server or client // // Launcher to launch Danbias server //
// Created by [Dennis Andersen] [2013] // // Created by [Dennis Andersen] [2013] //
////////////////////////////////////////////////// //////////////////////////////////////////////////
#define NOMINMAX //Blame it on windows #define NOMINMAX //Blame it on windows

View File

@ -39,16 +39,16 @@ AttatchmentMassDriver::~AttatchmentMassDriver(void)
/******************************************************** /********************************************************
* Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used * Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used
********************************************************/ ********************************************************/
void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput) void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage)
{ {
//switch case to determin what functionallity to use in the attatchment //switch case to determin what functionallity to use in the attatchment
switch (fireInput) switch (usage)
{ {
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
ForcePush(fireInput); ForcePush(usage);
break; break;
case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS:
ForcePull(fireInput); ForcePull(usage);
break; break;
} }
@ -57,7 +57,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInp
/******************************************************** /********************************************************
* Pushes objects in a cone in front of the weapon when fired * Pushes objects in a cone in front of the weapon when fired
********************************************************/ ********************************************************/
void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage)
{ {
//create coneRigidBody that will then collide with object and push them in the aimed direction //create coneRigidBody that will then collide with object and push them in the aimed direction
} }
@ -65,7 +65,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput)
/******************************************************** /********************************************************
* Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack) * Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack)
********************************************************/ ********************************************************/
void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &fireInput) void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage)
{ {
//Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100); //Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100);
} }

View File

@ -15,26 +15,26 @@ namespace GameLogic
~AttatchmentMassDriver(void); ~AttatchmentMassDriver(void);
void UseAttatchment(const WEAPON_FIRE &fireInput); void UseAttatchment(const WEAPON_FIRE &usage);
private: private:
/******************************************************** /********************************************************
* Pushes objects and players in a cone in front of the player * Pushes objects and players in a cone in front of the player
* @param fireInput: allows switching on different functionality in this specific function * @param fireInput: allows switching on different functionality in this specific function
********************************************************/ ********************************************************/
void ForcePush(const WEAPON_FIRE &fireInput); void ForcePush(const WEAPON_FIRE &usage);
/******************************************************** /********************************************************
* Pulls the player forward, this is a movement tool * Pulls the player forward, this is a movement tool
* @param fireInput: allows switching on different functionality in this specific function * @param fireInput: allows switching on different functionality in this specific function
********************************************************/ ********************************************************/
void ForcePull(const WEAPON_FIRE &fireInput); void ForcePull(const WEAPON_FIRE &usage);
/******************************************************** /********************************************************
* Sucks objects towards the player, the player can then pick up an object and throw it as a projectile * Sucks objects towards the player, the player can then pick up an object and throw it as a projectile
* @param fireInput: allows switching on different functionality in this specific function * @param fireInput: allows switching on different functionality in this specific function
********************************************************/ ********************************************************/
void ForceSuck(const WEAPON_FIRE &fireInput); void ForceSuck(const WEAPON_FIRE &usage);
private: private:
struct PrivateData; struct PrivateData;

View File

@ -1,6 +1,9 @@
#include "AttatchmentSocket.h" #include "AttatchmentSocket.h"
#include "IAttatchment.h" #include "IAttatchment.h"
#include "DynamicArray.h"
using namespace GameLogic; using namespace GameLogic;
using namespace Utility::DynamicMemory;
struct AttatchmentSocket::PrivateData struct AttatchmentSocket::PrivateData
{ {
@ -14,7 +17,7 @@ struct AttatchmentSocket::PrivateData
} }
IAttatchment *attatchment; SmartPointer<IAttatchment> attatchment;
}myData; }myData;
@ -26,10 +29,7 @@ AttatchmentSocket::AttatchmentSocket(void)
AttatchmentSocket::~AttatchmentSocket(void) AttatchmentSocket::~AttatchmentSocket(void)
{ {
if (myData->attatchment)
{
delete myData->attatchment;
}
} }
IAttatchment* AttatchmentSocket::GetAttatchment() IAttatchment* AttatchmentSocket::GetAttatchment()
@ -39,18 +39,12 @@ IAttatchment* AttatchmentSocket::GetAttatchment()
void AttatchmentSocket::SetAttatchment(IAttatchment *attatchment) void AttatchmentSocket::SetAttatchment(IAttatchment *attatchment)
{ {
if (myData->attatchment)
{
delete myData->attatchment;
}
myData->attatchment = attatchment; myData->attatchment = attatchment;
} }
void AttatchmentSocket::RemoveAttatchment() void AttatchmentSocket::RemoveAttatchment()
{ {
if (myData->attatchment)
{ myData->attatchment = 0;
delete myData->attatchment;
}
} }

View File

@ -55,3 +55,8 @@ using namespace GameLogic;
return Physics::ICustomBody::SubscriptMessage_none; return Physics::ICustomBody::SubscriptMessage_none;
} }
Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj)
{
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
}

View File

@ -14,7 +14,7 @@ namespace GameLogic
//typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); //typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj);
static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj);
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj);
//these are the specific collision case functions //these are the specific collision case functions
//void PlayerVBox(Player &player, DynamicObject &box); //void PlayerVBox(Player &player, DynamicObject &box);
//void BoxVBox(DynamicObject &box1, DynamicObject &box2); //void BoxVBox(DynamicObject &box1, DynamicObject &box2);

View File

@ -9,9 +9,7 @@
namespace GameLogic namespace GameLogic
{ {
class DynamicObject : public Object
class DANBIAS_GAMELOGIC_DLL DynamicObject : public Object
{ {
public: public:

View File

@ -0,0 +1,129 @@
#include "Game.h"
#include "Player.h"
#include "Level.h"
#include <DynamicArray.h>
#include <GID.h>
#include <PhysicsAPI.h>
#include <WinTimer.h>
using namespace GameLogic;
using namespace Utility::DynamicMemory;
using namespace Oyster::Physics;
#define DELTA_TIME 0.01666666666666666666666666666667f
template<typename T>
int InsertObject(DynamicArray<T*>& list, T* obj)
{
for (unsigned int i = 0; i < list.Size(); i++)
{
if(!list[i])
{
list[i] = obj;
return i;
}
}
list.Push(obj);
return list.Size() - 1;
}
template<typename T>
int RemoveObject(DynamicArray<T*>& list, T* obj)
{
for (unsigned int i = 0; i < list.Size(); i++)
{
if(!list[i])
{
list[i] = obj;
return i;
}
}
list.Push(obj);
return list.Size() - 1;
}
struct Game::PrivateData
{
PrivateData()
{ }
~PrivateData()
{
for (unsigned int i = 0; i < players.Size(); i++)
{
this->players[i]->player = 0;
}
}
DynamicArray<PlayerData*> players;
LevelData* level;
Utility::WinTimer timer;
}myData;
Game::Game(void)
{
myData = new PrivateData();
}
Game::~Game(void)
{
if(myData)
{
delete myData;
}
}
void Game::GetAllPlayerPositions() const
{
}
Game::PlayerData* Game::CreatePlayer()
{
Player *newPlayer = new Player();
PlayerData *newPdata = new PlayerData();
newPdata->player = newPlayer;
int id = InsertObject(this->myData->players, newPdata);
return this->myData->players[id];
}
Game::LevelData* Game::CreateLevel()
{
Level *newLevel = new Level();
newLevel->InitiateLevel(1000);
LevelData *newLdata = new LevelData();
newLdata->level = newLevel;
myData->level = newLdata;
return myData->level;
}
void Game::CreateTeam()
{
}
void Game::NewFrame()
{
double dt = this->myData->timer.getElapsedSeconds();
//60 fps sec is currently staticly
if(dt >= DELTA_TIME)
{
for (int i = 0; i < this->myData->players.Size(); i++)
{
if(this->myData->players[i]->player)
this->myData->players[i]->player->BeginFrame();
}
API::Instance().Update();
for (int i = 0; i < this->myData->players.Size(); i++)
{
if(this->myData->players[i]->player)
this->myData->players[i]->player->EndFrame();
}
this->myData->timer.reset();
}
}

119
Code/Game/GameLogic/Game.h Normal file
View File

@ -0,0 +1,119 @@
/////////////////////////////////////////////////////////////////////
// Created by [Erik Persson] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef GAME_H
#define GAME_H
#include "GameLogicDef.h"
#include "GameLogicStates.h"
#include <OysterMath.h>
namespace GameLogic
{
class Player;
class Level;
class DANBIAS_GAMELOGIC_DLL Game
{
public:
struct DANBIAS_GAMELOGIC_DLL PlayerData
{
private:
friend class Game;
Player *player;
PlayerData();
PlayerData(int playerID,int teamID);
~PlayerData();
public:
/********************************************************
* Moves the chosen player based on input
* @param playerID: ID of the player you want to recieve the message
* @param movement: enum value on what kind of action is to be taken
********************************************************/
void Move(const PLAYER_MOVEMENT &movement);
/********************************************************
* Uses the chosen players weapon based on input
* @param playerID: ID of the player you want to recieve the message
* @param Usage: enum value on what kind of action is to be taken
********************************************************/
void UseWeapon(int playerID, const WEAPON_FIRE &usage);
/********************************************************
* Gets players position
* @param playerID: ID of the player whos position you want
********************************************************/
Oyster::Math::Float3 GetPosition();
/********************************************************
* Gets players current orientation
* @param playerID: ID of the player whos position you want
********************************************************/
Oyster::Math::Float4x4 GetOrientation();
/********************************************************
* Check player state
* @return The current player state
********************************************************/
PLAYER_STATE GetState() const;
/***/
int GetID() const;
/***/
int GetTeamID() const;
};
struct DANBIAS_GAMELOGIC_DLL LevelData
{
private:
friend class Game;
Level *level;
LevelData();
~LevelData();
public:
};
public:
Game(void);
~Game(void);
/********************************************************
* Gets the position of all players currently in the game
********************************************************/
void GetAllPlayerPositions() const;
/********************************************************
* Creates a player and returns PlayerData
********************************************************/
PlayerData* CreatePlayer();
/********************************************************
* Creates a level and returns LevelData
********************************************************/
LevelData* CreateLevel();
/********************************************************
* Creates a team
********************************************************/
void CreateTeam();
/********************************************************
* Runs a update of the gamelogic and physics
********************************************************/
void NewFrame();
private:
struct PrivateData;
PrivateData *myData;
};
}
#endif

View File

@ -173,6 +173,7 @@
<ClInclude Include="AttatchmentSocket.h" /> <ClInclude Include="AttatchmentSocket.h" />
<ClInclude Include="CollisionManager.h" /> <ClInclude Include="CollisionManager.h" />
<ClInclude Include="DynamicObject.h" /> <ClInclude Include="DynamicObject.h" />
<ClInclude Include="Game.h" />
<ClInclude Include="GameLogicDef.h" /> <ClInclude Include="GameLogicDef.h" />
<ClInclude Include="GameLogicStates.h" /> <ClInclude Include="GameLogicStates.h" />
<ClInclude Include="GameMode.h" /> <ClInclude Include="GameMode.h" />
@ -190,7 +191,10 @@
<ClCompile Include="AttatchmentSocket.cpp" /> <ClCompile Include="AttatchmentSocket.cpp" />
<ClCompile Include="CollisionManager.cpp" /> <ClCompile Include="CollisionManager.cpp" />
<ClCompile Include="DynamicObject.cpp" /> <ClCompile Include="DynamicObject.cpp" />
<ClCompile Include="Game.cpp" />
<ClCompile Include="GameMode.cpp" /> <ClCompile Include="GameMode.cpp" />
<ClCompile Include="Game_LevelData.cpp" />
<ClCompile Include="Game_PlayerData.cpp" />
<ClCompile Include="IAttatchment.cpp" /> <ClCompile Include="IAttatchment.cpp" />
<ClCompile Include="Level.cpp" /> <ClCompile Include="Level.cpp" />
<ClCompile Include="Object.cpp" /> <ClCompile Include="Object.cpp" />

View File

@ -16,6 +16,8 @@ namespace GameLogic
PLAYER_STATE_JUMPING = 0, PLAYER_STATE_JUMPING = 0,
PLAYER_STATE_WALKING = 1, PLAYER_STATE_WALKING = 1,
PLAYER_STATE_IDLE = 2, PLAYER_STATE_IDLE = 2,
PLAYER_STATE_DEAD = 4,
PLAYER_STATE_INVALID = 8,
}; };
enum OBJECT_TYPE enum OBJECT_TYPE
@ -37,7 +39,7 @@ namespace GameLogic
enum WEAPON_STATE enum WEAPON_STATE
{ {
WEAPON_STATE_FIREING = 0, WEAPON_STATE_FIRING = 0,
WEAPON_STATE_IDLE = 1, WEAPON_STATE_IDLE = 1,
WEAPON_STATE_RELOADING = 2, WEAPON_STATE_RELOADING = 2,
}; };

View File

@ -0,0 +1,14 @@
#include "Game.h"
#include "Level.h"
using namespace GameLogic;
Game::LevelData::LevelData()
{
}
Game::LevelData::~LevelData()
{
}

View File

@ -0,0 +1,46 @@
#include "Game.h"
#include "Player.h"
using namespace GameLogic;
Game::PlayerData::PlayerData()
{
}
Game::PlayerData::PlayerData(int playerID,int teamID)
{
}
Game::PlayerData::~PlayerData()
{
}
void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement)
{
this->player->Move(movement);
}
void Game::PlayerData::UseWeapon(int playerID, const WEAPON_FIRE &usage)
{
}
Oyster::Math::Float3 Game::PlayerData::GetPosition()
{
return this->player->GetPosition();
}
Oyster::Math::Float4x4 Game::PlayerData::GetOrientation()
{
return this->player->GetOrientation();
}
PLAYER_STATE Game::PlayerData::GetState() const
{
return this->player->GetState();
}
int Game::PlayerData::GetID() const
{
return this->player->GetID();
}
int Game::PlayerData::GetTeamID() const
{
return this->player->GetTeamID();
}

View File

@ -19,7 +19,7 @@ namespace GameLogic
IAttatchment(void); IAttatchment(void);
~IAttatchment(void); ~IAttatchment(void);
virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0; virtual void UseAttatchment(const WEAPON_FIRE &usage) = 0;
private: private:

View File

@ -5,8 +5,11 @@
#include "Player.h" #include "Player.h"
#include "PhysicsAPI.h" #include "PhysicsAPI.h"
#include "TeamManager.h" #include "TeamManager.h"
#include "DynamicArray.h"
using namespace GameLogic; using namespace GameLogic;
using namespace Utility::DynamicMemory;
using namespace Oyster::Physics;
struct Level::PrivateData struct Level::PrivateData
{ {
@ -18,17 +21,15 @@ struct Level::PrivateData
{ {
} }
TeamManager *teamManager; //SmartPointer<TeamManager> teamManager;
StaticObject** staticObjects; //DynamicArray<SmartPointer<StaticObject>> staticObjects;
int nrOfStaticObjects;
DynamicObject** dynamicObjects; //DynamicArray<SmartPointer<DynamicObject>> dynamicObjects;
int nrOfDynamicObjects;
GameMode* gameMode; //SmartPointer<GameMode> gameMode;
Oyster::Physics::ICustomBody *rigidBodyLevel; SmartPointer<ICustomBody> rigidBodyLevel;
}myData; }myData;
@ -46,21 +47,42 @@ Level::~Level(void)
void Level::InitiateLevel(std::string levelPath) void Level::InitiateLevel(std::string levelPath)
{ {
}
void Level::InitiateLevel(float radius)
{
API::SphericalBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
sbDesc.ignoreGravity = true;
sbDesc.radius = radius;
sbDesc.mass = 1e16; //10^16
sbDesc.subscription_onCollision = CollisionManager::LevelCollision;
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
API::Instance().AddObject(rigidBody);
API::Gravity gravityWell;
gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = (float)1e16;
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
API::Instance().AddGravity(gravityWell);
} }
void Level::AddPlayerToTeam(Player *player, int teamID) void Level::AddPlayerToTeam(Player *player, int teamID)
{ {
myData->teamManager->AddPlayerToTeam(player,teamID); //myData->teamManager->AddPlayerToTeam(player,teamID);
} }
void Level::CreateTeam(int teamSize) void Level::CreateTeam(int teamSize)
{ {
myData->teamManager->CreateTeam(teamSize); //myData->teamManager->CreateTeam(teamSize);
} }
void Level::RespawnPlayer(Player *player) void Level::RespawnPlayer(Player *player)
{ {
myData->teamManager->RespawnPlayerRandom(player); //myData->teamManager->RespawnPlayerRandom(player);
} }

View File

@ -21,6 +21,7 @@ namespace GameLogic
* @param levelPath: Path to a file that contains all information on the level * @param levelPath: Path to a file that contains all information on the level
********************************************************/ ********************************************************/
void InitiateLevel(std::string levelPath); void InitiateLevel(std::string levelPath);
void Level::InitiateLevel(float radius);
/******************************************************** /********************************************************
* Creates a team in the level * Creates a team in the level

View File

@ -16,7 +16,10 @@ Object::Object()
//sbDesc.centerPosition = //sbDesc.centerPosition =
//poi //poi
ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
//rigidBody->gameObjectRef = this; //rigidBody->gameObjectRef = this;
@ -33,6 +36,8 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
//poi //poi
ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
//rigidBody->gameObjectRef = this; //rigidBody->gameObjectRef = this;
@ -46,14 +51,13 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
Object::~Object(void) Object::~Object(void)
{ {
} }
OBJECT_TYPE Object::GetType() OBJECT_TYPE Object::GetType() const
{ {
return this->type; return this->type;
} }
int Object::GetID() int Object::GetID() const
{ {
return this->objectID; return this->objectID;
} }

View File

@ -8,26 +8,19 @@
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "GameLogicDef.h" #include <PhysicsAPI.h>
namespace Oyster
{
namespace Physics
{
class ICustomBody;
}
}
namespace GameLogic namespace GameLogic
{ {
class DANBIAS_GAMELOGIC_DLL Object class Object
{ {
public: public:
Object(); Object();
Object(void* collisionFunc, OBJECT_TYPE type); Object(void* collisionFunc, OBJECT_TYPE type);
~Object(void); ~Object(void);
OBJECT_TYPE GetType(); OBJECT_TYPE GetType() const;
int GetID(); int GetID() const;
Oyster::Physics::ICustomBody* GetRigidBody(); Oyster::Physics::ICustomBody* GetRigidBody();
@ -36,6 +29,9 @@ namespace GameLogic
int objectID; int objectID;
protected: protected:
Oyster::Physics::ICustomBody *rigidBody; Oyster::Physics::ICustomBody *rigidBody;
Oyster::Physics::ICustomBody::State setState;
Oyster::Physics::ICustomBody::State getState;
}; };
} }

View File

@ -1,56 +1,36 @@
#include "Player.h" #include "Player.h"
#include "OysterMath.h"
#include "CollisionManager.h"
#include "Weapon.h" #include "Weapon.h"
using namespace GameLogic; using namespace GameLogic;
using namespace Oyster::Physics; using namespace Oyster::Physics;
struct Player::PrivateData
{
PrivateData()
{
weapon = new Weapon();
life = 100;
teamID = -1;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float3(1,0,0);
}
~PrivateData()
{
if (weapon)
{
delete weapon;
}
}
int life;
int teamID;
Weapon *weapon;
PLAYER_STATE playerState;
Oyster::Math::Float3 lookDir;
}myData;
Player::Player() Player::Player()
:Object(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) :DynamicObject(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
{ {
myData = new PrivateData(); weapon = new Weapon();
life = 100;
teamID = -1;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float4(0,0,-1,0);
Oyster::Physics::ICustomBody::State state;
this->rigidBody->GetState( this->setState );
setState.SetLinearMomentum( Oyster::Math::Float4(20, 0, 0, 0) );
this->rigidBody->SetState( setState );
} }
Player::~Player(void) Player::~Player(void)
{ {
delete myData; delete weapon;
weapon = NULL;
} }
void Player::Move(const PLAYER_MOVEMENT &movement) void Player::Move(const PLAYER_MOVEMENT &movement)
{ {
//Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
switch(movement) switch(movement)
{ {
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD: case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD:
@ -77,73 +57,91 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward() void Player::MoveForward()
{ {
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100); setState.ApplyLinearImpulse(this->lookDir * 100);
} }
void Player::MoveBackwards() void Player::MoveBackwards()
{ {
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100); setState.ApplyLinearImpulse(-this->lookDir * 100);
} }
void Player::MoveRight() void Player::MoveRight()
{ {
//Do cross product with forward vector and negative gravity vector //Do cross product with forward vector and negative gravity vector
//Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross(myData->lookDir); Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100); //Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(r * 100);
} }
void Player::MoveLeft() void Player::MoveLeft()
{ {
//Do cross product with forward vector and negative gravity vector //Do cross product with forward vector and negative gravity vector
//Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross(myData->lookDir); Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100); //Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(-r * 100);
} }
void Player::UseWeapon(const WEAPON_FIRE &fireInput) void Player::UseWeapon(const WEAPON_FIRE &usage)
{ {
myData->weapon->Use(fireInput); this->weapon->Use(usage);
} }
void Player::Respawn(Oyster::Math::Float3 spawnPoint) void Player::Respawn(Oyster::Math::Float3 spawnPoint)
{ {
//API::Instance().SetCenter(rigidBody,spawnPoint);
myData->life = 100; this->life = 100;
myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
myData->lookDir = Oyster::Math::Float3(1,0,0); this->lookDir = Oyster::Math::Float4(1,0,0);
} }
void Player::Jump() void Player::Jump()
{ {
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
} }
bool Player::IsWalking() bool Player::IsWalking()
{ {
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_WALKING); return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING);
} }
bool Player::IsJumping() bool Player::IsJumping()
{ {
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING); return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING);
} }
bool Player::IsIdle() bool Player::IsIdle()
{ {
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
} }
Oyster::Math::Float3 Player::GetPos() Oyster::Math::Float3 Player::GetPosition() const
{ {
//return rigidBody->GetCenter(); return (Oyster::Math::Float3)getState.GetCenterPosition();
return Oyster::Math::Float3(0,0,0);
} }
Oyster::Math::Float4x4 Player::GetOrientation() const
Oyster::Math::Float3 Player::GetLookDir()
{ {
return myData->lookDir; return this->getState.GetOrientation();
} }
Oyster::Math::Float3 Player::GetLookDir() const
int Player::GetTeamID()
{ {
return myData->teamID; return this->lookDir.xyz;
}
int Player::GetTeamID() const
{
return this->teamID;
}
PLAYER_STATE Player::GetState() const
{
return this->playerState;
} }
void Player::DamageLife(int damage) void Player::DamageLife(int damage)
{ {
myData->life -= damage; this->life -= damage;
}
void Player::BeginFrame()
{
this->rigidBody->SetState(this->setState);
}
void Player::EndFrame()
{
this->rigidBody->GetState(this->getState);
this->setState = this->getState;
} }

View File

@ -3,17 +3,20 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
#ifndef PLAYER_H #ifndef PLAYER_H
#define PLAYER_H #define PLAYER_H
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "GameLogicDef.h"
#include "OysterMath.h" #include "OysterMath.h"
#include "Object.h" #include "DynamicObject.h"
#include "OysterMath.h"
#include "CollisionManager.h"
namespace GameLogic namespace GameLogic
{ {
class DANBIAS_GAMELOGIC_DLL Player : public Object class Weapon;
class Player : public DynamicObject
{ {
public: public:
Player(void); Player(void);
~Player(void); ~Player(void);
@ -33,7 +36,7 @@ namespace GameLogic
* Uses the weapon based on input * Uses the weapon based on input
* @param fireInput: enum value on what kind of action is to be taken * @param fireInput: enum value on what kind of action is to be taken
********************************************************/ ********************************************************/
void UseWeapon(const WEAPON_FIRE &fireInput); void UseWeapon(const WEAPON_FIRE &usage);
/******************************************************** /********************************************************
* Respawns the player, this resets several stats and settings on the player * Respawns the player, this resets several stats and settings on the player
@ -46,18 +49,28 @@ namespace GameLogic
bool IsJumping(); bool IsJumping();
bool IsIdle(); bool IsIdle();
Oyster::Math::Float3 GetPos(); Oyster::Math::Float3 GetPosition() const;
Oyster::Math::Float3 GetLookDir(); Oyster::Math::Float3 GetLookDir() const;
int GetTeamID(); Oyster::Math::Float4x4 GetOrientation() const;
int GetTeamID() const;
PLAYER_STATE GetState() const;
void DamageLife(int damage); void DamageLife(int damage);
private: //Do frame calculations
void BeginFrame();
void EndFrame();
void Jump();
private: private:
struct PrivateData; void Jump();
PrivateData *myData;
private:
int life;
int teamID;
Weapon *weapon;
PLAYER_STATE playerState;
Oyster::Math::Float4 lookDir;
}; };
} }
#endif #endif

View File

@ -54,7 +54,7 @@ void TeamManager::RespawnPlayerRandom(Player *player)
Player *respawnOnThis = myData->teams[teamID]->GetPlayer(0); Player *respawnOnThis = myData->teams[teamID]->GetPlayer(0);
player->Respawn(respawnOnThis->GetPos()); player->Respawn(respawnOnThis->GetPosition());
} }
void TeamManager::CreateTeam(int teamSize) void TeamManager::CreateTeam(int teamSize)

View File

@ -1,8 +1,10 @@
#include "Weapon.h" #include "Weapon.h"
#include "AttatchmentSocket.h" #include "AttatchmentSocket.h"
#include "AttatchmentMassDriver.h" #include "AttatchmentMassDriver.h"
#include "DynamicArray.h"
using namespace GameLogic; using namespace GameLogic;
using namespace Utility::DynamicMemory;
struct Weapon::PrivateData struct Weapon::PrivateData
{ {
@ -12,7 +14,6 @@ struct Weapon::PrivateData
selectedAttatchment = 0; selectedAttatchment = 0;
currentNrOfAttatchments = 0; currentNrOfAttatchments = 0;
selectedSocketID = 0; selectedSocketID = 0;
maxNrOfSockets = 0;
attatchmentSockets = 0; attatchmentSockets = 0;
} }
@ -22,11 +23,9 @@ struct Weapon::PrivateData
WEAPON_STATE weaponState; WEAPON_STATE weaponState;
AttatchmentSocket **attatchmentSockets; DynamicArray<SmartPointer<AttatchmentSocket>> attatchmentSockets;
int maxNrOfSockets;
int currentNrOfAttatchments; int currentNrOfAttatchments;
SmartPointer<IAttatchment> selectedAttatchment;
IAttatchment *selectedAttatchment;
int selectedSocketID; int selectedSocketID;
}myData; }myData;
@ -39,34 +38,23 @@ Weapon::Weapon()
Weapon::Weapon(int MaxNrOfSockets) Weapon::Weapon(int MaxNrOfSockets)
{ {
myData = new PrivateData(); myData = new PrivateData();
myData->maxNrOfSockets = MaxNrOfSockets; myData->attatchmentSockets.Resize(MaxNrOfSockets);
myData->attatchmentSockets = new AttatchmentSocket*[MaxNrOfSockets];
for (int i = 0; i < MaxNrOfSockets; i++)
{
myData->attatchmentSockets[i] = new AttatchmentSocket();
}
} }
Weapon::~Weapon(void) Weapon::~Weapon(void)
{ {
for (int i = 0; i < myData->currentNrOfAttatchments; i++)
{
delete myData->attatchmentSockets[i];
}
delete[] myData->attatchmentSockets;
delete myData; delete myData;
} }
/******************************************************** /********************************************************
* Uses the weapon based on the input given and the current chosen attatchment * Uses the weapon based on the input given and the current chosen attatchment
********************************************************/ ********************************************************/
void Weapon::Use(const WEAPON_FIRE &fireInput) void Weapon::Use(const WEAPON_FIRE &usage)
{ {
if (myData->selectedAttatchment) if (myData->selectedAttatchment)
{ {
myData->selectedAttatchment->UseAttatchment(fireInput); myData->selectedAttatchment->UseAttatchment(usage);
} }
} }
@ -80,7 +68,7 @@ void Weapon::Use(const WEAPON_FIRE &fireInput)
********************************************************/ ********************************************************/
bool Weapon::IsFireing() bool Weapon::IsFireing()
{ {
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIREING); return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
} }
bool Weapon::IsIdle() bool Weapon::IsIdle()
@ -95,7 +83,7 @@ bool Weapon::IsReloading()
bool Weapon::IsValidSocket(int socketID) bool Weapon::IsValidSocket(int socketID)
{ {
if(socketID < myData->maxNrOfSockets && socketID >= 0) if(socketID < myData->attatchmentSockets.Size() && socketID >= 0)
{ {
if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0) if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0)
{ {
@ -114,7 +102,7 @@ int Weapon::GetCurrentSocketID()
void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner) void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner)
{ {
if(myData->currentNrOfAttatchments < myData->maxNrOfSockets) if(myData->currentNrOfAttatchments < myData->attatchmentSockets.Size())
{ {
myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment); myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment);
myData->currentNrOfAttatchments++; myData->currentNrOfAttatchments++;

View File

@ -35,8 +35,6 @@ namespace GameLogic
int GetCurrentSocketID(); int GetCurrentSocketID();
private: private:
struct PrivateData; struct PrivateData;
PrivateData *myData; PrivateData *myData;

View File

@ -13,6 +13,7 @@ namespace GameLogic
States_ready, States_ready,
States_idle, States_idle,
States_bussy, States_bussy,
State_waiting,
States_disconected, States_disconected,
}; };
States status; States status;

View File

@ -155,7 +155,8 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ControlProtocols.h" /> <ClInclude Include="ControlProtocols.h" />
<ClInclude Include="GameProtocols.h" /> <ClInclude Include="GameplayProtocols.h" />
<ClInclude Include="Protocols.h" />
<ClInclude Include="LobbyProtocols.h" /> <ClInclude Include="LobbyProtocols.h" />
<ClInclude Include="ObjectProtocols.h" /> <ClInclude Include="ObjectProtocols.h" />
<ClInclude Include="PlayerProtocols.h" /> <ClInclude Include="PlayerProtocols.h" />

View File

@ -0,0 +1,63 @@
#ifndef GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H
#define GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H
#include <vector>
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
namespace GameLogic
{
struct Protocol_GameplayInitiateSession :public Oyster::Network::CustomProtocolObject
{
struct SessionInitData
{
int id;
int type;
//std::string text;
};
std::vector<SessionInitData> element;
Protocol_GameplayInitiateSession()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_Initiate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
}
Protocol_GameplayInitiateSession(Oyster::Network::CustomNetProtocol& p)
{
int size = p[1].value.netInt;
for (int i = 0; i < size; i++)
{
SessionInitData d = { p[i+2].value.netInt, p[i+3].value.netInt /*, p[i+4].value.netCharPtr */ };
element.push_back(d);
}
}
void Add(int id, int type, std::string text)
{
SessionInitData d = { id, type /*, text*/ };
element.push_back(d);
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
//Store the elements count
this->protocol[1].value = element.size();
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (unsigned int i = 0; i < element.size(); i+=3)
{
this->protocol[i+2].value = element[i].id;
this->protocol[i+3].value = element[i].type;
//element[i].text.copy(this->protocol[i+4].value.netCharPtr, element[i].text.size());
this->protocol[i+2].type = Oyster::Network::NetAttributeType_Int;
this->protocol[i+3].type = Oyster::Network::NetAttributeType_Int;
//this->protocol[i+4].type = Oyster::Network::NetAttributeType_CharArray;
}
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
}
#endif // !GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H

View File

@ -28,27 +28,47 @@ namespace GameLogic
this->protocol[i].type = Oyster::Network::NetAttributeType_Float; this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
} }
} }
Protocol_CreateObject(float m[16], int id, char *path)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_CreateObject;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray;
for (int i = 3; i <= 18; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = id;
this->path = path;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
}
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol* GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
this->protocol[2].value = path; this->protocol[2].value = path;
this->protocol[3].value = worldMatrix[1]; this->protocol[3].value = worldMatrix[0];
this->protocol[4].value = worldMatrix[2]; this->protocol[4].value = worldMatrix[1];
this->protocol[5].value = worldMatrix[3]; this->protocol[5].value = worldMatrix[2];
this->protocol[6].value = worldMatrix[4]; this->protocol[6].value = worldMatrix[3];
this->protocol[7].value = worldMatrix[5]; this->protocol[7].value = worldMatrix[4];
this->protocol[8].value = worldMatrix[6]; this->protocol[8].value = worldMatrix[5];
this->protocol[9].value = worldMatrix[7]; this->protocol[9].value = worldMatrix[6];
this->protocol[10].value = worldMatrix[8]; this->protocol[10].value = worldMatrix[7];
this->protocol[11].value = worldMatrix[9]; this->protocol[11].value = worldMatrix[8];
this->protocol[12].value = worldMatrix[10]; this->protocol[12].value = worldMatrix[9];
this->protocol[13].value = worldMatrix[11]; this->protocol[13].value = worldMatrix[10];
this->protocol[14].value = worldMatrix[12]; this->protocol[14].value = worldMatrix[11];
this->protocol[15].value = worldMatrix[13]; this->protocol[15].value = worldMatrix[12];
this->protocol[16].value = worldMatrix[14]; this->protocol[16].value = worldMatrix[13];
this->protocol[17].value = worldMatrix[15]; this->protocol[17].value = worldMatrix[14];
this->protocol[18].value = worldMatrix[16]; this->protocol[18].value = worldMatrix[15];
return &protocol; return &protocol;
} }

View File

@ -42,7 +42,7 @@ namespace GameLogic
bTurnLeft = val[3].value.netBool; bTurnLeft = val[3].value.netBool;
bTurnRight = val[4].value.netBool; bTurnRight = val[4].value.netBool;
bStrafeRight = val[5].value.netBool; bStrafeRight = val[5].value.netBool;
bStrafeRight = val[6].value.netBool; bStrafeLeft = val[6].value.netBool;
return *this; return *this;
} }
@ -53,7 +53,7 @@ namespace GameLogic
this->protocol[3].value = bTurnLeft; this->protocol[3].value = bTurnLeft;
this->protocol[4].value = bTurnRight; this->protocol[4].value = bTurnRight;
this->protocol[5].value = bStrafeRight; this->protocol[5].value = bStrafeRight;
this->protocol[6].value = bStrafeRight; this->protocol[6].value = bStrafeLeft;
return &protocol; return &protocol;
} }

View File

@ -22,7 +22,7 @@
/***********************************/ /***********************************/
/********* GENERAL PROTOCOLS ***************************************************************************************************/ /********* GENERAL PROTOCOLS ***************************************************************************************************/
/***********[ 100 - 200 ]***********/ /***********[ 100 - 200 ]***********/
#define protocol_GeneralMIN 100 /* This defines lower bounds of general protocols (okay to have same value on first element). */ #define protocol_GeneralMIN 100
#define protocol_General_Status 100 #define protocol_General_Status 100
#define protocol_General_Text 101 #define protocol_General_Text 101
#define protocol_GeneralMAX 199 #define protocol_GeneralMAX 199
@ -51,6 +51,7 @@
#define protocol_Gameplay_CreateObject 303 #define protocol_Gameplay_CreateObject 303
#define protocol_Gameplay_RemoveObject 304 #define protocol_Gameplay_RemoveObject 304
#define protocol_Gameplay_ObjectPosition 305 #define protocol_Gameplay_ObjectPosition 305
#define protocol_Gameplay_Initiate 306
#define protocol_GameplayMAX 399 #define protocol_GameplayMAX 399
@ -61,11 +62,4 @@ inline bool ProtocolIsLobby(short ID) { return (ID >= protocol_LobbyMIN && ID <=
inline bool ProtocolIsGeneral(short ID) { return (ID >= protocol_GeneralMIN && ID <= protocol_GeneralMAX); } inline bool ProtocolIsGeneral(short ID) { return (ID >= protocol_GeneralMIN && ID <= protocol_GeneralMAX); }
inline bool ProtocolIsGameplay(short ID) { return (ID >= protocol_GameplayMIN && ID <= protocol_GameplayMAX); } inline bool ProtocolIsGameplay(short ID) { return (ID >= protocol_GameplayMIN && ID <= protocol_GameplayMAX); }
/***********************************/
/*********** TEST PROTOCOLS *******************************************************************************************************/
/***********[ x - x ]************/
#endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H #endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H

View File

@ -5,5 +5,6 @@
#include "PlayerProtocols.h" #include "PlayerProtocols.h"
#include "LobbyProtocols.h" #include "LobbyProtocols.h"
#include "ControlProtocols.h" #include "ControlProtocols.h"
#include "GameplayProtocols.h"
#endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H #endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H

View File

@ -1,13 +1,13 @@
#ifndef I_QUEUE_H #ifndef MISC_I_QUEUE_H
#define I_QUEUE_H #define MISC_I_QUEUE_H
///////////////////////////////// /////////////////////////////////
// Created by Sam Svensson 2013// // Created by Sam Svensson 2013//
///////////////////////////////// /////////////////////////////////
namespace Oyster namespace Utility
{ {
namespace Queue namespace Container
{ {
template <typename Type> template <typename Type>
class IQueue class IQueue
@ -18,16 +18,13 @@ namespace Oyster
//standard operations of the std::queue //standard operations of the std::queue
//--------------------------------------------- //---------------------------------------------
virtual ~IQueue() {}; virtual ~IQueue() {};
virtual void Push( Type item ) = 0; virtual void Push( Type item ) = 0;
virtual Type Pop() = 0; virtual Type Pop() = 0;
virtual Type Front() = 0;
virtual Type Front() = 0; virtual Type Back() = 0;
virtual Type Back() = 0; virtual int Size() = 0;
virtual bool IsEmpty() = 0;
virtual int Size() = 0; virtual void Swap( IQueue<Type> &queue ) = 0;
virtual bool IsEmpty() = 0;
virtual void Swap( IQueue<Type> &queue ) = 0;
}; };
} }
} }

View File

@ -162,6 +162,7 @@
<ClInclude Include="OysterCallback.h" /> <ClInclude Include="OysterCallback.h" />
<ClInclude Include="PostBox\IPostBox.h" /> <ClInclude Include="PostBox\IPostBox.h" />
<ClInclude Include="PostBox\PostBox.h" /> <ClInclude Include="PostBox\PostBox.h" />
<ClInclude Include="Queue.h" />
<ClInclude Include="Resource\OysterResource.h" /> <ClInclude Include="Resource\OysterResource.h" />
<ClInclude Include="Resource\OResource.h" /> <ClInclude Include="Resource\OResource.h" />
<ClInclude Include="ThreadSafeQueue.h" /> <ClInclude Include="ThreadSafeQueue.h" />

View File

@ -101,5 +101,8 @@
<ClInclude Include="OysterCallback.h"> <ClInclude Include="OysterCallback.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Queue.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -24,7 +24,8 @@ namespace Oyster
virtual bool IsEmpty(); virtual bool IsEmpty();
private: private:
Oyster::Queue::ThreadSafeQueue<T> messages; Utility::Container::ThreadSafeQueue<T> messages;
//Utility::Container::ThreadSafeQueue<T> messages;
}; };

181
Code/Misc/Queue.h Normal file
View File

@ -0,0 +1,181 @@
#ifndef MISC_QUEUE_H
#define MISC_QUEUE_H
////////////////////////////////////////////
// Created by Sam Svensson 2013
/////////////////////////////////////////////
#include "IQueue.h"
namespace Utility
{
namespace Container
{
template <typename Type>
class Queue : public IQueue<Type>
{
public:
Queue<Type>();
virtual ~Queue<Type>();
virtual void Push( Type item );
virtual Type Pop();
virtual Type Front();
virtual Type Back();
virtual int Size();
virtual bool IsEmpty();
virtual void Swap( IQueue<Type> &queue );
private:
class Node
{
public:
Type item;
Node *next;
Node(Type item){ this->item = item; this->next = NULL; };
~Node() {};
};
Node *front;
Node *back;
int nrOfNodes;
};
//----------------------------------------------
//implemented template functions
//----------------------------------------------
template < typename Type >
Queue<Type>::Queue()
{
this->front = NULL;
this->back = NULL;
this->nrOfNodes = 0;
}
template < typename Type >
Queue<Type>::~Queue()
{
if(!nrOfNodes) return;
if(this->front != NULL)
{
Node *destroyer;
Node *walker = this->front;
for(int i = 0; i < this->nrOfNodes; i++)
{
destroyer = walker;
walker = walker->next;
delete destroyer;
}
this->front = NULL;
this->back = NULL;
}
}
template < typename Type >
void Queue<Type>::Push(Type item)
{
Node *e = new Node(item);
if(this->front != NULL)
{
this->back->next = e;
this->back = e;
}
else
{
this->front = e;
this->back = e;
}
this->nrOfNodes++;
}
template < typename Type >
Type Queue<Type>::Pop()
{
Type item = this->front->item;
Node *destroyer = this->front;
this->front = front->next;
delete destroyer;
this->nrOfNodes--;
if(nrOfNodes == 0)
{
this->front = NULL;
this->back = NULL;
}
return item;
}
template < typename Type >
Type Queue<Type>::Front()
{
Type temp = this->front->item;
return temp;
}
template < typename Type >
Type Queue<Type>::Back()
{
Type temp = this->back->item;
return temp;
}
template < typename Type >
int Queue<Type>::Size()
{
int size = this->nrOfNodes;
return size;
}
template < typename Type >
bool Queue<Type>::IsEmpty()
{
if(nrOfNodes == 0 || this->front == NULL)
{
return true;
}
return false;
}
template < typename Type >
void Queue<Type>::Swap(IQueue<Type> &queue )
{
int prevNrOfNodes = this->nrOfNodes;
int size = queue.Size();
for(int i = 0; i < size; i++)
{
this->Push(queue.Pop());
}
for(int i = 0; i < prevNrOfNodes; i++)
{
queue.Push(this->Pop());
}
}
}
}
#endif

View File

@ -71,13 +71,13 @@ namespace Oyster
//OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackObject<bool, void>* worker, bool start, bool detach = false); //OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackObject<bool, void>* worker, bool start, bool detach = false);
//OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackFunction<bool, void>::FNC worker, bool start, bool detach = false); //OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackFunction<bool, void>::FNC worker, bool start, bool detach = false);
OYSTER_THREAD_ERROR Start(); OYSTER_THREAD_ERROR Start();
OYSTER_THREAD_ERROR Stop(bool wait = false); OYSTER_THREAD_ERROR Stop();
OYSTER_THREAD_ERROR Pause(); OYSTER_THREAD_ERROR Pause();
OYSTER_THREAD_ERROR Pause(int mSec); OYSTER_THREAD_ERROR Pause(int mSec);
OYSTER_THREAD_ERROR Resume(); OYSTER_THREAD_ERROR Resume();
OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0); OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0);
OYSTER_THREAD_ERROR SetWorker(ThreadFnc worker = 0); OYSTER_THREAD_ERROR SetWorker(ThreadFnc worker = 0);
OYSTER_THREAD_ERROR Terminate(bool wait = true); OYSTER_THREAD_ERROR Terminate();
OYSTER_THREAD_ERROR Wait(); OYSTER_THREAD_ERROR Wait();
OYSTER_THREAD_ERROR Wait(int mSec); OYSTER_THREAD_ERROR Wait(int mSec);
OYSTER_THREAD_ERROR Swap(const OysterThread* other); OYSTER_THREAD_ERROR Swap(const OysterThread* other);

View File

@ -15,8 +15,6 @@ using namespace Oyster::Thread;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
#pragma region Declerations #pragma region Declerations
enum OYSTER_THREAD_STATE enum OYSTER_THREAD_STATE
@ -51,8 +49,8 @@ using namespace Utility::DynamicMemory;
OwnerContainer ownerObj; // OwnerContainer ownerObj; //
std::atomic<int> msec; //<! A timer in miliseconds. std::atomic<int> msec; //<! A timer in miliseconds.
std::timed_mutex threadFunctionLock; //std::timed_mutex threadFunctionLock;
//std::mutex threadWaitFunctionLock; std::mutex threadStopMutex;
}; };
/** A typical Oyster thread function */ /** A typical Oyster thread function */
@ -60,8 +58,9 @@ using namespace Utility::DynamicMemory;
struct RefData struct RefData
{ {
//std::mutex threadWaitFunctionLock; std::mutex threadWaitFunctionLock;
bool isCreated; bool isCreated;
bool isAlive;
ThreadData *threadData; ThreadData *threadData;
std::thread workerThread; std::thread workerThread;
@ -73,74 +72,25 @@ using namespace Utility::DynamicMemory;
~RefData() ~RefData()
{ {
//threadWaitFunctionLock.lock(); //threadWaitFunctionLock.lock();
Terminate(true); Terminate();
//threadWaitFunctionLock.unlock(); //threadWaitFunctionLock.unlock();
} }
OYSTER_THREAD_ERROR Terminate(bool wait) OYSTER_THREAD_ERROR Terminate()
{ {
if(!threadData) return OYSTER_THREAD_ERROR_SUCCESS; if(!threadData) return OYSTER_THREAD_ERROR_SUCCESS;
this->threadData->state = OYSTER_THREAD_STATE_DEAD; this->threadData->state = OYSTER_THREAD_STATE_DEAD;
if(wait) if(this->workerThread.joinable())
{ {
if(std::this_thread::get_id() != this->workerThread.get_id()) this->workerThread.join();
if(this->workerThread.joinable()) this->isCreated = false;
{ delete this->threadData;
this->workerThread.join(); this->threadData = 0;
this->isCreated = false;
this->threadData = 0;
}
}
else
{
if(this->workerThread.joinable())
this->workerThread.detach();
} }
return OYSTER_THREAD_ERROR_SUCCESS; return OYSTER_THREAD_ERROR_SUCCESS;
} }
//OYSTER_THREAD_ERROR Create(ThreadFunction fnc, IThreadObject* worker, bool start, bool detach)
//{
// if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
//
// threadData = new ThreadData();
// if(start)
// this->threadData->state = OYSTER_THREAD_STATE_NORMAL;
// else
// this->threadData->state = OYSTER_THREAD_STATE_IDLE;
// threadData->owner = worker;
// threadData->prio = OYSTER_THREAD_PRIORITY_3;
//
// workerThread = std::thread(fnc, this->threadData);
//
// if(detach)
// this->workerThread.detach();
//
// isCreated = true;
//
// return OYSTER_THREAD_ERROR_SUCCESS;
//}
//OYSTER_THREAD_ERROR Create(ThreadFunction fnc, Oyster::Callback::OysterCallback<bool, void> worker, bool start, bool detach)
//{
// if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
//
// threadData = new ThreadData();
// if(start)
// this->threadData->state = OYSTER_THREAD_STATE_NORMAL;
// else
// this->threadData->state = OYSTER_THREAD_STATE_IDLE;
// threadData->ownerObj = worker;
// threadData->prio = OYSTER_THREAD_PRIORITY_3;
//
// workerThread = std::thread(fnc, this->threadData);
//
// if(detach)
// this->workerThread.detach();
//
// isCreated = true;
//
// return OYSTER_THREAD_ERROR_SUCCESS;
//}
OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach) OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach)
{ {
if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated; if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
@ -155,8 +105,8 @@ using namespace Utility::DynamicMemory;
workerThread = std::thread(fnc, this->threadData); workerThread = std::thread(fnc, this->threadData);
if(detach) //if(detach)
this->workerThread.detach(); // this->workerThread.detach();
isCreated = true; isCreated = true;
@ -171,9 +121,7 @@ using namespace Utility::DynamicMemory;
PrivateData(){} PrivateData(){}
~PrivateData() ~PrivateData()
{ {
if(data) data.Release();
if(data->threadData)
memset(&data->threadData->ownerObj, 0, sizeof(OwnerContainer));
} }
OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach) OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach)
{ {
@ -181,12 +129,12 @@ using namespace Utility::DynamicMemory;
data = new RefData(); data = new RefData();
return data->Create(fnc, worker, start, detach); return data->Create(fnc, worker, start, detach);
} }
OYSTER_THREAD_ERROR Terminate(bool wait) OYSTER_THREAD_ERROR Terminate()
{ {
if(!data) if(!data)
return OYSTER_THREAD_ERROR_FAILED; return OYSTER_THREAD_ERROR_FAILED;
return data->Terminate(wait); return data->Terminate();
} }
}; };
@ -248,7 +196,8 @@ using namespace Utility::DynamicMemory;
if(w->ownerObj.value.obj) w->ownerObj.value.obj->ThreadExit(); if(w->ownerObj.value.obj) w->ownerObj.value.obj->ThreadExit();
w->state = OYSTER_THREAD_STATE_DEAD; w->state = OYSTER_THREAD_STATE_DEAD;
delete w;
//delete w;
} }
}; };
@ -295,31 +244,6 @@ OYSTER_THREAD_ERROR OysterThread::Create(ThreadFnc worker, bool start, bool deta
return this->privateData->Create(ThreadHelp::ThreadingFunction, c, start, detach); return this->privateData->Create(ThreadHelp::ThreadingFunction, c, start, detach);
} }
/*
OYSTER_THREAD_ERROR OysterThread::Create(Oyster::Callback::CallbackObject<bool, void>* worker, bool start, bool detach)
{
if(!this->privateData)
this->privateData = new PrivateData();
Oyster::Callback::OysterCallback<> temp;
temp.callbackType = Oyster::Callback::CallbackType_Object;
temp.value = worker;
return this->privateData->Create(ThreadHelp::ThreadingFunction, temp, start, detach);
}
OYSTER_THREAD_ERROR OysterThread::Create(Oyster::Callback::CallbackFunction<bool, void>::FNC worker, bool start, bool detach)
{
if(!this->privateData)
this->privateData = new PrivateData();
Oyster::Callback::OysterCallback<> temp;
temp.callbackType = Oyster::Callback::CallbackType_Function;
temp.value = worker;
return this->privateData->Create(ThreadHelp::ThreadingFunction, temp, start, detach);
}
*/
OYSTER_THREAD_ERROR OysterThread::Start() OYSTER_THREAD_ERROR OysterThread::Start()
{ {
if(!this->privateData->data->threadData->ownerObj) if(!this->privateData->data->threadData->ownerObj)
@ -332,9 +256,9 @@ OYSTER_THREAD_ERROR OysterThread::Start()
return OYSTER_THREAD_ERROR_SUCCESS; return OYSTER_THREAD_ERROR_SUCCESS;
} }
OYSTER_THREAD_ERROR OysterThread::Stop(bool wait) OYSTER_THREAD_ERROR OysterThread::Stop()
{ {
return this->Terminate(wait); return this->Terminate();
} }
OYSTER_THREAD_ERROR OysterThread::Pause() OYSTER_THREAD_ERROR OysterThread::Pause()
{ {
@ -373,9 +297,9 @@ OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker)
return OYSTER_THREAD_ERROR_SUCCESS;; return OYSTER_THREAD_ERROR_SUCCESS;;
} }
OYSTER_THREAD_ERROR OysterThread::Terminate(bool wait) OYSTER_THREAD_ERROR OysterThread::Terminate()
{ {
return this->privateData->Terminate(wait); return this->privateData->Terminate();
} }
OYSTER_THREAD_ERROR OysterThread::Wait() OYSTER_THREAD_ERROR OysterThread::Wait()
{ {
@ -385,9 +309,6 @@ OYSTER_THREAD_ERROR OysterThread::Wait()
if( this->privateData->data->workerThread.get_id() == std::this_thread::get_id()) if( this->privateData->data->workerThread.get_id() == std::this_thread::get_id())
return OYSTER_THREAD_ERROR_ThreadCannotWaintOnItselfe; return OYSTER_THREAD_ERROR_ThreadCannotWaintOnItselfe;
//this->privateData->data->threadData->threadFunctionLock.lock();
//this->privateData->data->threadData->threadFunctionLock.unlock();
return OYSTER_THREAD_ERROR_SUCCESS; return OYSTER_THREAD_ERROR_SUCCESS;
} }
OYSTER_THREAD_ERROR OysterThread::Wait(int msec) OYSTER_THREAD_ERROR OysterThread::Wait(int msec)
@ -395,9 +316,6 @@ OYSTER_THREAD_ERROR OysterThread::Wait(int msec)
if(this->privateData->data->workerThread.get_id() == std::this_thread::get_id()) if(this->privateData->data->workerThread.get_id() == std::this_thread::get_id())
return OYSTER_THREAD_ERROR_ThreadCannotWaintOnItselfe; return OYSTER_THREAD_ERROR_ThreadCannotWaintOnItselfe;
//if(this->privateData->data->threadData->threadFunctionLock.try_lock_for(std::chrono::milliseconds(msec)))
// this->privateData->data->threadData->threadFunctionLock.unlock();
return OYSTER_THREAD_ERROR_SUCCESS; return OYSTER_THREAD_ERROR_SUCCESS;
} }
OYSTER_THREAD_ERROR OysterThread::Swap(const OysterThread* other) OYSTER_THREAD_ERROR OysterThread::Swap(const OysterThread* other)

View File

@ -10,11 +10,10 @@
///////////////////////////////////////////// /////////////////////////////////////////////
#include "IQueue.h" #include "IQueue.h"
#include "Thread/OysterMutex.h"
namespace Oyster namespace Utility
{ {
namespace Queue namespace Container
{ {
template <typename Type> template <typename Type>
class ThreadSafeQueue : public IQueue<Type> class ThreadSafeQueue : public IQueue<Type>

View File

@ -292,7 +292,8 @@ namespace Utility
this->_ptr = p; this->_ptr = p;
if(p) this->_rc->Incref(); if(p) this->_rc->Incref();
else this->_rc = 0;
} }
return *this; return *this;
} }

View File

@ -22,10 +22,10 @@ struct CustomNetProtocol::PrivateData
size_t size = strlen(i->second.value.netCharPtr); size_t size = strlen(i->second.value.netCharPtr);
if(size == 0) continue; if(size == 0) continue;
attributes[i->first];
attributes[i->first].value.netCharPtr = new char[size + 1]; attributes[i->first].value.netCharPtr = new char[size + 1];
//strcpy_s(attributes[i->first].value.netCharPtr, size + 1, i->second.value.netCharPtr); //strcpy_s(attributes[i->first].value.netCharPtr, size + 1, i->second.value.netCharPtr);
memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1); memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1);
attributes[i->first].type = NetAttributeType_CharArray;
} }
else else
{ {

View File

@ -63,9 +63,8 @@ struct ClientDataContainer
} }
~ClientDataContainer() ~ClientDataContainer()
{ {
thread.Stop();
thread.Wait();
connection.Disconnect(); connection.Disconnect();
thread.Stop();
callbackType = NetworkProtocolCallbackType_Unknown; callbackType = NetworkProtocolCallbackType_Unknown;
ShutdownWinSock(); ShutdownWinSock();
@ -244,6 +243,7 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[])
void NetworkClient::Disconnect() void NetworkClient::Disconnect()
{ {
privateData->data->connection.Disconnect(); privateData->data->connection.Disconnect();
privateData->data->thread.Terminate();
} }
bool NetworkClient::IsConnected() bool NetworkClient::IsConnected()

View File

@ -115,7 +115,7 @@ void NetworkServer::PrivateData::Stop()
started = false; started = false;
thread.Stop(true); thread.Stop();
} }
void NetworkServer::PrivateData::Shutdown() void NetworkServer::PrivateData::Shutdown()

View File

@ -108,6 +108,7 @@ int Connection::InitiateClient()
int Connection::Disconnect() int Connection::Disconnect()
{ {
if(this->closed) return -1;
int val = CloseSocket(this->socket); int val = CloseSocket(this->socket);
this->socket = -1; this->socket = -1;
this->closed = true; this->closed = true;
@ -117,6 +118,8 @@ int Connection::Disconnect()
int Connection::Send(OysterByte &bytes) int Connection::Send(OysterByte &bytes)
{ {
if(this->closed) return -1;
int nBytes; int nBytes;
nBytes = send(this->socket, bytes, bytes.GetSize(), 0); nBytes = send(this->socket, bytes, bytes.GetSize(), 0);
@ -130,6 +133,7 @@ int Connection::Send(OysterByte &bytes)
int Connection::Recieve(OysterByte &bytes) int Connection::Recieve(OysterByte &bytes)
{ {
if(this->closed) return -1;
int nBytes; int nBytes;
bytes.Resize(1000); bytes.Resize(1000);
@ -150,6 +154,8 @@ int Connection::Recieve(OysterByte &bytes)
//Listen will only return the correct socket or -1 for failure. //Listen will only return the correct socket or -1 for failure.
int Connection::Listen() int Connection::Listen()
{ {
if(this->closed) return -1;
int clientSocket; int clientSocket;
if((clientSocket = (int)accept(this->socket, NULL, NULL)) == INVALID_SOCKET) if((clientSocket = (int)accept(this->socket, NULL, NULL)) == INVALID_SOCKET)
{ {
@ -205,5 +211,14 @@ int Connection::InitiateSocket()
return WSAGetLastError(); return WSAGetLastError();
} }
int flag = 1;
int result = setsockopt(this->socket, /* socket affected */
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(char *) &flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
if (result < 0)
return -1;
return 0; return 0;
} }

View File

@ -6,11 +6,14 @@ using namespace Oyster::Thread;
Listener::Listener() Listener::Listener()
{ {
this->port = -1;
this->isListening = false;
connection = NULL; connection = NULL;
} }
Listener::Listener(Oyster::Network::IPostBox<int>* postBox) Listener::Listener(Oyster::Network::IPostBox<int>* postBox)
{ {
this->isListening = false;
connection = NULL; connection = NULL;
this->postBox = postBox; this->postBox = postBox;
} }
@ -19,9 +22,11 @@ Listener::~Listener()
{ {
if(connection) if(connection)
{ {
this->thread.Terminate(false); this->isListening = false;
this->thread.Terminate();
delete connection; delete connection;
connection = 0; connection = 0;
this->port = -1;
} }
} }
@ -36,6 +41,8 @@ bool Listener::Init(unsigned int port)
return false; return false;
} }
this->port = port;
this->isListening = true;
return true; return true;
} }
@ -52,6 +59,11 @@ bool Listener::Init(unsigned int port, bool start)
return false; return false;
} }
if(start)
{
this->isListening = true;
}
this->port = port;
return true; return true;
} }
@ -62,17 +74,18 @@ bool Listener::Start()
return false; return false;
} }
this->isListening = true;
return true; return true;
} }
void Listener::Stop() void Listener::Stop()
{ {
thread.Stop(); StopListen();
} }
void Listener::Shutdown() void Listener::Shutdown()
{ {
thread.Stop(false); StopListen();
} }
void Listener::SetPostBox(Oyster::Network::IPostBox<int>* postBox) void Listener::SetPostBox(Oyster::Network::IPostBox<int>* postBox)
@ -87,6 +100,10 @@ int Listener::Accept()
int clientSocket = -1; int clientSocket = -1;
clientSocket = connection->Listen(); clientSocket = connection->Listen();
if(!this->isListening.load())
{
return -1;
}
if(clientSocket != -1) if(clientSocket != -1)
{ {
stdMutex.lock(); stdMutex.lock();
@ -96,13 +113,26 @@ int Listener::Accept()
return clientSocket; return clientSocket;
} }
void Listener::StopListen()
{
if(this->connection && this->connection->IsConnected())
{
this->isListening = false;
Connection c;
c.InitiateClient();
c.Connect(this->port, "127.0.0.1");
}
}
bool Listener::DoWork() bool Listener::DoWork()
{ {
if(!this->connection) return false; if(!this->connection) return false;
int result = Accept(); int result = Accept();
if(result == -1) if(!this->isListening.load())
{
return false;
}
else if(result == -1)
{ {
//Do something? //Do something?
} }

View File

@ -11,6 +11,7 @@
#include "../../Misc/Thread/OysterThread.h" #include "../../Misc/Thread/OysterThread.h"
#include "../../Misc/Thread/OysterMutex.h" #include "../../Misc/Thread/OysterMutex.h"
#include "../../Misc/Utilities.h" #include "../../Misc/Utilities.h"
#include <atomic>
namespace Oyster namespace Oyster
{ {
@ -41,6 +42,7 @@ namespace Oyster
//Function that runs in the thread. //Function that runs in the thread.
int Accept(); int Accept();
void StopListen();
private: private:
::Oyster::Network::Connection* connection; ::Oyster::Network::Connection* connection;
@ -50,7 +52,8 @@ namespace Oyster
std::mutex stdMutex; std::mutex stdMutex;
IPostBox<int>* postBox; IPostBox<int>* postBox;
std::atomic<bool> isListening;
int port;
}; };
} }
} }

View File

@ -27,7 +27,7 @@ namespace Oyster
virtual bool IsFull(); virtual bool IsFull();
private: private:
Oyster::Queue::ThreadSafeQueue<T> messages; Utility::Container::ThreadSafeQueue<T> messages;
}; };

View File

@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
using namespace Oyster::Network; using namespace Oyster::Network;
using namespace Oyster::Thread; using namespace Oyster::Thread;
using namespace Utility::Container;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
ThreadedClient::ThreadedClient() ThreadedClient::ThreadedClient()

View File

@ -7,6 +7,7 @@
#include "Dx11Includes.h" #include "Dx11Includes.h"
#include <sstream> #include <sstream>
#include "OysterMath.h" #include "OysterMath.h"
#include <vld.h>
namespace Oyster namespace Oyster
{ {

View File

@ -52,8 +52,15 @@ namespace Oyster
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderV, -1, ForceReload); data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderV, -1, ForceReload);
if(data) if(data)
{ {
VSMap[name] = VS.size(); if(ForceReload && VSMap.count(name))
VS.push_back((ID3D11VertexShader*)data); {
VS[VSMap[name]] = (ID3D11VertexShader*)data;
}
else
{
VSMap[name] = VS.size();
VS.push_back((ID3D11VertexShader*)data);
}
} }
} }
break; break;
@ -63,8 +70,16 @@ namespace Oyster
{ {
if(data!=0) if(data!=0)
{ {
HSMap[name] = HS.size(); if(ForceReload && HSMap.count(name))
HS.push_back((ID3D11HullShader*)data); {
HS[HSMap[name]] = (ID3D11HullShader*)data;
}
else
{
HSMap[name] = HS.size();
HS.push_back((ID3D11HullShader*)data);
}
} }
} }
break; break;
@ -74,8 +89,15 @@ namespace Oyster
{ {
if(data!=0) if(data!=0)
{ {
DSMap[name] = DS.size(); if(ForceReload && DSMap.count(name))
DS.push_back((ID3D11DomainShader*)data); {
DS[DSMap[name]] = (ID3D11DomainShader*)data;
}
else
{
DSMap[name] = DS.size();
DS.push_back((ID3D11DomainShader*)data);
}
} }
} }
break; break;
@ -85,8 +107,15 @@ namespace Oyster
{ {
if(data!=0) if(data!=0)
{ {
GSMap[name] = GS.size(); if(ForceReload && GSMap.count(name))
GS.push_back((ID3D11GeometryShader*)data); {
GS[GSMap[name]] = (ID3D11GeometryShader*)data;
}
else
{
GSMap[name] = GS.size();
GS.push_back((ID3D11GeometryShader*)data);
}
} }
} }
break; break;
@ -96,8 +125,15 @@ namespace Oyster
{ {
if(data!=0) if(data!=0)
{ {
PSMap[name] = PS.size(); if(ForceReload && PSMap.count(name))
PS.push_back((ID3D11PixelShader*)data); {
PS[PSMap[name]] = (ID3D11PixelShader*)data;
}
else
{
PSMap[name] = PS.size();
PS.push_back((ID3D11PixelShader*)data);
}
} }
} }
break; break;
@ -107,8 +143,16 @@ namespace Oyster
{ {
if(data!=0) if(data!=0)
{ {
CSMap[name] = CS.size(); if(ForceReload && CSMap.count(name))
CS.push_back((ID3D11ComputeShader*)data); {
CS[CSMap[name]] = (ID3D11ComputeShader*)data;
}
else
{
CSMap[name] = CS.size();
CS.push_back((ID3D11ComputeShader*)data);
}
} }
} }
break; break;
@ -375,9 +419,9 @@ namespace Oyster
void Core::PipelineManager::CleanPipeline() void Core::PipelineManager::CleanPipeline()
{ {
deviceContext->VSSetShaderResources(0,16,Core::srvNULL); //deviceContext->VSSetShaderResources(0,16,Core::srvNULL);
deviceContext->GSSetShaderResources(0,16,Core::srvNULL); //deviceContext->GSSetShaderResources(0,16,Core::srvNULL);
deviceContext->PSSetShaderResources(0,16,Core::srvNULL); //deviceContext->PSSetShaderResources(0,16,Core::srvNULL);
deviceContext->CSSetShaderResources(0,16,Core::srvNULL); deviceContext->CSSetShaderResources(0,16,Core::srvNULL);
deviceContext->CSSetUnorderedAccessViews(0,8,Core::uavNULL,NULL); deviceContext->CSSetUnorderedAccessViews(0,8,Core::uavNULL,NULL);
deviceContext->OMSetRenderTargets(8,Core::rtvNULL, NULL); deviceContext->OMSetRenderTargets(8,Core::rtvNULL, NULL);

View File

@ -20,6 +20,12 @@ namespace Oyster
Oyster::Math::Matrix P; Oyster::Math::Matrix P;
}; };
struct PerModel
{
Math::Matrix WV;
Math::Matrix WVP;
};
struct FinalVertex struct FinalVertex
{ {
Oyster::Math::Float3 pos; Oyster::Math::Float3 pos;
@ -34,9 +40,10 @@ namespace Oyster
struct LightConstants struct LightConstants
{ {
Math::Float4x4 InvProj; Math::Float4x4 InvProj;
Math::Float4x4 Proj;
Math::Float2 Pixels; Math::Float2 Pixels;
int Lights; int Lights;
float Pad; float SSAORadius;
Oyster::Math::Float4x4 View; Oyster::Math::Float4x4 View;
}; };

View File

@ -6,6 +6,7 @@
#include "../FileLoader/ObjReader.h" #include "../FileLoader/ObjReader.h"
#include "../../Misc/Resource/OysterResource.h" #include "../../Misc/Resource/OysterResource.h"
#include "../FileLoader/GeneralLoader.h" #include "../FileLoader/GeneralLoader.h"
#include <vld.h>
namespace Oyster namespace Oyster
{ {
@ -26,12 +27,6 @@ namespace Oyster
{ {
return API::Fail; return API::Fail;
} }
#ifdef _DEBUG
if(Render::Resources::Debug::Init() == Core::Init::Fail)
{
return API::Fail;
}
#endif
Render::Resources::Deffered::Init(); Render::Resources::Deffered::Init();
Render::Preparations::Basic::SetViewPort(); Render::Preparations::Basic::SetViewPort();
@ -62,12 +57,12 @@ namespace Oyster
void API::RenderScene(Model::Model models[], int count) void API::RenderScene(Model::Model models[], int count)
{ {
Render::Rendering::Basic::RenderScene(models,count); Render::Rendering::Basic::RenderScene(models,count, View, Projection);
} }
void API::RenderModel(Model::Model& m) void API::RenderModel(Model::Model& m)
{ {
Render::Rendering::Basic::RenderScene(&m,1); Render::Rendering::Basic::RenderScene(&m,1, View, Projection);
} }
void API::EndFrame() void API::EndFrame()
@ -103,10 +98,6 @@ namespace Oyster
SAFE_DELETE(Core::viewPort); SAFE_DELETE(Core::viewPort);
Oyster::Resource::OysterResource::Clean(); Oyster::Resource::OysterResource::Clean();
Oyster::Graphics::Core::PipelineManager::Clean(); Oyster::Graphics::Core::PipelineManager::Clean();
#ifdef _DEBUG
Oyster::Graphics::Render::Resources::Debug::Clean();
#endif
Oyster::Graphics::Render::Resources::Deffered::Clean(); Oyster::Graphics::Render::Resources::Deffered::Clean();
SAFE_RELEASE(Core::depthStencil); SAFE_RELEASE(Core::depthStencil);
@ -128,5 +119,13 @@ namespace Oyster
{ {
Lights.clear(); Lights.clear();
} }
#ifdef _DEBUG
API::State API::ReloadShaders()
{
Render::Resources::Deffered::InitShaders();
return State::Sucsess;
}
#endif
} }
} }

View File

@ -4,7 +4,7 @@
#include "..\Model\Model.h" #include "..\Model\Model.h"
#include "OysterMath.h" #include "OysterMath.h"
#include <Windows.h> #include <Windows.h>
//#include <vld.h> #include <vld.h>
#ifdef GFX_DLL_EXPORT #ifdef GFX_DLL_EXPORT
#define GFX_DLL_USAGE __declspec(dllexport) #define GFX_DLL_USAGE __declspec(dllexport)
@ -29,23 +29,40 @@ namespace Oyster
}; };
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion);
#ifdef _DEBUG
static State ReloadShaders();
#endif
//! @todo Memory Leaks
//! @brief Clean Resources and release all memory
static void Clean(); static void Clean();
//! @brief Sets the view matrix to use next frame
static void SetView(Oyster::Math::Float4x4& View); static void SetView(Oyster::Math::Float4x4& View);
//! @brief Sets the projection matrix to use next frame
static void SetProjection(Oyster::Math::Float4x4& Projection); static void SetProjection(Oyster::Math::Float4x4& Projection);
//! @brief will internally use last values from SetView and SetProjection //! @brief will internally use last values from SetView and SetProjection
static void NewFrame(); static void NewFrame();
//! @brief Renders a list of models
static void RenderScene(Oyster::Graphics::Model::Model models[], int count); static void RenderScene(Oyster::Graphics::Model::Model models[], int count);
//! @brief Renders a single model
static void RenderModel(Oyster::Graphics::Model::Model& model); static void RenderModel(Oyster::Graphics::Model::Model& model);
//! @brief Performs light calculations, post effects and presents the scene
static void EndFrame(); static void EndFrame();
//! @brief Creates a model from the supplied file, note: do not include .obj
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename); static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);
//! @brief deletes a model and relases the models resources
static void DeleteModel(Oyster::Graphics::Model::Model* model); static void DeleteModel(Oyster::Graphics::Model::Model* model);
//! @brief adds a light to the scene
static void AddLight(Definitions::Pointlight light); static void AddLight(Definitions::Pointlight light);
//! @brief removes all lights from the scene
static void ClearLights(); static void ClearLights();
//! @brief Sets Options to the graphics, note: currently unused
static State SetOptions(Option); static State SetOptions(Option);
}; };
} }

View File

@ -39,11 +39,12 @@ void Oyster::Graphics::Loading::UnloadTexture(void* data)
void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out) void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out)
{ {
FileLoaders::ObjReader* obj = FileLoaders::ObjReader::LoadFile(filename); FileLoaders::ObjReader obj;
obj.LoadFile(filename);
Model::ModelInfo* info = new Model::ModelInfo(); Model::ModelInfo* info = new Model::ModelInfo();
Oyster::FileLoaders::ObjReader::Vertex* vdata; Oyster::FileLoaders::ObjReader::Vertex* vdata;
int count; int count;
obj->GetVertexData(&vdata, count); obj.GetVertexData(&vdata, count);
info->Vertices = new Core::Buffer(); info->Vertices = new Core::Buffer();
Core::Buffer::BUFFER_INIT_DESC desc; Core::Buffer::BUFFER_INIT_DESC desc;
desc.ElementSize = sizeof(FileLoaders::ObjReader::Vertex); desc.ElementSize = sizeof(FileLoaders::ObjReader::Vertex);

View File

@ -3,31 +3,16 @@
#include "..\Core\Core.h" #include "..\Core\Core.h"
#include <fstream> #include <fstream>
#include <map> #include <map>
#include <vld.h>
using namespace std; using namespace std;
using namespace Oyster::FileLoaders; using namespace Oyster::FileLoaders;
using namespace Oyster; using namespace Oyster;
using namespace Oyster::Math; using namespace Oyster::Math;
ObjReader *ObjReader::LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform) void ObjReader::LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform)
{ {
static std::map<std::wstring, ObjReader *> cache; this->ParseFile(fileName + L".obj", transform);
ObjReader *reader = NULL;
if (cache.count(fileName))
{
reader = cache[fileName];
}
else
{
reader = new ObjReader();
reader->ParseFile(fileName + L".obj", transform);
cache[fileName] = reader;
}
return reader;
} }
ObjReader::ObjReader(void) ObjReader::ObjReader(void)
@ -37,6 +22,7 @@ ObjReader::ObjReader(void)
ObjReader::~ObjReader(void) ObjReader::~ObjReader(void)
{ {
SAFE_DELETE_ARRAY(this->vertices);
} }
void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform) void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
@ -50,7 +36,6 @@ void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
} }
wstring path; wstring path;
//Utility::String::ExtractDirPath(path,fileName,'\\');
std::vector<Vertex> VertexList; std::vector<Vertex> VertexList;
std::vector<Float3> vList; std::vector<Float3> vList;
@ -74,6 +59,7 @@ void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
if(c==L"v") if(c==L"v")
{ {
position = readVertex(offset,s); position = readVertex(offset,s);
//position *= 0.001f;
vList.push_back(position); vList.push_back(position);
} }
else if(c==L"vt") else if(c==L"vt")

View File

@ -16,7 +16,7 @@ namespace Oyster
Oyster::Math::Float3 Normal; Oyster::Math::Float3 Normal;
}; };
static ObjReader *LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity); void LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
ObjReader(void); ObjReader(void);
~ObjReader(void); ~ObjReader(void);

View File

@ -9,9 +9,11 @@ namespace Oyster
{ {
namespace Model namespace Model
{ {
//struct ModelInfo;
struct Model struct Model
{ {
//! do not Edit, linked to render data //! do not Edit, linked to render data
//ModelInfo* info;
void* info; void* info;
Oyster::Math::Float4x4 WorldMatrix; Oyster::Math::Float4x4 WorldMatrix;
bool Visible; bool Visible;

View File

@ -182,7 +182,6 @@
<ClCompile Include="Render\Preparations\BasicPreparations.cpp" /> <ClCompile Include="Render\Preparations\BasicPreparations.cpp" />
<ClCompile Include="Render\Rendering\BasicRender.cpp" /> <ClCompile Include="Render\Rendering\BasicRender.cpp" />
<ClCompile Include="Render\Resources\Deffered.cpp" /> <ClCompile Include="Render\Resources\Deffered.cpp" />
<ClCompile Include="Render\Resources\Debug.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Core\Core.h" /> <ClInclude Include="Core\Core.h" />
@ -196,7 +195,6 @@
<ClInclude Include="Render\Rendering\Render.h" /> <ClInclude Include="Render\Rendering\Render.h" />
<ClInclude Include="Definitions\GraphicalDefinition.h" /> <ClInclude Include="Definitions\GraphicalDefinition.h" />
<ClInclude Include="Render\Resources\Deffered.h" /> <ClInclude Include="Render\Resources\Deffered.h" />
<ClInclude Include="Render\Resources\Debug.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Misc\Misc.vcxproj"> <ProjectReference Include="..\Misc\Misc.vcxproj">
@ -219,6 +217,16 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile> </FxCompile>
<FxCompile Include="Shader\HLSL\Deffered Shaders\PostPass.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="Shader\HLSL\Deffered Shaders\VertexGatherData.hlsl"> <FxCompile Include="Shader\HLSL\Deffered Shaders\VertexGatherData.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
@ -268,6 +276,7 @@
<None Include="Shader\HLSL\Deffered Shaders\GBufferHeader.hlsli" /> <None Include="Shader\HLSL\Deffered Shaders\GBufferHeader.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\LightCalc.hlsli" /> <None Include="Shader\HLSL\Deffered Shaders\LightCalc.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\PosManipulation.hlsli" /> <None Include="Shader\HLSL\Deffered Shaders\PosManipulation.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\SSAO.hlsli" />
<None Include="Shader\HLSL\SimpleDebug\Debug.hlsl" /> <None Include="Shader\HLSL\SimpleDebug\Debug.hlsl" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -34,6 +34,8 @@ namespace Oyster
lc.Pixels = Core::resolution; lc.Pixels = Core::resolution;
lc.Lights = numLights; lc.Lights = numLights;
lc.View = View; lc.View = View;
lc.Proj = Projection;
lc.SSAORadius = 3;
data = Resources::Deffered::LightConstantsData.Map(); data = Resources::Deffered::LightConstantsData.Map();
memcpy(data, &lc, sizeof(Definitions::LightConstants)); memcpy(data, &lc, sizeof(Definitions::LightConstants));
@ -44,14 +46,18 @@ namespace Oyster
Resources::Deffered::PointLightsData.Unmap(); Resources::Deffered::PointLightsData.Unmap();
} }
void Basic::RenderScene(Model::Model* models, int count) void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection)
{ {
for(int i = 0; i < count; ++i) for(int i = 0; i < count; ++i)
{ {
if(models[i].Visible) if(models[i].Visible)
{ {
Definitions::PerModel pm;
pm.WV = View * models[i].WorldMatrix;
pm.WVP = Projection * pm.WV;
void* data = Resources::Deffered::ModelData.Map(); void* data = Resources::Deffered::ModelData.Map();
memcpy(data,&(models[i].WorldMatrix),sizeof(Math::Float4x4)); memcpy(data,&(pm),sizeof(pm));
Resources::Deffered::ModelData.Unmap(); Resources::Deffered::ModelData.Unmap();
@ -82,6 +88,10 @@ namespace Oyster
Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1); Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1);
Core::PipelineManager::SetRenderPass(Resources::Deffered::PostPass);
Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1);
Core::swapChain->Present(0,0); Core::swapChain->Present(0,0);
} }
} }

View File

@ -17,7 +17,7 @@ namespace Oyster
public: public:
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights); static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights);
static void RenderScene(Model::Model* models, int count); static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection);
static void EndFrame(); static void EndFrame();
}; };
} }

View File

@ -11,6 +11,9 @@ typedef Oyster::Graphics::Core::Buffer Buffer;
const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\Deffered Shaders\\"; const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\Deffered Shaders\\";
const std::wstring PathToCSO = L"..\\Content\\Shaders\\"; const std::wstring PathToCSO = L"..\\Content\\Shaders\\";
const int KernelSize = 10;
const int SampleSpread = 8;
namespace Oyster namespace Oyster
{ {
namespace Graphics namespace Graphics
@ -20,12 +23,15 @@ namespace Oyster
namespace Resources namespace Resources
{ {
ID3D11RenderTargetView* Deffered::GBufferRTV[2] = {0}; ID3D11RenderTargetView* Deffered::GBufferRTV[Deffered::GBufferSize] = {0};
ID3D11ShaderResourceView* Deffered::GBufferSRV[2] = {0}; ID3D11ShaderResourceView* Deffered::GBufferSRV[Deffered::GBufferSize] = {0};
ID3D11UnorderedAccessView* Deffered::LBufferUAV[Deffered::LBufferSize] = {0};
ID3D11ShaderResourceView* Deffered::LBufferSRV[Deffered::LBufferSize] = {0};
Shader::RenderPass Deffered::GeometryPass; Shader::RenderPass Deffered::GeometryPass;
Shader::RenderPass Deffered::LightPass; Shader::RenderPass Deffered::LightPass;
Shader::RenderPass Deffered::PostPass;
Buffer Deffered::ModelData = Buffer(); Buffer Deffered::ModelData = Buffer();
Buffer Deffered::VPData = Buffer(); Buffer Deffered::VPData = Buffer();
@ -34,9 +40,12 @@ namespace Oyster
Buffer Deffered::PointLightsData = Buffer(); Buffer Deffered::PointLightsData = Buffer();
ID3D11ShaderResourceView* Deffered::PointLightView = NULL; ID3D11ShaderResourceView* Deffered::PointLightView = NULL;
Core::Init::State Deffered::Init() ID3D11ShaderResourceView* Deffered::SSAOKernel = NULL;
ID3D11ShaderResourceView* Deffered::SSAORandom = NULL;
Core::Init::State Deffered::InitShaders()
{ {
#ifdef _DEBUG #ifdef _DEBUG
std::wstring path = PathToHLSL; std::wstring path = PathToHLSL;
std::wstring end = L".hlsl"; std::wstring end = L".hlsl";
#else #else
@ -47,10 +56,17 @@ namespace Oyster
Core::PipelineManager::Init(path + L"PixelGatherData" + end, ShaderType::Pixel, L"Geometry"); Core::PipelineManager::Init(path + L"PixelGatherData" + end, ShaderType::Pixel, L"Geometry");
Core::PipelineManager::Init(path + L"VertexGatherData" + end, ShaderType::Vertex, L"Geometry"); Core::PipelineManager::Init(path + L"VertexGatherData" + end, ShaderType::Vertex, L"Geometry");
Core::PipelineManager::Init(path + L"LightPass" + end, ShaderType::Compute, L"LightPass"); Core::PipelineManager::Init(path + L"LightPass" + end, ShaderType::Compute, L"LightPass");
Core::PipelineManager::Init(path + L"PostPass" + end, ShaderType::Compute, L"PostPass");
return Core::Init::State::Success;
}
Core::Init::State Deffered::Init()
{
InitShaders();
//Create Buffers //Create Buffers
Buffer::BUFFER_INIT_DESC desc; Buffer::BUFFER_INIT_DESC desc;
desc.ElementSize = sizeof(Oyster::Math::Matrix); desc.ElementSize = sizeof(Definitions::PerModel);
desc.NumElements = 1; desc.NumElements = 1;
desc.InitData = NULL; desc.InitData = NULL;
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS; desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS;
@ -72,7 +88,7 @@ namespace Oyster
desc.Type = Buffer::STRUCTURED_BUFFER; desc.Type = Buffer::STRUCTURED_BUFFER;
PointLightsData.Init(desc); PointLightsData.Init(desc);
//Create States ////Create States
D3D11_RASTERIZER_DESC rdesc; D3D11_RASTERIZER_DESC rdesc;
rdesc.CullMode = D3D11_CULL_BACK; rdesc.CullMode = D3D11_CULL_BACK;
rdesc.FillMode = D3D11_FILL_SOLID; rdesc.FillMode = D3D11_FILL_SOLID;
@ -131,11 +147,82 @@ namespace Oyster
Core::Init::CreateLinkedShaderResourceFromTexture(&GBufferRTV[i],&GBufferSRV[i],NULL); Core::Init::CreateLinkedShaderResourceFromTexture(&GBufferRTV[i],&GBufferSRV[i],NULL);
} }
for(int i = 0; i < Resources::Deffered::LBufferSize; ++i)
{
Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&LBufferSRV[i],&LBufferUAV[i]);
}
Buffer* b = &PointLightsData; Buffer* b = &PointLightsData;
Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL); Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL);
srand(time(0));
//SSAO
Math::Vector3 kernel[KernelSize];
Math::Vector3 random[SampleSpread];
for(int i = 0;i < KernelSize; ++i)
{
kernel[i] = Oyster::Math::Vector3::null;
while( kernel[i] == Oyster::Math::Vector3::null )
{
kernel[i] = Oyster::Math::Vector3(
(float)rand() / (RAND_MAX + 1) * (1 - -1) + -1,
(float)rand() / (RAND_MAX + 1) * (1 - -1) + -1,
(float)rand() / (RAND_MAX + 1) * (1 - 0) + 0);
}
kernel[i].Normalize();
//Create ShaderEffects float scale = float(i) / float(KernelSize);
scale = (0.1f*(1 - scale * scale) + 1.0f *( scale * scale));
kernel[i] *= scale;
}
for( int i = 0; i < SampleSpread; ++i)
{
random[i] = Oyster::Math::Vector3::null;
while( random[i] == Oyster::Math::Vector3::null )
{
random[i] = Oyster::Math::Vector3(
(float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1,
(float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1,
0.0f);
}
random[i].Normalize();
}
//kernel[0] = Math::Vector3(0,1,1);
//kernel[0].Normalize();
D3D11_TEXTURE1D_DESC T1desc;
T1desc.Width = KernelSize;
T1desc.MipLevels = T1desc.ArraySize = 1;
T1desc.Format = DXGI_FORMAT_R32G32B32_FLOAT;
T1desc.Usage = D3D11_USAGE_DEFAULT;
T1desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
T1desc.CPUAccessFlags = 0;
T1desc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA sphere;
sphere.pSysMem = kernel;
D3D11_SUBRESOURCE_DATA rnd;
rnd.pSysMem = random;
ID3D11Texture1D *pTexture1[2];
Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1[0] );
Core::device->CreateShaderResourceView( pTexture1[0], 0, &SSAOKernel );
pTexture1[0]->Release();
T1desc.Width = SampleSpread;
Core::device->CreateTexture1D( &T1desc, &rnd, &pTexture1[1] );
Core::device->CreateShaderResourceView( (pTexture1[1]), 0, &SSAORandom );
pTexture1[1]->Release();
////Create ShaderEffects
////---------------- Geometry Pass Setup ----------------------------
GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Geometry"); GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Geometry");
GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Geometry"); GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Geometry");
@ -161,8 +248,12 @@ namespace Oyster
} }
GeometryPass.depth = Core::depthStencil; GeometryPass.depth = Core::depthStencil;
////---------------- Light Pass Setup ----------------------------
LightPass.Shaders.Compute = GetShader::Compute(L"LightPass"); LightPass.Shaders.Compute = GetShader::Compute(L"LightPass");
LightPass.UAV.Compute.push_back(Core::backBufferUAV); for(int i = 0; i<Deffered::LBufferSize;++i)
{
LightPass.UAV.Compute.push_back(LBufferUAV[i]);
}
for(int i = 0; i<Deffered::GBufferSize;++i) for(int i = 0; i<Deffered::GBufferSize;++i)
{ {
LightPass.SRV.Compute.push_back(GBufferSRV[i]); LightPass.SRV.Compute.push_back(GBufferSRV[i]);
@ -170,7 +261,16 @@ namespace Oyster
LightPass.SRV.Compute.push_back(Core::depthStencilUAV); LightPass.SRV.Compute.push_back(Core::depthStencilUAV);
LightPass.CBuffers.Compute.push_back(LightConstantsData); LightPass.CBuffers.Compute.push_back(LightConstantsData);
LightPass.SRV.Compute.push_back(PointLightView); LightPass.SRV.Compute.push_back(PointLightView);
LightPass.SRV.Compute.push_back(SSAOKernel);
LightPass.SRV.Compute.push_back(SSAORandom);
////---------------- Post Pass Setup ----------------------------
PostPass.Shaders.Compute = GetShader::Compute(L"PostPass");
for(int i = 0; i<Deffered::LBufferSize;++i)
{
PostPass.SRV.Compute.push_back(LBufferSRV[i]);
}
PostPass.UAV.Compute.push_back(Core::backBufferUAV);
return Core::Init::State::Success; return Core::Init::State::Success;
} }
@ -181,6 +281,9 @@ namespace Oyster
Resources::Deffered::VPData.~Buffer(); Resources::Deffered::VPData.~Buffer();
Resources::Deffered::LightConstantsData.~Buffer(); Resources::Deffered::LightConstantsData.~Buffer();
Resources::Deffered::PointLightsData.~Buffer(); Resources::Deffered::PointLightsData.~Buffer();
SAFE_RELEASE(Resources::Deffered::PointLightView);
SAFE_RELEASE(Deffered::SSAOKernel);
SAFE_RELEASE(Deffered::SSAORandom);
for(int i = 0; i< GBufferSize; ++i) for(int i = 0; i< GBufferSize; ++i)
{ {
@ -188,22 +291,10 @@ namespace Oyster
SAFE_RELEASE(GBufferSRV[i]); SAFE_RELEASE(GBufferSRV[i]);
} }
for(int i = 0; i< LBufferSize; ++i)
for(int i = 0; i < (int)GeometryPass.CBuffers.Vertex.size(); ++i)
{ {
SAFE_RELEASE(GeometryPass.CBuffers.Vertex[i]); SAFE_RELEASE(LBufferUAV[i]);
} SAFE_RELEASE(LBufferSRV[i]);
for(int i = 0; i < (int)GeometryPass.CBuffers.Pixel.size(); ++i)
{
SAFE_RELEASE(GeometryPass.CBuffers.Pixel[i]);
}
for(int i = 0; i < (int)GeometryPass.CBuffers.Geometry.size(); ++i)
{
SAFE_RELEASE(GeometryPass.CBuffers.Geometry[i]);
}
for(int i = 0; i < (int)GeometryPass.CBuffers.Compute.size(); ++i)
{
SAFE_RELEASE(GeometryPass.CBuffers.Compute[i]);
} }
SAFE_RELEASE(GeometryPass.IAStage.Layout); SAFE_RELEASE(GeometryPass.IAStage.Layout);

View File

@ -15,6 +15,7 @@ namespace Oyster
public: public:
static const int GBufferSize = 2; static const int GBufferSize = 2;
static const int LBufferSize = 3;
static const int MaxLightSize = 100; static const int MaxLightSize = 100;
//! GBuffers //! GBuffers
//! 0 = Diffuse + SpecKoeff //! 0 = Diffuse + SpecKoeff
@ -22,8 +23,14 @@ namespace Oyster
static ID3D11RenderTargetView* GBufferRTV[GBufferSize]; static ID3D11RenderTargetView* GBufferRTV[GBufferSize];
static ID3D11ShaderResourceView* GBufferSRV[GBufferSize]; static ID3D11ShaderResourceView* GBufferSRV[GBufferSize];
static ID3D11UnorderedAccessView* LBufferUAV[LBufferSize];
static ID3D11ShaderResourceView* LBufferSRV[LBufferSize];
static Core::PipelineManager::RenderPass GeometryPass; static Core::PipelineManager::RenderPass GeometryPass;
static Core::PipelineManager::RenderPass LightPass; static Core::PipelineManager::RenderPass LightPass;
static Core::PipelineManager::RenderPass PostPass;
static Core::Buffer ModelData; static Core::Buffer ModelData;
static Core::Buffer VPData; static Core::Buffer VPData;
@ -33,7 +40,12 @@ namespace Oyster
static Core::Buffer PointLightsData; static Core::Buffer PointLightsData;
static ID3D11ShaderResourceView* PointLightView; static ID3D11ShaderResourceView* PointLightView;
static ID3D11ShaderResourceView* SSAOKernel;
static ID3D11ShaderResourceView* SSAORandom;
static Core::Init::State Init(); static Core::Init::State Init();
static Core::Init::State InitShaders();
static void Clean(); static void Clean();
}; };
} }

Some files were not shown because too many files have changed in this diff Show More