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
master
est31 2015-06-20 03:20:06 +02:00
parent 40226e5274
commit dd91b3d6fb
8 changed files with 26 additions and 25 deletions

View 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) {

View 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;
//

View 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()

View 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; }

View 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);

View 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);

View 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;

View 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