From e30ba1d18604f0001e87b63272b4ecafe93a4043 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 19 Dec 2016 15:49:50 +0100 Subject: [PATCH] Fixed: Strict aliasing warnings --- code/ryzom/client/src/commands.cpp | 29 +++++++++++++++++++-------- code/ryzom/client/src/entities.cpp | 12 +++++++++-- code/ryzom/client/src/r2/editor.cpp | 5 ++--- code/ryzom/client/src/user_entity.cpp | 12 +++++++++-- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/code/ryzom/client/src/commands.cpp b/code/ryzom/client/src/commands.cpp index 2d8547bd6..03ed956fb 100644 --- a/code/ryzom/client/src/commands.cpp +++ b/code/ryzom/client/src/commands.cpp @@ -2041,17 +2041,21 @@ 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); if(node) { - float dir = (float)atan2(UserEntity->front().y, UserEntity->front().x); - prop = (sint64 *)(&dir); - node->setValue64(*prop); + union C64BitsRot + { + sint64 i64; + float f; + }; + + C64BitsRot rot; + rot.f = (float)atan2(UserEntity->front().y, UserEntity->front().x); + node->setValue64(rot.i64); } // Set Mode node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_MODE), false); if(node) { - MBEHAV::EMode m = MBEHAV::NORMAL; - prop = (sint64 *)&m; - node->setValue64(*prop); + node->setValue64((sint64)MBEHAV::NORMAL); EntitiesMngr.updateVisualProperty(0, slot, CLFECOMMON::PROPERTY_MODE); } // Set Visual Properties @@ -2842,8 +2846,17 @@ NLMISC_COMMAND(orient, "Orient an entity", "Slot: [1-254] orient(degree) [dt(tic fromString(args[2], dt); // Write the position in the DB. float fRot= (float)(rot*Pi/180.f); - uint64 val= *(uint32*)(&fRot); - IngameDbMngr.setProp("Entities:E" + toString(slot) + ":P"+toString(CLFECOMMON::PROPERTY_ORIENTATION), val); + + union C64BitsRot + { + sint64 i64; + float f; + }; + + C64BitsRot r; + r.f = fRot; + + IngameDbMngr.setProp("Entities:E" + toString(slot) + ":P"+toString(CLFECOMMON::PROPERTY_ORIENTATION), r.i64); // Update the position. EntitiesMngr.updateVisualProperty(NetMngr.getCurrentServerTick()+dt, slot, CLFECOMMON::PROPERTY_ORIENTATION); } diff --git a/code/ryzom/client/src/entities.cpp b/code/ryzom/client/src/entities.cpp index cb324d2bc..7e682a588 100644 --- a/code/ryzom/client/src/entities.cpp +++ b/code/ryzom/client/src/entities.cpp @@ -2584,8 +2584,16 @@ void CEntityManager::logPropertyChange(CLFECOMMON::TCLEntityId who, const CStage // Orientation else if(propLoged[i]==CLFECOMMON::PROPERTY_ORIENTATION) { - float rot= *(float*)(&value); - valStr= toString("%d", sint32(rot*180/Pi)); + union C64BitsRot + { + sint64 i64; + float f; + }; + + C64BitsRot rot; + rot.i64 = value; + + valStr= toString("%d", sint32(rot.f*180/Pi)); } diff --git a/code/ryzom/client/src/r2/editor.cpp b/code/ryzom/client/src/r2/editor.cpp index f9c047fd5..72d3a66e8 100644 --- a/code/ryzom/client/src/r2/editor.cpp +++ b/code/ryzom/client/src/r2/editor.cpp @@ -4905,11 +4905,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_MODE), false); if(node) { - MBEHAV::EMode m = MBEHAV::NORMAL; - prop = (sint64 *)&m; - node->setValue64(*prop); + node->setValue64((sint64)MBEHAV::NORMAL); EntitiesMngr.updateVisualProperty(0, slot, CLFECOMMON::PROPERTY_MODE); } + // Set Visual Properties SPropVisualA visualA; //visualA.PropertySubData.LTrail = 1; diff --git a/code/ryzom/client/src/user_entity.cpp b/code/ryzom/client/src/user_entity.cpp index f5b4b0f42..2b200d2e6 100644 --- a/code/ryzom/client/src/user_entity.cpp +++ b/code/ryzom/client/src/user_entity.cpp @@ -789,10 +789,18 @@ bool CUserEntity::mode(MBEHAV::EMode m) case MBEHAV::COMBAT: case MBEHAV::COMBAT_FLOAT: { + union C64BitsRot + { + sint64 i64; + float f; + }; + + C64BitsRot rot; + // Compute the angle const string propName = toString("SERVER:Entities:E%d:P%d", _Slot, CLFECOMMON::PROPERTY_ORIENTATION); - sint64 ang = NLGUI::CDBManager::getInstance()->getDbProp(propName)->getValue64(); - _TargetAngle = *(float *)(&ang); + rot.i64 = NLGUI::CDBManager::getInstance()->getDbProp(propName)->getValue64(); + _TargetAngle = rot.f; // Initialize controls for the combat. UserControls.startCombat();