diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp
index 392e917f..81650049 100644
--- a/Code/Game/GameClient/DanBiasGame_Impl.cpp
+++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp
@@ -99,9 +99,6 @@ namespace DanBias
data.timer.reset();
Graphics::API::Update( dt );
-
- if(data.networkClient.IsConnected())
- data.networkClient.Update();
data.capFrame += dt;
if(data.capFrame > 0.03)
@@ -118,6 +115,9 @@ namespace DanBias
data.capFrame = 0;
}
+ if(data.networkClient.IsConnected())
+ data.networkClient.Update();
+
}
return DanBiasClientReturn_Success;
}
diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj
index a87f61e4..3daafff3 100644
--- a/Code/Game/GameClient/GameClient.vcxproj
+++ b/Code/Game/GameClient/GameClient.vcxproj
@@ -112,7 +112,7 @@
Windows
true
%(AdditionalDependencies)
- NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)
+ NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;GameClient_$(PlatformShortName)D.dll;%(DelayLoadDLLs)
@@ -129,7 +129,7 @@
Windows
true
%(AdditionalDependencies)
- NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)
+ NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;GameClient_$(PlatformShortName)D.dll;%(DelayLoadDLLs)
@@ -150,7 +150,7 @@
true
true
%(AdditionalDependencies)
- NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)
+ NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;GameClient_$(PlatformShortName).dll;%(DelayLoadDLLs)
@@ -171,7 +171,7 @@
true
true
%(AdditionalDependencies)
- NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)
+ NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;GameClient_$(PlatformShortName).dll;%(DelayLoadDLLs)
diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp
index 29cfec03..38ded541 100644
--- a/Code/Game/GameClient/GameClientState/GameState.cpp
+++ b/Code/Game/GameClient/GameClientState/GameState.cpp
@@ -8,6 +8,7 @@
#include "C_obj/C_Player.h"
#include "C_obj/C_DynamicObj.h"
#include "C_obj/C_StaticObj.h"
+#include "Utilities.h"
using namespace ::DanBias::Client;
using namespace ::Oyster;
@@ -15,6 +16,7 @@ using namespace ::Oyster::Network;
using namespace ::Oyster::Math3D;
using namespace ::GameLogic;
using namespace ::Utility::DynamicMemory;
+using namespace ::Utility::String;
struct GameState::MyData
{
@@ -40,6 +42,11 @@ struct GameState::MyData
} privData;
+inline Quaternion ArrayToQuaternion( const float source[4] )
+{
+ return Quaternion( Float3(source[0], source[1], source[2]), source[3] );
+}
+
GameState::GameState()
{
this->privData = nullptr;
@@ -75,21 +82,33 @@ bool GameState::Init( SharedStateContent &shared )
return true;
}
-void GameState::InitiatePlayer( int id, std::wstring modelName, Float4x4 world )
+void GameState::InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3], bool isMyPlayer )
{
- this->privData->myId = id;
-
ModelInitData modelData;
- modelData.visible = true;
- modelData.position = Float3(world[12], world[13], world[14]);
- modelData.rotation = Quaternion(Float3(0,0,0), 1);
- modelData.scale = Float3(1,1,1);
- modelData.modelPath = modelName;
- modelData.id = this->privData->myId;
- this->privData->player.Init( modelData );
+ modelData.visible = true;
+ modelData.position = position;
+ modelData.rotation = ArrayToQuaternion( rotation );
+ modelData.scale = scale;
+ StringToWstring( modelName, modelData.modelPath );
+ modelData.id = id;
- this->privData->camera.SetPosition( this->privData->player.getPos() );
- this->privData->camera.UpdateOrientation();
+ if( isMyPlayer )
+ {
+ if( this->privData->player.Init(modelData) )
+ {
+ this->privData->myId = id;
+ this->privData->camera.SetPosition( this->privData->player.getPos() );
+ this->privData->camera.UpdateOrientation();
+ }
+ }
+ else
+ {
+ C_DynamicObj *p = new C_DynamicObj();
+ if( p->Init(modelData) )
+ {
+ (*this->privData->dynamicObjects)[id] = p;
+ }
+ }
}
GameClientState::ClientState GameState::Update( float deltaTime )
@@ -359,7 +378,12 @@ void GameState::DataRecieved( NetEventInitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotation, decoded.scale, decoded.owner );
+ }
+ break;
case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */
diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h
index 29ea2f1e..e3ced125 100644
--- a/Code/Game/GameClient/GameClientState/GameState.h
+++ b/Code/Game/GameClient/GameClientState/GameState.h
@@ -20,9 +20,8 @@ namespace DanBias { namespace Client
~GameState(void);
bool Init( SharedStateContent &shared );
GameClientState::ClientState Update( float deltaTime ) override;
- void InitiatePlayer( int id, std::wstring modelName, Oyster::Math::Float4x4 world );
+ void InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3] );
void ReadKeyInput();
-
bool Render()override;
bool Release()override;
void ChangeState( ClientState next );
diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp
index 8274472d..f50db40c 100644
--- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp
+++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp
@@ -27,7 +27,7 @@ struct NetLoadState::MyData
bool loading;
};
-inline Quaternion ArrayToQuaternion( float source[4] )
+inline Quaternion ArrayToQuaternion( const float source[4] )
{
return Quaternion( Float3(source[0], source[1], source[2]), source[3] );
}
@@ -99,6 +99,7 @@ void NetLoadState::DataRecieved( NetEventLoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName );
this->ChangeState( ClientState_Game );
+ this->privData->loading = false;
}
}
@@ -109,18 +110,20 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
LevelLoader loader;
auto objects = loader.LoadLevel( fileName );
auto object = objects.begin();
- ObjectHeader *oh;
+ ObjectTypeHeader *oth;
int objectID = 100; // first 100 is reserved for players. This is how the server does it.
for( ; object != objects.end(); ++object )
{
++objectID;
- oh = (ObjectHeader*)&*object;
- switch( oh->typeID )
+ oth = (ObjectTypeHeader*)(*object._Ptr);
+ switch( oth->typeID )
{
case ObjectType::ObjectType_Static:
{
+ ObjectHeader *oh = (ObjectHeader*)oth;
+
ModelInitData desc;
desc.id = objectID;
StringToWstring( oh->ModelFile, desc.modelPath );
@@ -142,6 +145,8 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
break;
case ObjectType::ObjectType_Dynamic:
{
+ ObjectHeader *oh = (ObjectHeader*)oth;
+
ModelInitData desc;
desc.id = objectID;
StringToWstring( oh->ModelFile, desc.modelPath );