Newer
Older
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
Perttu Ahola
committed
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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
Perttu Ahola
committed
GNU Lesser General Public License for more details.
Perttu Ahola
committed
You should have received a copy of the GNU Lesser 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.
*/
Perttu Ahola
committed
#include <queue>
#include "clientserver.h"
#include "map.h"
#include "jmutexautolock.h"
#include "main.h"
#include "constants.h"
#include "voxel.h"
#include "filesys.h"
Perttu Ahola
committed
#include "serverobject.h"
#include "settings.h"
#include "profiler.h"
#include "log.h"
#include "itemdef.h"
Perttu Ahola
committed
#include "mapgen.h"
#include "content_mapnode.h"
#include "content_nodemeta.h"
Perttu Ahola
committed
#include "content_abm.h"
#include "content_sao.h"
Perttu Ahola
committed
#include "sha1.h"
#include "base64.h"
#include "sound.h" // dummySoundManager
#include "util/string.h"
#include "util/pointedthing.h"
Perttu Ahola
committed
#include "util/serialize.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
Perttu Ahola
committed
class MapEditEventIgnorer
{
public:
MapEditEventIgnorer(bool *flag):
m_flag(flag)
{
if(*m_flag == false)
*m_flag = true;
else
m_flag = NULL;
}
~MapEditEventIgnorer()
{
if(m_flag)
{
assert(*m_flag);
*m_flag = false;
}
}
private:
bool *m_flag;
};
class MapEditEventAreaIgnorer
{
public:
MapEditEventAreaIgnorer(VoxelArea *ignorevariable, const VoxelArea &a):
m_ignorevariable(ignorevariable)
{
if(m_ignorevariable->getVolume() == 0)
*m_ignorevariable = a;
else
m_ignorevariable = NULL;
}
~MapEditEventAreaIgnorer()
{
if(m_ignorevariable)
{
assert(m_ignorevariable->getVolume() != 0);
*m_ignorevariable = VoxelArea();
}
}
private:
VoxelArea *m_ignorevariable;
};
void * ServerThread::Thread()
{
ThreadStarted();
log_register_thread("ServerThread");
BEGIN_DEBUG_EXCEPTION_HANDLER
//TimeTaker timer("AsyncRunStep() + Receive()");
{
//TimeTaker timer("AsyncRunStep()");
m_server->AsyncRunStep();
}
//infostream<<"Running m_server->Receive()"<<std::endl;
m_server->Receive();
}
catch(con::NoIncomingDataException &e)
{
}
infostream<<"Server: PeerNotFoundException"<<std::endl;
catch(con::ConnectionBindFailed &e)
{
m_server->setAsyncFatalError(e.what());
}
Perttu Ahola
committed
catch(LuaError &e)
{
m_server->setAsyncFatalError(e.what());
}
END_DEBUG_EXCEPTION_HANDLER(errorstream)
return NULL;
}
void * EmergeThread::Thread()
{
ThreadStarted();
log_register_thread("EmergeThread");
BEGIN_DEBUG_EXCEPTION_HANDLER
bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
Perttu Ahola
committed
v3s16 last_tried_pos(-32768,-32768,-32768); // For error output
Perttu Ahola
committed
/*
Get block info from queue, emerge them and send them
to clients.
After queue is empty, exit.
*/
while(getRun())
QueuedBlockEmerge *qptr = m_server->m_emerge_queue.pop();
if(qptr == NULL)
break;
SharedPtr<QueuedBlockEmerge> q(qptr);
v3s16 &p = q->pos;
Perttu Ahola
committed
v2s16 p2d(p.X,p.Z);
Perttu Ahola
committed
last_tried_pos = p;
Perttu Ahola
committed
/*
Do not generate over-limit
*/
Perttu Ahola
committed
if(blockpos_over_limit(p))
Perttu Ahola
committed
continue;
//infostream<<"EmergeThread::Thread(): running"<<std::endl;
//TimeTaker timer("block emerge");
Loading
Loading full blame...