diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index d9726205..6a79fc0b 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -56,7 +56,8 @@ namespace DanBias { 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; if( FAILED( InitDirect3D() ) ) @@ -200,6 +201,8 @@ namespace DanBias delete m_data->recieverObj; delete m_data->inputObj; delete m_data; + + GameServerAPI::ServerStop(); Oyster::Graphics::API::Clean(); diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index cd281717..c1b9da91 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -33,7 +33,8 @@ GameState::GameState(void) GameState::~GameState(void) { - + delete this->camera; + delete this->privData; } bool GameState::Init(Oyster::Network::NetworkClient* nwClient) { @@ -82,7 +83,7 @@ bool GameState::LoadModels(std::wstring mapFile) C_Object* obj; translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0)); modelData.world = translate ;//modelData.world * translate - modelData.modelPath = L"world_earth.dan"; + modelData.modelPath = L"..\\Content\\Models\\world_earth.dan"; modelData.id = 0; obj = new C_Player(); diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index d9973821..badd7328 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -93,7 +93,6 @@ void Game::CreateTeam() bool Game::NewFrame() { - for (unsigned int i = 0; i < this->players.Size(); i++) { 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(); } - 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); @@ -161,6 +139,7 @@ bool Game::Initiate() { API::Instance().Init((int)pow(2u, 9u), 1u, Oyster::Math::Float3()); API::Instance().SetSubscription(Game::PhysicsOnDestroy); + API::Instance().SetFrameTimeLength(1.0f/120.0f); this->initiated = true; return true; } diff --git a/Code/Game/GameProtocols/GeneralProtocols.h b/Code/Game/GameProtocols/GeneralProtocols.h index 02763ba0..0353d63f 100644 --- a/Code/Game/GameProtocols/GeneralProtocols.h +++ b/Code/Game/GameProtocols/GeneralProtocols.h @@ -36,11 +36,11 @@ namespace GameLogic this->status = state; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = status; - return &protocol; + return protocol; } private: @@ -59,12 +59,12 @@ namespace GameLogic destination = p.Get(1).value.netInt; 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(1, destination, Oyster::Network::NetAttributeType_Int); this->protocol.Set(2, text); - return &protocol; + return protocol; } private: diff --git a/Code/Game/GameProtocols/LobbyProtocols.h b/Code/Game/GameProtocols/LobbyProtocols.h index 192d81f2..3c173849 100644 --- a/Code/Game/GameProtocols/LobbyProtocols.h +++ b/Code/Game/GameProtocols/LobbyProtocols.h @@ -33,7 +33,7 @@ namespace GameLogic mapName = o[1].value.netCharPtr; gameId = o[2].value.netChar; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { protocol[1].value = mapName; protocol[2].value = gameId; @@ -59,10 +59,10 @@ namespace GameLogic { gameId = o[1].value.netInt; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { protocol[1].value = gameId; - return &protocol; + return protocol; } private: @@ -83,9 +83,9 @@ namespace GameLogic { } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { - return &protocol; + return protocol; } private: @@ -109,7 +109,7 @@ namespace GameLogic // this->protocol[1].type = Oyster::Network::NetAttributeType_Short; // value = p[1].value.netShort; // } - // Oyster::Network::CustomNetProtocol* GetProtocol() override + // Oyster::Network::CustomNetProtocol GetProtocol() override // { // protocol[1].value = value; // return &protocol; @@ -130,8 +130,8 @@ namespace GameLogic { } - Oyster::Network::CustomNetProtocol* GetProtocol() override - { return &protocol; } + Oyster::Network::CustomNetProtocol GetProtocol() override + { return protocol; } private: Oyster::Network::CustomNetProtocol protocol; @@ -175,7 +175,7 @@ namespace GameLogic list.Push(d); } } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = list.Size(); @@ -195,7 +195,7 @@ namespace GameLogic this->protocol.Set(a++, list[i].ip); } - return &protocol; + return protocol; } private: @@ -223,13 +223,13 @@ namespace GameLogic minorVersion = (int)p.Get(2).value.netInt; mapName = p.Get(3).value.netCharPtr; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = majorVersion; this->protocol[2].value = minorVersion; this->protocol.Set(3, mapName.c_str()); - return &protocol; + return protocol; } private: @@ -254,7 +254,7 @@ namespace GameLogic // { // // } - // Oyster::Network::CustomNetProtocol* GetProtocol() override + // Oyster::Network::CustomNetProtocol GetProtocol() override // { // return &protocol; // } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index b71599b1..ca8bb362 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -39,11 +39,11 @@ namespace GameLogic pickup_ID = pickupID; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = object_ID; this->protocol[2].value = pickup_ID; - return &protocol; + return protocol; } private: @@ -80,11 +80,11 @@ namespace GameLogic object_ID = id; health = hp; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = object_ID; this->protocol[2].value = health; - return &protocol; + return protocol; } private: @@ -129,14 +129,14 @@ namespace GameLogic object_ID = id; memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); } - Oyster::Network::CustomNetProtocol* GetProtocol() override + 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; + return protocol; } private: @@ -179,14 +179,14 @@ namespace GameLogic object_ID = id; memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); } - Oyster::Network::CustomNetProtocol* GetProtocol() override + 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; + return protocol; } private: @@ -221,11 +221,11 @@ namespace GameLogic object_ID = id; timer = time; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = object_ID; this->protocol[2].value = timer; - return &protocol; + return protocol; } private: @@ -272,7 +272,7 @@ namespace GameLogic this->name = path; memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = object_ID; @@ -297,7 +297,7 @@ namespace GameLogic - return &protocol; + return protocol; } private: diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 2413aa92..361b8d6e 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -49,14 +49,14 @@ namespace GameLogic return *this; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = bForward; this->protocol[2].value = bBackward; this->protocol[3].value = bLeft; this->protocol[4].value = bRight; - return &protocol; + return protocol; } private: @@ -94,13 +94,13 @@ namespace GameLogic return *this; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = lookDirX; this->protocol[2].value = lookDirY; this->protocol[3].value = lookDirZ; - return &protocol; + return protocol; } private: @@ -125,9 +125,9 @@ namespace GameLogic { return *this; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { - return &protocol; + return protocol; } private: @@ -154,10 +154,10 @@ namespace GameLogic hasShot = val[1].value.netBool; return *this; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = hasShot; - return &protocol; + return protocol; } private: @@ -184,10 +184,10 @@ namespace GameLogic hasJumped = val[1].value.netBool; return *this; } - Oyster::Network::CustomNetProtocol* GetProtocol() override + Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = hasJumped; - return &protocol; + return protocol; } private: diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index 8a421e1d..b5213518 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -52,6 +52,7 @@ namespace DanBias private: Utility::WinTimer timer; float refreshFrequency; + GameSession gameSession; LobbyLevelData description; }; diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 899bc189..14144aaa 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -55,6 +55,7 @@ namespace DanBias inline bool IsCreated() const { return this->isCreated; } inline bool IsRunning() const { return this->isRunning; } + operator bool() { return (this->isCreated && this->isCreated); } //Private member functions private: @@ -97,7 +98,9 @@ namespace DanBias NetworkSession* owner; bool isCreated; bool isRunning; - Utility::WinTimer timer; + float logicDeltaTime; + Utility::WinTimer logicTimer; + Utility::WinTimer networkTimer; GameDescription description; //TODO: Remove this uggly hax diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index b68846d4..4a064a26 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -17,7 +17,9 @@ namespace DanBias { } GameLobby::~GameLobby() - { } + { + this->clients.Clear(); + } void GameLobby::Release() { @@ -27,7 +29,7 @@ namespace DanBias void GameLobby::Update() { 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(); } @@ -85,29 +87,36 @@ namespace DanBias void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) { printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); - Attach(client); - Protocol_LobbyClientData p1; - Protocol_LobbyGameData p2; - - for (unsigned int i = 0; i < this->clients.Size(); i++) + if(this->gameSession) { - 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ÄrKung"; - p1.list.Push(t); - } + this->gameSession.ClientConnectedEvent(client); } - p2.majorVersion = 1; - p2.minorVersion = 0; - p2.mapName = "BetsMap"; + else + { + 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(p2.GetProtocol()); + client->Send(p1.GetProtocol()); + client->Send(p2.GetProtocol()); + } } }//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index 416503e5..670f7888 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -53,6 +53,7 @@ void GameServerAPI::ServerStart() } void GameServerAPI::ServerStop() { + if(!server.IsStarted()) return; lobby.Release(); server.Shutdown(); diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index f68aad4b..c8594074 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -29,16 +29,15 @@ namespace DanBias { if(this->isRunning) { - double dt = this->timer.getElapsedSeconds(); - gameInstance.SetFrameTimeLength((float)dt); - - if(dt >= DELTA_TIME_20) + float dt = (float)this->logicTimer.getElapsedSeconds(); + this->logicDeltaTime += dt; + this->logicTimer.reset(); + while( logicDeltaTime >= DELTA_TIME_120 ) { this->ProcessClients(); - this->gameInstance.NewFrame(); - this->timer.reset(); + logicDeltaTime -= DELTA_TIME_120; } } @@ -72,7 +71,7 @@ namespace DanBias break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: 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; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: 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) { - if(dynamic_cast (movedObject)) + if(gameSession->networkTimer.getElapsedSeconds() >= DELTA_TIME_60) { - IPlayerData* temp = (IPlayerData*)movedObject; + gameSession->networkTimer.reset(); + + if(dynamic_cast (movedObject)) + { + IPlayerData* temp = (IPlayerData*)movedObject; - int id = temp->GetID(); - Oyster::Math::Float4x4 world = temp->GetOrientation(); + int id = temp->GetID(); + Oyster::Math::Float4x4 world = temp->GetOrientation(); - Protocol_ObjectPosition p(world, id); - GameSession::gameSession->Send(*p.GetProtocol()); + Protocol_ObjectPosition p(world, id); + GameSession::gameSession->Send(*p.GetProtocol()); } if(dynamic_cast(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(); - Oyster::Math::Float4x4 world =obj->GetOrientation(); + if(obj->GetObjectType() == OBJECT_TYPE_WORLD) + { + int id = obj->GetID(); + Oyster::Math::Float4x4 world =obj->GetOrientation(); - Protocol_ObjectPosition p(world, id); - GameSession::gameSession->Send(*p.GetProtocol()); + Protocol_ObjectPosition p(world, id); + gameSession->Send(p.GetProtocol()); + } } - } - obj = NULL; - obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1); - if(obj) - { - if(obj->GetObjectType() == OBJECT_TYPE_BOX) + obj = NULL; + obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1); + if(obj) { - int id = obj->GetID(); - Oyster::Math::Float4x4 world = obj->GetOrientation(); - Protocol_ObjectPosition p(world, id); - GameSession::gameSession->Send(*p.GetProtocol()); + if(obj->GetObjectType() == OBJECT_TYPE_BOX) + { + int id = obj->GetID(); + Oyster::Math::Float4x4 world = obj->GetOrientation(); + Protocol_ObjectPosition p(world, id); + gameSession->Send(p.GetProtocol()); + } } } } diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index ae947874..dfd0617f 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -28,6 +28,7 @@ namespace DanBias this->isCreated = false; this->isRunning = false; this->gameSession = this; + this->logicDeltaTime = 0.0f; memset(&this->description, 0, sizeof(GameDescription)); } diff --git a/Code/Misc/Resource/ResourceManager.cpp b/Code/Misc/Resource/ResourceManager.cpp index 67776888..0112f872 100644 --- a/Code/Misc/Resource/ResourceManager.cpp +++ b/Code/Misc/Resource/ResourceManager.cpp @@ -284,7 +284,7 @@ HRESOURCE ResourceManager::LoadResource(const wchar_t filename[], LoadFunction l { return 0; } - if(!loadFnc) + if(!loadFnc || !unloadFnc) { return 0; } @@ -292,6 +292,8 @@ HRESOURCE ResourceManager::LoadResource(const wchar_t filename[], LoadFunction l ResourceData *t = FindResource(this->resources, filename); if(t) { + t->loadFnc = loadFnc; + t->unloadFnc = unloadFnc; if(force) { return ResourceManager::ReloadResource(filename); diff --git a/Code/Misc/ThreadSafeQueue.h b/Code/Misc/ThreadSafeQueue.h index 3afb1cb3..2bbd042f 100644 --- a/Code/Misc/ThreadSafeQueue.h +++ b/Code/Misc/ThreadSafeQueue.h @@ -40,6 +40,7 @@ namespace Utility public: Type item; Node *next; + Node(){ this->next = NULL; }; Node(Type item){ this->item = item; this->next = NULL; }; ~Node() {}; }; diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index 2ac6fcf5..1762bf86 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -4,7 +4,6 @@ #include "CustomNetProtocol.h" #include #include "Translator.h" -#include "Utilities.h" using namespace Oyster::Network; using namespace Utility::DynamicMemory; @@ -12,23 +11,17 @@ using namespace Utility::DynamicMemory; struct CustomNetProtocol::PrivateData { std::map attributes; //...Im an idiot - Utility::DynamicMemory::ReferenceCount *c; - + PrivateData() - { - //this->attributes = new std::map(); - this->c = new ReferenceCount(); - c->Incref(); - } + { } ~PrivateData() { - delete c; - c = 0; for (auto i = attributes.begin(); i != attributes.end(); i++) { RemoveAttribute(i->first); } + attributes.clear(); } void RemoveAttribute(int ID) @@ -55,39 +48,14 @@ CustomNetProtocol::CustomNetProtocol() CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o) { this->privateData = o.privateData; - if(this->privateData) - { - this->privateData->c = o.privateData->c; - this->privateData->c->Incref(); - } } 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; - if(this->privateData) - { - this->privateData->c = o.privateData->c; - this->privateData->c->Incref(); - } return *this; } CustomNetProtocol::~CustomNetProtocol() { - if(this->privateData && this->privateData->c) - { - if(this->privateData->c->Decref() == 0) - { - delete this->privateData; - } - } } NetAttributeContainer& CustomNetProtocol::operator[](int ID) { diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index 8e531f17..c519e417 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -4,7 +4,11 @@ #ifndef 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 +#include "Utilities.h" //#include #include "NetworkAPI_Preprocessor.h" @@ -70,7 +74,7 @@ namespace Oyster class CustomNetProtocol; struct CustomProtocolObject { - virtual CustomNetProtocol* GetProtocol() = 0; + virtual CustomNetProtocol GetProtocol() = 0; }; class NET_API_EXPORT CustomNetProtocol @@ -88,7 +92,7 @@ namespace Oyster private: struct PrivateData; - PrivateData* privateData; + Utility::DynamicMemory::SmartPointer privateData; friend class Translator; }; diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index d7ec5d34..4434d28c 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -19,6 +19,7 @@ #include "../../Misc/Packing/Packing.h" #include +#include using namespace Oyster::Network; using namespace Oyster::Thread; @@ -83,12 +84,12 @@ struct NetworkClient::PrivateData : public IThreadObject if(!this->sendQueue.IsEmpty()) { - SmartPointer temp = new OysterByte(); + OysterByte temp; CustomNetProtocol p = this->sendQueue.Pop(); this->translator.Pack(temp, p); errorCode = this->connection.Send(temp); - if(errorCode != 0) + if(errorCode != 0 && errorCode != WSAEWOULDBLOCK) { CEA parg; parg.type = CEA::EventType_ProtocolFailedToSend; @@ -299,12 +300,12 @@ void NetworkClient::Disconnect() 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) diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index dfe247de..3af8baf1 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -75,7 +75,7 @@ namespace Oyster /** * */ - void Send(CustomNetProtocol* protocol); + void Send(CustomNetProtocol protocol); /** * diff --git a/Code/Network/NetworkAPI/NetworkSession.cpp b/Code/Network/NetworkAPI/NetworkSession.cpp index c7bf15ba..6c728903 100644 --- a/Code/Network/NetworkAPI/NetworkSession.cpp +++ b/Code/Network/NetworkAPI/NetworkSession.cpp @@ -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() : data(new PrivateSessionData()) @@ -188,7 +196,7 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol) { if(this->clients[i]) { - this->clients[i]->Send(&protocol); + this->clients[i]->Send(protocol); returnValue = true; } } @@ -202,7 +210,7 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID) { if(this->clients[i] && this->clients[i]->GetID() == ID) { - this->clients[i]->Send(&protocol); + this->clients[i]->Send(protocol); return true; } } @@ -237,5 +245,8 @@ void NetworkSession::SetOwner(NetworkSession* owner) void NetworkSession::ClientConnectedEvent(NetClient client) { this->Attach(client); + + if(FindClient(this->clients, client) == -1) + NetworkSession::Attach(client); } diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp index 9b855d47..cab1d48b 100644 --- a/Code/Network/NetworkAPI/Translator.cpp +++ b/Code/Network/NetworkAPI/Translator.cpp @@ -15,10 +15,11 @@ using namespace ::Messages; using namespace Utility::DynamicMemory; using namespace std; + +//TODO: Fix this uggly hack struct MyCastingStruct { std::map attributes; - Utility::DynamicMemory::ReferenceCount *c; }; // 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) void PackHeader(OysterByte &bytes, CustomNetProtocol& protocol) { - auto it = ((MyCastingStruct*)protocol.privateData)->attributes.begin(); - auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end(); + auto it = ((MyCastingStruct*)protocol.privateData.Get())->attributes.begin(); + auto end = ((MyCastingStruct*)protocol.privateData.Get())->attributes.end(); size = 4; //size(int) message.SetSize(0); @@ -60,8 +61,8 @@ struct Translator::PrivateData void PackMessage(OysterByte &bytes, CustomNetProtocol& protocol) { - auto it = ((MyCastingStruct*)protocol.privateData)->attributes.begin(); - auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end(); + auto it = ((MyCastingStruct*)protocol.privateData.Get())->attributes.begin(); + auto end = ((MyCastingStruct*)protocol.privateData.Get())->attributes.end(); for(int i = 0; i < (int)headerString.size(); i++, it++) { diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl index 3e03dfcd..80754311 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl @@ -7,7 +7,7 @@ RWTexture2D Output; [numthreads(16, 16, 1)] 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];