GameServer - Pre-merge with graphic

This commit is contained in:
Dennis Andersen 2014-01-31 22:52:52 +01:00
parent 5aede62af6
commit a673e64694
22 changed files with 161 additions and 171 deletions

View File

@ -56,7 +56,8 @@ namespace DanBias
{ {
WindowShell::CreateConsoleWindow(); WindowShell::CreateConsoleWindow();
if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) //if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT())))
if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC()))
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
if( FAILED( InitDirect3D() ) ) if( FAILED( InitDirect3D() ) )
@ -200,6 +201,8 @@ namespace DanBias
delete m_data->recieverObj; delete m_data->recieverObj;
delete m_data->inputObj; delete m_data->inputObj;
delete m_data; delete m_data;
GameServerAPI::ServerStop();
Oyster::Graphics::API::Clean(); Oyster::Graphics::API::Clean();

View File

@ -33,7 +33,8 @@ GameState::GameState(void)
GameState::~GameState(void) GameState::~GameState(void)
{ {
delete this->camera;
delete this->privData;
} }
bool GameState::Init(Oyster::Network::NetworkClient* nwClient) bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
{ {
@ -82,7 +83,7 @@ bool GameState::LoadModels(std::wstring mapFile)
C_Object* obj; C_Object* obj;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
modelData.world = translate ;//modelData.world * translate modelData.world = translate ;//modelData.world * translate
modelData.modelPath = L"world_earth.dan"; modelData.modelPath = L"..\\Content\\Models\\world_earth.dan";
modelData.id = 0; modelData.id = 0;
obj = new C_Player(); obj = new C_Player();

View File

@ -93,7 +93,6 @@ void Game::CreateTeam()
bool Game::NewFrame() bool Game::NewFrame()
{ {
for (unsigned int i = 0; i < this->players.Size(); i++) for (unsigned int i = 0; i < this->players.Size(); i++)
{ {
if(this->players[i]->player) this->players[i]->player->BeginFrame(); if(this->players[i]->player) this->players[i]->player->BeginFrame();
@ -105,28 +104,7 @@ bool Game::NewFrame()
{ {
if(this->players[i]->player) this->players[i]->player->EndFrame(); if(this->players[i]->player) this->players[i]->player->EndFrame();
} }
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->BeginFrame();
}
API::Instance().Update();
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->EndFrame();
}
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->BeginFrame();
}
API::Instance().Update();
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->EndFrame();
}
gameInstance.onMoveFnc(this->level); gameInstance.onMoveFnc(this->level);
@ -161,6 +139,7 @@ bool Game::Initiate()
{ {
API::Instance().Init((int)pow(2u, 9u), 1u, Oyster::Math::Float3()); API::Instance().Init((int)pow(2u, 9u), 1u, Oyster::Math::Float3());
API::Instance().SetSubscription(Game::PhysicsOnDestroy); API::Instance().SetSubscription(Game::PhysicsOnDestroy);
API::Instance().SetFrameTimeLength(1.0f/120.0f);
this->initiated = true; this->initiated = true;
return true; return true;
} }

View File

@ -36,11 +36,11 @@ namespace GameLogic
this->status = state; this->status = state;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = status; this->protocol[1].value = status;
return &protocol; return protocol;
} }
private: private:
@ -59,12 +59,12 @@ namespace GameLogic
destination = p.Get(1).value.netInt; destination = p.Get(1).value.netInt;
text = p.Get(2).value.netCharPtr; text = p.Get(2).value.netCharPtr;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol.Set(0, protocol_General_Text, Oyster::Network::NetAttributeType_Short); this->protocol.Set(0, protocol_General_Text, Oyster::Network::NetAttributeType_Short);
this->protocol.Set(1, destination, Oyster::Network::NetAttributeType_Int); this->protocol.Set(1, destination, Oyster::Network::NetAttributeType_Int);
this->protocol.Set(2, text); this->protocol.Set(2, text);
return &protocol; return protocol;
} }
private: private:

View File

@ -33,7 +33,7 @@ namespace GameLogic
mapName = o[1].value.netCharPtr; mapName = o[1].value.netCharPtr;
gameId = o[2].value.netChar; gameId = o[2].value.netChar;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
protocol[1].value = mapName; protocol[1].value = mapName;
protocol[2].value = gameId; protocol[2].value = gameId;
@ -59,10 +59,10 @@ namespace GameLogic
{ {
gameId = o[1].value.netInt; gameId = o[1].value.netInt;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
protocol[1].value = gameId; protocol[1].value = gameId;
return &protocol; return protocol;
} }
private: private:
@ -83,9 +83,9 @@ namespace GameLogic
{ {
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
return &protocol; return protocol;
} }
private: private:
@ -109,7 +109,7 @@ namespace GameLogic
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short; // this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// value = p[1].value.netShort; // value = p[1].value.netShort;
// } // }
// Oyster::Network::CustomNetProtocol* GetProtocol() override // Oyster::Network::CustomNetProtocol GetProtocol() override
// { // {
// protocol[1].value = value; // protocol[1].value = value;
// return &protocol; // return &protocol;
@ -130,8 +130,8 @@ namespace GameLogic
{ {
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ return &protocol; } { return protocol; }
private: private:
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
@ -175,7 +175,7 @@ namespace GameLogic
list.Push(d); list.Push(d);
} }
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = list.Size(); this->protocol[1].value = list.Size();
@ -195,7 +195,7 @@ namespace GameLogic
this->protocol.Set(a++, list[i].ip); this->protocol.Set(a++, list[i].ip);
} }
return &protocol; return protocol;
} }
private: private:
@ -223,13 +223,13 @@ namespace GameLogic
minorVersion = (int)p.Get(2).value.netInt; minorVersion = (int)p.Get(2).value.netInt;
mapName = p.Get(3).value.netCharPtr; mapName = p.Get(3).value.netCharPtr;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = majorVersion; this->protocol[1].value = majorVersion;
this->protocol[2].value = minorVersion; this->protocol[2].value = minorVersion;
this->protocol.Set(3, mapName.c_str()); this->protocol.Set(3, mapName.c_str());
return &protocol; return protocol;
} }
private: private:
@ -254,7 +254,7 @@ namespace GameLogic
// { // {
// //
// } // }
// Oyster::Network::CustomNetProtocol* GetProtocol() override // Oyster::Network::CustomNetProtocol GetProtocol() override
// { // {
// return &protocol; // return &protocol;
// } // }

View File

@ -39,11 +39,11 @@ namespace GameLogic
pickup_ID = pickupID; pickup_ID = pickupID;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
this->protocol[2].value = pickup_ID; this->protocol[2].value = pickup_ID;
return &protocol; return protocol;
} }
private: private:
@ -80,11 +80,11 @@ namespace GameLogic
object_ID = id; object_ID = id;
health = hp; health = hp;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
this->protocol[2].value = health; this->protocol[2].value = health;
return &protocol; return protocol;
} }
private: private:
@ -129,14 +129,14 @@ namespace GameLogic
object_ID = id; object_ID = id;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
for (int i = 2; i <= 17; i++) for (int i = 2; i <= 17; i++)
{ {
this->protocol[i].value = worldMatrix[i-2]; this->protocol[i].value = worldMatrix[i-2];
} }
return &protocol; return protocol;
} }
private: private:
@ -179,14 +179,14 @@ namespace GameLogic
object_ID = id; object_ID = id;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
for (int i = 2; i <= 17; i++) for (int i = 2; i <= 17; i++)
{ {
this->protocol[i].value = worldMatrix[i-2]; this->protocol[i].value = worldMatrix[i-2];
} }
return &protocol; return protocol;
} }
private: private:
@ -221,11 +221,11 @@ namespace GameLogic
object_ID = id; object_ID = id;
timer = time; timer = time;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
this->protocol[2].value = timer; this->protocol[2].value = timer;
return &protocol; return protocol;
} }
private: private:
@ -272,7 +272,7 @@ namespace GameLogic
this->name = path; this->name = path;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
@ -297,7 +297,7 @@ namespace GameLogic
return &protocol; return protocol;
} }
private: private:

View File

@ -49,14 +49,14 @@ namespace GameLogic
return *this; return *this;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = bForward; this->protocol[1].value = bForward;
this->protocol[2].value = bBackward; this->protocol[2].value = bBackward;
this->protocol[3].value = bLeft; this->protocol[3].value = bLeft;
this->protocol[4].value = bRight; this->protocol[4].value = bRight;
return &protocol; return protocol;
} }
private: private:
@ -94,13 +94,13 @@ namespace GameLogic
return *this; return *this;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = lookDirX; this->protocol[1].value = lookDirX;
this->protocol[2].value = lookDirY; this->protocol[2].value = lookDirY;
this->protocol[3].value = lookDirZ; this->protocol[3].value = lookDirZ;
return &protocol; return protocol;
} }
private: private:
@ -125,9 +125,9 @@ namespace GameLogic
{ {
return *this; return *this;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
return &protocol; return protocol;
} }
private: private:
@ -154,10 +154,10 @@ namespace GameLogic
hasShot = val[1].value.netBool; hasShot = val[1].value.netBool;
return *this; return *this;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = hasShot; this->protocol[1].value = hasShot;
return &protocol; return protocol;
} }
private: private:
@ -184,10 +184,10 @@ namespace GameLogic
hasJumped = val[1].value.netBool; hasJumped = val[1].value.netBool;
return *this; return *this;
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = hasJumped; this->protocol[1].value = hasJumped;
return &protocol; return protocol;
} }
private: private:

View File

@ -52,6 +52,7 @@ namespace DanBias
private: private:
Utility::WinTimer timer; Utility::WinTimer timer;
float refreshFrequency; float refreshFrequency;
GameSession gameSession; GameSession gameSession;
LobbyLevelData description; LobbyLevelData description;
}; };

View File

@ -55,6 +55,7 @@ namespace DanBias
inline bool IsCreated() const { return this->isCreated; } inline bool IsCreated() const { return this->isCreated; }
inline bool IsRunning() const { return this->isRunning; } inline bool IsRunning() const { return this->isRunning; }
operator bool() { return (this->isCreated && this->isCreated); }
//Private member functions //Private member functions
private: private:
@ -97,7 +98,9 @@ namespace DanBias
NetworkSession* owner; NetworkSession* owner;
bool isCreated; bool isCreated;
bool isRunning; bool isRunning;
Utility::WinTimer timer; float logicDeltaTime;
Utility::WinTimer logicTimer;
Utility::WinTimer networkTimer;
GameDescription description; GameDescription description;
//TODO: Remove this uggly hax //TODO: Remove this uggly hax

View File

