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/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index 67146770..b168b92c 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -123,7 +123,10 @@ void C_Object::SetGlowTint(Oyster::Math::Float3 tint) model->GlowTint = tint; } - +void C_Object::SetVisible(bool visible) +{ + model->Visible = visible; +} //////////////////////////////////////////////// // RB DEBUG diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index fd118068..1a8f7517 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -72,7 +72,7 @@ namespace DanBias void SetTint(Oyster::Math::Float3); void SetGlowTint(Oyster::Math::Float3); - + void SetVisible(bool visible); // RB DEBUG void updateRBWorld(); diff --git a/Code/Game/GameClient/GameClientState/C_obj/C_DynamicObj.cpp b/Code/Game/GameClient/GameClientState/C_obj/C_DynamicObj.cpp index 73dd20b5..26619c0e 100644 --- a/Code/Game/GameClient/GameClientState/C_obj/C_DynamicObj.cpp +++ b/Code/Game/GameClient/GameClientState/C_obj/C_DynamicObj.cpp @@ -3,6 +3,7 @@ using namespace DanBias::Client; C_DynamicObj::C_DynamicObj(void) + :C_Object() { } diff --git a/Code/Game/GameClient/GameClientState/C_obj/C_StaticObj.cpp b/Code/Game/GameClient/GameClientState/C_obj/C_StaticObj.cpp index 42a12acd..22734a96 100644 --- a/Code/Game/GameClient/GameClientState/C_obj/C_StaticObj.cpp +++ b/Code/Game/GameClient/GameClientState/C_obj/C_StaticObj.cpp @@ -3,6 +3,7 @@ using namespace DanBias::Client; C_StaticObj::C_StaticObj(void) + :C_Object() { } diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 4686018f..7e8a0ee7 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -12,6 +12,7 @@ #include "GamingUI.h" #include "RespawnUI.h" #include "StatsUI.h" +#include using namespace ::DanBias::Client; using namespace ::Oyster; @@ -33,7 +34,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 +77,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); @@ -113,8 +115,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa modelData.position = position; modelData.rotation = ArrayToQuaternion( rotation ); modelData.scale = scale; - StringToWstring( modelName, modelData.modelPath ); modelData.id = id; + StringToWstring(modelName,modelData.modelPath); // RB DEBUG RBInitData RBData; @@ -123,37 +125,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"idle", 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 +182,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 +216,21 @@ 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) + { + 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 +291,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 +402,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 ) @@ -399,59 +421,139 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState switch(ID) { - case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectPickup: + { + Protocol_ObjectPickup decoded(data); + decoded.object_ID; + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } + + if( object ) + { + if( this->privData->myId == decoded.object_ID ) + { + // I picked up the pickUp! + } + + if (decoded.pickup_ID == GameLogic::PickupType::PickupType_Health) + { + // object->PickupHealth(); + } + else if (decoded.pickup_ID == GameLogic::PickupType::PickupType_SpeedBoost) + { + // object->PickupSpeed(); + } + } + decoded.pickup_ID; + + + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectDamage: { Protocol_ObjectDamage decoded(data); - if( this->privData->myId == decoded.object_ID ) + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) { - if(currGameUI == gameUI) + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + + if( object ) + { + if( this->privData->myId == decoded.objectID ) { - ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + // show that you took dmg + if(currGameUI == gameUI) + { + // set given players HP + ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + } } } } return GameClientState::event_processed; case protocol_Gameplay_ObjectHealthStatus: - { + { + // don't know if needed } return GameClientState::event_processed; case protocol_Gameplay_ObjectPosition: { Protocol_ObjectPosition decoded(data); - // if is this player. Remember to change camera - if( this->privData->myId == decoded.object_ID ) - this->privData->camera.SetPosition( decoded.position ); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } - (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position ); - // !RB DEBUG + if( object ) + { + if( this->privData->myId == decoded.objectID ) + { + this->privData->camera.SetPosition( decoded.position ); + } + + object->setPos( decoded.position ); + // RB DEBUG + object->setRBPos ( decoded.position ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); - (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale ); - // !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 ) + { + object->setScale( decoded.scale ); + // RB DEBUG + object->setRBScale ( decoded.scale ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectRotation: { Protocol_ObjectRotation decoded(data); Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } - // if is this player. Remember to change camera - if( this->privData->myId == decoded.object_ID ) - this->privData->camera.SetRotation( rotation ); + if( object ) + { + if( this->privData->myId == decoded.objectID ) + { + this->privData->camera.SetRotation( rotation ); + } - (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); - // !RB DEBUG + object->setRot( rotation ); + // RB DEBUG + object->setRBRot( rotation ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectPositionRotation: @@ -459,56 +561,72 @@ 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.objectID]; + 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.objectID]; } - else - { - C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; - if( object ) + if( object ) + { + if( this->privData->myId == decoded.objectID ) { - 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; + case protocol_Gameplay_ObjectEnabled: + { + Protocol_ObjectEnable decoded(data); + 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 ) + { + object->SetVisible(true); } } return GameClientState::event_processed; - case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDisabled: { Protocol_ObjectDisable decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } - auto object = this->privData->dynamicObjects->find( decoded.objectID ); + if( object ) + { + object->SetVisible(false); + } + + /*auto object = this->privData->dynamicObjects->find( decoded.objectID ); if( object != this->privData->dynamicObjects->end() ) { - object->second = nullptr; - this->privData->dynamicObjects->erase( object ); - } + object->second = nullptr; + this->privData->dynamicObjects->erase( object ); + }*/ + } return GameClientState::event_processed; case protocol_Gameplay_ObjectCreate: @@ -522,7 +640,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState modelData.rotation = Quaternion( Float3(decoded.position), decoded.rotationQ[3] ); modelData.scale = Float3( decoded.scale ); modelData.visible = true; - modelData.id = decoded.object_ID; + modelData.id = decoded.objectID; ::Utility::String::StringToWstring( decoded.name, modelData.modelPath ); } @@ -534,17 +652,17 @@ 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; + (*this->privData->dynamicObjects)[decoded.objectID] = object; } return GameClientState::event_processed; case protocol_Gameplay_ObjectCreatePlayer: { Protocol_ObjectCreatePlayer decoded(data); - this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); + this->InitiatePlayer( decoded.objectID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); } return GameClientState::event_processed; case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ @@ -553,17 +671,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; @@ -571,6 +701,8 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { Protocol_ObjectDie decoded(data); // if is this player. Remember to change camera + int killerID = decoded.killerID; + int victimID = decoded.objectID; if( this->privData->myId == decoded.objectID ) { this->currGameUI = this->respawnUI; @@ -591,6 +723,40 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectAction: + { + Protocol_ObjectAction decoded(data); + + C_Player *player; + player = (this->privData->players)[decoded.objectID]; + + if( player ) + { + if( this->privData->myId == decoded.objectID ) + { + // my player animation + //} + //else + //{ + // HACK for now animate my char + switch (decoded.animationID) + { + case GameLogic::PlayerAction::PlayerAction_Walk: + player->playAnimation(L"run_forwards", true); + break; + case GameLogic::PlayerAction::PlayerAction_Jump: + player->playAnimation(L"movement", true); + break; + case GameLogic::PlayerAction::PlayerAction_Idle: + player->playAnimation(L"idle", true); + break; + default: + break; + } + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 6d8c0d37..1486fdda 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -33,7 +33,7 @@ bool GamingUI::Init() // z value should be between 0.5 - 0.9 so that it will be behind other states // add textures and text this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); - this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f)); + this->text = new Text_UI(L"hej", Float3(0.3f,0.0f,0.1f), Float2(0.1f,0.1f)); return true; } @@ -105,7 +105,7 @@ void GamingUI::ReadKeyInput() float yaw = this->input->GetYaw(); //if( yaw != 0.0f ) //This made the camera reset to a specific rotation. { - this->netClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity,camera->GetLook()) ); + this->netClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity, camera->GetLook()) ); } } diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index bfea6d01..c1341f32 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -68,6 +68,8 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->connectIP->ReserveLines( 1 ); this->privData->connectIP->AppendText( L"127.0.0.1" ); //this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server + //this->privData->connectIP->AppendText( L"194.47.150.189" ); // HACK: connecting to Robins server + this->privData->connectIP->SetFontHeight( 0.08f ); this->privData->connectIP->SetLineSpacing( 0.005f ); this->privData->connectIP->SetTopAligned(); @@ -209,4 +211,4 @@ const GameClientState::NetEvent& LanMenuState::DataRecieved( const NetEvent &mes return message; -} \ No newline at end of file +} diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 6d68eb58..5553303e 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -242,5 +242,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) } } + Graphics::API::EndLoadingModels(); + this->privData->nextState = ClientState::ClientState_Game; } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index a092c81e..62f3599e 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -11,10 +11,18 @@ AttatchmentMassDriver::AttatchmentMassDriver(void) this->owner = 0; this->heldObject = NULL; this->hasObject = false; + this->currentEnergy = StandardMaxEnergy; + this->maxEnergy = StandardMaxEnergy; + this->rechargeRate = StandardrechargeRate; + this->force = Standardforce; } AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) { + this->currentEnergy = StandardMaxEnergy; + this->maxEnergy = StandardMaxEnergy; + this->rechargeRate = StandardrechargeRate; + this->force = Standardforce; this->owner = &owner; this->heldObject = NULL; @@ -36,15 +44,27 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, switch (usage) { case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: - ForcePush(usage,dt); + if(currentEnergy >= 90.0f) + { + currentEnergy -= 90.0f; + ForcePush(usage,dt); + } break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - ForcePull(usage,dt); + if(currentEnergy >= 1.0f) + { + currentEnergy -= 1.0f; + ForcePull(usage,dt); + } break; case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: - ForceZip(usage,dt); + if(currentEnergy >= 90.0f) + { + currentEnergy -= 90.0f; + ForceZip(usage,dt); + } break; } @@ -56,20 +76,22 @@ void AttatchmentMassDriver::Update(float dt) //update position of heldObject if there is an object being held if(hasObject) { - //Oyster::Physics::ICustomBody::State state; - //state = heldObject->GetState(); Oyster::Math::Float3 ownerPos = owner->GetPosition(); Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState(); Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2]; up *= -0.3f; - Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*5); - - //state.centerPos = pos; + Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*2); heldObject->SetPosition(pos); heldObject->SetLinearVelocity(Oyster::Math::Float3::null); - //heldObject->SetState(state); + currentEnergy += rechargeRate * 0.5f; //rechargeRate is halfed if you are holding an object } + else + { + currentEnergy += rechargeRate; + } + + } /******************************************************** @@ -83,9 +105,9 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float if(hasObject) { - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force); heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); - + ((DynamicObject*)(heldObject->GetCustomTag()))->RemoveManipulation(); hasObject = false; heldObject = NULL; return; @@ -96,14 +118,13 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float Oyster::Math::Float lenght = 10; Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos; - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force * 0.6f); Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); - - forcePushData args; args.pushForce = pushForce; + args.p = this->owner; Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); @@ -115,7 +136,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float ********************************************************/ void AttatchmentMassDriver::ForceZip(const WEAPON_FIRE &usage, float dt) { - Oyster::Math::Float3 force = Oyster::Math::Float4(this->owner->GetLookDir()) * (1000); + Oyster::Math::Float3 force = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force); this->owner->GetRigidBody()->ApplyImpulse(force); } @@ -136,11 +157,12 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) Oyster::Math::Float lenght = 10; Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos; - Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (100); + Oyster::Math::Float4 pullForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force * 0.2); Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); forcePushData args; - args.pushForce = -pushForce; + args.pushForce = -pullForce; + args.p = this->owner; Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); @@ -149,7 +171,7 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) { - Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized()*5; + Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized()*2; Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,10); Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp); diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index 51368e91..385fcca3 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -4,8 +4,14 @@ #ifndef ATTATCHMENTMASSDRIVER_H #define ATTATCHMENTMASSDRIVER_H #include "IAttatchment.h" + + + namespace GameLogic { + const Oyster::Math::Float StandardMaxEnergy = 100.0f; + const Oyster::Math::Float StandardrechargeRate = 0.5f; + const Oyster::Math::Float Standardforce = 1000.0f; class AttatchmentMassDriver : public IAttatchment { @@ -53,6 +59,19 @@ namespace GameLogic Oyster::Physics::ICustomBody *heldObject; bool hasObject; + Oyster::Math::Float force; + + Oyster::Math::Float maxEnergy; + Oyster::Math::Float currentEnergy; + + Oyster::Math::Float rechargeRate; + + struct Aim + { + + }; + + }; } #endif diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e042765..3e931f8e 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -10,6 +10,8 @@ #include "Portal.h" #include "ExplosiveCrate.h" +#include "PickupSystem/PickupHealth.h" + using namespace Oyster; using namespace GameLogic; @@ -108,13 +110,31 @@ using namespace GameLogic; obj.SetPosition(target); } - void ExplosiveCrate::ExplosiveCrateCollision(Oyster::Physics::ICustomBody *rigidBodyCrate, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + void ExplosiveCrate::ExplosiveCrateCollision(Oyster::Physics::ICustomBody *objA, Oyster::Physics::ICustomBody *objB, Oyster::Math::Float kineticEnergyLoss) { - int forceThreashHold = 200000; //how much force for the box to explode of the impact + - Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed? + Object *realObjA = ((Object*)(objA->GetCustomTag())); + Object *realObjB = (Object*)objB->GetCustomTag(); + ExplosiveCrate* crate; - switch (realObj->GetObjectType()) + if(!realObjA) + return; + if(!realObjB) + return; + + //check who is player and who is the object + if(realObjA->GetObjectType() == ObjectSpecialType::ObjectSpecialType_RedExplosiveBox) + { + crate = (ExplosiveCrate*)realObjA; + } + else + { + crate = (ExplosiveCrate*)realObjB; + realObjB = realObjA; + } + + switch (realObjB->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_Generic: break; @@ -122,29 +142,15 @@ using namespace GameLogic; break; case ObjectSpecialType::ObjectSpecialType_Player: - ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag()); - - - Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos; + if(crate->hasExploaded) return; + Oyster::Math::Float3 pos = crate->GetRigidBody()->GetState().centerPos; Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius); Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode); - + crate->hasExploaded = true; delete hitSphere; break; } - /*if(kineticEnergyLoss > forceThreashHold) - { - ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag()); - - - Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos; - Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius); - - Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode); - - delete hitSphere; - }*/ } void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args) @@ -155,16 +161,21 @@ using namespace GameLogic; Oyster::Math::Float3 explosionCenterPos = ExplosionSource->GetPosition(); Oyster::Math::Float3 hitObjectPos = obj->GetState().centerPos; Oyster::Math::Float3 force = (((hitObjectPos- explosionCenterPos).GetNormalized()) * ExplosionSource->pushForceMagnitude); - + + if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player) { Player *hitPlayer = (Player*)realObj; - + hitPlayer->DamageLife(ExplosionSource->extraDamageOnCollision); + //hitPlayer->GetRigidBody()->ApplyImpulse(force); + //hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision()); + realObj->GetRigidBody()->ApplyImpulse(force * 5); //do shredding damage } - realObj->GetRigidBody()->ApplyImpulse(force); + + } @@ -181,11 +192,11 @@ using namespace GameLogic; Oyster::Math::Float angularFactor = deltaPos.GetNormalized().Dot( (objPrevVel - playerPrevVel).GetNormalized()); Oyster::Math::Float impactPower = deltaSpeed * angularFactor; - Oyster::Math::Float damageFactor = 0.1f; + Oyster::Math::Float damageFactor = 0.01f; int damageDone = 0; - int forceThreashHold = 100; //FIX: balance this + int forceThreashHold = 30; //FIX: balance this if(impactPower > forceThreashHold) //should only take damage if the force is high enough { @@ -198,7 +209,7 @@ using namespace GameLogic; damageDone = (impactPower * obj.GetRigidBody()->GetState().mass)* damageFactor; } - //player.DamageLife(damageDone); + player.DamageLife(damageDone); } } @@ -221,6 +232,58 @@ using namespace GameLogic; { return Physics::ICustomBody::SubscriptMessage_none; } + + void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *objA, Oyster::Physics::ICustomBody *objB, Oyster::Math::Float kineticEnergyLoss) + { + + DynamicObject *realObjA = dynamic_cast((Object*)objA->GetCustomTag()); + + DynamicObject *realObjB = dynamic_cast((Object*)objB->GetCustomTag()); + + if(!realObjA || !realObjB) // one of the objects cannot be cast into a dynamicObject and so we leave the function + { + return; + } + + //check which obj is the one that is already affected, if both are then use the special case of changing ownership. + if(realObjA->getAffectingPlayer() == NULL && realObjB->getAffectingPlayer() == NULL) //None of the objects have a player affecting them + { + return;//leave function as the are not to transfer any ownership + } + + if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() == NULL) + { + //realobjA is the affectedObject, transfer this to realobjB + realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + + } + if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL) + { + //realobjB is the affectedObject, transfer this to realobjA + realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); + + } + + if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL) + { + //Both objects have a player affecting them, now use the special case + if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() ) + { + //realObjA is the winner and will change Bs ownership to A + realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + } + else + { + realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); + //realObjB is the winner and will change As ownership to B + } + } + + + + + } + Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_none; @@ -245,7 +308,17 @@ using namespace GameLogic; if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World) return; + + obj->ApplyImpulse(((forcePushData*)(args))->pushForce); + + + DynamicObject *dynamicObj = dynamic_cast(realObj); + + if(dynamicObj) + { + dynamicObj->SetAffectedBy(*((forcePushData*)(args))->p); + } } void AttatchmentMassDriver::AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args) @@ -263,12 +336,21 @@ using namespace GameLogic; Object* realObj = (Object*)(obj->GetCustomTag()); //check so that it is an object that you can pickup - switch(realObj->GetObjectType()) + DynamicObject *dynamicObj = dynamic_cast(realObj); + + if(!dynamicObj) return; + + if(dynamicObj->getManipulatingPlayer() != NULL) + { + return; + } + + switch(dynamicObj->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_StandardBox: weapon->heldObject = obj; //weapon now holds the object weapon->hasObject = true; - + dynamicObj->SetManipulatingPlayer(*weapon->owner); //TODO: add if this is to be a struggle of who has the most power in its weapon, the player that is already manipulating the object or you. if you then you take the object from the other player, if not then you do not take the object break; } @@ -276,4 +358,31 @@ using namespace GameLogic; } + } + + //General collision collision for pickups + //It calls the collision function defined in each pickup. + void Pickup::PickupCollision(Oyster::Physics::ICustomBody* objA, Oyster::Physics::ICustomBody* objB, Oyster::Math::Float kineticEnergyLoss) + { + //Check if player is a player. + Object* a = (Object*)objA->GetCustomTag(); + Object* b = (Object*)objB->GetCustomTag(); + + if(!a) + return; + if(!b) + return; + + if(b->GetObjectType() == ObjectSpecialType_Player) + { + ((Pickup*)a)->OnCollision((Player*)(b)); + } + else if(a->GetObjectType() != ObjectSpecialType_Player) + { + //One of the objects are not a player. + //Do nothing. + return; + } + + ((Pickup*)b)->OnCollision((Player*)a); } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index e6d9ff49..844deaf2 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -1,5 +1,6 @@ #include "DynamicObject.h" #include "CollisionManager.h" +#include "Player.h" using namespace GameLogic; using namespace Oyster::Math; @@ -10,6 +11,8 @@ DynamicObject::DynamicObject() { this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) @@ -17,12 +20,16 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev { this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) { this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -31,6 +38,8 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev this->extraDamageOnCollision = extraDamageOnCollision; this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -39,6 +48,8 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P this->extraDamageOnCollision = extraDamageOnCollision; this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::~DynamicObject(void) { @@ -74,4 +85,39 @@ void DynamicObject::Activate() { this->isActive = true; this->isReleased = false; +} + +void DynamicObject::SetAffectedBy(Player &player) +{ + this->affectedBy = &player; + if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player + { + player.AddAffectedObject(*this); + } + +} + +Player* DynamicObject::getAffectingPlayer() +{ + return this->affectedBy; +} + +void DynamicObject::RemoveAffectedBy() +{ + this->affectedBy = NULL; +} + +GameLogic::Player* DynamicObject::getManipulatingPlayer() +{ + return this->manipulatedBy; +} + +void DynamicObject::SetManipulatingPlayer(GameLogic::Player &player) +{ + this->manipulatedBy = &player; +} + +void DynamicObject::RemoveManipulation() +{ + this->manipulatedBy = NULL; } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 8a32e849..03a03ad6 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -9,6 +9,7 @@ namespace GameLogic { + class Player; class DynamicObject : public Object { @@ -28,9 +29,22 @@ namespace GameLogic void Inactivate(); void Activate(); + void SetAffectedBy(GameLogic::Player &player); + void SetManipulatingPlayer(GameLogic::Player &player); + void RemoveAffectedBy(); + void RemoveManipulation(); + GameLogic::Player* getAffectingPlayer(); + GameLogic::Player* getManipulatingPlayer(); + + static void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + private: bool isActive; bool isReleased; + protected: + GameLogic::Player *affectedBy; + GameLogic::Player *manipulatedBy; + }; diff --git a/Code/Game/GameLogic/ExplosiveCrate.cpp b/Code/Game/GameLogic/ExplosiveCrate.cpp index d236d400..cf011ce4 100644 --- a/Code/Game/GameLogic/ExplosiveCrate.cpp +++ b/Code/Game/GameLogic/ExplosiveCrate.cpp @@ -7,6 +7,7 @@ ExplosiveCrate::ExplosiveCrate(void) { this->pushForceMagnitude = 0; this->ExplosionRadius = 0; + this->hasExploaded = false; } ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type, int objectID,Oyster::Math::Float extraDamageOnCollision, Oyster::Math::Float pushForceMagnitude, Oyster::Math::Float ExplosionRadius) @@ -15,6 +16,7 @@ ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpe this->extraDamageOnCollision = extraDamageOnCollision; this->pushForceMagnitude = pushForceMagnitude; this->ExplosionRadius = ExplosionRadius; + this->hasExploaded = false; } ExplosiveCrate::~ExplosiveCrate(void) diff --git a/Code/Game/GameLogic/ExplosiveCrate.h b/Code/Game/GameLogic/ExplosiveCrate.h index 75afdc4a..b6054266 100644 --- a/Code/Game/GameLogic/ExplosiveCrate.h +++ b/Code/Game/GameLogic/ExplosiveCrate.h @@ -18,6 +18,7 @@ namespace GameLogic private: Oyster::Math::Float pushForceMagnitude; Oyster::Math::Float ExplosionRadius; + bool hasExploaded; }; diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index c599fecf..e4782582 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -43,6 +43,9 @@ Game::Game(void) : initiated(false) , onMoveFnc(0) , onDisableFnc(0) + , onDamageTakenFnc(0) + , onRespawnFnc(0) + , onDeadFnc(0) , frameTime(1.0f/120.0f) {} @@ -105,6 +108,7 @@ Game::PlayerData* Game::CreatePlayer() this->players[insert] = new PlayerData(freeID, 0); // user constructor with objectID and teamID this->players[insert]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + this->level->AddPlayerToGame(this->players[insert]); return this->players[insert]; } @@ -125,6 +129,9 @@ void Game::CreateTeam() bool Game::NewFrame() { + // HACK need dynamic delta time + this->level->Update(this->frameTime); + for (unsigned int i = 0; i < this->players.Size(); i++) { if(this->players[i] && this->players[i]->player) this->players[i]->player->BeginFrame(); @@ -149,16 +156,38 @@ void Game::SetFrameTimeLength( float seconds ) this->frameTime = seconds; } -void Game::SetSubscription(GameEvent::ObjectMovedFunction functionPointer) +void Game::SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) { this->onMoveFnc = functionPointer; } -void Game::SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) +void Game::SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) { this->onDisableFnc = functionPointer; - } - +void Game::SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) +{ + this->onEnableFnc = functionPointer; +} +void Game::SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) +{ + this->onDamageTakenFnc = functionPointer; +} +void Game::SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) +{ + this->onRespawnFnc = functionPointer; +} +void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) +{ + this->onDeadFnc = functionPointer; +} +void Game::SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) +{ + this->onPlayerActionEventFnc = functionPointer; +} +void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) +{ + this->onPickupEventFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); @@ -186,6 +215,5 @@ void Game::PhysicsOnMove(const ICustomBody *object) } void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto) { - if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0, 0); + if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0); } - diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 81410ac8..22b9fbda 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -45,7 +45,7 @@ namespace GameLogic ObjectSpecialType GetObjectType() const override; void Inactivate() override; void Release() override; - + Player* GetPlayer(); Player *player; }; @@ -63,7 +63,8 @@ namespace GameLogic int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const override; - + void Update(float deltaTime); + void AddPlayerToGame(IPlayerData *player); Level *level; }; @@ -78,22 +79,35 @@ namespace GameLogic bool NewFrame() override; void SetFPS( int FPS ) override; void SetFrameTimeLength( float seconds ) override; - void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) override; - void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) override; + void SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) override; + void SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) override; + void SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) override; + void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override; + void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override; + void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; + void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; + void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; static void PhysicsOnMove(const Oyster::Physics::ICustomBody *object); static void PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto); + static void PhysicsOnDead(const Oyster::Physics::ICustomBody *object); Utility::DynamicMemory::DynamicArray players; LevelData* level; float frameTime; bool initiated; - GameEvent::ObjectDisabledFunction onDisableFnc; - GameEvent::ObjectMovedFunction onMoveFnc; + GameEvent::ObjectMovedFunction onMoveFnc; + GameEvent::ObjectDisabledFunction onDisableFnc; + GameEvent::ObjectEnabledFunction onEnableFnc; + GameEvent::ObjectHpFunction onDamageTakenFnc; + GameEvent::ObjectRespawnedFunction onRespawnFnc; + GameEvent::ObjectDeadFunction onDeadFnc; + GameEvent::AnimationEventFunction onPlayerActionEventFnc; + GameEvent::PickupEventFunction onPickupEventFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 290b1c30..653fc26b 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -26,7 +26,13 @@ namespace GameLogic namespace GameEvent { typedef void(*ObjectMovedFunction)(IObjectData* object); // Callback method that recieves and object - typedef void(*ObjectDisabledFunction)(IObjectData* object, float seconds); // Callback method that recieves and object + typedef void(*ObjectDisabledFunction)(IObjectData* object); // Callback method that recieves and object + typedef void(*ObjectEnabledFunction)(IObjectData* object); // Callback method that recieves and object + typedef void(*ObjectHpFunction)(IObjectData* object, float hp); // Callback method that sends obj HP + typedef void(*ObjectRespawnedFunction)(IObjectData* object, Oyster::Math::Float3 spawnPos ); // Callback method that sends spawnPos + typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer + typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer + typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer //etc... }; @@ -114,8 +120,10 @@ namespace GameLogic class ILevelData :public IObjectData { public: + virtual void Update(float deltaTime) = 0; virtual int getNrOfDynamicObj()const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0; + virtual void AddPlayerToGame(IPlayerData *player) = 0; virtual void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& destMem) const = 0; }; @@ -172,12 +180,14 @@ namespace GameLogic /** Set a specific object event subscription callback * @param */ - virtual void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) = 0; - - /** Set a specific object event subscription callback - * @param - */ - virtual void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) = 0; + virtual void SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) = 0; + virtual void SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) = 0; + virtual void SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) = 0; + virtual void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) = 0; + virtual void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) = 0; + virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; + virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; + virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 52b7722b..08a932d2 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -173,6 +173,9 @@ + + + @@ -194,6 +197,9 @@ + + + diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 9ae0d482..f006ad27 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -2,8 +2,10 @@ #define GAMELOGICSTATES_H #include "OysterMath.h" + namespace GameLogic { + class Player; enum PLAYER_MOVEMENT { PLAYER_MOVEMENT_FORWARD = 0, @@ -18,7 +20,8 @@ namespace GameLogic PLAYER_STATE_WALKING = 1, PLAYER_STATE_IDLE = 2, PLAYER_STATE_DEAD = 4, - PLAYER_STATE_INVALID = 8, + PLAYER_STATE_DIED = 8, + PLAYER_STATE_INVALID = 16, }; enum WEAPON_FIRE @@ -41,6 +44,7 @@ namespace GameLogic struct forcePushData { Oyster::Math::Float3 pushForce; + Player *p; }; diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index 903cb959..f16f4072 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -54,9 +54,17 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const { - mem.Resize(level->dynamicObjects.Size()); - for(int i = 0; i < (int)level->dynamicObjects.Size(); i++) + mem.Resize(level->GetDynamicObject().Size()); + for(int i = 0; i < (int)level->GetDynamicObject().Size(); i++) { - mem[i] = level->dynamicObjects[i]; + mem[i] = level->GetDynamicObject()[i]; } +} +void Game::LevelData::Update(float deltaTime) +{ + this->level->Update(deltaTime); +} +void Game::LevelData::AddPlayerToGame(IPlayerData *player) +{ + this->level->AddPlayerToGame(((PlayerData*)player)->GetPlayer()); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index ad409e3b..88b4bbbe 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -101,4 +101,8 @@ void Game::PlayerData::Inactivate() void Game::PlayerData::Release() { this->player->ReleaseDynamicObject(); +} +Player* Game::PlayerData::GetPlayer() +{ + return this->player; } \ No newline at end of file diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index c9938dbd..0f0ab632 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -12,7 +12,7 @@ using namespace GameLogic; using namespace Utility::DynamicMemory; using namespace Oyster::Physics; - +using namespace Oyster::Math; Level::Level(void) { @@ -59,19 +59,19 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_RedExplosiveBox: { - Oyster::Math::Float dmg = 50; - Oyster::Math::Float force = 50; - Oyster::Math::Float radie = 50; + Oyster::Math::Float dmg = 120; + Oyster::Math::Float force = 500; + Oyster::Math::Float radie = 3; gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); } break; @@ -81,12 +81,12 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_CrystalFormation: @@ -98,7 +98,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_JumpPad: @@ -131,6 +131,11 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; + case ObjectSpecialType_PickupHealth: + { + gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); + } + break; default: { gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); @@ -216,7 +221,6 @@ bool Level::InitiateLevel(std::wstring levelPath) std::string convertedLevelPath = converterX.to_bytes(levelPath); objects = ll.LoadLevel(convertedLevelPath); - if(objects.size() == 0) return false; @@ -264,7 +268,12 @@ bool Level::InitiateLevel(std::wstring levelPath) { // create game object Object* staticGameObj = CreateGameObj(staticObjData, rigidBody_Static); - if(staticGameObj != NULL) + + if(staticObjData->specialTypeID == ObjectSpecialType_PickupHealth) + { + this->pickupSystem.CreatePickup((PickupHealth*)staticGameObj); + } + else if(staticGameObj != NULL) { this->staticObjects.Push((StaticObject*)staticGameObj); } @@ -321,6 +330,7 @@ bool Level::InitiateLevel(std::wstring levelPath) break; } } + return true; } bool Level::InitiateLevel(float radius) @@ -393,7 +403,20 @@ void Level::AddPlayerToTeam(Player *player, int teamID) { this->teamManager.AddPlayerToTeam(player,teamID); } - +void Level::AddPlayerToGame(Player *player) +{ + this->playerObjects.Push(player); +} +void Level::RemovePlayerFromGame(Player *player) +{ + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if ((Player*)this->playerObjects[i] == player) + { + //this->playerObjects[i]. + } + } +} void Level::CreateTeam(int teamSize) { this->teamManager.CreateTeam(teamSize); @@ -401,9 +424,34 @@ void Level::CreateTeam(int teamSize) void Level::RespawnPlayer(Player *player) { - this->teamManager.RespawnPlayerRandom(player); -} + //this->teamManager.RespawnPlayerRandom(player); + Float3 spawnPoint = spawnPoints[0]; + player->Respawn(spawnPoint); +} +void Level::Update(float deltaTime) +{ + // update lvl-things + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + } + } + + this->pickupSystem.Update(); +} int Level::getNrOfDynamicObj() { return this->dynamicObjects.Size(); @@ -417,10 +465,23 @@ Object* Level::GetObj( int ID) const } return NULL; } + void Level::PhysicsOnMoveLevel(const ICustomBody *object) { // function call from physics update when object was moved Object* temp = (Object*)object->GetCustomTag(); ((Game*)&Game::Instance())->onMoveFnc(temp); - } +Utility::DynamicMemory::DynamicArray> Level::GetPlayers() +{ + return this->playerObjects; +} +Utility::DynamicMemory::DynamicArray> Level::GetStaticObjects() +{ + return this->staticObjects; +} +Utility::DynamicMemory::DynamicArray> Level::GetDynamicObject() +{ + return this->dynamicObjects; +} + diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 9dce227d..7d6c25c9 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -16,6 +16,10 @@ #include "DynamicArray.h" #include "LevelLoader.h" +#include "PickupSystem\PickupSystem.h" +#include "PickupSystem\PickupHealth.h" + +const int DEATH_TIMER = 5; namespace GameLogic { @@ -48,7 +52,8 @@ namespace GameLogic * @param teamID: ArrayPos of the team you want to add the player to ********************************************************/ void AddPlayerToTeam(Player *player, int teamID); - + void AddPlayerToGame(Player *player); + void RemovePlayerFromGame(Player *player); /******************************************************** * Respawns a player on a random teammate @@ -64,12 +69,20 @@ namespace GameLogic ********************************************************/ static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + void Update(float deltaTime); + int getNrOfDynamicObj(); Object* GetObj( int ID ) const; + + static void PlayerDied( Player* player ); static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); + Utility::DynamicMemory::DynamicArray> GetPlayers(); + Utility::DynamicMemory::DynamicArray> GetStaticObjects(); + Utility::DynamicMemory::DynamicArray> GetDynamicObject(); - //private: + private: + Utility::DynamicMemory::DynamicArray> playerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; @@ -78,6 +91,7 @@ namespace GameLogic StaticObject *levelObj; int objID; Utility::DynamicMemory::DynamicArray spawnPoints; + PickupSystem pickupSystem; }; diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp new file mode 100644 index 00000000..73a319f8 --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -0,0 +1,32 @@ +#include "Pickup.h" +#include "../Game.h" + +using namespace GameLogic; + +Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisionFunc, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime) + : StaticObject(rigidBody, collisionFunc, type, objectID) +{ + this->active = true; + this->spawnTime = spawnTime; + timer.reset(); +} + +Pickup::~Pickup() +{} + +void Pickup::Update() +{ + if(!active) + { + if(timer.getElapsedSeconds() >= spawnTime) + { + active = true; + ((Game*)&Game::Instance())->onEnableFnc(this); + } + } +} + +bool Pickup::IsActive() +{ + return active; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.h b/Code/Game/GameLogic/PickupSystem/Pickup.h new file mode 100644 index 00000000..e48017fc --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/Pickup.h @@ -0,0 +1,35 @@ +#ifndef PICKUP_H +#define PICKUP_H + +#include "../StaticObject.h" +#include "../Player.h" +#include "WinTimer.h" + +typedef void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss); + +namespace GameLogic +{ + class Pickup : public StaticObject + { + public: + Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisionFunc, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime); + virtual ~Pickup(); + + virtual void Update(); + + bool IsActive(); + + virtual void OnCollision(Player *player) = 0; + + static void PickupCollision(Oyster::Physics::ICustomBody *rigidBodyCrate, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + + protected: + bool active; + + Utility::WinTimer timer; + double spawnTime; + + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp new file mode 100644 index 00000000..56cbef1e --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp @@ -0,0 +1,18 @@ +#include "PickupHealth.h" + +using namespace GameLogic; + +PickupHealth::PickupHealth(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime, Oyster::Math::Float healthValue) + : Pickup(rigidBody, Pickup::PickupCollision, type, objectID, spawnTime) +{ + this->hpValue = healthValue; +} + +PickupHealth::~PickupHealth() +{} + +void PickupHealth::OnCollision(Player *player) +{ + timer.reset(); + player->DamageLife(-hpValue); +} \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.h b/Code/Game/GameLogic/PickupSystem/PickupHealth.h new file mode 100644 index 00000000..5d5db809 --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.h @@ -0,0 +1,27 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef PICKUP_HEALTH_H +#define PICKUP_HEALTH_H + +#include "Pickup.h" + +namespace GameLogic +{ + class PickupHealth : public Pickup + { + public: + PickupHealth(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime, Oyster::Math::Float HealthValue); + virtual ~PickupHealth(); + + + void OnCollision(Player *player); + + protected: + int hpValue; + + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp b/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp new file mode 100644 index 00000000..0f60ddc9 --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp @@ -0,0 +1,22 @@ +#include "PickupSystem.h" + +using namespace GameLogic; + +PickupSystem::PickupSystem() +{} + +PickupSystem::~PickupSystem() +{} + +void PickupSystem::CreatePickup(Pickup* pickup) +{ + pickups.push_back(pickup); +} + +void PickupSystem::Update() +{ + for(int i = 0; i < pickups.size(); i++) + { + pickups.at(i)->Update(); + } +} \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupSystem.h b/Code/Game/GameLogic/PickupSystem/PickupSystem.h new file mode 100644 index 00000000..4bd1e69e --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupSystem.h @@ -0,0 +1,30 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef PICKUP_SYSTEM_H +#define PICKUP_SYSTEM_H + +#include + +#include "Pickup.h" + +namespace GameLogic +{ + class PickupSystem + { + public: + PickupSystem(); + ~PickupSystem(); + + void CreatePickup(Pickup* pickup); + + void Update(); + + private: + std::vector> pickups; + + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 508067a4..5d36dbd9 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -11,56 +11,28 @@ const float KEY_TIMER = 0.03f; Player::Player() :DynamicObject() { - + Player::initPlayerData(); + AffectedObjects.Reserve(15); + this->weapon = NULL; + this->teamID = -1; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { - weapon = new Weapon(2,this); - - this->life = 100; + this->weapon = new Weapon(2,this); + Player::initPlayerData(); + AffectedObjects.Reserve(15); this->teamID = teamID; - this->playerState = PLAYER_STATE_IDLE; - this->lookDir = Oyster::Math::Float3(0,0,-1); - key_forward = 0; - key_backward = 0; - key_strafeRight = 0; - key_strafeLeft = 0; - key_jump = 0; - invincibleCooldown = 0; - - this->previousPosition = Oyster::Math::Float3(0,0,0); - - this->moveDir = Oyster::Math::Float3(0,0,0); - this->moveSpeed = 100; - this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); - - this->rotationUp = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { - weapon = new Weapon(2,this); - - this->life = 100; + this->weapon = new Weapon(2,this); + Player::initPlayerData(); + AffectedObjects.Reserve(15); this->teamID = teamID; - this->playerState = PLAYER_STATE_IDLE; - this->lookDir = Oyster::Math::Float3(0,0,-1); - key_forward = 0; - key_backward = 0; - key_strafeRight = 0; - key_strafeLeft = 0; - key_jump = 0; - invincibleCooldown = 0; - - this->previousPosition = Oyster::Math::Float3(0,0,0); - this->moveDir = Oyster::Math::Float3(0,0,0); - this->moveSpeed = 20; - this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); - - this->rotationUp = 0; } Player::~Player(void) @@ -71,135 +43,186 @@ Player::~Player(void) weapon = NULL; } } +void Player::initPlayerData() +{ + this->playerStats.hp = MAX_HP; + this->playerStats.movementSpeed = BASIC_SPEED; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; + this->playerState = PLAYER_STATE_IDLE; + this->lookDir = Oyster::Math::Float3(0,0,-1); + + this->key_forward = 0; + this->key_backward = 0; + this->key_strafeRight = 0; + this->key_strafeLeft = 0; + this->key_jump = 0; + this->invincibleCooldown = 0; + this->deathTimer = 0; + + this->rotationUp = 0; +} void Player::BeginFrame() { - weapon->Update(0.002f); - //Object::BeginFrame(); + if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED) + { + weapon->Update(0.002f); - Oyster::Math::Float maxSpeed = 30; + Oyster::Math::Float maxSpeed = 30; - // Rotate player accordingly + // Rotate player accordingly this->rigidBody->AddRotationAroundY(this->rotationUp); - this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); + this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); - // Direction data - Oyster::Math::Float4x4 xform; - xform = this->rigidBody->GetState().GetOrientation(); + // Direction data + Oyster::Math::Float4x4 xform; + xform = this->rigidBody->GetState().GetOrientation(); - Oyster::Math::Float3 forwardDir = xform.v[2]; - Oyster::Math::Float3 upDir = xform.v[1]; - Oyster::Math::Float3 rightDir = xform.v[0]; - forwardDir.Normalize(); - upDir.Normalize(); - rightDir.Normalize(); + Oyster::Math::Float3 forwardDir = xform.v[2]; + Oyster::Math::Float3 upDir = xform.v[1]; + Oyster::Math::Float3 rightDir = xform.v[0]; + forwardDir.Normalize(); + upDir.Normalize(); + rightDir.Normalize(); - // Previous velocities data - Oyster::Math::Float3 linearVelocity = this->rigidBody->GetLinearVelocity(); - Oyster::Math::Float3 forwardVelocity = linearVelocity*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)); - Oyster::Math::Float forwardSpeed = (linearVelocity*forwardDir).GetLength(); - Oyster::Math::Float3 rightVelocity = linearVelocity*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)); - Oyster::Math::Float rightSpeed = (linearVelocity*rightDir).GetLength(); - Oyster::Math::Float3 upVelocity = linearVelocity*Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z)); + // Previous velocities data + Oyster::Math::Float3 linearVelocity = this->rigidBody->GetLinearVelocity(); + Oyster::Math::Float3 forwardVelocity = linearVelocity*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)); + Oyster::Math::Float forwardSpeed = (linearVelocity*forwardDir).GetLength(); + Oyster::Math::Float3 rightVelocity = linearVelocity*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)); + Oyster::Math::Float rightSpeed = (linearVelocity*rightDir).GetLength(); + Oyster::Math::Float3 upVelocity = linearVelocity*Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z)); - // Walking data - Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); - Oyster::Math::Float walkSpeed = this->moveSpeed*0.2f; + // Walking data + Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); + Oyster::Math::Float walkSpeed = this->playerStats.movementSpeed*0.2f; - // Check for input - if(key_forward > 0.001) - { - key_forward -= gameInstance->GetFrameTime(); - walkDirection += forwardDir; - } - if(key_backward > 0.001) - { - key_backward -= gameInstance->GetFrameTime(); - walkDirection -= forwardDir; - } - if(key_strafeRight > 0.001) - { - key_strafeRight -= gameInstance->GetFrameTime(); - walkDirection += rightDir; - } - if(key_strafeLeft > 0.001) - { - key_strafeLeft -= gameInstance->GetFrameTime(); - walkDirection -= rightDir; - } + // Check for input + if(key_forward > 0.001) + { + key_forward -= gameInstance->GetFrameTime(); + walkDirection += forwardDir; + } + if(key_backward > 0.001) + { + key_backward -= gameInstance->GetFrameTime(); + walkDirection -= forwardDir; + } + if(key_strafeRight > 0.001) + { + key_strafeRight -= gameInstance->GetFrameTime(); + walkDirection += rightDir; + } + if(key_strafeLeft > 0.001) + { + key_strafeLeft -= gameInstance->GetFrameTime(); + walkDirection -= rightDir; + } - // Dampen velocity if certain keys are not pressed + // Dampen velocity if certain keys are not pressed if(key_jump <= 0.001 && IsWalking()) - { - if(key_forward <= 0.001 && key_backward <= 0.001) { - forwardVelocity *= Oyster::Math::Float3(0.2f*fabs(forwardDir.x), 0.2f*fabs(forwardDir.y), 0.2f*fabs(forwardDir.z)); + if(key_forward <= 0.001 && key_backward <= 0.001) + { + forwardVelocity *= Oyster::Math::Float3(0.2f*fabs(forwardDir.x), 0.2f*fabs(forwardDir.y), 0.2f*fabs(forwardDir.z)); + } + if(key_strafeRight <= 0.001 && key_strafeLeft <= 0.001) + { + rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); + } } - if(key_strafeRight <= 0.001 && key_strafeLeft <= 0.001) - { - rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); - } - } - - // Walk if walkdirection is something - if(walkDirection != Oyster::Math::Float3::null) - { - walkDirection.Normalize(); - // If on the ground, accelerate normally - if(IsWalking()) + if(walkDirection == Oyster::Math::Float3::null) { - if(forwardSpeed < maxSpeed) + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { - forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed; - } - if(rightSpeed < maxSpeed) - { - rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), abs(rightDir.y), fabs(rightDir.z)) * walkSpeed; + if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; } } - // If in the air, accelerate slower + // Walk if walkdirection is something + if(walkDirection != Oyster::Math::Float3::null) + { + walkDirection.Normalize(); + + // If on the ground, accelerate normally + if(IsWalking()) + { + if(forwardSpeed < maxSpeed) + { + forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed; + } + if(rightSpeed < maxSpeed) + { + rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), abs(rightDir.y), fabs(rightDir.z)) * walkSpeed; + } + } + // If in the air, accelerate slower if(IsJumping()) - { - if(forwardSpeed < maxSpeed) { - forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed*0.2f; + if(forwardSpeed < maxSpeed) + { + forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed*0.2f; + } + if(rightSpeed < maxSpeed) + { + rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; + } } - if(rightSpeed < maxSpeed) + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { - rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; + if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Walk); + this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; } } - } - // Adjust velocities so no squaring occurs - forwardVelocity *= Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)); - rightVelocity *= Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)); - upVelocity *= Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z)); + // Adjust velocities so no squaring occurs + forwardVelocity *= Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)); + rightVelocity *= Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)); + upVelocity *= Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z)); - this->rigidBody->SetLinearVelocity(forwardVelocity+rightVelocity+upVelocity); + this->rigidBody->SetLinearVelocity(forwardVelocity+rightVelocity+upVelocity); - //Jump - if(key_jump > 0.001) - { - this->key_jump -= this->gameInstance->GetFrameTime(); + //Jump + if(key_jump > 0.001) + { + this->key_jump -= this->gameInstance->GetFrameTime(); if(IsWalking()) + { + Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); + this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); + + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Jump); + this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; + } + } + else { - Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); - this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass*20); - this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; + if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING) + { + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; + } } } - - - //this->weapon->Update(0.01f); } void Player::EndFrame() { - - //Object::EndFrame(); + //check if there are any objects that can be removed from the AffectedObjects list + for(int i = 0; i < this->AffectedObjects.Size(); i++) + { + if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) + { + this->AffectedObjects[i]->RemoveAffectedBy(); + this->AffectedObjects.Remove(i); + } + } } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -252,10 +275,13 @@ void Player::UseWeapon(const WEAPON_FIRE &usage) void Player::Respawn(Oyster::Math::Float3 spawnPoint) { - this->life = 100; - this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - this->lookDir = Oyster::Math::Float4(1,0,0); - this->rigidBody->SetPosition(spawnPoint); + if( this->playerState == PLAYER_STATE_DEAD) + { + Player::initPlayerData(); + this->rigidBody->SetPosition(spawnPoint); + this->gameInstance->onRespawnFnc( this, spawnPoint); + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + } } void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir) @@ -315,13 +341,43 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - this->life -= damage; - this->life = 0; + this->playerStats.hp -= damage; + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); - if(this->life <= 0) + if(this->playerStats.hp <= 0) { - this->life = 0; - playerState = PLAYER_STATE_DEAD; - this->gameInstance->onDisableFnc(this, 0.0f); + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; } + +} + +void Player::AddAffectedObject(DynamicObject &AffectedObject) +{ + //check if object already exists in the list, if so then do not add + for(int i = 0; i < AffectedObjects.Size(); i++) + { + if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) + { + //object already exists, exit function + return; + } + } + //else you add the object to the stack + AffectedObjects.Push(&AffectedObject); +} +bool Player::deathTimerTick(float dt) +{ + this->deathTimer -= dt; + if( this->deathTimer <= 0) + { + return true; + } + return false; +} +void Player::setDeathTimer(float deathTimer) +{ + this->deathTimer = deathTimer; + this->playerState = PLAYER_STATE_DEAD; } diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 1fc3443a..c64ba066 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -7,7 +7,10 @@ #include "GameLogicStates.h" #include "OysterMath.h" #include "DynamicObject.h" +#include "DynamicArray.h" +const float MAX_HP = 100.0f; +const float BASIC_SPEED = 30.0f; namespace GameLogic { @@ -15,6 +18,21 @@ namespace GameLogic class Player : public DynamicObject { public: + struct PlayerStats + { + Oyster::Math::Float hp; + Oyster::Math::Float movementSpeed; + //Oyster::Math::Float resistance; + }; + + struct PlayerScore + { + int killScore; + int deathScore; + // int assistScore; + // int suicideScore; + }; + Player(void); Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID); @@ -49,6 +67,8 @@ namespace GameLogic void SetLookDir(const Oyster::Math3D::Float3& lookDir); void TurnLeft(Oyster::Math3D::Float deltaRadians); + + void AddAffectedObject(DynamicObject &AffectedObject); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody @@ -72,6 +92,8 @@ namespace GameLogic PLAYER_STATE GetState() const; void DamageLife(int damage); + void setDeathTimer(float deathTimer); + bool deathTimerTick(float dt); void BeginFrame(); void EndFrame(); @@ -79,9 +101,11 @@ namespace GameLogic private: void Jump(); + void initPlayerData(); private: - Oyster::Math::Float life; + + Utility::DynamicMemory::DynamicArray AffectedObjects; int teamID; Weapon *weapon; PLAYER_STATE playerState; @@ -93,16 +117,15 @@ namespace GameLogic float key_jump; - Oyster::Math::Float3 previousPosition; - Oyster::Math::Float3 moveDir; - Oyster::Math::Float moveSpeed; - Oyster::Math::Float3 previousMoveSpeed; - Oyster::Math::Float rotationUp; + float deathTimer; bool hasTakenDamage; float invincibleCooldown; + PlayerStats playerStats; + PlayerScore playerScore; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 22f8213e..48fa71f7 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -59,7 +59,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectDamage 351 struct Protocol_ObjectDamage :public Oyster::Network::CustomProtocolObject { - int object_ID; + int objectID; float healthLost; //Precentage% Protocol_ObjectDamage() @@ -70,26 +70,28 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - object_ID = -1; + objectID = -1; healthLost = 0.0f; } Protocol_ObjectDamage(Oyster::Network::CustomNetProtocol& p) { - + this->objectID = p[1].value.netInt; + this->healthLost = p[2].value.netFloat; } Protocol_ObjectDamage(int id, float hp) { this->protocol[0].value = protocol_Gameplay_ObjectDamage; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; - + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; healthLost = hp; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = healthLost; return protocol; } @@ -101,8 +103,8 @@ namespace GameLogic //#define protocol_Gameplay_ObjectHealthStatus 352 struct Protocol_ObjectHealthStatus :public Oyster::Network::CustomProtocolObject { + int objectID; float currentHealth; - int id; Protocol_ObjectHealthStatus() { @@ -110,7 +112,7 @@ namespace GameLogic this->protocol[0].value.netShort = protocol_Gameplay_ObjectHealthStatus; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->id = 0; + this->objectID = -1; this->currentHealth = 0.0f; } Protocol_ObjectHealthStatus(int id, float health) @@ -119,16 +121,16 @@ namespace GameLogic this->protocol[0].value.netShort = protocol_Gameplay_ObjectHealthStatus; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->id = id; this->currentHealth = health; + this->objectID = id; this->currentHealth = health; } Protocol_ObjectHealthStatus(Oyster::Network::CustomNetProtocol& p) { - this->id = p[1].value.netInt; + this->objectID = p[1].value.netInt; this->currentHealth = p[2].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->id; + this->protocol[1].value = this->objectID; this->protocol[2].value = this->currentHealth; return protocol; @@ -141,7 +143,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectPosition 353 struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float position[3]; Protocol_ObjectPosition() @@ -153,12 +155,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = 0; + objectID = -1; memset(&position[0], 0, sizeof(float) * 3); } Protocol_ObjectPosition(Oyster::Network::CustomNetProtocol& p) { - object_ID = p[1].value.netShort; + objectID = p[1].value.netShort; position[0] = p[2].value.netFloat; position[1] = p[3].value.netFloat; position[2] = p[4].value.netFloat; @@ -172,12 +174,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&position[0], &v[0], sizeof(float) * 3); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = position[0]; this->protocol[3].value = position[1]; this->protocol[4].value = position[2]; @@ -191,7 +193,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectScale 354 struct Protocol_ObjectScale :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float scale[3]; Protocol_ObjectScale() @@ -203,12 +205,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = 0; + objectID = -1; memset(&scale[0], 0, sizeof(float) * 3); } Protocol_ObjectScale(Oyster::Network::CustomNetProtocol& p) { - object_ID = p[1].value.netShort; + objectID = p[1].value.netShort; scale[0] = p[2].value.netFloat; scale[1] = p[3].value.netFloat; scale[2] = p[4].value.netFloat; @@ -222,12 +224,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&scale[0], &v[0], sizeof(float) * 3); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = scale[0]; this->protocol[3].value = scale[1]; this->protocol[4].value = scale[2]; @@ -241,7 +243,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectRotation 355 struct Protocol_ObjectRotation :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float rotationQ[4]; Protocol_ObjectRotation() @@ -254,12 +256,12 @@ namespace GameLogic this->protocol[4].type = Oyster::Network::NetAttributeType_Float; this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - object_ID = 0; + objectID = -1; memset(&rotationQ[0], 0, sizeof(float) * 4); } Protocol_ObjectRotation(Oyster::Network::CustomNetProtocol& p) { - object_ID = p[1].value.netShort; + objectID = p[1].value.netShort; rotationQ[0] = p[2].value.netFloat; rotationQ[1] = p[3].value.netFloat; rotationQ[2] = p[4].value.netFloat; @@ -275,12 +277,12 @@ namespace GameLogic this->protocol[4].type = Oyster::Network::NetAttributeType_Float; this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&rotationQ[0], &v[0], sizeof(float) * 4); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = rotationQ[0]; this->protocol[3].value = rotationQ[1]; this->protocol[4].value = rotationQ[2]; @@ -295,7 +297,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectEnabled 356 struct Protocol_ObjectPositionRotation :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float position[3]; float rotationQ[4]; @@ -314,13 +316,13 @@ namespace GameLogic this->protocol[7].type = Oyster::Network::NetAttributeType_Float; this->protocol[8].type = Oyster::Network::NetAttributeType_Float; - this->object_ID = 0; + this->objectID = -1; memset(&this->position[0], 0, sizeof(float) * 3); memset(&this->rotationQ[0], 0, sizeof(float) * 4); } Protocol_ObjectPositionRotation(Oyster::Network::CustomNetProtocol& p) { - this->object_ID = p[1].value.netShort; + this->objectID = p[1].value.netShort; //POSITION this->position[0] = p[2].value.netFloat; this->position[1] = p[3].value.netFloat; @@ -346,13 +348,13 @@ namespace GameLogic this->protocol[7].type = Oyster::Network::NetAttributeType_Float; this->protocol[8].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&this->position[0], &p[0], sizeof(float) * 3); memcpy(&this->rotationQ[0], &r[0], sizeof(float) * 4); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->object_ID; + 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]; @@ -404,35 +406,28 @@ namespace GameLogic struct Protocol_ObjectDisable :public Oyster::Network::CustomProtocolObject { int objectID; - float seconds; Protocol_ObjectDisable() { this->protocol[0].value = protocol_Gameplay_ObjectDisabled; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->objectID = 0; - this->seconds = 0.0f; + this->objectID = -1; } - Protocol_ObjectDisable(int objctID, float seconds) + Protocol_ObjectDisable(int objctID) { this->protocol[0].value = protocol_Gameplay_ObjectDisabled; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->objectID = objctID; - this->seconds = seconds; } Protocol_ObjectDisable(Oyster::Network::CustomNetProtocol& p) { this->objectID = p[1].value.netInt; - this->seconds = p[2].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = this->objectID; - this->protocol[2].value = this->seconds; return protocol; } @@ -444,7 +439,7 @@ namespace GameLogic struct Protocol_ObjectCreate :public Oyster::Network::CustomProtocolObject { //ObjectType type; //ie player, box or whatever - int object_ID; + int objectID; std::string name; float position[3]; float rotationQ[4]; @@ -471,13 +466,13 @@ namespace GameLogic this->protocol[11].type = Oyster::Network::NetAttributeType_Float; this->protocol[12].type = Oyster::Network::NetAttributeType_Float; - this->object_ID = 0; + this->objectID = -1; memset(this->position, 0, sizeof(float) * 3); memset(this->rotationQ, 0, sizeof(float) * 4); } Protocol_ObjectCreate( Oyster::Network::CustomNetProtocol& p ) { - this->object_ID = p[1].value.netInt; + this->objectID = p[1].value.netInt; this->name.assign(p[2].value.netCharPtr); this->position[0] = p[3].value.netFloat; @@ -514,7 +509,7 @@ namespace GameLogic this->protocol[11].type = Oyster::Network::NetAttributeType_Float; this->protocol[12].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; this->name = path; memcpy(this->position, p, sizeof(float) * 3); @@ -524,7 +519,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol.Set(2, name); this->protocol[3].value = this->position[0]; this->protocol[4].value = this->position[1]; @@ -544,10 +539,42 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectCreatePlayer 360 + //#define protocol_Gameplay_ObjectDelete 360 + struct Protocol_ObjectDelete :public Oyster::Network::CustomProtocolObject + { + int objectID; + + Protocol_ObjectDelete() + { + this->protocol[0].value = protocol_Gameplay_ObjectDelete; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = -1; + } + Protocol_ObjectDelete(int objctID) + { + this->protocol[0].value = protocol_Gameplay_ObjectDelete; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = objctID; + } + Protocol_ObjectDelete(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netInt; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = this->objectID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + //#define protocol_Gameplay_ObjectCreatePlayer 361 struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject { - /*1*/ int object_ID; + /*1*/ int objectID; /*2*/ int teamId; /*3*/ bool owner; /*4*/ std::string name; @@ -587,7 +614,7 @@ namespace GameLogic Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) { this->owner = p[1].value.netBool; - this->object_ID = p[2].value.netInt; + this->objectID = p[2].value.netInt; this->teamId = p[3].value.netInt; this->name.assign(p[4].value.netCharPtr); @@ -635,7 +662,7 @@ namespace GameLogic this->protocol[14].type = Oyster::Network::NetAttributeType_Float; this->protocol[15].type = Oyster::Network::NetAttributeType_Float; - this->object_ID = ObjectID; + this->objectID = ObjectID; this->teamId = teamID; this->owner = owner; this->name = name; @@ -647,7 +674,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = this->owner; - this->protocol[2].value = this->object_ID; + this->protocol[2].value = this->objectID; this->protocol[3].value = this->teamId; this->protocol.Set(4, this->name); @@ -674,7 +701,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectJoinTeam 361 + //#define protocol_Gameplay_ObjectJoinTeam 362 struct Protocol_ObjectJoinTeam :public Oyster::Network::CustomProtocolObject { int objectID; @@ -714,7 +741,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectLeaveTeam 362 + //#define protocol_Gameplay_ObjectLeaveTeam 363 struct Protocol_ObjectLeaveTeam :public Oyster::Network::CustomProtocolObject { int objectID; @@ -746,7 +773,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectWeaponCooldown 363 + //#define protocol_Gameplay_ObjectWeaponCooldown 364 struct Protocol_ObjectWeaponCooldown :public Oyster::Network::CustomProtocolObject { float seconds; @@ -778,7 +805,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectWeaponEnergy 364 + //#define protocol_Gameplay_ObjectWeaponEnergy 365 struct Protocol_ObjectWeaponEnergy :public Oyster::Network::CustomProtocolObject { float energy; @@ -810,42 +837,51 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectRespawn 365 + //#define protocol_Gameplay_ObjectRespawn 366 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; } @@ -853,10 +889,11 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectDie 366 + //#define protocol_Gameplay_ObjectDie 367 struct Protocol_ObjectDie :public Oyster::Network::CustomProtocolObject { int objectID; + int killerID; float seconds; Protocol_ObjectDie() @@ -864,28 +901,34 @@ namespace GameLogic this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectDie; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->objectID = 0; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + this->protocol[3].type = Oyster::Network::NetAttributeType_Float; + this->objectID = -1; + this->killerID = -1; this->seconds = 0.0f; } - Protocol_ObjectDie(int objectID, float seconds) + Protocol_ObjectDie(int objectID, int killerID, float seconds) { this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectDie; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->objectID = objectID; + this->killerID = killerID; this->seconds = seconds; } Protocol_ObjectDie(Oyster::Network::CustomNetProtocol& p) { - this->objectID = p[1].value.netInt; - this->seconds = p[2].value.netFloat; + this->objectID = p[1].value.netInt; + this->killerID = p[2].value.netInt; + this->seconds = p[3].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = this->objectID; - this->protocol[2].value = this->seconds; + this->protocol[2].value = this->killerID; + this->protocol[3].value = this->seconds; return protocol; } @@ -893,7 +936,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectDisconnectPlayer 367 + //#define protocol_Gameplay_ObjectDisconnectPlayer 368 struct Protocol_ObjectDisconnectPlayer :public Oyster::Network::CustomProtocolObject { int objectID; @@ -926,5 +969,45 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; } +//#define protocol_Gameplay_ObjectAction 369 + struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject + { + short objectID; + int animationID; + + Protocol_ObjectAction() + { + this->protocol[0].value = protocol_Gameplay_ObjectAction; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + objectID = -1; + animationID = -1; + } + Protocol_ObjectAction(Oyster::Network::CustomNetProtocol& p) + { + objectID = p[1].value.netShort; + animationID = p[2].value.netInt; + } + Protocol_ObjectAction( int id, int animID) + { + this->protocol[0].value = protocol_Gameplay_ObjectAction; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + objectID = id; + animationID = animID; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = objectID; + this->protocol[2].value = animationID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index e1a23850..02b1084a 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -63,14 +63,16 @@ #define protocol_Gameplay_ObjectEnabled 357 #define protocol_Gameplay_ObjectDisabled 358 #define protocol_Gameplay_ObjectCreate 359 -#define protocol_Gameplay_ObjectCreatePlayer 360 -#define protocol_Gameplay_ObjectJoinTeam 361 -#define protocol_Gameplay_ObjectLeaveTeam 362 -#define protocol_Gameplay_ObjectWeaponCooldown 363 -#define protocol_Gameplay_ObjectWeaponEnergy 364 -#define protocol_Gameplay_ObjectRespawn 365 -#define protocol_Gameplay_ObjectDie 366 -#define protocol_Gameplay_ObjectDisconnectPlayer 367 +#define protocol_Gameplay_ObjectDelete 360 +#define protocol_Gameplay_ObjectCreatePlayer 361 +#define protocol_Gameplay_ObjectJoinTeam 362 +#define protocol_Gameplay_ObjectLeaveTeam 363 +#define protocol_Gameplay_ObjectWeaponCooldown 364 +#define protocol_Gameplay_ObjectWeaponEnergy 365 +#define protocol_Gameplay_ObjectRespawn 366 +#define protocol_Gameplay_ObjectDie 367 +#define protocol_Gameplay_ObjectDisconnectPlayer 368 +#define protocol_Gameplay_ObjectAction 369 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index ad9440e9..79b50395 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -96,10 +96,15 @@ namespace DanBias void General_Status ( GameLogic::Protocol_General_Status& p, DanBias::GameClient* c ); void General_Text ( GameLogic::Protocol_General_Text& p, DanBias::GameClient* c ); - //Callback method recieving from gamelogic + //Callback method receiving from game logic static void ObjectMove ( GameLogic::IObjectData* movedObject ); - static void ObjectDisabled ( GameLogic::IObjectData* movedObject, float seconds ); - + static void ObjectDisabled ( GameLogic::IObjectData* movedObject ); + static void ObjectEnabled ( GameLogic::IObjectData* movedObject ); + static void ObjectDamaged ( GameLogic::IObjectData* movedObject, float hp ); + static void ObjectRespawned ( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos ); + static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ); + static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); + static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; 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 4782dcf4..fd000a0c 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,17 +143,39 @@ using namespace DanBias; Oyster::Math::Float3 temp = movedObject->GetPosition(); - if(temp.x < -300) - id = 0; - GameSession::gameSession->Send(p.GetProtocol()); //} } - void GameSession::ObjectDisabled( GameLogic::IObjectData* movedObject, float seconds ) + void GameSession::ObjectDisabled( GameLogic::IObjectData* movedObject ) { - GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID(), seconds).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + } + void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) + { + GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + } + void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) + { + GameSession::gameSession->Send(Protocol_ObjectDamage(movedObject->GetID(), hp).GetProtocol()); + } + void GameSession::ObjectRespawned( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos ) + { + GameSession::gameSession->Send(Protocol_ObjectRespawn(movedObject->GetID(), spawnPos).GetProtocol()); + } + void GameSession::ObjectDead( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ) + { + GameSession::gameSession->Send(Protocol_ObjectDie(victim->GetID(), killer->GetID(), seconds).GetProtocol()); + } + void GameSession::PickupEvent( GameLogic::IObjectData* movedObject, int pickupEffectID ) + { + // send pickup protocol + GameSession::gameSession->Send(Protocol_ObjectPickup(movedObject->GetID(), pickupEffectID).GetProtocol()); + } + void GameSession::ActionEvent( GameLogic::IObjectData* movedObject , int actionID ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); } - //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// @@ -187,7 +202,6 @@ using namespace DanBias; break; case protocol_Gameplay_PlayerShot: this->Gameplay_PlayerShot ( Protocol_PlayerShot (p), c ); break; - case protocol_Gameplay_ObjectPickup: this->Gameplay_ObjectPickup ( Protocol_ObjectPickup (p), c ); break; case protocol_Gameplay_ObjectDamage: this->Gameplay_ObjectDamage ( Protocol_ObjectDamage (p), c ); @@ -200,7 +214,6 @@ using namespace DanBias; break; case protocol_Gameplay_ObjectCreate: this->Gameplay_ObjectCreate ( Protocol_ObjectCreate (p), c ); break; - case protocol_General_Status: this->General_Status ( Protocol_General_Status (p), c ); break; case protocol_General_Text: this->General_Text ( Protocol_General_Text (p), c ); @@ -231,7 +244,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 ) { @@ -241,11 +254,8 @@ using namespace DanBias; { if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); - if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS); } - - void GameSession::Gameplay_ObjectPickup ( Protocol_ObjectPickup& p, DanBias::GameClient* c ) { @@ -275,17 +285,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/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 11e80a9f..ca869fb7 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -106,8 +106,14 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) } /* Set some game instance data options */ - this->gameInstance.SetSubscription(GameSession::ObjectMove); - this->gameInstance.SetSubscription(GameSession::ObjectDisabled); + this->gameInstance.SetMoveSubscription(GameSession::ObjectMove); + this->gameInstance.SetDisableSubscription(GameSession::ObjectDisabled); + this->gameInstance.SetEnableSubscription(GameSession::ObjectEnabled); + this->gameInstance.SetHpSubscription(GameSession::ObjectDamaged); + this->gameInstance.SetRespawnSubscription(GameSession::ObjectRespawned); + this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); + this->gameInstance.SetActionSubscription(GameSession::ActionEvent); + this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); this->gameInstance.SetFPS(60); this->description.clients.Clear(); diff --git a/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp b/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp index 62332541..3357f52c 100644 --- a/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp +++ b/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp @@ -32,7 +32,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh GameServerAPI::GameSetGameMode(L"free-for-all"); GameServerAPI::GameSetGameName(L"DebugServer"); GameServerAPI::GameSetGameTime(15); - GameServerAPI::GameSetMapName(L"2ofAll.bias"); + GameServerAPI::GameSetMapName(L"erik_250.bias"); GameServerAPI::GameSetMaxClients(10); if(GameServerAPI::GameStart(true)) diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index fe349988..680b0358 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -156,6 +156,21 @@ std::vector> LevelParser::Parse(std::string filen objects.push_back(header); break; } + + case ObjectSpecialType_PickupHealth: + { + PickupHealthAttributes* header = new PickupHealthAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], &header->spawnTime, 4); + counter += 4; + + ParseObject(&buffer[counter], &header->healthValue, 4); + counter += 4; + + objects.push_back(header); + break; + } //this is a hotfix, fix so you only load the relevant data when the file is updated default: //Couldn't find specialType diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 52f0e088..3eae71a5 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -42,6 +42,7 @@ namespace GameLogic ObjectSpecialType_Player, ObjectSpecialType_Generic, + ObjectSpecialType_PickupHealth, ObjectSpecialType_Count, ObjectSpecialType_Unknown = -1 @@ -92,6 +93,23 @@ namespace GameLogic WorldSize_Unknown = -1 }; + enum PlayerAction + { + PlayerAction_Jump, + PlayerAction_Walk, + PlayerAction_Idle, + }; + enum WeaponAction + { + WeaponAtcion_PrimaryShoot, + WeaponAction_SecondaryShoot + }; + + enum PickupType + { + PickupType_Health, + PickupType_SpeedBoost + }; /************************************ Structs @@ -246,7 +264,11 @@ namespace GameLogic float skySize; }; - + struct PickupHealthAttributes : public ObjectHeader + { + float spawnTime; + float healthValue; + }; diff --git a/Code/Game/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp index ac361c46..060180a2 100644 --- a/Code/Game/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -23,9 +23,9 @@ namespace GameLogic void ParseLight(char* buffer, BasicLight& header, int& size) { int start = 0; - memcpy(&header.typeID, &buffer[start], 40); - start += 40; - /* + memcpy(&header.typeID, &buffer[start], 4); + start += 4; + memcpy(&header.lightType, &buffer[start], 4); start += 4; @@ -39,7 +39,7 @@ namespace GameLogic start += 4; memcpy(&header.intensity, &buffer[start], 4); - start += 4;*/ + start += 4; size += start; diff --git a/Code/Misc/OysterMath/LinearMath.h b/Code/Misc/OysterMath/LinearMath.h index 25b65331..5b87d83d 100644 --- a/Code/Misc/OysterMath/LinearMath.h +++ b/Code/Misc/OysterMath/LinearMath.h @@ -376,9 +376,13 @@ namespace LinearAlgebra3D template inline ::LinearAlgebra::Vector3 AngularAxis( const ::LinearAlgebra::Quaternion &rotation ) { // see http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm - ScalarType angle = ScalarType(2) * (ScalarType)::std::acos( rotation.real ), - multiplier = angle / (ScalarType)::std::sqrt( ScalarType(1) - rotation.real * rotation.real ); - return multiplier * rotation.imaginary; + if( rotation.real < ScalarType(1) ) + { + ScalarType angle = ScalarType(2) * ScalarType( ::std::acos(rotation.real) ), + multiplier = angle / ScalarType( ::std::sqrt(ScalarType(1) - rotation.real * rotation.real) ); + return multiplier * rotation.imaginary; + } + else return ::LinearAlgebra::Vector3::null; } // All Matrix to AngularAxis conversions here is incorrect @@ -838,7 +842,7 @@ namespace LinearAlgebra3D template ::LinearAlgebra::Vector3 & SnapAngularAxis( const ::LinearAlgebra::Vector3 &startAngularAxis, const ::LinearAlgebra::Vector3 &localStartNormal, const ::LinearAlgebra::Vector3 &worldEndNormal, ::LinearAlgebra::Vector3 &targetMem = ::LinearAlgebra::Vector3() ) - { + { //! @todo TODO: This code is broken and do not work! ::LinearAlgebra::Vector3 worldStartNormal( WorldAxisOf(Rotation(startAngularAxis), localStartNormal) ); targetMem = worldStartNormal.Cross( worldEndNormal ); targetMem *= (ScalarType)::std::acos( ::Utility::Value::Clamp(worldStartNormal.Dot(worldEndNormal), (ScalarType)0, (ScalarType)1) ); 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..77aecdc8 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -90,6 +90,14 @@ namespace Oyster Math::Float3 GlowTint; Math::Float PAD2; }; + + struct RenderInstanceData + { + Math::Matrix WV; + Math::Matrix WVP; + Math::Float3 Tint; + Math::Float3 GTint; + }; } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 8f01bea4..ee3d9f8a 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; @@ -57,9 +58,11 @@ namespace Oyster debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); cube = CreateModel(L"generic_cube.dan"); - cube->Tint = Math::Float3(0.0f,0.0f,1.0f); + cube->Tint = Math::Float3(1.0f,0.0f,0.0f); + cube->Instanced = false; sphere = CreateModel(L"generic_sphere.dan"); sphere->Tint = Math::Float3(1.0f,0.5f,182/255.0f); + sphere->Instanced = false; D3D11_RASTERIZER_DESC desc; @@ -133,6 +136,35 @@ namespace Oyster return API::Sucsess; } + void API::BeginLoadingModels() + { + } + + void API::EndLoadingModels() + { + //TODO finalize instance buffers and create rendering map; + int maxModels = 0; + for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) + { + if((*i).second->Models > maxModels) + { + maxModels = (*i).second->Models; + } + (*i).second->rid = new Definitions::RenderInstanceData[(*i).second->Models+1]; + } + + Core::Buffer::BUFFER_INIT_DESC desc; + + + desc.ElementSize = sizeof(Definitions::RenderInstanceData); + desc.Type = Core::Buffer::VERTEX_BUFFER; + desc.Usage = Core::Buffer::BUFFER_CPU_WRITE_DISCARD; + desc.InitData = 0; + desc.NumElements = maxModels+1; + + Render::Resources::Gather::InstancedData.Init(desc); + } + //returns null for invalid filenames Model::Model* API::CreateModel(std::wstring filename) { @@ -142,6 +174,7 @@ namespace Oyster m->Animation.AnimationPlaying = NULL; m->Tint = Math::Float3(1); m->GlowTint = Math::Float3(1); + m->Instanced = true; m->info = (Model::ModelInfo*)Core::loader.LoadResource((Core::modelPath + filename).c_str(),Oyster::Graphics::Loading::LoadDAN, Oyster::Graphics::Loading::UnloadDAN); Model::ModelInfo* mi = (Model::ModelInfo*)m->info; @@ -152,6 +185,18 @@ namespace Oyster delete mi; return NULL; } + + if(!m->info->Animated) + { + 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; } @@ -187,6 +232,12 @@ namespace Oyster SAFE_RELEASE(Core::deviceContext); SAFE_RELEASE(Core::device); + for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) + { + SAFE_DELETE((*i).second->rid); + SAFE_DELETE((*i).second); + } + } void API::AddLight(Definitions::Pointlight light) @@ -208,9 +259,9 @@ namespace Oyster void API::StartRenderWireFrame() { - Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); + //Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::AnimatedPass.RTV.size(),&Render::Resources::Gather::AnimatedPass.RTV[0],NULL); Core::deviceContext->RSSetState(wire); - Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); + //Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::AnimatedPass.RTV.size(),&Render::Resources::Gather::AnimatedPass.RTV[0],NULL); } void API::RenderDebugCube(Math::Matrix world) 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/Model/Model.h b/Code/OysterGraphics/Model/Model.h index 5985dbcd..6d4e96f2 100644 --- a/Code/OysterGraphics/Model/Model.h +++ b/Code/OysterGraphics/Model/Model.h @@ -26,6 +26,7 @@ namespace Oyster Oyster::Math::Float3 Tint; Oyster::Math::Float3 GlowTint; bool Visible; + bool Instanced; AnimationData Animation; }; } diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj b/Code/OysterGraphics/OysterGraphics.vcxproj index 8faf4d0f..f4a3d130 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj +++ b/Code/OysterGraphics/OysterGraphics.vcxproj @@ -239,13 +239,25 @@ Vertex Vertex + + Pixel + Pixel + Pixel + Pixel + + + Vertex + Vertex + Vertex + Vertex + Compute Compute Compute Compute - + Pixel Pixel Pixel @@ -281,7 +293,7 @@ Compute 5.0 - + Vertex Vertex Vertex @@ -328,8 +340,9 @@ + - + diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.filters b/Code/OysterGraphics/OysterGraphics.vcxproj.filters index d76a066f..83731090 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.filters +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.filters @@ -100,8 +100,6 @@ - - @@ -109,6 +107,10 @@ + + + + @@ -117,8 +119,9 @@ - + + \ No newline at end of file diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 7d0d987b..4b979be8 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -19,7 +19,6 @@ namespace Oyster Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0)); Preparations::Basic::ClearDepthStencil(Resources::Gui::depth); Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0)); - Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass); Lights[1]; void* data; @@ -39,15 +38,39 @@ namespace Oyster data = Resources::Light::PointLightsData.Map(); memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); Resources::Light::PointLightsData.Unmap(); + + for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) + { + (*i).second->Models=0; + } + + Core::PipelineManager::SetRenderPass(Resources::Gather::AnimatedPass); } void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime) { for(int i = 0; i < count; ++i) { - if(&models[i] == NULL) + if(&models[i] == NULL || !models[i].Visible) continue; - if(models[i].Visible) + + Model::ModelInfo* info = models[i].info; + if(!info->Animated && models[i].Instanced) + { + Definitions::RenderInstanceData rid; + Math::Float3x3 normalTransform; + normalTransform = Math::Float3x3(models[i].WorldMatrix.v[0].xyz, models[i].WorldMatrix.v[1].xyz, models[i].WorldMatrix.v[2].xyz); + normalTransform.Transpose().Invert(); + Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f)); + rid.WV = View * m; + rid.WVP = Projection * View * models[i].WorldMatrix; + + rid.Tint = models[i].Tint; + rid.GTint = models[i].GlowTint; + + Resources::RenderData[info]->rid[Resources::RenderData[info]->Models++] = rid; + } + else { Definitions::PerModel pm; Math::Float3x3 normalTransform; @@ -55,7 +78,6 @@ namespace Oyster normalTransform.Transpose().Invert(); Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f)); pm.WV = View * m; - //pm.WV = models[i].WorldMatrix.GetTranspose().GetInverse(); pm.WVP = Projection * View * models[i].WorldMatrix; Model::ModelInfo* info = models[i].info; @@ -207,9 +229,47 @@ namespace Oyster Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); } + void RenderModel(Model::ModelInfo* info, Definitions::RenderInstanceData* rid , int count) + { + if(count < 1) + return; + if(info->Material.size()) + { + Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); + } + info->Vertices->Apply(); + if(info->Indexed) + { + info->Indecies->Apply(); + } + + void* data = Resources::Gather::InstancedData.Map(); + memcpy(data, rid, sizeof(Definitions::RenderInstanceData)*count); + Resources::Gather::InstancedData.Unmap(); + + if(info->Indexed) + { + Core::deviceContext->DrawIndexedInstanced(info->IndexCount,count,0,0,0); + //Core::deviceContext->DrawIndexed(info->IndexCount,0,0); + } + else + { + Core::deviceContext->DrawInstanced(info->VertexCount,count,0,0); + //Core::deviceContext->Draw(info->VertexCount,0); + } + } + void DefaultRenderer::EndFrame() { + Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::InstancedPass); + Resources::Gather::InstancedData.Apply(1); + + for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) + { + RenderModel((*i).first,(*i).second->rid, (*i).second->Models); + } + Core::PipelineManager::SetRenderPass(Resources::Light::Pass); Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 2e693472..cced13e9 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -33,7 +33,8 @@ namespace Oyster ID3D11UnorderedAccessView* Resources::Blur::BufferUAV = {0}; ID3D11ShaderResourceView* Resources::Blur::BufferSRV = {0}; - Shader::RenderPass Resources::Gather::Pass; + Shader::RenderPass Resources::Gather::AnimatedPass; + Shader::RenderPass Resources::Gather::InstancedPass; Shader::RenderPass Resources::Light::Pass; Shader::RenderPass Resources::Post::Pass; Shader::RenderPass Resources::Gui::Pass; @@ -43,6 +44,7 @@ namespace Oyster Buffer Resources::Gather::ModelData = Buffer(); Buffer Resources::Gather::AnimationData = Buffer(); + Buffer Resources::Gather::InstancedData = Buffer(); Buffer Resources::Light::LightConstantsData = Buffer(); Buffer Resources::Gui::Data = Buffer(); Buffer Resources::Color = Buffer(); @@ -63,6 +65,8 @@ namespace Oyster ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL; ID3D11DepthStencilView* Resources::Gui::depth = NULL; + + std::map Resources::RenderData = std::map(); #pragma endregion @@ -76,8 +80,12 @@ namespace Oyster std::wstring end = L".cso"; #endif //Load Shaders - Core::PipelineManager::Init(path + L"GatherPixel" + end, ShaderType::Pixel, L"Gather"); - Core::PipelineManager::Init(path + L"GatherVertex" + end, ShaderType::Vertex, L"Gather"); + Core::PipelineManager::Init(path + L"GatherAnimPixel" + end, ShaderType::Pixel, L"AGather"); + Core::PipelineManager::Init(path + L"GatherAnimVertex" + end, ShaderType::Vertex, L"AGather"); + + + Core::PipelineManager::Init(path + L"GatherInstPixel" + end, ShaderType::Pixel, L"IGather"); + Core::PipelineManager::Init(path + L"GatherInstVertex" + end, ShaderType::Vertex, L"IGather"); #ifdef _DEBUG path = PathToHLSL+L"Light\\"; #endif @@ -151,6 +159,7 @@ namespace Oyster desc.NumElements = MAX_LETTER_COUNT; Gui::Text::Vertex.Init(desc); + return Core::Init::Success; } @@ -356,10 +365,11 @@ namespace Oyster { ////---------------- Geometry Pass Setup ---------------------------- - Gather::Pass.Shaders.Pixel = GetShader::Pixel(L"Gather"); - Gather::Pass.Shaders.Vertex = GetShader::Vertex(L"Gather"); +#pragma region Animated Pass + Gather::AnimatedPass.Shaders.Pixel = GetShader::Pixel(L"AGather"); + Gather::AnimatedPass.Shaders.Vertex = GetShader::Vertex(L"AGather"); - D3D11_INPUT_ELEMENT_DESC indesc[] = + D3D11_INPUT_ELEMENT_DESC AnimInDesc[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, @@ -368,20 +378,163 @@ namespace Oyster { "BONEWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0 } }; - Shader::CreateInputLayout(indesc,5,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout); - Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; - Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData); - Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData); - Gather::Pass.CBuffers.Pixel.push_back(Color); - Gather::Pass.RenderStates.Rasterizer = RenderStates::rs; - Gather::Pass.RenderStates.SampleCount = 1; - Gather::Pass.RenderStates.SampleState = RenderStates::ss; - Gather::Pass.RenderStates.DepthStencil = RenderStates::dsState; + Shader::CreateInputLayout(AnimInDesc,5,GetShader::Vertex(L"AGather"),Gather::AnimatedPass.IAStage.Layout); + Gather::AnimatedPass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; + Gather::AnimatedPass.CBuffers.Vertex.push_back(Gather::AnimationData); + Gather::AnimatedPass.CBuffers.Vertex.push_back(Gather::ModelData); + Gather::AnimatedPass.CBuffers.Pixel.push_back(Color); + Gather::AnimatedPass.RenderStates.Rasterizer = RenderStates::rs; + Gather::AnimatedPass.RenderStates.SampleCount = 1; + Gather::AnimatedPass.RenderStates.SampleState = RenderStates::ss; + Gather::AnimatedPass.RenderStates.DepthStencil = RenderStates::dsState; for(int i = 0; i RenderData; static const int GBufferSize = 3; static const int LBufferSize = 3; @@ -44,9 +54,11 @@ namespace Oyster struct Gather { - static Core::PipelineManager::RenderPass Pass; + static Core::PipelineManager::RenderPass AnimatedPass; + static Core::PipelineManager::RenderPass InstancedPass; static Core::Buffer ModelData; static Core::Buffer AnimationData; + static Core::Buffer InstancedData; }; struct Light diff --git a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/AnimHeader.hlsli similarity index 97% rename from Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli rename to Code/OysterGraphics/Shader/Passes/Gather/AnimHeader.hlsli index 75a297bb..6f69bfca 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Gather/AnimHeader.hlsli @@ -1,4 +1,4 @@ -struct VertexIn +struct AnimVertexIn { float3 pos : POSITION; float2 UV : TEXCOORD; diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherAnimPixel.hlsl similarity index 95% rename from Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl rename to Code/OysterGraphics/Shader/Passes/Gather/GatherAnimPixel.hlsl index 11447238..dede36c2 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherAnimPixel.hlsl @@ -1,4 +1,4 @@ -#include "Header.hlsli" +#include "AnimHeader.hlsli" @@ -42,7 +42,7 @@ PixelOut main(VertexOut input) PixelOut output; float4 DiffGlow = Diffuse.Sample(S1, input.UV); float3 tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; - tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; + //tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; output.DiffuseGlow = DiffGlow * float4(tint,1); //NORMALIZE diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherAnimVertex.hlsl similarity index 90% rename from Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl rename to Code/OysterGraphics/Shader/Passes/Gather/GatherAnimVertex.hlsl index 79c21eec..7e7a803f 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherAnimVertex.hlsl @@ -1,6 +1,6 @@ -#include "Header.hlsli" +#include "AnimHeader.hlsli" -VertexOut main( VertexIn input ) +VertexOut main( AnimVertexIn input ) { VertexOut output; diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherInstPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherInstPixel.hlsl new file mode 100644 index 00000000..72fce8c5 --- /dev/null +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherInstPixel.hlsl @@ -0,0 +1,63 @@ +#include "InstHeader.hlsli" + + + +float3x3 cotangent_frame( float3 N, float3 p, float2 uv ) +{ + // get edge vectors of the pixel triangle + float3 dp1 = ddx( p ); + float3 dp2 = ddy( p ); + float2 duv1 = ddx( uv ); + float2 duv2 = ddy( uv ); + + // solve the linear system + float3 dp2perp = cross( dp2, N ); + float3 dp1perp = cross( N, dp1 ); + float3 T = dp2perp * duv1.x + dp1perp * duv2.x; + float3 B = dp2perp * duv1.y + dp1perp * duv2.y; + + // construct a scale-invariant frame + float invmax = rsqrt( max( dot(T,T), dot(B,B) ) ); + return transpose(float3x3( T * invmax, B * invmax, N )); +} + +float3 perturb_normal( float3 N, float3 V, float2 texcoord ) +{ + // assume N, the interpolated vertex normal and + // V, the view vector (vertex to eye) + float3 map = Normal.Sample(S1,texcoord).xyz; + map = map * 255./127. - 128./127.; +#ifdef WITH_NORMALMAP_2CHANNEL + map.z = sqrt( 1. - dot( map.xy, map.xy ) ); +#endif +#ifdef WITH_NORMALMAP_GREEN_UP + map.y = -map.y; +#endif + float3x3 TBN = cotangent_frame( N, -V, texcoord ); + return normalize( mul(transpose(TBN), map) ); +} + +PixelOut main(VertexOut input) +{ + PixelOut output; + float4 DiffGlow = Diffuse.Sample(S1, input.UV); + float3 tint = input.tint * (1-DiffGlow.w) + input.gtint * DiffGlow.w; + //tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; + output.DiffuseGlow = DiffGlow * float4(tint,1); + + //NORMALIZE + float3x3 CoTangentFrame = cotangent_frame(input.normal, normalize(input.ViewPos), input.UV); + + float3 map = Normal.Sample(S1,input.UV).xyz; + //map = normalize((map * 2) -1); + map = map * 255./127. - 128./127.; + //map = map * 255; + float3 normal = normalize(mul(CoTangentFrame, map)); + //normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); + + output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255); + + //output.NormalSpec = float4(input.normal, Normal.Sample(S1, input.UV).w * 0); + //output.NormalSpec = float4(map,0); + return output; +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherInstVertex.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherInstVertex.hlsl new file mode 100644 index 00000000..525ff982 --- /dev/null +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherInstVertex.hlsl @@ -0,0 +1,18 @@ +#include "InstHeader.hlsli" + +VertexOut main( InstVertexIn input ) +{ + VertexOut output; + + matrix WV = transpose(matrix(input.wv1, input.wv2, input.wv3, input.wv4)); + matrix WVP = transpose(matrix(input.wvp1, input.wvp2, input.wvp3, input.wvp4)); + + output.pos = mul(WVP, float4(input.pos,1)); + output.ViewPos = mul(WV, float4(input.pos,1)); + output.normal = mul(WV, float4(input.normal,0)).xyz; + output.UV = input.UV; + output.tint = input.Tint; + output.gtint = input.GlowTint; + + return output; +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Gather/InstHeader.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/InstHeader.hlsli new file mode 100644 index 00000000..497374b4 --- /dev/null +++ b/Code/OysterGraphics/Shader/Passes/Gather/InstHeader.hlsli @@ -0,0 +1,44 @@ +struct InstVertexIn +{ + float3 pos : POSITION; + float2 UV : TEXCOORD; + float3 normal : NORMAL; + float4 boneIndex : BONEINDEX; + float4 boneWeight : BONEWEIGHT; + //instance Data + //WV MATRIX + float4 wv1 : WV0; + float4 wv2 : WV1; + float4 wv3 : WV2; + float4 wv4 : WV3; + + //WVP MATRIX + float4 wvp1 : WVP0; + float4 wvp2 : WVP1; + float4 wvp3 : WVP2; + float4 wvp4 : WVP3; + + float3 Tint : TINT; + float3 GlowTint : GTINT; +}; + +struct VertexOut +{ + float4 pos : SV_POSITION; + float4 ViewPos : POSITION; + float2 UV : TEXCOORD; + float3 normal : NORMAL; + float3 tint : TINT; + float3 gtint : GTINT; +}; + +struct PixelOut +{ + float4 DiffuseGlow : SV_TARGET0; + float4 NormalSpec : SV_TARGET1; +}; + +Texture2D Diffuse : register(t0); +Texture2D Normal : register(t1); + +SamplerState S1 : register(s0); \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli b/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli index adf01e9d..fb125b12 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli @@ -25,6 +25,16 @@ cbuffer LightConstants : register(b0) float4x4 View; } +struct FrustrumPoints +{ + float3 v0; + float3 v1; + float3 v2; + float3 v3; + float3 v4; + float3 v5; +}; + Texture2D DiffuseGlow : register(t0); Texture2D NormalSpec : register(t1); Texture2D GUI : register(t2); diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli index 3dc2b45e..81fa2fa1 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli @@ -27,4 +27,9 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) float SpecCo = normalSpec.w < 1 ? 0.0f : 1.0f; output.Specular = output.Specular * SpecCo; return output; +} + +bool intersects(FrustrumPoints box, int Index) +{ + return true; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl index 89ed06d3..ddaed99e 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl @@ -8,13 +8,85 @@ //Calc Ambience Done //Write Glow +#define EXPAND 1024.0f +#define SHRINK 1.0f/EXPAND +#define UINT_MAX 0xFFFFFFFF +#define FLOAT_MAX 3.402823466e+38 +#define BLOCKSIZE 16 +#define NUMTHREADS BLOCKSIZE * BLOCKSIZE +#define MAXLIGHTS 100 -[numthreads(16, 16, 1)] -void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) + +// -- Shared Memory ------------------------------------------------- // + +groupshared uint iMinDepth = UINT_MAX, + iMaxDepth = 0; +groupshared uint numVisiblePointLights = 0, + visiblePointlightIndex[MAXLIGHTS]; + +// ------------------------------------------------------------------ // + +[numthreads(BLOCKSIZE, BLOCKSIZE, 1)] +void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex ) { float2 UV = DTid.xy / Pixels; UV.x = UV.x * 2 - 1; UV.y = 1 - 2 * UV.y; + + float3 posN = float3(UV, DepthTexture[DTid.xy].x); + + // store and load shared minDepth and maxDepth + float minDepth = 0.0f, maxDepth = 0.0f, + depth = posN.z; + { + uint uidepth = (uint)( depth * EXPAND); + InterlockedMin( iMinDepth, uidepth ); + InterlockedMax( iMaxDepth, uidepth ); + + GroupMemoryBarrierWithGroupSync(); + minDepth = (float)( iMinDepth ) * SHRINK; + maxDepth = (float)( iMaxDepth ) * SHRINK; + } + + + // -- Switching to LightCulling ------------------------------------- // + + //define collision volume + float2 size = BLOCKSIZE / Pixels; + FrustrumPoints tile; + tile.v0 = float3(size * Gid,minDepth); + tile.v1 = float3(tile.v0.xy+size,maxDepth); + tile.v2 = float3(tile.v1.xy, minDepth); + tile.v3 = float3(tile.v0.x,tile.v1.y,minDepth); + tile.v4 = float3(tile.v1.x, tile.v0.y, minDepth); + tile.v5 = float3(tile.v0.xy, maxDepth); + + + + // culling the tile's near and far to minDepth & maxDepth ( with tolerance ) + + + uint numPass = (Lights + NUMTHREADS - 1) / NUMTHREADS; + numPass = min( numPass, MAXLIGHTS / NUMTHREADS ); + + for( uint passI = 0; passI < numPass; ++passI ) + { + uint lightIndex = (passI * NUMTHREADS) + GI; + lightIndex = min( lightIndex, Lights ); + + if( lightIndex < Lights ) + if( intersects(tile, lightIndex) ) + { + uint offset; + InterlockedAdd( numVisiblePointLights, 1, offset ); + visiblePointlightIndex[offset] = lightIndex; + } + } + + GroupMemoryBarrierWithGroupSync(); + + + float3 ViewPos = ToVpos(DTid.xy, UV); DiffSpec Shaded; Shaded.Diffuse = float3(0,0,0); @@ -47,7 +119,7 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) DepthBase = DepthBase /4; Ambient[DTid.xy/2] = float4(DiffBase.xyz, AmbValue); Ambient[DTid.xy/2 + float2(Pixels.x/2, 0)] = GUI[DTid.xy]; - Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffBase.xyz * DiffBase.w /* * (2-DepthBase) */,DiffBase.w); + Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffBase.xyz * DiffBase.w ,DiffBase.w); Ambient[DTid.xy/2 + Pixels/2] = float4(NormalSpec[DTid.xy].xyz * float3(1,1,-1),1); }