GameServer - Added more protocols and modified old ones a bit. Also added a new project that starts both server and client

This commit is contained in:
Dennis Andersen 2014-01-21 09:52:48 +01:00
parent 0a41d20099
commit f7f59e8ac8
24 changed files with 958 additions and 539 deletions

View File

@ -44,6 +44,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameProtocols", "Game\GameP
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServerLauncher", "Game\DanBiasServerLauncher\DanBiasServerLauncher.vcxproj", "{060B1890-CBF3-4808-BA99-A4776222093B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
@ -270,6 +272,18 @@ Global
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|Win32.Build.0 = Release|Win32
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.ActiveCfg = Release|x64
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.Build.0 = Release|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -285,5 +299,6 @@ Global
{8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{060B1890-CBF3-4808-BA99-A4776222093B} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A}
EndGlobalSection
EndGlobal

View File

@ -26,7 +26,7 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
}
}
break;
case protocol_Gameplay_PlayerNavigation:
case protocol_Gameplay_PlayerMovement:
{
Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput;
for(int i = 0; i< 6; i++)
@ -40,21 +40,21 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
protocolData = NULL;
}
break;
case protocol_Gameplay_PlayerPosition:
{
Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos;
for(int i = 0; i< 3; i++)
{
protocolData->playerPos[i] = p[i].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
//case protocol_Gameplay_PlayerPosition:
// {
// Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos;
// for(int i = 0; i< 3; i++)
// {
// protocolData->playerPos[i] = p[i].value.netFloat;
// }
// if(dynamic_cast<Client::GameState*>(gameClientState))
// ((Client::GameState*)gameClientState)->Protocol(protocolData);
// delete protocolData;
// protocolData = NULL;
// }
// break;
case protocol_Gameplay_CreateObject:
case protocol_Gameplay_ObjectCreate:
{
Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj;
protocolData->object_ID = p[1].value.netInt;
@ -72,7 +72,7 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
protocolData = NULL;
}
break;
case protocol_Gameplay_RemoveObject:
case protocol_Gameplay_ObjectDisabled:
{
Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj;
protocolData->object_ID = p[1].value.netInt;

View File

@ -131,10 +131,8 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
GameLogic::Protocol_PlayerMovement movePlayer;
movePlayer.bForward = false;
movePlayer.bBackward = false;
movePlayer.bStrafeLeft = false;
movePlayer.bStrafeRight = false;
movePlayer.bTurnLeft = false;
movePlayer.bTurnRight = false;
movePlayer.bLeft = false;
movePlayer.bRight = false;
if(KeyInput->IsKeyPressed(DIK_W))
{
@ -165,7 +163,7 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
{
if(!key_strafeLeft)
{
movePlayer.bStrafeLeft = true;
movePlayer.bLeft = true;
send = true;
key_strafeLeft = true;
}
@ -177,7 +175,7 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
{
if(!key_strafeRight)
{
movePlayer.bStrafeRight = true;
movePlayer.bRight = true;
send = true;
key_strafeRight = true;
}
@ -221,7 +219,7 @@ bool GameState::Render()
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection(privData->proj);
Oyster::Graphics::API::NewFrame();
for (int i = 0; i < privData->object.size(); i++)
for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Render();
}
@ -230,7 +228,7 @@ bool GameState::Render()
}
bool GameState::Release()
{
for (int i = 0; i < privData->object.size(); i++)
for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Release();
delete privData->object[i];
@ -305,7 +303,7 @@ void GameState::Protocol( NewObj* newObj )
void DanBias::Client::GameState::Protocol( RemoveObj* obj )
{
for (int i = 0; i < privData->object.size(); i++)
for (unsigned int i = 0; i < privData->object.size(); i++)
{
if(privData->object[i]->GetId() == obj->object_ID)
{

View File

@ -42,34 +42,28 @@ namespace DanBias
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
case protocol_Gameplay_PlayerMovement:
{
//Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity;
if(p[1].value.netBool) //bool bForward;
//world.v[3].x = 2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
//world.v[3].x = -2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
//world.v[3].y = 2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
//world.v[3].y = -2;
if(p[3].value.netBool) //bool bStrafeLeft;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
if(p[4].value.netBool) //bool bStrafeRight;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
}
break;
case protocol_Gameplay_PlayerMouseMovement:
{
Protocol_PlayerMouse m; m = p;
c->GetPlayer()->Rotate(m.dxMouse, m.dyMouse);
}
break;
case protocol_Gameplay_PlayerChangeWeapon:
break;
case protocol_Gameplay_PlayerPosition:
break;
case protocol_Gameplay_CreateObject:
break;
case protocol_Gameplay_ObjectPosition:
case protocol_Gameplay_PlayerDamage:
break;
}
@ -110,11 +104,9 @@ namespace DanBias
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
{
//if (movedObject->)
//{
//
//}
//movedObject->GetOrientation();
movedObject->GetID();
movedObject->GetOrientation();
}
}//End namespace DanBias

View File

@ -67,7 +67,6 @@ namespace DanBias
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
Protocol_ObjectPosition p(world, 1);
Send(p.GetProtocol());
//Sleep(100);
}
}

View File

@ -151,9 +151,9 @@ float Game::GetFrameTime() const
void Game::PhysicsOnMove(const ICustomBody *object)
{
IObjectData* temp = 0;
//IObjectData* temp = ((IObjectData*)object->GetDataTag());
if(gameInstance.onMoveFnc) gameInstance.onMoveFnc(temp);
IObjectData* temp = (IObjectData*)object->GetCustomTag();
if(gameInstance.onMoveFnc && temp) gameInstance.onMoveFnc(temp);
}
void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer<ICustomBody> proto)
{

View File

@ -39,6 +39,8 @@ namespace GameLogic
Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override;
OBJECT_TYPE GetObjectType() const override;
void Rotate(const float x, const float y) override;
Player *player;
};

View File

@ -75,6 +75,12 @@ namespace GameLogic
********************************************************/
virtual void Move(const PLAYER_MOVEMENT &movement) = 0;
/** Relative rotation around given axis
* @param x: The relative x axis
* @param y: The relative y axis
**/
virtual void Rotate(const float x, const float y) = 0;
/********************************************************
* Uses the chosen players weapon based on input
* @param Usage: enum value on what kind of action is to be taken

View File

@ -6,6 +6,7 @@ using namespace GameLogic;
Game::PlayerData::PlayerData()
{
this->player = new Player();
this->player->GetRigidBody()->SetCustomTag(this);
}
Game::PlayerData::PlayerData(int playerID,int teamID)
{
@ -48,3 +49,7 @@ OBJECT_TYPE Game::PlayerData::GetObjectType() const
{
return this->player->GetType();
}
void Game::PlayerData::Rotate(const float x, const float y)
{
this->player->Rotate(x, y);
}

View File

@ -88,6 +88,11 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint)
this->lookDir = Oyster::Math::Float4(1,0,0);
}
void Player::Rotate(float x, float y)
{
this->setState.AddRotation(Oyster::Math::Float4(x, y));
}
void Player::Jump()
{

View File

@ -41,6 +41,7 @@ namespace GameLogic
********************************************************/
void Respawn(Oyster::Math::Float3 spawnPoint);
void Rotate(float x, float y);
bool IsWalking();
bool IsJumping();

View File

@ -5,9 +5,128 @@
#include "ProtocolIdentificationID.h"
namespace GameLogic
{
struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject
{
int object_ID;
float worldMatrix[16];
// look at dir
Protocol_ObjectPosition()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = -1;
memset(&worldMatrix[0], 0, sizeof(float) * 16);
}
Protocol_ObjectPosition(float m[16], int id)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = id;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].value = worldMatrix[i-2];
}
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_ObjectEnable :public Oyster::Network::CustomProtocolObject
{
int object_ID;
float worldMatrix[16];
// look at dir
Protocol_ObjectEnable()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = -1;
memset(&worldMatrix[0], 0, sizeof(float) * 16);
}
Protocol_ObjectEnable(float m[16], int id)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (int i = 2; i <= 17; i++)
{ this->protocol[i].type = Oyster::Network::NetAttributeType_Float; }
object_ID = id;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].value = worldMatrix[i-2];
}
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_ObjectDisable :public Oyster::Network::CustomProtocolObject
{
int object_ID;
float timer;
Protocol_ObjectDisable()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDisabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
this->protocol[2].value = timer;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_CreateObject :public Oyster::Network::CustomProtocolObject
{
int object_ID;
@ -17,7 +136,7 @@ namespace GameLogic
Protocol_CreateObject()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_CreateObject;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -30,7 +149,7 @@ namespace GameLogic
}
Protocol_CreateObject(float m[16], int id, char *path)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_CreateObject;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -70,77 +189,6 @@ namespace GameLogic
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject
{
int object_ID;
float worldMatrix[16];
// look at dir
Protocol_ObjectPosition()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = -1;
memset(&worldMatrix[0], 0, sizeof(float) * 16);
}
Protocol_ObjectPosition(float m[16], int id)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = id;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].value = worldMatrix[i-2];
}
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_RemoveObject :public Oyster::Network::CustomProtocolObject
{
int object_ID;
Protocol_RemoveObject()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_RemoveObject;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
return &protocol;
}

