Broekn branch not broekn more

This commit is contained in:
Dennis Andersen 2014-01-29 10:18:01 +01:00
parent 91e825dbfb
commit 36f057d2cc
53 changed files with 1305 additions and 1486 deletions

View File

@ -32,9 +32,6 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameLogic", "Game\GameLogic\GameLogic.vcxproj", "{B1195BB9-B3A5-47F0-906C-8DEA384D1520}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasLauncher", "Game\DanBiasLauncher\DanBiasLauncher.vcxproj", "{8690FDDF-C5B7-4C42-A337-BD5243F29B85}"
ProjectSection(ProjectDependencies) = postProject
{52380DAA-0F4A-4D97-8E57-98DF39319CAF} = {52380DAA-0F4A-4D97-8E57-98DF39319CAF}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkAPI", "Network\NetworkAPI\NetworkAPI.vcxproj", "{460D625F-2AC9-4559-B809-0BA89CEAEDF4}"
EndProject
@ -44,8 +41,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServerLauncher", "Ga
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServerDependencies", "Game\ServerDependencies\ServerDependencies.vcxproj", "{52380DAA-0F4A-4D97-8E57-98DF39319CAF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameServer", "Game\GameServer\GameServer.vcxproj", "{143BD516-20A1-4890-A3E4-F8BFD02220E7}"
EndProject
Global
@ -274,18 +269,6 @@ Global
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Win32.ActiveCfg = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Win32.Build.0 = Debug|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.ActiveCfg = Debug|x64
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.Build.0 = Debug|x64
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Mixed Platforms.Build.0 = Release|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Win32.ActiveCfg = Release|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Win32.Build.0 = Release|Win32
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|x64.ActiveCfg = Release|x64
{52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|x64.Build.0 = Release|x64
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Win32.ActiveCfg = Debug|Win32
@ -313,7 +296,6 @@ Global
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{060B1890-CBF3-4808-BA99-A4776222093B} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{52380DAA-0F4A-4D97-8E57-98DF39319CAF} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{143BD516-20A1-4890-A3E4-F8BFD02220E7} = {20720CA7-795C-45AD-A302-9383A6DD503A}
EndGlobalSection
EndGlobal

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.2">
<diagram program="umlet" version="12.1">
<zoom_level>10</zoom_level>
<element>
<id>UMLClass</id>
<coordinates>
<x>380</x>
<y>360</y>
<x>610</x>
<y>340</y>
<w>100</w>
<h>30</h>
</coordinates>
@ -16,8 +16,8 @@
<element>
<id>UMLClass</id>
<coordinates>
<x>360</x>
<y>540</y>
<x>580</x>
<y>480</y>
<w>160</w>
<h>80</h>
</coordinates>
@ -28,77 +28,33 @@
/players./</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>560</x>
<y>360</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>LobbyClient</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>400</x>
<y>460</y>
<w>50</w>
<h>100</h>
<x>620</x>
<y>340</y>
<w>60</w>
<h>160</h>
</coordinates>
<panel_attributes>lt=-&gt;&gt;&gt;&gt;</panel_attributes>
<additional_attributes>30;80;30;30</additional_attributes>
<additional_attributes>30;140;40;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>450</x>
<y>340</y>
<w>130</w>
<x>710</x>
<y>480</y>
<w>100</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;&gt;-</panel_attributes>
<additional_attributes>110;30;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>460</x>
<y>270</y>
<w>170</w>
<h>110</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;&gt;-</panel_attributes>
<additional_attributes>150;90;150;30;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>490</x>
<y>450</y>
<w>140</w>
<h>140</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;&gt;-</panel_attributes>
<additional_attributes>120;30;120;120;30;120</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>460</x>
<y>180</y>
<w>400</w>
<h>150</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>380;130;170;130;170;30;30;30</additional_attributes>
<panel_attributes>lt=&gt;&gt;&gt;&gt;-</panel_attributes>
<additional_attributes>80;30;30;30</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>370</x>
<y>200</y>
<x>600</x>
<y>180</y>
<w>120</w>
<h>120</h>
</coordinates>
@ -108,42 +64,19 @@
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>400</x>
<y>290</y>
<x>630</x>
<y>270</y>
<w>50</w>
<h>90</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;&gt;&gt;-</panel_attributes>
<additional_attributes>30;70;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>600</x>
<y>300</y>
<w>260</w>
<h>80</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>240;30;30;30;30;60</additional_attributes>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>840</x>
<y>290</y>
<w>120</w>
<h>50</h>
</coordinates>
<panel_attributes>NetworkAPI
bg=#a21aff</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>360</x>
<y>120</y>
<x>590</x>
<y>100</y>
<w>130</w>
<h>40</h>
</coordinates>
@ -154,8 +87,8 @@ DanBiasServerAPI</panel_attributes>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>400</x>
<y>130</y>
<x>630</x>
<y>110</y>
<w>50</w>
<h>90</h>
</coordinates>
@ -166,10 +99,10 @@ DanBiasServerAPI</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>150</x>
<y>360</y>
<x>1060</x>
<y>330</y>
<w>120</w>
<h>30</h>
<h>50</h>
</coordinates>
<panel_attributes>NetworkSession</panel_attributes>
<additional_attributes/>
@ -177,41 +110,41 @@ DanBiasServerAPI</panel_attributes>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>180</x>
<y>270</y>
<w>210</w>
<h>110</h>
<x>690</x>
<y>220</y>
<w>390</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=-&gt;&gt;&gt;&gt;&gt;</panel_attributes>
<additional_attributes>190;30;30;30;30;90</additional_attributes>
<panel_attributes>lt=-&lt;&lt;&lt;&lt;</panel_attributes>
<additional_attributes>30;30;370;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>240</x>
<y>340</y>
<w>160</w>
<x>680</x>
<y>320</y>
<w>400</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=-&gt;&gt;&gt;&gt;&gt;</panel_attributes>
<additional_attributes>140;30;30;30</additional_attributes>
<additional_attributes>30;30;380;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>180</x>
<y>360</y>
<w>200</w>
<h>210</h>
<x>690</x>
<y>340</y>
<w>390</w>
<h>160</h>
</coordinates>
<panel_attributes>lt=-&gt;&gt;&gt;&gt;&gt;</panel_attributes>
<additional_attributes>180;190;30;190;30;30</additional_attributes>
<additional_attributes>30;140;40;40;370;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>840</x>
<y>410</y>
<x>460</x>
<y>640</y>
<w>120</w>
<h>50</h>
</coordinates>
@ -222,164 +155,19 @@ bg=blue</panel_attributes>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>600</x>
<y>360</y>
<w>260</w>
<h>90</h>
<x>370</x>
<y>530</y>
<w>350</w>
<h>290</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>240;70;30;70;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>840</x>
<y>350</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>PhysicsAPI
bg=blue
--
</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>630</x>
<y>340</y>
<w>230</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=.&lt;&lt;</panel_attributes>
<additional_attributes>210;30;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>490</x>
<y>420</y>
<w>370</w>
<h>190</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>350;30;190;30;190;170;30;170</additional_attributes>
<additional_attributes>90;150;30;270;330;240;240;30</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>170</x>
<y>160</y>
<w>130</w>
<h>90</h>
</coordinates>
<panel_attributes>ServerInitReader
--
Helper to load ini files to server
elementstyle=wordwrap
</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>270</x>
<y>180</y>
<w>120</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;.
</panel_attributes>
<additional_attributes>100;30;30;30</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>360</x>
<y>440</y>
<w>160</w>
<h>50</h>
</coordinates>
<panel_attributes>GameSessionManager
--
/Creates game sessions/</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>400</x>
<y>360</y>
<w>50</w>
<h>100</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;-</panel_attributes>
<additional_attributes>30;30;30;80</additional_attributes>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>840</x>
<y>470</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>ProtocolManager
bg=#aaaaa</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>160</x>
<y>360</y>
<w>770</w>
<h>300</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>750;150;750;280;30;280;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>930</x>
<y>300</y>
<w>70</w>
<h>210</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>30;190;50;190;50;30;30;30</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>10</x>
<y>350</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>/&lt;&lt;interface&gt;&gt;/
INetworkSession</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>100</x>
<y>340</y>
<w>70</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=-&gt;&gt;&gt;&gt;&gt;</panel_attributes>
<additional_attributes>50;30;30;30</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>560</x>
<y>450</y>
<x>790</x>
<y>500</y>
<w>100</w>
<h>30</h>
</coordinates>
@ -389,28 +177,91 @@ INetworkSession</panel_attributes>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>580</x>
<y>360</y>
<w>50</w>
<h>110</h>
<x>670</x>
<y>530</y>
<w>150</w>
<h>180</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;&gt;-</panel_attributes>
<additional_attributes>30;30;30;90</additional_attributes>
<panel_attributes>lt=&lt;&lt;.</panel_attributes>
<additional_attributes>130;160;30;30</additional_attributes>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>800</x>
<y>670</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>GameProtocols
bg=#aaaaa</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Package</type>
<coordinates>
<x>1040</x>
<y>200</y>
<w>160</w>
<h>190</h>
</coordinates>
<panel_attributes>NetworkAPI
bg=#a21aff</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>0</x>
<y>460</y>
<w>160</w>
<h>50</h>
<x>1060</x>
<y>280</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>MapManager
--
Manages all map stuff.
elementstyle=wordwrap
</panel_attributes>
<panel_attributes>NetworkClient</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1060</x>
<y>230</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>NetworkServer</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>690</x>
<y>240</y>
<w>390</w>
<h>80</h>
</coordinates>
<panel_attributes>lt=-&gt;</panel_attributes>
<additional_attributes>30;30;200;30;200;60;370;60</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>690</x>
<y>260</y>
<w>390</w>
<h>100</h>
</coordinates>
<panel_attributes>lt=-&lt;&lt;&lt;&lt;</panel_attributes>
<additional_attributes>30;30;180;30;180;80;370;80</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>860</x>
<y>270</y>
<w>380</w>
<h>260</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;&gt;-</panel_attributes>
<additional_attributes>320;30;360;30;360;230;30;240</additional_attributes>
</element>
</diagram>

View File

@ -192,6 +192,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="GameClientState\Camera.cpp" />
<ClCompile Include="GameClientState\C_obj\C_DynamicObj.cpp" />
<ClCompile Include="GameClientState\C_obj\C_Player.cpp" />
<ClCompile Include="GameClientState\C_obj\C_StaticObj.cpp" />
@ -205,6 +206,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClientRecieverFunc.h" />
<ClInclude Include="GameClientState\Camera.h" />
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
<ClInclude Include="GameClientState\C_obj\C_Player.h" />
<ClInclude Include="GameClientState\C_obj\C_StaticObj.h" />

View File

@ -61,18 +61,16 @@ namespace DanBias
return DanBiasClientReturn_Error;
m_data->recieverObj = new GameRecieverObject;
m_data->recieverObj->Connect(desc.port, desc.IP);
m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object);
m_data->recieverObj->nwClient->Connect(desc.port, desc.IP);
if (!m_data->recieverObj->nwClient->IsConnected())
if (!m_data->recieverObj->IsConnected())
{
// failed to connect
return DanBiasClientReturn_Error;
}
// Start in lobby state
m_data->recieverObj->gameClientState = new Client::LobbyState();
if(!m_data->recieverObj->gameClientState->Init(m_data->recieverObj->nwClient))
if(!m_data->recieverObj->gameClientState->Init(m_data->recieverObj))
return DanBiasClientReturn_Error;
m_data->timer = new Utility::WinTimer(); //why dynamic memory?
@ -157,7 +155,7 @@ namespace DanBias
return E_FAIL;
break;
}
m_data->recieverObj->gameClientState->Init(m_data->recieverObj->nwClient); // send game client
m_data->recieverObj->gameClientState->Init(m_data->recieverObj); // send game client
}
return S_OK;
@ -184,10 +182,9 @@ namespace DanBias
{
m_data->recieverObj->gameClientState->Release();
delete m_data->recieverObj->gameClientState;
m_data->recieverObj->nwClient->Disconnect();
delete m_data->recieverObj->nwClient;
delete m_data->timer;
m_data->recieverObj->Disconnect();
delete m_data->recieverObj;
delete m_data->timer;
delete m_data->inputObj;
delete m_data;

View File

@ -1,11 +1,12 @@
#ifndef DANBIAS_CLIENTRECIEVEROBJECT_H
#define DANBIAS_CLIENTRECIEVEROBJECT_H
//WTF!? No headers included???
namespace DanBias
{
struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
struct GameRecieverObject :public Oyster::Network::NetworkClient
{
Oyster::Network::NetworkClient* nwClient;
Client::GameClientState* gameClientState;
// receiver function for server messages

View File

@ -8,6 +8,7 @@ struct C_Player::myData
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
Oyster::Graphics::Model::Model *model;
Oyster::Math3D::Float4 lookDir;
int ID;
}privData;
@ -29,7 +30,7 @@ void C_Player::Init(ModelInitData modelInit)
privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
privData->lookDir = Oyster::Math3D::Float4 (0,0,1,0);
}
void C_Player::setPos(Oyster::Math::Float4x4 world)
{

View File

@ -0,0 +1,192 @@
#include "Camera.h"
Camera::Camera()
{
this->m_position = Oyster::Math::Float3(0, 50, 0);
this->mRight = Oyster::Math::Float3(1, 0, 0);
this->mUp = Oyster::Math::Float3(0, 1, 0);
this->mLook = Oyster::Math::Float3(0, 0, 1);
}
Camera::~Camera()
{
}
void Camera::SetPosition(const Oyster::Math::Float3& v)
{
this->m_position = v;
}
Oyster::Math::Float3 Camera::GetPosition()const
{
return this->m_position;
}
Oyster::Math::Float3 Camera::GetRight()const
{
return this->mRight;
}
Oyster::Math::Float3 Camera::GetUp()const
{
return this->mUp;
}
Oyster::Math::Float3 Camera::GetLook()const
{
return this->mLook;
}
float Camera::GetNearZ()const
{
return this->mNearZ;
}
float Camera::GetFarZ()const
{
return this->mFarZ;
}
float Camera::GetAspect()const
{
return this->mAspect;
}
Oyster::Math::Float3 Camera::CrossMatrix(const Oyster::Math::Float3& vector, const Oyster::Math::Float4x4& matrix)
{
Oyster::Math::Float3 vec;
vec.x = matrix.m11*vector.x + matrix.m12*vector.y + matrix.m13*vector.z;
vec.y = matrix.m21*vector.x + matrix.m22*vector.y + matrix.m23*vector.z;
vec.z = matrix.m31*vector.x + matrix.m32*vector.y + matrix.m33*vector.z;
return vec;
}
void Camera::SetLens(float fovY, float aspect, float zn, float zf)
{
this->mFovY = fovY;
this->mAspect = aspect;
this->mNearZ = zn;
this->mFarZ = zf;
/*float yScale = tan((Oyster::Math::pi*0.5f) - (mFovY*0.5f));
float xScale = yScale/this->mAspect;
mProj = Oyster::Math::Float4x4(xScale, 0, 0, 0,
0, yScale, 0, 0,
0, 0, zf/(zf-zn), 1,
0, 0, -zn*zf/(zf-zn), 0);
mProj.Transpose();*/
mProj = Oyster::Math3D::ProjectionMatrix_Perspective(fovY,aspect,zn,zf);
}
void Camera::LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp)
{
Oyster::Math::Float3 L;
L = target - pos;
L.Normalize();
Oyster::Math::Float3 R;
R = worldUp.Cross(L);
R.Normalize();
Oyster::Math::Float3 U;
U = L.Cross(R);
this->m_position = pos;
this->mLook = L;
this->mRight = R;
this->mUp = U;
}
Oyster::Math::Float4x4 Camera::View()const
{
return this->mView;
}
Oyster::Math::Float4x4 Camera::Proj()const
{
return this->mProj;
}
Oyster::Math::Float4x4 Camera::ViewsProj()const
{
Oyster::Math::Float4x4 M;
M = mView * mProj;
return M;
}
void Camera::Walk(float dist)
{
this->m_position += dist*this->mLook;
}
void Camera::Strafe(float dist)
{
this->m_position += dist*this->mRight;
}
void Camera::Pitch(float angle)
{
float radians = angle * 0.0174532925f;
Oyster::Math::Float4x4 R;
Oyster::Math3D::RotationMatrix(radians,-mRight,R);
this->mUp = CrossMatrix(this->mUp, R);
this->mLook = CrossMatrix(this->mLook, R);
}
void Camera::Yaw(float angle)
{
float radians = angle * 0.0174532925f;
Oyster::Math::Float4x4 R;
Oyster::Math::Float3 up(0,1,0);
Oyster::Math3D::RotationMatrix(radians,-up,R);
this->mRight = CrossMatrix(this->mRight, R);
this->mUp = CrossMatrix(mUp, R);
this->mLook = CrossMatrix(this->mLook, R);
}
void Camera::UpdateViewMatrix()
{
mLook.Normalize();
mUp = mLook.Cross(mRight);
mUp.Normalize();
mRight = mUp.Cross(mLook);
mView = Oyster::Math3D::ViewMatrix_LookAtDirection(mLook, mUp, m_position);
/*
mLook.Normalize();
mUp = mLook.Cross(mRight);
mUp.Normalize();
mRight = mUp.Cross(mLook);
float x = -m_position.Dot(mRight);
float y = -m_position.Dot(mUp);
float z = -m_position.Dot(mLook);
mView.m11 = mRight.x;
mView.m21 = mRight.y;
mView.m31 = mRight.z;
mView.m41 = x;
mView.m12 = mUp.x;
mView.m22 = mUp.y;
mView.m32 = mUp.z;
mView.m42 = y;
mView.m13 = mLook.x;
mView.m23 = mLook.y;
mView.m33 = mLook.z;
mView.m43 = z;
mView.m14 = 0.0f;
mView.m24 = 0.0f;
mView.m34 = 0.0f;
mView.m44 = 1.0f;
mView.Transpose();*/
}

View File

@ -0,0 +1,63 @@
#ifndef CAMERA__H
#define CAMERA__H
#include "OysterMath.h"
class Camera
{
private:
Oyster::Math::Float3 m_position;
Oyster::Math::Float3 mRight;
Oyster::Math::Float3 mUp;
Oyster::Math::Float3 mLook;
float mNearZ;
float mFarZ;
float mAspect;
float mFovY;
Oyster::Math::Float4x4 mView;
Oyster::Math::Float4x4 mProj;
public:
Camera();
virtual ~Camera();
void SetPosition(const Oyster::Math::Float3& v);
Oyster::Math::Float3 GetPosition()const;
Oyster::Math::Float3 GetRight()const;
Oyster::Math::Float3 GetUp()const;
Oyster::Math::Float3 GetLook()const;
float GetNearZ()const;
float GetFarZ()const;
float GetAspect()const;
Oyster::Math::Float3 CrossMatrix(const Oyster::Math::Float3& v, const Oyster::Math::Float4x4& m);
void SetLens(float fovY, float aspect, float zn, float zf);
void LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp);
void setLook(Oyster::Math::Float3 look) { mLook = look; }
void setUp(Oyster::Math::Float3 up) { mUp = up; }
void setRight(Oyster::Math::Float3 right) { mRight = right; }
Oyster::Math::Float4x4 View()const;
Oyster::Math::Float4x4 Proj()const;
Oyster::Math::Float4x4 ViewsProj()const;
void Walk(float dist);
void Strafe(float dist);
void Pitch(float angle);
void Yaw(float angle);
void UpdateViewMatrix();
};
#endif

