Gamelogic - Added threading functionality to NetworkClient
This commit is contained in:
parent
b351a7bac4
commit
ec3c5f1290
|
@ -47,6 +47,8 @@ namespace Oyster
|
|||
OYSTER_THREAD_ERROR Swap(const OysterThread* other);
|
||||
bool IsActive();
|
||||
void SetPriority(OYSTER_THREAD_PRIORITY priority);
|
||||
|
||||
bool IsCreated() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,10 +59,12 @@ using namespace Utility::DynamicMemory;
|
|||
};
|
||||
struct OysterThread::PrivateData
|
||||
{
|
||||
bool isCreated;
|
||||
SmartPointer<ThreadData> 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;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
|
@ -88,12 +88,14 @@
|
|||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
|
|
|
@ -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<RecieverObject>(&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;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#endif
|
||||
|
||||
#include "NetworkCallbackHelper.h"
|
||||
#include <vld.h>
|
||||
//#include <vld.h>
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue