From ec3c5f129043935de8eaf313df9b48d1cde89425 Mon Sep 17 00:00:00 2001 From: dean11 Date: Mon, 16 Dec 2013 11:05:24 +0100 Subject: [PATCH] Gamelogic - Added threading functionality to NetworkClient --- Code/Misc/Thread/OysterThread.h | 2 ++ Code/Misc/Thread/OysterThread_Impl.cpp | 8 +++++++- Code/Network/NetworkAPI/NetworkAPI.vcxproj | 4 +++- Code/Network/NetworkAPI/NetworkClient.cpp | 7 ++++++- Code/Network/NetworkAPI/NetworkClient.h | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Code/Misc/Thread/OysterThread.h b/Code/Misc/Thread/OysterThread.h index 805dea3b..51f1cf6e 100644 --- a/Code/Misc/Thread/OysterThread.h +++ b/Code/Misc/Thread/OysterThread.h @@ -47,6 +47,8 @@ namespace Oyster OYSTER_THREAD_ERROR Swap(const OysterThread* other); bool IsActive(); void SetPriority(OYSTER_THREAD_PRIORITY priority); + + bool IsCreated() const; }; } } diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index ab829adf..b8a9b962 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -59,10 +59,12 @@ using namespace Utility::DynamicMemory; }; struct OysterThread::PrivateData { + bool isCreated; SmartPointer threadData; PrivateData() { + isCreated = false; threadData = new ThreadData(); threadData->first = true; threadData->owner = 0; @@ -73,6 +75,7 @@ using namespace Utility::DynamicMemory; } PrivateData(const PrivateData& o) { + isCreated = o.isCreated; threadData = o.threadData; } const PrivateData& operator=(const PrivateData& o) @@ -276,4 +279,7 @@ void OysterThread::SetPriority(OYSTER_THREAD_PRIORITY priority) { this->privateData->threadData->prio = priority; } - +bool OysterThread::IsCreated() const +{ + return privateData->isCreated; +} diff --git a/Code/Network/NetworkAPI/NetworkAPI.vcxproj b/Code/Network/NetworkAPI/NetworkAPI.vcxproj index 78e11523..a53ef673 100644 --- a/Code/Network/NetworkAPI/NetworkAPI.vcxproj +++ b/Code/Network/NetworkAPI/NetworkAPI.vcxproj @@ -78,7 +78,7 @@ true C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) - C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath) $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(SolutionDir)..\Bin\DLL\ $(ProjectName)_$(PlatformShortName)D @@ -88,12 +88,14 @@ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(SolutionDir)..\Bin\DLL\ $(ProjectName)_$(PlatformShortName) + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) false $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(SolutionDir)..\Bin\DLL\ $(ProjectName)_$(PlatformShortName) + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index e99ab502..924416aa 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -166,6 +166,7 @@ NetworkClient::NetworkClient() NetworkClient::NetworkClient(unsigned int socket) { privateData = new PrivateData(socket); + this->privateData->data->thread.Create(this->privateData, true); } NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type) @@ -179,6 +180,7 @@ NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType privateData = new PrivateData(socket); this->privateData->data->recvObj = SmartPointer(&recvObj); this->privateData->data->callbackType = type; + this->privateData->data->thread.Create(this->privateData, true); } NetworkClient::NetworkClient(const NetworkClient& obj) @@ -209,7 +211,10 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[]) //Connect has succeeded if(result == 0) { - privateData->data->thread.Start(); + if(this->privateData->data->thread.IsCreated()) return false; + + this->privateData->data->thread.Create(this->privateData, true); + return true; } diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 95463d1c..e77667a8 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -12,7 +12,7 @@ #endif #include "NetworkCallbackHelper.h" -#include +//#include namespace Oyster {