View File

@ -4,7 +4,7 @@
#include "C_obj/C_DynamicObj.h"
#include <Protocols.h>
#include "NetworkClient.h"
#include "Camera.h"
using namespace DanBias::Client;
@ -19,7 +19,6 @@ struct GameState::myData
gameStateState state;
}privData;
GameState::GameState(void)
@ -38,10 +37,12 @@ GameState::~GameState(void)
bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
{
// load models
camera = new Camera;
privData = new myData();
privData->state = gameStateState_loading;
privData->nwClient = nwClient;
privData->state = LoadGame();
return true;
}
GameState::gameStateState GameState::LoadGame()
@ -92,14 +93,14 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
modelData.id ++;
obj = new C_DynamicObj();
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
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.modelPath = L"..\\Content\\Models\\char_white.dan";
modelData.id ++;
modelData.id ++;*/
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
@ -110,7 +111,7 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.modelPath = L"..\\Content\\Models\\ball.dan";
modelData.id ++;
obj = new C_DynamicObj();
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
@ -119,10 +120,19 @@ bool GameState::LoadModels(std::wstring mapFile)
}
bool GameState::InitCamera(Oyster::Math::Float3 startPos)
{
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1);
Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0);
Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 20);
camera->LookAt(pos, dir, up);
camera->SetLens(3.14f/2, 1024/768, 1, 1000);
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
camera->UpdateViewMatrix();
privData->view = camera->View();
privData->view = Oyster::Math3D::ViewMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true;
@ -147,6 +157,53 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
// read server data
// update objects
{
readKeyInput(KeyInput);
camera->UpdateViewMatrix();
}
break;
case gameStateState_end:
return ClientState_Lobby;
break;
default:
break;
}
// send key input to server.
return ClientState_Same;
}
bool GameState::Render()
{
Oyster::Graphics::API::SetView(camera->View());
//Oyster::Graphics::API::SetProjection(camera->Proj());
//Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection(privData->proj);
Oyster::Graphics::API::NewFrame();
for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Render();
}
Oyster::Graphics::API::EndFrame();
return true;
}
bool GameState::Release()
{
for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}
delete this->camera;
delete privData;
privData = NULL;
return true;
}
void GameState::readKeyInput(InputClass* KeyInput)
{
bool send = false;
GameLogic::Protocol_PlayerMovement movePlayer;
movePlayer.bForward = false;
@ -162,10 +219,6 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
movePlayer.bForward = true;
send = true;
key_forward = true;
GameLogic::Protocol_General_Text tp;
tp.text = "What!?";
this->privData->nwClient->Send(tp);
}
}
else
@ -216,52 +269,33 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
//send delta mouse movement
if (KeyInput->IsMousePressed())
{
GameLogic::Protocol_PlayerMouse deltaMouseMove;
deltaMouseMove.dxMouse = KeyInput->GetYaw();
deltaMouseMove.dyMouse = KeyInput->GetPitch();
//privData->nwClient->Send(deltaMouseMove);
camera->Yaw(KeyInput->GetYaw());
camera->Pitch(KeyInput->GetPitch());
camera->UpdateViewMatrix();
GameLogic::Protocol_PlayerLook playerLookDir;
Oyster::Math::Float3 look = camera->GetLook();
playerLookDir.lookDirX = look.x;
playerLookDir.lookDirY = look.y;
playerLookDir.lookDirZ = look.z;
privData->nwClient->Send(playerLookDir);
}
if(KeyInput->IsKeyPressed(DIK_Z))
{
if(!key_Shoot)
{
GameLogic::Protocol_PlayerShot playerShot;
playerShot.hasShot = true;
privData->nwClient->Send(playerShot);
key_Shoot = true;
}
}
else
key_Shoot = false;
// send event data
//
if(KeyInput->IsKeyPressed(DIK_L))
privData->state = GameState::gameStateState_end;
}
break;
case gameStateState_end:
return ClientState_Lobby;
break;
default:
break;
}
// send key input to server.
return ClientState_Same;
}
bool GameState::Render()
{
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection(privData->proj);
Oyster::Graphics::API::NewFrame();
for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Render();
}
Oyster::Graphics::API::EndFrame();
return true;
}
bool GameState::Release()
{
for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}
delete privData;
privData = NULL;
return true;
}
void GameState::Protocol(ProtocolStruct* pos)
@ -290,13 +324,17 @@ void GameState::Protocol( ObjPos* pos )
for (unsigned int i = 0; i < privData->object.size(); i++)
{
if(privData->object[i] && privData->object[i]->GetId() == pos->object_ID)
if(privData->object[i]->GetId() == pos->object_ID)
{
privData->object[i]->setPos(world);
//privData->view = world;
//privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
//camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
//camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6])));
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
if(i == 0)
{
camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
camera->UpdateViewMatrix();
}
}
}
}

