before adding day/night lighting
authorPerttu Ahola <celeron55@gmail.com>
Sat, 18 Dec 2010 11:10:37 +0000 (13:10 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 18 Dec 2010 11:10:37 +0000 (13:10 +0200)
--HG--
rename : data/light.png => data/cloud.png

19 files changed:
data/cloud.png [new file with mode: 0644]
data/light.png [deleted file]
doc/README.txt
makepackage_binary.sh
src/client.cpp
src/client.h
src/clientserver.h
src/light.cpp
src/light.h
src/main.cpp
src/map.cpp
src/mapblock.cpp
src/mapblock.h
src/mapnode.cpp
src/mapnode.h
src/server.cpp
src/server.h
src/tile.cpp
src/tile.h

diff --git a/data/cloud.png b/data/cloud.png
new file mode 100644 (file)
index 0000000..24091a3
Binary files /dev/null and b/data/cloud.png differ
diff --git a/data/light.png b/data/light.png
deleted file mode 100644 (file)
index 24091a3..0000000
Binary files a/data/light.png and /dev/null differ
index 3467564bd1ed88382696119d2966b45144993c56..46e72e0c034881cddec68b55abfe2ace56fb1996 100644 (file)
@@ -38,6 +38,9 @@ Configuration file:
        ../minetest.conf
        ../../minetest.conf
 
+Command-line options:
+- Use --help
+
 Running on Windows:
 - The working directory should be ./bin
 
index ad3ff33d7003b650a20d778c7a7e157e232a307b..b921c9aeef736bf834b512867bf94a13f8fd8f23 100755 (executable)
@@ -29,7 +29,7 @@ cp -r data/water.png $PACKAGEPATH/data/
 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/
index ed3a437597f95f547a6876690a3e53eb089fdab4..f8644572062a9a6a6b3fb8d979763753e3de1d2e 100644 (file)
@@ -1140,6 +1140,35 @@ bool Client::AsyncProcessPacket(LazyMeshUpdater &mesh_updater)
                                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
                
@@ -1412,16 +1441,20 @@ void Client::pressGround(u8 button, v3s16 nodepos_undersurface,
        }
        
        /*
-               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);
@@ -1455,9 +1488,35 @@ void Client::clickObject(u8 button, v3s16 blockpos, s16 id, u16 item)
        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)
index 95bff0ff5ae2b7c86a934005e4728efaf991238a..70996cfef1e7aae9a7dca91edf828d378afc8fa5 100644 (file)
@@ -196,7 +196,7 @@ public:
        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);
        
index 9d3545907b2b53b248019321a0879dc87daa852b..4526083dabe4972a4954e1f0442be5554f6be86e 100644 (file)
@@ -159,22 +159,21 @@ enum ToServerCommand
                [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,
        /*
index a9fe023ef2f0793f59383653541e34334ce27503..03821a672ad9e8ca50adef3a5d5f981c81dee186 100644 (file)
@@ -19,49 +19,45 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #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
 
@@ -100,48 +96,6 @@ u8 light_decode_table[LIGHT_MAX+1] =
 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
 
 
index 8714269015f5e10d8b193b9d91fe45cefaef4b60..1827ab53a1d72b4f6a553068840c188f2dcd658c 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 // 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
 
index b4e2d478c1075a77086c0c225b45339b28de373c..5d1be0184c174670e3edff4c02b15ffa6178a3e6 100644 (file)
@@ -27,30 +27,87 @@ NOTE: VBO cannot be turned on for fast-changing stuff because there
 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
@@ -63,8 +120,6 @@ TODO: - Keep track of the place of the mob in the last few hundreth's
                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
@@ -72,39 +127,9 @@ TODO: Moving players more smoothly. Calculate moving animation
 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
@@ -113,12 +138,10 @@ TODO: Make the amount of blocks sending to client and the total
 \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
@@ -129,15 +152,11 @@ Block object server side:
          - 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, 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
@@ -147,46 +166,23 @@ TODO: Copy the text of the last picked sign to inventory in creative
 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
@@ -486,6 +482,10 @@ public:
 \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
@@ -494,6 +494,14 @@ public:
                        {\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
@@ -530,10 +538,23 @@ public:
                                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
@@ -550,13 +571,24 @@ public:
        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
@@ -597,6 +629,15 @@ public:
                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
@@ -618,6 +659,27 @@ public:
                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
@@ -651,6 +713,15 @@ public:
                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
@@ -668,6 +739,21 @@ public:
                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
@@ -1563,6 +1649,11 @@ int main(int argc, char *argv[])
        //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
@@ -1920,6 +2011,10 @@ int main(int argc, char *argv[])
                }\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
@@ -2066,6 +2161,9 @@ int main(int argc, char *argv[])
                        } // 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
@@ -2076,41 +2174,54 @@ int main(int argc, char *argv[])
                        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
index caebb516182441b02244f7ce54a33fc5728d02e4..7b057840dfdf027a0fb8bc74a66dd8a90237f86c 100644 (file)
@@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "map.h"
-//#include "player.h"
 #include "main.h"
 #include "jmutexautolock.h"
 #include "client.h"
@@ -112,13 +111,6 @@ Map::~Map()
        }
 }
 
-/*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);
@@ -160,20 +152,6 @@ MapBlock * Map::getBlockNoCreate(v3s16 p3d)
        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{
@@ -215,156 +193,6 @@ bool Map::isNodeUnderground(v3s16 p)
        }
 }
 
-#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.
 
@@ -813,11 +641,6 @@ void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
        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;
@@ -2764,6 +2587,8 @@ ClientMap::ClientMap(
        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,
@@ -2772,8 +2597,8 @@ ClientMap::ClientMap(
                        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()
index 86bd9c98c5a5e6ecb3d795380e85f3323cb271f8..1afe00001a32b81c432169fd4d673994be89c384 100644 (file)
@@ -68,7 +68,7 @@ void MapBlock::setNodeParent(v3s16 p, MapNode & n)
        }
 }
 
-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;
@@ -118,7 +118,7 @@ FastFace * MapBlock::makeFastFace(u16 tile, u8 light, v3f p,
 
        u8 alpha = 255;
 
-       if(tile == TILE_WATER)
+       if(tile.id == TILE_WATER)
        {
                alpha = 128;
        }
@@ -184,25 +184,78 @@ u8 MapBlock::getFaceLight(v3s16 p, v3s16 face_dir)
 
 /*
        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);
                
@@ -243,16 +296,16 @@ void MapBlock::updateFastFaceRow(v3s16 startpos,
        
        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){
@@ -493,19 +546,23 @@ void MapBlock::updateMesh()
                        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()
index 608249383b6e699bdce66a62797d01730734f80c..ebc2b52ff5d39f41fef296837aa25dfe2315a9ec 100644 (file)
@@ -46,10 +46,27 @@ enum{
 
 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,
@@ -283,12 +300,12 @@ public:
                                        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);
 
        /*
@@ -380,6 +397,24 @@ public:
        {
                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
@@ -432,6 +467,9 @@ private:
        
        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)
index 973b89ddd6cbec79ae17218f50124fa001c7db2d..883c188427ad3b649bc1b486c5b6494f8ac21835 100644 (file)
@@ -41,6 +41,7 @@ u16 g_content_tiles[USEFUL_CONTENT_COUNT][6] =
        {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] =
@@ -55,5 +56,6 @@ const char * g_content_inventory_textures[USEFUL_CONTENT_COUNT] =
        "mese",
        "mud",
        "water",
+       "cloud",
 };
 
index 680884bcd96ec83e494d463585edba524684945b..7314420115d1f54803b1fc9005369ad87f1c2869 100644 (file)
@@ -75,6 +75,7 @@ enum Content
        CONTENT_MESE,
        CONTENT_MUD,
        CONTENT_OCEAN,
+       CONTENT_CLOUD,
        
        // This is set to the number of the actual values in this enum
        USEFUL_CONTENT_COUNT
@@ -367,7 +368,8 @@ struct MapNode
                // If not transparent, can't set light
                if(light_propagates() == false)
                        return;
-               param = a_light;
+               param &= 0xf0;
+               param |= a_light;
        }
 
        u16 getTile(v3s16 dir)
index 88a8492c1080f882cdf018edd0ee1185bcfe74b7..6b026d9a76dd6f45ac5d83dfcab07e4c16792531 100644 (file)
@@ -1101,22 +1101,110 @@ void Server::AsyncRunStep()
                }
        }
 
-       // 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
        {
@@ -1466,19 +1554,23 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        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]);
@@ -1492,13 +1584,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                //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
@@ -1513,70 +1603,39 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        }
                        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
@@ -1772,16 +1831,17 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                }
                        }
 
-               } // 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)
@@ -1791,8 +1851,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        [0] u16 command
                        [2] u8 button
                */
-               //TODO
+               dstream<<"TOSERVER_RELEASE ignored"<<std::endl;
        }
