GL - merge and some more protocols

This commit is contained in:
Linda Andersson 2013-12-19 10:22:32 +01:00
commit 13430f31fc
38 changed files with 756 additions and 917 deletions

View File

@ -7,6 +7,7 @@
#include "GameClientState\LobbyState.h"
#include "PlayerProtocols.h"
#include "ControlProtocols.h"
#include "GameProtocols.h"
#include "NetworkClient.h"
#include "../WindowManager/WindowShell.h"

View File

@ -2,9 +2,11 @@
#include "DllInterfaces/GFXAPI.h"
#include "C_obj/C_Player.h"
#include "C_obj/C_DynamicObj.h"
#include "NetworkClient.h"
#include "PlayerProtocols.h"
#include "ControlProtocols.h"
#include "GameProtocols.h"
#include "NetworkClient.h"
using namespace DanBias::Client;

View File

@ -5,8 +5,8 @@
#include <Windows.h>
#include <vld.h>
//#include "DanBiasServerAPI.h"
#include "DanBiasGame.h"
#include "DanBiasServerAPI.h"
//#include "DanBiasGame.h"
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)

View File

@ -177,6 +177,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="GameSessionManager.cpp" />
<ClCompile Include="Include\DanBiasServerAPI.cpp" />
<ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameServer.cpp" />
@ -189,6 +190,7 @@
<ItemGroup>
<ClInclude Include="Event\EventManager.h" />
<ClInclude Include="GameServer.h" />
<ClInclude Include="GameSessionManager.h" />
<ClInclude Include="Include\DanBiasServerAPI.h" />
<ClInclude Include="ServerInitReader.h" />
<ClInclude Include="ServerObjects\ClientObject.h" />

View File

@ -54,6 +54,7 @@ namespace DanBias
if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error;
if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error;
if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error;
this->initiated = true;
return DanBiasServerReturn_Sucess;

View File

@ -15,7 +15,7 @@ namespace DanBias
{
public:
GameServer();
~GameServer();
virtual~GameServer();
DanBiasServerReturn Create();
DanBiasServerReturn Run();

View File

@ -0,0 +1,57 @@
#include "GameSessionManager.h"
#include "ServerObjects\GameSession.h"
#include "DynamicArray.h"
struct GameSessionData
{
Utility::DynamicMemory::DynamicArray<DanBias::GameSession*> sessions;
int freeSpot;
int Existst(DanBias::GameSession* s)
{
for (unsigned int i = 0; i < sessions.Size(); i++)
{
if(!sessions[i] && freeSpot == -1) freeSpot = i;
if(sessions[i] == s) return i;
}
return -1;
}
int GetFree()
{
for (unsigned int i = 0; i < sessions.Size(); i++)
if(!sessions[i])
return i;
return -1;
}
} __gameSessionData;
void GameSessionManager::AddSession(DanBias::GameSession* session)
{
if(__gameSessionData.Existst(session) == -1)
{
int k = __gameSessionData.freeSpot;
if( k == -1) k = __gameSessionData.GetFree();
if(k == -1) __gameSessionData.sessions.Push(session);
else __gameSessionData.sessions[k] = session;
}
}
void GameSessionManager::CloseSession(DanBias::GameSession* session)
{
int i = __gameSessionData.Existst(session);
//Moron check...
if(i == -1) return;
//__gameSessionData.sessions[i]->Close();
}

View File

@ -0,0 +1,16 @@
#ifndef DANBIASSERVER_GAME_SEESION_MANAGER_H
#define DANBIASSERVER_GAME_SEESION_MANAGER_H
namespace DanBias
{
class GameSession;
}
class GameSessionManager
{
public:
static void AddSession(DanBias::GameSession* session);
static void CloseSession(DanBias::GameSession* session);
};
#endif // !DANBIASSERVER_GAME_SEESION_MANAGER_H

View File

@ -13,7 +13,7 @@ ClientObject::~ClientObject()
this->client->Disconnect();
}
void ClientObject::SetPostbox(Oyster::PostBox<NetworkSession::NetEvent>* box)
void ClientObject::SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box)
{
this->box = box;
}

View File

@ -14,13 +14,14 @@ namespace DanBias
{
public:
ClientObject(Oyster::Network::NetworkClient* client);
~ClientObject();
virtual~ClientObject();
void SetPostbox(Oyster::PostBox<NetworkSession::NetEvent>* box);
void SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box);
GameLogic::Player* Logic_Object();
Oyster::Network::NetworkClient* NetClient_Object();
private:
/** This method is NOT threadsafe. */
virtual void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override;

View File