View File

@ -3,6 +3,7 @@
#include "GameClientState.h"
#include "OysterMath.h"
#include <string>
#include "Camera.h"
namespace DanBias
{
namespace Client
@ -21,6 +22,8 @@ private:
bool key_backward;
bool key_strafeRight;
bool key_strafeLeft;
bool key_Shoot;
Camera* camera;
struct myData;
myData* privData;
@ -33,6 +36,7 @@ public:
bool InitCamera(Oyster::Math::Float3 startPos) ;
gameStateState LoadGame();
void readKeyInput(InputClass* KeyInput);
bool Render()override;
bool Release()override;

View File

@ -1,21 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameLobby.h"
namespace DanBias
{
GameLobby::GameLobby(Utility::DynamicMemory::SmartPointer<LobbyClient> owner)
{
}
GameLobby::~GameLobby()
{
}
void GameLobby::Release()
{
}
}//End namespace DanBias

View File

@ -71,7 +71,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)WindowManager\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -79,7 +79,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)WindowManager\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -87,7 +87,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)WindowManager\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -95,7 +95,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\GameServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)WindowManager\;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -111,8 +111,8 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll</DelayLoadDLLs>
<AdditionalDependencies>GameServer_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -128,8 +128,8 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>DanBiasServer_$(PlatformShortName)D.dll;DanBiasGame_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll</DelayLoadDLLs>
<AdditionalDependencies>GameServer_$(PlatformShortName)D.lib;DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -149,8 +149,8 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>GameServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -170,13 +170,18 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>DanBiasServer_$(PlatformShortName).dll;DanBiasGame_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>GameServer_$(PlatformShortName).lib;DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ServerLauncher.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\WindowManager\WindowManager.vcxproj">
<Project>{35aea3c0-e0a7-4e1e-88cd-514aa5a442b1}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -5,7 +5,8 @@
#define NOMINMAX //Blame it on windows
#include <Windows.h>
#include <vld.h>
#include <iostream>
#include <WindowShell.h>
#include <GameServerAPI.h>
@ -16,13 +17,14 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
return cmdShow;
}
DanBias::GameServerAPI::GameInitDesc desc;
desc.connectionPort = 15151;
desc.maxNumberOfClients = 0;
desc.threaded = false;
if( !DanBias::GameServerAPI::Create(desc) == DanBias::DanBiasServerReturn_Sucess)
{
WindowShell::CreateConsoleWindow();
DanBias::GameServerAPI::GameInitDesc desc;
desc.listenPort = 15151;
if(DanBias::GameServerAPI::Create(desc) == DanBias::DanBiasServerReturn_Sucess)
{
DanBias::GameServerAPI::Start();
DanBias::GameServerAPI::Terminate();
}
return cmdShow;
}

View File

@ -56,33 +56,36 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_PlayerMouse :public Oyster::Network::CustomProtocolObject
struct Protocol_PlayerLook :public Oyster::Network::CustomProtocolObject
{
float dxMouse;
float dyMouse;
float lookDirX;
float lookDirY;
float lookDirZ;
Protocol_PlayerMouse()
Protocol_PlayerLook()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerMouseMovement;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerLookDir;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
this->protocol[3].type = Oyster::Network::NetAttributeType_Float;
}
const Protocol_PlayerMouse& operator=(Oyster::Network::CustomNetProtocol& val)
const Protocol_PlayerLook& operator=(Oyster::Network::CustomNetProtocol& val)
{
dxMouse = val[1].value.netFloat;
dyMouse = val[2].value.netFloat;
lookDirX = val[1].value.netFloat;
lookDirY = val[2].value.netFloat;
lookDirZ = val[3].value.netFloat;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = dxMouse;
this->protocol[2].value = dyMouse;
this->protocol[1].value = lookDirX;
this->protocol[2].value = lookDirY;
this->protocol[3].value = lookDirZ;
return &protocol;
}
@ -119,6 +122,32 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject
{
bool hasShot;
Protocol_PlayerShot()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerShot;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
}
const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val)
{
hasShot = val[1].value.netBool;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = hasShot;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
}
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -47,14 +47,15 @@
/***********[ 300 - 399 ]***********/
#define protocol_GameplayMIN 300
#define protocol_Gameplay_PlayerMovement 300
#define protocol_Gameplay_PlayerMouseMovement 301
#define protocol_Gameplay_PlayerLookDir 301
#define protocol_Gameplay_PlayerChangeWeapon 302
#define protocol_Gameplay_ObjectPickup 303
#define protocol_Gameplay_ObjectDamage 304
#define protocol_Gameplay_ObjectPosition 305
#define protocol_Gameplay_ObjectEnabled 306
#define protocol_Gameplay_ObjectDisabled 307
#define protocol_Gameplay_ObjectCreate 308
#define protocol_Gameplay_PlayerShot 303
#define protocol_Gameplay_ObjectPickup 304
#define protocol_Gameplay_ObjectDamage 305
#define protocol_Gameplay_ObjectPosition 306
#define protocol_Gameplay_ObjectEnabled 307
#define protocol_Gameplay_ObjectDisabled 308
#define protocol_Gameplay_ObjectCreate 309
#define protocol_GameplayMAX 399

View File

@ -7,26 +7,28 @@
#include <NetworkClient.h>
#include <PostBox\PostBox.h>
#include <GameAPI.h>
#include <Utilities.h>
namespace DanBias
{
/**
* Container to keep logic player and network client together as a unit.
*/
class GameClient
{
public:
GameClient(Oyster::Network::NetworkClient client, GameLogic::IPlayerData* player);
GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client, GameLogic::IPlayerData* player);
virtual~GameClient();
//void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
GameLogic::IPlayerData* GetPlayer();
GameLogic::IPlayerData* ReleasePlayer();
Oyster::Network::NetworkClient* GetClient();
Oyster::Network::NetworkClient ReleaseClient();
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> GetClient();
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> ReleaseClient();
int GetID() const;
private:
GameLogic::IPlayerData* player;
Oyster::Network::NetworkClient client;
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
int id;
};

View File

@ -8,6 +8,7 @@
#include <Protocols.h>
#include <PostBox\IPostBox.h>
#include <WinTimer.h>
#include "GameSession.h"
namespace DanBias
{
@ -16,33 +17,32 @@ namespace DanBias
public:
GameLobby();
virtual~GameLobby();
void Release();
void Update();
void Frame();
//void ClientEventCallback(NetEvent<Client*, Client::ClientEventArgs> e) override;
operator bool();
private:
void ParseEvents();
void ParseGeneralProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c);
void ParseLobbyProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c);
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c);
//Lobby events
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c);
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c);
//General events
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c);
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c);
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status:
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
void LobbyJoin(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
void LobbyLogin(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
void LobbyMainData(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
void LobbyGameData(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
private:
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
void ClientConnectedEvent(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
private:
Utility::WinTimer timer;
float refreshFrequency;
GameSession* gameSession;
};
}//End namespace DanBias
#endif // !DANBIASGAME_GAMELOBBY_H

View File

@ -1,33 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_GAME_SERVER_H
#define DANBIASSERVER_GAME_SERVER_H
#include "GameServerAPI.h"
#include "GameLobby.h"
#include <NetworkServer.h>
#include <Utilities.h>
namespace DanBias
{
class GameServer
{
public:
GameServer();
virtual~GameServer();
DanBiasServerReturn Create(const GameServerAPI::GameInitDesc& desc);
private:
static void Run(GameServer* owner);
void Run();
void Release();
private:
int maxClients;
Utility::DynamicMemory::SmartPointer<GameLobby> lobby;
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkServer> server;
};
}// End namspace DanBias
#endif // !DANBIASSERVER_DBSERVER_H

View File

@ -178,31 +178,20 @@
<ClCompile Include="Implementation\GameClient.cpp" />
<ClCompile Include="Implementation\GameLobby.cpp" />
<ClCompile Include="Implementation\GameServer.cpp" />
<ClCompile Include="Implementation\GameSessionManager.cpp" />
<ClCompile Include="Implementation\GameSession_Events.cpp" />
<ClCompile Include="Implementation\GameSession_General.cpp" />
<ClCompile Include="Implementation\GameSession_Logic.cpp" />
<ClCompile Include="Implementation\GameSession_Network.cpp" />
<ClCompile Include="Implementation\LobbyGeneralProtocolParser.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="Implementation\LobbyProtocolParser.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ClCompile Include="Implementation\GameSession_Gameplay.cpp" />
<ClCompile Include="Implementation\GameLobby_ProtocolParser.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClient.h" />
<ClInclude Include="GameLobby.h" />
<ClInclude Include="GameServer.h" />
<ClInclude Include="GameServerAPI.h" />
<ClInclude Include="GameSession.h" />
<ClInclude Include="GameSessionManager.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Misc\Misc.vcxproj">

View File

@ -20,6 +20,7 @@ namespace DanBias
{
DanBiasServerReturn_Error,
DanBiasServerReturn_Sucess,
DanBiasServerReturn_GameNotCreated,
};
extern "C"
@ -29,13 +30,16 @@ namespace DanBias
public:
struct GameInitDesc
{
//stuff
int connectionPort;
int maxNumberOfClients;
int listenPort;
bool threaded;
};
public:
static DanBiasServerReturn Create(const GameInitDesc& desc);
static void Start();
static void Stop();
static void Terminate();
};//End class DanBiasServer
}//End Extern "C"
} //End namspace DanBias

View File

@ -15,20 +15,24 @@
#include <GameAPI.h>
#include <Queue.h>
#include <NetworkSession.h>
#include <DynamicArray.h>
namespace DanBias
{
class GameSession : public Oyster::Thread::IThreadObject
class GameSession : public Oyster::Network::NetworkSession
, public Oyster::Thread::IThreadObject
{
public:
/**
* A container to use when initiating a new session
*/
struct GameDescription
{
std::wstring mapName;
NetworkSession* owner;
Utility::DynamicMemory::DynamicArray<NetworkClient> clients;
Oyster::Network::NetworkSession* owner;
Utility::DynamicMemory::DynamicArray<Oyster::Network::NetClient> clients;
};
public:
@ -44,13 +48,7 @@ namespace DanBias
/** Join an existing/running game session
* @param client The client to attach to the session
*/
bool Join(Utility::DynamicMemory::SmartPointer<NetworkSession> 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 disconnectClients = false);
bool Attach(Oyster::Network::NetClient client) override;
inline bool IsCreated() const { return this->isCreated; }
inline bool IsRunning() const { return this->isRunning; }
@ -58,31 +56,20 @@ namespace DanBias
//Private member functions
private:
//Handles all events recieved
void ParseEvents();
//Handles all gameplay events
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Handles all general events
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Adds a client to the client list
void InsertClient(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);
//Frame function, derived from IThreadObject
bool DoWork ( ) override;
//void ParseEvents();
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//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();
//Frame function, derived from IThreadObject
bool DoWork ( ) override;
//Private member variables
private:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
//Oyster::PostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
GameLogic::GameAPI& gameInstance;
GameLogic::ILevelData *levelData;

View File

@ -1,82 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_GAME_SEESION_MANAGER_H
#define DANBIASSERVER_GAME_SEESION_MANAGER_H
#include <NetworkSession.h>
#include <string>
#include <Utilities.h>
#include <DynamicArray.h>
using namespace Oyster::Network;
namespace DanBias
{
struct GameSessionDescription
{
std::wstring mapName;
Utility::DynamicMemory::DynamicArray<NetworkClient> clients;
NetworkSession* exitDestionation; //The new owner when session dies
};
struct GameSessionInfo
{
std::wstring mapName;
unsigned int numberOfPlayers;
float gametime;
};
class GameSessionManager
{
public:
/**
* Add a new game session.
* On success, the function returns the game instance id number greater than 0.
*/
static int AddSession(GameSessionDescription& instance, bool run);
/**
* Starts an existing game session
* @param session The session id recieved when created.
* @param run Indicates if the game session should start imidiatly when created.
* @return Returns false if session is not found.
*/
static bool StartSession(int session);
/**
* Join an exiting session
* @param session The session id recieved when created.
* @param client The client that is to join a game session
* @return Returns false on failure.
*/
static bool JoinSession(int session, Utility::DynamicMemory::SmartPointer<NetworkSession> client);
/**
* Gets information about a given session
* @param session The session id recieved when created.
* @param sessionInformation The output parameter that will be filled.
*/
static void GetSessionInfo(int session, GameSessionInfo& sessionInformation);
/**
* Close a session.
* @param session The session id recieved when created a session.
*/
static void CloseSession(int session);
/**
* Close all sessions.
*/
static void CloseSessions();
/**
* Get total sessions running
* @return Returns the total sessions curently running.
*/
static int GetSessionSize();
private:
friend class AdminInterface;
};
}
#endif // !DANBIASSERVER_GAME_SEESION_MANAGER_H

View File

@ -7,12 +7,13 @@
#include <Protocols.h>
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace DanBias;
using namespace GameLogic;
static int gameClientIDCount = 1;
GameClient::GameClient(Oyster::Network::NetworkClient client, GameLogic::IPlayerData* player)
GameClient::GameClient(SmartPointer<NetworkClient> client, GameLogic::IPlayerData* player)
{
this->client = client;
this->id = gameClientIDCount++;
@ -20,7 +21,7 @@ GameClient::GameClient(Oyster::Network::NetworkClient client, GameLogic::IPlayer
}
GameClient::~GameClient()
{
this->client.Disconnect();
this->client->Disconnect();
this->player = 0;
this->id = -1;
}
@ -35,13 +36,14 @@ GameLogic::IPlayerData* GameClient::ReleasePlayer()
this->player = 0;
return temp;
}
Oyster::Network::NetworkClient* GameClient::GetClient()
SmartPointer<Oyster::Network::NetworkClient> GameClient::GetClient()
{
return &this->client;
return this->client;
}
Oyster::Network::NetworkClient GameClient::ReleaseClient()
SmartPointer<Oyster::Network::NetworkClient> GameClient::ReleaseClient()
{
Oyster::Network::NetworkClient temp = this->client;
SmartPointer<Oyster::Network::NetworkClient> temp = this->client;
this->client = 0;
return temp;
}
int GameClient::GetID() const

View File

@ -18,34 +18,37 @@ namespace DanBias
{ }
void GameLobby::Release()
{ }
void GameLobby::Frame()
{
ParseEvents();
NetworkSession::CloseSession(true);
}
void GameLobby::Update()
{
this->ProcessClients();
}
GameLobby::operator bool()
{
return true;
}
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
{
}
void GameLobby::ClientConnectedEvent(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
switch (e.args.type)
{
case NetworkClient::ClientEventArgs::EventType_Disconnect:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
this->ParseProtocol(e.args.data.protocol, e.sender);
break;
}
//////// Private
void GameLobby::ParseEvents()
}
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
{
//if(this->box && !this->box->IsEmpty())
//{
// NetEvent &e = this->box->Fetch();
//
// short type = e.protocol[0].value.netShort;
//
// if(ProtocolIsLobby(type)) ParseLobbyProtocol(e.protocol, e.sender);
// else if(ProtocolIsGeneral(type)) ParseGeneralProtocol(e.protocol, e.sender);
//}
//Attach(client);
}
}//End namespace DanBias

View File

@ -0,0 +1,100 @@
#include "..\GameLobby.h"
using namespace DanBias;
using namespace GameLogic;
using namespace Oyster::Network;
void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClient* c)
{
switch (p[0].value.netShort)
{
//LobbyStartGame(GameLogic::Protocol_LobbyStartGame(p), c);
//LobbyRefresh(GameLogic::Protocol_LobbyRefresh(p), c);
//LobbyLogin(GameLogic::Protocol_LobbyLogin(p), c);
//LobbyJoin(GameLogic::Protocol_LobbyJoin(p), c);
//GeneralStatus(GameLogic::Protocol_General_Status(p), c);
//GeneralText(GameLogic::Protocol_General_Text(p), c);
case protocol_General_Status:
break;
case protocol_General_Text:
break;
case protocol_Lobby_Create:
break;
case protocol_Lobby_Start:
break;
case protocol_Lobby_Join:
break;
case protocol_Lobby_Login:
break;
case protocol_Lobby_Refresh:
break;
case protocol_Lobby_MainData:
break;
case protocol_Lobby_GameData:
break;
}
}
void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c)
{
switch (p.status)
{
case Protocol_General_Status::States_ready:
{
}
case Protocol_General_Status::States_idle:
{
}
case Protocol_General_Status::States_leave:
case Protocol_General_Status::States_disconected:
{
Detach(c)->Disconnect();
}
}
}
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c)
{
printf(p.text.c_str());
}
void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c)
{
}
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
{
}
void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
{
//for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
//{
// if (this->gameLobby[i]->GetID() == p.value)
// {
// this->gameLobby[i]->Attach(Detach(c));
// return;
// }
//}
}
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
{
}
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
{
//Dont need to handle this on the server...
}
void GameLobby::LobbyMainData(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
{
}
void GameLobby::LobbyGameData(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
{
}

View File

@ -3,137 +3,93 @@
/////////////////////////////////////////////////////////////////////
#define NOMINMAX
#include <Windows.h>
#include <WindowShell.h>
#include <iostream>
#include <vld.h>
#include "..\GameServer.h"
#include "..\GameSessionManager.h"
#include "..\GameServerAPI.h"
#include "..\GameLobby.h"
#include "..\GameSession.h"
#include <Thread\OysterThread.h>
#include <Utilities.h>
#include <NetworkServer.h>
#include <NetworkClient.h>
#include <thread>
#include <CollisionManager.h>
namespace DanBias
#include <WindowShell.h>
#include <Utilities.h>
#include <WinTimer.h>
#include <Thread\OysterThread.h>
using namespace DanBias;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace Utility;
namespace
{
using namespace Oyster::Network;
GameLobby lobby;
NetworkServer server;
WinTimer timer;
GameServerAPI instance;
//typedef void(*WorkerThreadFnc)(GameServerAPI*);
}
GameServer* instance = 0;
std::thread workerThread;
typedef void(*WorkerThreadFnc)(GameServer*);
DanBiasServerReturn GameServerAPI::Create(const GameInitDesc& desc)
DanBiasServerReturn GameServerAPI::Create(const GameInitDesc& desc)
{
if(server.Init(desc.listenPort, &lobby) == NetworkServer::ServerReturnCode_Error)
{
if(!instance)
instance = new GameServer();
return instance->Create(desc);
return DanBiasServerReturn_Error;
}
GameServer::GameServer()
: maxClients(0)
{ }
GameServer::~GameServer()
{ }
DanBiasServerReturn GameServer::Create(const GameServerAPI::GameInitDesc& desc)
{
this->maxClients = desc.maxNumberOfClients;
this->server = new NetworkServer();
this->lobby = new GameLobby();
if(desc.threaded)
{
if(!this->server->Init(desc.connectionPort, this->lobby))
return DanBiasServerReturn_Error;
if(!this->server->Start())
return DanBiasServerReturn_Error;
WorkerThreadFnc temp = GameServer::Run;
workerThread = std::thread(temp, this);
}
else
{
if(!this->server->Init(desc.connectionPort, this->lobby))
return DanBiasServerReturn_Error;
if(!this->server->Start())
return DanBiasServerReturn_Error;
Run();
}
std::printf("Server created!\t-\t%s: [%i]\n", server.GetLanAddress().c_str(), desc.listenPort);
return DanBiasServerReturn_Sucess;
}
void GameServer::Run(GameServer* owner)
{
}
void GameServerAPI::Start()
{
server.Start();
timer.reset();
while (true)
{
owner->server->ProcessConnectedClients();
owner->lobby->ProcessClients();
int c = server.ProcessConnectedClients();
if(c > 0) printf(" - [%i] client(s) connected!\n", c);
lobby.Update();
if(GetAsyncKeyState(0x51)) //Q for exit
break;
}
}
void GameServer::Run()
double total = timer.getElapsedSeconds();
int time = (int)total;
int hour, min, sec;
hour=time / 3600;
time=time % 3600;
min=time / 60;
time=time % 60;
sec = time;
printf( "Server has been running for: %i:%i:%i - [hh:mm:ss] \n\n", hour, min, sec );
printf( "Terminating in : ");
for (int i = 0; i < 4; i++)
{
while (true)
{
this->server->ProcessConnectedClients();
this->lobby->Frame();
if(GetAsyncKeyState(0x51)) //Q for exit
break;
}
}
void GameServer::Release()
{
GameSessionManager::CloseSessions();
printf( "%i ", 3-i );
Sleep(1000);
}
}
void GameServerAPI::Stop()
{
server.Stop();
lobby.ProcessClients();
}
void GameServerAPI::Terminate()
{
lobby.Release();
server.Shutdown();
printf( "Server terminated!" );
//void GameServer::ClientConnected(NetworkClient* client)
//{
// static bool myTest = false;
// static int sessionId = -1;
// printf("Client with ID [%i] connected.\n", client->GetID());
//
// if(!myTest)
// {
// Utility::DynamicMemory::SmartPointer<NetworkSession> c = new Client(client);
//
// GameSessionDescription desc;
// desc.mapName = L"test";
// desc.clients.Push(c);
// desc.exitDestionation = this->lobby;
// if((sessionId = GameSessionManager::AddSession(desc, true)) == 0)
// printf("Failed to create a game session\n");
// myTest = true;
// //myTest = new GameSession();
// //
// //DanBias::GameSession::GameSessionDescription desc;
// //desc.owner = 0;
// //desc.clients.Push(c);
// //
// //if(!myTest->Create(desc)) return;
// //myTest->Run();
// }
// else
// {
// Utility::DynamicMemory::SmartPointer<NetworkSession> c = new NetworkSession(client);
// GameSessionManager::JoinSession(sessionId, c);
// }
//
//
// //Utility::DynamicMemory::SmartPointer<NetworkSession> c = new NetworkSession(client);
// //this->mainLobby->Attach(c, this->mainLobby->GetPostbox());
//}
}//End namespace DanBias
}

View File

@ -1,121 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\GameSessionManager.h"
#include "..\GameSession.h"
#include <DynamicArray.h>
using namespace DanBias;
using namespace Utility::DynamicMemory;
struct GameSessionData
{
DynamicArray< SmartPointer< GameSession > > sessions;
int freeSpot;
int Existst(int session)
{
for (unsigned int i = 0; i < sessions.Size(); i++)
{
if(!sessions[i] && freeSpot == -1) freeSpot = i;
if(sessions[i]->GetID() == session) return i;
}
return -1;
}
int GetFree()
{
for (unsigned int i = 0; i < sessions.Size(); i++)
{
if(!sessions[i])
{
this->freeSpot = i;
return this->freeSpot;
}
}
this->freeSpot = -1;
return this->freeSpot;
}
} gameSessionData;
int GameSessionManager::AddSession(GameSessionDescription& instance, bool run)
{
int k = gameSessionData.GetFree();
SmartPointer<GameSession> gs = new GameSession();
DanBias::GameSession::GameDescription desc;
desc.owner = instance.exitDestionation;
desc.clients = instance.clients;
desc.mapName = instance.mapName;
if(!gs->Create(desc)) return 0;
if(k == -1) gameSessionData.sessions.Push(gs);
else gameSessionData.sessions[k] = gs;
if(run) gs->Run();
return gs->GetID();
}
bool GameSessionManager::StartSession(int session)
{
int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return false;
gameSessionData.sessions[i]->Run();
return true;
}
bool GameSessionManager::JoinSession(int session, Utility::DynamicMemory::SmartPointer<NetworkSession> client)
{
int i = -1;
if((i = gameSessionData.Existst(session)) == -1) return false;
gameSessionData.sessions[i]->Join(client);
return true;
}
void GameSessionManager::GetSessionInfo(int session, GameSessionInfo& data)
{
memset(&data, 0, sizeof(GameSessionInfo));
int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return;
//data.gametime = gameSessionData.sessions[i]->
//data.mapName = gameSessionData.sessions[i]->
//data.numberOfPlayers = gameSessionData.sessions[i]->
}
void GameSessionManager::CloseSessions()
{
for (unsigned int i = 0; i < gameSessionData.sessions.Size(); i++)
{
gameSessionData.sessions[i]->CloseSession();
}
}
void GameSessionManager::CloseSession(int session)
{
int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return;
gameSessionData.sessions[i]->CloseSession();
}
int GameSessionManager::GetSessionSize()
{
return gameSessionData.sessions.Size();
}

View File

@ -4,14 +4,18 @@
#include "..\GameSession.h"
#include "..\GameClient.h"
#include <NetworkServerEventStruct.h>
#include <Protocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <OysterMath.h>
#define NOMINMAX
#include <Windows.h>
#define DELTA_TIME_20 0.05f
#define DELTA_TIME_24 0.04166666666666666666666666666667f
#define DELTA_TIME_30 0.03333333333333333333333333333333f
#define DELTA_TIME_60 0.01666666666666666666666666666667f
#define DELTA_TIME_120 0.00833333333333333333333333333333f
using namespace Utility::DynamicMemory;
using namespace Oyster;
@ -21,25 +25,45 @@ using namespace GameLogic;
namespace DanBias
{
void GameSession::ParseEvents()
bool GameSession::DoWork( )
{
if( !this->box->IsEmpty() )
if(this->isRunning)
{
NetworkSession::NetEvent &e = this->box->Fetch();
static int ii = 0;
printf("%i - Message recieved! [%i]\n", ii++, e.protocol[0].value);
double dt = this->timer.getElapsedSeconds();
gameInstance.SetFrameTimeLength((float)dt);
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
if(dt >= DELTA_TIME_20)
{
this->ProcessClients();
if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGameplayEvent(e.protocol, e.gameClient);
this->gameInstance.NewFrame();
if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGeneralEvent(e.protocol, e.gameClient);
this->timer.reset();
}
}
void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
return this->isRunning;
}
//void GameSession::ParseEvents()
//{
// if( !this->box->IsEmpty() )
// {
// NetworkSession::NetEvent &e = this->box->Fetch();
// static int ii = 0;
// printf("%i - Message recieved! [%i]\n", ii++, e.protocol[0].value);
//
// 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::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
@ -55,10 +79,10 @@ namespace DanBias
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
}
break;
case protocol_Gameplay_PlayerMouseMovement:
case protocol_Gameplay_PlayerLookDir:
{
Protocol_PlayerMouse m; m = p;
c->GetPlayer()->Rotate(m.dxMouse, m.dyMouse);
Protocol_PlayerLook m; m = p;
//c->GetPlayer()->Rotate(m.dxMouse, m.dyMouse);
}
break;
case protocol_Gameplay_PlayerChangeWeapon:
@ -67,19 +91,12 @@ namespace DanBias
case protocol_Gameplay_ObjectDamage:
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_disconected:
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
this->RemoveClient(c);
this->Detach(c->GetClient()->GetID());
break;
case GameLogic::Protocol_General_Status::States_idle:
@ -101,17 +118,18 @@ namespace DanBias
printf("Message recieved from (%i):\t %s\n", c->GetID(), temp.text.c_str());
}
break;
}
}
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
{
movedObject->GetID();
movedObject->GetOrientation();
}
void GameSession::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
{
}
}//End namespace DanBias

