forked from oerkki/voxelands
random changes and remove that fucking warning
This commit is contained in:
parent
bc072e14c7
commit
38c3a50db5
|
@ -1,21 +1,28 @@
|
|||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* client.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2014 <lisa@ltmnet.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "client.h"
|
||||
#include "utility.h"
|
||||
|
|
|
@ -1,21 +1,28 @@
|
|||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* clientserver.h
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2014 <lisa@ltmnet.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef CLIENTSERVER_HEADER
|
||||
#define CLIENTSERVER_HEADER
|
||||
|
|
|
@ -582,13 +582,10 @@ void ServerEnvironment::clearAllObjects()
|
|||
{
|
||||
infostream<<"ServerEnvironment::clearAllObjects(): "
|
||||
<<"Removing all active objects"<<std::endl;
|
||||
core::list<u16> objects_to_remove;
|
||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
ServerActiveObject* obj = i.getNode()->getValue();
|
||||
u16 id = i.getNode()->getKey();
|
||||
std::vector<u16> objects_to_remove;
|
||||
for (std::map<u16, ServerActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
ServerActiveObject* obj = i->second;
|
||||
u16 id = i->first;
|
||||
v3f objectpos = obj->getBasePosition();
|
||||
// Delete static object if block is loaded
|
||||
if(obj->m_static_exists){
|
||||
|
@ -611,10 +608,8 @@ void ServerEnvironment::clearAllObjects()
|
|||
objects_to_remove.push_back(id);
|
||||
}
|
||||
// Remove references from m_active_objects
|
||||
for(core::list<u16>::Iterator i = objects_to_remove.begin();
|
||||
i != objects_to_remove.end(); i++)
|
||||
{
|
||||
m_active_objects.remove(*i);
|
||||
for (std::vector<u16>::iterator i = objects_to_remove.begin(); i != objects_to_remove.end(); i++) {
|
||||
m_active_objects.erase(*i);
|
||||
}
|
||||
|
||||
core::list<v3s16> loadable_blocks;
|
||||
|
@ -2722,11 +2717,8 @@ void ServerEnvironment::step(float dtime)
|
|||
send_recommended = true;
|
||||
}
|
||||
|
||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
ServerActiveObject* obj = i.getNode()->getValue();
|
||||
for (std::map<u16, ServerActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
ServerActiveObject* obj = i->second;
|
||||
// Remove non-peaceful mobs on peaceful mode
|
||||
if (obj->level() > mob_level)
|
||||
obj->m_removed = true;
|
||||
|
@ -2736,10 +2728,8 @@ void ServerEnvironment::step(float dtime)
|
|||
// Step object
|
||||
obj->step(dtime, send_recommended);
|
||||
// Read messages from object
|
||||
while(obj->m_messages_out.size() > 0)
|
||||
{
|
||||
m_active_object_messages.push_back(
|
||||
obj->m_messages_out.pop_front());
|
||||
while (obj->m_messages_out.size() > 0) {
|
||||
m_active_object_messages.push_back(obj->m_messages_out.pop_front());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2759,11 +2749,10 @@ void ServerEnvironment::step(float dtime)
|
|||
|
||||
ServerActiveObject* ServerEnvironment::getActiveObject(u16 id)
|
||||
{
|
||||
core::map<u16, ServerActiveObject*>::Node *n;
|
||||
n = m_active_objects.find(id);
|
||||
if(n == NULL)
|
||||
std::map<u16, ServerActiveObject*>::iterator i = m_active_objects.find(id);
|
||||
if (i == m_active_objects.end())
|
||||
return NULL;
|
||||
return n->getValue();
|
||||
return i->second;
|
||||
}
|
||||
|
||||
bool ServerEnvironment::propogateEnergy(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos)
|
||||
|
@ -3037,24 +3026,18 @@ bool ServerEnvironment::propogateEnergy(u8 level, v3s16 powersrc, v3s16 signalsr
|
|||
return false;
|
||||
}
|
||||
|
||||
bool isFreeServerActiveObjectId(u16 id,
|
||||
core::map<u16, ServerActiveObject*> &objects)
|
||||
bool isFreeServerActiveObjectId(u16 id, std::map<u16, ServerActiveObject*> &objects)
|
||||
{
|
||||
if (id == 0)
|
||||
return false;
|
||||
|
||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
||||
i = objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
if(i.getNode()->getKey() == id)
|
||||
std::map<u16, ServerActiveObject*>::iterator i = objects.find(id);
|
||||
if (i == objects.end())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
u16 getFreeServerActiveObjectId(
|
||||
core::map<u16, ServerActiveObject*> &objects)
|
||||
u16 getFreeServerActiveObjectId(std::map<u16, ServerActiveObject*> &objects)
|
||||
{
|
||||
//try to reuse id's as late as possible
|
||||
static u16 last_used_id = 0;
|
||||
|
@ -3137,13 +3120,10 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
|
|||
- discard objects that are found in current_objects.
|
||||
- add remaining objects to added_objects
|
||||
*/
|
||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
u16 id = i.getNode()->getKey();
|
||||
for (std::map<u16, ServerActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
u16 id = i->first;
|
||||
// Get object
|
||||
ServerActiveObject *object = i.getNode()->getValue();
|
||||
ServerActiveObject *object = i->second;
|
||||
if (object == NULL)
|
||||
continue;
|
||||
// Discard if removed
|
||||
|
@ -3248,7 +3228,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, bool set_c
|
|||
/*infostream<<"ServerEnvironment::addActiveObjectRaw(): "
|
||||
<<"added (id="<<object->getId()<<")"<<std::endl;*/
|
||||
|
||||
m_active_objects.insert(object->getId(), object);
|
||||
m_active_objects[object->getId()] = object;
|
||||
|
||||
verbosestream<<"ServerEnvironment::addActiveObjectRaw(): "
|
||||
<<"Added id="<<object->getId()<<"; there are now "
|
||||
|
@ -3285,16 +3265,12 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, bool set_c
|
|||
*/
|
||||
void ServerEnvironment::removeRemovedObjects()
|
||||
{
|
||||
core::list<u16> objects_to_remove;
|
||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
u16 id = i.getNode()->getKey();
|
||||
ServerActiveObject* obj = i.getNode()->getValue();
|
||||
std::vector<u16> objects_to_remove;
|
||||
for (std::map<u16, ServerActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
u16 id = i->first;
|
||||
ServerActiveObject* obj = i->second;
|
||||
// This shouldn't happen but check it
|
||||
if(obj == NULL)
|
||||
{
|
||||
if (obj == NULL) {
|
||||
infostream<<"NULL object found in ServerEnvironment"
|
||||
<<" while finding removed objects. id="<<id<<std::endl;
|
||||
// Id to be removed from m_active_objects
|
||||
|
@ -3312,11 +3288,9 @@ void ServerEnvironment::removeRemovedObjects()
|
|||
/*
|
||||
Delete static data from block if is marked as removed
|
||||
*/
|
||||
if(obj->m_static_exists && obj->m_removed)
|
||||
{
|
||||
if (obj->m_static_exists && obj->m_removed) {
|
||||
MapBlock *block = m_map->emergeBlock(obj->m_static_block);
|
||||
if(block)
|
||||
{
|
||||
if (block) {
|
||||
block->m_static_objects.remove(id);
|
||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
||||
obj->m_static_exists = false;
|
||||
|
@ -3333,10 +3307,8 @@ void ServerEnvironment::removeRemovedObjects()
|
|||
objects_to_remove.push_back(id);
|
||||
}
|
||||
// Remove references from m_active_objects
|
||||
for(core::list<u16>::Iterator i = objects_to_remove.begin();
|
||||
i != objects_to_remove.end(); i++)
|
||||
{
|
||||
m_active_objects.remove(*i);
|
||||
for (std::vector<u16>::iterator i = objects_to_remove.begin(); i != objects_to_remove.end(); i++) {
|
||||
m_active_objects.erase(*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3401,7 +3373,7 @@ void ServerEnvironment::activateObjects(MapBlock *block)
|
|||
}
|
||||
// A list for objects that couldn't be converted to static for some
|
||||
// reason. They will be stored back.
|
||||
core::list<StaticObject> new_stored;
|
||||
std::vector<StaticObject> new_stored;
|
||||
// Loop through stored static objects
|
||||
for (core::list<StaticObject>::Iterator
|
||||
i = block->m_static_objects.m_stored.begin();
|
||||
|
@ -3414,8 +3386,7 @@ void ServerEnvironment::activateObjects(MapBlock *block)
|
|||
ServerActiveObject *obj = ServerActiveObject::create
|
||||
(s_obj.type, this, 0, s_obj.pos, s_obj.data);
|
||||
// If couldn't create object, store static data back.
|
||||
if(obj==NULL)
|
||||
{
|
||||
if (obj==NULL) {
|
||||
errorstream<<"ServerEnvironment::activateObjects(): "
|
||||
<<"failed to create active object from static object "
|
||||
<<"in block "<<PP(s_obj.pos/BS)
|
||||
|
@ -3434,10 +3405,7 @@ void ServerEnvironment::activateObjects(MapBlock *block)
|
|||
// Clear stored list
|
||||
block->m_static_objects.m_stored.clear();
|
||||
// Add leftover failed stuff to stored list
|
||||
for(core::list<StaticObject>::Iterator
|
||||
i = new_stored.begin();
|
||||
i != new_stored.end(); i++)
|
||||
{
|
||||
for (std::vector<StaticObject>::iterator i = new_stored.begin(); i != new_stored.end(); i++) {
|
||||
StaticObject &s_obj = *i;
|
||||
block->m_static_objects.m_stored.push_back(s_obj);
|
||||
}
|
||||
|
@ -3462,16 +3430,12 @@ void ServerEnvironment::activateObjects(MapBlock *block)
|
|||
*/
|
||||
void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
||||
{
|
||||
core::list<u16> objects_to_remove;
|
||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
ServerActiveObject* obj = i.getNode()->getValue();
|
||||
std::vector<u16> objects_to_remove;
|
||||
for (std::map<u16, ServerActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
ServerActiveObject* obj = i->second;
|
||||
|
||||
// This shouldn't happen but check it
|
||||
if(obj == NULL)
|
||||
{
|
||||
if (obj == NULL) {
|
||||
errorstream<<"NULL object found in ServerEnvironment"
|
||||
<<std::endl;
|
||||
assert(0);
|
||||
|
@ -3482,23 +3446,49 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||
if (obj->m_pending_deactivation)
|
||||
continue;
|
||||
|
||||
u16 id = i.getNode()->getKey();
|
||||
u16 id = i->first;
|
||||
v3f objectpos = obj->getBasePosition();
|
||||
|
||||
// The block in which the object resides in
|
||||
v3s16 blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS));
|
||||
|
||||
// If known by some client, don't immediately delete.
|
||||
bool pending_delete = (obj->m_known_by_count > 0 && !force_delete);
|
||||
|
||||
// If block is active, don't remove
|
||||
if(m_active_blocks.contains(blockpos_o))
|
||||
if (m_active_blocks.contains(blockpos_o)) {
|
||||
if (obj->m_static_exists && blockpos_o != obj->m_static_block) {
|
||||
std::string staticdata_new = obj->getStaticData();
|
||||
StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
|
||||
|
||||
MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
|
||||
if (block) {
|
||||
block->m_static_objects.remove(id);
|
||||
obj->m_static_exists = false;
|
||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
||||
}
|
||||
block = m_map->emergeBlock(blockpos_o);
|
||||
if (block) {
|
||||
if (block->m_static_objects.m_stored.size() < 50) {
|
||||
u16 new_id = pending_delete ? id : 0;
|
||||
block->m_static_objects.insert(new_id, s_obj);
|
||||
|
||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
||||
|
||||
obj->m_static_exists = true;
|
||||
obj->m_static_block = block->getPos();
|
||||
}else{
|
||||
obj->m_removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
verbosestream<<"ServerEnvironment::deactivateFarObjects(): "
|
||||
<<"deactivating object id="<<id<<" on inactive block "
|
||||
<<PP(blockpos_o)<<std::endl;
|
||||
|
||||
// If known by some client, don't immediately delete.
|
||||
bool pending_delete = (obj->m_known_by_count > 0 && !force_delete);
|
||||
|
||||
/*
|
||||
Update the static data
|
||||
*/
|
||||
|
@ -3516,13 +3506,11 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||
|
||||
MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
|
||||
|
||||
core::map<u16, StaticObject>::Node *n =
|
||||
block->m_static_objects.m_active.find(id);
|
||||
core::map<u16, StaticObject>::Node *n = block->m_static_objects.m_active.find(id);
|
||||
if (n) {
|
||||
StaticObject static_old = n->getValue();
|
||||
|
||||
if(static_old.data == staticdata_new &&
|
||||
(static_old.pos - objectpos).getLength() < 2*BS)
|
||||
if (static_old.data == staticdata_new && (static_old.pos - objectpos).getLength() < 2*BS)
|
||||
data_changed = false;
|
||||
}else{
|
||||
errorstream<<"ServerEnvironment::deactivateFarObjects(): "
|
||||
|
@ -3533,11 +3521,9 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||
}
|
||||
|
||||
// Delete old static object
|
||||
if(obj->m_static_exists)
|
||||
{
|
||||
if (obj->m_static_exists) {
|
||||
MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
|
||||
if(block)
|
||||
{
|
||||
if (block) {
|
||||
block->m_static_objects.remove(id);
|
||||
obj->m_static_exists = false;
|
||||
// Only mark block as modified if data changed considerably
|
||||
|
@ -3551,8 +3537,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||
// Get or generate the block
|
||||
MapBlock *block = m_map->emergeBlock(blockpos);
|
||||
|
||||
if(block)
|
||||
{
|
||||
if (block) {
|
||||
if (block->m_static_objects.m_stored.size() >= 49) {
|
||||
errorstream<<"ServerEnv: Trying to store id="<<obj->getId()
|
||||
<<" statically but block "<<PP(blockpos)
|
||||
|
@ -3572,8 +3557,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||
obj->m_static_exists = true;
|
||||
obj->m_static_block = block->getPos();
|
||||
}
|
||||
}
|
||||
else{
|
||||
}else{
|
||||
errorstream<<"ServerEnv: Could not find or generate "
|
||||
<<"a block for storing id="<<obj->getId()
|
||||
<<" statically"<<std::endl;
|
||||
|
@ -3585,8 +3569,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||
Otherwise delete it immediately.
|
||||
*/
|
||||
|
||||
if(pending_delete)
|
||||
{
|
||||
if (pending_delete) {
|
||||
verbosestream<<"ServerEnvironment::deactivateFarObjects(): "
|
||||
<<"object id="<<id<<" is known by clients"
|
||||
<<"; not deleting yet"<<std::endl;
|
||||
|
@ -3605,10 +3588,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||
}
|
||||
|
||||
// Remove references from m_active_objects
|
||||
for(core::list<u16>::Iterator i = objects_to_remove.begin();
|
||||
i != objects_to_remove.end(); i++)
|
||||
{
|
||||
m_active_objects.remove(*i);
|
||||
for (std::vector<u16>::iterator i = objects_to_remove.begin(); i != objects_to_remove.end(); i++) {
|
||||
m_active_objects.erase(*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3631,11 +3612,8 @@ ClientEnvironment::ClientEnvironment(Client *client, ClientMap *map, scene::ISce
|
|||
ClientEnvironment::~ClientEnvironment()
|
||||
{
|
||||
// delete active objects
|
||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
delete i.getNode()->getValue();
|
||||
for (std::map<u16, ClientActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
delete i->second;
|
||||
}
|
||||
|
||||
// Drop/delete map
|
||||
|
@ -3943,16 +3921,12 @@ void ClientEnvironment::step(float dtime)
|
|||
Step active objects and update lighting of them
|
||||
*/
|
||||
|
||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
ClientActiveObject* obj = i.getNode()->getValue();
|
||||
for (std::map<u16, ClientActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
ClientActiveObject* obj = i->second;
|
||||
// Step object
|
||||
obj->step(dtime, this);
|
||||
|
||||
if(m_active_object_light_update_interval.step(dtime, 0.21))
|
||||
{
|
||||
if (m_active_object_light_update_interval.step(dtime, 0.21)) {
|
||||
// Update lighting
|
||||
//u8 light = LIGHT_MAX;
|
||||
u8 light = 0;
|
||||
|
@ -3980,31 +3954,24 @@ void ClientEnvironment::expireMeshes(bool only_daynight_diffed)
|
|||
|
||||
ClientActiveObject* ClientEnvironment::getActiveObject(u16 id)
|
||||
{
|
||||
core::map<u16, ClientActiveObject*>::Node *n;
|
||||
n = m_active_objects.find(id);
|
||||
if(n == NULL)
|
||||
std::map<u16, ClientActiveObject*>::iterator i = m_active_objects.find(id);
|
||||
if (i == m_active_objects.end())
|
||||
return NULL;
|
||||
return n->getValue();
|
||||
return i->second;
|
||||
}
|
||||
|
||||
bool isFreeClientActiveObjectId(u16 id,
|
||||
core::map<u16, ClientActiveObject*> &objects)
|
||||
bool isFreeClientActiveObjectId(u16 id, std::map<u16, ClientActiveObject*> &objects)
|
||||
{
|
||||
if (id == 0)
|
||||
return false;
|
||||
|
||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
||||
i = objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
if(i.getNode()->getKey() == id)
|
||||
std::map<u16, ClientActiveObject*>::iterator i = objects.find(id);
|
||||
if (i == objects.end())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
u16 getFreeClientActiveObjectId(
|
||||
core::map<u16, ClientActiveObject*> &objects)
|
||||
u16 getFreeClientActiveObjectId(std::map<u16, ClientActiveObject*> &objects)
|
||||
{
|
||||
//try to reuse id's as late as possible
|
||||
static u16 last_used_id = 0;
|
||||
|
@ -4045,7 +4012,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
|
|||
}
|
||||
infostream<<"ClientEnvironment::addActiveObject(): "
|
||||
<<"added (id="<<object->getId()<<")"<<std::endl;
|
||||
m_active_objects.insert(object->getId(), object);
|
||||
m_active_objects[object->getId()] = object;
|
||||
object->addToScene(m_smgr);
|
||||
{ // Update lighting immediately
|
||||
u8 light = 0;
|
||||
|
@ -4091,7 +4058,7 @@ void ClientEnvironment::removeActiveObject(u16 id)
|
|||
}
|
||||
obj->removeFromScene();
|
||||
delete obj;
|
||||
m_active_objects.remove(id);
|
||||
m_active_objects.erase(id);
|
||||
}
|
||||
|
||||
void ClientEnvironment::processActiveObjectMessage(u16 id,
|
||||
|
@ -4132,14 +4099,10 @@ void ClientEnvironment::damageLocalPlayer(u8 damage)
|
|||
Client likes to call these
|
||||
*/
|
||||
|
||||
void ClientEnvironment::getActiveObjects(v3f origin, f32 max_d,
|
||||
core::array<DistanceSortedActiveObject> &dest)
|
||||
void ClientEnvironment::getActiveObjects(v3f origin, f32 max_d, core::array<DistanceSortedActiveObject> &dest)
|
||||
{
|
||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
ClientActiveObject* obj = i.getNode()->getValue();
|
||||
for (std::map<u16, ClientActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
ClientActiveObject* obj = i->second;
|
||||
|
||||
f32 d = (obj->getPosition() - origin).getLength();
|
||||
|
||||
|
@ -4241,13 +4204,11 @@ bool ClientEnvironment::searchNearInv(v3s16 pos, v3s16 radius_min, v3s16 radius_
|
|||
|
||||
void ClientEnvironment::updateObjectsCameraOffset(v3s16 camera_offset)
|
||||
{
|
||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
||||
i = m_active_objects.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
ClientActiveObject* obj = i.getNode()->getValue();
|
||||
for (std::map<u16, ClientActiveObject*>::iterator i = m_active_objects.begin(); i != m_active_objects.end(); i++) {
|
||||
ClientActiveObject* obj = i->second;
|
||||
obj->updateCameraOffset(camera_offset);
|
||||
}
|
||||
|
||||
for (core::list<Player*>::Iterator i = m_players.begin();
|
||||
i != m_players.end(); i++)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "common_irrlicht.h"
|
||||
#include "player.h"
|
||||
#include "map.h"
|
||||
|
@ -301,7 +302,7 @@ private:
|
|||
// Pointer to server (which is handling this environment)
|
||||
Server *m_server;
|
||||
// Active object list
|
||||
core::map<u16, ServerActiveObject*> m_active_objects;
|
||||
std::map<u16, ServerActiveObject*> m_active_objects;
|
||||
// Outgoing network message buffer for active objects
|
||||
Queue<ActiveObjectMessage> m_active_object_messages;
|
||||
// Some timers
|
||||
|
@ -425,8 +426,7 @@ public:
|
|||
*/
|
||||
|
||||
// Get all nearby objects
|
||||
void getActiveObjects(v3f origin, f32 max_d,
|
||||
core::array<DistanceSortedActiveObject> &dest);
|
||||
void getActiveObjects(v3f origin, f32 max_d, core::array<DistanceSortedActiveObject> &dest);
|
||||
|
||||
void updateObjectsCameraOffset(v3s16 camera_offset);
|
||||
|
||||
|
@ -462,7 +462,7 @@ private:
|
|||
Client *m_client;
|
||||
ClientMap *m_map;
|
||||
scene::ISceneManager *m_smgr;
|
||||
core::map<u16, ClientActiveObject*> m_active_objects;
|
||||
std::map<u16, ClientActiveObject*> m_active_objects;
|
||||
Queue<ClientEnvEvent> m_client_event_queue;
|
||||
IntervalLimiter m_active_object_light_update_interval;
|
||||
IntervalLimiter m_lava_hurt_interval;
|
||||
|
|
|
@ -1255,23 +1255,6 @@ void Server::AsyncRunStep()
|
|||
|
||||
core::map<v3s16, MapBlock*> modified_blocks;
|
||||
m_env.getMap().transformLiquids(modified_blocks);
|
||||
#if 0
|
||||
/*
|
||||
Update lighting
|
||||
*/
|
||||
core::map<v3s16, MapBlock*> lighting_modified_blocks;
|
||||
ServerMap &map = ((ServerMap&)m_env.getMap());
|
||||
map.updateLighting(modified_blocks, lighting_modified_blocks);
|
||||
|
||||
// Add blocks modified by lighting to modified_blocks
|
||||
for(core::map<v3s16, MapBlock*>::Iterator
|
||||
i = lighting_modified_blocks.getIterator();
|
||||
i.atEnd() == false; i++)
|
||||
{
|
||||
MapBlock *block = i.getNode()->getValue();
|
||||
modified_blocks.insert(block->getPos(), block);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Set the modified blocks unsent for all the clients
|
||||
*/
|
||||
|
|
|
@ -32,11 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#ifdef _WIN32
|
||||
#pragma message ("Disabling unit tests")
|
||||
#else
|
||||
#warning "Disabling unit tests"
|
||||
#endif
|
||||
// Disable unit tests
|
||||
#define ENABLE_TESTS 0
|
||||
#else
|
||||
|
|
|
@ -1,21 +1,28 @@
|
|||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* utility.h
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2014 <lisa@ltmnet.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef UTILITY_HEADER
|
||||
#define UTILITY_HEADER
|
||||
|
|
Loading…
Reference in New Issue