@ -1,9 +1,148 @@
#include <GameProtocols.h>
#include "GameSession.h"
#include <PostBox\PostBox.h>
#include "ClientObject.h"
#define ERIK
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
namespace DanBias
{
GameSession::GameSession()
{
}
GameSession::~GameSession()
{
}
void GameSession::Run(const GameSessionDescription& desc)
{
}
void GameSession::AttachClient(SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box )
{
this->Init();
}
////private: //overriden NetworkSession functions
void GameSession::Close()
{
}
SmartPointer<ClientObject> GameSession::DetachClient(NetworkClient* client)
{
return SmartPointer<ClientObject>();
}
SmartPointer<ClientObject> GameSession::DetachClient(ClientObject* client)
{
return SmartPointer<ClientObject>();
}
SmartPointer<ClientObject> GameSession::DetachClient(short ID)
{
return SmartPointer<ClientObject>();
}
void GameSession::Send(::CustomNetProtocol& protocol)
{
}
void GameSession::Send(CustomNetProtocol& protocol, int ID)
{
}
void GameSession::SetPostbox(IPostBox<NetworkSession::NetEvent> *box)
{
}
void GameSession::CloseSession(NetworkSession* clientDestination)
{
}
////private: //overriden Threading functions
void GameSession::ThreadEntry()
{
}
void GameSession::ThreadExit()
{
}
bool GameSession::DoWork ( )
{
this->ParseEvents();
this->Frame();
return true;
}
////private:
void GameSession::Init()
{
#ifdef ERIK
EricLogicInitFunc();
#else
#endif
}
void GameSession::Frame()
{
#ifdef ERIK
EricLogicFrameFunc();
#else
#endif
}
void GameSession::ParseEvents()
{
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box->Fetch();
#ifdef ERIK
EricsLogicTestingProtocalRecieved(e.reciever, e.protocol);
#else
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
short f = e.protocol[0].value.netShort;
switch (f)
{
default:
break;
}
#endif
}
}
}//End namespace DanBias
#pragma region TESTING
//VARIABLES GOES HERE
int i = 0;
GameLogic::Player erik;
void GameSession::EricLogicInitFunc()
{
}
void GameSession::EricLogicFrameFunc()
{
}
void GameSession::EricsLogicTestingProtocalRecieved(ClientObject* reciever, CustomNetProtocol& protocol)
{
}
#pragma endregion
}//End namespace DanBias

View File

@ -2,16 +2,59 @@
#define DANBIASSERVER_GAME_SESSION_H
#include "NetworkSession.h"
#include <PostBox\IPostBox.h>
#include <Thread\OysterThread.h>
namespace DanBias
{
class GameSession :public NetworkSession
class ClientObject;
class GameSession :private NetworkSession, public Oyster::Thread::IThreadObject
{
public:
struct GameSessionDescription
{
NetworkSession* owner;
};
public:
GameSession();
~GameSession();
virtual~GameSession();
void Run(const GameSessionDescription& desc);
void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box = 0) override;
private: //overriden NetworkSession functions
void Close();
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(Oyster::Network::NetworkClient* client) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(ClientObject* client) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(short ID) override;
void Send(Oyster::Network::CustomNetProtocol& protocol) override;
void Send(Oyster::Network::CustomNetProtocol& protocol, int ID) override;
void SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box) override;
void CloseSession(NetworkSession* clientDestination) override;
private: //overriden Threading functions
void ThreadEntry() override;
void ThreadExit() override;
bool DoWork ( ) override;
private:
void Init();
void Frame();
void ParseEvents();
private:
NetworkSession* owner;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
#pragma region TESTING
void EricLogicInitFunc();
void EricLogicFrameFunc();
void EricsLogicTestingProtocalRecieved(ClientObject* reciever, Oyster::Network::CustomNetProtocol& protocol);
#pragma endregion
};//End GameSession

View File