View File

@ -3,11 +3,11 @@
/////////////////////////////////////////////////////////////////////
#include "..\GameSession.h"
#include "..\GameClient.h"
#include "..\GameServer.h"
#include <Protocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#define NOMINMAX
#include <Windows.h>
@ -23,16 +23,18 @@ namespace DanBias
:gameInstance(GameAPI::Instance())
{
this->owner = 0;
this->box = 0;
this->isCreated = false;
this->isRunning = false;
}
GameSession::~GameSession()
{
delete this->box;
this->box = 0;
this->worker.Terminate();
this->clients.Clear();
this->gameInstance;
this->owner = 0;
this->isCreated = false;
this->isRunning = false;
}
bool GameSession::Create(GameDescription& desc)
@ -45,7 +47,6 @@ namespace DanBias
/* standard initialization of some data */
this->clients.Resize(desc.clients.Size());
this->box = new PostBox<NetworkSession::NetEvent>();
this->owner = desc.owner;
/* Initiate the game instance */
@ -61,18 +62,13 @@ namespace DanBias
return false;
}
/* Create a callback object */
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
/* Create the players in the game instance */
GameLogic::IPlayerData* p = 0;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
if( (p = this->gameInstance.CreatePlayer()) )
{
this->clients[i] = new GameClient(desc.clients[i], p, c);
this->clients[i] = new GameClient(desc.clients[i], p);
}
else
{
@ -81,12 +77,12 @@ namespace DanBias
}
/* Create the worker thread */
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS)
if(this->worker.Create(this, false) != OYSTER_THREAD_ERROR_SUCCESS)
return false;
this->worker.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_3);
/* Set some gameinstance data options */
/* Set some game instance data options */
this->gameInstance.SetSubscription(GameLogic::GameEvent::ObjectEventFunctionType_OnMove, GameSession::ObjectMove);
this->isCreated = true;
@ -95,106 +91,39 @@ namespace DanBias
void GameSession::Run()
{
if(this->isRunning) return;
if(this->clients.Size() > 0)
{
this->worker.Start();
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
this->isRunning = true;
}
}
bool GameSession::Join(Utility::DynamicMemory::SmartPointer<NetworkSession> client)
bool GameSession::Attach(Utility::DynamicMemory::SmartPointer<NetworkClient> 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;
client->SetOwner(this);
SmartPointer<GameClient> obj = new GameClient(client, this->gameInstance.CreatePlayer());
SmartPointer<GameClient> obj = new GameClient(client, this->gameInstance.CreatePlayer(), c);
InsertClient(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::InsertClient(SmartPointer<GameClient> obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(!clients[i])
{
clients[i] = obj;
return;
return true;
}
}
clients.Push(obj);
return true;
}
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

@ -1,74 +0,0 @@
/////////////////////////////////////////////////////////////////////
// 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>
#define DELTA_TIME_20 0.05f
#define DELTA_TIME_24 0.04166666666666666666666666666667f
#define DELTA_TIME_30 0.03333333333333333333333333333333f
#define DELTA_TIME_60 0.01666666666666666666666666666667f
#define DELTA_TIME_120 0.00833333333333333333333333333333f
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
bool GameSession::DoWork( )
{
if(this->isRunning)
{
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_ObjectCreate p(world, 2, "../Content/crate");
Send(p.GetProtocol());
Sleep(100);
}
double dt = this->timer.getElapsedSeconds();
gameInstance.SetFrameTimeLength((float)dt);
if(dt >= DELTA_TIME_20)
{
this->ParseEvents();
this->gameInstance.NewFrame();
this->UpdateGameObjects();
this->timer.reset();
}
}
return this->isRunning;
}
void GameSession::UpdateGameObjects()
{
if(clients.Size() >= 1 && clients[0])
{
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
Protocol_ObjectPosition p(world, 1);
Send(p.GetProtocol());
}
}
}//End namespace DanBias