@ -17,7 +17,9 @@ namespace DanBias
{ } { }
GameLobby::~GameLobby() GameLobby::~GameLobby()
{ } {
this->clients.Clear();
}
void GameLobby::Release() void GameLobby::Release()
{ {
@ -27,7 +29,7 @@ namespace DanBias
void GameLobby::Update() void GameLobby::Update()
{ {
if(GetAsyncKeyState(VK_DOWN)) //TODO: Dont forget to remove this... if(GetAsyncKeyState(VK_DOWN)) //TODO: Dont forget to remove this...
this->Send(*GameLogic::Protocol_General_Status().GetProtocol()); this->Send(GameLogic::Protocol_General_Status().GetProtocol());
this->ProcessClients(); this->ProcessClients();
} }
@ -85,29 +87,36 @@ namespace DanBias
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
{ {
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
Attach(client);
Protocol_LobbyClientData p1; if(this->gameSession)
Protocol_LobbyGameData p2;
for (unsigned int i = 0; i < this->clients.Size(); i++)
{ {
if(this->clients[i]) this->gameSession.ClientConnectedEvent(client);
{
Protocol_LobbyClientData::PlayerData t;
t.id = this->clients[i]->GetID();
t.ip = this->clients[i]->GetIpAddress();
t.team = 0;
t.name = "DennisÄrKung";
p1.list.Push(t);
}
} }
p2.majorVersion = 1; else
p2.minorVersion = 0; {
p2.mapName = "BetsMap"; Attach(client);
Protocol_LobbyClientData p1;
Protocol_LobbyGameData p2;
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i])
{
Protocol_LobbyClientData::PlayerData t;
t.id = this->clients[i]->GetID();
t.ip = this->clients[i]->GetIpAddress();
t.team = 0;
t.name = "Dennis är kung tycker Erik!";
p1.list.Push(t);
}
}
p2.majorVersion = 1;
p2.minorVersion = 0;
p2.mapName = "Dennis är kung tycker Erik!";
client->Send(p1.GetProtocol()); client->Send(p1.GetProtocol());
client->Send(p2.GetProtocol()); client->Send(p2.GetProtocol());
}
} }
}//End namespace DanBias }//End namespace DanBias

View File

