GameLogic - pree-sprint merge

This commit is contained in:
Dennis Andersen 2014-01-20 15:47:52 +01:00
parent b85439bd5e
commit 6c3c234be1
36 changed files with 631 additions and 451 deletions

View File

@ -75,7 +75,7 @@ namespace DanBias
if(!m_data->recieverObj->gameClientState->Init(m_data->recieverObj->nwClient))
return DanBiasClientReturn_Error;
m_data->timer = new Utility::WinTimer();
m_data->timer = new Utility::WinTimer(); //why dynamic memory?
m_data->timer->reset();
return DanBiasClientReturn_Sucess;
}

View File

@ -56,7 +56,6 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
case protocol_Gameplay_CreateObject:
{
Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj;
protocolData->object_ID = p[1].value.netInt;
protocolData->path = p[2].value.netCharPtr;

View File

@ -173,11 +173,6 @@
<ItemGroup>
<ClCompile Include="Launcher.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DanBiasGame\DanBiasGame.vcxproj">
<Project>{2a1bc987-af42-4500-802d-89cd32fc1309}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -20,6 +20,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
//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";
gameDesc.hinst = hinst;
gameDesc.nCmdShow = cmdShow;

View File

@ -112,7 +112,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll;GamePhysics_$(PlatformShortName)D.dll</DelayLoadDLLs>
<DelayLoadDLLs>GameLogic_$(PlatformShortName)D.dll;NetworkAPI_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -128,7 +128,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll;GamePhysics_$(PlatformShortName)D.dll</DelayLoadDLLs>
<DelayLoadDLLs>GameLogic_$(PlatformShortName)D.dll;NetworkAPI_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -148,7 +148,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName).dll;GamePhysics_$(PlatformShortName).dll</DelayLoadDLLs>
<DelayLoadDLLs>GameLogic_$(PlatformShortName).dll;NetworkAPI_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -168,7 +168,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<DelayLoadDLLs>GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName).dll;GamePhysics_$(PlatformShortName).dll</DelayLoadDLLs>
<DelayLoadDLLs>GameLogic_$(PlatformShortName).dll;NetworkAPI_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -206,9 +206,6 @@
<ClInclude Include="LobbySessions\NetworkSession.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GamePhysics\GamePhysics.vcxproj">
<Project>{104fa3e9-94d9-4e1d-a941-28a03bc8a095}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Misc\Misc.vcxproj">
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
</ProjectReference>

View File

@ -4,7 +4,6 @@
#include "GameClient.h"
#include "..\LobbySessions\NetworkSession.h"
#include <Game.h>
#include <Protocols.h>
using namespace Utility::DynamicMemory;
@ -13,7 +12,7 @@ using namespace GameLogic;
static int gameClientIDCount = 1;
GameClient::GameClient(SmartPointer<LobbyClient> client, Game::PlayerData* player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
GameClient::GameClient(SmartPointer<LobbyClient> client, IPlayerData* player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
{
this->callbackValue = value;
this->client = client;
@ -37,13 +36,13 @@ void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSessi
this->callbackValue = value;
}
GameLogic::Game::PlayerData* GameClient::GetPlayer()
GameLogic::IPlayerData* GameClient::GetPlayer()
{
return this->player;
}
GameLogic::Game::PlayerData* GameClient::ReleasePlayer()
GameLogic::IPlayerData* GameClient::ReleasePlayer()
{
GameLogic::Game::PlayerData *temp = this->player;
GameLogic::IPlayerData *temp = this->player;
this->player = 0;
return temp;
}

View File

@ -6,22 +6,22 @@
#include "..\LobbySessions\LobbyClient.h"
#include <PostBox\PostBox.h>
#include <Game.h>
#include <GameAPI.h>
namespace DanBias
{
class GameClient: Oyster::Callback::CallbackObject<void, NetworkSession::NetEvent>
{
public:
GameClient(Utility::DynamicMemory::SmartPointer<LobbyClient> client, GameLogic::Game::PlayerData* player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
GameClient(Utility::DynamicMemory::SmartPointer<LobbyClient> client, GameLogic::IPlayerData* player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
virtual~GameClient();
void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
/* */
GameLogic::Game::PlayerData* GetPlayer();
GameLogic::IPlayerData* GetPlayer();
GameLogic::Game::PlayerData* ReleasePlayer();
GameLogic::IPlayerData* ReleasePlayer();
LobbyClient* GetClient() const;
Utility::DynamicMemory::SmartPointer<LobbyClient> ReleaseClient();
@ -29,7 +29,7 @@ namespace DanBias
private:
//Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
GameLogic::Game::PlayerData* player;
GameLogic::IPlayerData* player;
Utility::DynamicMemory::SmartPointer<LobbyClient> client;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue;
int id;

View File

@ -11,7 +11,7 @@
#include <WinTimer.h>
#include <PostBox\IPostBox.h>
#include <Thread\OysterThread.h>
#include <Game.h>
#include <GameAPI.h>
#include <Queue.h>
namespace DanBias
@ -31,19 +31,6 @@ namespace DanBias
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
};
struct GameSessionEvent
{
union EventData
{
GameLogic::Game::PlayerData* player;
} data;
enum EventType
{
EventType_Player,
EventType_DynamicObject,
} value;
};
public:
GameSession();
virtual~GameSession();
@ -77,7 +64,7 @@ namespace DanBias
//Handles all general events
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Adds a client to the client list
void AddClient(Utility::DynamicMemory::SmartPointer<GameClient> obj);
void InsertClient(Utility::DynamicMemory::SmartPointer<GameClient> obj);
//Removes a client from the client list
void RemoveClient(DanBias::GameClient* obj);
//Sends a protocol ta all clients in session
@ -97,11 +84,14 @@ namespace DanBias
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
GameLogic::Game gameInstance;
GameLogic::GameAPI& gameInstance;
GameLogic::ILevelData *levelData;
NetworkSession* owner;
bool isCreated;
bool isRunning;
Utility::Container::Queue<GameSessionEvent> modifiedClient;
Utility::WinTimer timer;
static void ObjectMove(GameLogic::IObjectData* movedObject);
private:
friend class AdminInterface;

View File

@ -25,6 +25,8 @@ namespace DanBias
if( !this->box->IsEmpty() )
{
NetworkSession::NetEvent &e = this->box->Fetch();
static int ii = 0;
printf("%i - Message recieved! [%i]\n", ii++, e.protocol[0].value);
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
@ -38,10 +40,6 @@ namespace DanBias
void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
GameSessionEvent e;
e.data.player = c->GetPlayer();
e.value = GameSessionEvent::EventType_Player;
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
@ -60,9 +58,6 @@ namespace DanBias
if(p[6].value.netBool) //bool bStrafeLeft;
//world.v[3].y = -2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
}
break;
case protocol_Gameplay_PlayerMouseMovement:
@ -77,11 +72,7 @@ namespace DanBias
case protocol_Gameplay_ObjectPosition:
break;
}
this->modifiedClient.Push(e);
}
void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
@ -116,5 +107,15 @@ namespace DanBias
}
}
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
{
//if (movedObject->)
//{
//
//}
//movedObject->GetOrientation();
}
}//End namespace DanBias

View File

@ -20,6 +20,7 @@ using namespace GameLogic;
namespace DanBias
{
GameSession::GameSession()
:gameInstance(GameAPI::Instance())
{
this->owner = 0;
this->box = 0;
@ -36,30 +37,60 @@ namespace DanBias
bool GameSession::Create(GameDescription& desc)
{
/* Do some error checking */
if(desc.clients.Size() == 0) return false;
if(!desc.owner) return false;
if(!desc.mapName.size()) return false;
if(this->isCreated) return false;
/* standard initialization of some data */
this->clients.Resize(desc.clients.Size());
this->box = new PostBox<NetworkSession::NetEvent>();
this->owner = desc.owner;
/* Initiate the game instance */
if(!this->gameInstance.Initiate())
{
printf("Failed to initiate the game instance\n");
}
/* Create the game level */
if(!(this->levelData = this->gameInstance.CreateLevel()))
{
printf("Level not created!");
return false;
}
/* Create a callback object */
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
/* Create the players in the game instance */
GameLogic::IPlayerData* p = 0;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
this->clients[i] = new GameClient(desc.clients[i], gameInstance.CreatePlayer(), c);
if( (p = this->gameInstance.CreatePlayer()) )
{
this->clients[i] = new GameClient(desc.clients[i], p, c);
}
else
{
printf("Failed to create player (%i)\n", i);
}
}
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return false;
/* Create the worker thread */
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS)
return false;
this->worker.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_3);
/* Set some gameinstance data options */
this->gameInstance.SetSubscription(GameLogic::GameEvent::ObjectEventFunctionType_OnMove, GameSession::ObjectMove);
this->isCreated = true;
return true;
return this->isCreated;
}
void GameSession::Run()
@ -69,8 +100,7 @@ namespace DanBias
if(this->clients.Size() > 0)
{
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2);
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
this->isRunning = true;
}
}
@ -84,7 +114,7 @@ namespace DanBias
c.callbackType = Oyster::Callback::CallbackType_PostBox;
SmartPointer<GameClient> obj = new GameClient(client, this->gameInstance.CreatePlayer(), c);
AddClient(obj);
InsertClient(obj);
return true;
}
@ -105,7 +135,7 @@ namespace DanBias
this->Clean();
}
void GameSession::AddClient(SmartPointer<GameClient> obj)
void GameSession::InsertClient(SmartPointer<GameClient> obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{

View File

@ -10,6 +10,11 @@
#include <Windows.h>
#include <OysterMath.h>
#define DELTA_TIME_24 0.04166666666666666666666666666667f
#define DELTA_TIME_30 0.03333333333333333333333333333333f
#define DELTA_TIME_60 0.01666666666666666666666666666667f
#define DELTA_TIME_120 0.00833333333333333333333333333333f
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
@ -19,6 +24,8 @@ using namespace GameLogic;
namespace DanBias
{
bool GameSession::DoWork( )
{
if(this->isRunning)
{
if(GetAsyncKeyState(VK_UP))
{
@ -34,39 +41,32 @@ namespace DanBias
Sleep(100);
}
double dt = this->timer.getElapsedSeconds();
gameInstance.SetFrameTimeLength((float)dt);
if(dt >= DELTA_TIME_60)
{
this->ParseEvents();
this->gameInstance.NewFrame();
this->UpdateGameObjects();
this->timer.reset();
}
}
return this->isRunning;
}
void GameSession::UpdateGameObjects()
{
while(!this->modifiedClient.IsEmpty())
{
//There is something that needs update
GameSessionEvent e = this->modifiedClient.Pop();
switch (e.value)
{
case GameSessionEvent::EventType_Player:
//e.data.player->GetOrientation();
break;
}
}
if(clients.Size() == 1)
if(clients.Size() >= 1 && clients[0])
{
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
Protocol_ObjectPosition p(world, 1);
Send(p.GetProtocol());
Sleep(100);
//Sleep(100);
}
}

View File

@ -1,19 +1,10 @@
#include "Game.h"
#include "Player.h"
#include "Level.h"
#include <DynamicArray.h>
#include <GID.h>
#include <PhysicsAPI.h>
#include <WinTimer.h>
using namespace GameLogic;
using namespace Utility::DynamicMemory;
using namespace Oyster::Physics;
#define DELTA_TIME 0.01666666666666666666666666666667f
template<typename T>
int InsertObject(DynamicArray<T*>& list, T* obj)
template<typename T> int InsertObject(DynamicArray<T*>& list, T* obj)
{
for (unsigned int i = 0; i < list.Size(); i++)
{
@ -26,8 +17,7 @@ int InsertObject(DynamicArray<T*>& list, T* obj)
list.Push(obj);
return list.Size() - 1;
}
template<typename T>
int RemoveObject(DynamicArray<T*>& list, T* obj)
template<typename T> int RemoveObject(DynamicArray<T*>& list, T* obj)
{
for (unsigned int i = 0; i < list.Size(); i++)
{
@ -41,37 +31,33 @@ int RemoveObject(DynamicArray<T*>& list, T* obj)
return list.Size() - 1;
}
struct Game::PrivateData
Game gameInstance;
GameAPI& GameAPI::Instance()
{
PrivateData()
{ }
~PrivateData()
{
for (unsigned int i = 0; i < players.Size(); i++)
{
this->players[i]->player = 0;
}
}
DynamicArray<PlayerData*> players;
LevelData* level;
Utility::WinTimer timer;
}myData;
return gameInstance;
}
Game::Game(void)
{
myData = new PrivateData();
}
: initiated(false)
, onMoveFnc(0)
, onDeadFnc(0)
, frameTime(1.0f/120.0f)
{}
Game::~Game(void)
{
if(myData)
for (unsigned int i = 0; i < gameInstance.players.Size(); i++)
{
delete myData;
delete gameInstance.players[i];
}
gameInstance.players.Clear();
delete this->level;
this->level = 0;
initiated = false;
}
void Game::GetAllPlayerPositions() const
@ -81,21 +67,23 @@ void Game::GetAllPlayerPositions() const
Game::PlayerData* Game::CreatePlayer()
{
Player *newPlayer = new Player();
PlayerData *newPdata = new PlayerData();
newPdata->player = newPlayer;
int id = InsertObject(this->myData->players, newPdata);
return this->myData->players[id];
// Find a free space in array or insert at end
int id = InsertObject(this->players, (PlayerData*)0);
this->players[id] = new PlayerData();
this->players[id]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove);
return this->players[id];
}
Game::LevelData* Game::CreateLevel()
{
Level *newLevel = new Level();
newLevel->InitiateLevel(1000);
LevelData *newLdata = new LevelData();
newLdata->level = newLevel;
myData->level = newLdata;
return myData->level;
if(this->level) return this->level;
this->level = new LevelData();
this->level->level->InitiateLevel(1000);
return this->level;
}
void Game::CreateTeam()
@ -103,27 +91,72 @@ void Game::CreateTeam()
}
void Game::NewFrame()
bool Game::NewFrame()
{
double dt = this->myData->timer.getElapsedSeconds();
//60 fps sec is currently staticly
if(dt >= DELTA_TIME)
for (unsigned int i = 0; i < this->players.Size(); i++)
{
for (int i = 0; i < this->myData->players.Size(); i++)
{
if(this->myData->players[i]->player)
this->myData->players[i]->player->BeginFrame();
if(this->players[i]->player) this->players[i]->player->BeginFrame();
}
API::Instance().Update();
for (int i = 0; i < this->myData->players.Size(); i++)
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->myData->players[i]->player)
this->myData->players[i]->player->EndFrame();
}
this->myData->timer.reset();
if(this->players[i]->player) this->players[i]->player->EndFrame();
}
return true;
}
void Game::SetFPS(int FPS)
{
this->frameTime = 1.0f / FPS;
}
void Game::SetFrameTimeLength( float seconds )
{
this->frameTime = seconds;
}
void Game::SetSubscription(GameEvent::ObjectEventFunctionType type, GameEvent::ObjectEventFunction functionPointer)
{
switch (type)
{
case GameLogic::GameEvent::ObjectEventFunctionType_OnMove:
this->onMoveFnc = functionPointer;
break;
case GameLogic::GameEvent::ObjectEventFunctionType_OnDead:
this->onDeadFnc = functionPointer;
break;
}
}
bool Game::Initiate()
{
API::Instance().Init((int)pow(2u, 9u), 1u, Oyster::Math::Float3());
API::Instance().SetSubscription(Game::PhysicsOnDestroy);
this->initiated = true;
return true;
}
float Game::GetFrameTime() const
{
return this->frameTime;
}
/**********************************************/
/*********** Private methods ******************/
/***************************************************************************************************/
void Game::PhysicsOnMove(const ICustomBody *object)
{
IObjectData* temp = 0;
//IObjectData* temp = ((IObjectData*)object->GetDataTag());
if(gameInstance.onMoveFnc) gameInstance.onMoveFnc(temp);
}
void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer<ICustomBody> proto)
{
if(gameInstance.onDeadFnc) gameInstance.onDeadFnc(0);
}

