commit before some more radical changes
authorPerttu Ahola <celeron55@gmail.com>
Sun, 3 Apr 2011 13:21:06 +0000 (16:21 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 3 Apr 2011 13:21:06 +0000 (16:21 +0300)
12 files changed:
src/CMakeLists.txt
src/client.cpp
src/client.h
src/main.cpp
src/map.cpp
src/map.h
src/mapblock.cpp
src/mapblock.h
src/mapnode.cpp
src/mapnode.h
src/materials.cpp
src/server.cpp

index 2b49cb32d17dfd89d135c8d82bb61e037ead5b9e..187d84cc7027269e9c30a1e4c5e740eaaaf7f0f3 100644 (file)
@@ -50,6 +50,7 @@ configure_file(
 )
 
 set(common_SRCS
+       nodemetadata.cpp
        serverobject.cpp
        noise.cpp
        mineral.cpp
index c16e00da9881fb13d58fab8b381fa3ab03823c32..4cae9d02e83c729a5bec2d13b3494b6239a99fee 100644 (file)
@@ -36,7 +36,7 @@ void * ClientUpdateThread::Thread()
        
        while(getRun())
        {
-               m_client->asyncStep();
+               //m_client->asyncStep();
 
                //m_client->updateSomeExpiredMeshes();
 
@@ -357,6 +357,7 @@ void Client::step(float dtime)
        }*/
 }
 
+#if 0
 float Client::asyncStep()
 {
        DSTACK(__FUNCTION_NAME);
@@ -374,6 +375,7 @@ float Client::asyncStep()
        return dtime;*/
        return 0.0;
 }
+#endif
 
 // Virtual methods from con::PeerHandler
 void Client::peerAdded(con::Peer *peer)
@@ -1182,8 +1184,6 @@ bool Client::AsyncProcessPacket()
                // Ignore too small packet
                if(datasize < 8)
                        return true;
-               /*if(datasize < 8 + MapBlock::serializedLength(ser_version))
-                       goto getdata;*/
                        
                v3s16 p;
                p.X = readS16(&data[2]);
@@ -1238,35 +1238,6 @@ bool Client::AsyncProcessPacket()
                                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
                
@@ -1605,6 +1576,12 @@ MapNode Client::getNode(v3s16 p)
        return m_env.getMap().getNode(p);
 }
 
+NodeMetadata* Client::getNodeMetadataClone(v3s16 p)
+{
+       JMutexAutoLock envlock(m_env_mutex);
+       return m_env.getMap().getNodeMetadataClone(p);
+}
+
 v3f Client::getPlayerPosition()
 {
        JMutexAutoLock envlock(m_env_mutex);
index d6496d9dfd471982aaff5e260709ee39108700ae..c6002a469b807ec13d4980a2f50d9293c7fd9115 100644 (file)
@@ -138,7 +138,7 @@ public:
 
        // Called from updater thread
        // Returns dtime
-       float asyncStep();
+       //float asyncStep();
 
        void ProcessData(u8 *data, u32 datasize, u16 sender_peer_id);
        // Returns true if something was received
@@ -166,6 +166,8 @@ public:
        
        // Returns InvalidPositionException if not found
        MapNode getNode(v3s16 p);
+       // Wrapper to Map
+       NodeMetadata* getNodeMetadataClone(v3s16 p);
 
        v3f getPlayerPosition();
 
index c9db0bdc45451b2a972d4bac5b4de8b99c48cdda..a901163df9554823ab8d492aff05dc06b06ec66f 100644 (file)
@@ -2701,6 +2701,55 @@ int main(int argc, char *argv[])
                                        }\r
                                }\r
                        }\r