View File

@ -10,7 +10,6 @@
#include "ProtocolIdentificationID.h"
namespace GameLogic
{
struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject
@ -18,31 +17,25 @@ namespace GameLogic
bool bForward;
bool bBackward;
bool bTurnLeft;
bool bTurnRight;
bool bStrafeRight;
bool bStrafeLeft;
bool bLeft;
bool bRight;
Protocol_PlayerMovement()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerNavigation;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerMovement;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[2].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[4].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[5].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[6].type = Oyster::Network::NetAttributeType_Bool;
}
const Protocol_PlayerMovement& operator=(Oyster::Network::CustomNetProtocol& val)
{
bForward = val[1].value.netBool;
bBackward = val[2].value.netBool;
bTurnLeft = val[3].value.netBool;
bTurnRight = val[4].value.netBool;
bStrafeRight = val[5].value.netBool;
bStrafeLeft = val[6].value.netBool;
bLeft = val[3].value.netBool;
bRight = val[4].value.netBool;
return *this;
}
@ -50,10 +43,8 @@ namespace GameLogic
{
this->protocol[1].value = bForward;
this->protocol[2].value = bBackward;
this->protocol[3].value = bTurnLeft;
this->protocol[4].value = bTurnRight;
this->protocol[5].value = bStrafeRight;
this->protocol[6].value = bStrafeLeft;
this->protocol[3].value = bLeft;
this->protocol[4].value = bRight;
return &protocol;
}
@ -97,15 +88,14 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_PlayerPosition :public Oyster::Network::CustomProtocolObject
struct Protocol_PlayerChangeWeapon :public Oyster::Network::CustomProtocolObject
{
float position[3];
// look at dir
int ID;
Protocol_PlayerPosition()
Protocol_PlayerChangeWeapon()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerPosition;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerChangeWeapon;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
@ -113,19 +103,69 @@ namespace GameLogic
this->protocol[3].type = Oyster::Network::NetAttributeType_Float;
}
const Protocol_PlayerPosition& operator=(Oyster::Network::CustomNetProtocol& val)
const Protocol_PlayerChangeWeapon& operator=(Oyster::Network::CustomNetProtocol& val)
{
position[0] = val[1].value.netFloat;
position[1] = val[2].value.netFloat;
position[2] = val[3].value.netFloat;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_PlayerDamage :public Oyster::Network::CustomProtocolObject
{
int hp;
// look at dir
Protocol_PlayerDamage()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerDamage;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
}
const Protocol_PlayerDamage& operator=(Oyster::Network::CustomNetProtocol& val)
{
hp = val[1].value.netInt;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value =hp;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_PlayerPickup :public Oyster::Network::CustomProtocolObject
{
int pickupID;
Protocol_PlayerPickup()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerPickup;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
}
const Protocol_PlayerPickup& operator=(Oyster::Network::CustomNetProtocol& val)
{
pickupID = val[3].value.netInt;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = position[0];
this->protocol[2].value = position[1];
this->protocol[3].value = position[2];
this->protocol[3].value = pickupID;
return &protocol;
}

View File

@ -45,13 +45,16 @@
/********* GAMEPLAY PROTOCOLS ***************************************************************************************************/
/***********[ 300 - 400 ]***********/
#define protocol_GameplayMIN 300
#define protocol_Gameplay_PlayerNavigation 300
#define protocol_Gameplay_PlayerMovement 300
#define protocol_Gameplay_PlayerMouseMovement 301
#define protocol_Gameplay_PlayerPosition 302
#define protocol_Gameplay_CreateObject 303
#define protocol_Gameplay_RemoveObject 304
#define protocol_Gameplay_PlayerChangeWeapon 302
#define protocol_Gameplay_PlayerDamage 303
#define protocol_Gameplay_PlayerPickup 304
#define protocol_Gameplay_ObjectPosition 305
#define protocol_Gameplay_Initiate 306
#define protocol_Gameplay_ObjectEnabled 306
#define protocol_Gameplay_ObjectDisabled 307
#define protocol_Gameplay_ObjectCreate 308
#define protocol_Gameplay_Initiate 309
#define protocol_GameplayMAX 399

View File

@ -0,0 +1,62 @@
#define NOMINMAX
#include <Windows.h>
#include <vld.h>
#include "DanBiasGame.h"
#include <DanBiasServerAPI.h>
#include <thread>
void ServerFnc()
{
if( DanBias::DanBiasServerAPI::Initiate() == DanBias::DanBiasServerReturn_Sucess)
{
DanBias::DanBiasServerAPI::Run();
DanBias::DanBiasServerAPI::Release();
}
Sleep(100);
}
void ClientFnc()
{
// Game client starter code goes here
DanBias::DanBiasGameDesc gameDesc;
gameDesc.port = 15151;
//gameDesc.port = 15152;
//gameDesc.IP = "193.11.184.196";
//gameDesc.IP = "193.11.184.31";
//gameDesc.IP = "194.47.150.56";
gameDesc.IP = "127.0.0.1";
if( DanBias::DanBiasGame::Initiate(gameDesc) == DanBias::DanBiasClientReturn_Sucess)
{
DanBias::DanBiasGame::Run();
DanBias::DanBiasGame::Release();
}
Sleep(100);
}
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)
{
std::thread serverThread;
std::thread clientThread;
if(SetDllDirectory(L"..\\DLL") == FALSE)
{
return cmdShow;
}
serverThread = std::thread(ServerFnc);
Sleep(100);
clientThread = std::thread(ClientFnc);
if (serverThread.joinable()) serverThread.join();
if (clientThread.joinable()) clientThread.join();
return cmdShow;
}

View File

@ -0,0 +1,187 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{666FEA52-975F-41CD-B224-B19AF3C0ABBA}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>aDanBiasGameLauncher</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Launcher.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DanBiasGame\DanBiasGame.vcxproj">
<Project>{2a1bc987-af42-4500-802d-89cd32fc1309}</Project>
</ProjectReference>
<ProjectReference Include="..\DanBiasServer\DanBiasServer.vcxproj">
<Project>{52380daa-0f4a-4d97-8e57-98df39319caf}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -35,6 +35,8 @@ namespace Utility
void Resize(unsigned int size);
void Reserve(unsigned int size);
void Swap(unsigned int a, unsigned int b);
unsigned int Size() const;
@ -201,6 +203,11 @@ namespace Utility
this->data = temp;
}
template <typename T> void DynamicArray<T>::Reserve(unsigned int size)
{
Expand(size);
}
template <typename T> void DynamicArray<T>::Swap(unsigned int a, unsigned int b)
{
T temp = this->data[a];

View File

@ -0,0 +1,247 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "ResourceManager.h"
using namespace Oyster::Resource;
struct Oyster::Resource::ResourceData
{
}
ResourceData* FindResource(std::map<std::wstring, ResourceData*> resources, const HRESOURCE& h) const
{
for (auto i = resources.begin(); i != resources.end() ; i++)
{
if(i->second->GetResourceHandle() == h)
{
return i->second;
}
}
return 0;
}
ResourceData* FindResource(std::map<std::wstring, ResourceData*> resources, const wchar_t c[]) const
{
std::wstring temp = c;
auto t = this->resources.find(c);
if(t == this->resources.end()) return 0;
return t->second;
}
void SaveResource( std::map<std::wstring, ResourceData*> resources, OResource* r, bool addNew )
{
if(!r) return;
if(addNew)
{
this->resources[r->GetResourceFilename()] = r;
}
r->resourceRef.Incref();
}
ResourceManager::ResourceManager()
{
}
ResourceManager::
HRESOURCE OysterResource::LoadResource(const wchar_t* filename, ResourceType type, int customID, bool force)
{
if(!filename) return 0;
OResource *resourceData = FindResource(filename);
if(resourceData)
{
if(force)
{
return OysterResource::ReloadResource(filename);
}
else
{
//Add new reference
resourcePrivate.SaveResource(resourceData, false);
return resourceData->GetResourceHandle();
}
}
else
{
resourceData = OResource::Load(filename, type);
if(resourceData)
{
resourceData->SetResourceID(customID);
resourcePrivate.SaveResource(resourceData);
}
}
return resourceData->GetResourceHandle();
}
HRESOURCE OysterResource::LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc, int customId, bool force)
{
if(!filename)
{
return 0;
}
if(!loadFnc)
{
return 0;
}
OResource *resourceData = resourcePrivate.FindResource(filename);
if(resourceData)
{
if(force)
{
return OysterResource::ReloadResource(filename);
}
else
{
//Add new reference
resourcePrivate.SaveResource(resourceData, false);
return resourceData->GetResourceHandle();
}
}
else
{
resourceData = OResource::Load(filename, loadFnc);
if(resourceData)
{
resourceData->SetResourceID(customId);
resourcePrivate.SaveResource(resourceData);
}
}
if(!resourceData)
{
return 0;
}
return (OHRESOURCE)resourceData->GetResourceHandle();
}
OHRESOURCE OysterResource::ReloadResource(const wchar_t filename[])
{
OResource *resourceData = resourcePrivate.FindResource(filename);
if(!resourceData) return 0; //The resource has not been loaded
return OResource::Reload(resourceData)->GetResourceHandle();
}
OHRESOURCE OysterResource::ReloadResource(OHRESOURCE resource)
{
OResource *resourceData = resourcePrivate.FindResource(resource);
if(!resourceData) return 0; //The resource has not been loaded
return OResource::Reload(resourceData)->GetResourceHandle();
}
void OysterResource::Clean()
{
auto i = resourcePrivate.resources.begin();
auto last = resourcePrivate.resources.end();
for (i; i != last; i++)
{
//Remove all the references
while (!OResource::Release(i->second));
std::wstring temp = i->second->GetResourceFilename();
delete resourcePrivate.resources[temp];
}
resourcePrivate.resources.clear();
}
void OysterResource::ReleaseResource(const OHRESOURCE& resourceData)
{
OResource* t = resourcePrivate.FindResource(resourceData);
if(t)
{
if(OResource::Release(t))
{
std::wstring temp = t->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}
}
}
void OysterResource::ReleaseResource(const wchar_t filename[])
{
OResource* t = resourcePrivate.FindResource(filename);
if(t)
{
if(OResource::Release(t))
{
std::wstring temp = t->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}
}
}
void OysterResource::SetResourceId (const OHRESOURCE& resourceData, unsigned int id)
{
OResource* t = resourcePrivate.FindResource(resourceData);
if(t) t->SetResourceID(id);
}
void OysterResource::SetResourceId(const wchar_t c[], unsigned int id)
{
OResource* t = resourcePrivate.FindResource(c);
if(t) t->SetResourceID(id);
}
ResourceType OysterResource::GetResourceType (const OHRESOURCE& resourceData)
{
OResource* t = resourcePrivate.FindResource(resourceData);
if(t) return t->GetResourceType();
return ResourceType_INVALID;
}
ResourceType OysterResource::GetResourceType (const wchar_t c[])
{
OResource* t = resourcePrivate.FindResource(c);
if(t) return t->GetResourceType();
return ResourceType_INVALID;
}
const wchar_t* OysterResource::GetResourceFilename (const OHRESOURCE& resourceData)
{
OResource* t = resourcePrivate.FindResource(resourceData);
if(t) return t->GetResourceFilename();
return 0;
}
OHRESOURCE OysterResource::GetResourceHandle(const wchar_t filename[])
{
OResource* t = resourcePrivate.FindResource(filename);
if(t) return t->GetResourceHandle();
return 0;
}
int OysterResource::GetResourceId (const OHRESOURCE& resourceData)
{
OResource* t = resourcePrivate.FindResource(resourceData);
if(t) return t->GetResourceID();
return -1;
}
int OysterResource::GetResourceId(const wchar_t c[])
{
OResource* t = resourcePrivate.FindResource(c);
if(t) return t->GetResourceID();
return -1;
}

