diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 2a46b8d6..b461f908 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -103,7 +103,6 @@ namespace DanBias float dt = (float)data.timer.getElapsedSeconds(); data.timer.reset(); - Graphics::API::Update( dt ); data.capFrame += dt; if(data.capFrame > 0.03f) @@ -115,6 +114,8 @@ namespace DanBias case Result_error: return DanBiasClientReturn_Error; default: break; } + + Graphics::API::Update( data.capFrame ); if(Render() != S_OK) return DanBiasClientReturn_Error; data.capFrame -= 0.03f; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 4686018f..cd4083b7 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -33,7 +33,8 @@ struct GameState::MyData ::std::map> *dynamicObjects; ::std::map> *lights; - C_Player player; + //C_Player player; + ::std::map> players; Camera_FPSV2 camera; int myId; @@ -75,7 +76,7 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); gfxOp.AmbientValue = 0.5f; - gfxOp.GlobalGlowTint = Math::Float3(2,1,1); + gfxOp.GlobalGlowTint = Math::Float3(1,1,1); gfxOp.GlobalTint = Math::Float3(1,1,1); Graphics::API::SetOptions(gfxOp); @@ -123,37 +124,30 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBData.scale = scale; RBData.type = RB_Type_Cube; // !RB DEBUG - if( isMyPlayer ) + C_Player *p = new C_Player(); + if( p->Init(modelData) ) { - if( this->privData->player.Init(modelData) ) - { - // RB DEBUG - this->privData->player.InitRB( RBData ); - // !RB DEBUG + // RB DEBUG + p->InitRB( RBData ); + // !RB DEBUG + // start with runing animation + p->playAnimation( L"run_forwards", true ); + (this->privData->players)[id] = p; + + if( isMyPlayer ) + { this->privData->myId = id; - this->privData->camera.SetPosition( this->privData->player.getPos() ); + this->privData->camera.SetPosition( p->getPos() ); Float3 offset = Float3( 0.0f ); // DEBUG position of camera so we can see the player model - //offset.y = this->privData->player.getScale().y * 5.0f; - //offset.z = this->privData->player.getScale().z * -5.0f; + //offset.y = p->getScale().y * 5.0f; + //offset.z = p->getScale().z * -5.0f; // !DEBUG this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); } } - else - { - C_DynamicObj *p = new C_DynamicObj(); - if( p->Init(modelData) ) - { - // RB DEBUG - this->privData->player.InitRB( RBData ); - // !RB DEBUG - - (*this->privData->dynamicObjects)[id] = p; - } - } } GameClientState::ClientState GameState::Update( float deltaTime ) @@ -187,7 +181,17 @@ bool GameState::Render() Oyster::Graphics::API::NewFrame(); // for debugging to be replaced with render weapon - this->privData->player.Render(); + auto playerObject = this->privData->players.begin(); + for( ; playerObject != this->privData->players.end(); ++playerObject ) + { + if(playerObject->second) + { + if( this->privData->myId != playerObject->second->GetId() ) + { + playerObject->second->Render(); + } + } + } auto staticObject = this->privData->staticObjects->begin(); for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) @@ -211,11 +215,18 @@ bool GameState::Render() { Oyster::Graphics::API::StartRenderWireFrame(); - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); - Oyster::Math3D::Float4x4 world = translation * scale; - Oyster::Graphics::API::RenderDebugCube( world ); - Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); + playerObject = this->privData->players.begin(); + for( ; playerObject != this->privData->players.end(); ++playerObject ) + { + if( playerObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( playerObject->second->getRBWorld()); + } + if( playerObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( playerObject->second->getRBWorld()); + } + } staticObject = this->privData->staticObjects->begin(); for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) @@ -276,6 +287,12 @@ bool GameState::Release() Graphics::API::Option o = Graphics::API::GetOption(); if( privData ) { + auto playerObject = this->privData->players.begin(); + for( ; playerObject != this->privData->players.end(); ++playerObject ) + { + playerObject->second = nullptr; + } + auto staticObject = this->privData->staticObjects->begin(); for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { @@ -381,6 +398,7 @@ void GameState::ReadKeyInput() this->key_showStats = false; } } + const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) @@ -459,42 +477,29 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState Protocol_ObjectPositionRotation decoded(data); Float3 position = decoded.position; Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); - - // if is this player. Remember to change camera - if( this->privData->myId == decoded.object_ID ) + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) { - if( !Within(position.Dot(position), 2500.0f, 90000.0f) ) - { // HACK: bug trap - const char *breakPoint = "Something is wrong."; - position = Float3( 0.0f, 160.0f, 0.0f ); - } - - this->privData->camera.SetPosition( position ); - this->privData->camera.SetRotation( rotation ); - this->privData->player.setPos( position ); - this->privData->player.setRot( rotation ); - this->privData->player.updateWorld(); - // RB DEBUG - this->privData->player.setRBPos ( position ); - this->privData->player.setRBRot ( rotation ); - this->privData->player.updateRBWorld(); - // !RB DEBUG + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; } - else - { - C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; - if( object ) + if( object ) + { + if( this->privData->myId == decoded.object_ID ) { - object->setPos( position ); - object->setRot( rotation ); - object->updateWorld(); - // RB DEBUG - object->setRBPos ( position ); - object->setRBRot ( rotation ); - object->updateRBWorld(); - // !RB DEBUG + this->privData->camera.SetPosition( position ); + this->privData->camera.SetRotation( rotation ); } + object->setPos( position ); + object->setRot( rotation ); + object->updateWorld(); + // RB DEBUG + object->setRBPos ( position ); + object->setRBRot ( rotation ); + object->updateRBWorld(); + // !RB DEBUG } } return GameClientState::event_processed; @@ -534,7 +539,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState RBData.rotation = ArrayToQuaternion( decoded.position ); RBData.scale = Float3( decoded.scale ); - this->privData->player.InitRB( RBData ); + object->InitRB( RBData ); // !RB DEBUG (*this->privData->dynamicObjects)[decoded.object_ID] = object; @@ -553,17 +558,29 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectRespawn: { - // set player pos Protocol_ObjectRespawn decoded(data); - // move player. Remember to change camera - this->privData->camera.SetPosition( decoded.position ); - this->privData->player.setPos( decoded.position ); - this->privData->player.updateWorld(); - // RB DEBUG - this->privData->player.setRBPos ( decoded.position ); - this->privData->player.updateRBWorld(); - // !RB DEBUG + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + + if( object ) + { + if( this->privData->myId == decoded.objectID ) + { + this->privData->camera.SetPosition( decoded.position ); + } + object->setPos( decoded.position ); + object->updateWorld(); + // RB DEBUG + object->setRBPos ( decoded.position ); + object->updateRBWorld(); + // !RB DEBUG + } this->currGameUI = this->gameUI; } return GameClientState::event_processed; diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 22f8213e..3dfdf8f4 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -813,39 +813,48 @@ namespace GameLogic //#define protocol_Gameplay_ObjectRespawn 365 struct Protocol_ObjectRespawn :public Oyster::Network::CustomProtocolObject { + int objectID; float position[3]; Protocol_ObjectRespawn() { this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectRespawn; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + // ID + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + // POSITION this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[3].type = Oyster::Network::NetAttributeType_Float; + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; + this->objectID = 0; memset(&this->position[0], 0, sizeof(float) * 3); } - Protocol_ObjectRespawn(float position[3]) + Protocol_ObjectRespawn(int id, float position[3]) { this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectRespawn; - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + // ID + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + // POSITION this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[3].type = Oyster::Network::NetAttributeType_Float; - + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; + this->objectID = id; memcpy(&this->position[0], &position[0], sizeof(float) * 3); } Protocol_ObjectRespawn(Oyster::Network::CustomNetProtocol& p) { - this->position[0] = p[1].value.netFloat; - this->position[1] = p[2].value.netFloat; - this->position[2] = p[3].value.netFloat; + this->objectID = p[1].value.netInt; + this->position[0] = p[2].value.netFloat; + this->position[1] = p[3].value.netFloat; + this->position[2] = p[4].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->position[0]; - this->protocol[2].value = this->position[1]; - this->protocol[3].value = this->position[2]; + this->protocol[1].value = this->objectID; + this->protocol[2].value = this->position[0]; + this->protocol[3].value = this->position[1]; + this->protocol[4].value = this->position[2]; return protocol; } diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index e8e78ab0..90b412ef 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -19,7 +19,7 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerclient = nwClient; this->player = 0; isReady = false; - this->character = L"crate_colonists.dan"; + this->character = L"char_orca.dan"; this->alias = L"Unknown"; this->secondsSinceLastResponse = 0.0f; } @@ -29,7 +29,7 @@ GameClient::~GameClient() this->player->Inactivate(); this->isReady = false; - this->character = L"crate_colonists.dan"; + this->character = L"char_orca.dan"; this->alias = L"Unknown"; this->secondsSinceLastResponse = 0.0f; this->client = 0; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 1b3f6cb5..bc839554 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -62,31 +62,24 @@ using namespace DanBias; { case NetworkClient::ClientEventArgs::EventType_Disconnect: { - printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); - Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID()); - for (unsigned int i = 0; i < this->gClients.Size(); i++) + //Send disconnect message to all the other players so the player can be removed from the client. + Protocol_ObjectDisconnectPlayer dp(cl->GetClient()->GetID()); + for(int i = 0; i < this->gClients.Size(); i++) { - if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot); + if(this->gClients[i] && this->gClients[i] != cl) + { + this->gClients[i]->GetClient()->Send(dp); + } } - + printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); this->gClients[temp]->Invalidate(); } break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: - { if(this->gClients[temp]->IncrementFailedProtocol() >= 5/*client->threshold*/) - { - printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); - Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID()); - for (unsigned int i = 0; i < this->gClients.Size(); i++) - { - if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot); - } this->gClients[temp]->Invalidate(); - } - } break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: this->ParseProtocol(e.args.data.protocol, cl); @@ -150,9 +143,6 @@ using namespace DanBias; Oyster::Math::Float3 temp = movedObject->GetPosition(); - if(temp.x < -300) - id = 0; - GameSession::gameSession->Send(p.GetProtocol()); //} } @@ -231,7 +221,7 @@ using namespace DanBias; void GameSession::Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn& p, DanBias::GameClient* c ) { c->GetPlayer()->TurnLeft( p.deltaRadian ); - c->GetPlayer()->SetLookDir(p.lookdir); + c->GetPlayer()->SetLookDir( p.lookdir ) ; } void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ) { @@ -275,17 +265,10 @@ using namespace DanBias; switch (p.status) { case GameLogic::Protocol_General_Status::States_disconected: - { printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID()); - - Protocol_ObjectDisconnectPlayer prot(c->GetPlayer()->GetID()); - for (unsigned int i = 0; i < this->gClients.Size(); i++) - { - if( this->gClients[i] && c->GetClient()->GetID() != this->gClients[i]->GetClient()->GetID() ) this->gClients[i]->GetClient()->Send(prot); - } - c->Invalidate(); + //TODO: Tell other clients + //Protocol_ this->Detach(c->GetClient()->GetID()); - } break; case GameLogic::Protocol_General_Status::States_idle: diff --git a/Code/Misc/Utilities/Resource/ResourceManager.cpp b/Code/Misc/Utilities/Resource/ResourceManager.cpp index 04c03a6f..e23ff398 100644 --- a/Code/Misc/Utilities/Resource/ResourceManager.cpp +++ b/Code/Misc/Utilities/Resource/ResourceManager.cpp @@ -437,6 +437,38 @@ int ResourceManager::GetResourceId(const wchar_t c[]) return -1; } +int ResourceManager::GetResourceCount(const wchar_t filename[]) +{ + ResourceData *t = FindResource(this->resources, filename); + + if(t) return t->referenceCount; + + return 0; +} +int ResourceManager::GetResourceCount(const HRESOURCE& resource) +{ + ResourceData *t = FindResource(this->resources, resource); + + if(t) return t->referenceCount; + + return 0; +} +int ResourceManager::GetResourceSize(const wchar_t filename[]) +{ + ResourceData *t = FindResource(this->resources, filename); + + if(t) return t->resourceSize; + + return 0; +} +int ResourceManager::GetResourceSize(const HRESOURCE& resource) +{ + ResourceData *t = FindResource(this->resources, resource); + + if(t) return t->resourceSize; + + return 0; +} diff --git a/Code/Misc/Utilities/Resource/ResourceManager.h b/Code/Misc/Utilities/Resource/ResourceManager.h index d5684538..b3de6af5 100644 --- a/Code/Misc/Utilities/Resource/ResourceManager.h +++ b/Code/Misc/Utilities/Resource/ResourceManager.h @@ -148,6 +148,14 @@ namespace Oyster * @return Returns the accociated ID */ int GetResourceId(const wchar_t filename[]); + + int GetResourceCount(const wchar_t filename[]); + + int GetResourceCount(const HRESOURCE& resource); + + int GetResourceSize(const wchar_t filename[]); + + int GetResourceSize(const HRESOURCE& resource); private: ResourceManager(const ResourceManager& obj); diff --git a/Code/Misc/Utilities/Utilities.h b/Code/Misc/Utilities/Utilities.h index b97d62d7..bf9bb65c 100644 --- a/Code/Misc/Utilities/Utilities.h +++ b/Code/Misc/Utilities/Utilities.h @@ -44,6 +44,7 @@ namespace Utility ReferenceCount() :count(0) { } ReferenceCount(const ReferenceCount& o) { count = o.count; } inline const ReferenceCount& operator=(const ReferenceCount& o) { count = o.count; return *this;} + operator int() { return this->count; } inline void Incref() { this->count++; } inline void Incref(int c) { this->count += c; } inline int Decref() { return --this->count;} diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index f6a6431c..9d7d4301 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -90,6 +90,13 @@ namespace Oyster Math::Float3 GlowTint; Math::Float PAD2; }; + + struct RenderInstanceData + { + Math::Matrix WV; + Math::Matrix WVP; + TintData td; + }; } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 8f01bea4..4e61c7f3 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -19,6 +19,7 @@ namespace Oyster Math::Float4x4 Projection; std::vector Lights; float deltaTime; + int MostModel; #ifdef _DEBUG Model::Model* cube; Model::Model* sphere; @@ -133,6 +134,16 @@ namespace Oyster return API::Sucsess; } + void API::BeginLoadingModels() + { + } + + void API::EndLoadingModels() + { + //TODO finalize instance buffers and create rendering map; + + } + //returns null for invalid filenames Model::Model* API::CreateModel(std::wstring filename) { @@ -153,6 +164,15 @@ namespace Oyster return NULL; } + if(Core::loader.GetResourceCount(m->info) == 1) + { + Render::Resources::RenderData[m->info] = new Render::Resources::ModelDataWrapper(); + } + else + { + Render::Resources::RenderData[m->info]->Models++; + } + return m; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index 795f649a..7f338cce 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -42,6 +42,10 @@ namespace Oyster static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Option options); + static void BeginLoadingModels(); + + static void EndLoadingModels(); + static State ReloadShaders(); //should be called after rendered normal models, before GUI or Text rendering diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 2e693472..4c203cf9 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -63,6 +63,8 @@ namespace Oyster ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL; ID3D11DepthStencilView* Resources::Gui::depth = NULL; + + std::map Resources::RenderData = std::map(); #pragma endregion diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index 665ab8dc..6ad756eb 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -1,6 +1,8 @@ #pragma once #include "../Core/Core.h" +#include "../Model/ModelInfo.h" +#include "../Definitions/GraphicalDefinition.h" namespace Oyster { @@ -11,6 +13,14 @@ namespace Oyster class Resources { public: + struct ModelDataWrapper + { + Definitions::RenderInstanceData* rid; + int Models; + }; + + + static std::map RenderData; static const int GBufferSize = 3; static const int LBufferSize = 3;