View File

@ -5,112 +5,84 @@
#ifndef GAME_H
#define GAME_H
#include "GameLogicDef.h"
#include "GameLogicStates.h"
#include <OysterMath.h>
//Includes windows so we need to undef minmax
#define NOMINMAX
#include <vld.h>
#include "GameAPI.h"
#include "Player.h"
#include "Level.h"
#include <DynamicArray.h>
#include <GID.h>
#include <PhysicsAPI.h>
#include <WinTimer.h>
namespace GameLogic
{
class Player;
class Level;
class DANBIAS_GAMELOGIC_DLL Game
class Game :public GameAPI
{
public:
struct DANBIAS_GAMELOGIC_DLL PlayerData
class PlayerData :public IPlayerData
{
private:
friend class Game;
Player *player;
public:
PlayerData();
PlayerData(int playerID,int teamID);
~PlayerData();
public:
/********************************************************
* Moves the chosen player based on input
* @param playerID: ID of the player you want to recieve the message
* @param movement: enum value on what kind of action is to be taken
********************************************************/
void Move(const PLAYER_MOVEMENT &movement);
void Move(const PLAYER_MOVEMENT &movement) override;
void UseWeapon(int playerID, const WEAPON_FIRE &usage) override;
int GetTeamID() const override;
PLAYER_STATE GetState() const override;
Oyster::Math::Float3 GetPosition() override;
Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override;
OBJECT_TYPE GetObjectType() const override;
/********************************************************
* Uses the chosen players weapon based on input
* @param playerID: ID of the player you want to recieve the message
* @param Usage: enum value on what kind of action is to be taken
********************************************************/
void UseWeapon(int playerID, const WEAPON_FIRE &usage);
/********************************************************
* Gets players position
* @param playerID: ID of the player whos position you want
********************************************************/
Oyster::Math::Float3 GetPosition();
/********************************************************
* Gets players current orientation
* @param playerID: ID of the player whos position you want
********************************************************/
Oyster::Math::Float4x4 GetOrientation();
/********************************************************
* Check player state
* @return The current player state
********************************************************/
PLAYER_STATE GetState() const;
/***/
int GetID() const;
/***/
int GetTeamID() const;
Player *player;
};
struct DANBIAS_GAMELOGIC_DLL LevelData
class LevelData :public ILevelData
{
private:
friend class Game;
Level *level;
public:
LevelData();
~LevelData();
Oyster::Math::Float3 GetPosition() override;
Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override;
OBJECT_TYPE GetObjectType() const override;
public:
Level *level;
};
public:
Game(void);
~Game(void);
Game();
~Game();
/********************************************************
* Gets the position of all players currently in the game
********************************************************/
void GetAllPlayerPositions() const;
void GetAllPlayerPositions() const override;
PlayerData* CreatePlayer() override;
LevelData* CreateLevel() override;
void CreateTeam() override;
bool NewFrame() override;
void SetFPS( int FPS ) override;
void SetFrameTimeLength( float seconds ) override;
void SetSubscription(GameEvent::ObjectEventFunctionType type, GameEvent::ObjectEventFunction functionPointer) override;
bool Initiate() override;
/********************************************************
* Creates a player and returns PlayerData
********************************************************/
PlayerData* CreatePlayer();
/********************************************************
* Creates a level and returns LevelData
********************************************************/
LevelData* CreateLevel();
/********************************************************
* Creates a team
********************************************************/
void CreateTeam();
/********************************************************
* Runs a update of the gamelogic and physics
********************************************************/
void NewFrame();
float GetFrameTime() const;
private:
struct PrivateData;
PrivateData *myData;
static void PhysicsOnMove(const Oyster::Physics::ICustomBody *object);
static void PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer<Oyster::Physics::ICustomBody> proto);
private:
Utility::DynamicMemory::DynamicArray<PlayerData*> players;
LevelData* level;
float frameTime;
bool initiated;
GameEvent::ObjectEventFunction onDeadFnc;
GameEvent::ObjectEventFunction onMoveFnc;
};
}