+                       else if(n.d == CONTENT_SIGN_WALL)\r
+                       {\r
+                               v3s16 dir = unpackDir(n.dir);\r
+                               v3f dir_f = v3f(dir.X, dir.Y, dir.Z);\r
+                               dir_f *= BS/2 - BS/6 - BS/20;\r
+                               v3f cpf = npf + dir_f;\r
+                               f32 distance = (cpf - camera_position).getLength();\r
+\r
+                               v3f vertices[4] =\r
+                               {\r
+                                       v3f(BS*0.42,-BS*0.35,-BS*0.4),\r
+                                       v3f(BS*0.49, BS*0.35, BS*0.4),\r
+                               };\r
+\r
+                               for(s32 i=0; i<2; i++)\r
+                               {\r
+                                       if(dir == v3s16(1,0,0))\r
+                                               vertices[i].rotateXZBy(0);\r
+                                       if(dir == v3s16(-1,0,0))\r
+                                               vertices[i].rotateXZBy(180);\r
+                                       if(dir == v3s16(0,0,1))\r
+                                               vertices[i].rotateXZBy(90);\r
+                                       if(dir == v3s16(0,0,-1))\r
+                                               vertices[i].rotateXZBy(-90);\r
+                                       if(dir == v3s16(0,-1,0))\r
+                                               vertices[i].rotateXYBy(-90);\r
+                                       if(dir == v3s16(0,1,0))\r
+                                               vertices[i].rotateXYBy(90);\r
+\r
+                                       vertices[i] += npf;\r
+                               }\r
+\r
+                               core::aabbox3d<f32> box;\r
+\r
+                               box = core::aabbox3d<f32>(vertices[0]);\r
+                               box.addInternalPoint(vertices[1]);\r
+\r
+                               if(distance < mindistance)\r
+                               {\r
+                                       if(box.intersectsWithLine(shootline))\r
+                                       {\r
+                                               nodefound = true;\r
+                                               nodepos = np;\r
+                                               neighbourpos = np;\r
+                                               mindistance = distance;\r
+                                               nodehilightbox = box;\r
+                                       }\r
+                               }\r
+                       }\r
                        /*\r
                                Regular blocks\r
                        */\r
@@ -2765,11 +2814,20 @@ int main(int argc, char *argv[])
                        static float dig_time = 0.0;\r
                        static u16 dig_index = 0;\r
                        \r
-                       // Visualize selection\r
+                       /*\r
+                               Visualize selection\r
+                       */\r
 \r
                        hilightboxes.push_back(nodehilightbox);\r
 \r
-                       // Handle digging\r
+                       /*\r
+                               TODO:\r
+                               Check information text of node\r
+                       */\r
+\r
+                       /*\r
+                               Handle digging\r
+                       */\r
                        \r
                        if(g_input->getLeftReleased())\r
                        {\r
index 0a1b65ace389f5be874f529d9e37c1f04a617e02..39e35156988568a080cba52773644b35ba6030a2 100644 (file)
@@ -940,6 +940,15 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
                n.setLight(bank, 0);
        }
 
+       /*
+               If node lets sunlight through and is under sunlight, it has
+               sunlight too.
+       */
+       if(node_under_sunlight && content_features(n.d).sunlight_propagates)
+       {
+               n.setLight(LIGHTBANK_DAY, LIGHT_SUN);
+       }
+       
        /*
                Set the node on the map
        */
@@ -947,13 +956,13 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
        setNode(p, n);
        
        /*
-               If node is under sunlight, take all sunlighted nodes under
-               it and clear light from them and from where the light has
-               been spread.
+               If node is under sunlight and doesn't let sunlight through,
+               take all sunlighted nodes under it and clear light from them
+               and from where the light has been spread.
                TODO: This could be optimized by mass-unlighting instead
                      of looping
        */
-       if(node_under_sunlight)
+       if(node_under_sunlight && !content_features(n.d).sunlight_propagates)
        {
                s16 y = p.Y - 1;
                for(;; y--){
@@ -981,7 +990,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
                                break;
                }
        }
-       
+
        for(s32 i=0; i<2; i++)
        {
                enum LightBank bank = banks[i];
@@ -1687,6 +1696,17 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
        //dstream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
 }
 
+NodeMetadata* Map::getNodeMetadataClone(v3s16 p)
+{
+       v3s16 blockpos = getNodeBlockPos(p);
+       v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
+       MapBlock *block = getBlockNoCreateNoEx(blockpos);
+       if(block == NULL)
+               return NULL;
+       NodeMetadata *meta = block->m_node_metadata.getClone(p_rel);
+       return meta;
+}
+
 /*
        ServerMap
 */
