Now I am writing code that enables HGE to support the network...
This part of code is currently being written this week .. That is, today ..
However, if you want to compile the network. You have to add a line of code in the hge. h file,
1: and add it before # include <windows. h>.
# Define WIN32_LEAN_AND_MEAN # include <windows. h>
Because our network interface will reference the file winsock2.h. This is required ..
2: many codes have reversed min and max. I don't think it's a good thing. We can write one by ourselves:
# Define t_min (x, y) (x) <(y ))? (X): (y)
# Define t_max (x, y) (x)> (y ))? (X): (y)
Instead of dropping # unidef.
3: We will make the network part run in multi-thread mode.
So the following code will use. lock. h:
# Pragma once
# Include <assert. h>
// Configure //-----------------------------------------------------------------------------------------------
// TCriticalSection
// Configure //-----------------------------------------------------------------------------------------------
Class tCriticalSection
{
Public:
// Construct
TCriticalSection () {InitializeCriticalSection (& m_CritSect );}
// Structure
~ TCriticalSection () {DeleteCriticalSection (& m_CritSect );}
Public:
// Lock the critical lock
Void Lock () {EnterCriticalSection (& m_CritSect );}
// Unlock the critical lock
Void Unlock () {LeaveCriticalSection (& m_CritSect );}
Private:
CRITICAL_SECTION m_CritSect; // critical Lock Object
};
// Configure //-----------------------------------------------------------------------------------------------
// TAutoLock class, mutex class
// Configure //-----------------------------------------------------------------------------------------------
Class tAutoLock
{
Public:
TAutoLock (tCriticalSection * pLock)
{
Assert (pLock! = NULL );
M_pLock = pLock;
PLock-> Lock ();
M_LockNums = 1;
}
~ TAutoLock ()
{
Assert (m_pLock! = NULL );
While (m_LockNums> 0)
{
M_pLock-> Unlock ();
M_LockNums --;
}
}
Void Lock ()
{
Assert (m_pLock! = NULL );
M_pLock-> Lock ();
M_LockNums ++;
}
Void Unlock ()
{
Assert (m_pLock! = NULL );
If (m_LockNums> 0)
{
M_pLock-> Unlock ();
M_LockNums --;
}
}
Private:
TCriticalSection * m_pLock;
Int m_LockNums;
};
Reprinted with the source: original BLOG (ShowLong)
Okay. Other code I am writing ing... will be published soon.