View File

@ -0,0 +1,160 @@
/////////////////////////////////////////////////////////////////////
// Created by [Erik Persson] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef GAME_API_H
#define GAME_API_H
//Includes windows so we need to undef minmax
#define NOMINMAX
#include <vld.h>
#include "GameLogicDef.h"
#include "GameLogicStates.h"
#include <OysterMath.h>
namespace GameLogic
{
class IObjectData;
/**
* Collection of various event structures that may be used to get events grom the game.
*/
namespace GameEvent
{
/**
* The type of event to listen on.
*/
enum ObjectEventFunctionType
{
ObjectEventFunctionType_OnMove,
ObjectEventFunctionType_OnDead,
};
typedef void(*ObjectEventFunction)(IObjectData* object); // Callback method that recieves and object
//etc...
};
/**
* An object that collects the standard usage functions
*/
class IObjectData
{
public:
/********************************************************
* Gets players position
* @param playerID: ID of the player whos position you want
********************************************************/
virtual Oyster::Math::Float3 GetPosition() = 0;
/********************************************************
* Gets players current orientation
* @param playerID: ID of the player whos position you want
********************************************************/
virtual Oyster::Math::Float4x4 GetOrientation() = 0;
/** Get the uniuqe id for the object
* @return The id for the object.
*/
virtual int GetID() const = 0;
/** Get the type of the object
* @return The OBJECT_TYPE of the object is returned
*/
virtual OBJECT_TYPE GetObjectType() const = 0;
};
class IPlayerData :public IObjectData
{
public:
/********************************************************
* Moves the chosen player based on input
* @param playerID: ID of the player you want to recieve the message
* @param movement: enum value on what kind of action is to be taken
********************************************************/
virtual void Move(const PLAYER_MOVEMENT &movement) = 0;
/********************************************************
* Uses the chosen players weapon based on input
* @param playerID: ID of the player you want to recieve the message
* @param Usage: enum value on what kind of action is to be taken
********************************************************/
virtual void UseWeapon(int playerID, const WEAPON_FIRE &usage) = 0;
/***/
virtual int GetTeamID() const = 0;
/********************************************************
* Check player state
* @return The current player state
********************************************************/
virtual PLAYER_STATE GetState() const = 0;
};
class ILevelData :public IObjectData
{
public:
};
class DANBIAS_GAMELOGIC_DLL GameAPI
{
public:
/** A global function to get an instance of the API
* @return Returns the GameAPI instance
*/
static GameAPI& Instance( void );
public:
/** Initiates the Game instance.
* - This method must be called before the API can be used.
* @return If the return value is false, something went wrong.
*/
virtual bool Initiate( void ) = 0;
/********************************************************
* Gets the position of all players currently in the game
********************************************************/
virtual void GetAllPlayerPositions( void ) const = 0;
/** Creates a player
* @return Returns a IPlayerData container to use for player manipulation.
*/
virtual IPlayerData* CreatePlayer( void ) = 0;
/** Creates a level
* @return Returns a ILevelData container to use for level manipulation
*/
virtual ILevelData* CreateLevel( void ) = 0;
/** Creates a team
* @return ?
*/
virtual void CreateTeam( void ) = 0;
/** Runs a update of the gamelogic and physics
* @return Returns true if a frame was proccessed
*/
virtual bool NewFrame( void ) = 0;
/** Set the frame time in fps
* @param FPS The fps to set
*/
virtual void SetFPS( int FPS = 60 ) = 0;
/** Set the frames time in seconds
* @param seconds The frame length
*/
virtual void SetFrameTimeLength( float seconds ) = 0;
/** Set a specific object event subscription callback
* @param
*/
virtual void SetSubscription(GameEvent::ObjectEventFunctionType type, GameEvent::ObjectEventFunction functionPointer) = 0;
};
}
#endif