@ -53,6 +53,7 @@ void GameServerAPI::ServerStart()
} }
void GameServerAPI::ServerStop() void GameServerAPI::ServerStop()
{ {
if(!server.IsStarted()) return;
lobby.Release(); lobby.Release();
server.Shutdown(); server.Shutdown();

View File

@ -29,16 +29,15 @@ namespace DanBias
{ {
if(this->isRunning) if(this->isRunning)
{ {
double dt = this->timer.getElapsedSeconds(); float dt = (float)this->logicTimer.getElapsedSeconds();
gameInstance.SetFrameTimeLength((float)dt); this->logicDeltaTime += dt;
this->logicTimer.reset();
if(dt >= DELTA_TIME_20) while( logicDeltaTime >= DELTA_TIME_120 )
{ {
this->ProcessClients(); this->ProcessClients();
this->gameInstance.NewFrame(); this->gameInstance.NewFrame();
this->timer.reset(); logicDeltaTime -= DELTA_TIME_120;
} }
} }
@ -72,7 +71,7 @@ namespace DanBias
break; break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
this->Detach(e.sender)->Disconnect(); this->Detach(e.sender);
break; break;
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
@ -83,43 +82,48 @@ namespace DanBias
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
{ {
if(dynamic_cast<IPlayerData*> (movedObject)) if(gameSession->networkTimer.getElapsedSeconds() >= DELTA_TIME_60)
{ {
IPlayerData* temp = (IPlayerData*)movedObject; gameSession->networkTimer.reset();
if(dynamic_cast<IPlayerData*> (movedObject))
{
IPlayerData* temp = (IPlayerData*)movedObject;
int id = temp->GetID(); int id = temp->GetID();
Oyster::Math::Float4x4 world = temp->GetOrientation(); Oyster::Math::Float4x4 world = temp->GetOrientation();
Protocol_ObjectPosition p(world, id); Protocol_ObjectPosition p(world, id);
GameSession::gameSession->Send(*p.GetProtocol()); GameSession::gameSession->Send(*p.GetProtocol());
} }
if(dynamic_cast<GameLogic::ILevelData*>(movedObject)) if(dynamic_cast<GameLogic::ILevelData*>(movedObject))
{
GameLogic::IObjectData* obj = NULL;
obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
if(obj)
{ {
if(obj->GetObjectType() == OBJECT_TYPE_WORLD) GameLogic::IObjectData* obj = NULL;
obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
if(obj)
{ {
int id = obj->GetID(); if(obj->GetObjectType() == OBJECT_TYPE_WORLD)
Oyster::Math::Float4x4 world =obj->GetOrientation(); {
int id = obj->GetID();
Oyster::Math::Float4x4 world =obj->GetOrientation();
Protocol_ObjectPosition p(world, id); Protocol_ObjectPosition p(world, id);
GameSession::gameSession->Send(*p.GetProtocol()); gameSession->Send(p.GetProtocol());
}
} }
}
obj = NULL; obj = NULL;
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1); obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1);
if(obj) if(obj)
{
if(obj->GetObjectType() == OBJECT_TYPE_BOX)
{ {
int id = obj->GetID(); if(obj->GetObjectType() == OBJECT_TYPE_BOX)
Oyster::Math::Float4x4 world = obj->GetOrientation(); {
Protocol_ObjectPosition p(world, id); int id = obj->GetID();
GameSession::gameSession->Send(*p.GetProtocol()); Oyster::Math::Float4x4 world = obj->GetOrientation();
Protocol_ObjectPosition p(world, id);
gameSession->Send(p.GetProtocol());
}
} }
} }
} }

View File

@ -28,6 +28,7 @@ namespace DanBias
this->isCreated = false; this->isCreated = false;
this->isRunning = false; this->isRunning = false;
this->gameSession = this; this->gameSession = this;
this->logicDeltaTime = 0.0f;
memset(&this->description, 0, sizeof(GameDescription)); memset(&this->description, 0, sizeof(GameDescription));
} }

View File

@ -284,7 +284,7 @@ HRESOURCE ResourceManager::LoadResource(const wchar_t filename[], LoadFunction l
{ {
return 0; return 0;
} }
if(!loadFnc) if(!loadFnc || !unloadFnc)
{ {
return 0; return 0;
} }
@ -292,6 +292,8 @@ HRESOURCE ResourceManager::LoadResource(const wchar_t filename[], LoadFunction l
ResourceData *t = FindResource(this->resources, filename); ResourceData *t = FindResource(this->resources, filename);
if(t) if(t)
{ {
t->loadFnc = loadFnc;
t->unloadFnc = unloadFnc;
if(force) if(force)
{ {
return ResourceManager::ReloadResource(filename); return ResourceManager::ReloadResource(filename);

View File

@ -40,6 +40,7 @@ namespace Utility
public: public:
Type item; Type item;
Node *next; Node *next;
Node(){ this->next = NULL; };
Node(Type item){ this->item = item; this->next = NULL; }; Node(Type item){ this->item = item; this->next = NULL; };
~Node() {}; ~Node() {};
}; };

View File

@ -4,7 +4,6 @@
#include "CustomNetProtocol.h" #include "CustomNetProtocol.h"
#include <map> #include <map>
#include "Translator.h" #include "Translator.h"
#include "Utilities.h"
using namespace Oyster::Network; using namespace Oyster::Network;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
@ -12,23 +11,17 @@ using namespace Utility::DynamicMemory;
struct CustomNetProtocol::PrivateData struct CustomNetProtocol::PrivateData
{ {
std::map<int, NetAttributeContainer> attributes; //...Im an idiot std::map<int, NetAttributeContainer> attributes; //...Im an idiot
Utility::DynamicMemory::ReferenceCount *c;
PrivateData() PrivateData()
{ { }
//this->attributes = new std::map<int, NetAttributeContainer>();
this->c = new ReferenceCount();
c->Incref();
}
~PrivateData() ~PrivateData()
{ {
delete c;
c = 0;
for (auto i = attributes.begin(); i != attributes.end(); i++) for (auto i = attributes.begin(); i != attributes.end(); i++)
{ {
RemoveAttribute(i->first); RemoveAttribute(i->first);
} }
attributes.clear(); attributes.clear();
} }
void RemoveAttribute(int ID) void RemoveAttribute(int ID)
@ -55,39 +48,14 @@ CustomNetProtocol::CustomNetProtocol()
CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o) CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o)
{ {
this->privateData = o.privateData; this->privateData = o.privateData;
if(this->privateData)
{
this->privateData->c = o.privateData->c;
this->privateData->c->Incref();
}
} }
const CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o) const CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o)
{ {
if(this->privateData && this->privateData->c)
{
if(this->privateData->c->Decref() == 0)
{
delete this->privateData;
}
}
this->privateData = o.privateData; this->privateData = o.privateData;
if(this->privateData)
{
this->privateData->c = o.privateData->c;
this->privateData->c->Incref();
}
return *this; return *this;
} }
CustomNetProtocol::~CustomNetProtocol() CustomNetProtocol::~CustomNetProtocol()
{ {
if(this->privateData && this->privateData->c)
{
if(this->privateData->c->Decref() == 0)
{
delete this->privateData;
}
}
} }
NetAttributeContainer& CustomNetProtocol::operator[](int ID) NetAttributeContainer& CustomNetProtocol::operator[](int ID)
{ {

View File

@ -4,7 +4,11 @@
#ifndef NETWORK_CUSTOM_NETWORK_PROTOCOL_H #ifndef NETWORK_CUSTOM_NETWORK_PROTOCOL_H
#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H #define NETWORK_CUSTOM_NETWORK_PROTOCOL_H
//needs to have dll-interface to be used by clients of class 'Oyster::Network::NetworkSession'
#pragma warning(disable : 4251)
#include <string> #include <string>
#include "Utilities.h"
//#include <vld.h> //#include <vld.h>
#include "NetworkAPI_Preprocessor.h" #include "NetworkAPI_Preprocessor.h"
@ -70,7 +74,7 @@ namespace Oyster
class CustomNetProtocol; class CustomNetProtocol;
struct CustomProtocolObject struct CustomProtocolObject
{ {
virtual CustomNetProtocol* GetProtocol() = 0; virtual CustomNetProtocol GetProtocol() = 0;
}; };
class NET_API_EXPORT CustomNetProtocol class NET_API_EXPORT CustomNetProtocol
@ -88,7 +92,7 @@ namespace Oyster
private: private:
struct PrivateData; struct PrivateData;
PrivateData* privateData; Utility::DynamicMemory::SmartPointer<PrivateData> privateData;
friend class Translator; friend class Translator;
}; };

View File

@ -19,6 +19,7 @@
#include "../../Misc/Packing/Packing.h" #include "../../Misc/Packing/Packing.h"
#include <queue> #include <queue>
#include <WinSock2.h>
using namespace Oyster::Network; using namespace Oyster::Network;
using namespace Oyster::Thread; using namespace Oyster::Thread;
@ -83,12 +84,12 @@ struct NetworkClient::PrivateData : public IThreadObject
if(!this->sendQueue.IsEmpty()) if(!this->sendQueue.IsEmpty())
{ {
SmartPointer<OysterByte> temp = new OysterByte(); OysterByte temp;
CustomNetProtocol p = this->sendQueue.Pop(); CustomNetProtocol p = this->sendQueue.Pop();
this->translator.Pack(temp, p); this->translator.Pack(temp, p);
errorCode = this->connection.Send(temp); errorCode = this->connection.Send(temp);
if(errorCode != 0) if(errorCode != 0 && errorCode != WSAEWOULDBLOCK)
{ {
CEA parg; CEA parg;
parg.type = CEA::EventType_ProtocolFailedToSend; parg.type = CEA::EventType_ProtocolFailedToSend;
@ -299,12 +300,12 @@ void NetworkClient::Disconnect()
void NetworkClient::Send(CustomProtocolObject& protocol) void NetworkClient::Send(CustomProtocolObject& protocol)
{ {
this->privateData->sendQueue.Push(*protocol.GetProtocol()); this->privateData->sendQueue.Push(protocol.GetProtocol());
} }
void NetworkClient::Send(CustomNetProtocol* protocol) void NetworkClient::Send(CustomNetProtocol protocol)
{ {
this->privateData->sendQueue.Push(*protocol); this->privateData->sendQueue.Push(protocol);
} }
void NetworkClient::SetOwner(NetworkSession* owner) void NetworkClient::SetOwner(NetworkSession* owner)

View File

@ -75,7 +75,7 @@ namespace Oyster
/** /**
* *
*/ */
void Send(CustomNetProtocol* protocol); void Send(CustomNetProtocol protocol);
/** /**
* *

View File

@ -26,7 +26,15 @@ struct NetworkSession::PrivateSessionData
{} {}
}; };
int FindClient(NetClientList& list, NetClient c)
{
for (unsigned int i = 0; i < list.Size(); i++)
{
if(c == list[i])
return i;
}
return -1;
}
NetworkSession::NetworkSession() NetworkSession::NetworkSession()
: data(new PrivateSessionData()) : data(new PrivateSessionData())
@ -188,7 +196,7 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol)
{ {
if(this->clients[i]) if(this->clients[i])
{ {
this->clients[i]->Send(&protocol); this->clients[i]->Send(protocol);
returnValue = true; returnValue = true;
} }
} }
@ -202,7 +210,7 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID)
{ {
if(this->clients[i] && this->clients[i]->GetID() == ID) if(this->clients[i] && this->clients[i]->GetID() == ID)
{ {
this->clients[i]->Send(&protocol); this->clients[i]->Send(protocol);
return true; return true;
} }
} }
@ -237,5 +245,8 @@ void NetworkSession::SetOwner(NetworkSession* owner)
void NetworkSession::ClientConnectedEvent(NetClient client) void NetworkSession::ClientConnectedEvent(NetClient client)
{ {
this->Attach(client); this->Attach(client);
if(FindClient(this->clients, client) == -1)
NetworkSession::Attach(client);
} }

View File

@ -15,10 +15,11 @@ using namespace ::Messages;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
using namespace std; using namespace std;
//TODO: Fix this uggly hack
struct MyCastingStruct struct MyCastingStruct
{ {
std::map<int, NetAttributeContainer> attributes; std::map<int, NetAttributeContainer> attributes;
Utility::DynamicMemory::ReferenceCount *c;
}; };
// TODO: Check if the package has been packed correctly. // TODO: Check if the package has been packed correctly.
@ -33,8 +34,8 @@ struct Translator::PrivateData
//Packages a header with a size(int) and a string of characters(char) //Packages a header with a size(int) and a string of characters(char)
void PackHeader(OysterByte &bytes, CustomNetProtocol& protocol) void PackHeader(OysterByte &bytes, CustomNetProtocol& protocol)
{ {
auto it = ((MyCastingStruct*)protocol.privateData)->attributes.begin(); auto it = ((MyCastingStruct*)protocol.privateData.Get())->attributes.begin();
auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end(); auto end = ((MyCastingStruct*)protocol.privateData.Get())->attributes.end();
size = 4; //size(int) size = 4; //size(int)
message.SetSize(0); message.SetSize(0);
@ -60,8 +61,8 @@ struct Translator::PrivateData
void PackMessage(OysterByte &bytes, CustomNetProtocol& protocol) void PackMessage(OysterByte &bytes, CustomNetProtocol& protocol)
{ {
auto it = ((MyCastingStruct*)protocol.privateData)->attributes.begin(); auto it = ((MyCastingStruct*)protocol.privateData.Get())->attributes.begin();
auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end(); auto end = ((MyCastingStruct*)protocol.privateData.Get())->attributes.end();
for(int i = 0; i < (int)headerString.size(); i++, it++) for(int i = 0; i < (int)headerString.size(); i++, it++)
{ {

View File

@ -7,7 +7,7 @@ RWTexture2D<float4> Output;
[numthreads(16, 16, 1)] [numthreads(16, 16, 1)]
void main( uint3 DTid : SV_DispatchThreadID ) void main( uint3 DTid : SV_DispatchThreadID )
{ {
Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy];// + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
//Output[DTid.xy] = Diffuse[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW //Output[DTid.xy] = Diffuse[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
//Output[DTid.xy] = Diffuse[DTid.xy]; //Output[DTid.xy] = Diffuse[DTid.xy];