@ -9,7 +9,8 @@ namespace DanBias
{
public:
GameLobby();
~GameLobby();
virtual~GameLobby();
void Release();
private:

View File

@ -1,19 +1,21 @@
#include "MainLobby.h"
#include <PlayerProtocols.h>
#include <PostBox\PostBox.h>
namespace DanBias
{
MainLobby::MainLobby()
{
this->box = new Oyster::PostBox<DanBias::NetworkSession::NetEvent>();
}
MainLobby::~MainLobby()
{
delete this->box;
this->box = 0;
}
void MainLobby::Release()
{
this->DetachClient();
this->CloseSession(0);
}
void MainLobby::Frame()
@ -24,9 +26,9 @@ namespace DanBias
//////// Private
void MainLobby::ParseEvents()
{
if(!this->box.IsEmpty())
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box.Fetch();
NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;

View File

@ -2,6 +2,7 @@
#define DANBIASSERVER_MAINLOBBY_H
#include "..\NetworkSession.h"
#include <PostBox\IPostBox.h>
namespace DanBias
{
@ -9,7 +10,7 @@ namespace DanBias
{
public:
MainLobby();
~MainLobby();
virtual~MainLobby();
void Release();
void Frame();
@ -17,6 +18,9 @@ namespace DanBias
private:
void ParseEvents();
private:
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
};
}//End namespace DanBias
#endif // !DANBIASGAME_GAMELOBBY_H

View File

@ -8,79 +8,154 @@ static std::mutex ClientListLock;
namespace DanBias
{
NetworkSession::NetworkSession()
{ }
NetworkSession::NetworkSession(const NetworkSession& orig)
{
this->clients = orig.clients;
}
const NetworkSession& NetworkSession::operator=(const NetworkSession& orig)
{
this->clients = orig.clients;
return *this;
}
NetworkSession::~NetworkSession()
{
this->clients.Clear();
}
void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client)
void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box)
{
while (!ClientListLock.try_lock()); //Possible Deadlock
ClientListLock.lock();
int k = -1;
for (unsigned int i = 0; (k == -1) && i < this->clients.size(); i++)
{
if(!this->clients[i])
k = i;
}
int k = -1;
for (unsigned int i = 0; (k == -1) && i < this->clients.Size(); i++)
{
if(!this->clients[i])
k = i;
}
if(k == -1)
{
this->clients.push_back(client);
this->clients[this->clients.size() - 1]->SetPostbox(&this->box);
}
else
{
this->clients[k]->SetPostbox(&this->box);
}
if(k == -1)
{
this->clients.Push(client);
this->clients[this->clients.Size() - 1]->SetPostbox(box);
}
else
{
this->clients[k] = client;
this->clients[k]->SetPostbox(box);
}
ClientListLock.unlock();
}
void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client)
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::DetachClient(Oyster::Network::NetworkClient* client)
{
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->Id())
this->clients[i] = 0;
}
Utility::DynamicMemory::SmartPointer<ClientObject> val;
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->Id())
{
val = this->clients[i];
this->clients[i] = 0;
}
}
ClientListLock.unlock();
return val;
}
void NetworkSession::DetachClient(ClientObject* client)
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::DetachClient(ClientObject* client)
{
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->NetClient_Object()->Id())
this->clients[i] = 0;
}
Utility::DynamicMemory::SmartPointer<ClientObject> val;
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->NetClient_Object()->Id())
{
val = this->clients[i];
this->clients[i] = 0;
}
}
ClientListLock.unlock();
return val;
}
void NetworkSession::DetachClient(short ID)
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::DetachClient(short ID)
{
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == ID)
this->clients[i] = 0;
}
}
void NetworkSession::DetachClient()
{
for (unsigned int i = 0; i < this->clients.size(); i++)
{
this->clients[i] = 0;
}
Utility::DynamicMemory::SmartPointer<ClientObject> val;
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == ID)
{
val = this->clients[i];
this->clients[i] = 0;
}
}
ClientListLock.unlock();
return val;
}
void NetworkSession::Kick()
void NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol)
{
for (unsigned int i = 0; i < this->clients.size(); i++)
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->NetClient_Object()->Disconnect();
this->clients[i] = 0;
this->clients[i]->NetClient_Object()->Send(&protocol);
}
}
void NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->NetClient_Object()->Id() == ID)
{
this->clients[i]->NetClient_Object()->Send(&protocol);
break;
}
}
}
void NetworkSession::SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->SetPostbox(box);
}
}
void NetworkSession::CloseSession(NetworkSession * owner)
{
ClientListLock.lock();
if(!owner)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->NetClient_Object()->Disconnect();
}
}
else
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
owner->AttachClient(this->clients[i]);
}
}
this->clients.Clear();
ClientListLock.unlock();
}
}//End namespace DanBias

View File

@ -4,13 +4,17 @@
#ifndef DANBIASSERVER_NETWORK_SESSION_H
#define DANBIASSERVER_NETWORK_SESSION_H
#pragma warning(disable: 4150)
#define NOMINMAX
#include "Utilities.h"
#include <PostBox\PostBox.h>
#include <DynamicArray.h>
#include <PostBox\IPostBox.h>
#include <CustomNetProtocol.h>
#include <NetworkClient.h>
#include <vector>
namespace DanBias
{
class ClientObject;
@ -25,26 +29,26 @@ namespace DanBias
public:
NetworkSession();
~NetworkSession();
NetworkSession(const NetworkSession& orig);
const NetworkSession& operator=(const NetworkSession& orig);
virtual~NetworkSession();
void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client);
virtual void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box = 0);
void DetachClient(Oyster::Network::NetworkClient* client);
void DetachClient(ClientObject* client);
void DetachClient(short ID);
void DetachClient();
virtual Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(Oyster::Network::NetworkClient* client);
virtual Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(ClientObject* client);
virtual Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(short ID);
void Kick();
void Send(Oyster::Network::CustomNetProtocol& protocol);
void Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
virtual void Send(Oyster::Network::CustomNetProtocol& protocol);
virtual void Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
//TODO: Do more lobby features
//virtual void
virtual void SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box);
virtual void CloseSession(NetworkSession* clientDestination); //<! Closes the session and sends the clients to given sesison. If session is null, clients is kicked from server.
protected:
std::vector<Utility::DynamicMemory::SmartPointer<ClientObject>> clients;
Oyster::PostBox<DanBias::NetworkSession::NetEvent> box;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<ClientObject>> clients;
};
}//End namespace DanBias
#endif // !DANBIASSERVER_NETWORK_SESSION_H

View File

