Skip to content

Commit

Permalink
Fixed compilation error using C++20 standard (PR #1048).
Browse files Browse the repository at this point in the history
  • Loading branch information
cbnolok committed Oct 23, 2023
1 parent 0b845d3 commit 3cfa824
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
14 changes: 1 addition & 13 deletions src/common/sphere_library/CSAssoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ struct CElementDef
ELEM_TYPE m_type;
uint m_offset; // The offset into the class instance for this item.

CElementDef() = default;
~CElementDef() = default;
CElementDef(const CElementDef&) = delete;
CElementDef& operator=(const CElementDef& other) = delete;

// get structure value.
void * GetValPtr( const void * pBaseInst ) const;
int GetValLength() const;
Expand All @@ -77,21 +72,14 @@ struct CElementDef
bool SetValStr( void * pBase, lpctstr pszVal ) const;
};

class CAssocReg // associate members of some class/structure with entries in the registry.
struct CAssocReg // associate members of some class/structure with entries in the registry.
{
// LAST = { nullptr, 0, ELEM_VOID }
public:
static const char* m_sClassName;

lpctstr m_pszKey; // A single key identifier to be cat to a base key. nullptr=last
CElementDef m_elem;

public:
CAssocReg() = default;
~CAssocReg() = default;
CAssocReg(const CAssocReg&) = delete;
CAssocReg& operator=(const CAssocReg& other) = delete;

operator lpctstr() const
{
return m_pszKey;
Expand Down
10 changes: 10 additions & 0 deletions src/common/sphere_library/ssorted_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
// Sphere library
namespace sl
{
<<<<<<< HEAD
#if __cplusplus >= 202002L
// C++20 (and later) code
consteval
#else
constexpr
#endif
size_t scont_bad_index() noexcept {
=======
inline constexpr size_t scont_bad_index() noexcept {
>>>>>>> 0b845d3654874fde1e04f7eba69d5588a41cc19d
return size_t(-1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/CServerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ enum RC_TYPE
RC_QTY
};

const CAssocReg CServerConfig::sm_szLoadKeys[RC_QTY+1] =
const CAssocReg CServerConfig::sm_szLoadKeys[RC_QTY+1]
{
{ "ACCTFILES", { ELEM_CSTRING, static_cast<uint>OFFSETOF(CServerConfig,m_sAcctBaseDir) }},
{ "ADVANCEDLOS", { ELEM_INT, static_cast<uint>OFFSETOF(CServerConfig,m_iAdvancedLos) }},
Expand Down
24 changes: 12 additions & 12 deletions src/game/CWorldMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,14 +969,14 @@ void CWorldMap::GetFixPoint( const CPointMap & pt, CServerMapBlockState & block)
if ((z < pt.m_z + PLAYER_HEIGHT) && (dwBlockThis & (CAN_I_PLATFORM|CAN_I_CLIMB|CAN_I_WATER)))
{
block.m_Bottom.m_dwBlockFlags = dwBlockThis;
block.m_Bottom.m_dwTile = iDispID + TERRAIN_QTY;
block.m_Bottom.m_dwTile = iDispID + (ITEMID_TYPE)TERRAIN_QTY;
block.m_Bottom.m_z = z;
// Leave block->...->m_height unchanged, since it already has the height of the char/item
}
else if (block.m_Top.m_z > z)
{
block.m_Top.m_dwBlockFlags = dwBlockThis;
block.m_Top.m_dwTile = iDispID + TERRAIN_QTY;
block.m_Top.m_dwTile = iDispID + (ITEMID_TYPE)TERRAIN_QTY;
block.m_Top.m_z = z;
// Leave block->...->m_height unchanged, since it already has the height of the char/item
}
Expand Down Expand Up @@ -1071,14 +1071,14 @@ void CWorldMap::GetFixPoint( const CPointMap & pt, CServerMapBlockState & block)
if ((z < pt.m_z + PLAYER_HEIGHT) && (dwBlockThis & (CAN_I_PLATFORM|CAN_I_CLIMB|CAN_I_WATER)))
{
block.m_Bottom.m_dwBlockFlags = dwBlockThis;
block.m_Bottom.m_dwTile = iDispID + TERRAIN_QTY;
block.m_Bottom.m_dwTile = iDispID + (ITEMID_TYPE)TERRAIN_QTY;
block.m_Bottom.m_z = z;
// Leave block->...->m_height unchanged, since it already has the height of the char/item
}
else if (block.m_Top.m_z > z)
{
block.m_Top.m_dwBlockFlags = dwBlockThis;
block.m_Top.m_dwTile = iDispID + TERRAIN_QTY;
block.m_Top.m_dwTile = iDispID + (ITEMID_TYPE)TERRAIN_QTY;
block.m_Top.m_z = z;
// Leave block->...->m_height unchanged, since it already has the height of the char/item
}
Expand Down Expand Up @@ -1141,14 +1141,14 @@ void CWorldMap::GetFixPoint( const CPointMap & pt, CServerMapBlockState & block)
if ( (z < pt.m_z + PLAYER_HEIGHT) && (dwBlockThis & (CAN_I_PLATFORM|CAN_I_CLIMB|CAN_I_WATER)) )
{
block.m_Bottom.m_dwBlockFlags = dwBlockThis;
block.m_Bottom.m_dwTile = pItemDef->GetDispID() + TERRAIN_QTY;
block.m_Bottom.m_dwTile = pItemDef->GetDispID() + (ITEMID_TYPE)TERRAIN_QTY;
block.m_Bottom.m_z = z;
// Leave block->...->m_height unchanged, since it already has the height of the char/item
}
else if ( block.m_Top.m_z > z )
{
block.m_Top.m_dwBlockFlags = dwBlockThis;
block.m_Top.m_dwTile = pItemDef->GetDispID() + TERRAIN_QTY;
block.m_Top.m_dwTile = pItemDef->GetDispID() + (ITEMID_TYPE)TERRAIN_QTY;
block.m_Top.m_z = z;
// Leave block->...->m_height unchanged, since it already has the height of the char/item
}
Expand Down Expand Up @@ -1288,7 +1288,7 @@ void CWorldMap::GetHeightPoint(const CPointMap & pt, CServerMapBlockState & bloc

// This static is at the coordinates in question.
// enough room for me to stand here ?
block.CheckTile_Item( dwBlockThis, z, zHeight, iDispID + TERRAIN_QTY );
block.CheckTile_Item( dwBlockThis, z, zHeight, iDispID + (ITEMID_TYPE)TERRAIN_QTY );
}
}

Expand Down Expand Up @@ -1379,7 +1379,7 @@ void CWorldMap::GetHeightPoint(const CPointMap & pt, CServerMapBlockState & bloc
CItemBase::GetItemTiledataFlags(&dwBlockThis, iDispID);
}

block.CheckTile_Item( dwBlockThis, z, zHeight, iDispID + TERRAIN_QTY );
block.CheckTile_Item( dwBlockThis, z, zHeight, iDispID + (ITEMID_TYPE)TERRAIN_QTY );
}
}
}
Expand Down Expand Up @@ -1440,7 +1440,7 @@ void CWorldMap::GetHeightPoint(const CPointMap & pt, CServerMapBlockState & bloc
CItemBase::GetItemTiledataFlags(&dwBlockThis, iDispID);
}

block.CheckTile_Item(dwBlockThis, z, zHeight, iDispID + TERRAIN_QTY);
block.CheckTile_Item(dwBlockThis, z, zHeight, iDispID + (ITEMID_TYPE)TERRAIN_QTY);
}

dwBlockThis = 0;
Expand Down Expand Up @@ -1591,7 +1591,7 @@ void CWorldMap::GetHeightPoint2( const CPointMap & pt, CServerMapBlockState & bl

// This static is at the coordinates in question.
// enough room for me to stand here ?
block.CheckTile( dwBlockThis, z, zHeight, iDispID + TERRAIN_QTY );
block.CheckTile( dwBlockThis, z, zHeight, iDispID + (ITEMID_TYPE)TERRAIN_QTY );
}
}

