../minetest.conf
../../minetest.conf
+Command-line options:
+- Use --help
+
Running on Windows:
- The working directory should be ./bin
cp -r data/tree.png $PACKAGEPATH/data/
cp -r data/leaves.png $PACKAGEPATH/data/
cp -r data/mese.png $PACKAGEPATH/data/
-cp -r data/light.png $PACKAGEPATH/data/
+cp -r data/cloud.png $PACKAGEPATH/data/
cp -r data/sign.png $PACKAGEPATH/data/
cp -r data/sign_back.png $PACKAGEPATH/data/
cp -r data/rat.png $PACKAGEPATH/data/
block->deSerialize(istr, ser_version);
sector->insertBlock(block);
//block->setChangedFlag();
+
+ //DEBUG
+ /*NodeMod mod;
+ mod.type = NODEMOD_CHANGECONTENT;
+ mod.param = CONTENT_MESE;
+ block->setTempMod(v3s16(8,10,8), mod);
+ block->setTempMod(v3s16(8,9,8), mod);
+ block->setTempMod(v3s16(8,8,8), mod);
+ block->setTempMod(v3s16(8,7,8), mod);
+ block->setTempMod(v3s16(8,6,8), mod);*/
+
+ /*
+ Add some coulds
+ Well, this is a dumb way to do it, they should just
+ be drawn as separate objects.
+ */
+ /*if(p.Y == 3)
+ {
+ NodeMod mod;
+ mod.type = NODEMOD_CHANGECONTENT;
+ mod.param = CONTENT_CLOUD;
+ v3s16 p2;
+ p2.Y = 8;
+ for(p2.X=3; p2.X<=13; p2.X++)
+ for(p2.Z=3; p2.Z<=13; p2.Z++)
+ {
+ block->setTempMod(p2, mod);
+ }
+ }*/
}
} //envlock
}
/*
- length: 19
+ length: 17
[0] u16 command
- [2] u8 button (0=left, 1=right)
+ [2] u8 action
[3] v3s16 nodepos_undersurface
[9] v3s16 nodepos_abovesurface
[15] u16 item
+ actions:
+ 0: start digging
+ 1: place block
+ 2: stop digging (all parameters ignored)
*/
u8 datasize = 2 + 1 + 6 + 6 + 2;
SharedBuffer<u8> data(datasize);
- writeU16(&data[0], TOSERVER_PRESS_GROUND);
+ writeU16(&data[0], TOSERVER_GROUND_ACTION);
writeU8(&data[2], button);
writeV3S16(&data[3], nodepos_undersurface);
writeV3S16(&data[9], nodepos_oversurface);
Send(0, data, true);
}
-void Client::release(u8 button)
+void Client::stopDigging()
{
- //TODO
+ if(connectedAndInitialized() == false){
+ dout_client<<DTIME<<"Client::release() "
+ "cancelled (not connected)"
+ <<std::endl;
+ return;
+ }
+
+ /*
+ length: 17
+ [0] u16 command
+ [2] u8 action
+ [3] v3s16 nodepos_undersurface
+ [9] v3s16 nodepos_abovesurface
+ [15] u16 item
+ actions:
+ 0: start digging
+ 1: place block
+ 2: stop digging (all parameters ignored)
+ */
+ u8 datasize = 2 + 1 + 6 + 6 + 2;
+ SharedBuffer<u8> data(datasize);
+ writeU16(&data[0], TOSERVER_GROUND_ACTION);
+ writeU8(&data[2], 2);
+ writeV3S16(&data[3], v3s16(0,0,0));
+ writeV3S16(&data[9], v3s16(0,0,0));
+ writeU16(&data[15], 0);
+ Send(0, data, true);
}
void Client::sendSignText(v3s16 blockpos, s16 id, std::string text)
void pressGround(u8 button, v3s16 nodepos_undersurface,
v3s16 nodepos_oversurface, u16 item);
void clickObject(u8 button, v3s16 blockpos, s16 id, u16 item);
- void release(u8 button);
+ void stopDigging();
void sendSignText(v3s16 blockpos, s16 id, std::string text);
[11] u16 item
*/
- TOSERVER_PRESS_GROUND = 0x28,
+ TOSERVER_GROUND_ACTION = 0x28,
/*
length: 17
[0] u16 command
- [2] u8 button (0=left, 1=right)
+ [2] u8 action
[3] v3s16 nodepos_undersurface
[9] v3s16 nodepos_abovesurface
[15] u16 item
+ actions:
+ 0: start digging (from undersurface)
+ 1: place block (to abovesurface)
+ 2: stop digging (all parameters ignored)
*/
- TOSERVER_RELEASE = 0x29,
- /*
- length: 3
- [0] u16 command
- [2] u8 button
- */
+ TOSERVER_RELEASE = 0x29, // Not used
TOSERVER_SIGNTEXT = 0x30,
/*
#include "light.h"
-/*
-
-#!/usr/bin/python
-
-from math import *
-from sys import stdout
-
-# We want 0 at light=0 and 255 at light=LIGHT_MAX
-LIGHT_MAX = 15
-
-L = []
-for i in range(1,LIGHT_MAX+1):
- L.append(int(round(255.0 * 0.69 ** (i-1))))
- L.append(0)
-
-L.reverse()
-for i in L:
- stdout.write(str(i)+",\n")
-
-*/
-
-/*
- The first value should be 0, the last value should be 255.
-*/
+// LIGHT_MAX is 15, 0-15 is 16 values
/*u8 light_decode_table[LIGHT_MAX+1] =
{
0,
-2,
-3,
-4,
-6,
9,
-13,
-19,
-28,
-40,
-58,
-84,
-121,
-176,
+12,
+14,
+16,
+20,
+26,
+34,
+45,
+61,
+81,
+108,
+143,
+191,
255,
};*/
+u8 light_decode_table[LIGHT_MAX+1] =
+{
+0,
+5,
+12,
+22,
+35,
+50,
+65,
+85,
+100,
+120,
+140,
+160,
+185,
+215,
+255,
+};
+#if 0
/*
#!/usr/bin/python
191,
255,
};
-
-/*
-#!/usr/bin/python
-
-from math import *
-from sys import stdout
-
-# We want 0 at light=0 and 255 at light=LIGHT_MAX
-LIGHT_MAX = 14
-#FACTOR = 0.69
-FACTOR = 0.75
-
-maxlight = 255
-minlight = 8
-
-L = []
-for i in range(1,LIGHT_MAX+1):
- L.append(minlight+int(round((maxlight-minlight) * FACTOR ** (i-1))))
- #L.append(int(round(255.0 * FACTOR ** (i-1))))
-L.append(minlight)
-
-L.reverse()
-for i in L:
- stdout.write(str(i)+",\n")
-*/
-/*u8 light_decode_table[LIGHT_MAX+1] =
-{
-8,
-14,
-16,
-18,
-22,
-27,
-33,
-41,
-52,
-67,
-86,
-112,
-147,
-193,
-255,
-};*/
+#endif
// This directly sets the range of light
#define LIGHT_MAX 14
+// Light is stored as 4 bits, thus 15 is the maximum.
// This brightness is reserved for sunlight
#define LIGHT_SUN 15
NOTE: iostream.imbue(std::locale("C")) is very slow\r
NOTE: Global locale is now set at initialization\r
\r
-SUGGESTION: add a second lighting value to the MS nibble of param of\r
- air to tell how bright the air node is when there is no sunlight.\r
- When day changes to night, these two values can be interpolated.\r
+SUGG: Fix address to be ipv6 compatible\r
\r
-TODO: Fix address to be ipv6 compatible\r
+FIXME: When a new sector is generated, it may change the ground level\r
+ of it's and it's neighbors border that two blocks that are\r
+ above and below each other and that are generated before and\r
+ after the sector heightmap generation (order doesn't matter),\r
+ can have a small gap between each other at the border.\r
+SUGGESTION: Use same technique for sector heightmaps as what we're\r
+ using for UnlimitedHeightmap? (getting all neighbors\r
+ when generating)\r
+\r
+SUGG: Transfer more blocks in a single packet\r
+SUGG: A blockdata combiner class, to which blocks are added and at\r
+ destruction it sends all the stuff in as few packets as possible.\r
+\r
+SUGG: If player is on ground, mainly fetch ground-level blocks\r
+SUGG: Fetch stuff mainly from the viewing direction\r
+\r
+SUGG: Expose Connection's seqnums and ACKs to server and client.\r
+ - This enables saving many packets and making a faster connection\r
+ - This also enables server to check if client has received the\r
+ most recent block sent, for example.\r
+SUGG: Add a sane bandwidth throttling system to Connection\r
+\r
+SUGG: More fine-grained control of client's dumping of blocks from\r
+ memory\r
+ - ...What does this mean in the first place?\r
+\r
+SUGG: A map editing mode (similar to dedicated server mode)\r
+\r
+SUGG: Add a time value to the param of footstepped grass and check it\r
+ against a global timer when a block is accessed, to make old\r
+ steps fade away.\r
+\r
+SUGG: Make a copy of close-range environment on client for showing\r
+ on screen, with minimal mutexes to slow down the main loop\r
+\r
+SUGG: Make a PACKET_COMBINED which contains many subpackets. Utilize\r
+ it by sending more stuff in a single packet.\r
+ - Add a packet queue to RemoteClient, from which packets will be\r
+ combined with object data packets\r
+ - This is not exactly trivial: the object data packets are\r
+ sometimes very big by themselves\r
+\r
+SUGG: Split MapBlockObject serialization to to-client and to-disk\r
+ - This will allow saving ages of rats on disk but not sending\r
+ them to clients\r
+\r
+SUGG: Implement lighting using VoxelManipulator\r
+ - Would it be significantly faster?\r
+\r
+FIXME: Rats somehow go underground sometimes (you can see it in water)\r
+ - Does their position get saved to a border value or something?\r
+ - Does this happen anymore?\r
+\r
+SUGG: MovingObject::move and Player::move are basically the same.\r
+ combine them.\r
+\r
+SUGG: Implement a "Fast check queue" (a queue with a map for checking\r
+ if something is already in it)\r
+ - Use it in active block queue in water flowing\r
+\r
+SUGG: Signs could be done in the same way as torches. For this, blocks\r
+ need an additional metadata field for the texts\r
+\r
+SUGG: Precalculate lighting translation table at runtime (at startup)\r
+\r
+SUGG: A version number to blocks, which increments when the block is\r
+ modified (node add/remove, water update, lighting update)\r
+ - This can then be used to make sure the most recent version of\r
+ a block has been sent to client\r
\r
-TODO: ESC Pause mode in which the cursor is not kept at the center of window.\r
TODO: Stop player if focus of window is taken away (go to pause mode)\r
-TODO: Optimize and fix makeFastFace or whatever it's called\r
- - Face calculation is the source of CPU usage on the client\r
-SUGGESTION: The client will calculate and send lighting changes and\r
- the server will randomly check some of them and kick the client out\r
- if it fails to calculate them right.\r
- - Actually, it could just start ignoring them and calculate them\r
- itself.\r
-SUGGESTION: Combine MapBlock's face caches to so big pieces that VBO\r
- gets used\r
- - That is >500 vertices\r
+\r
+TODO: Combine MapBlock's face caches to so big pieces that VBO\r
+ gets used\r
+ - That is >500 vertices\r
\r
TODO: Better dungeons\r
-TODO: There should be very slight natural caves also, starting from\r
- only a straightened-up cliff\r
+TODO: Cliffs, arcs\r
\r
-TODO: Changing of block with mouse wheel or something\r
TODO: Menus\r
\r
TODO: Mobs\r
avg_rtt/2 before the moment the packet is received.\r
TODO: - Scripting\r
\r
-SUGGESTION: Modify client to calculate single changes asynchronously\r
-\r
TODO: Moving players more smoothly. Calculate moving animation\r
in a way that doesn't make the player jump to the right place\r
immediately when the server sends a new position\r
TODO: There are some lighting-related todos and fixmes in\r
ServerMap::emergeBlock\r
\r
-FIXME: When a new sector is generated, it may change the ground level\r
- of it's and it's neighbors border that two blocks that are\r
- above and below each other and that are generated before and\r
- after the sector heightmap generation (order doesn't matter),\r
- can have a small gap between each other at the border.\r
-SUGGESTION: Use same technique for sector heightmaps as what we're\r
- using for UnlimitedHeightmap? (getting all neighbors\r
- when generating)\r
-\r
TODO: Proper handling of spawning place (try to find something that\r
is not in the middle of an ocean (some land to stand on at\r
least) and save it in map config.\r
-SUGG: Set server to automatically find a good spawning place in some\r
- place where there is water and land.\r
- - Map to have a getWalkableNear(p)\r
- - Is this a good idea? It's part of the game to find a good place.\r
-\r
-TODO: Transfer more blocks in a single packet\r
-SUGG: A blockdata combiner class, to which blocks are added and at\r
- destruction it sends all the stuff in as few packets as possible.\r
-\r
-SUGG: If player is on ground, mainly fetch ground-level blocks\r
-SUGG: Fetch stuff mainly from the viewing direction\r
-\r
-SUGG: Expose Connection's seqnums and ACKs to server and client.\r
- - This enables saving many packets and making a faster connection\r
- - This also enables server to check if client has received the\r
- most recent block sent, for example.\r
-TODO: Add a sane bandwidth throttling system to Connection\r
-\r
-SUGG: More fine-grained control of client's dumping of blocks from\r
- memory\r
- - ...What does this mean in the first place?\r
\r
TODO: Make the amount of blocks sending to client and the total\r
amount of blocks dynamically limited. Transferring blocks is the\r
\r
TODO: Server to load starting inventory from disk\r
\r
-TODO: PLayers to only be hidden when the client quits.\r
+TODO: Players to only be hidden when the client quits.\r
TODO: - Players to be saved on disk, with inventory\r
TODO: Players to be saved as text in map/players/<name>\r
\r
-SUGG: A map editing mode (similar to dedicated server mode)\r
-\r
TODO: Make fetching sector's blocks more efficient when rendering\r
sectors that have very large amounts of blocks (on client)\r
\r
- For all blocks in the buffer, objects are stepped(). This\r
means they are active.\r
- TODO: A global active buffer is needed for the server\r
+ - TODO: A timestamp to blocks\r
- TODO: All blocks going in and out of the buffer are recorded.\r
- - TODO: For outgoing blocks, a timestamp is written.\r
- - TODO: For incoming blocks, the time difference is calculated and\r
+ - TODO: For outgoing blocks, timestamp is written.\r
+ - TODO: For incoming blocks, time difference is calculated and\r
objects are stepped according to it.\r
-TODO: A timestamp to blocks\r
-\r
-SUGG: Add a time value to the param of footstepped grass and check it\r
- against a global timer when a block is accessed, to make old\r
- steps fade away.\r
\r
TODO: Add config parameters for server's sending and generating distance\r
\r
TODO: Untie client network operations from framerate\r
- Needs some input queues or something\r
\r
-SUGG: Make a copy of close-range environment on client for showing\r
- on screen, with minimal mutexes to slow down the main loop\r
-\r
-SUGG: Make a PACKET_COMBINED which contains many subpackets. Utilize\r
- it by sending more stuff in a single packet.\r
- - Add a packet queue to RemoteClient, from which packets will be\r
- combined with object data packets\r
- - This is not exactly trivial: the object data packets are\r
- sometimes very big by themselves\r
-\r
-SUGG: Split MapBlockObject serialization to to-client and to-disk\r
- - This will allow saving ages of rats on disk but not sending\r
- them to clients\r
-\r
TODO: Get rid of GotSplitPacketException\r
\r
-SUGG: Implement lighting using VoxelManipulator\r
- - Would it be significantly faster?\r
-\r
TODO: Check what goes wrong with caching map to disk (Kray)\r
\r
TODO: Remove LazyMeshUpdater. It is not used as supposed.\r
\r
-FIXME: Rats somehow go underground sometimes (you can see it in water)\r
- - Does their position get saved to a border value or something?\r
- - Does this happen anymore?\r
-\r
-SUGG: MovingObject::move and Player::move are basically the same.\r
- combine them.\r
-\r
-SUGG: Implement a "Fast check queue" (a queue with a map for checking\r
- if something is already in it)\r
- - Use it in active block queue in water flowing\r
-\r
-SUGG: Signs could be done in the same way as torches. For this, blocks\r
- need an additional metadata field for the texts\r
+TODO: Node cracking animation when digging\r
+ - TODO: A way to generate new textures by combining textures\r
+ - TODO: Mesh update to fetch cracked faces from the former\r
\r
Doing now:\r
======================================================================\r
\r
+TODO: Add a second lighting value to the MS nibble of param of\r
+ air to tell how bright the air node is when there is no sunlight.\r
+ When day changes to night, these two values can be interpolated.\r
+ - The biggest job is to add support to the lighting routines\r
\r
======================================================================\r
\r
\r
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)\r
{\r
+ left_active = event.MouseInput.isLeftPressed();\r
+ middle_active = event.MouseInput.isMiddlePressed();\r
+ right_active = event.MouseInput.isRightPressed();\r
+\r
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)\r
{\r
leftclicked = true;\r
{\r
rightclicked = true;\r
}\r
+ if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)\r
+ {\r
+ leftreleased = true;\r
+ }\r
+ if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)\r
+ {\r
+ rightreleased = true;\r
+ }\r
if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)\r
{\r
/*dstream<<"event.MouseInput.Wheel="\r
keyIsDown[i] = false;\r
leftclicked = false;\r
rightclicked = false;\r
+ leftreleased = false;\r
+ rightreleased = false;\r
+\r
+ left_active = false;\r
+ middle_active = false;\r
+ right_active = false;\r
}\r
\r
bool leftclicked;\r
bool rightclicked;\r
+ bool leftreleased;\r
+ bool rightreleased;\r
+\r
+ bool left_active;\r
+ bool middle_active;\r
+ bool right_active;\r
+\r
private:\r
// We use this array to store the current state of each key\r
bool keyIsDown[KEY_KEY_CODES_COUNT];\r
virtual ~InputHandler()\r
{\r
}\r
+\r
virtual bool isKeyDown(EKEY_CODE keyCode) = 0;\r
+\r
virtual v2s32 getMousePos() = 0;\r
virtual void setMousePos(s32 x, s32 y) = 0;\r
+\r
+ virtual bool getLeftState() = 0;\r
+ virtual bool getRightState() = 0;\r
+\r
virtual bool getLeftClicked() = 0;\r
virtual bool getRightClicked() = 0;\r
virtual void resetLeftClicked() = 0;\r
virtual void resetRightClicked() = 0;\r
+\r
+ virtual bool getLeftReleased() = 0;\r
+ virtual bool getRightReleased() = 0;\r
+ virtual void resetLeftReleased() = 0;\r
+ virtual void resetRightReleased() = 0;\r
\r
virtual void step(float dtime) {};\r
\r
m_device->getCursorControl()->setPosition(x, y);\r
}\r
\r
+ virtual bool getLeftState()\r
+ {\r
+ return m_receiver->left_active;\r
+ }\r
+ virtual bool getRightState()\r
+ {\r
+ return m_receiver->right_active;\r
+ }\r
+ \r
virtual bool getLeftClicked()\r
{\r
if(g_game_focused == false)\r
m_receiver->rightclicked = false;\r
}\r
\r
+ virtual bool getLeftReleased()\r
+ {\r
+ if(g_game_focused == false)\r
+ return false;\r
+ return m_receiver->leftreleased;\r
+ }\r
+ virtual bool getRightReleased()\r
+ {\r
+ if(g_game_focused == false)\r
+ return false;\r
+ return m_receiver->rightreleased;\r
+ }\r
+ virtual void resetLeftReleased()\r
+ {\r
+ m_receiver->leftreleased = false;\r
+ }\r
+ virtual void resetRightReleased()\r
+ {\r
+ m_receiver->rightreleased = false;\r
+ }\r
+\r
void clear()\r
{\r
resetRightClicked();\r
mousepos = v2s32(x,y);\r
}\r
\r
+ virtual bool getLeftState()\r
+ {\r
+ return false;\r
+ }\r
+ virtual bool getRightState()\r
+ {\r
+ return false;\r
+ }\r
+\r
virtual bool getLeftClicked()\r
{\r
return leftclicked;\r
rightclicked = false;\r
}\r
\r
+ virtual bool getLeftReleased()\r
+ {\r
+ return false;\r
+ }\r
+ virtual bool getRightReleased()\r
+ {\r
+ return false;\r
+ }\r
+ virtual void resetLeftReleased()\r
+ {\r
+ }\r
+ virtual void resetRightReleased()\r
+ {\r
+ }\r
+\r
virtual void step(float dtime)\r
{\r
{\r
//gui::IGUIWindow* input_window = NULL;\r
gui::IGUIStaticText* input_guitext = NULL;\r
\r
+ /*\r
+ Digging animation\r
+ */\r
+ //f32 \r
+\r
/*\r
Main loop\r
*/\r
}\r
else // selected_object == NULL\r
{\r
+\r
+ /*\r
+ Find out which node we are pointing at\r
+ */\r
\r
bool nodefound = false;\r
v3s16 nodepos;\r
} // regular block\r
} // for coords\r
\r
+ /*static v3s16 oldnodepos;\r
+ static bool oldnodefound = false;*/\r
+\r
if(nodefound)\r
{\r
//std::cout<<DTIME<<"nodefound == true"<<std::endl;\r
if(nodepos != nodepos_old){\r
std::cout<<DTIME<<"Pointing at ("<<nodepos.X<<","\r
<<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;\r
- nodepos_old = nodepos;\r
-\r
- /*wchar_t positiontext[20];\r
- swprintf(positiontext, 20, L"(%i,%i,%i)",\r
- nodepos.X, nodepos.Y, nodepos.Z);\r
- positiontextgui->setText(positiontext);*/\r
}\r
\r
hilightboxes.push_back(nodefacebox);\r
\r
- if(g_input->getLeftClicked())\r
+ //if(g_input->getLeftClicked())\r
+ if(g_input->getLeftClicked() ||\r
+ (g_input->getLeftState() && nodepos != nodepos_old))\r
{\r
- //std::cout<<DTIME<<"Removing node"<<std::endl;\r
- //client.removeNode(nodepos);\r
std::cout<<DTIME<<"Ground left-clicked"<<std::endl;\r
client.pressGround(0, nodepos, neighbourpos, g_selected_item);\r
}\r
if(g_input->getRightClicked())\r
+ /*if(g_input->getRightClicked() ||\r
+ (g_input->getRightState() && nodepos != nodepos_old))*/\r
{\r
- //std::cout<<DTIME<<"Placing node"<<std::endl;\r
- //client.addNodeFromInventory(neighbourpos, g_selected_item);\r
std::cout<<DTIME<<"Ground right-clicked"<<std::endl;\r
client.pressGround(1, nodepos, neighbourpos, g_selected_item);\r
}\r
+ \r
+ nodepos_old = nodepos;\r
}\r
else{\r
//std::cout<<DTIME<<"nodefound == false"<<std::endl;\r
//positiontextgui->setText(L"");\r
}\r
\r
+ /*oldnodefound = nodefound;\r
+ oldnodepos = nodepos;*/\r
+\r
} // selected_object == NULL\r
\r
g_input->resetLeftClicked();\r
g_input->resetRightClicked();\r
\r
+ if(g_input->getLeftReleased())\r
+ {\r
+ std::cout<<DTIME<<"Left released"<<std::endl;\r
+ client.stopDigging();\r
+ }\r
+ if(g_input->getRightReleased())\r
+ {\r
+ //std::cout<<DTIME<<"Right released"<<std::endl;\r
+ // Nothing here\r
+ }\r
+ \r
+ g_input->resetLeftReleased();\r
+ g_input->resetRightReleased();\r
+ \r
/*\r
Calculate stuff for drawing\r
*/\r
*/
#include "map.h"
-//#include "player.h"
#include "main.h"
#include "jmutexautolock.h"
#include "client.h"
}
}
-/*bool Map::sectorExists(v2s16 p)
-{
- JMutexAutoLock lock(m_sector_mutex);
- core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p);
- return (n != NULL);
-}*/
-
MapSector * Map::getSectorNoGenerate(v2s16 p)
{
JMutexAutoLock lock(m_sector_mutex);
return block;
}
-/*MapBlock * Map::getBlock(v3s16 p3d, bool generate)
-{
- dstream<<"Map::getBlock() with generate=true called"
- <<std::endl;
- v2s16 p2d(p3d.X, p3d.Z);
- //MapSector * sector = getSector(p2d, generate);
- MapSector * sector = getSectorNoGenerate(p2d);
-
- if(sector == NULL)
- throw InvalidPositionException();
-
- return sector->getBlockNoCreate(p3d.Y);
-}*/
-
f32 Map::getGroundHeight(v2s16 p, bool generate)
{
try{
}
}
-#if 0
-void Map::interpolate(v3s16 block,
- core::map<v3s16, MapBlock*> & modified_blocks)
-{
- const v3s16 dirs[6] = {
- v3s16(0,0,1), // back
- v3s16(0,1,0), // top
- v3s16(1,0,0), // right
- v3s16(0,0,-1), // front
- v3s16(0,-1,0), // bottom
- v3s16(-1,0,0), // left
- };
-
- if(from_nodes.size() == 0)
- return;
-
- u32 blockchangecount = 0;
-
- core::map<v3s16, bool> lighted_nodes;
- core::map<v3s16, bool>::Iterator j;
- j = from_nodes.getIterator();
-
- /*
- Initialize block cache
- */
- v3s16 blockpos_last;
- MapBlock *block = NULL;
- // Cache this a bit, too
- bool block_checked_in_modified = false;
-
- for(; j.atEnd() == false; j++)
- //for(; j != from_nodes.end(); j++)
- {
- v3s16 pos = j.getNode()->getKey();
- //v3s16 pos = *j;
- //dstream<<"pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"<<std::endl;
- v3s16 blockpos = getNodeBlockPos(pos);
-
- // Only fetch a new block if the block position has changed
- try{
- if(block == NULL || blockpos != blockpos_last){
- block = getBlockNoCreate(blockpos);
- blockpos_last = blockpos;
-
- block_checked_in_modified = false;
- blockchangecount++;
- }
- }
- catch(InvalidPositionException &e)
- {
- continue;
- }
-
- if(block->isDummy())
- continue;
-
- // Calculate relative position in block
- v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
-
- // Get node straight from the block
- MapNode n = block->getNode(relpos);
-
- u8 oldlight = n.getLight();
- u8 newlight = diminish_light(oldlight);
-
- // Loop through 6 neighbors
- for(u16 i=0; i<6; i++){
- // Get the position of the neighbor node
- v3s16 n2pos = pos + dirs[i];
-
- // Get the block where the node is located
- v3s16 blockpos = getNodeBlockPos(n2pos);
-
- try
- {
- // Only fetch a new block if the block position has changed
- try{
- if(block == NULL || blockpos != blockpos_last){
- block = getBlockNoCreate(blockpos);
- blockpos_last = blockpos;
-
- block_checked_in_modified = false;
- blockchangecount++;
- }
- }
- catch(InvalidPositionException &e)
- {
- continue;
- }
-
- // Calculate relative position in block
- v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
- // Get node straight from the block
- MapNode n2 = block->getNode(relpos);
-
- bool changed = false;
- /*
- If the neighbor is brighter than the current node,
- add to list (it will light up this node on its turn)
- */
- if(n2.getLight() > undiminish_light(oldlight))
- {
- lighted_nodes.insert(n2pos, true);
- //lighted_nodes.push_back(n2pos);
- changed = true;
- }
- /*
- If the neighbor is dimmer than how much light this node
- would spread on it, add to list
- */
- if(n2.getLight() < newlight)
- {
- if(n2.light_propagates())
- {
- n2.setLight(newlight);
- block->setNode(relpos, n2);
- lighted_nodes.insert(n2pos, true);
- //lighted_nodes.push_back(n2pos);
- changed = true;
- }
- }
-
- // Add to modified_blocks
- if(changed == true && block_checked_in_modified == false)
- {
- // If the block is not found in modified_blocks, add.
- if(modified_blocks.find(blockpos) == NULL)
- {
- modified_blocks.insert(blockpos, block);
- }
- block_checked_in_modified = true;
- }
- }
- catch(InvalidPositionException &e)
- {
- continue;
- }
- }
- }
-
- /*dstream<<"spreadLight(): Changed block "
- <<blockchangecount<<" times"
- <<" for "<<from_nodes.size()<<" nodes"
- <<std::endl;*/
-
- if(lighted_nodes.size() > 0)
- spreadLight(lighted_nodes, modified_blocks);
-}
-#endif
-
/*
Goes recursively through the neighbours of the node.
bool debug=false;
u32 count_was = modified_blocks.size();
- /*core::list<MapBlock *>::Iterator i = a_blocks.begin();
- for(; i != a_blocks.end(); i++)
- {
- MapBlock *block = *i;*/
-
core::map<v3s16, bool> light_sources;
core::map<v3s16, u8> unlight_from;
m_client(client),
mesh(NULL)
{
+ mesh_mutex.Init();
+
/*m_box = core::aabbox3d<f32>(0,0,0,
map->getW()*BS, map->getH()*BS, map->getD()*BS);*/
/*m_box = core::aabbox3d<f32>(0,0,0,
map->getSizeNodes().Z * BS);*/
m_box = core::aabbox3d<f32>(-BS*1000000,-BS*1000000,-BS*1000000,
BS*1000000,BS*1000000,BS*1000000);
-
- mesh_mutex.Init();
+
+ //setPosition(v3f(BS,BS,BS));
}
ClientMap::~ClientMap()
}
}
-FastFace * MapBlock::makeFastFace(u16 tile, u8 light, v3f p,
+FastFace * MapBlock::makeFastFace(TileSpec tile, u8 light, v3f p,
v3s16 dir, v3f scale, v3f posRelative_f)
{
FastFace *f = new FastFace;
u8 alpha = 255;
- if(tile == TILE_WATER)
+ if(tile.id == TILE_WATER)
{
alpha = 128;
}
/*
Gets node tile from any place relative to block.
- Returns CONTENT_IGNORE if doesn't exist or should not be drawn.
+ Returns TILE_NODE if doesn't exist or should not be drawn.
*/
-u16 MapBlock::getNodeTile(v3s16 p, v3s16 face_dir)
+TileSpec MapBlock::getNodeTile(v3s16 p, v3s16 face_dir)
{
+ TileSpec spec;
+
+ spec.feature = TILEFEAT_NONE;
try{
MapNode n = getNodeParent(p);
- //return content_tile(n.d);
- return n.getTile(face_dir);
+ spec.id = n.getTile(face_dir);
}
catch(InvalidPositionException &e)
{
- //return CONTENT_IGNORE;
- return TILE_NONE;
+ spec.id = TILE_NONE;
}
+
+ /*
+ Check temporary modifications on this node
+ */
+ core::map<v3s16, NodeMod>::Node *n;
+ n = m_temp_mods.find(p);
+
+ // If modified
+ if(n != NULL)
+ {
+ struct NodeMod mod = n->getValue();
+ if(mod.type == NODEMOD_CHANGECONTENT)
+ {
+ spec.id = content_tile(mod.param, face_dir);
+ }
+ if(mod.type == NODEMOD_CRACK)
+ {
+ }
+ }
+
+ return spec;
}
u8 MapBlock::getNodeContent(v3s16 p)
{
+ /*
+ Check temporary modifications on this node
+ */
+ core::map<v3s16, NodeMod>::Node *n;
+ n = m_temp_mods.find(p);
+
+ // If modified
+ if(n != NULL)
+ {
+ struct NodeMod mod = n->getValue();
+ if(mod.type == NODEMOD_CHANGECONTENT)
+ {
+ // Overrides content
+ return mod.param;
+ }
+ if(mod.type == NODEMOD_CRACK)
+ {
+ /*
+ Content doesn't change.
+
+ face_contents works just like it should, because
+ there should not be faces between differently cracked
+ nodes.
+
+ If a semi-transparent node is cracked in front an
+ another one, it really doesn't matter whether there
+ is a cracked face drawn in between or not.
+ */
+ }
+ }
+
try{
MapNode n = getNodeParent(p);
u16 continuous_tiles_count = 0;
- u8 tile0 = getNodeTile(p, face_dir);
- u8 tile1 = getNodeTile(p + face_dir, -face_dir);
+ TileSpec tile0 = getNodeTile(p, face_dir);
+ TileSpec tile1 = getNodeTile(p + face_dir, -face_dir);
for(u16 j=0; j<length; j++)
{
bool next_is_different = true;
v3s16 p_next;
- u8 tile0_next = 0;
- u8 tile1_next = 0;
+ TileSpec tile0_next;
+ TileSpec tile1_next;
u8 light_next = 0;
if(j != length - 1){
FastFace *f = *i;
const u16 indices[] = {0,1,2,2,3,0};
-
- /*collector.append(g_materials[f->material], f->vertices, 4,
- indices, 6);*/
- /*collector.append(g_materials[f->tile], f->vertices, 4,
- indices, 6);*/
- collector.append(g_tile_materials[f->tile], f->vertices, 4,
- indices, 6);
+
+ if(f->tile.feature == TILEFEAT_NONE)
+ {
+ collector.append(g_tile_materials[f->tile.id], f->vertices, 4,
+ indices, 6);
+ }
+ else
+ {
+ // Not implemented
+ assert(0);
+ }
}
collector.fillMesh(mesh_new);
// Use VBO for mesh (this just would set this for ever buffer)
- //mesh_new->setHardwareMappingHint(scene::EHM_STATIC);
+ mesh_new->setHardwareMappingHint(scene::EHM_STATIC);
/*std::cout<<"MapBlock has "<<fastfaces_new->getSize()<<" faces "
<<"and uses "<<mesh_new->getMeshBufferCount()
struct FastFace
{
- u16 tile;
+ TileSpec tile;
video::S3DVertex vertices[4]; // Precalculated vertices
};
+enum NodeModType
+{
+ NODEMOD_NONE,
+ NODEMOD_CHANGECONTENT, //param is content id
+ NODEMOD_CRACK // param is crack progression
+};
+
+struct NodeMod
+{
+ NodeMod()
+ {
+ type = NODEMOD_NONE;
+ }
+ enum NodeModType type;
+ u16 param;
+};
+
enum
{
NODECONTAINER_ID_MAPBLOCK,
setNode(x0+x, y0+y, z0+z, node);
}
- static FastFace * makeFastFace(u16 tile, u8 light, v3f p,
+ static FastFace * makeFastFace(TileSpec tile, u8 light, v3f p,
v3s16 dir, v3f scale, v3f posRelative_f);
u8 getFaceLight(v3s16 p, v3s16 face_dir);
- u16 getNodeTile(v3s16 p, v3s16 face_dir);
+ TileSpec getNodeTile(v3s16 p, v3s16 face_dir);
u8 getNodeContent(v3s16 p);
/*
{
return m_objects.getCount();
}
+
+ /*
+ Methods for setting temporary modifications to nodes for
+ drawing
+ */
+ void setTempMod(v3s16 p, NodeMod mod)
+ {
+ m_temp_mods[p] = mod;
+ }
+ void clearTempMod(v3s16 p)
+ {
+ if(m_temp_mods.find(p))
+ m_temp_mods.remove(p);
+ }
+ void clearTempMods()
+ {
+ m_temp_mods.clear();
+ }
/*
Serialization
MapBlockObjectList m_objects;
+ // Temporary modifications to nodes
+ // These are only used when drawing
+ core::map<v3s16, NodeMod> m_temp_mods;
};
inline bool blockpos_over_limit(v3s16 p)
{TILE_MESE,TILE_MESE,TILE_MESE,TILE_MESE,TILE_MESE,TILE_MESE},
{TILE_MUD,TILE_MUD,TILE_MUD,TILE_MUD,TILE_MUD,TILE_MUD},
{TILE_WATER,TILE_WATER,TILE_WATER,TILE_WATER,TILE_WATER,TILE_WATER},
+ {TILE_CLOUD,TILE_CLOUD,TILE_CLOUD,TILE_CLOUD,TILE_CLOUD,TILE_CLOUD},
};
const char * g_content_inventory_textures[USEFUL_CONTENT_COUNT] =
"mese",
"mud",
"water",
+ "cloud",
};
CONTENT_MESE,
CONTENT_MUD,
CONTENT_OCEAN,
+ CONTENT_CLOUD,
// This is set to the number of the actual values in this enum
USEFUL_CONTENT_COUNT
// If not transparent, can't set light
if(light_propagates() == false)
return;
- param = a_light;
+ param &= 0xf0;
+ param |= a_light;
}
u16 getTile(v3s16 dir)
}
}
- // Run time- and client- related stuff
- // NOTE: If you intend to add something here, check that it
- // doesn't fit in RemoteClient::GetNextBlocks for example.
- /*{
- // Clients are behind connection lock
- JMutexAutoLock lock(m_con_mutex);
+ /*
+ Update digging
+
+ NOTE: Some of this could be moved to RemoteClient
+ */
+
+ {
+ JMutexAutoLock envlock(m_env_mutex);
+ JMutexAutoLock conlock(m_con_mutex);
for(core::map<u16, RemoteClient*>::Iterator
i = m_clients.getIterator();
i.atEnd() == false; i++)
{
RemoteClient *client = i.getNode()->getValue();
- //con::Peer *peer = m_con.GetPeer(client->peer_id);
- //client->RunSendingTimeouts(dtime, peer->resend_timeout);
+ Player *player = m_env.getPlayer(client->peer_id);
+
+ JMutexAutoLock digmutex(client->m_dig_mutex);
+
+ if(client->m_dig_tool_item == -1)
+ continue;
+
+ client->m_dig_time_remaining -= dtime;
+
+ if(client->m_dig_time_remaining > 0)
+ continue;
+
+ v3s16 p_under = client->m_dig_position;
+
+ // Mandatory parameter; actually used for nothing
+ core::map<v3s16, MapBlock*> modified_blocks;
+
+ u8 material;
+
+ try
+ {
+ // Get material at position
+ material = m_env.getMap().getNode(p_under).d;
+ // If it's not diggable, do nothing
+ if(content_diggable(material) == false)
+ {
+ derr_server<<"Server: Not finishing digging: Node not diggable"
+ <<std::endl;
+ client->m_dig_tool_item = -1;
+ break;
+ }
+ }
+ catch(InvalidPositionException &e)
+ {
+ derr_server<<"Server: Not finishing digging: Node not found"
+ <<std::endl;
+ client->m_dig_tool_item = -1;
+ break;
+ }
+
+ // Create packet
+ u32 replysize = 8;
+ SharedBuffer<u8> reply(replysize);
+ writeU16(&reply[0], TOCLIENT_REMOVENODE);
+ writeS16(&reply[2], p_under.X);
+ writeS16(&reply[4], p_under.Y);
+ writeS16(&reply[6], p_under.Z);
+ // Send as reliable
+ m_con.SendToAll(0, reply, true);
+
+ if(g_settings.getBool("creative_mode") == false)
+ {
+ // Add to inventory and send inventory
+ InventoryItem *item = new MaterialItem(material, 1);
+ player->inventory.addItem(item);
+ SendInventory(player->peer_id);
+ }
+
+ /*
+ Remove the node
+ (this takes some time so it is done after the quick stuff)
+ */
+ m_env.getMap().removeNodeAndUpdate(p_under, modified_blocks);
+
+ /*
+ Update water
+ */
+
+ // Update water pressure around modification
+ // This also adds it to m_flow_active_nodes if appropriate
+
+ MapVoxelManipulator v(&m_env.getMap());
+ v.m_disable_water_climb =
+ g_settings.getBool("disable_water_climb");
+
+ VoxelArea area(p_under-v3s16(1,1,1), p_under+v3s16(1,1,1));
+
+ try
+ {
+ v.updateAreaWaterPressure(area, m_flow_active_nodes);
+ }
+ catch(ProcessingLimitException &e)
+ {
+ dstream<<"Processing limit reached (1)"<<std::endl;
+ }
+
+ v.blitBack(modified_blocks);
}
- }*/
+ }
// Send object positions
{
block->removeObject(id);
}
}
- else if(command == TOSERVER_PRESS_GROUND)
+ else if(command == TOSERVER_GROUND_ACTION)
{
if(datasize < 17)
return;
/*
length: 17
[0] u16 command
- [2] u8 button (0=left, 1=right)
+ [2] u8 action
[3] v3s16 nodepos_undersurface
[9] v3s16 nodepos_abovesurface
[15] u16 item
+ actions:
+ 0: start digging
+ 1: place block
+ 2: stop digging (all parameters ignored)
*/
- u8 button = readU8(&data[2]);
+ u8 action = readU8(&data[2]);
v3s16 p_under;
p_under.X = readS16(&data[3]);
p_under.Y = readS16(&data[5]);
//TODO: Check that target is reasonably close
/*
- Left button digs ground
+ 0: start digging
*/
- if(button == 0)
+ if(action == 0)
{
- core::map<v3s16, MapBlock*> modified_blocks;
-
u8 material;
try
}
catch(InvalidPositionException &e)
{
- derr_server<<"Server: Ignoring REMOVENODE: Node not found"
+ derr_server<<"Server: Not starting digging: Node not found"
<<std::endl;
return;
}
- // Reset build time counter
- getClient(peer->id)->m_time_from_building.set(0.0);
-
- // Create packet
- u32 replysize = 8;
- SharedBuffer<u8> reply(replysize);
- writeU16(&reply[0], TOCLIENT_REMOVENODE);
- writeS16(&reply[2], p_under.X);
- writeS16(&reply[4], p_under.Y);
- writeS16(&reply[6], p_under.Z);
- // Send as reliable
- m_con.SendToAll(0, reply, true);
-
- if(g_settings.getBool("creative_mode") == false)
- {
- // Add to inventory and send inventory
- InventoryItem *item = new MaterialItem(material, 1);
- player->inventory.addItem(item);
- SendInventory(player->peer_id);
- }
-
- /*
- Remove the node
- (this takes some time so it is done after the quick stuff)
- */
- m_env.getMap().removeNodeAndUpdate(p_under, modified_blocks);
-
/*
- Update water
+ Set stuff in RemoteClient
*/
+ RemoteClient *client = getClient(peer->id);
+ JMutexAutoLock(client->m_dig_mutex);
+ client->m_dig_tool_item = 0;
+ client->m_dig_position = p_under;
+ client->m_dig_time_remaining = 1.0;
- // Update water pressure around modification
- // This also adds it to m_flow_active_nodes if appropriate
-
- MapVoxelManipulator v(&m_env.getMap());
- v.m_disable_water_climb =
- g_settings.getBool("disable_water_climb");
+ // Reset build time counter
+ getClient(peer->id)->m_time_from_building.set(0.0);
- VoxelArea area(p_under-v3s16(1,1,1), p_under+v3s16(1,1,1));
+ } // action == 0
- try
- {
- v.updateAreaWaterPressure(area, m_flow_active_nodes);
- }
- catch(ProcessingLimitException &e)
- {
- dstream<<"Processing limit reached (1)"<<std::endl;
- }
-
- v.blitBack(modified_blocks);
-
- // Add the node to m_flow_active_nodes.
- //m_flow_active_nodes[p_under] = 1;
+ /*
+ 2: stop digging
+ */
+ else if(action == 2)
+ {
+ RemoteClient *client = getClient(peer->id);
+ JMutexAutoLock digmutex(client->m_dig_mutex);
+ client->m_dig_tool_item = -1;
+ }
- } // button == 0
/*
- Right button places blocks and stuff
+ 1: place block
*/
- else if(button == 1)
+ else if(action == 1)
{
// Get item
}
}
- } // button == 1
+ } // action == 1
/*
- Catch invalid buttons
+ Catch invalid actions
*/
else
{
- derr_server<<"WARNING: Server: Invalid button "
- <<button<<std::endl;
+ derr_server<<"WARNING: Server: Invalid action "
+ <<action<<std::endl;
}
}
+#if 0
else if(command == TOSERVER_RELEASE)
{
if(datasize < 3)
[0] u16 command
[2] u8 button
*/
- //TODO
+ dstream<<"TOSERVER_RELEASE ignored"<<std::endl;
}
+#endif
else if(command == TOSERVER_SIGNTEXT)
{
/*
/*
Set player position
*/
-
+
+ // We're going to throw the player to this position
+ //v2s16 nodepos(29990,29990);
+ //v2s16 nodepos(9990,9990);
+ v2s16 nodepos(0,0);
+ v2s16 sectorpos = getNodeSectorPos(nodepos);
// Get zero sector (it could have been unloaded to disk)
- m_env.getMap().emergeSector(v2s16(0,0));
+ m_env.getMap().emergeSector(sectorpos);
// Get ground height at origin
- f32 groundheight = m_env.getMap().getGroundHeight(v2s16(0,0), true);
- // The zero sector should have been generated
+ f32 groundheight = m_env.getMap().getGroundHeight(nodepos, true);
+ // The sector should have been generated -> groundheight exists
assert(groundheight > GROUNDHEIGHT_VALID_MINVALUE);
// Don't go underwater
if(groundheight < WATER_LEVEL)
groundheight = WATER_LEVEL;
player->setPosition(intToFloat(v3s16(
- 0,
+ nodepos.X,
groundheight + 1,
- 0
+ nodepos.Y
)));
/*
RemoteClient():
m_time_from_building(9999)
- //m_num_blocks_in_emerge_queue(0)
{
peer_id = 0;
serialization_version = SER_FMT_VER_INVALID;
m_blocks_sent_mutex.Init();
m_blocks_sending_mutex.Init();
+
+ m_dig_mutex.Init();
+ m_dig_time_remaining = 0;
+ m_dig_tool_item = -1;
}
~RemoteClient()
{
JMutexAutoLock l2(m_blocks_sent_mutex);
JMutexAutoLock l3(m_blocks_sending_mutex);
o<<"RemoteClient "<<peer_id<<": "
- /*<<"m_num_blocks_in_emerge_queue="
- <<m_num_blocks_in_emerge_queue.get()*/
<<", m_blocks_sent.size()="<<m_blocks_sent.size()
<<", m_blocks_sending.size()="<<m_blocks_sending.size()
<<", m_nearest_unsent_d="<<m_nearest_unsent_d
// Time from last placing or removing blocks
MutexedVariable<float> m_time_from_building;
+ JMutex m_dig_mutex;
+ float m_dig_time_remaining;
+ // -1 = not digging
+ s16 m_dig_tool_item;
+ v3s16 m_dig_position;
+
private:
/*
All members that are accessed by many threads should
"mud",
"tree_top",
"mud_with_grass",
+ "cloud",
};
video::SMaterial g_tile_materials[TILES_COUNT];
TILE_MUD,
TILE_TREE_TOP,
TILE_MUD_WITH_GRASS,
+ TILE_CLOUD,
// Count of tile ids
TILES_COUNT
};
+enum TileSpecialFeature
+{
+ TILEFEAT_NONE,
+ TILEFEAT_CRACK,
+};
+
+struct TileCrackParam
+{
+ bool operator==(TileCrackParam &other)
+ {
+ return progression == other.progression;
+ }
+
+ u16 progression;
+};
+
+struct TileSpec
+{
+ TileSpec()
+ {
+ id = TILE_NONE;
+ feature = TILEFEAT_NONE;
+ }
+
+ bool operator==(TileSpec &other)
+ {
+ if(id != other.id)
+ return false;
+ if(feature != other.feature)
+ return false;
+ if(feature == TILEFEAT_NONE)
+ return true;
+ if(feature == TILEFEAT_CRACK)
+ {
+ return param.crack == other.param.crack;
+ }
+ // Invalid feature
+ assert(0);
+ return false;
+ }
+
+ u16 id; // Id in g_tile_materials, TILE_NONE=none
+ enum TileSpecialFeature feature;
+ union
+ {
+ TileCrackParam crack;
+ } param;
+};
+
// A mapping from tiles to names of cached textures
extern const char * g_tile_texture_names[TILES_COUNT];