View File

@ -69,26 +69,30 @@
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<LibraryPath>$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<LibraryPath>$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<LibraryPath>$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<LibraryPath>$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -174,6 +178,7 @@
<ClInclude Include="CollisionManager.h" />
<ClInclude Include="DynamicObject.h" />
<ClInclude Include="Game.h" />
<ClInclude Include="GameAPI.h" />
<ClInclude Include="GameLogicDef.h" />
<ClInclude Include="GameLogicStates.h" />
<ClInclude Include="GameMode.h" />

View File

@ -24,7 +24,8 @@ namespace GameLogic
{
OBJECT_TYPE_PLAYER = 0,
OBJECT_TYPE_BOX = 1,
OBJECT_TYPE_UNKNOWN = 2,
OBJECT_TYPE_WORLD = 2,
OBJECT_TYPE_UNKNOWN = -1,
};
enum WEAPON_FIRE

View File

@ -3,28 +3,13 @@
using namespace GameLogic;
struct GameMode::PrivateData
{
PrivateData()
{
}
~PrivateData()
{
}
}myData;
GameMode::GameMode()
{
myData = new PrivateData();
}
GameMode::~GameMode(void)
{
delete myData;
}

View File

@ -13,9 +13,9 @@ namespace GameLogic
public:
GameMode(void);
~GameMode(void);
private:
struct PrivateData;
PrivateData *myData;
};
}

View File

@ -5,10 +5,33 @@ using namespace GameLogic;
Game::LevelData::LevelData()
{
this->level = new Level();
}
Game::LevelData::~LevelData()
{
delete this->level;
this->level = 0;
}
Oyster::Math::Float3 Game::LevelData::GetPosition()
{
//return this->level->GetCenter();
return Oyster::Math::Float3();
}
Oyster::Math::Float4x4 Game::LevelData::GetOrientation()
{
//return this->level->GetOrientation();
return Oyster::Math::Float4x4();
}
int Game::LevelData::GetID() const
{
//this->level->GetID();
return -1;
}
OBJECT_TYPE Game::LevelData::GetObjectType() const
{
//return this->level->GetType();
return OBJECT_TYPE_UNKNOWN;
}

View File

@ -5,15 +5,15 @@ using namespace GameLogic;
Game::PlayerData::PlayerData()
{
this->player = new Player();
}
Game::PlayerData::PlayerData(int playerID,int teamID)
{
this->player = new Player();
}
Game::PlayerData::~PlayerData()
{
delete this->player;
}
void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement)
@ -44,3 +44,7 @@ int Game::PlayerData::GetTeamID() const
{
return this->player->GetTeamID();
}
OBJECT_TYPE Game::PlayerData::GetObjectType() const
{
return this->player->GetType();
}