View File

@ -1,29 +0,0 @@
/////////////////////////////////////////////////////////////////////
// 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,52 +0,0 @@
#include "GameLobby.h"
#include "NetworkSession.h"
using namespace DanBias;
using namespace GameLogic;
void GameLobby::ParseGeneralProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::NetworkSession* c)
{
switch (p[0].value.netShort)
{
case protocol_General_Status:
{
GeneralStatus(GameLogic::Protocol_General_Status(p), c);
} break;
case protocol_General_Text:
{
GeneralText(GameLogic::Protocol_General_Text(p), c);
} break;
}
}
//////////////////////////////////////////////////////
void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, DanBias::NetworkSession* c)
{
switch (p.status)
{
case Protocol_General_Status::States_ready:
{
}
case Protocol_General_Status::States_idle:
{
}
case Protocol_General_Status::States_leave:
{
}
case Protocol_General_Status::States_disconected:
{
Detach(c)->Disconnect();
}
}
}
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, DanBias::NetworkSession* c)
{
}

View File

@ -1,58 +0,0 @@
#include "..\GameLobby.h"
using namespace DanBias;
void GameLobby::ParseLobbyProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::NetworkSession* c)
{
switch (p[0].value.netShort)
{
case protocol_Lobby_Start:
LobbyStartGame(GameLogic::Protocol_LobbyStartGame(p), c);
break;
case protocol_Lobby_Refresh:
LobbyRefresh(GameLogic::Protocol_LobbyRefresh(p), c);
break;
case protocol_Lobby_Login:
{
LobbyLogin(GameLogic::Protocol_LobbyLogin(p), c);
} break;
case protocol_Lobby_Join:
{
LobbyJoin(GameLogic::Protocol_LobbyJoin(p), c);
} break;
}
}
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, DanBias::NetworkSession* c)
{
}
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, DanBias::NetworkSession* c)
{
double now = this->timer.getElapsedSeconds() + c->lastPoll;
if(now > this->refreshFrequency)
{
c->lastPoll = (float)now;
}
}
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyLogin& p, DanBias::NetworkSession* c)
{
}
void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, DanBias::NetworkSession* c)
{
for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
{
if (this->gameLobby[i]->GetID() == p.value)
{
this->gameLobby[i]->Attach(Detach(c));
return;
}
}
}

View File

@ -4,18 +4,19 @@
#include <vld.h>
#include "DanBiasGame.h"
#include <DanBiasServerAPI.h>
#include <GameServerAPI.h>
#include <thread>
void ServerFnc()
{
if( DanBias::DanBiasServerAPI::Initiate() == DanBias::DanBiasServerReturn_Sucess)
DanBias::GameServerAPI::GameInitDesc desc;
desc.listenPort = 15151;
if( DanBias::GameServerAPI::Create(desc) == DanBias::DanBiasServerReturn_Sucess)
{
DanBias::DanBiasServerAPI::Run();
DanBias::DanBiasServerAPI::Release();
DanBias::GameServerAPI::Start();
DanBias::GameServerAPI::Terminate();
}
Sleep(100);
}

View File

@ -71,7 +71,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\GameServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -79,7 +79,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\GameServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -87,7 +87,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\GameServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -95,7 +95,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\GameServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -110,7 +110,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -126,7 +126,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -146,7 +146,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -166,7 +166,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -177,6 +177,9 @@
<ProjectReference Include="..\DanBiasGame\DanBiasGame.vcxproj">
<Project>{2a1bc987-af42-4500-802d-89cd32fc1309}</Project>
</ProjectReference>
<ProjectReference Include="..\GameServer\GameServer.vcxproj">
<Project>{143bd516-20a1-4890-a3e4-f8bfd02220e7}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -118,15 +118,17 @@ using namespace Utility::DynamicMemory;
{
SmartPointer<RefData> data;
PrivateData(){}
PrivateData()
{
data = new RefData();
}
~PrivateData()
{
data.Release();
data = 0;
}
OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach)
{
if(data) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
data = new RefData();
if(!data) data = new RefData();
return data->Create(fnc, worker, start, detach);
}
OYSTER_THREAD_ERROR Terminate()
@ -205,9 +207,8 @@ using namespace Utility::DynamicMemory;
OysterThread::OysterThread()
{
this->privateData = new PrivateData();
}
:privateData(0)
{ }
OysterThread::OysterThread(const OysterThread& original)
{
this->privateData = new PrivateData(*original.privateData);
@ -229,7 +230,6 @@ OYSTER_THREAD_ERROR OysterThread::Create(IThreadObject* worker, bool start, bool
{
if(!this->privateData) this->privateData = new PrivateData();
if(this->privateData->data->isCreated) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
OwnerContainer c;
c.type = Oyster::Callback::CallbackType_Object;
c.value = worker;

View File

@ -7,6 +7,7 @@
#ifndef WINTIMER_H
#define WINTIMER_H
#define NOMINMAX
#include <Windows.h>
namespace Utility

View File

@ -4,36 +4,27 @@
#include "CustomNetProtocol.h"
#include <map>
#include "Translator.h"
#include "Utilities.h"
using namespace Oyster::Network;
using namespace Utility::DynamicMemory;
struct CustomNetProtocol::PrivateData
{
std::map<int, NetAttributeContainer> attributes;
std::map<int, NetAttributeContainer> attributes; //...Im an idiot
Utility::DynamicMemory::ReferenceCount *c;
PrivateData()
{ }
PrivateData( const CustomNetProtocol::PrivateData& o)
{
for (auto i = o.attributes.begin(); i != o.attributes.end(); i++)
{
if(i->second.type == NetAttributeType_CharArray)
{
size_t size = strlen(i->second.value.netCharPtr);
if(size == 0) continue;
//this->attributes = new std::map<int, NetAttributeContainer>();
this->c = new ReferenceCount();
c->Incref();
}
attributes[i->first].value.netCharPtr = new char[size + 1];
memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1);
attributes[i->first].type = NetAttributeType_CharArray;
}
else
{
attributes[i->first] = i->second;
}
}
}
~PrivateData()
{
delete c;
c = 0;
for (auto i = attributes.begin(); i != attributes.end(); i++)
{
RemoveAttribute(i->first);
@ -49,7 +40,6 @@ struct CustomNetProtocol::PrivateData
{
case NetAttributeType_CharArray:
delete [] i->second.value.netCharPtr;
//i->second.value.netCharPtr = 0;
break;
}
}
@ -64,17 +54,40 @@ CustomNetProtocol::CustomNetProtocol()
}
CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o)
{
this->privateData = new PrivateData(*o.privateData);
this->privateData = o.privateData;
if(this->privateData)
{
this->privateData->c = o.privateData->c;
this->privateData->c->Incref();
}
}
const CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o)
{
if(this->privateData && this->privateData->c)
{
if(this->privateData->c->Decref() == 0)
{
delete this->privateData;
this->privateData = new PrivateData(*o.privateData);
}
}
this->privateData = o.privateData;
if(this->privateData)
{
this->privateData->c = o.privateData->c;
this->privateData->c->Incref();
}
return *this;
}
CustomNetProtocol::~CustomNetProtocol()
{
if(this->privateData && this->privateData->c)
{
if(this->privateData->c->Decref() == 0)
{
delete this->privateData;
}
}
}
NetAttributeContainer& CustomNetProtocol::operator[](int ID)
{

View File

@ -88,16 +88,16 @@
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSDK_LibraryPath_x86);</LibraryPath>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(VCInstallDir)lib\amd64;$(VCInstallDir)atlmfc\lib\amd64;$(WindowsSDK_LibraryPath_x64);</LibraryPath>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -107,6 +107,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>NETWORKAPI_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)Misc\</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -121,6 +122,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>NETWORKAPI_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)Misc\</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -137,6 +139,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NETWORKAPI_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)Misc\</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -155,6 +158,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NETWORKAPI_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)Misc\</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@ -26,8 +26,9 @@ using namespace Utility::Container;
PrivateData
*************************************/
typedef NetworkClient::ClientEventArgs CEA;
struct NetDataContainer : public IThreadObject
{ //This struct is contained within a smart pointer. To avoide dependencies in link its implemented here..
struct NetworkClient::PrivateData : public IThreadObject
{
NetworkSession *owner;
NetworkClient *parent;
Connection connection;
@ -43,19 +44,17 @@ struct NetDataContainer : public IThreadObject
static unsigned int currID;
const unsigned int ID;
NetDataContainer()
PrivateData()
: ID(currID++)
, parent(0)
, owner(0)
{
InitWinSock();
this->thread.Create(this, true);
this->thread.Create(this, false);
this->thread.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_1);
}
NetDataContainer(const NetDataContainer& obj)
:ID(obj.ID) { }
~NetDataContainer()
~PrivateData()
{
ShutdownWinSock();
this->connection.Disconnect();
@ -73,7 +72,6 @@ struct NetDataContainer : public IThreadObject
return true;
}
int Send()
{
int errorCode = 0;
@ -96,7 +94,6 @@ struct NetDataContainer : public IThreadObject
return errorCode;
}
int Recv()
{
int errorCode = -1;
@ -119,33 +116,19 @@ struct NetDataContainer : public IThreadObject
this->recieveQueue.Push(e);
}
}
else
{
CEA parg;
parg.type = CEA::EventType_ProtocolFailedToRecieve;
parg.data.nothing = 0;
NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e = { this->parent, parg };
this->recieveQueue.Push(e);
}
//else
//{
// CEA parg;
// parg.type = CEA::EventType_ProtocolFailedToRecieve;
// parg.data.nothing = 0;
// NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e = { this->parent, parg };
// this->recieveQueue.Push(e);
//}
return errorCode;
}
};
struct NetworkClient::PrivateData
{
SmartPointer<NetDataContainer> dat;
public:
PrivateData()
{ this->dat = new NetDataContainer(); }
PrivateData(const PrivateData& obj)
{ this->dat = obj.dat; }
~PrivateData()
{ this->dat = 0; }
};
unsigned int NetDataContainer::currID = 0;
unsigned int NetworkClient::PrivateData::currID = 0;
/*************************************
NetworkClient
@ -155,21 +138,6 @@ NetworkClient::NetworkClient()
: privateData(0)
{ }
NetworkClient::NetworkClient(const NetworkClient& obj)
{
if(obj.privateData) this->privateData = new PrivateData(*obj.privateData);
else this->privateData = 0;
}
NetworkClient& NetworkClient::operator =(const NetworkClient& obj)
{
delete privateData;
this->privateData = 0;
if(obj.privateData) this->privateData = new PrivateData(*obj.privateData);
return *this;
}
NetworkClient::~NetworkClient()
{
if(this->privateData)
@ -181,22 +149,25 @@ NetworkClient::~NetworkClient()
bool NetworkClient::operator ==(const NetworkClient& obj)
{
return (this->privateData->dat->ID == obj.privateData->dat->ID);
return (this->privateData->ID == obj.privateData->ID);
}
bool NetworkClient::operator ==(const int& ID)
{
return this->privateData->dat->ID == ID;
return this->privateData->ID == ID;
}
void NetworkClient::ProcessMessages()
void NetworkClient::Update()
{
while (!this->privateData->dat->recieveQueue.IsEmpty())
while (!this->privateData->recieveQueue.IsEmpty())
{
if(this->privateData->dat->owner)
{
this->privateData->dat->owner->ClientEventCallback(this->privateData->dat->recieveQueue.Pop());
}
NetEvent<NetworkClient*, ClientEventArgs> temp = this->privateData->recieveQueue.Pop();
this->DataRecieved(temp);
//--------- Deprecate ---------
this->NetworkCallback(temp.args.data.protocol);
//------------------------------
}
}
@ -206,13 +177,16 @@ bool NetworkClient::Connect(int socket)
if(this->privateData) return false;
if(!this->privateData) this->privateData = new PrivateData();
int result = this->privateData->dat->connection.Connect(socket, true);
int result = this->privateData->connection.Connect(socket, false);
//Connect has succeeded
if(result == 0) return true;
if(result != 0) return false;
this->privateData->parent = this;
this->privateData->thread.Start();
//Connect has failed
return false;
return true;
}
bool NetworkClient::Connect(unsigned short port, const char serverIP[])
@ -221,46 +195,59 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[])
if(this->privateData) return false;
if(!this->privateData) this->privateData = new PrivateData();
int result = this->privateData->dat->connection.Connect(port, serverIP, false);
int result = this->privateData->connection.Connect(port, serverIP, false);
//Connect has succeeded
if(result == 0) return true;
if(result != 0) return false;
this->privateData->parent = this;
this->privateData->thread.Start();
//Connect has failed
return false;
return true;
}
void NetworkClient::Disconnect()
{
privateData->dat->connection.Disconnect();
privateData->dat->thread.Terminate();
privateData->connection.Disconnect();
privateData->thread.Terminate();
}
void NetworkClient::Send(CustomProtocolObject& protocol)
{
this->privateData->dat->sendQueue.Push(*protocol.GetProtocol());
this->privateData->sendQueue.Push(*protocol.GetProtocol());
}
void NetworkClient::Send(CustomNetProtocol* protocol)
{
this->privateData->dat->sendQueue.Push(*protocol);
this->privateData->sendQueue.Push(*protocol);
}
void NetworkClient::SetOwner(NetworkSession* owner)
{
this->privateData->dat->owner = owner;
this->privateData->owner = owner;
}
bool NetworkClient::IsConnected()
{
if(!this->privateData) return false;
return privateData->dat->connection.IsConnected();
return privateData->connection.IsConnected();
}
int NetworkClient::GetID() const
{
return this->privateData->dat->ID;
return this->privateData->ID;
}
void NetworkClient::DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e)
{
if(this->privateData->owner)
{
this->privateData->owner->ClientEventCallback(e);
}
}
void NetworkClient::NetworkCallback(Oyster::Network::CustomNetProtocol& p)
{}

View File

@ -41,8 +41,6 @@ namespace Oyster
public:
NetworkClient();
NetworkClient(const NetworkClient& obj);
NetworkClient& operator =(const NetworkClient& obj);
virtual ~NetworkClient();
bool operator ==(const NetworkClient& obj);
@ -51,7 +49,7 @@ namespace Oyster
/**
*
*/
void ProcessMessages();
void Update();
/**
*
@ -93,7 +91,21 @@ namespace Oyster
*/
int GetID() const;
/**
*
*/
virtual void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
/** ! Deprecate !
* Do not use this furthermore, instead use void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
* @see DataRecieved
*/
virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p);
private:
NetworkClient(const NetworkClient& obj);
NetworkClient& operator =(const NetworkClient& obj);
struct PrivateData;
PrivateData* privateData;
};

