Generic CAO cleanups and renames for clarification
authorest31 <MTest31@outlook.com>
Sat, 20 Jun 2015 01:20:06 +0000 (03:20 +0200)
committerest31 <MTest31@outlook.com>
Sat, 20 Jun 2015 01:37:30 +0000 (03:37 +0200)
* Use enum for GENERIC_CMD_*
* Rename m_attachements to attachement_parent_ids (public member and clearer name)
* Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
* USHRT_MAX + 1 buffer sizes to prevent overflows as @kahrl suggested
* Remove unneccessary m_id from GenericCAO (shadowing protected superclass member for no reason) as @kahrl suggested

src/content_cao.cpp
src/content_cao.h
src/environment.cpp
src/environment.h
src/genericobject.cpp
src/genericobject.h
src/mapblock.cpp
src/network/networkprotocol.h

index 4f1336d281b58ff1b55f4d63da3ba060e029ee15..d82af9e57a4e846419da7981231e40478852cac5 100644 (file)
@@ -543,7 +543,6 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
                //
                m_is_player(false),
                m_is_local_player(false),
-               m_id(0),
                //
                m_smgr(NULL),
                m_irr(NULL),
@@ -747,7 +746,7 @@ ClientActiveObject* GenericCAO::getParent()
 {
        ClientActiveObject *obj = NULL;
 
-       u16 attached_id = m_env->m_attachements[getId()];
+       u16 attached_id = m_env->attachement_parent_ids[getId()];
 
        if ((attached_id != 0) &&
                        (attached_id != getId())) {
@@ -764,12 +763,12 @@ void GenericCAO::removeFromScene(bool permanent)
                for(std::vector<u16>::iterator ci = m_children.begin();
                                                ci != m_children.end(); ci++)
                {
-                       if (m_env->m_attachements[*ci] == getId()) {
-                               m_env->m_attachements[*ci] = 0;
+                       if (m_env->attachement_parent_ids[*ci] == getId()) {
+                               m_env->attachement_parent_ids[*ci] = 0;
                        }
                }
 
-               m_env->m_attachements[getId()] = 0;
+               m_env->attachement_parent_ids[getId()] = 0;
 
                LocalPlayer* player = m_env->getLocalPlayer();
                if (this == player->parent) {
@@ -1111,7 +1110,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
                for(std::vector<u16>::iterator ci = m_children.begin();
                                ci != m_children.end();)
                {
-                       if (m_env->m_attachements[*ci] != getId()) {
+                       if (m_env->attachement_parent_ids[*ci] != getId()) {
                                ci = m_children.erase(ci);
                                continue;
                        }
@@ -1669,9 +1668,9 @@ void GenericCAO::processMessage(const std::string &data)
                m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
 
                updateBonePosition();
-       } else if (cmd == GENERIC_CMD_SET_ATTACHMENT) {
+       } else if (cmd == GENERIC_CMD_ATTACH_TO) {
                u16 parentID = readS16(is);
-               m_env->m_attachements[getId()] = parentID;
+               m_env->attachement_parent_ids[getId()] = parentID;
                GenericCAO *parentobj = m_env->getGenericCAO(parentID);
 
                if (parentobj) {
index 813a4125930adec8d0e95cfd0647ad03b178751d..58c373389868c977ee7f596d8ffb06bb4faa6c52 100644 (file)
@@ -60,7 +60,6 @@ private:
        std::string m_name;
        bool m_is_player;
        bool m_is_local_player;
-       int m_id;
        // Property-ish things
        ObjectProperties m_prop;
        //
index 7d80619bc4e96bc06503f4c4c7d939e9699efca5..09db886a83d6c463bc67d8c5a5ef3eb6d7e8b3e8 100644 (file)
@@ -2009,7 +2009,7 @@ ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
        m_irr(irr)
 {
        char zero = 0;
-       memset(m_attachements, zero, sizeof(m_attachements));
+       memset(attachement_parent_ids, zero, sizeof(attachement_parent_ids));
 }
 
 ClientEnvironment::~ClientEnvironment()
index 983f094092a21188326bbcbba75a0a148d8ff076..b35ca42496b175bd4eea290b42faac9d2faddc68 100644 (file)
@@ -505,7 +505,7 @@ public:
        // Get event from queue. CEE_NONE is returned if queue is empty.
        ClientEnvEvent getClientEvent();
 
-       u16 m_attachements[USHRT_MAX];
+       u16 attachement_parent_ids[USHRT_MAX + 1];
 
        std::list<std::string> getPlayerNames()
        { return m_player_names; }
index 78dc7fa9172d3f506d077390f60313e6fb5a352c..5daba55edfeea4fda0cc4e34b97af21ef0eabeab 100644 (file)
@@ -161,7 +161,7 @@ std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f posit
 {
        std::ostringstream os(std::ios::binary);
        // command 
-       writeU8(os, GENERIC_CMD_SET_ATTACHMENT);
+       writeU8(os, GENERIC_CMD_ATTACH_TO);
        // parameters
        writeS16(os, parent_id);
        os<<serializeString(bone);
index 2233e4ea04c059858d88ed9c1ad42c682c9e2dc3..b36a3830d88511a3bdd3894d6ceb2217a099bb31 100644 (file)
@@ -24,17 +24,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "irrlichttypes_bloated.h"
 #include <iostream>
 
-#define GENERIC_CMD_SET_PROPERTIES 0
-#define GENERIC_CMD_UPDATE_POSITION 1
-#define GENERIC_CMD_SET_TEXTURE_MOD 2
-#define GENERIC_CMD_SET_SPRITE 3
-#define GENERIC_CMD_PUNCHED 4
-#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 5
-#define GENERIC_CMD_SET_ANIMATION 6
-#define GENERIC_CMD_SET_BONE_POSITION 7
-#define GENERIC_CMD_SET_ATTACHMENT 8
-#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
-#define GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES 10
+enum GenericCMD {
+       GENERIC_CMD_SET_PROPERTIES,
+       GENERIC_CMD_UPDATE_POSITION,
+       GENERIC_CMD_SET_TEXTURE_MOD,
+       GENERIC_CMD_SET_SPRITE,
+       GENERIC_CMD_PUNCHED,
+       GENERIC_CMD_UPDATE_ARMOR_GROUPS,
+       GENERIC_CMD_SET_ANIMATION,
+       GENERIC_CMD_SET_BONE_POSITION,
+       GENERIC_CMD_ATTACH_TO,
+       GENERIC_CMD_SET_PHYSICS_OVERRIDE,
+       GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES
+};
 
 #include "object_properties.h"
 std::string gob_cmd_set_properties(const ObjectProperties &prop);
index 9eb64a76ef10e75429a2c9fd5a71edb55dbc8134..39cac0b60e912979e7ee56ed96659550d6c796ec 100644 (file)
@@ -465,11 +465,11 @@ s16 MapBlock::getGroundLevel(v2s16 p2d)
 // sure we can handle all content ids. But it's absolutely worth it as it's
 // a speedup of 4 for one of the major time consuming functions on storing
 // mapblocks.
-static content_t getBlockNodeIdMapping_mapping[USHRT_MAX];
+static content_t getBlockNodeIdMapping_mapping[USHRT_MAX + 1];
 static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
                INodeDefManager *nodedef)
 {
-       memset(getBlockNodeIdMapping_mapping, 0xFF, USHRT_MAX * sizeof(content_t));
+       memset(getBlockNodeIdMapping_mapping, 0xFF, (USHRT_MAX + 1) * sizeof(content_t));
 
        std::set<content_t> unknown_contents;
        content_t id_counter = 0;
index 09617c9d9f1193af4f43eedc50d8c4334033ca72..852f2ee0390c880bce058873fc556dd99ea20106 100644 (file)
@@ -129,6 +129,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                Add TOCLIENT_HELLO for presenting server to client after client
                        presentation
                Add TOCLIENT_AUTH_ACCEPT to accept connection from client
+               Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
 */
 
 #define LATEST_PROTOCOL_VERSION 25