View File

@ -1,47 +1,16 @@
#include "Level.h"
#include "StaticObject.h"
#include "DynamicObject.h"
#include "GameMode.h"
#include "Player.h"
#include "PhysicsAPI.h"
#include "TeamManager.h"
#include "DynamicArray.h"
#include "CollisionManager.h"
using namespace GameLogic;
using namespace Utility::DynamicMemory;
using namespace Oyster::Physics;
struct Level::PrivateData
{
PrivateData()
{
}
~PrivateData()
{
}
SmartPointer<TeamManager> teamManager;
DynamicArray<SmartPointer<StaticObject>> staticObjects;
DynamicArray<SmartPointer<DynamicObject>> dynamicObjects;
SmartPointer<GameMode> gameMode;
SmartPointer<ICustomBody> rigidBodyLevel;
}myData;
Level::Level(void)
{
myData = new PrivateData();
}
Level::~Level(void)
{
delete myData;
}
void Level::InitiateLevel(std::string levelPath)
@ -50,39 +19,40 @@ void Level::InitiateLevel(std::string levelPath)
}
void Level::InitiateLevel(float radius)
{
API::SphericalBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
sbDesc.ignoreGravity = true;
sbDesc.radius = radius;
sbDesc.mass = 1e16; //10^16
sbDesc.subscription = CollisionManager::LevelCollision;
//API::SphericalBodyDescription sbDesc;
//sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
//sbDesc.ignoreGravity = true;
//sbDesc.radius = radius;
//sbDesc.mass = 1e16f; //10^16
//sbDesc.mass = 0; //10^16
//sbDesc.subscription_onCollision = CollisionManager::LevelCollision;
//
//ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
//API::Instance().AddObject(rigidBody);
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
API::Instance().AddObject(rigidBody);
API::Gravity gravityWell;
gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = (float)1e16;
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
API::Instance().AddGravity(gravityWell);
//API::Gravity gravityWell;
//
//gravityWell.gravityType = API::Gravity::GravityType_Well;
//gravityWell.well.mass = 1e16f;
//gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
//
//API::Instance().AddGravity(gravityWell);
}
void Level::AddPlayerToTeam(Player *player, int teamID)
{
myData->teamManager->AddPlayerToTeam(player,teamID);
this->teamManager.AddPlayerToTeam(player,teamID);
}
void Level::CreateTeam(int teamSize)
{
myData->teamManager->CreateTeam(teamSize);
this->teamManager.CreateTeam(teamSize);
}
void Level::RespawnPlayer(Player *player)
{
myData->teamManager->RespawnPlayerRandom(player);
this->teamManager.RespawnPlayerRandom(player);
}

View File

@ -4,7 +4,15 @@
#ifndef LEVEL_H
#define LEVEL_H
#include <string>
#include "Player.h"
#include "StaticObject.h"
#include "DynamicObject.h"
#include "GameMode.h"
#include "Player.h"
#include "PhysicsAPI.h"
#include "TeamManager.h"
#include "DynamicArray.h"
namespace GameLogic
{
@ -44,10 +52,11 @@ namespace GameLogic
void RespawnPlayer(Player *player);
private:
private:
struct PrivateData;
PrivateData *myData;
TeamManager teamManager;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> dynamicObjects;
GameMode gameMode;
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
};

View File

@ -3,6 +3,7 @@
#include "CollisionManager.h"
#include "GID.h"
#include "PhysicsAPI.h"
#include "Game.h"
using namespace GameLogic;
@ -10,6 +11,8 @@ using namespace GameLogic;
using namespace Oyster::Math;
using namespace Oyster::Physics;
const Game *Object::gameInstance = (Game*)(&Game::Instance());
Object::Object()
{
API::SimpleBodyDescription sbDesc;
@ -34,7 +37,7 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
//sbDesc.centerPosition =
//poi
ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
@ -66,3 +69,14 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody()
{
return this->rigidBody;
}
void Object::BeginFrame()
{
this->rigidBody->SetState(this->setState);
}
void Object::EndFrame()
{
this->rigidBody->GetState(this->getState);
this->setState = this->getState;
}

View File

@ -6,12 +6,13 @@
#ifndef OBJECT_H
#define OBJECT_H
#include "GameLogicStates.h"
#include <PhysicsAPI.h>
namespace GameLogic
{
class Game;
class Object
{
public:
@ -21,17 +22,22 @@ namespace GameLogic
OBJECT_TYPE GetType() const;
int GetID() const;
Oyster::Physics::ICustomBody* GetRigidBody();
void BeginFrame();
void EndFrame();
private:
OBJECT_TYPE type;
int objectID;
protected:
Oyster::Physics::ICustomBody *rigidBody;
Oyster::Physics::ICustomBody::State setState;
Oyster::Physics::ICustomBody::State getState;
static const Game* gameInstance;
};
}

View File

@ -1,6 +1,8 @@
#include "Player.h"
#include "Weapon.h"
#include "CollisionManager.h"
#include "Game.h"
using namespace GameLogic;
using namespace Oyster::Physics;
@ -14,17 +16,11 @@ Player::Player()
teamID = -1;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float4(0,0,-1,0);
Oyster::Physics::ICustomBody::State state;
this->rigidBody->GetState( this->setState );
setState.SetLinearMomentum( Oyster::Math::Float4(20, 0, 0, 0) );
this->rigidBody->SetState( setState );
}
Player::~Player(void)
{
delete weapon;
weapon = NULL;
}
@ -57,26 +53,26 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward()
{
setState.ApplyLinearImpulse(this->lookDir * 100);
setState.ApplyLinearImpulse(this->lookDir * (100 * this->gameInstance->GetFrameTime()));
}
void Player::MoveBackwards()
{
setState.ApplyLinearImpulse(-this->lookDir * 100);
setState.ApplyLinearImpulse(-this->lookDir * 100 * this->gameInstance->GetFrameTime());
}
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(r * 100);
setState.ApplyLinearImpulse(r * 100 * this->gameInstance->GetFrameTime());
}
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(-r * 100);
//Oyster::Math::Float4 r1 = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero
setState.ApplyLinearImpulse(-r * 100 * this->gameInstance->GetFrameTime());
}
void Player::UseWeapon(const WEAPON_FIRE &usage)
@ -136,12 +132,3 @@ void Player::DamageLife(int damage)
this->life -= damage;
}
void Player::BeginFrame()
{
this->rigidBody->SetState(this->setState);
}
void Player::EndFrame()
{
this->rigidBody->GetState(this->getState);
this->setState = this->getState;
}

