]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapnode.h
mapgen tweaking
[dragonfireclient.git] / src / mapnode.h
index c69436c9ed19ec09547ba02778c788e0d0840d30..03a294ad27bddc2b4fc6575540ab3c47439031df 100644 (file)
@@ -1,6 +1,6 @@
 /*
 Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -27,10 +27,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "exceptions.h"
 #include "serialization.h"
 #include "tile.h"
+#include "iirrlichtwrapper.h"
 
-// Initializes all kind of stuff in here.
-// Doesn't depend on anything else.
-// Many things depend on this.
+/*
+       Initializes all kind of stuff in here.
+       Many things depend on this.
+
+       This accesses g_texturesource; if it is non-NULL, textures are set.
+
+       Client first calls this with g_texturesource=NULL to run some
+       unit tests and stuff, then it runs this again with g_texturesource
+       defined to get the textures.
+
+       Server only calls this once with g_texturesource=NULL.
+*/
 void init_mapnode();
 
 // Initializes g_content_inventory_texture_paths
@@ -128,8 +138,12 @@ struct ContentFeatures
                5: front
        */
        TileSpec tiles[6];
-
-       std::string inventory_image_path;
+       
+       // TODO: Somehow specify inventory image
+       //std::string inventory_image_path;
+       //TextureSpec inventory_texture;
+       //u32 inventory_texture_id;
+       video::ITexture *inventory_texture;
 
        bool is_ground_content; //TODO: Remove, use walkable instead
        bool light_propagates;
@@ -140,7 +154,13 @@ struct ContentFeatures
        bool diggable;
        bool buildable_to;
        enum LiquidType liquid_type;
-       bool wall_mounted; // If true, param2 is set to direction when placed
+       // If true, param2 is set to direction when placed
+       // NOTE: the direction format is quite inefficient and should be changed
+       bool wall_mounted;
+       
+       // Inventory item string as which the node appears in inventory when dug.
+       // Mineral overrides this.
+       std::string dug_item;
 
        //TODO: Move more properties here
 
@@ -148,6 +168,7 @@ struct ContentFeatures
        {
                translate_to = NULL;
                param_type = CPT_NONE;
+               inventory_texture = NULL;
                is_ground_content = false;
                light_propagates = false;
                sunlight_propagates = false;
@@ -158,43 +179,47 @@ struct ContentFeatures
                buildable_to = false;
                liquid_type = LIQUID_NONE;
                wall_mounted = false;
+               dug_item = "";
        }
 
        ~ContentFeatures();
        
-       void setAllTextures(std::string imgname, u8 alpha=255)
+       /*
+               Quickhands for simple materials
+       */
+       
+       void setTexture(u16 i, std::string name, u8 alpha=255);
+
+       void setAllTextures(std::string name, u8 alpha=255)
        {
                for(u16 i=0; i<6; i++)
                {
-                       tiles[i].name = porting::getDataPath(imgname.c_str());
-                       tiles[i].alpha = alpha;
+                       setTexture(i, name, alpha);
                }
-               
-               // Set this too so it can be left as is most times
-               if(inventory_image_path == "")
-                       inventory_image_path = porting::getDataPath(imgname.c_str());
        }
-       void setTexture(u16 i, std::string imgname, u8 alpha=255)
+
+       void setTile(u16 i, const TileSpec &tile)
        {
-               tiles[i].name = porting::getDataPath(imgname.c_str());
-               tiles[i].alpha = alpha;
+               tiles[i] = tile;
        }
-
-       void setInventoryImage(std::string imgname)
+       void setAllTiles(const TileSpec &tile)
        {
-               inventory_image_path = porting::getDataPath(imgname.c_str());
+               for(u16 i=0; i<6; i++)
+               {
+                       setTile(i, tile);
+               }
        }
-};
 
-// Initialized by init_mapnode()
-extern struct ContentFeatures g_content_features[256];
-
-inline ContentFeatures & content_features(u8 i)
-{
-       return g_content_features[i];
-}
+       void setInventoryTexture(std::string imgname);
+       
+       void setInventoryTextureCube(std::string top,
+                       std::string left, std::string right);
+};
 
-extern const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT];
+/*
+       Call this to access the ContentFeature list
+*/
+ContentFeatures & content_features(u8 i);
 
 /*
        If true, the material allows light propagation and brightness is stored
@@ -203,7 +228,7 @@ extern const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT];
 */
 inline bool light_propagates_content(u8 m)
 {
-       return g_content_features[m].light_propagates;
+       return content_features(m).light_propagates;
        //return (m == CONTENT_AIR || m == CONTENT_TORCH || m == CONTENT_WATER || m == CONTENT_WATERSOURCE);
 }
 
@@ -214,7 +239,7 @@ inline bool light_propagates_content(u8 m)
 */
 inline bool sunlight_propagates_content(u8 m)
 {
-       return g_content_features[m].sunlight_propagates;
+       return content_features(m).sunlight_propagates;
        //return (m == CONTENT_AIR || m == CONTENT_TORCH);
 }
 
