Major updates to Collision handling with the class CollitionManager. changes started on the massdriver

This commit is contained in:
Erik Persson 2014-01-21 15:46:54 +01:00
parent 8792aab992
commit ebaa668382
11 changed files with 117 additions and 128 deletions

View File

@ -3,52 +3,38 @@
using namespace GameLogic; using namespace GameLogic;
struct AttatchmentMassDriver::PrivateData
{
PrivateData()
{
}
~PrivateData()
{
}
}myData;
AttatchmentMassDriver::AttatchmentMassDriver(void) AttatchmentMassDriver::AttatchmentMassDriver(void)
{ {
myData = new PrivateData();
this->owner = 0; this->owner = 0;
} }
AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) AttatchmentMassDriver::AttatchmentMassDriver(Player &owner)
{ {
myData = new PrivateData();
this->owner = &owner; this->owner = &owner;
} }
AttatchmentMassDriver::~AttatchmentMassDriver(void) AttatchmentMassDriver::~AttatchmentMassDriver(void)
{ {
delete myData;
} }
/******************************************************** /********************************************************
* Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used * Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used
********************************************************/ ********************************************************/
void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage) void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float dt)
{ {
//switch case to determin what functionallity to use in the attatchment //switch case to determin what functionallity to use in the attatchment
switch (usage) switch (usage)
{ {
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
ForcePush(usage); ForcePush(usage,dt);
break; break;
case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS:
ForcePull(usage); ForcePull(usage,dt);
break; break;
} }
@ -57,17 +43,27 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage)
/******************************************************** /********************************************************
* Pushes objects in a cone in front of the weapon when fired * Pushes objects in a cone in front of the weapon when fired
********************************************************/ ********************************************************/
void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage) void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt)
{ {
//create coneRigidBody that will then collide with object and push them in the aimed direction Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt);
//create frustum that will then collide with object and push them in the aimed direction
//sample with frustum using visitor pattern(needs a function ptr sent with it that idicates what happens when a collision has been made)
} }
/******************************************************** /********************************************************
* Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack) * Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack)
********************************************************/ ********************************************************/
void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage) void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt)
{ {
//Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100); Oyster::Physics::Struct::CustomBodyState state = this->owner->GetRigidBody()->GetState();
//do something with state
state.ApplyLinearImpulse(Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt));
this->owner->GetRigidBody()->SetState(state);
} }

View File

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

View File

@ -1,62 +1,59 @@
#include "CollisionManager.h"
#include "PhysicsAPI.h" #include "PhysicsAPI.h"
#include "Object.h" #include "Object.h"
#include "DynamicObject.h" #include "DynamicObject.h"
#include "Player.h" #include "Player.h"
#include "Level.h"
using namespace Oyster; using namespace Oyster;
using namespace GameLogic; using namespace GameLogic;
void PlayerVBox(Player &player, DynamicObject &box); void PlayerVBox(Player &player, DynamicObject &box);
void PlayerVObject(Player &player, Object &obj);
Physics::ICustomBody::SubscriptMessage CollisionManager::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) Physics::ICustomBody::SubscriptMessage Player::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
{ {
//Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef)); Player *player = ((Player*)(rigidBodyPlayer->GetCustomTag()));
//Object *realObj = (Object*)obj->gameObjectRef; Object *realObj = (Object*)obj->GetCustomTag();
//switch (realObj->GetType()) switch (realObj->GetType())
//{ {
//case OBJECT_TYPE::OBJECT_TYPE_BOX: case OBJECT_H::OBJECT_TYPE_GENERIC:
// PlayerVBox(*player,(*(DynamicObject*) realObj)); PlayerVObject(*player,*realObj);
// break; Physics::ICustomBody::SubscriptMessage_none;
//case OBJECT_TYPE::OBJECT_TYPE_PLAYER: break;
//
// break; case OBJECT_TYPE::OBJECT_TYPE_BOX:
//} PlayerVBox(*player,(*(DynamicObject*) realObj));
Physics::ICustomBody::SubscriptMessage_none;
break;
case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
Physics::ICustomBody::SubscriptMessage_none;
break;
}
return Physics::ICustomBody::SubscriptMessage_none; return Physics::ICustomBody::SubscriptMessage_none;
} }
void PlayerVBox(Player &player, DynamicObject &box) void PlayerVBox(Player &player, DynamicObject &box)
{ {
//use kinetic energyloss of the collision in order too determin how much damage to take
//use as part of the damage algorithm
player.DamageLife(20); player.DamageLife(20);
} }
Physics::ICustomBody::SubscriptMessage CollisionManager::BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) void PlayerVObject(Player &player, Object &obj)
{ {
if(rigidBodyBox == 0) //Collision between a player and a general static or dynamic object
{ //use kinetic energyloss of the collision in order too determin how much damage to take
return Physics::ICustomBody::SubscriptMessage::SubscriptMessage_none; //use as part of the damage algorithm
} player.DamageLife(20);
//DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef;
//Object *realObj = (Object*)obj->gameObjectRef;
//switch (realObj->GetType())
//{
//case OBJECT_TYPE::OBJECT_TYPE_BOX:
//
// break;
//case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
// //PlayerVBox(*(Player*)realObj,*box);
// break;
//}
return Physics::ICustomBody::SubscriptMessage_none;
} }
Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj)
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj)
{ {
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
} }