View File

@ -7,9 +7,6 @@
#include "GameLogicStates.h"
#include "OysterMath.h"
#include "Object.h"
#include "OysterMath.h"
#include "CollisionManager.h"
namespace GameLogic
@ -58,10 +55,6 @@ namespace GameLogic
void DamageLife(int damage);
//Do frame calculations
void BeginFrame();
void EndFrame();
private:
void Jump();

View File

@ -1,60 +1,54 @@
#include "Team.h"
#include "Player.h"
using namespace GameLogic;
struct Team::PrivateData
{
PrivateData()
{
players = 0;
nrOfPlayers = 0;
teamSize = 0;
}
~PrivateData()
{
}
Player **players;
int nrOfPlayers;
int teamSize;
}myData;
Team::Team(void)
{
myData = new PrivateData();
}
: players(5)
, teamSize(5)
{}
Team::Team(int teamSize)
{
myData = new PrivateData();
myData->teamSize = teamSize;
}
: players((unsigned int)teamSize)
, teamSize(teamSize)
{}
Team::~Team(void)
{
delete myData;
this->players.Clear();
}
Player* Team::GetPlayer(int playerID)
{
return myData->players[playerID];
if(playerID >= 0 && playerID < this->teamSize)
return this->players[playerID];
return NULL;
}
bool Team::AddPlayer(Player *player)
{
if (myData->nrOfPlayers >= myData->teamSize)
if ((int)this->players.Size() >= this->teamSize)
{
return false;
}
else
{
myData->players[myData->nrOfPlayers] = player;
myData->nrOfPlayers++;
int k = -1;
for (int i = 0; k == -1 && i < this->teamSize; i++)
{
if(!this->players[i])
k = i;
}
if(k == -1)
{
this->players.Push(player);
}
else
{
this->players[k] = player;
}
}
return true;

View File

@ -4,7 +4,9 @@
#ifndef TEAM_H
#define TEAM_H
#include "Player.h"
#include "DynamicArray.h"
namespace GameLogic
{
@ -29,8 +31,8 @@ namespace GameLogic
bool AddPlayer(Player *player);
private:
struct PrivateData;
PrivateData *myData;
Utility::DynamicMemory::DynamicArray<Player*> players;
int teamSize;
};
}
#endif

View File

@ -1,69 +1,56 @@
#include "TeamManager.h"
#include "Team.h"
using namespace GameLogic;
struct TeamManager::PrivateData
{
PrivateData()
{
teams = 0;
nrOfTeams = 0;
}
~PrivateData()
{
}
Team **teams;
int nrOfTeams;
int maxNrOfTeams;
}myData;
TeamManager::TeamManager(void)
: teams(10)
, maxNrOfTeams(10)
{
myData = new PrivateData();
myData->maxNrOfTeams = 10;
myData->teams = new Team*[myData->maxNrOfTeams];
for (int i = 0; i < 10; i++)
{
teams[i] = 0;
}
}
TeamManager::TeamManager(int maxNrOfTeams)
: teams(maxNrOfTeams)
, maxNrOfTeams(maxNrOfTeams)
{
myData = new PrivateData();
myData->maxNrOfTeams = maxNrOfTeams;
myData->teams = new Team*[myData->maxNrOfTeams];
for (int i = 0; i < myData->maxNrOfTeams; i++)
for (int i = 0; i < this->maxNrOfTeams; i++)
{
myData->teams[i] = 0;
teams[i] = 0;
}
}
TeamManager::~TeamManager(void)
{
delete myData;
for (int i = 0; i < this->maxNrOfTeams; i++)
{
delete this->teams[i];
this->teams[i] = 0;
}
}
void TeamManager::RespawnPlayerRandom(Player *player)
{
int teamID = player->GetTeamID();
Player *respawnOnThis = myData->teams[teamID]->GetPlayer(0);
player->Respawn(respawnOnThis->GetPosition());
// Whats going on here?
int teamID = player->GetTeamID(); // ?
// ?
Player *respawnOnThis = this->teams[teamID]->GetPlayer(0); // ?
// ?
player->Respawn(respawnOnThis->GetPosition()); // ?
// player->Respawn(player->GetPosition()); ?
}
void TeamManager::CreateTeam(int teamSize)
{
if (myData->nrOfTeams < myData->maxNrOfTeams)
{
myData->teams[myData->nrOfTeams] = new Team(teamSize);
myData->nrOfTeams++;
}
//if (this->nrOfTeams < this->maxNrOfTeams)
//{
// this->teams[this->nrOfTeams] = new Team(teamSize);
// this->nrOfTeams++;
//}
}
void TeamManager::RemoveTeam(int teamID)
@ -73,10 +60,10 @@ void TeamManager::RemoveTeam(int teamID)
bool TeamManager::AddPlayerToTeam(Player *player,int teamID)
{
if (IsValidTeam(teamID))
{
return myData->teams[teamID]->AddPlayer(player);
}
//if (IsValidTeam(teamID))
//{
// return this->teams[teamID]->AddPlayer(player);
//}
return false;
}
@ -87,10 +74,10 @@ bool TeamManager::AddPlayerToTeam(Player *player)
bool TeamManager::IsValidTeam(int teamID)
{
if (teamID < myData->nrOfTeams && teamID > 0 && myData->teams[teamID] != NULL)
{
return true;
}
//if (teamID < this->nrOfTeams && teamID > 0 && this->teams[teamID] != NULL)
//{
// return true;
//}
return false;
}