index 1cebef63442727eac60cfdb9dd02a42a07e8af08..2fafcae17e1fef95540be8f4ed56768880cae988 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "constants.h"
 #include "voxel.h"
 #include "mapchunk.h"
+#include "nodemetadata.h"
 
 #define MAPTYPE_BASE 0
 #define MAPTYPE_SERVER 1
@@ -276,6 +277,13 @@ public:
        
        void transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks);
 
+       /*
+               Node metadata
+               These are basically coordinate wrappers to MapBlock
+       */
+       
+       NodeMetadata* getNodeMetadataClone(v3s16 p);
+
        /*
                Variables
        */
index 66833addbcd6433a6f4ab2c3f31cb04f2a924e13..26280dec4b92fc53070c16ff1c54423cb0e25f53 100644 (file)
@@ -799,6 +799,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                {
                        video::SColor c(255,255,255,255);
 
+                       // Wall at X+ of node
                        video::S3DVertex vertices[4] =
                        {
                                video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c, 0,1),
@@ -854,6 +855,61 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                        // Add to mesh collector
                        collector.append(material, vertices, 4, indices, 6);
                }
+               /*
+                       Signs on walls
+               */
+               if(n.d == CONTENT_SIGN_WALL)
+               {
+                       u8 l = decode_light(n.getLightBlend(daynight_ratio));
+                       video::SColor c(255,l,l,l);
+                               
+                       float d = (float)BS/16;
+                       // Wall at X+ of node
+                       video::S3DVertex vertices[4] =
+                       {
+                               video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c, 0,1),
+                               video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c, 1,1),
+                               video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c, 1,0),
+                               video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c, 0,0),
+                       };
+
+                       v3s16 dir = unpackDir(n.dir);
+
+                       for(s32 i=0; i<4; i++)
+                       {
+                               if(dir == v3s16(1,0,0))
+                                       vertices[i].Pos.rotateXZBy(0);
+                               if(dir == v3s16(-1,0,0))
+                                       vertices[i].Pos.rotateXZBy(180);
+                               if(dir == v3s16(0,0,1))
+                                       vertices[i].Pos.rotateXZBy(90);
+                               if(dir == v3s16(0,0,-1))
+                                       vertices[i].Pos.rotateXZBy(-90);
+                               if(dir == v3s16(0,-1,0))
+                                       vertices[i].Pos.rotateXYBy(-90);
+                               if(dir == v3s16(0,1,0))
+                                       vertices[i].Pos.rotateXYBy(90);
+
+                               vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
+                       }
+
+                       // Set material
+                       video::SMaterial material;
+                       material.setFlag(video::EMF_LIGHTING, false);
+                       material.setFlag(video::EMF_BACK_FACE_CULLING, false);
+                       material.setFlag(video::EMF_BILINEAR_FILTER, false);
+                       material.setFlag(video::EMF_FOG_ENABLE, true);
+                       //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+                       material.MaterialType
+                                       = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+
+                       material.setTexture(0, 
+                                       g_texturesource->getTextureRaw("sign_wall.png"));
+
+                       u16 indices[] = {0,1,2,2,3,0};
+                       // Add to mesh collector
+                       collector.append(material, vertices, 4, indices, 6);
+               }
                /*
                        Add flowing water to mesh
                */
index 3614d136750277383fb7c8743af8bbf136039c3f..6af4070bc59d27ca7f734c31ffc1c9786c1e6447 100644 (file)
@@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "constants.h"
 #include "mapblockobject.h"
 #include "voxel.h"