@ -1,185 +0,0 @@
#include "Camera.h"
Camera::Camera()
{
this->m_position = Oyster::Math::Float3(0, 50, 0);
this->mRight = Oyster::Math::Float3(1, 0, 0);
this->mUp = Oyster::Math::Float3(0, 1, 0);
this->mLook = Oyster::Math::Float3(0, 0, 1);
}
Camera::~Camera()
{
}
void Camera::SetPosition(const Oyster::Math::Float3& v)
{
this->m_position = v;
}
Oyster::Math::Float3 Camera::GetPosition()const
{
return this->m_position;
}
Oyster::Math::Float3 Camera::GetRight()const
{
return this->mRight;
}
Oyster::Math::Float3 Camera::GetUp()const
{
return this->mUp;
}
Oyster::Math::Float3 Camera::GetLook()const
{
return this->mLook;
}
float Camera::GetNearZ()const
{
return this->mNearZ;
}
float Camera::GetFarZ()const
{
return this->mFarZ;
}
float Camera::GetAspect()const
{
return this->mAspect;
}
Oyster::Math::Float3 Camera::CrossMatrix(const Oyster::Math::Float3& vector, const Oyster::Math::Float4x4& matrix)
{
Oyster::Math::Float3 vec;
vec.x = matrix.m11*vector.x + matrix.m12*vector.y + matrix.m13*vector.z;
vec.y = matrix.m21*vector.x + matrix.m22*vector.y + matrix.m23*vector.z;
vec.z = matrix.m31*vector.x + matrix.m32*vector.y + matrix.m33*vector.z;
return vec;
}
void Camera::SetLens(float fovY, float aspect, float zn, float zf)
{
this->mFovY = fovY;
this->mAspect = aspect;
this->mNearZ = zn;
this->mFarZ = zf;
float yScale = tan((Oyster::Math::pi*0.5f) - (mFovY*0.5f));
float xScale = yScale/this->mAspect;
mProj = Oyster::Math::Float4x4(xScale, 0, 0, 0,
0, yScale, 0, 0,
0, 0, zf/(zf-zn), 1,
0, 0, -zn*zf/(zf-zn), 0);
mProj.Transpose();
}
void Camera::LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp)
{
Oyster::Math::Float3 L;
L = target - pos;
L.Normalize();
Oyster::Math::Float3 R;
R = worldUp.Cross(L);
R.Normalize();
Oyster::Math::Float3 U;
U = L.Cross(R);
this->m_position = pos;
this->mLook = L;
this->mRight = R;
this->mUp = U;
}
Oyster::Math::Float4x4 Camera::View()const
{
return this->mView;
}
Oyster::Math::Float4x4 Camera::Proj()const
{
return this->mProj;
}
Oyster::Math::Float4x4 Camera::ViewsProj()const
{
Oyster::Math::Float4x4 M;
M = mView * mProj;
return M;
}
void Camera::Walk(float dist)
{
this->m_position += dist*this->mLook;
}
void Camera::Strafe(float dist)
{
this->m_position += dist*this->mRight;
}
void Camera::Pitch(float angle)
{
float radians = angle * 0.0174532925f;
Oyster::Math::Float4x4 R;
Oyster::Math3D::RotationMatrix(radians,-mRight,R);
this->mUp = CrossMatrix(this->mUp, R);
this->mLook = CrossMatrix(this->mLook, R);
}
void Camera::Yaw(float angle)
{
float radians = angle * 0.0174532925f;
Oyster::Math::Float4x4 R;
Oyster::Math::Float3 up(0,1,0);
Oyster::Math3D::RotationMatrix(radians,-up,R);
this->mRight = CrossMatrix(this->mRight, R);
this->mUp = CrossMatrix(mUp, R);
this->mLook = CrossMatrix(this->mLook, R);
}
void Camera::UpdateViewMatrix()
{
mLook.Normalize();
mUp = mLook.Cross(mRight);
mUp.Normalize();
mRight = mUp.Cross(mLook);
float x = -m_position.Dot(mRight);
float y = -m_position.Dot(mUp);
float z = -m_position.Dot(mLook);
mView.m11 = mRight.x;
mView.m21 = mRight.y;
mView.m31 = mRight.z;
mView.m41 = x;
mView.m12 = mUp.x;
mView.m22 = mUp.y;
mView.m32 = mUp.z;
mView.m42 = y;
mView.m13 = mLook.x;
mView.m23 = mLook.y;
mView.m33 = mLook.z;
mView.m43 = z;
mView.m14 = 0.0f;
mView.m24 = 0.0f;
mView.m34 = 0.0f;
mView.m44 = 1.0f;
mView.Transpose();
}

View File

