mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-25 16:26:18 +00:00
Changed: Use a global C64BitsParts union to avoid strict aliasing warnings
This commit is contained in:
parent
44c4aac649
commit
73663e30dc
10 changed files with 71 additions and 98 deletions
|
@ -714,6 +714,25 @@ inline T iavoid0(T x)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper to convert in memory between types of different sizes
|
||||||
|
union C64BitsParts
|
||||||
|
{
|
||||||
|
// unsigned
|
||||||
|
uint64 u64[1];
|
||||||
|
uint32 u32[2];
|
||||||
|
uint16 u16[4];
|
||||||
|
uint8 u8[8];
|
||||||
|
|
||||||
|
// signed
|
||||||
|
sint64 i64[1];
|
||||||
|
sint32 i32[2];
|
||||||
|
sint16 i16[4];
|
||||||
|
sint8 i8[8];
|
||||||
|
|
||||||
|
// floats
|
||||||
|
double d[1];
|
||||||
|
float f[2];
|
||||||
|
};
|
||||||
|
|
||||||
} // NLMISC
|
} // NLMISC
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "nel/gui/interface_property.h"
|
#include "nel/gui/interface_property.h"
|
||||||
#include "nel/gui/interface_common.h"
|
#include "nel/gui/interface_common.h"
|
||||||
#include "nel/gui/db_manager.h"
|
#include "nel/gui/db_manager.h"
|
||||||
|
#include "nel/misc/common.h"
|
||||||
|
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -30,13 +31,6 @@ using namespace std;
|
||||||
|
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
// helper to convert double <> sint64
|
|
||||||
union C64BitsParts
|
|
||||||
{
|
|
||||||
sint64 i64;
|
|
||||||
double d;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool CInterfaceProperty::link( CCDBNodeLeaf *dbNode )
|
bool CInterfaceProperty::link( CCDBNodeLeaf *dbNode )
|
||||||
{
|
{
|
||||||
_VolatileValue = dbNode;
|
_VolatileValue = dbNode;
|
||||||
|
@ -79,15 +73,15 @@ namespace NLGUI
|
||||||
void CInterfaceProperty::setDouble(double value)
|
void CInterfaceProperty::setDouble(double value)
|
||||||
{
|
{
|
||||||
C64BitsParts parts;
|
C64BitsParts parts;
|
||||||
parts.d = value;
|
parts.d[0] = value;
|
||||||
setSInt64(parts.i64);
|
setSInt64(parts.i64[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
double CInterfaceProperty::getDouble() const
|
double CInterfaceProperty::getDouble() const
|
||||||
{
|
{
|
||||||
C64BitsParts parts;
|
C64BitsParts parts;
|
||||||
parts.i64 = getSInt64();
|
parts.i64[0] = getSInt64();
|
||||||
return parts.d;
|
return parts.d[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// *****************
|
// *****************
|
||||||
|
@ -129,8 +123,8 @@ namespace NLGUI
|
||||||
{
|
{
|
||||||
_VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(id);
|
_VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(id);
|
||||||
C64BitsParts buf;
|
C64BitsParts buf;
|
||||||
fromString(ptr, buf.d);
|
fromString(ptr, buf.d[0]);
|
||||||
_VolatileValue->setValue64(buf.i64);
|
_VolatileValue->setValue64(buf.i64[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1309,8 +1309,9 @@ void CCharacterCL::updateVisualPropertyMode(const NLMISC::TGameCycle &gameCycle,
|
||||||
nlwarning("CH::updtVPMode:%d: Cannot find the property 'PROPERTY_ORIENTATION(%d)'.", _Slot, CLFECOMMON::PROPERTY_ORIENTATION);
|
nlwarning("CH::updtVPMode:%d: Cannot find the property 'PROPERTY_ORIENTATION(%d)'.", _Slot, CLFECOMMON::PROPERTY_ORIENTATION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const sint64 &ori = nodeOri->getValue64();
|
C64BitsParts parts;
|
||||||
float angleZ = *(float *)(&ori);
|
parts.i64[0] = nodeOri->getValue64();
|
||||||
|
float angleZ = parts.f[0];
|
||||||
// server forces the entity orientation even if it cannot turn
|
// server forces the entity orientation even if it cannot turn
|
||||||
front(CVector((float)cos(angleZ), (float)sin(angleZ), 0.f), true, true, true);
|
front(CVector((float)cos(angleZ), (float)sin(angleZ), 0.f), true, true, true);
|
||||||
dir(front(), false, false);
|
dir(front(), false, false);
|
||||||
|
@ -5228,7 +5229,9 @@ bool CCharacterCL::applyStage(CStage &stage)
|
||||||
pair<bool, sint64> resultTeta = stage.property(PROPERTY_ORIENTATION);
|
pair<bool, sint64> resultTeta = stage.property(PROPERTY_ORIENTATION);
|
||||||
if(resultTeta.first)
|
if(resultTeta.first)
|
||||||
{
|
{
|
||||||
float angleZ = *(float *)(&resultTeta.second);
|
C64BitsParts parts;
|
||||||
|
parts.i64[0] = resultTeta.second;
|
||||||
|
float angleZ = parts.f[0];
|
||||||
// server forces the entity orientation even if it cannot turn
|
// server forces the entity orientation even if it cannot turn
|
||||||
front(CVector((float)cos(angleZ), (float)sin(angleZ), 0.f), true, true, true);
|
front(CVector((float)cos(angleZ), (float)sin(angleZ), 0.f), true, true, true);
|
||||||
|
|
||||||
|
@ -5242,7 +5245,9 @@ bool CCharacterCL::applyStage(CStage &stage)
|
||||||
if(resultMode.first)
|
if(resultMode.first)
|
||||||
{
|
{
|
||||||
// Get the mode from stage.
|
// Get the mode from stage.
|
||||||
uint8 mo = *(uint8 *)(&resultMode.second);
|
C64BitsParts parts;
|
||||||
|
parts.i64[0] = resultMode.second;
|
||||||
|
uint8 mo = parts.u8[0];
|
||||||
// If the mode wanted is not the same, change the mode wanted.
|
// If the mode wanted is not the same, change the mode wanted.
|
||||||
if(mo != _ModeWanted)
|
if(mo != _ModeWanted)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2041,15 +2041,10 @@ NLMISC_COMMAND(entity, "Create an entity on the user or just remove it if Form n
|
||||||
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_ORIENTATION), false);
|
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_ORIENTATION), false);
|
||||||
if(node)
|
if(node)
|
||||||
{
|
{
|
||||||
union C64BitsRot
|
C64BitsParts rot;
|
||||||
{
|
rot.f[0] = (float)atan2(UserEntity->front().y, UserEntity->front().x);
|
||||||
sint64 i64;
|
rot.f[1] = 0.f; // to be sure 64 bits value is initialized
|
||||||
float f;
|
node->setValue64(rot.i64[0]);
|
||||||
};
|
|
||||||
|
|
||||||
C64BitsRot rot;
|
|
||||||
rot.f = (float)atan2(UserEntity->front().y, UserEntity->front().x);
|
|
||||||
node->setValue64(rot.i64);
|
|
||||||
}
|
}
|
||||||
// Set Mode
|
// Set Mode
|
||||||
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_MODE), false);
|
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_MODE), false);
|
||||||
|
@ -2847,16 +2842,11 @@ NLMISC_COMMAND(orient, "Orient an entity", "Slot: [1-254] orient(degree) [dt(tic
|
||||||
// Write the position in the DB.
|
// Write the position in the DB.
|
||||||
float fRot= (float)(rot*Pi/180.f);
|
float fRot= (float)(rot*Pi/180.f);
|
||||||
|
|
||||||
union C64BitsRot
|
C64BitsParts r;
|
||||||
{
|
r.f[0] = fRot;
|
||||||
sint64 i64;
|
r.f[1] = 0.f; // to be sure 64 bits value is initialized
|
||||||
float f;
|
|
||||||
};
|
|
||||||
|
|
||||||
C64BitsRot r;
|
IngameDbMngr.setProp("Entities:E" + toString(slot) + ":P"+toString(CLFECOMMON::PROPERTY_ORIENTATION), r.u32[0]);
|
||||||
r.f = fRot;
|
|
||||||
|
|
||||||
IngameDbMngr.setProp("Entities:E" + toString(slot) + ":P"+toString(CLFECOMMON::PROPERTY_ORIENTATION), r.i64);
|
|
||||||
// Update the position.
|
// Update the position.
|
||||||
EntitiesMngr.updateVisualProperty(NetMngr.getCurrentServerTick()+dt, slot, CLFECOMMON::PROPERTY_ORIENTATION);
|
EntitiesMngr.updateVisualProperty(NetMngr.getCurrentServerTick()+dt, slot, CLFECOMMON::PROPERTY_ORIENTATION);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2584,16 +2584,10 @@ void CEntityManager::logPropertyChange(CLFECOMMON::TCLEntityId who, const CStage
|
||||||
// Orientation
|
// Orientation
|
||||||
else if(propLoged[i]==CLFECOMMON::PROPERTY_ORIENTATION)
|
else if(propLoged[i]==CLFECOMMON::PROPERTY_ORIENTATION)
|
||||||
{
|
{
|
||||||
union C64BitsRot
|
C64BitsParts rot;
|
||||||
{
|
rot.i64[0] = value;
|
||||||
sint64 i64;
|
|
||||||
float f;
|
|
||||||
};
|
|
||||||
|
|
||||||
C64BitsRot rot;
|
valStr= toString(sint32(rot.f[0]*180/Pi));
|
||||||
rot.i64 = value;
|
|
||||||
|
|
||||||
valStr= toString("%d", sint32(rot.f*180/Pi));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -146,19 +146,12 @@ static DECLARE_INTERFACE_USER_FCT(getCompassText)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper
|
|
||||||
union C64BitsParts
|
|
||||||
{
|
|
||||||
sint64 i64;
|
|
||||||
double d;
|
|
||||||
};
|
|
||||||
|
|
||||||
//get the direction
|
//get the direction
|
||||||
// sint64 in the databae.
|
// sint64 in the databae.
|
||||||
C64BitsParts angle;
|
C64BitsParts angle;
|
||||||
angle.i64 = args[0].getInteger();
|
angle.i64[0] = args[0].getInteger();
|
||||||
// cast as double now.
|
// cast as double now.
|
||||||
sint direction =(sint) floor( 0.5 + ( 8.0 * (angle.d + NLMISC::Pi)/(NLMISC::Pi) ) );
|
sint direction =(sint) floor( 0.5 + ( 8.0 * (angle.d[0] + NLMISC::Pi)/(NLMISC::Pi) ) );
|
||||||
direction = ((direction%16)+16)%16;
|
direction = ((direction%16)+16)%16;
|
||||||
static const string txts[]=
|
static const string txts[]=
|
||||||
{
|
{
|
||||||
|
|
|
@ -4893,13 +4893,10 @@ CEntityCL *CEditor::createEntity(uint slot, const NLMISC::CSheetId &sheetId, con
|
||||||
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_ORIENTATION), false);
|
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_ORIENTATION), false);
|
||||||
if(node)
|
if(node)
|
||||||
{
|
{
|
||||||
union
|
C64BitsParts parts;
|
||||||
{
|
parts.f[0] = heading;
|
||||||
uint64 heading64;
|
parts.f[1] = 0.f;
|
||||||
float headingFloat;
|
node->setValue64(parts.i64[0]);
|
||||||
};
|
|
||||||
headingFloat = heading;
|
|
||||||
node->setValue64(heading64);
|
|
||||||
}
|
}
|
||||||
// Set Mode
|
// Set Mode
|
||||||
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_MODE), false);
|
node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_MODE), false);
|
||||||
|
|
|
@ -789,18 +789,12 @@ bool CUserEntity::mode(MBEHAV::EMode m)
|
||||||
case MBEHAV::COMBAT:
|
case MBEHAV::COMBAT:
|
||||||
case MBEHAV::COMBAT_FLOAT:
|
case MBEHAV::COMBAT_FLOAT:
|
||||||
{
|
{
|
||||||
union C64BitsRot
|
C64BitsParts rot;
|
||||||
{
|
|
||||||
sint64 i64;
|
|
||||||
float f;
|
|
||||||
};
|
|
||||||
|
|
||||||
C64BitsRot rot;
|
|
||||||
|
|
||||||
// Compute the angle
|
// Compute the angle
|
||||||
const string propName = toString("SERVER:Entities:E%d:P%d", _Slot, CLFECOMMON::PROPERTY_ORIENTATION);
|
const string propName = toString("SERVER:Entities:E%d:P%d", _Slot, CLFECOMMON::PROPERTY_ORIENTATION);
|
||||||
rot.i64 = NLGUI::CDBManager::getInstance()->getDbProp(propName)->getValue64();
|
rot.i64[0] = NLGUI::CDBManager::getInstance()->getDbProp(propName)->getValue64();
|
||||||
_TargetAngle = rot.f;
|
_TargetAngle = rot.f[0];
|
||||||
|
|
||||||
// Initialize controls for the combat.
|
// Initialize controls for the combat.
|
||||||
UserControls.startCombat();
|
UserControls.startCombat();
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "nel/misc/entity_id.h"
|
#include "nel/misc/entity_id.h"
|
||||||
#include "nel/misc/sheet_id.h"
|
#include "nel/misc/sheet_id.h"
|
||||||
#include "nel/misc/sstring.h"
|
#include "nel/misc/sstring.h"
|
||||||
|
#include "nel/misc/common.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -18,20 +18,6 @@
|
||||||
// inlines CPersistentDataRecord
|
// inlines CPersistentDataRecord
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
union C64BitParts
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint32 i32_1;
|
|
||||||
uint32 i32_2;
|
|
||||||
};
|
|
||||||
|
|
||||||
sint64 s64;
|
|
||||||
uint64 u64;
|
|
||||||
double d;
|
|
||||||
float f;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void CPersistentDataRecord::addString(const std::string& name,uint16 &result)
|
inline void CPersistentDataRecord::addString(const std::string& name,uint16 &result)
|
||||||
{
|
{
|
||||||
// check whether the value of 'result' is already correct
|
// check whether the value of 'result' is already correct
|
||||||
|
@ -110,8 +96,8 @@ inline void CPersistentDataRecord::push(TToken token,sint32 val)
|
||||||
inline void CPersistentDataRecord::push(TToken token,sint64 val)
|
inline void CPersistentDataRecord::push(TToken token,sint64 val)
|
||||||
{
|
{
|
||||||
// create a union for splitting the i64 value into 2 32bit parts and map the union onto the input value
|
// create a union for splitting the i64 value into 2 32bit parts and map the union onto the input value
|
||||||
C64BitParts valueInBits;
|
NLMISC::C64BitsParts valueInBits;
|
||||||
valueInBits.s64 = val;
|
valueInBits.i64[0] = val;
|
||||||
|
|
||||||
// make sure the token is valid
|
// make sure the token is valid
|
||||||
#ifdef NL_DEBUG
|
#ifdef NL_DEBUG
|
||||||
|
@ -120,9 +106,9 @@ inline void CPersistentDataRecord::push(TToken token,sint64 val)
|
||||||
|
|
||||||
// store the token and value to the relavent data buffers
|
// store the token and value to the relavent data buffers
|
||||||
_TokenTable.push_back((token<<3)+CArg::EXTEND_TOKEN);
|
_TokenTable.push_back((token<<3)+CArg::EXTEND_TOKEN);
|
||||||
_ArgTable.push_back(valueInBits.i32_1);
|
_ArgTable.push_back(valueInBits.u32[0]);
|
||||||
_TokenTable.push_back((token<<3)+CArg::SINT_TOKEN);
|
_TokenTable.push_back((token<<3)+CArg::SINT_TOKEN);
|
||||||
_ArgTable.push_back(valueInBits.i32_2);
|
_ArgTable.push_back(valueInBits.u32[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CPersistentDataRecord::push(TToken token,uint8 val)
|
inline void CPersistentDataRecord::push(TToken token,uint8 val)
|
||||||
|
@ -164,8 +150,8 @@ inline void CPersistentDataRecord::push(TToken token,uint32 val)
|
||||||
inline void CPersistentDataRecord::push(TToken token,uint64 val)
|
inline void CPersistentDataRecord::push(TToken token,uint64 val)
|
||||||
{
|
{
|
||||||
// create a union for splitting the i64 value into 2 32bit parts and map the union onto the input value
|
// create a union for splitting the i64 value into 2 32bit parts and map the union onto the input value
|
||||||
C64BitParts valueInBits;
|
NLMISC::C64BitsParts valueInBits;
|
||||||
valueInBits.u64 = val;
|
valueInBits.u64[0] = val;
|
||||||
|
|
||||||
// make sure the token is valid
|
// make sure the token is valid
|
||||||
#ifdef NL_DEBUG
|
#ifdef NL_DEBUG
|
||||||
|
@ -174,15 +160,15 @@ inline void CPersistentDataRecord::push(TToken token,uint64 val)
|
||||||
|
|
||||||
// store the token and value to the relavent data buffers
|
// store the token and value to the relavent data buffers
|
||||||
_TokenTable.push_back((token<<3)+CArg::EXTEND_TOKEN);
|
_TokenTable.push_back((token<<3)+CArg::EXTEND_TOKEN);
|
||||||
_ArgTable.push_back(valueInBits.i32_1);
|
_ArgTable.push_back(valueInBits.u32[0]);
|
||||||
_TokenTable.push_back((token<<3)+CArg::UINT_TOKEN);
|
_TokenTable.push_back((token<<3)+CArg::UINT_TOKEN);
|
||||||
_ArgTable.push_back(valueInBits.i32_2);
|
_ArgTable.push_back(valueInBits.u32[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CPersistentDataRecord::push(TToken token,float val)
|
inline void CPersistentDataRecord::push(TToken token,float val)
|
||||||
{
|
{
|
||||||
C64BitParts valueInBits;
|
NLMISC::C64BitsParts valueInBits;
|
||||||
valueInBits.f = val;
|
valueInBits.f[0] = val;
|
||||||
|
|
||||||
// make sure the token is valid
|
// make sure the token is valid
|
||||||
#ifdef NL_DEBUG
|
#ifdef NL_DEBUG
|
||||||
|
@ -191,14 +177,14 @@ inline void CPersistentDataRecord::push(TToken token,float val)
|
||||||
|
|
||||||
// store the token and value to the relavent data buffers
|
// store the token and value to the relavent data buffers
|
||||||
_TokenTable.push_back((token<<3)+CArg::FLOAT_TOKEN);
|
_TokenTable.push_back((token<<3)+CArg::FLOAT_TOKEN);
|
||||||
_ArgTable.push_back(valueInBits.i32_1);
|
_ArgTable.push_back(valueInBits.u32[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CPersistentDataRecord::push(TToken token,double val)
|
inline void CPersistentDataRecord::push(TToken token,double val)
|
||||||
{
|
{
|
||||||
// create a union for splitting the i64 value into 2 32bit parts and map the union onto the input value
|
// create a union for splitting the i64 value into 2 32bit parts and map the union onto the input value
|
||||||
C64BitParts valueInBits;
|
NLMISC::C64BitsParts valueInBits;
|
||||||
valueInBits.d = val;
|
valueInBits.d[0] = val;
|
||||||
|
|
||||||
// make sure the token is valid
|
// make sure the token is valid
|
||||||
#ifdef NL_DEBUG
|
#ifdef NL_DEBUG
|
||||||
|
@ -207,9 +193,9 @@ inline void CPersistentDataRecord::push(TToken token,double val)
|
||||||
|
|
||||||
// store the token and value to the relavent data buffers
|
// store the token and value to the relavent data buffers
|
||||||
_TokenTable.push_back((token<<3)+CArg::EXTEND_TOKEN);
|
_TokenTable.push_back((token<<3)+CArg::EXTEND_TOKEN);
|
||||||
_ArgTable.push_back(valueInBits.i32_1);
|
_ArgTable.push_back(valueInBits.u32[0]);
|
||||||
_TokenTable.push_back((token<<3)+CArg::FLOAT_TOKEN);
|
_TokenTable.push_back((token<<3)+CArg::FLOAT_TOKEN);
|
||||||
_ArgTable.push_back(valueInBits.i32_2);
|
_ArgTable.push_back(valueInBits.u32[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CPersistentDataRecord::push(TToken token,const std::string& val)
|
inline void CPersistentDataRecord::push(TToken token,const std::string& val)
|
||||||
|
|
Loading…
Reference in a new issue