View File

@ -9,11 +9,14 @@
#include "../NetworkDependencies/PostBox.h"
#include "../NetworkDependencies/WinsockFunctions.h"
#include "../../Misc/Utilities.h"
#include "../../Misc/Thread/OysterThread.h"
#include "Utilities.h"
#include "Thread/OysterThread.h"
#ifndef _DEBUG
#include <winsock2.h>
#endif
using namespace Oyster::Network;
using namespace ::Server;
using namespace Utility::DynamicMemory;
using namespace Oyster::Thread;
@ -21,6 +24,41 @@ using namespace Oyster::Thread;
PrivateData
*************************************/
void Broadcast()
{
char pkt[4];
size_t pkt_length = 4;
sockaddr_in dest;
sockaddr_in local;
WSAData data;
WSAStartup( MAKEWORD( 2, 2 ), &data );
local.sin_family = AF_INET;
local.sin_addr.s_addr = inet_addr( "127.0.0.1" );
local.sin_port = 15151; // choose any
dest.sin_family = AF_INET;
dest.sin_port = htons( 15151 );
// create the socket
SOCKET s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
// bind to the local address
bind( s, (sockaddr *)&local, sizeof(local) );
std::string addr;
for (int i = 0; i < 256; i++)
{
addr = "192.168.0.";
char buff[5];
_itoa_s<5>(i, buff, 10);
addr.append(buff);
dest.sin_addr.s_addr = inet_addr( addr.c_str() );
// send the pkt
int ret = sendto( s, pkt, pkt_length, 0, (sockaddr *)&dest, sizeof(dest) );
}
}
struct NetworkServer::PrivateData : public IThreadObject
{
public:
@ -30,6 +68,7 @@ public:
, isInitiated(0)
, isReleased(0)
, isRunning(0)
, port(-1)
{ }
~PrivateData()
{ }
@ -37,11 +76,11 @@ public:
bool DoWork();
public:
IListener* listener;
Listener* listener;
PostBox<int> postBox; //Postbox for new clients
OysterThread thread; //Server thread
NetworkSession *mainSession;
Utility::Container::ThreadSafeQueue<NetworkClient> clientQueue;
Utility::Container::ThreadSafeQueue<SmartPointer<NetworkClient>> clientQueue;
bool isInitiated;
bool isReleased;
@ -51,6 +90,8 @@ public:
bool NetworkServer::PrivateData::DoWork()
{
//Broadcast();
/** Check for new clients **/
if(postBox.IsFull())
{
@ -61,10 +102,9 @@ bool NetworkServer::PrivateData::DoWork()
//Something went wrong somewhere... do we care?
}
SmartPointer<NetworkClient> client(new NetworkClient());
client->Connect(clientSocketNum);
Oyster::Network::NetworkClient client;
client.Connect(clientSocketNum);
if(this->mainSession)
this->clientQueue.Push(client);
}
@ -101,6 +141,7 @@ NetworkServer::~NetworkServer()
NetworkServer::ServerReturnCode NetworkServer::Init(const int& port, NetworkSession const* mainSession)
{
this->privateData->mainSession = const_cast<NetworkSession*>(mainSession);
//Check if it's a valid port
if(port == 0 || port == -1)
{
@ -117,7 +158,7 @@ NetworkServer::ServerReturnCode NetworkServer::Init(const int& port, NetworkSess
//Initiate listener
this->privateData->listener = new Listener(&this->privateData->postBox);
if(!((Listener*)this->privateData->listener)->Init(port, false))
if(!this->privateData->listener->Init(port, false))
{
return NetworkServer::ServerReturnCode_Error;
}
@ -129,14 +170,13 @@ NetworkServer::ServerReturnCode NetworkServer::Init(const int& port, NetworkSess
this->privateData->isInitiated = true;
this->privateData->isReleased = false;
this->privateData->mainSession = 0;
return NetworkServer::ServerReturnCode_Sucess;
}
NetworkServer::ServerReturnCode NetworkServer::Start()
{
//Start listener
if(!((Listener*)this->privateData->listener)->Start())
if(!this->privateData->listener->Start())
{
return NetworkServer::ServerReturnCode_Error;
}
@ -154,7 +194,7 @@ void NetworkServer::Stop()
{
if(this->privateData->listener)
{
((Listener*)this->privateData->listener)->Stop();
this->privateData->listener->Stop();
}
this->privateData->thread.Stop();
@ -164,6 +204,10 @@ void NetworkServer::Stop()
void NetworkServer::Shutdown()
{
if(this->privateData->mainSession)
{
this->privateData->mainSession->CloseSession(true);
}
if(this->privateData->listener)
{
this->privateData->listener->Shutdown();
@ -180,12 +224,23 @@ void NetworkServer::Shutdown()
this->privateData->isReleased = true;
}
void NetworkServer::ProcessConnectedClients()
int NetworkServer::ProcessConnectedClients()
{
int c = 0;
while(!this->privateData->clientQueue.IsEmpty())
{
if(this->privateData->mainSession) this->privateData->mainSession->Attach(this->privateData->clientQueue.Pop());
if(this->privateData->mainSession)
{
this->privateData->mainSession->ClientConnectedEvent(this->privateData->clientQueue.Pop());
c++;
}
else
{
//Clients have nowhere to go?
this->privateData->clientQueue.Pop()->Disconnect();
}
}
return c;
}
void NetworkServer::SetSession(NetworkSession const* mainSession)
@ -198,7 +253,7 @@ NetworkSession const* NetworkServer::GetMainSession()
return this->privateData->mainSession;
}
NetworkSession const* NetworkServer::ReleaseMainSessionSession()
NetworkSession const* NetworkServer::ReleaseMainSession()
{
NetworkSession const * temp;
temp = this->privateData->mainSession;
@ -211,7 +266,22 @@ bool NetworkServer::IsStarted() const
return this->privateData->isRunning;
}
std::string NetworkServer::GetLanAddress()
{
std::string szLocalIP;
char szHostName[255];
struct hostent *host_entry;
gethostname(szHostName, 255);
host_entry = gethostbyname(szHostName);
char* temp = inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list);
char buff[255];
strcpy_s(buff, temp);
szLocalIP = buff;
return szLocalIP;
}

View File

@ -57,7 +57,7 @@ namespace Oyster
/** Parses asynchronous connected clients.
*/
void ProcessConnectedClients();
int ProcessConnectedClients();
/** Set the main session connected clients will enter when connected to server.
* @param mainSession The session to connect as main server session.
@ -72,13 +72,17 @@ namespace Oyster
/** Sets the main session to NULL and returns it
* @return Returns the main session
*/
NetworkSession const* ReleaseMainSessionSession();
NetworkSession const* ReleaseMainSession();
/**
*
*/
bool IsStarted() const;
/**
*
*/
std::string GetLanAddress();
private:
struct PrivateData;

View File

@ -10,13 +10,13 @@
#include <vector>
#include <mutex>
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
struct NetworkSession::PrivateSessionData
{
Utility::DynamicMemory::DynamicArray<NetworkClient> clients;
Utility::DynamicMemory::DynamicArray<NetClient> clients;
NetworkClient::ClientEventFunction messageCallback;
std::mutex clientListLock;
NetworkSession* owner; //Where clients end up when session is closed.
@ -32,7 +32,7 @@ struct NetworkSession::PrivateSessionData
NetworkSession::NetworkSession()
: data(0)
: data(new PrivateSessionData())
{}
NetworkSession::NetworkSession(const NetworkSession& orig)
{
@ -59,24 +59,26 @@ NetworkSession::~NetworkSession()
this->data->clients.Clear();
this->data->clientCount = 0;
this->data->messageCallback = 0;
delete this->data;
this->data = 0;
}
void NetworkSession::ProcessClients()
{
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
this->data->clients[i].ProcessMessages();
if(this->data->clients[i]) this->data->clients[i]->Update();
}
}
bool NetworkSession::Attach(NetworkClient client)
bool NetworkSession::Attach(NetClient client)
{
this->data->clientListLock.lock();
int k = -1;
for (unsigned int i = 0; (k == -1) && i < this->data->clients.Size(); i++)
{
if(!this->data->clients[i].IsConnected()) //TODO: Dont check connection status, check more general status..
if(!this->data->clients[i]->IsConnected()) //TODO: Dont check connection status, check more general status..
k = i;
}
@ -91,23 +93,44 @@ bool NetworkSession::Attach(NetworkClient client)
this->data->clientCount++;
client->SetOwner(this);
this->data->clientListLock.unlock();
return true;
}
NetworkClient NetworkSession::Detach(const NetworkClient& client)
void NetworkSession::Detach()
{
NetworkClient val;
if(this->data->owner)
{
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
this->data->owner->Attach(this->data->clients[i]);
this->data->clients[i] = 0;
}
}
else
{
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
this->data->clients[i]->Disconnect();
this->data->clients[i] = 0;
}
}
}
NetClient NetworkSession::Detach(const NetworkClient* client)
{
NetClient val;
this->data->clientListLock.lock();
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
if(this->data->clients[0].GetID() == client.GetID())
if(this->data->clients[i] && this->data->clients[0]->GetID() == client->GetID())
{
val = this->data->clients[i];
this->data->clients[i] = NetworkClient();
this->data->clients[i] = 0;
this->data->clientCount--;
}
}
@ -117,18 +140,18 @@ NetworkClient NetworkSession::Detach(const NetworkClient& client)
return val;
}
NetworkClient NetworkSession::Detach(short ID)
NetClient NetworkSession::Detach(short ID)
{
NetworkClient val;
NetClient val;
this->data->clientListLock.lock();
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
if(this->data->clients[0].GetID() == ID)
if(this->data->clients[i] && this->data->clients[0]->GetID() == ID)
{
val = this->data->clients[i];
this->data->clients[i] = NetworkClient();
this->data->clients[i] = 0;
this->data->clientCount--;
}
}
@ -143,9 +166,12 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol)
bool returnValue = false;
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
this->data->clients[i].Send(&protocol);
if(this->data->clients[i])
{
this->data->clients[i]->Send(&protocol);
returnValue = true;
}
}
return returnValue;
}
@ -154,9 +180,9 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID)
{
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
if(this->data->clients[i].GetID() == ID)
if(this->data->clients[i] && this->data->clients[i]->GetID() == ID)
{
this->data->clients[i].Send(&protocol);
this->data->clients[i]->Send(&protocol);
return true;
}
}
@ -169,9 +195,12 @@ void NetworkSession::CloseSession(bool dissconnectClients)
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
if(dissconnectClients) this->data->clients[i].Disconnect();
if(this->data->clients[i])
{
if(dissconnectClients) this->data->clients[i]->Disconnect();
else if(this->data->owner) this->data->owner->Attach(this->data->clients[i]);
else this->data->clients[i].Disconnect();
else this->data->clients[i]->Disconnect(); //Idiot check, clients have to go somewhere..
}
}
this->data->clients.Clear();
@ -180,5 +209,23 @@ void NetworkSession::CloseSession(bool dissconnectClients)
this->data->clientListLock.unlock();
}
void NetworkSession::SetOwner(NetworkSession* owner)
{
this->data->owner = owner;
}
int NetworkSession::GetClientCount() const
{
int c = 0;
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
if(this->data->clients[i]) c++;
}
return c;
}
void NetworkSession::ClientConnectedEvent(NetClient client)
{
this->Attach(client);
}

