various cleanups and optimisations

This commit is contained in:
darkrose 2013-04-25 13:24:43 +10:00
parent 1aac87bf61
commit 4ce27a2dc5
2 changed files with 28 additions and 27 deletions

View File

@ -1439,17 +1439,20 @@ bool isFreeServerActiveObjectId(u16 id,
u16 getFreeServerActiveObjectId( u16 getFreeServerActiveObjectId(
core::map<u16, ServerActiveObject*> &objects) core::map<u16, ServerActiveObject*> &objects)
{ {
u16 new_id = 1; //try to reuse id's as late as possible
for(;;) static u16 last_used_id = 0;
{ u16 startid = last_used_id;
if(isFreeServerActiveObjectId(new_id, objects))
return new_id;
if(new_id == 65535) for (;;) {
last_used_id++;
if (isFreeServerActiveObjectId(last_used_id, objects))
return last_used_id;
if (last_used_id == startid)
return 0; return 0;
new_id++;
} }
return 0;
} }
u16 ServerEnvironment::addActiveObject(ServerActiveObject *object) u16 ServerEnvironment::addActiveObject(ServerActiveObject *object)
@ -2342,17 +2345,19 @@ bool isFreeClientActiveObjectId(u16 id,
u16 getFreeClientActiveObjectId( u16 getFreeClientActiveObjectId(
core::map<u16, ClientActiveObject*> &objects) core::map<u16, ClientActiveObject*> &objects)
{ {
u16 new_id = 1; //try to reuse id's as late as possible
for(;;) static u16 last_used_id = 0;
{ u16 startid = last_used_id;
if(isFreeClientActiveObjectId(new_id, objects))
return new_id;
if(new_id == 65535) for (;;) {
last_used_id ++;
if (isFreeClientActiveObjectId(last_used_id, objects))
return last_used_id;
if(last_used_id == startid)
return 0; return 0;
new_id++;
} }
return 0;
} }
u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)

View File

@ -712,9 +712,8 @@ const InventoryList * Inventory::getList(const std::string &name) const
const s32 Inventory::getListIndex(const std::string &name) const const s32 Inventory::getListIndex(const std::string &name) const
{ {
for(u32 i=0; i<m_lists.size(); i++) for(u32 i=0; i<m_lists.size(); i++) {
{ if (m_lists[i]->getName() == name)
if(m_lists[i]->getName() == name)
return i; return i;
} }
return -1; return -1;
@ -729,22 +728,19 @@ InventoryAction * InventoryAction::deSerialize(std::istream &is)
std::string type; std::string type;
std::getline(is, type, ' '); std::getline(is, type, ' ');
InventoryAction *a = NULL;
if(type == "Move") if(type == "Move")
{ return new IMoveAction(is);
a = new IMoveAction(is);
}
return a; return NULL;
} }
static std::string describeC(const struct InventoryContext *c) static std::string describeC(const struct InventoryContext *c)
{ {
if(c->current_player == NULL) if(c->current_player == NULL) {
return "current_player=NULL"; return "current_player=NULL";
else }else{
return std::string("current_player=") + c->current_player->getName(); return std::string("current_player=") + c->current_player->getName();
}
} }
void IMoveAction::apply(InventoryContext *c, InventoryManager *mgr) void IMoveAction::apply(InventoryContext *c, InventoryManager *mgr)