View File

@ -10,14 +10,7 @@ namespace GameLogic
class CollisionManager class CollisionManager
{ {
public: public:
//these are the main collision functions //put general collision functions here that are not part of a specific object
//typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj);
static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj);
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj);
//these are the specific collision case functions
//void PlayerVBox(Player &player, DynamicObject &box);
//void BoxVBox(DynamicObject &box1, DynamicObject &box2);
}; };

View File

@ -25,6 +25,7 @@ namespace GameLogic
OBJECT_TYPE_PLAYER = 0, OBJECT_TYPE_PLAYER = 0,
OBJECT_TYPE_BOX = 1, OBJECT_TYPE_BOX = 1,
OBJECT_TYPE_WORLD = 2, OBJECT_TYPE_WORLD = 2,
OBJECT_TYPE_GENERIC = 4,
OBJECT_TYPE_UNKNOWN = -1, OBJECT_TYPE_UNKNOWN = -1,
}; };

View File

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

View File

@ -51,6 +51,14 @@ namespace GameLogic
********************************************************/ ********************************************************/
void RespawnPlayer(Player *player); void RespawnPlayer(Player *player);
/********************************************************
* Collision function for level, this is to be sent to physics through the subscribe function with the rigidbody
* Will be called when the physics detect a collision
* @param rigidBodyLevel: physics object of the level
* @param obj: physics object for the object that collided with the level
********************************************************/
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj);
private: private:
TeamManager teamManager; TeamManager teamManager;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects; Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;

View File

@ -8,7 +8,7 @@ using namespace GameLogic;
using namespace Oyster::Physics; using namespace Oyster::Physics;
Player::Player() Player::Player()
:DynamicObject(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) :DynamicObject(Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
{ {
weapon = new Weapon(); weapon = new Weapon();
@ -81,7 +81,7 @@ void Player::MoveLeft()
void Player::UseWeapon(const WEAPON_FIRE &usage) void Player::UseWeapon(const WEAPON_FIRE &usage)
{ {
this->weapon->Use(usage); this->weapon->Use(usage,gameInstance->GetFrameTime());
} }
void Player::Respawn(Oyster::Math::Float3 spawnPoint) void Player::Respawn(Oyster::Math::Float3 spawnPoint)

View File

@ -41,7 +41,18 @@ namespace GameLogic
********************************************************/ ********************************************************/
void Respawn(Oyster::Math::Float3 spawnPoint); void Respawn(Oyster::Math::Float3 spawnPoint);
<<<<<<< HEAD
void Rotate(float x, float y); void Rotate(float x, float y);
=======
/********************************************************
* Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody
* Will be called when the physics detect a collision
* @param rigidBodyPlayer: physics object of the player
* @param obj: physics object for the object that collided with the player
********************************************************/
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj);
>>>>>>> Major updates to Collision handling with the class CollitionManager. changes started on the massdriver
bool IsWalking(); bool IsWalking();
bool IsJumping(); bool IsJumping();
@ -65,6 +76,9 @@ namespace GameLogic
PLAYER_STATE playerState; PLAYER_STATE playerState;
Oyster::Math::Float4 lookDir; Oyster::Math::Float4 lookDir;
bool hasTakenDamage;
float invincibleCooldown;
}; };
} }
#endif #endif

View File

