diff options
author | est31 <MTest31@outlook.com> | 2015-06-20 03:20:06 +0200 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-06-20 03:37:30 +0200 |
commit | dd91b3d6fbc3a0b4b18b36b14864d703213dd622 (patch) | |
tree | 0c73f02ef3357f9557694d489a42df424fab51fc | |
parent | 40226e52747156cbdc5128a416480b226e498fff (diff) | |
download | minetest-dd91b3d6fbc3a0b4b18b36b14864d703213dd622.tar.gz minetest-dd91b3d6fbc3a0b4b18b36b14864d703213dd622.tar.bz2 minetest-dd91b3d6fbc3a0b4b18b36b14864d703213dd622.zip |
Generic CAO cleanups and renames for clarification
* 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
-rw-r--r-- | src/content_cao.cpp | 15 | ||||
-rw-r--r-- | src/content_cao.h | 1 | ||||
-rw-r--r-- | src/environment.cpp | 2 | ||||
-rw-r--r-- | src/environment.h | 2 | ||||
-rw-r--r-- | src/genericobject.cpp | 2 | ||||
-rw-r--r-- | src/genericobject.h | 24 | ||||
-rw-r--r-- | src/mapblock.cpp | 4 | ||||
-rw-r--r-- | src/network/networkprotocol.h | 1 |
8 files changed, 26 insertions, 25 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 4f1336d28..d82af9e57 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -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) { diff --git a/src/content_cao.h b/src/content_cao.h index 813a41259..58c373389 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -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; // diff --git a/src/environment.cpp b/src/environment.cpp index 7d80619bc..09db886a8 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -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() diff --git a/src/environment.h b/src/environment.h index 983f09409..b35ca4249 100644 --- a/src/environment.h +++ b/src/environment.h @@ -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; } diff --git a/src/genericobject.cpp b/src/genericobject.cpp index 78dc7fa91..5daba55ed 100644 --- a/src/genericobject.cpp +++ b/src/genericobject.cpp @@ -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); diff --git a/src/genericobject.h b/src/genericobject.h index 2233e4ea0..b36a3830d 100644 --- a/src/genericobject.h +++ b/src/genericobject.h @@ -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); diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 9eb64a76e..39cac0b60 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -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; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 09617c9d9..852f2ee03 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -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 |