Skip to content

Commit dd91b3d

Browse files
committedJun 20, 2015
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
1 parent 40226e5 commit dd91b3d

File tree

8 files changed

+26
-25
lines changed

8 files changed

+26
-25
lines changed
 

‎src/content_cao.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
543543
//
544544
m_is_player(false),
545545
m_is_local_player(false),
546-
m_id(0),
547546
//
548547
m_smgr(NULL),
549548
m_irr(NULL),
@@ -747,7 +746,7 @@ ClientActiveObject* GenericCAO::getParent()
747746
{
748747
ClientActiveObject *obj = NULL;
749748

750-
u16 attached_id = m_env->m_attachements[getId()];
749+
u16 attached_id = m_env->attachement_parent_ids[getId()];
751750

752751
if ((attached_id != 0) &&
753752
(attached_id != getId())) {
@@ -764,12 +763,12 @@ void GenericCAO::removeFromScene(bool permanent)
764763
for(std::vector<u16>::iterator ci = m_children.begin();
765764
ci != m_children.end(); ci++)
766765
{
767-
if (m_env->m_attachements[*ci] == getId()) {
768-
m_env->m_attachements[*ci] = 0;
766+
if (m_env->attachement_parent_ids[*ci] == getId()) {
767+
m_env->attachement_parent_ids[*ci] = 0;
769768
}
770769
}
771770

772-
m_env->m_attachements[getId()] = 0;
771+
m_env->attachement_parent_ids[getId()] = 0;
773772

774773
LocalPlayer* player = m_env->getLocalPlayer();
775774
if (this == player->parent) {
@@ -1111,7 +1110,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
11111110
for(std::vector<u16>::iterator ci = m_children.begin();
11121111
ci != m_children.end();)
11131112
{
1114-
if (m_env->m_attachements[*ci] != getId()) {
1113+
if (m_env->attachement_parent_ids[*ci] != getId()) {
11151114
ci = m_children.erase(ci);
11161115
continue;
11171116
}
@@ -1669,9 +1668,9 @@ void GenericCAO::processMessage(const std::string &data)
16691668
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
16701669

16711670
updateBonePosition();
1672-
} else if (cmd == GENERIC_CMD_SET_ATTACHMENT) {
1671+
} else if (cmd == GENERIC_CMD_ATTACH_TO) {
16731672
u16 parentID = readS16(is);
1674-
m_env->m_attachements[getId()] = parentID;
1673+
m_env->attachement_parent_ids[getId()] = parentID;
16751674
GenericCAO *parentobj = m_env->getGenericCAO(parentID);
16761675

16771676
if (parentobj) {

‎src/content_cao.h

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class GenericCAO : public ClientActiveObject
6060
std::string m_name;
6161
bool m_is_player;
6262
bool m_is_local_player;
63-
int m_id;
6463
// Property-ish things
6564
ObjectProperties m_prop;
6665
//

‎src/environment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
20092009
m_irr(irr)
20102010
{
20112011
char zero = 0;
2012-
memset(m_attachements, zero, sizeof(m_attachements));
2012+
memset(attachement_parent_ids, zero, sizeof(attachement_parent_ids));
20132013
}
20142014

20152015
ClientEnvironment::~ClientEnvironment()

‎src/environment.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class ClientEnvironment : public Environment
505505
// Get event from queue. CEE_NONE is returned if queue is empty.
506506
ClientEnvEvent getClientEvent();
507507

508-
u16 m_attachements[USHRT_MAX];
508+
u16 attachement_parent_ids[USHRT_MAX + 1];
Has a conversation. Original line has a conversation.
509509

510510
std::list<std::string> getPlayerNames()
511511
{ return m_player_names; }

‎src/genericobject.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f posit
161161
{
162162
std::ostringstream os(std::ios::binary);
163163
// command
164-
writeU8(os, GENERIC_CMD_SET_ATTACHMENT);
164+
writeU8(os, GENERIC_CMD_ATTACH_TO);
165165
// parameters
166166
writeS16(os, parent_id);
167167
os<<serializeString(bone);

‎src/genericobject.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include "irrlichttypes_bloated.h"
2525
#include <iostream>
2626

27-
#define GENERIC_CMD_SET_PROPERTIES 0
28-
#define GENERIC_CMD_UPDATE_POSITION 1
29-
#define GENERIC_CMD_SET_TEXTURE_MOD 2
30-
#define GENERIC_CMD_SET_SPRITE 3
31-
#define GENERIC_CMD_PUNCHED 4
32-
#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 5
33-
#define GENERIC_CMD_SET_ANIMATION 6
34-
#define GENERIC_CMD_SET_BONE_POSITION 7
35-
#define GENERIC_CMD_SET_ATTACHMENT 8
36-
#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
37-
#define GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES 10
27+
enum GenericCMD {
28+
GENERIC_CMD_SET_PROPERTIES,
29+
GENERIC_CMD_UPDATE_POSITION,
30+
GENERIC_CMD_SET_TEXTURE_MOD,
31+
GENERIC_CMD_SET_SPRITE,
32+
GENERIC_CMD_PUNCHED,
33+
GENERIC_CMD_UPDATE_ARMOR_GROUPS,
34+
GENERIC_CMD_SET_ANIMATION,
35+
GENERIC_CMD_SET_BONE_POSITION,
36+
GENERIC_CMD_ATTACH_TO,
37+
GENERIC_CMD_SET_PHYSICS_OVERRIDE,
38+
GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES
39+
};
3840

3941
#include "object_properties.h"
4042
std::string gob_cmd_set_properties(const ObjectProperties &prop);

‎src/mapblock.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,11 @@ s16 MapBlock::getGroundLevel(v2s16 p2d)
465465
// sure we can handle all content ids. But it's absolutely worth it as it's
466466
// a speedup of 4 for one of the major time consuming functions on storing
467467
// mapblocks.
468-
static content_t getBlockNodeIdMapping_mapping[USHRT_MAX];
468+
static content_t getBlockNodeIdMapping_mapping[USHRT_MAX + 1];
469469
static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
470470
INodeDefManager *nodedef)
471471
{
472-
memset(getBlockNodeIdMapping_mapping, 0xFF, USHRT_MAX * sizeof(content_t));
472+
memset(getBlockNodeIdMapping_mapping, 0xFF, (USHRT_MAX + 1) * sizeof(content_t));
473473

474474
std::set<content_t> unknown_contents;
475475
content_t id_counter = 0;

‎src/network/networkprotocol.h

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
129129
Add TOCLIENT_HELLO for presenting server to client after client
130130
presentation
131131
Add TOCLIENT_AUTH_ACCEPT to accept connection from client
132+
Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
132133
*/
133134

134135
#define LATEST_PROTOCOL_VERSION 25

0 commit comments

Comments
 (0)
Please sign in to comment.