@ -1,60 +1,39 @@
#include "Weapon.h" #include "Weapon.h"
#include "AttatchmentSocket.h"
#include "AttatchmentMassDriver.h" #include "AttatchmentMassDriver.h"
#include "DynamicArray.h"
using namespace GameLogic; using namespace GameLogic;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
struct Weapon::PrivateData
{
PrivateData()
{
weaponState = WEAPON_STATE_IDLE;
selectedAttatchment = 0;
currentNrOfAttatchments = 0;
selectedSocketID = 0;
attatchmentSockets = 0;
}
~PrivateData()
{
}
WEAPON_STATE weaponState;
DynamicArray<SmartPointer<AttatchmentSocket>> attatchmentSockets;
int currentNrOfAttatchments;
SmartPointer<IAttatchment> selectedAttatchment;
int selectedSocketID;
}myData;
Weapon::Weapon() Weapon::Weapon()
{ {
myData = new PrivateData(); weaponState = WEAPON_STATE_IDLE;
selectedAttatchment = 0;
currentNrOfAttatchments = 0;
selectedSocketID = 0;
attatchmentSockets = 0;
} }
Weapon::Weapon(int MaxNrOfSockets) Weapon::Weapon(int MaxNrOfSockets)
{ {
myData = new PrivateData(); attatchmentSockets.Resize(MaxNrOfSockets);
myData->attatchmentSockets.Resize(MaxNrOfSockets);
} }
Weapon::~Weapon(void) Weapon::~Weapon(void)
{ {
delete myData;
} }
/******************************************************** /********************************************************
* Uses the weapon based on the input given and the current chosen attatchment * Uses the weapon based on the input given and the current chosen attatchment
********************************************************/ ********************************************************/
void Weapon::Use(const WEAPON_FIRE &usage) void Weapon::Use(const WEAPON_FIRE &usage, float dt)
{ {
if (myData->selectedAttatchment) if (selectedAttatchment)
{ {
myData->selectedAttatchment->UseAttatchment(usage); selectedAttatchment->UseAttatchment(usage, dt);
} }
} }
@ -68,24 +47,24 @@ void Weapon::Use(const WEAPON_FIRE &usage)
********************************************************/ ********************************************************/
bool Weapon::IsFireing() bool Weapon::IsFireing()
{ {
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIRING); return (weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
} }
bool Weapon::IsIdle() bool Weapon::IsIdle()
{ {
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_IDLE); return (weaponState == WEAPON_STATE::WEAPON_STATE_IDLE);
} }
bool Weapon::IsReloading() bool Weapon::IsReloading()
{ {
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING); return (weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING);
} }
bool Weapon::IsValidSocket(int socketID) bool Weapon::IsValidSocket(int socketID)
{ {
if(socketID < (int)myData->attatchmentSockets.Size() && socketID >= 0) if(socketID < (int)attatchmentSockets.Size() && socketID >= 0)
{ {
if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0) if (attatchmentSockets[socketID]->GetAttatchment() != 0)
{ {
return true; return true;
} }
@ -96,16 +75,16 @@ bool Weapon::IsValidSocket(int socketID)
int Weapon::GetCurrentSocketID() int Weapon::GetCurrentSocketID()
{ {
return myData->selectedSocketID; return selectedSocketID;
} }
void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner) void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner)
{ {
if(myData->currentNrOfAttatchments < (int)myData->attatchmentSockets.Size()) if(currentNrOfAttatchments < (int)attatchmentSockets.Size())
{ {
myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment); attatchmentSockets[currentNrOfAttatchments]->SetAttatchment(attatchment);
myData->currentNrOfAttatchments++; currentNrOfAttatchments++;
} }
} }
@ -113,7 +92,7 @@ void Weapon::SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *
{ {
if (IsValidSocket(socketID)) if (IsValidSocket(socketID))
{ {
myData->attatchmentSockets[socketID]->SetAttatchment(attatchment); attatchmentSockets[socketID]->SetAttatchment(attatchment);
} }
} }
@ -121,7 +100,7 @@ void Weapon::RemoveAttatchment(int socketID)
{ {
if (IsValidSocket(socketID)) if (IsValidSocket(socketID))
{ {
myData->attatchmentSockets[socketID]->RemoveAttatchment(); attatchmentSockets[socketID]->RemoveAttatchment();
} }
} }
@ -129,8 +108,8 @@ void Weapon::SelectAttatchment(int socketID)
{ {
if (IsValidSocket(socketID)) if (IsValidSocket(socketID))
{ {
myData->selectedAttatchment = myData->attatchmentSockets[socketID]->GetAttatchment(); selectedAttatchment = attatchmentSockets[socketID]->GetAttatchment();
myData->selectedSocketID = socketID; selectedSocketID = socketID;
} }
} }

View File

@ -6,21 +6,20 @@
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "IAttatchment.h" #include "IAttatchment.h"
#include "Player.h" #include "Player.h"
#include "AttatchmentSocket.h"
#include "DynamicArray.h"
namespace GameLogic namespace GameLogic
{ {
class Weapon class Weapon
{ {
public: public:
Weapon(void); Weapon(void);
Weapon(int nrOfAttatchmentSockets); Weapon(int nrOfAttatchmentSockets);
~Weapon(void); ~Weapon(void);
void Use(const WEAPON_FIRE &fireInput); void Use(const WEAPON_FIRE &usage, float dt);
void AddNewAttatchment(IAttatchment *attatchment, Player *owner); void AddNewAttatchment(IAttatchment *attatchment, Player *owner);
void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner); void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner);
@ -36,8 +35,11 @@ namespace GameLogic
int GetCurrentSocketID(); int GetCurrentSocketID();
private: private:
struct PrivateData; WEAPON_STATE weaponState;
PrivateData *myData; Utility::DynamicMemory::DynamicArray<AttatchmentSocket*> attatchmentSockets;
int currentNrOfAttatchments;
IAttatchment *selectedAttatchment;
int selectedSocketID;
}; };
} }