View File

@ -0,0 +1,160 @@
#ifndef MISC_RESOURCELOADER_H
#define MISC_RESOURCELOADER_H
#include <string>
#include <map>
namespace Oyster
{
namespace Resource
{
struct ResourceData;
typedef void* HRESOURCE;
/** Typedef on a fuction required for custom unloading */
typedef void(*UnloadFunction)(void* loadedData);
/** Typedef on a fuction required for custom loading */
typedef void*(*LoadFunction)(const wchar_t filename[]);
/** An enum class representing all avalible resources that is supported. */
enum ResourceType
{
//Byte
ResourceType_Byte_Raw, /**< Handle can be interpeted as char[] or char* */
ResourceType_Byte_ANSI, /**< Handle can be interpeted as char[] or char* */
ResourceType_Byte_UTF8, /**< Handle can be interpeted as char[] or char* */
ResourceType_Byte_UNICODE, /**< Handle can be interpeted as char[] or char* */
ResourceType_Byte_UTF16LE, /**< Handle can be interpeted as char[] or char* */
ResourceType_COUNT, /**< Handle can be interpeted as ? */
ResourceType_UNKNOWN = -1, /**< Handle can be interpeted as void* */
ResourceType_INVALID = -2, /**< Invalid or non existing resource */
};
/** A resource handler interface to interact with when loading resources.
* The resource handler uses the filename to make resources unuiqe.
*/
class ResourceManager
{
public:
ResourceManager();
~ResourceManager();
ResourceManager(const ResourceManager&) = delete;
const ResourceManager& operator=(const ResourceManager&) = delete;
/**
* Load a resource given a type.
* @param filename The path to the resource.
* @param customId An optional custom ID to associate with the resource.
* @param type The resource type to load.
* @param force If set to true, the resource will be reloaded if it already exists. If it does not, nothing happens.
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
*/
char* LoadBytes(const wchar_t filename[], ResourceType type, int customId = -1, bool force = false);
/**
* Load a resource with a custom loading function
* @param filename The path to the resource.
* @param loadFnc The function that will load the data.
* @param unloadFnc The function that will unload the loaded data.
* @param customId An optional custom ID to associate with the resource.
* @param force If set to true, the resource will be removed and loaded if exists.
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
*/
HRESOURCE LoadResource(const wchar_t filename[], LoadFunction loadFnc = 0, UnloadFunction unloadFnc = 0, int customId = -1, bool force = false);
/**
* Reload a resource
* @param filename The path to the resource.
* @return If function suceeds, the return value is true.
*/
bool ReloadResource(const wchar_t filename[]);
/**
* Reload a resource
* @param filename The path to the resource.
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
*/
bool ReloadResource(HRESOURCE resource);
/**
* Releases all resources loaded by the resource handler.
* @return Nothing
*/
void Clean();
/**
* Release a reference to the resource handle
* @param resource The handle to release.
* @return Nothing
*/
void ReleaseResource(const HRESOURCE& resource);
/**
* Release a reference to the resource handle
* @param resource The resource filename to release reference.
* @return Nothing
*/
void ReleaseResource(const wchar_t filename[]);
/** Set a user defined ID
* @param resource A handle to accociate the id with.
* @param id A user defined identifier that the resource handler does not touch.
*/
void SetResourceId(const HRESOURCE& resource, unsigned int id);
/** Set a user defined ID
* If the resource is not loaded the id will not be set.
* @param resource A filename to accociate the id with.
* @param id A user defined identifier that the resource handler does not touch.
*/
void SetResourceId(const wchar_t filename[], unsigned int id);
/** Get a resource type given a OHRESOURCE handle
* @param resource The handle to check
* @return Returns the resource type of the handle
*/
ResourceType GetResourceType(const HRESOURCE& resource);
/** Get a resource type given a filename
* If the resource is not loaded the id will not be set.
* @param resource The filename to check
* @return Returns the resource type of the handle
*/
ResourceType GetResourceType (const wchar_t filename[]);
/** Get a resource filename given a OHRESOURCE handle
* @param resource The handle to check
* @return Returns the accociated filename
*/
const wchar_t* GetResourceFilename(const HRESOURCE& resource);
/** Get a resource handle given a filename
* If the resource is not loaded function returns 0.
* @param resource The filename to check
* @return Returns the accociated handle
*/
HRESOURCE GetResourceHandle(const wchar_t filename[]);
/** Get a user defined ID accociated with a handle
* @param resource The handle to check
* @return Returns the accociated ID
*/
int GetResourceId(const HRESOURCE& resource);
/** Get a user defined ID accociated with a filename
* @param resource The filename to check
* @return Returns the accociated ID
*/
int GetResourceId(const wchar_t filename[]);
private:
std::map<std::wstring, ResourceData*> resources;
};
}
}
#endif // !MISC_RESOURCELOADER_H

