diff --git a/Code/Dokumentation/LevelLoader.uxf b/Code/Dokumentation/LevelLoader.uxf new file mode 100644 index 00000000..723857bb --- /dev/null +++ b/Code/Dokumentation/LevelLoader.uxf @@ -0,0 +1,277 @@ + + + 8 + + com.umlet.element.Package + + 552 + 320 + 584 + 368 + + LevelLoader + + + + com.umlet.element.Class + + 440 + 88 + 128 + 40 + + GameLogic +<<Erik>> + + + + com.umlet.element.Relation + + 768 + 472 + 136 + 104 + + lt=<<<<- + 120;24;120;88;24;88 + + + com.umlet.element.Class + + 560 + 544 + 232 + 136 + + <<Interface>> +Parser +-- +Functions: +vector<struct> Parse(); +- +Privates: +enum headerType; +const int FileHeaderSize; +const int FileVersion; + + + + + com.umlet.element.Class + + 624 + 208 + 80 + 24 + + LevelLoader + + + + + com.umlet.element.Relation + + 640 + 208 + 40 + 168 + + lt=<<. + 24;24;24;152 + + + com.umlet.element.Relation + + 384 + 176 + 256 + 56 + + lt=->>>> +m1=1..1 +m2=1..1 +<Knows about + 240;40;24;40 + + + com.umlet.element.Package + + 248 + 320 + 248 + 160 + + Defines + + + + com.umlet.element.Class + + 800 + 360 + 208 + 136 + + <<Interface>> +Loader +-- +Functions: +wchar* LoadFile(string fileName); +Model* LoadModel(string modelName); +Model* LoadModel(int modelID); +- +Privates: + + + + com.umlet.element.Class + + 328 + 208 + 80 + 24 + + Defines + + + + com.umlet.element.Class + + 256 + 360 + 232 + 104 + + Defines.h +<<Header file>> +-- +Enum ObjectType(static, dynamic, specials); +. +Struct static; +Struct dynamic; +Struct specials + + + + com.umlet.element.Relation + + 680 + 176 + 152 + 56 + + lt=- +m1=1..1 +m2=1..1 +Uses> + 24;40;136;40 + + + com.umlet.element.Class + + 816 + 192 + 128 + 40 + + Resource Loader +<<Dennis>><<Singleton> + + + + com.umlet.element.Class + + 928 + 560 + 200 + 120 + + Collection of functions +<<lots of functions>> +-- +functions for creating the right structs + + + + com.umlet.element.Relation + + 768 + 576 + 176 + 56 + + lt=- +m1=1..1 +m2=1..1 +Uses> + 24;40;160;40 + + + com.umlet.element.Class + + 560 + 360 + 232 + 136 + + LevelLoader +<<API>><Interface>> +-- +Functions: +vector<struct> LoadLevel(String fileName); +struct LoadLevelHeader(String fileName); +- +Privates: + + + + + + com.umlet.element.Relation + + 344 + 208 + 40 + 168 + + lt=<<. + 24;24;24;152 + + + com.umlet.element.Relation + + 840 + 208 + 88 + 168 + + lt=. +<Uses + 24;24;24;64;72;64;72;152 + + + com.umlet.element.Relation + + 656 + 472 + 40 + 88 + + lt=<<<<- + 24;72;24;24 + + + com.umlet.element.Relation + + 544 + 64 + 136 + 160 + + lt=lt=->>>> +m1=1..1 +m2=1..1 +Uses> + 24;40;80;40;120;40;120;144 + + diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 6ec70e1b..11ec5ea8 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -3,71 +3,68 @@ using namespace GameLogic; -struct AttatchmentMassDriver::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - -}myData; AttatchmentMassDriver::AttatchmentMassDriver(void) { - myData = new PrivateData(); this->owner = 0; } AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) { - myData = new PrivateData(); + this->owner = &owner; } AttatchmentMassDriver::~AttatchmentMassDriver(void) { - delete myData; + } /******************************************************** * 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 (usage) { case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: - ForcePush(usage); + ForcePush(usage,dt); break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - ForcePull(usage); + ForcePull(usage,dt); break; } - + } /******************************************************** * 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); + Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); + Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); + Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); + + //Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,ForcePushAction); + } /******************************************************** * 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); } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index a1ededd0..3fb8932a 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -15,30 +15,31 @@ namespace GameLogic ~AttatchmentMassDriver(void); - void UseAttatchment(const WEAPON_FIRE &usage); + void UseAttatchment(const WEAPON_FIRE &usage, float dt); private: /******************************************************** * Pushes objects and players in a cone in front of the player * @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 * @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 * @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); + + void ForcePushAction(Oyster::Physics::ICustomBody *obj); private: - struct PrivateData; - PrivateData *myData; + }; } #endif diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 4cdb3689..eaafd59a 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -1,62 +1,65 @@ -#include "CollisionManager.h" #include "PhysicsAPI.h" #include "Object.h" #include "DynamicObject.h" #include "Player.h" +#include "Level.h" +#include "AttatchmentMassDriver.h" using namespace Oyster; using namespace GameLogic; - void PlayerVBox(Player &player, DynamicObject &box); + void PlayerVBox(Player &player, DynamicObject &box, Oyster::Math::Float kineticEnergyLoss); + void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss); - - Physics::ICustomBody::SubscriptMessage CollisionManager::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) + //Physics::ICustomBody::SubscriptMessage + void Player::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { - //Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef)); - //Object *realObj = (Object*)obj->gameObjectRef; + Player *player = ((Player*)(rigidBodyPlayer->GetCustomTag())); + Object *realObj = (Object*)obj->GetCustomTag(); - //switch (realObj->GetType()) - //{ - //case OBJECT_TYPE::OBJECT_TYPE_BOX: - // PlayerVBox(*player,(*(DynamicObject*) realObj)); - // break; - //case OBJECT_TYPE::OBJECT_TYPE_PLAYER: - // - // break; - //} + switch (realObj->GetType()) + { + case OBJECT_H::OBJECT_TYPE_GENERIC: + PlayerVObject(*player,*realObj, kineticEnergyLoss); + //return Physics::ICustomBody::SubscriptMessage_none; + break; + + case OBJECT_TYPE::OBJECT_TYPE_BOX: + PlayerVBox(*player,(*(DynamicObject*) realObj), kineticEnergyLoss); + //return Physics::ICustomBody::SubscriptMessage_none; + break; + case OBJECT_TYPE::OBJECT_TYPE_PLAYER: + //return 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, Oyster::Math::Float kineticEnergyLoss) { + //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); + } + + void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss) + { + //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 + //use as part of the damage algorithm player.DamageLife(20); } - Physics::ICustomBody::SubscriptMessage CollisionManager::BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) + //Oyster::Physics::ICustomBody::SubscriptMessage + void Level::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { - if(rigidBodyBox == 0) - { - return Physics::ICustomBody::SubscriptMessage::SubscriptMessage_none; - } - //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; + //return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; } - Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj) + void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj) { - return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; + Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500); + ((Object*)obj->GetCustomTag())->ApplyLinearImpulse(pushForce); } diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index 21723885..6179333f 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -10,14 +10,7 @@ namespace GameLogic class CollisionManager { public: - //these are the main collision functions - //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); + //put general collision functions here that are not part of a specific object }; diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 4c7c4197..2b0d0b8b 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -24,7 +24,8 @@ namespace GameLogic { OBJECT_TYPE_PLAYER = 0, OBJECT_TYPE_BOX = 1, - OBJECT_TYPE_WORLD = 2, + OBJECT_TYPE_WORLD = 2, + OBJECT_TYPE_GENERIC = 4, OBJECT_TYPE_UNKNOWN = -1, }; diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h index 5bc400e6..e458fdbf 100644 --- a/Code/Game/GameLogic/IAttatchment.h +++ b/Code/Game/GameLogic/IAttatchment.h @@ -19,7 +19,7 @@ namespace GameLogic IAttatchment(void); ~IAttatchment(void); - virtual void UseAttatchment(const WEAPON_FIRE &usage) = 0; + virtual void UseAttatchment(const WEAPON_FIRE &usage, float dt) = 0; private: diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index b2bbe60c..8335ea8e 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -25,7 +25,7 @@ void Level::InitiateLevel(float radius) sbDesc.radius = 8; //radius; sbDesc.mass = 10e12f; //sbDesc.mass = 0; //10^16 - sbDesc.subscription_onCollision = CollisionManager::LevelCollision; + sbDesc.subscription_onCollisionResponse = Level::LevelCollision; ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); API::Instance().AddObject(rigidBody); diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 2242a8b2..71e7ed06 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -51,6 +51,14 @@ namespace GameLogic ********************************************************/ 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 void LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + private: TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index fb0e8994..bb36246f 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -49,6 +49,11 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type) this->type = type; } +void Object::ApplyLinearImpulse(Oyster::Math::Float4 force) +{ + setState.ApplyLinearImpulse(force); +} + Object::~Object(void) { diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 1316b287..26bf17db 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -23,6 +23,7 @@ namespace GameLogic OBJECT_TYPE GetType() const; int GetID() const; Oyster::Physics::ICustomBody* GetRigidBody(); + void ApplyLinearImpulse(Oyster::Math::Float4 force); void BeginFrame(); void EndFrame(); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index d21422d8..a6320bd5 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -8,7 +8,7 @@ using namespace GameLogic; using namespace Oyster::Physics; Player::Player() - :DynamicObject(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) + :DynamicObject(Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) { weapon = new Weapon(); @@ -81,7 +81,7 @@ void Player::MoveLeft() void Player::UseWeapon(const WEAPON_FIRE &usage) { - this->weapon->Use(usage); + this->weapon->Use(usage,gameInstance->GetFrameTime()); } void Player::Respawn(Oyster::Math::Float3 spawnPoint) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 39e8f5f6..6d1f0424 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -41,7 +41,17 @@ namespace GameLogic ********************************************************/ void Respawn(Oyster::Math::Float3 spawnPoint); + 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 void PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + bool IsWalking(); bool IsJumping(); @@ -65,6 +75,9 @@ namespace GameLogic PLAYER_STATE playerState; Oyster::Math::Float4 lookDir; + bool hasTakenDamage; + float invincibleCooldown; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 28765cf3..994ccac5 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -1,60 +1,39 @@ #include "Weapon.h" -#include "AttatchmentSocket.h" #include "AttatchmentMassDriver.h" -#include "DynamicArray.h" + using namespace GameLogic; 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> attatchmentSockets; - int currentNrOfAttatchments; - SmartPointer selectedAttatchment; - int selectedSocketID; - -}myData; Weapon::Weapon() { - myData = new PrivateData(); + weaponState = WEAPON_STATE_IDLE; + selectedAttatchment = 0; + currentNrOfAttatchments = 0; + selectedSocketID = 0; + attatchmentSockets = 0; } Weapon::Weapon(int MaxNrOfSockets) { - myData = new PrivateData(); - myData->attatchmentSockets.Resize(MaxNrOfSockets); + attatchmentSockets.Resize(MaxNrOfSockets); } Weapon::~Weapon(void) { - delete myData; + } /******************************************************** * 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() { - return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIRING); + return (weaponState == WEAPON_STATE::WEAPON_STATE_FIRING); } bool Weapon::IsIdle() { - return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_IDLE); + return (weaponState == WEAPON_STATE::WEAPON_STATE_IDLE); } bool Weapon::IsReloading() { - return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING); + return (weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING); } 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; } @@ -96,16 +75,16 @@ bool Weapon::IsValidSocket(int socketID) int Weapon::GetCurrentSocketID() { - return myData->selectedSocketID; + return selectedSocketID; } 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); - myData->currentNrOfAttatchments++; + attatchmentSockets[currentNrOfAttatchments]->SetAttatchment(attatchment); + currentNrOfAttatchments++; } } @@ -113,7 +92,7 @@ void Weapon::SwitchAttatchment(IAttatchment *attatchment, int socketID, Player * { if (IsValidSocket(socketID)) { - myData->attatchmentSockets[socketID]->SetAttatchment(attatchment); + attatchmentSockets[socketID]->SetAttatchment(attatchment); } } @@ -121,7 +100,7 @@ void Weapon::RemoveAttatchment(int socketID) { if (IsValidSocket(socketID)) { - myData->attatchmentSockets[socketID]->RemoveAttatchment(); + attatchmentSockets[socketID]->RemoveAttatchment(); } } @@ -129,8 +108,8 @@ void Weapon::SelectAttatchment(int socketID) { if (IsValidSocket(socketID)) { - myData->selectedAttatchment = myData->attatchmentSockets[socketID]->GetAttatchment(); - myData->selectedSocketID = socketID; + selectedAttatchment = attatchmentSockets[socketID]->GetAttatchment(); + selectedSocketID = socketID; } } \ No newline at end of file diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h index 719a853c..0d3c09d8 100644 --- a/Code/Game/GameLogic/Weapon.h +++ b/Code/Game/GameLogic/Weapon.h @@ -6,21 +6,20 @@ #include "GameLogicStates.h" #include "IAttatchment.h" #include "Player.h" +#include "AttatchmentSocket.h" +#include "DynamicArray.h" namespace GameLogic { class Weapon { - public: - - Weapon(void); Weapon(int nrOfAttatchmentSockets); ~Weapon(void); - void Use(const WEAPON_FIRE &fireInput); + void Use(const WEAPON_FIRE &usage, float dt); void AddNewAttatchment(IAttatchment *attatchment, Player *owner); void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner); @@ -35,9 +34,12 @@ namespace GameLogic int GetCurrentSocketID(); - private: - struct PrivateData; - PrivateData *myData; + private: + WEAPON_STATE weaponState; + Utility::DynamicMemory::DynamicArray attatchmentSockets; + int currentNrOfAttatchments; + IAttatchment *selectedAttatchment; + int selectedSocketID; }; } diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index 60f05298..3faff29e 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -134,7 +134,7 @@ void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, Visitor { if(collideable.Intersects(this->leafData[i].container)) { - hitAction(*this, i); + hitAction( this->GetCustomBody(i) ); } } } diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 6c6606a9..7b350795 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -18,7 +18,7 @@ namespace Oyster static const unsigned int invalid_ref; typedef void(*VisitorAction)(Octree&, unsigned int, unsigned int); - typedef void(*VisitorActionCollideable)(Octree&, unsigned int); + typedef void(*VisitorActionCollideable)(ICustomBody*); struct Data { diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 7615216c..ead748e4 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -94,9 +94,14 @@ namespace // proto->Predict( forwardedDeltaPos, forwardedDeltaAxis, bounceLinearImpulse, bounceAngularImpulse, API_instance.GetFrameTimeLength() ); // } + + // protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis ); protoState.ApplyImpulse( bounce, worldPointOfContact, normal ); proto->SetState( protoState ); + + proto->CallSubscription_CollisionResponse( deuter, protoState.GetLinearMomentum().GetMagnitude()/(protoState.GetMass() + protoState.GetLinearMomentum().GetMagnitude())); + } break; } @@ -270,7 +275,7 @@ void API_Impl::RemoveGravity( const API::Gravity &g ) } } -void API_Impl::ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ) +void API_Impl::ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(ICustomBody*) ) { this->worldScene.Visit(collideable, hitAction); } @@ -383,6 +388,11 @@ namespace Oyster { namespace Physics return ::Oyster::Physics::ICustomBody::SubscriptMessage_none; } + void EventAction_CollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ) + { /* Do nothing except returning business as usual. */ + + } + void EventAction_Move( const ::Oyster::Physics::ICustomBody *object ) { /* Do nothing. */ } } diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index ad2c91a4..b9343ae6 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -35,7 +35,7 @@ namespace Oyster void AddGravity( const API::Gravity &g ); void RemoveGravity( const API::Gravity &g ); - void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ); + void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(ICustomBody*) ); //void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ); @@ -62,6 +62,7 @@ namespace Oyster { void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto ); ::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter ); + void EventAction_CollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ); void EventAction_Move( const ::Oyster::Physics::ICustomBody *object ); } } diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 1f2837b2..5a9bf53f 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -47,6 +47,7 @@ SimpleRigidBody::SimpleRigidBody() this->rigid.SetMass_KeepMomentum( 16.0f ); this->gravityNormal = Float3::null; this->onCollision = Default::EventAction_Collision; + this->onCollisionResponse = Default::EventAction_CollisionResponse; this->onMovement = Default::EventAction_Move; this->scene = nullptr; this->customTag = nullptr; @@ -74,6 +75,15 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc ) this->onCollision = Default::EventAction_Collision; } + if( desc.subscription_onCollisionResponse ) + { + this->onCollisionResponse = desc.subscription_onCollisionResponse; + } + else + { + this->onCollisionResponse = Default::EventAction_CollisionResponse; + } + if( desc.subscription_onMovement ) { this->onMovement= desc.subscription_onMovement; @@ -158,6 +168,11 @@ ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription_Collision( const return this->onCollision( this, deuter ); } +void SimpleRigidBody::CallSubscription_CollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss ) +{ + return this->onCollisionResponse( this, deuter, kineticEnergyLoss ); +} + void SimpleRigidBody::CallSubscription_Move() { this->onMovement( this ); @@ -315,6 +330,18 @@ void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functi } } +void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_CollisionResponse functionPointer ) +{ + if( functionPointer ) + { + this->onCollisionResponse = functionPointer; + } + else + { + this->onCollisionResponse = Default::EventAction_CollisionResponse; + } +} + void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Move functionPointer ) { if( functionPointer ) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h index cce657da..271c4362 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -22,6 +22,7 @@ namespace Oyster { namespace Physics //::Oyster::Math::Float3 GetRigidLinearVelocity() const; SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter ); + void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ); void CallSubscription_Move(); bool IsAffectedByGravity() const; @@ -44,6 +45,7 @@ namespace Oyster { namespace Physics void SetScene( void *scene ); void SetSubscription( EventAction_Collision functionPointer ); + void SetSubscription( EventAction_CollisionResponse functionPointer ); void SetSubscription( EventAction_Move functionPointer ); void SetGravity( bool ignore); @@ -64,6 +66,7 @@ namespace Oyster { namespace Physics ::Oyster::Math::Float4 deltaPos, deltaAxis; ::Oyster::Math::Float3 gravityNormal; EventAction_Collision onCollision; + EventAction_CollisionResponse onCollisionResponse; EventAction_Move onMovement; Octree *scene; void *customTag; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 7b15510a..9fd8d219 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -14,6 +14,7 @@ SphericalRigidBody::SphericalRigidBody() this->rigid.SetMass_KeepMomentum( 10.0f ); this->gravityNormal = Float3::null; this->onCollision = Default::EventAction_Collision; + this->onCollisionResponse = Default::EventAction_CollisionResponse; this->onMovement = Default::EventAction_Move; this->scene = nullptr; this->customTag = nullptr; @@ -42,6 +43,15 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des this->onCollision = Default::EventAction_Collision; } + if( desc.subscription_onCollisionResponse ) + { + this->onCollisionResponse = desc.subscription_onCollisionResponse; + } + else + { + this->onCollisionResponse = Default::EventAction_CollisionResponse; + } + if( desc.subscription_onMovement ) { this->onMovement= desc.subscription_onMovement; @@ -123,6 +133,12 @@ ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription_Collision( co return this->onCollision( this, deuter ); } +void SphericalRigidBody::CallSubscription_CollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss ) +{ + this->onCollisionResponse( this, deuter, kineticEnergyLoss); +} + + void SphericalRigidBody::CallSubscription_Move() { this->onMovement( this ); @@ -234,6 +250,18 @@ void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision fun } } +void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_CollisionResponse functionPointer ) +{ + if( functionPointer ) + { + this->onCollisionResponse = functionPointer; + } + else + { + this->onCollisionResponse = Default::EventAction_CollisionResponse; + } +} + void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Move functionPointer ) { if( functionPointer ) diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index 49c8fb8c..213e225b 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -23,6 +23,7 @@ namespace Oyster { namespace Physics //::Oyster::Math::Float3 GetRigidLinearVelocity() const; SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter ); + void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ); void CallSubscription_Move(); bool IsAffectedByGravity() const; @@ -45,6 +46,7 @@ namespace Oyster { namespace Physics void SetScene( void *scene ); void SetSubscription( EventAction_Collision functionPointer ); + void SetSubscription( EventAction_CollisionResponse functionPointer ); void SetSubscription( EventAction_Move functionPointer ); void SetGravity( bool ignore); @@ -65,6 +67,7 @@ namespace Oyster { namespace Physics ::Oyster::Math::Float4 deltaPos, deltaAxis; ::Oyster::Math::Float3 gravityNormal; EventAction_Collision onCollision; + EventAction_CollisionResponse onCollisionResponse; EventAction_Move onMovement; Octree *scene; void *customTag; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 4e1844f5..7f20fcf7 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -16,7 +16,6 @@ namespace Oyster { class API; class ICustomBody; - class Octree; namespace Struct { @@ -137,7 +136,12 @@ namespace Oyster ********************************************************/ virtual void RemoveGravity( const API::Gravity &g ) = 0; - virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ) = 0; + /******************************************************** + * Applies an effect to objects that collide with the set volume. + * @param collideable: An ICollideable that defines the volume of the effect. + * @param hitAction: A function that contains the effect. + ********************************************************/ + virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(ICustomBody*) ) = 0; ///******************************************************** // * Apply force on an object. @@ -234,6 +238,7 @@ namespace Oyster enum SubscriptMessage { SubscriptMessage_none, + SubscriptMessage_kineticLoss, SubscriptMessage_ignore_collision_response }; @@ -257,6 +262,11 @@ namespace Oyster ********************************************************/ virtual SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter ) = 0; + /******************************************************** + * @todo TODO: need doc + ********************************************************/ + virtual void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ) = 0; + /******************************************************** * @todo TODO: need doc ********************************************************/ @@ -387,6 +397,13 @@ namespace Oyster ********************************************************/ virtual void SetSubscription( EventAction_Collision functionPointer ) = 0; + /******************************************************** + * Sets the function that will be called by the engine + * whenever a collision has finished. + * @param functionPointer: If NULL, an empty default function will be set. + ********************************************************/ + virtual void SetSubscription( EventAction_CollisionResponse functionPointer ) = 0; + /******************************************************** * Sets the function that will be called by the engine * whenever an object have moved. diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index eac9bef3..46de90cc 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -21,6 +21,7 @@ namespace Oyster this->frictionCoeff_Static = 0.5f; this->inertiaTensor = ::Oyster::Math::Float4x4::identity; this->subscription_onCollision = NULL; + this->subscription_onCollisionResponse = NULL; this->subscription_onMovement = NULL; this->ignoreGravity = false; } @@ -35,6 +36,7 @@ namespace Oyster this->frictionCoeff_Dynamic = 0.5f; this->frictionCoeff_Static = 0.5f; this->subscription_onCollision = NULL; + this->subscription_onCollisionResponse = NULL; this->subscription_onMovement = NULL; this->ignoreGravity = false; } diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index 059e9f98..1bc1736f 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -19,6 +19,7 @@ namespace Oyster { namespace Physics ::Oyster::Math::Float frictionCoeff_Dynamic; ::Oyster::Math::Float4x4 inertiaTensor; ::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision; + ::Oyster::Physics::ICustomBody::EventAction_CollisionResponse subscription_onCollisionResponse; ::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement; bool ignoreGravity; @@ -35,6 +36,7 @@ namespace Oyster { namespace Physics ::Oyster::Math::Float frictionCoeff_Static; ::Oyster::Math::Float frictionCoeff_Dynamic; ::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision; + ::Oyster::Physics::ICustomBody::EventAction_CollisionResponse subscription_onCollisionResponse; ::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement; bool ignoreGravity;