View File

@ -4,7 +4,10 @@
#ifndef TEAMMANAGER_H
#define TEAMMANAGER_H
#include "Player.h"
#include "Team.h"
#include <DynamicArray.h>
namespace GameLogic
{
@ -56,8 +59,8 @@ namespace GameLogic
bool IsValidTeam(int teamID);
private:
struct PrivateData;
PrivateData *myData;
Utility::DynamicMemory::DynamicArray<Team*> teams;
int maxNrOfTeams;
};
}
#endif

View File

@ -83,7 +83,7 @@ bool Weapon::IsReloading()
bool Weapon::IsValidSocket(int socketID)
{
if(socketID < myData->attatchmentSockets.Size() && socketID >= 0)
if(socketID < (int)myData->attatchmentSockets.Size() && socketID >= 0)
{
if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0)
{
@ -102,7 +102,7 @@ int Weapon::GetCurrentSocketID()
void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner)
{
if(myData->currentNrOfAttatchments < myData->attatchmentSockets.Size())
if(myData->currentNrOfAttatchments < (int)myData->attatchmentSockets.Size())
{
myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment);
myData->currentNrOfAttatchments++;

View File

@ -46,6 +46,7 @@ namespace GameLogic
struct Protocol_General_Text :public Oyster::Network::CustomProtocolObject
{
char* text;
int destination;
Protocol_General_Text()
{

View File

@ -150,6 +150,10 @@
<ClCompile Include="Resource\Loaders\CustomLoader.cpp" />
<ClCompile Include="Resource\OResourceHandler.cpp" />
<ClCompile Include="Resource\OResource.cpp" />
<ClCompile Include="Resource\ResourceManager.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="Thread\OysterMutex.cpp" />
<ClCompile Include="Thread\OysterThread_Impl.cpp" />
<ClCompile Include="Utilities.cpp" />
@ -165,6 +169,10 @@
<ClInclude Include="Queue.h" />
<ClInclude Include="Resource\OysterResource.h" />
<ClInclude Include="Resource\OResource.h" />
<ClInclude Include="Resource\ResourceManager.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="ThreadSafeQueue.h" />
<ClInclude Include="Thread\IThreadObject.h" />
<ClInclude Include="Thread\OysterMutex.h" />

View File

@ -45,6 +45,9 @@
<ClCompile Include="Thread\OysterThread_Impl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Resource\ResourceManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Utilities.h">
@ -104,5 +107,8 @@
<ClInclude Include="Queue.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource\ResourceManager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -101,7 +101,7 @@ using namespace Utility::DynamicMemory;
else
this->threadData->state = OYSTER_THREAD_STATE_IDLE;
threadData->ownerObj = worker;
threadData->prio = OYSTER_THREAD_PRIORITY_3;
threadData->prio = OYSTER_THREAD_PRIORITY_2;
workerThread = std::thread(fnc, this->threadData);

View File

@ -73,6 +73,7 @@ struct ClientDataContainer
};
unsigned int ClientDataContainer::currID = 0;
struct NetworkClient::PrivateData : public IThreadObject
{
Utility::DynamicMemory::SmartPointer<ClientDataContainer> data;
@ -92,6 +93,7 @@ struct NetworkClient::PrivateData : public IThreadObject
return true;
}
void Send(CustomNetProtocol* protocol)
{
if(!data) return;
@ -175,12 +177,14 @@ struct NetworkClient::PrivateData : public IThreadObject
NetworkClient::NetworkClient()
{
privateData = new PrivateData();
this->privateData->data->thread.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_1);
}
NetworkClient::NetworkClient(unsigned int socket)
{
privateData = new PrivateData(socket);
this->privateData->data->thread.Create(this->privateData, true);
this->privateData->data->thread.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_1);
}
NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type)
@ -196,6 +200,7 @@ NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType
this->privateData->data->callbackType = type;
this->privateData->data->recvObj = recvObj;
this->privateData->data->thread.Create(this->privateData, true);
this->privateData->data->thread.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_1);
}
NetworkClient::NetworkClient(const NetworkClient& obj)