@ -1,63 +0,0 @@
#ifndef CAMERA__H
#define CAMERA__H
#include "OysterMath.h"
class Camera
{
private:
Oyster::Math::Float3 m_position;
Oyster::Math::Float3 mRight;
Oyster::Math::Float3 mUp;
Oyster::Math::Float3 mLook;
float mNearZ;
float mFarZ;
float mAspect;
float mFovY;
Oyster::Math::Float4x4 mView;
Oyster::Math::Float4x4 mProj;
public:
Camera();
virtual ~Camera();
void SetPosition(const Oyster::Math::Float3& v);
Oyster::Math::Float3 GetPosition()const;
Oyster::Math::Float3 GetRight()const;
Oyster::Math::Float3 GetUp()const;
Oyster::Math::Float3 GetLook()const;
float GetNearZ()const;
float GetFarZ()const;
float GetAspect()const;
Oyster::Math::Float3 CrossMatrix(const Oyster::Math::Float3& v, const Oyster::Math::Float4x4& m);
void SetLens(float fovY, float aspect, float zn, float zf);
void LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp);
void setLook(Oyster::Math::Float3 look) { mLook = look; }
void setUp(Oyster::Math::Float3 up) { mUp = up; }
void setRight(Oyster::Math::Float3 right) { mRight = right; }
Oyster::Math::Float4x4 View()const;
Oyster::Math::Float4x4 Proj()const;
Oyster::Math::Float4x4 ViewsProj()const;
void Walk(float dist);
void Strafe(float dist);
void Pitch(float angle);
void Yaw(float angle);
void UpdateViewMatrix();
};
#endif

View File

@ -1,79 +0,0 @@
#include "Game.h"
using namespace GameLogic;
Game::Game(void)
{
player = NULL;
level = NULL;
camera = NULL;
}
Game::~Game(void)
{
//SAFE_DELETE(player);
if(player)
{
delete player;
player = NULL;
}
if(camera)
{
delete camera;
camera = NULL;
}
}
void Game::Init()
{
//Oyster::Physics::API::SetSubscription("remove object");
player = new Player(L"worldDummy");
box = new DynamicObject(L"crate");
//poi
//box = new physcTestObj("box");
camera = new Camera();
}
void Game::StartGame()
{
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1);
Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0);
Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 100);
camera->LookAt(pos, dir, up);
camera->SetLens(3.14f/2, 1024/768, 1, 1000);
}
void Game::Update(keyInput keyPressed, float pitch, float yaw)
{
//player->Update(keyPressed);
camera->Yaw(yaw);
camera->Pitch(pitch);
if(keyPressed == keyInput_A)
{
camera->Strafe(-0.1);
}
if(keyPressed == keyInput_D)
{
camera->Strafe(0.1);
}
if(keyPressed == keyInput_S)
{
camera->Walk(-0.1);
}
if(keyPressed == keyInput_W)
{
camera->Walk(0.1);
}
camera->UpdateViewMatrix();
//poi Oyster::Physics::API::Update();
}
void Game::Render()
{
Oyster::Graphics::API::SetView(camera->View());
Oyster::Graphics::API::SetProjection(camera->Proj());
Oyster::Graphics::API::NewFrame();
player->Render();
box->Render();
}

View File

@ -1,30 +0,0 @@
#ifndef GAME_H
#define GAME_H
#include "Level.h"
#include "Player.h"
#include "IGame.h"
#include "Camera.h"
#include "DynamicObject.h"
namespace GameLogic
{
class Game
{
public:
Game();
~Game();
void Init();
void StartGame();
void Update(keyInput keyPressed, float pitch, float yaw);
void Render();
private:
Level* level;
DynamicObject* box;
Player* player;
Camera* camera;
};
}
#endif

View File

@ -8,7 +8,6 @@
namespace GameLogic
{
class GameMode
{
public:

View File

@ -1,43 +0,0 @@
#include "IGame.h"
#include "Game.h"
#include <windows.h>
BOOL WINAPI DllMain(
_In_ HINSTANCE hinstDLL,
_In_ DWORD fdwReason,
_In_ LPVOID lpvReserved
)
{
return TRUE;
}
using namespace GameLogic;
IGame::IGame()
{
gameModule = new Game();
}
IGame::~IGame()
{
delete gameModule;
}
void IGame::Init()
{
gameModule->Init();
}
void IGame::StartGame()
{
gameModule->StartGame();
}
void IGame::Update(keyInput keyPressed, float pitch, float yaw)
{
gameModule->Update(keyPressed, pitch, yaw);
}
void IGame::Render()
{
gameModule->Render();
}
Game* IGame::getGameModule()
{
return gameModule;
}

View File

@ -1,47 +0,0 @@
//////////////////////////////////////////////////
//Created by Erik and Linda of the GameLogic team
//////////////////////////////////////////////////
#ifndef IGAME_H
#define IGAME_H
#if defined GAME_DLL_EXPORT
#define GAME_DLL_USAGE __declspec(dllexport)
#else
#define GAME_DLL_USAGE __declspec(dllimport)
#endif
namespace GameLogic
{
class Game;
enum keyInput
{
keyInput_W,
keyInput_A,
keyInput_S,
keyInput_D,
keyInput_none
};
class GAME_DLL_USAGE IGame
{
private:
Game* gameModule;
public:
IGame();
~IGame();
void Init();
void StartGame();
/************************************************************************/
/* Get key input to update the player */
/************************************************************************/
void Update(keyInput keyPressed, float pitch, float yaw);
void Render();
Game* getGameModule();
private:
};
}
#endif

View File

@ -1,6 +1,7 @@
#include "Object.h"
#include "OysterMath.h"
#include "CollisionManager.h"
#include "GID.h"
using namespace GameLogic;
@ -18,6 +19,7 @@ Object::Object()
rigidBody->gameObjectRef = this;
this->objectID = GID();
this->type = OBJECT_TYPE_UNKNOWN;
}
@ -34,6 +36,8 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
rigidBody->gameObjectRef = this;
this->objectID = GID();
this->type = type;
}
@ -48,6 +52,10 @@ OBJECT_TYPE Object::GetType()
{
return this->type;
}
int Object::GetID()
{
return this->objectID;
}
Oyster::Physics::ICustomBody* Object::GetRigidBody()
{

View File

@ -21,11 +21,13 @@ namespace GameLogic
~Object(void);
OBJECT_TYPE GetType();
int GetID();
Oyster::Physics::ICustomBody* GetRigidBody();
private:
OBJECT_TYPE type;
int objectID;
protected:
Oyster::Physics::ICustomBody *rigidBody;
};