@@ -228,7 +253,7 @@ inline bool sunlight_propagates_content(u8 m)
 */
 inline u8 content_solidness(u8 m)
 {
-       return g_content_features[m].solidness;
+       return content_features(m).solidness;
        /*// As of now, every pseudo node like torches are added to this
        if(m == CONTENT_AIR || m == CONTENT_TORCH || m == CONTENT_WATER)
                return 0;
@@ -241,28 +266,28 @@ inline u8 content_solidness(u8 m)
 // NOTE: Don't use, use "content_features(m).whatever" instead
 inline bool content_walkable(u8 m)
 {
-       return g_content_features[m].walkable;
+       return content_features(m).walkable;
        //return (m != CONTENT_AIR && m != CONTENT_WATER && m != CONTENT_WATERSOURCE && m != CONTENT_TORCH);
 }
 
 // NOTE: Don't use, use "content_features(m).whatever" instead
 inline bool content_liquid(u8 m)
 {
-       return g_content_features[m].liquid_type != LIQUID_NONE;
+       return content_features(m).liquid_type != LIQUID_NONE;
        //return (m == CONTENT_WATER || m == CONTENT_WATERSOURCE);
 }
 
 // NOTE: Don't use, use "content_features(m).whatever" instead
 inline bool content_flowing_liquid(u8 m)
 {
-       return g_content_features[m].liquid_type == LIQUID_FLOWING;
+       return content_features(m).liquid_type == LIQUID_FLOWING;
        //return (m == CONTENT_WATER);
 }
 
 // NOTE: Don't use, use "content_features(m).whatever" instead
 inline bool content_liquid_source(u8 m)
 {
-       return g_content_features[m].liquid_type == LIQUID_SOURCE;
+       return content_features(m).liquid_type == LIQUID_SOURCE;
        //return (m == CONTENT_WATERSOURCE);
 }
 
@@ -279,21 +304,21 @@ inline u8 make_liquid_flowing(u8 m)
 // NOTE: Don't use, use "content_features(m).whatever" instead
 inline bool content_pointable(u8 m)
 {
-       return g_content_features[m].pointable;
+       return content_features(m).pointable;
        //return (m != CONTENT_AIR && m != CONTENT_WATER && m != CONTENT_WATERSOURCE);
 }
 
 // NOTE: Don't use, use "content_features(m).whatever" instead
 inline bool content_diggable(u8 m)
 {
-       return g_content_features[m].diggable;
+       return content_features(m).diggable;
        //return (m != CONTENT_AIR && m != CONTENT_WATER && m != CONTENT_WATERSOURCE);
 }
 
 // NOTE: Don't use, use "content_features(m).whatever" instead
 inline bool content_buildable_to(u8 m)
 {
-       return g_content_features[m].buildable_to;
+       return content_features(m).buildable_to;
        //return (m == CONTENT_AIR || m == CONTENT_WATER || m == CONTENT_WATERSOURCE);
 }
 
@@ -303,7 +328,7 @@ inline bool content_buildable_to(u8 m)
 */
 /*inline bool is_ground_content(u8 m)
 {
-       return g_content_features[m].is_ground_content;
+       return content_features(m).is_ground_content;
 }*/
 
 /*
@@ -409,12 +434,11 @@ struct MapNode
        
        union
        {
-               u8 param2;
-
                /*
-                       Direction for torches and other stuff.
-                       Format is freeform. e.g. packDir or encode_dirs can be used.
+                       The second parameter. Initialized to 0.
+                       Direction for torches and flowing water.
                */
+               u8 param2;
                u8 dir;
        };
 
@@ -430,6 +454,14 @@ struct MapNode
                param2 = a_param2;
        }
 
+       /*MapNode & operator=(const MapNode &other)
+       {
+               d = other.d;
+               param = other.param;
+               param2 = other.param2;
+               return *this;
+       }*/
+
        bool operator==(const MapNode &other)
        {
                return (d == other.d
@@ -622,7 +654,9 @@ struct MapNode
                }
 
                // Translate deprecated stuff
-               MapNode *translate_to = g_content_features[d].translate_to;
+               // NOTE: This doesn't get used because MapBlock handles node
+               // parameters directly
+               MapNode *translate_to = content_features(d).translate_to;
                if(translate_to)
                {
                        dstream<<"MapNode: WARNING: Translating "<<d<<" to "
@@ -632,32 +666,6 @@ struct MapNode
        }
 };
 
-/*
-       Returns integer position of the node in given
-       floating point position.
-*/
-inline v3s16 floatToInt(v3f p)
-{
-       v3s16 p2(
-               (p.X + (p.X>0 ? BS/2 : -BS/2))/BS,
-               (p.Y + (p.Y>0 ? BS/2 : -BS/2))/BS,
-               (p.Z + (p.Z>0 ? BS/2 : -BS/2))/BS);
-       return p2;
-}
-
-/*
-       The same thing backwards
-*/
-inline v3f intToFloat(v3s16 p)
-{
-       v3f p2(
-               p.X * BS,
-               p.Y * BS,
-               p.Z * BS
-       );
-       return p2;
-}
-
 
 
 #endif