Expand Down Expand Up @@ -1631,7 +1631,7 @@ void CWorldMap::GetHeightPoint2( const CPointMap & pt, CServerMapBlockState & bl
const ITEMID_TYPE iDispID = pMultiItem->GetDispID();
height_t zHeight = CItemBase::GetItemHeight( iDispID, &dwBlockThis );

block.CheckTile( dwBlockThis, zitem, zHeight, iDispID + TERRAIN_QTY );
block.CheckTile( dwBlockThis, zitem, zHeight, iDispID + (ITEMID_TYPE)TERRAIN_QTY );
}
}
}
Expand Down Expand Up @@ -1667,7 +1667,7 @@ void CWorldMap::GetHeightPoint2( const CPointMap & pt, CServerMapBlockState & bl
if (zHeight == 0)
zHeight = zStaticHeight;

if ( !block.CheckTile(dwBlockThis, zitem, zHeight, pItemDef->GetDispID() + TERRAIN_QTY ) )
if ( !block.CheckTile(dwBlockThis, zitem, zHeight, pItemDef->GetDispID() + (ITEMID_TYPE)TERRAIN_QTY ) )
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/uo_files/uofiles_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ enum GUMP_TYPE // The gumps. (most of these are not useful to the server.)
GUMP_OPEN_SPELLBOOK = 0xFFFF
};