+#endif
        else if(command == TOSERVER_SIGNTEXT)
        {
                /*
@@ -1978,21 +2039,26 @@ void Server::peerAdded(con::Peer *peer)
                /*
                        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
                )));
 
                /*
index 273a7d5ef7d046d77d84d05fe7c43396823bbae1..851a5ba67ab7e7e2c5a2f0cf4f3817f1a446ba2e 100644 (file)
@@ -276,7 +276,6 @@ public:
 
        RemoteClient():
                m_time_from_building(9999)
-               //m_num_blocks_in_emerge_queue(0)
        {
                peer_id = 0;
                serialization_version = SER_FMT_VER_INVALID;
@@ -285,6 +284,10 @@ public:
 
                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()
        {
@@ -338,8 +341,6 @@ public:
                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
@@ -349,6 +350,12 @@ public:
        // 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
index 32db69672427a4734f078b9d976948487076fb51..37785822c7ad66c0114c35c4c98b2360f95ecfe6 100644 (file)
@@ -32,6 +32,7 @@ const char * g_tile_texture_names[TILES_COUNT] =
        "mud",
        "tree_top",
        "mud_with_grass",
+       "cloud",
 };
 
 video::SMaterial g_tile_materials[TILES_COUNT];
index 286c5fb2e8aec90514e0e6946c1a974a7394232c..f1aa100fcca3d1dfaa4b267cbd2a63fcf910df49 100644 (file)
@@ -38,11 +38,61 @@ enum TileID
        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];