View File

@ -10,11 +10,13 @@
#include "NetworkAPI_Preprocessor.h"
#include "NetworkServerEventStruct.h"
#include "NetworkClient.h"
#include "Utilities.h"
namespace Oyster
{
namespace Network
{
typedef Utility::DynamicMemory::SmartPointer<NetworkClient> NetClient;
class NET_API_EXPORT NetworkSession
{
public:
@ -30,49 +32,60 @@ namespace Oyster
/**
*
*/
bool Attach(NetworkClient client);
virtual bool Attach(NetClient client);
/**
* Detaches all clients and sends them to owner.
* If no owner is set the clients is disconnected.
*/
virtual void Detach();
/**
*
*/
NetworkClient Detach(const NetworkClient& client);
virtual NetClient Detach(const NetworkClient* client);
/**
*
*/
NetworkClient Detach(short ID);
virtual NetClient Detach(short ID);
/** Send a message to all clients in this session
* @param message The message
*/
bool Send(Oyster::Network::CustomNetProtocol& message);
virtual bool Send(Oyster::Network::CustomNetProtocol& message);
/** Send a message to a specific client in this session
* @param message The message
*/
bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
virtual bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
/**
*
*/
void CloseSession( bool dissconnectClients = false );
virtual void CloseSession( bool dissconnectClients = false );
/**
* Set the owner that clients will be returned to.
* @param owner If owner is NULL, clients will be disconnected when session is over.
*/
void SetOwner(NetworkSession* owner);
virtual void SetOwner(NetworkSession* owner);
/** Get the number of clients active in this session
* @return The client count
*/
int GetClientCount() const;
/**
*
*/
virtual void ClientConnectedEvent(NetClient client);
/**
*
*/
virtual void ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e) = 0;
/**
*
*/
virtual void ClientConnectedEvent(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e) = 0;
private:
struct PrivateSessionData;
PrivateSessionData* data;

View File

@ -18,6 +18,7 @@ using namespace std;
struct MyCastingStruct
{
std::map<int, NetAttributeContainer> attributes;
Utility::DynamicMemory::ReferenceCount *c;
};
// TODO: Check if the package has been packed correctly.

View File

@ -53,6 +53,8 @@ int Connection::Connect(int socket, bool blocking)
int Connection::Connect(unsigned short port , const char serverName[], bool blocking)
{
if(this->socket == -1 || this->socket == 0) InitiateSocket();
struct hostent *hostEnt;
if((hostEnt = gethostbyname(serverName)) == NULL)
{

View File

@ -1,27 +0,0 @@
#ifndef NETWORK_SERVER_ILISTENER_H
#define NETWORK_SERVER_ILISTENER_H
/////////////////////////////////////
// Created by Pontus Fransson 2013 //
/////////////////////////////////////
namespace Oyster
{
namespace Network
{
namespace Server
{
class IListener
{
public:
virtual ~IListener() {}
virtual bool Init(unsigned int port) = 0;
virtual int Accept() = 0;
virtual void Shutdown() = 0;
};
}
}
}
#endif

View File

@ -1,8 +1,8 @@
#include "Listener.h"
using namespace Oyster::Network::Server;
using namespace Utility::DynamicMemory;
using namespace Oyster::Thread;
using namespace Oyster::Network;
Listener::Listener()
{

View File

@ -5,7 +5,6 @@
// Created by Pontus Fransson 2013 //
/////////////////////////////////////
#include "IListener.h"
#include "Connection.h"
#include "IPostBox.h"
#include "../../Misc/Thread/OysterThread.h"
@ -17,16 +16,14 @@ namespace Oyster
{
namespace Network
{
namespace Server
{
class Listener : public IListener, public ::Oyster::Thread::IThreadObject
class Listener : public ::Oyster::Thread::IThreadObject
{
public:
Listener();
Listener(Oyster::Network::IPostBox<int>* postBox);
~Listener();
bool Init(unsigned int port) override;
bool Init(unsigned int port);
bool Init(unsigned int port, bool start);
bool Start();
void Stop();
@ -55,7 +52,7 @@ namespace Oyster
std::atomic<bool> isListening;
int port;
};
}
}
}

View File

@ -164,7 +164,6 @@
<ItemGroup>
<ClInclude Include="Connection.h" />
<ClInclude Include="IConnection.h" />
<ClInclude Include="IListener.h" />
<ClInclude Include="IPostBox.h" />
<ClInclude Include="Listener.h" />
<ClInclude Include="Messages\MessageHeader.h" />

View File

@ -14,7 +14,6 @@
<ItemGroup>
<ClInclude Include="Connection.h" />
<ClInclude Include="IConnection.h" />
<ClInclude Include="IListener.h" />
<ClInclude Include="IPostBox.h" />
<ClInclude Include="Listener.h" />
<ClInclude Include="Messages\MessageHeader.h" />

View File

@ -132,13 +132,14 @@ void Oyster::Graphics::Loading::UnloadDAN(void* data)
delete info;
}
static wchar_t* charToWChar(const char* text)
static std::wstring charToWChar(const char* text)
{
// Convert to a wchar_t*
size_t origsize = strlen(text) + 1;
size_t convertedChars = 0;
wchar_t* wcstring = new wchar_t[origsize];
mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
//wchar_t* wcstring = new wchar_t[origsize];
std::wstring wcstring; wcstring.resize(origsize);
mbstowcs_s(&convertedChars, &wcstring[0], origsize, text, _TRUNCATE);
return wcstring;
}
@ -175,7 +176,7 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
buffer = new char[4];
danFile.read(buffer, 4);
memcpy(&headerType, buffer, 4);
//delete[] buffer; // ( note: may crash here.)
delete[] buffer; // ( note: may crash here.)
// handle header type
switch ((HeaderType)headerType)
@ -276,11 +277,14 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
delete[] buffer; // ( note: may crash here.)
//
ID3D11ShaderResourceView* diffuseMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(charToWChar(materialHeader.diffuseMapPath), Oyster::Graphics::Loading::LoadTexture);
ID3D11ShaderResourceView* normalMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(charToWChar(materialHeader.normalMapPath), Oyster::Graphics::Loading::LoadTexture);
ID3D11ShaderResourceView* diffuseMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(charToWChar(materialHeader.diffuseMapPath).c_str(), Oyster::Graphics::Loading::LoadTexture);
ID3D11ShaderResourceView* normalMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(charToWChar(materialHeader.normalMapPath).c_str(), Oyster::Graphics::Loading::LoadTexture);
modelInfo->Material.push_back(diffuseMap);
modelInfo->Material.push_back(normalMap);
delete materialHeader.normalMapPath;
delete materialHeader.diffuseMapPath;
break;
}
// skeleton header
@ -298,6 +302,7 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
}
}
// close file
danFile.close();