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.
+MeshUpdateQueue::(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
#include <sstream>
#include "porting.h"
#include "mapsector.h"
+#include "mapblock_mesh.h"
+#include "mapblock.h"
+
+/*
+ QueuedMeshUpdate
+*/
+
+QueuedMeshUpdate::QueuedMeshUpdate():
+ p(-1337,-1337,-1337),
+ data(NULL),
+ ack_block_to_server(false)
+{
+}
+
+QueuedMeshUpdate::~QueuedMeshUpdate()
+{
+ if(data)
+ delete data;
+}
+
+/*
+ MeshUpdateQueue
+*/
+
+MeshUpdateQueue::MeshUpdateQueue()
+{
+ m_mutex.Init();
+}
+
+MeshUpdateQueue::~MeshUpdateQueue()
+{
+ JMutexAutoLock lock(m_mutex);
+
+ core::list<QueuedMeshUpdate*>::Iterator i;
+ for(i=m_queue.begin(); i!=m_queue.end(); i++)
+ {
+ QueuedMeshUpdate *q = *i;
+ delete q;
+ }
+}
+
+/*
+ peer_id=0 adds with nobody to send to
+*/
+void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_server)
+{
+ DSTACK(__FUNCTION_NAME);
+
+ assert(data);
+
+ JMutexAutoLock lock(m_mutex);
+
+ /*
+ Find if block is already in queue.
+ If it is, update the data and quit.
+ */
+ core::list<QueuedMeshUpdate*>::Iterator i;
+ for(i=m_queue.begin(); i!=m_queue.end(); i++)
+ {
+ QueuedMeshUpdate *q = *i;
+ if(q->p == p)
+ {
+ if(q->data)
+ delete q->data;
+ q->data = data;
+ if(ack_block_to_server)
+ q->ack_block_to_server = true;
+ return;
+ }
+ }
+
+ /*
+ Add the block
+ */
+ QueuedMeshUpdate *q = new QueuedMeshUpdate;
+ q->p = p;
+ q->data = data;
+ q->ack_block_to_server = ack_block_to_server;
+ m_queue.push_back(q);
+}
+
+// Returned pointer must be deleted
+// Returns NULL if queue is empty
+QueuedMeshUpdate * MeshUpdateQueue::pop()
+{
+ JMutexAutoLock lock(m_mutex);
+
+ core::list<QueuedMeshUpdate*>::Iterator i = m_queue.begin();
+ if(i == m_queue.end())
+ return NULL;
+ QueuedMeshUpdate *q = *i;
+ m_queue.erase(i);
+ return q;
+}
+
+/*
+ MeshUpdateThread
+*/
void * MeshUpdateThread::Thread()
{
try
{
- TimeTaker timer3("Client::addNode(): addNodeAndUpdate");
+ //TimeTaker timer3("Client::addNode(): addNodeAndUpdate");
m_env.getMap().addNodeAndUpdate(p, n, modified_blocks);
}
catch(InvalidPositionException &e)
<<std::endl;*/
}
-/*s32 Client::getDayNightIndex()
-{
- assert(m_daynight_i >= 0 && m_daynight_i < DAYNIGHT_CACHE_COUNT);
- return m_daynight_i;
-}*/
-
u32 Client::getDayNightRatio()
{
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
return player->hp;
}
+void Client::setTempMod(v3s16 p, NodeMod mod)
+{
+ //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
+ assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
+
+ core::map<v3s16, MapBlock*> affected_blocks;
+ ((ClientMap&)m_env.getMap()).setTempMod(p, mod,
+ &affected_blocks);
+
+ for(core::map<v3s16, MapBlock*>::Iterator
+ i = affected_blocks.getIterator();
+ i.atEnd() == false; i++)
+ {
+ i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
+ }
+}
+
+void Client::clearTempMod(v3s16 p)
+{
+ //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
+ assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
+
+ core::map<v3s16, MapBlock*> affected_blocks;
+ ((ClientMap&)m_env.getMap()).clearTempMod(p,
+ &affected_blocks);
+
+ for(core::map<v3s16, MapBlock*>::Iterator
+ i = affected_blocks.getIterator();
+ i.atEnd() == false; i++)
+ {
+ i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
+ }
+}
+
void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server)
{
/*dstream<<"Client::addUpdateMeshTask(): "
#include <ostream>
#include "clientobject.h"
+struct MeshMakeData;
+
class ClientNotReadyException : public BaseException
{
public:
MeshMakeData *data;
bool ack_block_to_server;
- QueuedMeshUpdate():
- p(-1337,-1337,-1337),
- data(NULL),
- ack_block_to_server(false)
- {
- }
-
- ~QueuedMeshUpdate()
- {
- if(data)
- delete data;
- }
+ QueuedMeshUpdate();
+ ~QueuedMeshUpdate();
};
/*
class MeshUpdateQueue
{
public:
- MeshUpdateQueue()
- {
- m_mutex.Init();
- }
-
- ~MeshUpdateQueue()
- {
- JMutexAutoLock lock(m_mutex);
+ MeshUpdateQueue();
- core::list<QueuedMeshUpdate*>::Iterator i;
- for(i=m_queue.begin(); i!=m_queue.end(); i++)
- {
- QueuedMeshUpdate *q = *i;
- delete q;
- }
- }
+ ~MeshUpdateQueue();
/*
peer_id=0 adds with nobody to send to
*/
- void addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_server)
- {
- DSTACK(__FUNCTION_NAME);
-
- assert(data);
-
- JMutexAutoLock lock(m_mutex);
-
- /*
- Find if block is already in queue.
- If it is, update the data and quit.
- */
- core::list<QueuedMeshUpdate*>::Iterator i;
- for(i=m_queue.begin(); i!=m_queue.end(); i++)
- {
- QueuedMeshUpdate *q = *i;
- if(q->p == p)
- {
- if(q->data)
- delete q->data;
- q->data = data;
- if(ack_block_to_server)
- q->ack_block_to_server = true;
- return;
- }
- }
-
- /*
- Add the block
- */
- QueuedMeshUpdate *q = new QueuedMeshUpdate;
- q->p = p;
- q->data = data;
- q->ack_block_to_server = ack_block_to_server;
- m_queue.push_back(q);
- }
+ void addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_server);
// Returned pointer must be deleted
// Returns NULL if queue is empty
- QueuedMeshUpdate * pop()
- {
- JMutexAutoLock lock(m_mutex);
-
- core::list<QueuedMeshUpdate*>::Iterator i = m_queue.begin();
- if(i == m_queue.end())
- return NULL;
- QueuedMeshUpdate *q = *i;
- m_queue.erase(i);
- return q;
- }
+ QueuedMeshUpdate * pop();
u32 size()
{
u16 getHP();
- //void updateSomeExpiredMeshes();
-
- void setTempMod(v3s16 p, NodeMod mod)
- {
- //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
- assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
-
- core::map<v3s16, MapBlock*> affected_blocks;
- ((ClientMap&)m_env.getMap()).setTempMod(p, mod,
- &affected_blocks);
-
- for(core::map<v3s16, MapBlock*>::Iterator
- i = affected_blocks.getIterator();
- i.atEnd() == false; i++)
- {
- i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
- }
- }
- void clearTempMod(v3s16 p)
- {
- //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
- assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
-
- core::map<v3s16, MapBlock*> affected_blocks;
- ((ClientMap&)m_env.getMap()).clearTempMod(p,
- &affected_blocks);
-
- for(core::map<v3s16, MapBlock*>::Iterator
- i = affected_blocks.getIterator();
- i.atEnd() == false; i++)
- {
- i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
- }
- }
+ void setTempMod(v3s16 p, NodeMod mod);
+ void clearTempMod(v3s16 p);
float getAvgRtt()
{
#include "porting.h"
#include "collision.h"
#include "content_mapnode.h"
-
+#include "mapblock.h"
Environment::Environment():
m_time_of_day(9000)
#include "clouds.h"
#include "keycode.h"
#include "farmesh.h"
+#include "mapblock.h"
-// TODO: Move content-aware stuff to separate file
+/*
+ TODO: Move content-aware stuff to separate file by adding properties
+ and virtual interfaces
+*/
#include "content_mapnode.h"
#include "content_nodemeta.h"
from big caves and such\r
FIXME: Block send distance configuration does not take effect for some reason\r
\r
-TODO: Map saving should be done by EmergeThread\r
-\r
SUGG: Map unloading based on sector reference is not very good, it keeps\r
unnecessary stuff in memory. I guess. Investigate this.\r
\r
#include "serverobject.h"
#include "content_mapnode.h"
#include "mapgen.h"
+#include "nodemetadata.h"
extern "C" {
#include "sqlite3.h"
return block;
}
-
-/*MapBlock * Map::getBlockCreate(v3s16 p3d)
-{
- v2s16 p2d(p3d.X, p3d.Z);
- MapSector * sector = getSectorCreate(p2d);
- assert(sector);
- MapBlock *block = sector->getBlockNoCreate(p3d.Y);
- if(block)
- return block;
- block = sector->createBlankBlock(p3d.Y);
- return block;
-}*/
-
bool Map::isNodeUnderground(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
}
}
+bool Map::isValidPosition(v3s16 p)
+{
+ v3s16 blockpos = getNodeBlockPos(p);
+ MapBlock *block = getBlockNoCreate(blockpos);
+ return (block != NULL);
+}
+
+// Returns a CONTENT_IGNORE node if not found
+MapNode Map::getNodeNoEx(v3s16 p)
+{
+ v3s16 blockpos = getNodeBlockPos(p);
+ MapBlock *block = getBlockNoCreateNoEx(blockpos);
+ if(block == NULL)
+ return MapNode(CONTENT_IGNORE);
+ v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
+ return block->getNodeNoCheck(relpos);
+}
+
+// throws InvalidPositionException if not found
+MapNode Map::getNode(v3s16 p)
+{
+ v3s16 blockpos = getNodeBlockPos(p);
+ MapBlock *block = getBlockNoCreateNoEx(blockpos);
+ if(block == NULL)
+ throw InvalidPositionException();
+ v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
+ return block->getNodeNoCheck(relpos);
+}
+
+// throws InvalidPositionException if not found
+void Map::setNode(v3s16 p, MapNode & n)
+{
+ v3s16 blockpos = getNodeBlockPos(p);
+ MapBlock *block = getBlockNoCreate(blockpos);
+ v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
+ block->setNodeNoCheck(relpos, n);
+}
+
+
/*
Goes recursively through the neighbours of the node.
/*
Update lighting
*/
-
- core::map<v3s16, MapBlock*> lighting_update_blocks;
- // Center block
- lighting_update_blocks.insert(block->getPos(), block);
-#if 0
- // All modified blocks
- for(core::map<v3s16, MapBlock*>::Iterator
- i = changed_blocks.getIterator();
- i.atEnd() == false; i++)
{
- lighting_update_blocks.insert(i.getNode()->getKey(),
- i.getNode()->getValue());
+ TimeTaker t("finishBlockMake lighting update");
+
+ core::map<v3s16, MapBlock*> lighting_update_blocks;
+ // Center block
+ lighting_update_blocks.insert(block->getPos(), block);
+ #if 0
+ // All modified blocks
+ for(core::map<v3s16, MapBlock*>::Iterator
+ i = changed_blocks.getIterator();
+ i.atEnd() == false; i++)
+ {
+ lighting_update_blocks.insert(i.getNode()->getKey(),
+ i.getNode()->getValue());
+ }
+ #endif
+ updateLighting(lighting_update_blocks, changed_blocks);
}
-#endif
- updateLighting(lighting_update_blocks, changed_blocks);
-
+
/*
Add random objects to block
*/
#include <jthread.h>
#include <iostream>
-#ifdef _WIN32
- #include <windows.h>
- #define sleep_s(x) Sleep((x*1000))
-#else
- #include <unistd.h>
- #define sleep_s(x) sleep(x)
-#endif
-
#include "common_irrlicht.h"
#include "mapnode.h"
-#include "mapblock.h"
+#include "mapblock_nodemod.h"
#include "constants.h"
#include "voxel.h"
-#include "mapchunk.h"
-#include "nodemetadata.h"
class MapSector;
class ServerMapSector;
class ClientMapSector;
-
class MapBlock;
+class NodeMetadata;
namespace mapgen{
struct BlockMakeData;
MapBlock * getBlockNoCreate(v3s16 p);
// Returns NULL if not found
MapBlock * getBlockNoCreateNoEx(v3s16 p);
- // Gets an existing block or creates an empty one
- //MapBlock * getBlockCreate(v3s16 p);
// Returns InvalidPositionException if not found
bool isNodeUnderground(v3s16 p);
- // virtual from NodeContainer
- bool isValidPosition(v3s16 p)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- MapBlock *blockref;
- try{
- blockref = getBlockNoCreate(blockpos);
- }
- catch(InvalidPositionException &e)
- {
- return false;
- }
- return true;
- /*v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- bool is_valid = blockref->isValidPosition(relpos);
- return is_valid;*/
- }
+ bool isValidPosition(v3s16 p);
- // virtual from NodeContainer
// throws InvalidPositionException if not found
- MapNode getNode(v3s16 p)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- MapBlock * blockref = getBlockNoCreate(blockpos);
- v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
+ MapNode getNode(v3s16 p);
- return blockref->getNodeNoCheck(relpos);
- }
-
- // virtual from NodeContainer
// throws InvalidPositionException if not found
- void setNode(v3s16 p, MapNode & n)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- MapBlock * blockref = getBlockNoCreate(blockpos);
- v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- blockref->setNodeNoCheck(relpos, n);
- }
+ void setNode(v3s16 p, MapNode & n);
// Returns a CONTENT_IGNORE node if not found
- MapNode getNodeNoEx(v3s16 p)
- {
- try{
- v3s16 blockpos = getNodeBlockPos(p);
- MapBlock * blockref = getBlockNoCreate(blockpos);
- v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
-
- return blockref->getNodeNoCheck(relpos);
- }
- catch(InvalidPositionException &e)
- {
- return MapNode(CONTENT_IGNORE);
- }
- }
+ MapNode getNodeNoEx(v3s16 p);
void unspreadLight(enum LightBank bank,
core::map<v3s16, u8> & from_nodes,
#include "map.h"
#include "inventory.h"
#include "utility.h"
+#include "mapblock.h"
/*
MapBlockObject
#ifndef MAPCHUNK_HEADER
#define MAPCHUNK_HEADER
+/*
+ TODO: Remove
+*/
+
+#if 0
/*
MapChunk contains map-generation-time metadata for an area of
some MapSectors. (something like 16x16)
u8 m_generation_level;
bool m_modified;
};
+#endif
#endif
#include "content_mapnode.h"
#include "content_craft.h"
#include "content_nodemeta.h"
+#include "mapblock.h"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)