From 2859588d2063147c032e9a85b19b90a7cdb011f5 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 26 Nov 2013 09:19:59 +0100 Subject: [PATCH 1/3] added collisionManager also some changes around the place --- Code/GameLogic/CollisionManager.cpp | 12 ++++++++++++ Code/GameLogic/CollisionManager.h | 30 +++++++++++++++++++++++++++++ Code/GameLogic/Game.h | 16 +++++++-------- Code/GameLogic/Object.h | 6 +++--- Code/GameLogic/Player.cpp | 4 +++- Code/GameLogic/RefManager.cpp | 8 ++++---- Code/GameLogic/RefManager.h | 4 ++-- 7 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 Code/GameLogic/CollisionManager.cpp create mode 100644 Code/GameLogic/CollisionManager.h diff --git a/Code/GameLogic/CollisionManager.cpp b/Code/GameLogic/CollisionManager.cpp new file mode 100644 index 00000000..35b497d1 --- /dev/null +++ b/Code/GameLogic/CollisionManager.cpp @@ -0,0 +1,12 @@ +#include "CollisionManager.h" + +using namespace GameLogic; + +CollisionManager::CollisionManager(void) +{ +} + + +CollisionManager::~CollisionManager(void) +{ +} diff --git a/Code/GameLogic/CollisionManager.h b/Code/GameLogic/CollisionManager.h new file mode 100644 index 00000000..f4418b3d --- /dev/null +++ b/Code/GameLogic/CollisionManager.h @@ -0,0 +1,30 @@ +#ifndef COLLISIONMANAGER_H +#define COLLISIONMANAGER_H + +#include "Object.h" +#include "PhysicsAPI.h" +#include "RefManager.h" +#include "DynamicObject.h" +#include "Player.h" + +namespace GameLogic +{ + + class CollisionManager + { + + public: + CollisionManager(void); + ~CollisionManager(void); + + void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2); + void PlayerVBox(Player &player, DynamicObject &box); + + private: + + + }; + +} + +#endif \ No newline at end of file diff --git a/Code/GameLogic/Game.h b/Code/GameLogic/Game.h index 0b452b30..2d808388 100644 --- a/Code/GameLogic/Game.h +++ b/Code/GameLogic/Game.h @@ -8,21 +8,21 @@ namespace GameLogic { class Game { - private: + public: + Game(); + ~Game(); + + void Init(); + void StartGame(); + void Update(); + void Render(); private: Level* level; Player* player; - public: - Game(); - ~Game(); - void Init(); - void StartGame(); - void Update(); - void Render(); }; } #endif \ No newline at end of file diff --git a/Code/GameLogic/Object.h b/Code/GameLogic/Object.h index a3c9fa2e..193be4db 100644 --- a/Code/GameLogic/Object.h +++ b/Code/GameLogic/Object.h @@ -17,7 +17,7 @@ namespace GameLogic Object(void); virtual ~Object(void); - Utility::DynamicMemory::UniquePointer model; + void Render(); private: @@ -25,9 +25,9 @@ namespace GameLogic protected: //either a model pointer or an ID to an arraypos filled with models that are to be rendered //rigidBody - unsigned int ref; - ::Utility::DynamicMemory::UniquePointer rigidBody; + Utility::DynamicMemory::UniquePointer rigidBody; + Utility::DynamicMemory::UniquePointer model; }; } diff --git a/Code/GameLogic/Player.cpp b/Code/GameLogic/Player.cpp index 67cbf52e..bc83ba25 100644 --- a/Code/GameLogic/Player.cpp +++ b/Code/GameLogic/Player.cpp @@ -46,7 +46,9 @@ Player::Player(void) { life = 10; - UniquePointer rigidBody = API::Instance().CreateSimpleRigidBody(); + rigidBody = API::Instance().CreateSimpleRigidBody(); + + //ref = API::Instance().AddObject(rigidBody); ////ref = API::Instance().AddObject(API::Instance().CreateSimpleRigidBody()); //const ICustomBody* rB; diff --git a/Code/GameLogic/RefManager.cpp b/Code/GameLogic/RefManager.cpp index 852cb6b1..022ec6bb 100644 --- a/Code/GameLogic/RefManager.cpp +++ b/Code/GameLogic/RefManager.cpp @@ -13,14 +13,14 @@ RefManager::~RefManager(void) { } -Object* RefManager::GetMap(Oyster::Physics::ICustomBody *body) +Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body) { - return mapper[body]; + return mapper[&body]; } -void RefManager::AddMapping(Oyster::Physics::ICustomBody *body, Object *obj) +void RefManager::AddMapping(Oyster::Physics::ICustomBody &body, Object &obj) { - mapper.insert(mapData(body,obj)); + mapper.insert(mapData(&body,&obj)); } diff --git a/Code/GameLogic/RefManager.h b/Code/GameLogic/RefManager.h index 1d49af78..2e1e9498 100644 --- a/Code/GameLogic/RefManager.h +++ b/Code/GameLogic/RefManager.h @@ -16,8 +16,8 @@ namespace GameLogic RefManager(void); ~RefManager(void); - Object* GetMap(Oyster::Physics::ICustomBody *body); - void AddMapping(Oyster::Physics::ICustomBody *body, Object *obj); + Object* GetMap(Oyster::Physics::ICustomBody &body); + void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); private: From d87e643777655dbe189b20026aed4547e7c7a2e8 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 26 Nov 2013 11:30:49 +0100 Subject: [PATCH 2/3] =?UTF-8?q?lite=20saker=20+=20debug=20f=C3=B6nster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/GameLogic/CollisionManager.cpp | 35 ++++++++++++++++ Code/GameLogic/CollisionManager.h | 5 ++- Code/GameLogic/Object.cpp | 5 +++ Code/GameLogic/Object.h | 14 ++++++- Code/GameLogic/Player.cpp | 65 ++--------------------------- Code/GameLogic/Player.h | 4 +- Code/GameLogic/RefManager.h | 8 ++-- 7 files changed, 62 insertions(+), 74 deletions(-) diff --git a/Code/GameLogic/CollisionManager.cpp b/Code/GameLogic/CollisionManager.cpp index 35b497d1..5994dc89 100644 --- a/Code/GameLogic/CollisionManager.cpp +++ b/Code/GameLogic/CollisionManager.cpp @@ -4,9 +4,44 @@ using namespace GameLogic; CollisionManager::CollisionManager(void) { + refManager = new RefManager(); } CollisionManager::~CollisionManager(void) { + SAFE_DELETE(refManager); } + +void CollisionManager::ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2) +{ + Object *realObj1 = refManager->GetMap(obj1); + Object *realObj2 = refManager->GetMap(obj2); + + + switch(realObj1->GetType()) + { + case Object::OBJECT_TYPE_PLAYER: + + if (realObj2->GetType() == Object::OBJECT_TYPE_BOX ) + { + PlayerVBox(*((Player*)realObj1),*((DynamicObject*)realObj2)); + } + + break; + case Object::OBJECT_TYPE_BOX: + + if (realObj2->GetType() == Object::OBJECT_TYPE_PLAYER) + { + PlayerVBox(*((Player*)realObj2),*((DynamicObject*)realObj1)); + } + + break; + } + +} + +void CollisionManager::PlayerVBox(Player &player, DynamicObject &box) +{ + //spela ljud? ta skada? etc etc +} \ No newline at end of file diff --git a/Code/GameLogic/CollisionManager.h b/Code/GameLogic/CollisionManager.h index f4418b3d..8bbc06c7 100644 --- a/Code/GameLogic/CollisionManager.h +++ b/Code/GameLogic/CollisionManager.h @@ -17,11 +17,12 @@ namespace GameLogic CollisionManager(void); ~CollisionManager(void); + private: void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2); void PlayerVBox(Player &player, DynamicObject &box); - + private: - + RefManager *refManager; }; diff --git a/Code/GameLogic/Object.cpp b/Code/GameLogic/Object.cpp index 18c7f1c0..e9c8db7a 100644 --- a/Code/GameLogic/Object.cpp +++ b/Code/GameLogic/Object.cpp @@ -59,3 +59,8 @@ void Object::Render() model->info->Vertices.Apply(0); Oyster::Graphics::Core::deviceContext->Draw(model->info->VertexCount,0); } + +Object::OBJECT_TYPE Object::GetType() +{ + return this->type; +} diff --git a/Code/GameLogic/Object.h b/Code/GameLogic/Object.h index 193be4db..6ee07df5 100644 --- a/Code/GameLogic/Object.h +++ b/Code/GameLogic/Object.h @@ -4,23 +4,33 @@ #include "Model/Model.h" #include "Render/Rendering/Render.h" #include "Utilities.h" - #include "PhysicsAPI.h" namespace GameLogic { + class Object { + + public: Object(void); virtual ~Object(void); - + + enum OBJECT_TYPE + { + OBJECT_TYPE_PLAYER, + OBJECT_TYPE_BOX, + }; void Render(); + OBJECT_TYPE GetType(); + private: + OBJECT_TYPE type; protected: //either a model pointer or an ID to an arraypos filled with models that are to be rendered diff --git a/Code/GameLogic/Player.cpp b/Code/GameLogic/Player.cpp index bfd41757..b67c889a 100644 --- a/Code/GameLogic/Player.cpp +++ b/Code/GameLogic/Player.cpp @@ -7,73 +7,15 @@ using namespace Oyster::Physics; using namespace Utility::DynamicMemory; -//void ColisionEvent(unsigned int obj1Ref, unsigned int obj2Ref) -//{ -// const ICustomBody *body1 = &API::Instance().Peek( obj1Ref ); -// const ICustomBody *body2 = &API::Instance().Peek( obj2Ref ); -// if( body1 != &Error::nobody ) -// { -// Object *obj1 = (Object*) const_cast(body1); -// -// Object *obj2 = (Object*) const_cast(body2); -// -// //switch( obj1->type ) -// //{ -// //case Player: -// // switch (obj2->type) -// // { -// // case låda: -// // //action -// // //soud -// // //particle effect -// -// // } -// -// //case låda : -// -// -// //} -// } -// -//} -void DestructionEvent(unsigned int obj1, ::Utility::DynamicMemory::UniquePointer obj2) -{ -} Player::Player(void) :Object() { - life = 10; + life = 100; - UniquePointer rigidBody = API::Instance().CreateSimpleRigidBody(); + rigidBody = API::Instance().CreateSimpleRigidBody(); API::Instance().AddObject(rigidBody); - - ////ref = API::Instance().AddObject(API::Instance().CreateSimpleRigidBody()); - //const ICustomBody* rB; - - ////rB = &API::Instance().Peek(ref); - ////if( rB == &Error::nobody) - ////{ - //// //error - ////} - - //API::Instance().SetCenter(ref, Oyster::Math::Float3::null); - //API::Instance().SetMass_KeepMomentum(ref, 20); - //// get Tensor matrix (tröghetsmonent) - ////API::Instance().SetMomentOfInertiaTensor_KeepMomentum(ref, tensorMatrix ) - // - ////Oyster::Math::Float3 ve = rB->GetCenter(); - //API::Instance().SetDeltaTime(0.01f); - - ////API::Instance().ApplyForceAt(ref, rB->GetCenter(), Oyster::Math::Float3::null); - // - ////API::Instance().SetAction(ColisionEvent); - - ////API::Instance().Update(); - - - } @@ -83,8 +25,7 @@ Player::~Player(void) } void Player::Update() { - //API::Instance().API::Update(); - //API::Instance().API::ApplyForceAt(ref, ) + } void Player::Move() diff --git a/Code/GameLogic/Player.h b/Code/GameLogic/Player.h index 3747e9fe..39deb4b2 100644 --- a/Code/GameLogic/Player.h +++ b/Code/GameLogic/Player.h @@ -7,9 +7,7 @@ namespace GameLogic { - //void ColisionEvent(unsigned int obj1, unsigned int obj2); - void DestructionEvent(unsigned int obj1, ::Utility::DynamicMemory::UniquePointer obj2); - + class Player : public Object { diff --git a/Code/GameLogic/RefManager.h b/Code/GameLogic/RefManager.h index 2e1e9498..1aa51dc8 100644 --- a/Code/GameLogic/RefManager.h +++ b/Code/GameLogic/RefManager.h @@ -8,20 +8,18 @@ namespace GameLogic { - - class RefManager { public: RefManager(void); ~RefManager(void); - Object* GetMap(Oyster::Physics::ICustomBody &body); - void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); + Object* GetMap(Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler + void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value private: - std::map mapper; //shall be pointer from physics that map to an object + std::map mapper; //mapper points a rigidBody to an actual game object }; } From 97e92f8516c58826445133bce2eb979e285bf848 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 26 Nov 2013 11:32:00 +0100 Subject: [PATCH 3/3] GL: debug fix --- Code/GameLogic/DynamicObject.cpp | 4 ++++ Code/GameLogic/DynamicObject.h | 1 + Code/GameLogic/TestGLMain.cpp | 34 +++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Code/GameLogic/DynamicObject.cpp b/Code/GameLogic/DynamicObject.cpp index bdb5be0c..303f9e7d 100644 --- a/Code/GameLogic/DynamicObject.cpp +++ b/Code/GameLogic/DynamicObject.cpp @@ -1,9 +1,13 @@ #include "DynamicObject.h" using namespace GameLogic; +using namespace Oyster::Physics; +using namespace Utility::DynamicMemory; DynamicObject::DynamicObject(void) { + rigidBody = API::Instance().CreateSimpleRigidBody(); + API::Instance().AddObject(rigidBody); } diff --git a/Code/GameLogic/DynamicObject.h b/Code/GameLogic/DynamicObject.h index 445b2e7b..5aa47d97 100644 --- a/Code/GameLogic/DynamicObject.h +++ b/Code/GameLogic/DynamicObject.h @@ -6,6 +6,7 @@ namespace GameLogic { + class DynamicObject : public Object { diff --git a/Code/GameLogic/TestGLMain.cpp b/Code/GameLogic/TestGLMain.cpp index bf8cebbe..363e5d4e 100644 --- a/Code/GameLogic/TestGLMain.cpp +++ b/Code/GameLogic/TestGLMain.cpp @@ -10,6 +10,10 @@ #include "Core/Core.h" #include "Render\Preparations\Preparations.h" #include "IGame.h" + +#include +#include +#include //#include "InputController.h" @@ -40,6 +44,34 @@ HRESULT CleanUp(); // Entry point to the program. Initializes everything and goes into a message processing // loop. Idle time is used to render the scene. //-------------------------------------------------------------------------------------- + +void SetStdOutToNewConsole() +{ + // allocate a console for this app + AllocConsole(); + + // redirect unbuffered STDOUT to the console + HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT); + FILE *fp = _fdopen( fileDescriptor, "w" ); + *stdout = *fp; + setvbuf( stdout, NULL, _IONBF, 0 ); + + // give the console window a nicer title + + SetConsoleTitle(L"Debug Output"); + + // give the console window a bigger buffer size + CONSOLE_SCREEN_BUFFER_INFO csbi; + if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) ) + { + COORD bufferSize; + bufferSize.X = csbi.dwSize.X; + bufferSize.Y = 50; + SetConsoleScreenBufferSize(consoleHandle, bufferSize); + } +} + int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) { if( FAILED( InitWindow( hInstance, nCmdShow ) ) ) @@ -57,7 +89,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL __int64 prevTimeStamp = 0; QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp); - + SetStdOutToNewConsole(); // Main message loop MSG msg = {0}; while(WM_QUIT != msg.message)