View File

@ -1,47 +0,0 @@
#include "RefManager.h"
using namespace GameLogic;
typedef std::pair<const Oyster::Physics::ICustomBody*, Object*> mapData;
RefManager* RefManager::instance = 0;
RefManager::RefManager(void)
{
}
RefManager::~RefManager(void)
{
}
void RefManager::Release()
{
if (instance)
{
delete instance;
instance = NULL;
}
}
RefManager* RefManager::getInstance( )
{
if (!instance)
{
instance = new RefManager();
};
return instance;
}
Object* RefManager::GetMap(const Oyster::Physics::ICustomBody &body)
{
return mapper[&body];
}
void RefManager::AddMapping( const Oyster::Physics::ICustomBody &body, Object &obj)
{
mapper.insert(mapData(&body,&obj));
}

View File

@ -1,36 +0,0 @@
//////////////////////////////////////////////////
//Created by Erik and Linda of the GameLogic team
//////////////////////////////////////////////////
#ifndef REFMANAGER_H
#define REFMANAGER_H
#include<map>
#include "Object.h"
namespace GameLogic
{
class RefManager
{
public:
RefManager(void);
~RefManager(void);
static RefManager* getInstance( );
void Release();
Object* GetMap(const Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler
void AddMapping(const Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value
private:
static RefManager* instance;
std::map<const Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object
};
}
#endif

View File

@ -56,4 +56,6 @@ bool Team::AddPlayer(Player *player)
myData->players[myData->nrOfPlayers] = player;
myData->nrOfPlayers++;
}
return true;
}

View File

@ -1,304 +0,0 @@
//--------------------------------------------------------------------------------------
// File: TemplateMain.cpp
//
// BTH-D3D-Template
//
// Copyright (c) Stefan Petersson 2011. All rights reserved.
//--------------------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// Test main function for game logic when .exe
// Doesn't run when Game logic is compiled as a .dll
//////////////////////////////////////////////////////////////////////////
#define NOMINMAX
#include <Windows.h>
#include "Core/Core.h"
#include "DllInterfaces/GFXAPI.h"
#include "IGame.h"
#include "L_inputClass.h"
// debug window include
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <iostream>
//--------------------------------------------------------------------------------------
// Global Variables
//--------------------------------------------------------------------------------------
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
GameLogic::IGame *game;
InputClass *inputObj;
//--------------------------------------------------------------------------------------
// Forward declarations
//--------------------------------------------------------------------------------------
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow );
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HRESULT Render(float deltaTime);
HRESULT Update(float deltaTime);
HRESULT InitDirect3D();
HRESULT InitGame();
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 ) ) )
return 0;
if( FAILED( InitDirect3D() ) )
return 0;
if( FAILED( InitGame() ) )
return 0;
__int64 cntsPerSec = 0;
QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
float secsPerCnt = 1.0f / (float)cntsPerSec;
__int64 prevTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
//Init debug window
//SetStdOutToNewConsole();
// Main message loop
MSG msg = {0};
while(WM_QUIT != msg.message)
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
__int64 currTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;
//render
Update(dt);
Render(dt);
prevTimeStamp = currTimeStamp;
}
}
CleanUp();
return (int) msg.wParam;
}
//--------------------------------------------------------------------------------------
// Register class and create window
//--------------------------------------------------------------------------------------
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
{
// Register class
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"BTH_D3D_Template";
wcex.hIconSm = 0;
if( !RegisterClassEx(&wcex) )
return E_FAIL;
// Adjust and create window
g_hInst = hInstance;
RECT rc = { 0, 0, 1024, 768 };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
if(!(g_hWnd = CreateWindow(
L"BTH_D3D_Template",
L"BTH - Direct3D 11.0 Template",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rc.right - rc.left,
rc.bottom - rc.top,
NULL,
NULL,
hInstance,
NULL)))
{
return E_FAIL;
}
ShowWindow( g_hWnd, nCmdShow );
return S_OK;
}
//--------------------------------------------------------------------------------------
// Create Direct3D with Oyster Graphics
//--------------------------------------------------------------------------------------
HRESULT InitDirect3D()
{
if(Oyster::Graphics::API::Init(g_hWnd, false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess)
return E_FAIL;
return S_OK;
}
//--------------------------------------------------------------------------------------
// Init the input and the game
//-------------------------------------------------------------------------------------
HRESULT InitGame()
{
inputObj = new InputClass;
if(!inputObj->Initialize(g_hInst, g_hWnd, 1024, 768))
{
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
return false;
}
game = new GameLogic::IGame();
game->Init();
game->StartGame();
return S_OK;
}
HRESULT Update(float deltaTime)
{
inputObj->Update();
GameLogic::keyInput key = GameLogic::keyInput_none;
if(inputObj->IsKeyPressed(DIK_W))
{
key = GameLogic::keyInput_W;
}
else if(inputObj->IsKeyPressed(DIK_A))
{
key = GameLogic::keyInput_A;
}
else if(inputObj->IsKeyPressed(DIK_S))
{
key = GameLogic::keyInput_S;
}
else if(inputObj->IsKeyPressed(DIK_D))
{
key = GameLogic::keyInput_D;
}
float pitch = 0;
float yaw = 0;
// move only when mouse is pressed
//if(inputObj->IsMousePressed())
//{
pitch = inputObj->GetPitch();
yaw = inputObj->GetYaw();
//}
game->Update(key, pitch, yaw);
return S_OK;
}
HRESULT Render(float deltaTime)
{
int isPressed = 0;
if(inputObj->IsKeyPressed(DIK_A))
{
isPressed = 1;
//std::cout<<"test";
}
game->Render();
wchar_t title[255];
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
SetWindowText(g_hWnd, title);
Oyster::Graphics::API::EndFrame();
return S_OK;
}
HRESULT CleanUp()
{
SAFE_DELETE(game);
return S_OK;
}
//--------------------------------------------------------------------------------------
// Called every time the application receives a message
//--------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

View File

@ -0,0 +1,10 @@
#ifndef GAMEPROTOCOLS_GAMEPROTOCOLS_H
#define GAMEPROTOCOLS_GAMEPROTOCOLS_H
#include "ObjectProtocols.h"
#include "PlayerProtocols.h"
#include "ControlProtocols.h"
#include "TEST_PROTOCOLS.h"
#endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H

View File

@ -155,6 +155,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ControlProtocols.h" />
<ClInclude Include="GameProtocols.h" />
<ClInclude Include="ObjectProtocols.h" />
<ClInclude Include="PlayerProtocols.h" />
<ClInclude Include="ProtocolIdentificationID.h" />

View File

@ -1,5 +1,5 @@
#ifndef GAMELOGIC_PLAYER_PROTOCOLS_H
#define GAMELOGIC_PLAYER_PROTOCOLS_H
#ifndef GAMELOGIC_OBJECT_PROTOCOLS_H
#define GAMELOGIC_OBJECT_PROTOCOLS_H
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"

215
Code/Misc/DynamicArray.h Normal file
View File

@ -0,0 +1,215 @@
//////////////////////////////
// Dennis Andersen 2013 //
//////////////////////////////
#ifndef MISC_DYNAMIC_ARRAY_H
#define MISC_DYNAMIC_ARRAY_H
namespace Utility
{
namespace DynamicMemory
{
template <typename T>
class DynamicArray
{
public:
DynamicArray();
DynamicArray(unsigned int capacity);
DynamicArray(const DynamicArray& orig);
const DynamicArray& operator=(const DynamicArray& orig);
virtual~DynamicArray();
T& operator[](unsigned int index);
const T& operator[](unsigned int index) const;
void Push(const T& value);
void Push(unsigned int index, const T& value);
T& PopFront();
T& PopBack();
T& Pop(unsigned int index);
void Remove(unsigned int index);
void Remove(unsigned int first, unsigned int last);
void Clear();
void Expand(int elements = 0);
unsigned int Size() const;
unsigned int Capacity() const;
private:
T* data;
int size;
int capacity;
};
#pragma region Implementation
template <typename T> DynamicArray<T>::DynamicArray()
: data(0)
, size(0)
, capacity(0)
{ }
template <typename T> DynamicArray<T>::DynamicArray(unsigned int capacity)
: size(capacity)
, capacity(capacity)
, data(new T[capacity])
{ }
template <typename T> DynamicArray<T>::DynamicArray(const DynamicArray& orig)
: capacity(orig.capacity)
, size(orig.size)
{
this->data = new T[orig.capacity];
for (int i = 0; i < orig.size; i++)
{
this->data[i] = orig.data[i];
}
}
template <typename T> const DynamicArray<T>& DynamicArray<T>::operator=(const DynamicArray& orig)
{
if(this->data)
{
delete [] this->data;
}
this->capacity = orig.capacity;
this->size = orig.size;
if(orig.capacity > 0)
{
this->data = new T[orig.capacity];
for (int i = 0; i < orig.size; i++)
{
this->data[i] = orig.data[i];
}
}
return *this;
}
template <typename T> DynamicArray<T>::~DynamicArray()
{
Clear();
}
template <typename T> T& DynamicArray<T>::operator[](unsigned int index)
{
assert((int)index < this->size);
return this->data[index];
}
template <typename T> const T& DynamicArray<T>::operator[](unsigned int index) const
{
assert(index < this->size);
return this->data[index];
}
template <typename T> void DynamicArray<T>::Push(const T& value)
{
Expand(1);
this->data[this->size] = value;
this->size ++;
}
template <typename T> void DynamicArray<T>::Push(unsigned int index, const T& value)
{
int newElem = 1;
if((int)index >= this->size)
newElem = (index + 1) - this->size;
Expand(newElem);
this->data[index] = value;
this->size += newElem;
}
template <typename T> T& DynamicArray<T>::PopFront()
{
return Pop(0);
}
template <typename T> T& DynamicArray<T>::PopBack()
{
return Pop(this->size-1);
}
template <typename T> T& DynamicArray<T>::Pop(unsigned int index)
{
assert((int)index < this->size);
T* temp = new T[this->capacity];
for (int i = 0; i < this->size; i++)
{
if(i != index) temp[i] = this->data[i];
}
delete [] this->data;
this->data = temp;
this->size--;
return this->data[index];
}
template <typename T> void DynamicArray<T>::Remove(unsigned int index)
{
assert(index > this->size);
T* temp = new T[this->capacity - 1];
for (int i = 0; i < this->size; i++)
{
if(i != index) temp[i] = this->data[i];
}
delete [] this->data;
this->data = temp;
this->size--;
}
template <typename T> void DynamicArray<T>::Clear()
{
delete [] this->data;
this->data = 0;
this->size = 0;
this->capacity = 0;
}
template <typename T> void DynamicArray<T>::Expand(int elements)
{
int newSize = this->size + elements;
if(newSize >= this->capacity)
{
T* temp = new T[newSize];
for (int i = 0; i < this->size; i++)
{
temp[i] = this->data[i];
}
this->capacity = newSize;
delete [] this->data;
this->data = temp;
}
}
template <typename T> unsigned int DynamicArray<T>::Size() const
{
return (unsigned int)this->size;
}
template <typename T> unsigned int DynamicArray<T>::Capacity() const
{
return (unsigned int)this->capacity;
}
#pragma endregion
}
}
#endif

29
Code/Misc/GID.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef GID_H
#define GID_H
#include <vector>
/**
* This class only purpos is to generate a uniqe global id, nothing else..
*/
class GID
{
private:
int id;
int usft() { static int ID = 0; return ID++; }
public:
GID::GID() { this->id = usft(); }
GID::~GID() { }
GID(const GID& o) { this->id = usft(); }
const GID& operator=(const GID& o) { this->id = usft(); return *this; }
operator int() const { return this->id; }
bool operator == (const GID& object) const { return (this->id == object.id); }
bool operator == (const int& id) const { return (this->id == id); }
int get() const { return this->id; }
};
#endif

View File

@ -156,7 +156,10 @@
<ClCompile Include="WinTimer.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DynamicArray.h" />
<ClInclude Include="GID.h" />
<ClInclude Include="IQueue.h" />
<ClInclude Include="OysterCallback.h" />
<ClInclude Include="PostBox\IPostBox.h" />
<ClInclude Include="PostBox\PostBox.h" />
<ClInclude Include="Resource\OysterResource.h" />

View File

@ -92,5 +92,14 @@
<ClInclude Include="PostBox\IPostBox.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DynamicArray.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GID.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OysterCallback.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,47 @@
//////////////////////////////
// Dennis Andersen 2013 //
//////////////////////////////
#ifndef MISC_OYSTER_CALLBACK_H
#define MISC_OYSTER_CALLBACK_H
#include "PostBox\IPostBox.h"
namespace Oyster
{
namespace Callback
{
template <typename ReturnVal = void, typename ParamVal = void>
struct CallbackFunction
{
typedef ReturnVal (*FNC)(ParamVal);
};
template <typename ReturnVal = void, typename ParamVal = void>
struct CallbackObject
{
virtual ReturnVal ObjectCallback(ParamVal) = 0;
};
enum CallbackType
{
CallbackType_PostBox,
CallbackType_Function,
CallbackType_Object,
};
template <typename ReturnVal = void, typename ParamVal = void>
union OysterCallback
{
IPostBox<ParamVal>* callbackPostBox;
CallbackObject<ReturnVal, ParamVal> *callbackObject;
typename CallbackFunction<ReturnVal, ParamVal>::FNC callbackFunction;
OysterCallback() { memset(this, 0, sizeof(OysterCallback)); }
OysterCallback(IPostBox<ReturnVal>* postbox) { callbackPostBox = postbox; }
OysterCallback(CallbackObject<ReturnVal, ParamVal>* obj) { callbackObject = obj; }
OysterCallback(typename CallbackFunction<ReturnVal, ParamVal>::FNC function) { callbackFunction = function; }
};
}
}
#endif