+#include "nodemetadata.h"
 
 // Named by looking towards z+
 enum{
@@ -619,6 +620,8 @@ public:
        JMutex mesh_mutex;
 #endif
        
+       NodeMetadataList m_node_metadata;
+       
 private:
        /*
                Private member variables
@@ -665,27 +668,11 @@ private:
        // Whether day and night lighting differs
        bool m_day_night_differs;
        
-       /*
-               Whether everything that is mainly located on this block has
-               been added to the world.
-
-               While this is false, a block can still be changed a bit when
-               stuff is added to the neighboring blocks that extends to this
-               one.
-
-               When this is false on every one of a 3x3x3 chunk of blocks, the
-               central one will not be changed by the map generator in the
-               future.
-
-               TODO: Save in file
-       */
-       //bool m_not_fully_generated;
-       
        MapBlockObjectList m_objects;
 
        // Object spawning stuff
        float m_spawn_timer;
-       
+
 #ifndef SERVER // Only on client
        /*
                Set to true if the mesh has been ordered to be updated
index 2ca4ade7a75e889f33e0b25ce7fb8e18b444c876..a8c951ab3414c75a6e00dceb669ffbda3744472d 100644 (file)
@@ -201,6 +201,7 @@ void init_mapnode()
        }
        f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
        
+       // Deprecated
        i = CONTENT_COALSTONE;
        f = &g_content_features[i];
        //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
@@ -287,6 +288,25 @@ void init_mapnode()
        f->wall_mounted = true;
        f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
        
+       i = CONTENT_FURNACE;
+       f = &g_content_features[i];
+       f->setAllTextures("furnace_side.png");
+       f->setTexture(2, "furnace_front.png");
+       f->setInventoryTexture("furnace_front.png");
+       f->param_type = CPT_NONE;
+       f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+       
+       i = CONTENT_SIGN_WALL;
+       f = &g_content_features[i];
+       f->setInventoryTexture("sign_wall.png");
+       f->param_type = CPT_LIGHT;
+       f->light_propagates = true;
+       f->sunlight_propagates = true;
+       f->solidness = 0; // drawn separately, makes no faces
+       f->walkable = false;
+       f->wall_mounted = true;
+       f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+       
 }
 
 TileSpec MapNode::getTile(v3s16 dir)
index 03a294ad27bddc2b4fc6575540ab3c47439031df..ba08a37daaeeec8c39f01b1b915def9540aaafcf 100644 (file)
@@ -94,12 +94,8 @@ void init_content_inventory_texture_paths();
 #define CONTENT_COALSTONE 11
 #define CONTENT_WOOD 12
 #define CONTENT_SAND 13
-
-/*
-       This is used by all kinds of things to allocate memory for all
-       contents except CONTENT_AIR and CONTENT_IGNORE
-*/
-#define USEFUL_CONTENT_COUNT 14
+#define CONTENT_FURNACE 14
+#define CONTENT_SIGN_WALL 15
 
 /*
        Content feature list
index 0558a5e39e2a90e6d47b625e89278fbb7d5c8b8f..50f994523e1e4da1cc92f30caa1b4de258823eea 100644 (file)
@@ -60,6 +60,8 @@ void initializeMaterialProperties()
        g_material_properties[CONTENT_SAND].setDiggingProperties("",
                        DiggingProperties(true, 0.4, 0));
        
+       setStoneLikeDiggingProperties(CONTENT_FURNACE, 1.0);
+       
        /*
                Add MesePick to everything
        */
index 72f121c06353c64a1eb796f79c3510b3d286941e..b3ce9c13aeeef720b876219bf11227d0516b75dd 100644 (file)
@@ -3327,6 +3327,36 @@ void setCreativeInventory(Player *player)
        /*
                Give materials
        */
+       
+       // CONTENT_IGNORE-terminated list
+       u8 material_items[] = {
+               CONTENT_TORCH,
+               CONTENT_MUD,
+               CONTENT_STONE,
+               CONTENT_SAND,
+               CONTENT_TREE,
+               CONTENT_LEAVES,
+               CONTENT_MESE,
+               CONTENT_WATERSOURCE,
+               CONTENT_CLOUD,
+               CONTENT_FURNACE,
+               CONTENT_SIGN_WALL,
+               CONTENT_IGNORE
+       };
+       
+       u8 *mip = material_items;
+       for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
+       {
+               if(*mip == CONTENT_IGNORE)
+                       break;
+
+               InventoryItem *item = new MaterialItem(*mip, 1);
+               player->inventory.addItem("main", item);
+
+               mip++;
+       }
+
+#if 0
        assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
        
        // add torch first
@@ -3344,6 +3374,8 @@ void setCreativeInventory(Player *player)
                InventoryItem *item = new MaterialItem(i, 1);
                player->inventory.addItem("main", item);
        }
+#endif
+
        // Sign
        {
                InventoryItem *item = new MapBlockObjectItem("Sign Example text");