before adding day/night lighting
[oweals/minetest.git] / src / mapnode.h
index 77fd677da3fae6591f5d85851395422ab0576c2a..7314420115d1f54803b1fc9005369ad87f1c2869 100644 (file)
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "utility.h"
 #include "exceptions.h"
 #include "serialization.h"
+#include "tile.h"
 
 // Size of node in rendering units
 #define BS 10
@@ -64,37 +65,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 enum Content
 {
-       CONTENT_STONE=0,
-
-       CONTENT_GRASS=1,
-
-       CONTENT_WATER=2,
-
-       CONTENT_LIGHT=3,
-
-       CONTENT_TREE=4,
-       
-       CONTENT_LEAVES=5,
-
-       CONTENT_GRASS_FOOTSTEPS=6,
-       
-       CONTENT_MESE=7,
-
-       CONTENT_MUD=8,
-
-       CONTENT_OCEAN=9,
+       CONTENT_STONE,
+       CONTENT_GRASS,
+       CONTENT_WATER,
+       CONTENT_TORCH,
+       CONTENT_TREE,
+       CONTENT_LEAVES,
+       CONTENT_GRASS_FOOTSTEPS,
+       CONTENT_MESE,
+       CONTENT_MUD,
+       CONTENT_OCEAN,
+       CONTENT_CLOUD,
        
        // This is set to the number of the actual values in this enum
        USEFUL_CONTENT_COUNT
 };
 
+extern u16 g_content_tiles[USEFUL_CONTENT_COUNT][6];
+extern const char * g_content_inventory_textures[USEFUL_CONTENT_COUNT];
+
 /*
        If true, the material allows light propagation and brightness is stored
        in param.
 */
 inline bool light_propagates_content(u8 m)
 {
-       return (m == CONTENT_AIR || m == CONTENT_LIGHT || m == CONTENT_WATER || m == CONTENT_OCEAN);
+       return (m == CONTENT_AIR || m == CONTENT_TORCH || m == CONTENT_WATER || m == CONTENT_OCEAN);
 }
 
 /*
@@ -102,7 +98,7 @@ inline bool light_propagates_content(u8 m)
 */
 inline bool sunlight_propagates_content(u8 m)
 {
-       return (m == CONTENT_AIR || m == CONTENT_LIGHT);
+       return (m == CONTENT_AIR || m == CONTENT_TORCH);
 }
 
 /*
@@ -114,7 +110,8 @@ inline bool sunlight_propagates_content(u8 m)
 */
 inline u8 content_solidness(u8 m)
 {
-       if(m == CONTENT_AIR)
+       // As of now, every pseudo node like torches are added to this
+       if(m == CONTENT_AIR || m == CONTENT_TORCH)
                return 0;
        if(m == CONTENT_WATER || m == CONTENT_OCEAN)
                return 1;
@@ -124,7 +121,7 @@ inline u8 content_solidness(u8 m)
 // Objects collide with walkable contents
 inline bool content_walkable(u8 m)
 {
-       return (m != CONTENT_AIR && m != CONTENT_WATER && m != CONTENT_OCEAN && m != CONTENT_LIGHT);
+       return (m != CONTENT_AIR && m != CONTENT_WATER && m != CONTENT_OCEAN && m != CONTENT_TORCH);
 }
 
 // A liquid resists fast movement
@@ -149,18 +146,6 @@ inline bool content_buildable_to(u8 m)
        return (m == CONTENT_AIR || m == CONTENT_WATER || m == CONTENT_OCEAN);
 }
 
-/*
-       TODO: Make a mapper class for mapping every side of a content
-             to some tile.
-       This dumbily maps all sides of content to the tile of the same id.
-*/
-inline u8 content_tile(u8 c)
-{
-       if(c == CONTENT_IGNORE || c == CONTENT_LIGHT)
-               return CONTENT_AIR;
-       return c;
-}
-
 /*
        Returns true for contents that form the base ground that
        follows the main heightmap
@@ -176,6 +161,13 @@ inline bool is_ground_content(u8 m)
        );
 }
 
+/*inline bool content_has_faces(u8 c)
+{
+       return (m != CONTENT_IGNORE
+            && m != CONTENT_AIR
+                && m != CONTENT_TORCH);
+}*/
+
 /*
        Nodes make a face if contents differ and solidness differs.
        Return value:
@@ -203,7 +195,7 @@ inline u8 face_contents(u8 m1, u8 m2)
 
 inline bool liquid_replaces_content(u8 c)
 {
-       return (c == CONTENT_AIR || c == CONTENT_LIGHT);
+       return (c == CONTENT_AIR || c == CONTENT_TORCH);
 }
 
 /*
@@ -211,7 +203,7 @@ inline bool liquid_replaces_content(u8 c)
 */
 inline bool content_directional(u8 c)
 {
-       return (c == CONTENT_LIGHT);
+       return (c == CONTENT_TORCH);
 }
 
 /*
@@ -260,6 +252,34 @@ inline v3s16 unpackDir(u8 b)
        return d;
 }
 
+inline u16 content_tile(u8 c, v3s16 dir)
+{
+       if(c == CONTENT_IGNORE || c == CONTENT_AIR
+                       || c >= USEFUL_CONTENT_COUNT)
+               return TILE_NONE;
+
+       s32 dir_i = -1;
+       
+       if(dir == v3s16(0,1,0))
+               dir_i = 0;
+       else if(dir == v3s16(0,-1,0))
+               dir_i = 1;
+       else if(dir == v3s16(1,0,0))
+               dir_i = 2;
+       else if(dir == v3s16(-1,0,0))
+               dir_i = 3;
+       else if(dir == v3s16(0,0,1))
+               dir_i = 4;
+       else if(dir == v3s16(0,0,-1))
+               dir_i = 5;
+       
+       /*if(dir_i == -1)
+               return TILE_NONE;*/
+       assert(dir_i != -1);
+
+       return g_content_tiles[c][dir_i];
+}
+
 struct MapNode
 {
        // Content
@@ -326,7 +346,7 @@ struct MapNode
                /*
                        Note that a block that isn't light_propagates() can be a light source.
                */
-               if(d == CONTENT_LIGHT)
+               if(d == CONTENT_TORCH)
                        return LIGHT_MAX;
                
                return 0;
@@ -348,7 +368,13 @@ 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)
+       {
+               return content_tile(d, dir);
        }
 
        /*