View File

@ -1,253 +0,0 @@
//--------------------------------------------------------------------------------------
// File: TemplateMain.cpp
//
// BTH-D3D-Template
//
// Copyright (c) Stefan Petersson 2011. All rights reserved.
//--------------------------------------------------------------------------------------
#define NOMINMAX
#include <vld.h>
#include <Windows.h>
#include "DllInterfaces\GFXAPI.h"
//--------------------------------------------------------------------------------------
// Global Variables
//--------------------------------------------------------------------------------------
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
Oyster::Graphics::Model::Model* m = NULL;
Oyster::Graphics::Model::Model* m2 = NULL;
Oyster::Graphics::Model::Model* m3 = NULL;
Oyster::Math::Float4x4 V;
Oyster::Math::Float4x4 P;
//--------------------------------------------------------------------------------------
// 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();
//--------------------------------------------------------------------------------------
// Entry point to the program. Initializes everything and goes into a message processing
// loop. Idle time is used to render the scene.
//--------------------------------------------------------------------------------------
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
BOOL b = SetDllDirectoryW(L"..\\DLL");
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
return 0;
if( FAILED( InitDirect3D() ) )
return 0;
__int64 cntsPerSec = 0;
QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
float secsPerCnt = 1.0f / (float)cntsPerSec;
__int64 prevTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
std::string fps = "FPS:";
char count[100];
// Main message loop
MSG msg = {0};
float fpsCounter = 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);
fpsCounter += dt;
if(fpsCounter>0.1f)
{
sprintf_s(count, "%f",1/dt);
SetWindowTextA(g_hWnd, (fps + count).c_str());
fpsCounter = 0;
}
prevTimeStamp = currTimeStamp;
}
}
Oyster::Graphics::API::DeleteModel(m);
Oyster::Graphics::API::DeleteModel(m2);
Oyster::Graphics::API::DeleteModel(m3);
Oyster::Graphics::API::Clean();
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 device and swap chain
//--------------------------------------------------------------------------------------
HRESULT InitDirect3D()
{
HRESULT hr = S_OK;;
if(Oyster::Graphics::API::Init(g_hWnd,false,false, Oyster::Math::Float2( 1024, 768 )) == Oyster::Graphics::API::Fail)
{
return E_FAIL;
}
m = Oyster::Graphics::API::CreateModel(L"cube_tri.dan");
m2 = Oyster::Graphics::API::CreateModel(L"cube_tri.dan");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
m3 = Oyster::Graphics::API::CreateModel(L"cube_tri.dan");
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,100);
Oyster::Graphics::API::SetProjection(P);
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,15.4f));
V = V.GetInverse();
Oyster::Graphics::Definitions::Pointlight pl;
pl.Color = Oyster::Math::Float3(1,1,1);
pl.Bright = 1;
pl.Pos = Oyster::Math::Float3(0,5,5.4f);
pl.Radius = 15;
Oyster::Graphics::API::AddLight(pl);
return S_OK;
}
float angle = 0;
HRESULT Update(float deltaTime)
{
angle += Oyster::Math::pi/8 * deltaTime;
m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-angle,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null);
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null);
return S_OK;
}
HRESULT Render(float deltaTime)
{
Oyster::Graphics::API::SetView(V);
Oyster::Graphics::API::NewFrame();
Oyster::Graphics::API::RenderModel(*m);
Oyster::Graphics::API::RenderModel(*m2);
Oyster::Graphics::API::RenderModel(*m3);
Oyster::Graphics::API::EndFrame();
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;
//R
case 0x52:
#ifdef _DEBUG
Oyster::Graphics::API::ReloadShaders();
#endif
break;
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

View File

@ -1,99 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Tester</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\OysterGraphics;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="MainTest.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Misc\Misc.vcxproj">
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
</ProjectReference>
<ProjectReference Include="..\OysterGraphics\OysterGraphics.vcxproj">
<Project>{0ec83e64-230e-48ef-b08c-6ac9651b4f82}</Project>
</ProjectReference>
<ProjectReference Include="..\OysterMath\OysterMath.vcxproj">
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MainTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>