enum
enum TERRAINID_TYPE
{
// Terrain samples
TERRAIN_HOLE = 0x0002, // "NODRAW" we can pas thru this.
Expand Down
15 changes: 9 additions & 6 deletions src/sphere/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _WIN32_DCOM

#include <algorithm>
#include <atomic>
#include "../common/CException.h"
#include "../common/common.h"
#include "../common/CLog.h"
Expand All @@ -28,12 +29,12 @@

// Normal Buffer
SimpleMutex g_tmpStringMutex;
volatile int g_tmpStringIndex = 0;
std::atomic<int> g_tmpStringIndex = 0;
char g_tmpStrings[THREAD_TSTRING_STORAGE][THREAD_STRING_LENGTH];

// TemporaryString Buffer
SimpleMutex g_tmpTemporaryStringMutex;
volatile int g_tmpTemporaryStringIndex = 0;
std::atomic<int> g_tmpTemporaryStringIndex = 0;

struct TemporaryStringStorage
{
Expand Down Expand Up @@ -395,7 +396,7 @@ bool AbstractThread::isActive() const

void AbstractThread::waitForClose()
{
// Another thread has requested us to close and it's waiting for us to complete the current tick,
// Another thread has requested us to close and it's waiting for us to complete the current tick,
// or to forcefully be forcefully terminated after a THREADJOIN_TIMEOUT, which of the two happens first.

// TODO? add a mutex here to protect at least the changes to m_terminateRequested?
Expand Down Expand Up @@ -546,7 +547,7 @@ char *AbstractSphereThread::allocateBuffer()

if( g_tmpStringIndex >= THREAD_TSTRING_STORAGE )
{
g_tmpStringIndex %= THREAD_TSTRING_STORAGE;
g_tmpStringIndex = g_tmpStringIndex % THREAD_TSTRING_STORAGE;
}

buffer = g_tmpStrings[g_tmpStringIndex];
Expand All @@ -564,7 +565,9 @@ TemporaryStringStorage *AbstractSphereThread::allocateStringBuffer()
index = ++g_tmpTemporaryStringIndex;
if( g_tmpTemporaryStringIndex >= THREAD_STRING_STORAGE )
{
index = g_tmpTemporaryStringIndex %= THREAD_STRING_STORAGE;
const int inc = g_tmpTemporaryStringIndex % THREAD_STRING_STORAGE;
g_tmpTemporaryStringIndex = inc;
index = inc;
}

if( g_tmpTemporaryStringStorage[index].m_state == 0 )
Expand Down Expand Up @@ -638,7 +641,7 @@ void AbstractSphereThread::printStackTrace()
{
// don't allow call stack to be modified whilst we're printing it
freezeCallStack(true);

const uint64_t threadId = static_cast<uint64_t>(getId());
const lpctstr threadName = getName();

Expand Down

0 comments on commit 3cfa824

Please sign in to comment.