Skip to content

Commit

Permalink
Generic CAO cleanups and renames for clarification
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
est31 committed Jun 20, 2015
1 parent 40226e5 commit dd91b3d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
15 changes: 7 additions & 8 deletions src/content_cao.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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())) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/content_cao.h
Expand Up @@ -60,7 +60,6 @@ class GenericCAO : public ClientActiveObject
std::string m_name;
bool m_is_player;
bool m_is_local_player;
int m_id;
// Property-ish things
ObjectProperties m_prop;
//
Expand Down
2 changes: 1 addition & 1 deletion src/environment.cpp
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/environment.h
Expand Up @@ -505,7 +505,7 @@ class ClientEnvironment : public Environment
// 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];

This comment has been minimized.

Copy link
@ShadowNinja

ShadowNinja Jun 27, 2015

Member
  • It's spelled attachment (only onee).
  • I wonder if allocating 128KiB for this is really necessary (or even 8GiB if shorts are 32-bit -- although that's admittedly very unlikely), it seems like most of it isn't even used.

std::list<std::string> getPlayerNames()
{ return m_player_names; }
Expand Down
2 changes: 1 addition & 1 deletion src/genericobject.cpp
Expand Up @@ -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);
Expand Down
24 changes: 13 additions & 11 deletions src/genericobject.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/mapblock.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/network/networkprotocol.h
Expand Up @@ -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
Expand Down

0 comments on commit dd91b3d

Please sign in to comment.