From dc5319b6c9f2e39d93f2fa881403f36fc47ffaac Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 17 Jun 2011 22:20:15 +0300 Subject: [PATCH] Moved some mapnode content stuff from mapnode.{h,cpp} and digging property stuff from material.cpp to content_mapnode.{h,cpp} --- src/CMakeLists.txt | 1 + src/content_mapnode.cpp | 351 ++++++++++++++++++++++++++++++++++++++++ src/content_mapnode.h | 53 ++++++ src/environment.cpp | 1 + src/game.cpp | 3 + src/inventory.cpp | 1 + src/main.cpp | 9 +- src/map.cpp | 1 + src/mapblock.cpp | 3 + src/mapnode.cpp | 257 +---------------------------- src/mapnode.h | 157 +++++++----------- src/materials.cpp | 106 +----------- src/materials.h | 24 +-- src/nodemetadata.cpp | 1 + src/server.cpp | 1 + src/servermain.cpp | 2 +- src/test.cpp | 1 + src/voxel.cpp | 5 +- 18 files changed, 514 insertions(+), 463 deletions(-) create mode 100644 src/content_mapnode.cpp create mode 100644 src/content_mapnode.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 558c2802..05b56310 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ configure_file( ) set(common_SRCS + content_mapnode.cpp auth.cpp collision.cpp nodemetadata.cpp diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp new file mode 100644 index 00000000..1f1c8e30 --- /dev/null +++ b/src/content_mapnode.cpp @@ -0,0 +1,351 @@ +/* +Minetest-c55 +Copyright (C) 2010-2011 celeron55, Perttu Ahola + +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 +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +// For g_settings +#include "main.h" + +#include "content_mapnode.h" +#include "mapnode.h" +#include "nodemetadata.h" + +// TODO: Get rid of these and set up some attributes like toughness, +// fluffyness, and a funciton to calculate time and durability loss +// (and sound? and whatever else) from them +void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness); +void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness); +void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness); + +void content_mapnode_init() +{ + // Read some settings + bool new_style_water = g_settings.getBool("new_style_water"); + bool new_style_leaves = g_settings.getBool("new_style_leaves"); + + u8 i; + ContentFeatures *f = NULL; + + i = CONTENT_STONE; + f = &content_features(i); + f->setAllTextures("stone.png"); + f->setInventoryTextureCube("stone.png", "stone.png", "stone.png"); + f->param_type = CPT_MINERAL; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1"; + setStoneLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_GRASS; + f = &content_features(i); + f->setAllTextures("mud.png^grass_side.png"); + f->setTexture(0, "grass.png"); + f->setTexture(1, "mud.png"); + f->param_type = CPT_MINERAL; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1"; + setDirtLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_GRASS_FOOTSTEPS; + f = &content_features(i); + f->setAllTextures("mud.png^grass_side.png"); + f->setTexture(0, "grass_footsteps.png"); + f->setTexture(1, "mud.png"); + f->param_type = CPT_MINERAL; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1"; + setDirtLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_MUD; + f = &content_features(i); + f->setAllTextures("mud.png"); + f->setInventoryTextureCube("mud.png", "mud.png", "mud.png"); + f->param_type = CPT_MINERAL; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setDirtLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_SAND; + f = &content_features(i); + f->setAllTextures("sand.png"); + f->param_type = CPT_MINERAL; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setDirtLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_TREE; + f = &content_features(i); + f->setAllTextures("tree.png"); + f->setTexture(0, "tree_top.png"); + f->setTexture(1, "tree_top.png"); + f->param_type = CPT_MINERAL; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setWoodLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_LEAVES; + f = &content_features(i); + f->light_propagates = true; + //f->param_type = CPT_MINERAL; + f->param_type = CPT_LIGHT; + f->is_ground_content = true; + if(new_style_leaves) + { + f->solidness = 0; // drawn separately, makes no faces + f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png"); + } + else + { + f->setAllTextures("[noalpha:leaves.png"); + } + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setWoodLikeDiggingProperties(f->digging_properties, 0.15); + + i = CONTENT_GLASS; + f = &content_features(i); + f->light_propagates = true; + f->param_type = CPT_LIGHT; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + f->solidness = 0; // drawn separately, makes no faces + f->setInventoryTextureCube("glass.png", "glass.png", "glass.png"); + setWoodLikeDiggingProperties(f->digging_properties, 0.15); + + i = CONTENT_FENCE; + f = &content_features(i); + f->light_propagates = true; + f->param_type = CPT_LIGHT; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + f->solidness = 0; // drawn separately, makes no faces + f->air_equivalent = true; // grass grows underneath + f->setInventoryTexture("item_fence.png"); + setWoodLikeDiggingProperties(f->digging_properties, 0.75); + + // Deprecated + i = CONTENT_COALSTONE; + f = &content_features(i); + //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL); + f->setAllTextures("stone.png^mineral_coal.png"); + f->is_ground_content = true; + setStoneLikeDiggingProperties(f->digging_properties, 1.5); + + i = CONTENT_WOOD; + f = &content_features(i); + f->setAllTextures("wood.png"); + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setWoodLikeDiggingProperties(f->digging_properties, 0.75); + + i = CONTENT_MESE; + f = &content_features(i); + f->setAllTextures("mese.png"); + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setStoneLikeDiggingProperties(f->digging_properties, 0.5); + + i = CONTENT_CLOUD; + f = &content_features(i); + f->setAllTextures("cloud.png"); + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + + i = CONTENT_AIR; + f = &content_features(i); + f->param_type = CPT_LIGHT; + f->light_propagates = true; + f->sunlight_propagates = true; + f->solidness = 0; + f->walkable = false; + f->pointable = false; + f->diggable = false; + f->buildable_to = true; + f->air_equivalent = true; + + i = CONTENT_WATER; + f = &content_features(i); + f->setInventoryTextureCube("water.png", "water.png", "water.png"); + f->param_type = CPT_LIGHT; + f->light_propagates = true; + f->solidness = 0; // Drawn separately, makes no faces + f->walkable = false; + f->pointable = false; + f->diggable = false; + f->buildable_to = true; + f->liquid_type = LIQUID_FLOWING; + f->liquid_alternative_flowing = CONTENT_WATER; + + i = CONTENT_WATERSOURCE; + f = &content_features(i); + f->setInventoryTexture("water.png"); + if(new_style_water) + { + f->solidness = 0; // drawn separately, makes no faces + } + else // old style + { + f->solidness = 1; + + TileSpec t; + if(g_texturesource) + t.texture = g_texturesource->getTexture("water.png"); + + t.alpha = WATER_ALPHA; + t.material_type = MATERIAL_ALPHA_VERTEX; + t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING; + f->setAllTiles(t); + } + f->param_type = CPT_LIGHT; + f->light_propagates = true; + f->walkable = false; + f->pointable = false; + f->diggable = false; + f->buildable_to = true; + f->liquid_type = LIQUID_SOURCE; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + f->liquid_alternative_flowing = CONTENT_WATER; + + i = CONTENT_TORCH; + f = &content_features(i); + f->setInventoryTexture("torch_on_floor.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->air_equivalent = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + f->light_source = LIGHT_MAX; + f->digging_properties.set("", DiggingProperties(true, 0.0, 0)); + + i = CONTENT_SIGN_WALL; + f = &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->air_equivalent = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + if(f->initial_metadata == NULL) + f->initial_metadata = new SignNodeMetadata("Some sign"); + f->digging_properties.set("", DiggingProperties(true, 0.5, 0)); + + i = CONTENT_CHEST; + f = &content_features(i); + f->param_type = CPT_FACEDIR_SIMPLE; + f->setAllTextures("chest_side.png"); + f->setTexture(0, "chest_top.png"); + f->setTexture(1, "chest_top.png"); + f->setTexture(5, "chest_front.png"); // Z- + f->setInventoryTexture("chest_top.png"); + //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png"); + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + if(f->initial_metadata == NULL) + f->initial_metadata = new ChestNodeMetadata(); + setWoodLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_FURNACE; + f = &content_features(i); + f->param_type = CPT_FACEDIR_SIMPLE; + f->setAllTextures("furnace_side.png"); + f->setTexture(5, "furnace_front.png"); // Z- + f->setInventoryTexture("furnace_front.png"); + //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6"; + if(f->initial_metadata == NULL) + f->initial_metadata = new FurnaceNodeMetadata(); + setStoneLikeDiggingProperties(f->digging_properties, 3.0); + + i = CONTENT_COBBLE; + f = &content_features(i); + f->setAllTextures("cobble.png"); + f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png"); + f->param_type = CPT_NONE; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setStoneLikeDiggingProperties(f->digging_properties, 1.0); + + i = CONTENT_STEEL; + f = &content_features(i); + f->setAllTextures("steel_block.png"); + f->setInventoryTextureCube("steel_block.png", "steel_block.png", + "steel_block.png"); + f->param_type = CPT_NONE; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + setStoneLikeDiggingProperties(f->digging_properties, 5.0); + + // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp + + + /* + Add MesePick to everything + */ + for(u16 i=0; i<256; i++) + { + content_features(i).digging_properties.set("MesePick", + DiggingProperties(true, 0.0, 65535./1337)); + } + +} + +void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness) +{ + list.set("", + DiggingProperties(true, 15.0*toughness, 0)); + + list.set("WPick", + DiggingProperties(true, 1.3*toughness, 65535./30.*toughness)); + list.set("STPick", + DiggingProperties(true, 0.75*toughness, 65535./100.*toughness)); + list.set("SteelPick", + DiggingProperties(true, 0.50*toughness, 65535./333.*toughness)); + + /*list.set("MesePick", + DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/ +} + +void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness) +{ + list.set("", + DiggingProperties(true, 0.75*toughness, 0)); + + list.set("WShovel", + DiggingProperties(true, 0.4*toughness, 65535./50.*toughness)); + list.set("STShovel", + DiggingProperties(true, 0.2*toughness, 65535./150.*toughness)); + list.set("SteelShovel", + DiggingProperties(true, 0.15*toughness, 65535./400.*toughness)); +} + +void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness) +{ + list.set("", + DiggingProperties(true, 3.0*toughness, 0)); + + list.set("WAxe", + DiggingProperties(true, 1.5*toughness, 65535./30.*toughness)); + list.set("STAxe", + DiggingProperties(true, 0.75*toughness, 65535./100.*toughness)); + list.set("SteelAxe", + DiggingProperties(true, 0.5*toughness, 65535./333.*toughness)); +} + + diff --git a/src/content_mapnode.h b/src/content_mapnode.h new file mode 100644 index 00000000..c511834e --- /dev/null +++ b/src/content_mapnode.h @@ -0,0 +1,53 @@ +/* +Minetest-c55 +Copyright (C) 2010-2011 celeron55, Perttu Ahola + +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 +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef CONTENT_MAPNODE_HEADER +#define CONTENT_MAPNODE_HEADER + +void content_mapnode_init(); + +/* + Node content type IDs +*/ +#define CONTENT_STONE 0 +#define CONTENT_GRASS 1 +#define CONTENT_WATER 2 +#define CONTENT_TORCH 3 +#define CONTENT_TREE 4 +#define CONTENT_LEAVES 5 +#define CONTENT_GRASS_FOOTSTEPS 6 +#define CONTENT_MESE 7 +#define CONTENT_MUD 8 +#define CONTENT_WATERSOURCE 9 +// Pretty much useless, clouds won't be drawn this way +#define CONTENT_CLOUD 10 +#define CONTENT_COALSTONE 11 +#define CONTENT_WOOD 12 +#define CONTENT_SAND 13 +#define CONTENT_SIGN_WALL 14 +#define CONTENT_CHEST 15 +#define CONTENT_FURNACE 16 +//#define CONTENT_WORKBENCH 17 +#define CONTENT_COBBLE 18 +#define CONTENT_STEEL 19 +#define CONTENT_GLASS 20 +#define CONTENT_FENCE 21 + +#endif + diff --git a/src/environment.cpp b/src/environment.cpp index 79822880..8f862830 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "porting.h" #include "collision.h" +#include "content_mapnode.h" Environment::Environment(): diff --git a/src/game.cpp b/src/game.cpp index ef574c34..eef27c80 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -32,6 +32,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "keycode.h" #include "farmesh.h" +// TODO: Move content-aware stuff to separate file +#include "content_mapnode.h" + /* Setting this to 1 enables a special camera mode that forces the renderers to think that the camera statically points from diff --git a/src/inventory.cpp b/src/inventory.cpp index 47a8d4de..88453530 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "main.h" #include "serverobject.h" +#include "content_mapnode.h" /* InventoryItem diff --git a/src/main.cpp b/src/main.cpp index bb34a1a9..ed3b322a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -228,6 +228,12 @@ TODO: Map saving should be done by EmergeThread SUGG: Map unloading based on sector reference is not very good, it keeps unnecessary stuff in memory. I guess. Investigate this. +TODO: FIXME: Make furnaces handle long step() times better; now a 10-day + dtime for a bunch of furnaces will take ages + +TODO: When block is placed and it has param_type==CPT_FACEDIR_SIMPLE, set + the direction accordingly. + Environment: ------------ @@ -1143,7 +1149,7 @@ int main(int argc, char *argv[]) fs::CreateDir(porting::path_userdata); // Init material properties table - initializeMaterialProperties(); + //initializeMaterialProperties(); // Debug handler BEGIN_DEBUG_EXCEPTION_HANDLER @@ -1414,7 +1420,6 @@ int main(int argc, char *argv[]) Preload some textures and stuff */ - init_content_inventory_texture_paths(); init_mapnode(); // Second call with g_texturesource set init_mineral(); diff --git a/src/map.cpp b/src/map.cpp index 9230d1c1..515885d8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mineral.h" #include "noise.h" #include "serverobject.h" +#include "content_mapnode.h" /* Map diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 1ebdd6b0..70006a71 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -24,6 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "light.h" #include +// TODO: Move content-aware mesh generation to a separate file +#include "content_mapnode.h" + #ifndef SERVER void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block) { diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 9a8a09a1..3717bf0a 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mineral.h" // For g_settings #include "main.h" +#include "content_mapnode.h" #include "nodemetadata.h" ContentFeatures::~ContentFeatures() @@ -107,9 +108,9 @@ void init_mapnode() "g_texturesource!=NULL"<reset(); for(u16 j=0; j<6; j++) f->tiles[j].material_type = initial_material_type; } - - u8 i; - ContentFeatures *f = NULL; - - i = CONTENT_STONE; - f = &g_content_features[i]; - f->setAllTextures("stone.png"); - f->setInventoryTextureCube("stone.png", "stone.png", "stone.png"); - f->param_type = CPT_MINERAL; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1"; - - i = CONTENT_GRASS; - f = &g_content_features[i]; - f->setAllTextures("mud.png^grass_side.png"); - f->setTexture(0, "grass.png"); - f->setTexture(1, "mud.png"); - f->param_type = CPT_MINERAL; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1"; - - i = CONTENT_GRASS_FOOTSTEPS; - f = &g_content_features[i]; - f->setAllTextures("mud.png^grass_side.png"); - f->setTexture(0, "grass_footsteps.png"); - f->setTexture(1, "mud.png"); - f->param_type = CPT_MINERAL; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1"; - - i = CONTENT_MUD; - f = &g_content_features[i]; - f->setAllTextures("mud.png"); - f->setInventoryTextureCube("mud.png", "mud.png", "mud.png"); - f->param_type = CPT_MINERAL; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_SAND; - f = &g_content_features[i]; - f->setAllTextures("sand.png"); - f->param_type = CPT_MINERAL; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_TREE; - f = &g_content_features[i]; - f->setAllTextures("tree.png"); - f->setTexture(0, "tree_top.png"); - f->setTexture(1, "tree_top.png"); - f->param_type = CPT_MINERAL; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_LEAVES; - f = &g_content_features[i]; - f->light_propagates = true; - //f->param_type = CPT_MINERAL; - f->param_type = CPT_LIGHT; - f->is_ground_content = true; - if(new_style_leaves) - { - f->solidness = 0; // drawn separately, makes no faces - f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png"); - } - else - { - f->setAllTextures("[noalpha:leaves.png"); - } - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_GLASS; - f = &g_content_features[i]; - f->light_propagates = true; - f->param_type = CPT_LIGHT; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - f->solidness = 0; // drawn separately, makes no faces - f->setInventoryTextureCube("glass.png", "glass.png", "glass.png"); - - i = CONTENT_FENCE; - f = &g_content_features[i]; - f->light_propagates = true; - f->param_type = CPT_LIGHT; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - f->solidness = 0; // drawn separately, makes no faces - f->air_equivalent = true; // grass grows underneath - f->setInventoryTexture("item_fence.png"); - - // Deprecated - i = CONTENT_COALSTONE; - f = &g_content_features[i]; - //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL); - f->setAllTextures("stone.png^mineral_coal.png"); - f->is_ground_content = true; - - i = CONTENT_WOOD; - f = &g_content_features[i]; - f->setAllTextures("wood.png"); - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_MESE; - f = &g_content_features[i]; - f->setAllTextures("mese.png"); - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_CLOUD; - f = &g_content_features[i]; - f->setAllTextures("cloud.png"); - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_AIR; - f = &g_content_features[i]; - f->param_type = CPT_LIGHT; - f->light_propagates = true; - f->sunlight_propagates = true; - f->solidness = 0; - f->walkable = false; - f->pointable = false; - f->diggable = false; - f->buildable_to = true; - f->air_equivalent = true; - - i = CONTENT_WATER; - f = &g_content_features[i]; - f->setInventoryTextureCube("water.png", "water.png", "water.png"); - f->param_type = CPT_LIGHT; - f->light_propagates = true; - f->solidness = 0; // Drawn separately, makes no faces - f->walkable = false; - f->pointable = false; - f->diggable = false; - f->buildable_to = true; - f->liquid_type = LIQUID_FLOWING; - - i = CONTENT_WATERSOURCE; - f = &g_content_features[i]; - f->setInventoryTexture("water.png"); - if(new_style_water) - { - f->solidness = 0; // drawn separately, makes no faces - } - else // old style - { - f->solidness = 1; - TileSpec t; - if(g_texturesource) - t.texture = g_texturesource->getTexture("water.png"); - - t.alpha = WATER_ALPHA; - t.material_type = MATERIAL_ALPHA_VERTEX; - t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING; - f->setAllTiles(t); - } - f->param_type = CPT_LIGHT; - f->light_propagates = true; - f->walkable = false; - f->pointable = false; - f->diggable = false; - f->buildable_to = true; - f->liquid_type = LIQUID_SOURCE; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_TORCH; - f = &g_content_features[i]; - f->setInventoryTexture("torch_on_floor.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->air_equivalent = true; - 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->air_equivalent = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - if(f->initial_metadata == NULL) - f->initial_metadata = new SignNodeMetadata("Some sign"); - - i = CONTENT_CHEST; - f = &g_content_features[i]; - f->param_type = CPT_FACEDIR_SIMPLE; - f->setAllTextures("chest_side.png"); - f->setTexture(0, "chest_top.png"); - f->setTexture(1, "chest_top.png"); - f->setTexture(5, "chest_front.png"); // Z- - f->setInventoryTexture("chest_top.png"); - //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png"); - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - if(f->initial_metadata == NULL) - f->initial_metadata = new ChestNodeMetadata(); - - i = CONTENT_FURNACE; - f = &g_content_features[i]; - f->param_type = CPT_FACEDIR_SIMPLE; - f->setAllTextures("furnace_side.png"); - f->setTexture(5, "furnace_front.png"); // Z- - f->setInventoryTexture("furnace_front.png"); - //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6"; - if(f->initial_metadata == NULL) - f->initial_metadata = new FurnaceNodeMetadata(); - - i = CONTENT_COBBLE; - f = &g_content_features[i]; - f->setAllTextures("cobble.png"); - f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png"); - f->param_type = CPT_NONE; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; - - i = CONTENT_STEEL; - f = &g_content_features[i]; - f->setAllTextures("steel_block.png"); - f->setInventoryTextureCube("steel_block.png", "steel_block.png", - "steel_block.png"); - f->param_type = CPT_NONE; - f->is_ground_content = true; - f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + /* + Initialize mapnode content + */ + content_mapnode_init(); - // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp } v3s16 facedir_rotate(u8 facedir, v3s16 dir) @@ -459,16 +230,4 @@ u8 MapNode::getMineral() return MINERAL_NONE; } -// Pointers to c_str()s g_content_features[i].inventory_image_path -//const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT] = {0}; - -void init_content_inventory_texture_paths() -{ - dstream<<"DEPRECATED "<<__FUNCTION_NAME< CONTENT_WATER // CONTENT_LAVA || CONTENT_LAVASOURCE -> CONTENT_LAVA +// NOTE: Don't use, use "content_features(m).whatever" instead inline u8 make_liquid_flowing(u8 m) { - if(m == CONTENT_WATER || m == CONTENT_WATERSOURCE) - return CONTENT_WATER; - assert(0); + u8 c = content_features(m).liquid_alternative_flowing; + assert(c != CONTENT_IGNORE); + return c; } - // Pointable contents can be pointed to in the map // NOTE: Don't use, use "content_features(m).whatever" instead inline bool content_pointable(u8 m) { 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 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 content_features(m).buildable_to; - //return (m == CONTENT_AIR || m == CONTENT_WATER || m == CONTENT_WATERSOURCE); } -/* - Returns true for contents that form the base ground that - follows the main heightmap -*/ -/*inline bool is_ground_content(u8 m) -{ - return content_features(m).is_ground_content; -}*/ - /* Nodes make a face if contents differ and solidness differs. Return value: @@ -493,31 +449,25 @@ struct MapNode && param == other.param && param2 == other.param2); } - + + /* + These four are DEPRECATED I guess. -c55 + */ bool light_propagates() { return light_propagates_content(d); } - bool sunlight_propagates() { return sunlight_propagates_content(d); } - u8 solidness() { return content_solidness(d); } - u8 light_source() { - /* - Note that a block that isn't light_propagates() can be a light source. - */ - if(d == CONTENT_TORCH) - return LIGHT_MAX; - - return 0; + return content_features(d).light_source; } u8 getLightBanksWithSource() @@ -537,11 +487,6 @@ struct MapNode return (lightday&0x0f) | ((lightnight<<4)&0xf0); } - void setLightBanks(u8 a_light) - { - param = a_light; - } - u8 getLight(enum LightBank bank) { // Select the brightest of [light source, propagated light] @@ -606,13 +551,25 @@ struct MapNode } // In mapnode.cpp + /* + Get tile of a face of the node. + dir: direction of face + Returns: TileSpec. Can contain miscellaneous texture coordinates, + which must be obeyed so that the texture atlas can be used. + */ TileSpec getTile(v3s16 dir); - + + /* + Gets mineral content of node, if there is any. + MINERAL_NONE if doesn't contain or isn't able to contain mineral. + */ u8 getMineral(); /* These serialization functions are used when informing client - of a single node add + of a single node add. + + NOTE: When loading a MapBlock, these are not used. Should they? */ static u32 serializedLength(u8 version) diff --git a/src/materials.cpp b/src/materials.cpp index 841f1d65..e3a24b9e 100644 --- a/src/materials.cpp +++ b/src/materials.cpp @@ -1,112 +1,20 @@ #include "materials.h" +#include "mapnode.h" -#define MATERIAL_PROPERTIES_COUNT 256 +// NOTE: DEPRECATED -// These correspond to the CONTENT_* constants -MaterialProperties g_material_properties[MATERIAL_PROPERTIES_COUNT]; - -bool g_material_properties_initialized = false; - -void setStoneLikeDiggingProperties(u8 material, float toughness) -{ - g_material_properties[material].setDiggingProperties("", - DiggingProperties(true, 15.0*toughness, 0)); - - g_material_properties[material].setDiggingProperties("WPick", - DiggingProperties(true, 1.3*toughness, 65535./30.*toughness)); - g_material_properties[material].setDiggingProperties("STPick", - DiggingProperties(true, 0.75*toughness, 65535./100.*toughness)); - g_material_properties[material].setDiggingProperties("SteelPick", - DiggingProperties(true, 0.50*toughness, 65535./333.*toughness)); - - /*g_material_properties[material].setDiggingProperties("MesePick", - DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/ -} - -void setDirtLikeDiggingProperties(u8 material, float toughness) -{ - g_material_properties[material].setDiggingProperties("", - DiggingProperties(true, 0.75*toughness, 0)); - - g_material_properties[material].setDiggingProperties("WShovel", - DiggingProperties(true, 0.4*toughness, 65535./50.*toughness)); - g_material_properties[material].setDiggingProperties("STShovel", - DiggingProperties(true, 0.2*toughness, 65535./150.*toughness)); - g_material_properties[material].setDiggingProperties("SteelShovel", - DiggingProperties(true, 0.15*toughness, 65535./400.*toughness)); -} - -void setWoodLikeDiggingProperties(u8 material, float toughness) -{ - g_material_properties[material].setDiggingProperties("", - DiggingProperties(true, 3.0*toughness, 0)); - - g_material_properties[material].setDiggingProperties("WAxe", - DiggingProperties(true, 1.5*toughness, 65535./30.*toughness)); - g_material_properties[material].setDiggingProperties("STAxe", - DiggingProperties(true, 0.75*toughness, 65535./100.*toughness)); - g_material_properties[material].setDiggingProperties("SteelAxe", - DiggingProperties(true, 0.5*toughness, 65535./333.*toughness)); -} - -void initializeMaterialProperties() -{ - /* - Now, the g_material_properties array is already initialized - by the constructors to such that no digging is possible. - - Add some digging properties to them. - */ - - setStoneLikeDiggingProperties(CONTENT_STONE, 1.0); - setStoneLikeDiggingProperties(CONTENT_MESE, 0.5); - setStoneLikeDiggingProperties(CONTENT_COALSTONE, 1.5); - setStoneLikeDiggingProperties(CONTENT_FURNACE, 3.0); - setStoneLikeDiggingProperties(CONTENT_COBBLE, 1.0); - setStoneLikeDiggingProperties(CONTENT_STEEL, 5.0); - - setDirtLikeDiggingProperties(CONTENT_MUD, 1.0); - setDirtLikeDiggingProperties(CONTENT_GRASS, 1.0); - setDirtLikeDiggingProperties(CONTENT_GRASS_FOOTSTEPS, 1.0); - setDirtLikeDiggingProperties(CONTENT_SAND, 1.0); - - setWoodLikeDiggingProperties(CONTENT_TREE, 1.0); - setWoodLikeDiggingProperties(CONTENT_LEAVES, 0.15); - setWoodLikeDiggingProperties(CONTENT_GLASS, 0.15); - setWoodLikeDiggingProperties(CONTENT_FENCE, 0.75); - setWoodLikeDiggingProperties(CONTENT_WOOD, 0.75); - setWoodLikeDiggingProperties(CONTENT_CHEST, 1.0); - - g_material_properties[CONTENT_SIGN_WALL].setDiggingProperties("", - DiggingProperties(true, 0.5, 0)); - g_material_properties[CONTENT_TORCH].setDiggingProperties("", - DiggingProperties(true, 0.0, 0)); - - /* - Add MesePick to everything - */ - for(u16 i=0; igetDiggingProperties(tool); + return mprop->get(tool); } diff --git a/src/materials.h b/src/materials.h index 42214975..272116d8 100644 --- a/src/materials.h +++ b/src/materials.h @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "common_irrlicht.h" -#include "inventory.h" #include struct DiggingProperties @@ -49,20 +48,26 @@ struct DiggingProperties u16 wear; }; -class MaterialProperties +/* + This is a DEPRECATED way of determining mining characteristics. + TODO: Get rid of this and set up some attributes like toughness, + fluffyness, and a funciton to calculate time and durability loss + (and sound? and whatever else) from them +*/ +class DiggingPropertiesList { public: - MaterialProperties() + DiggingPropertiesList() { } - void setDiggingProperties(const std::string toolname, + void set(const std::string toolname, const DiggingProperties &prop) { m_digging_properties[toolname] = prop; } - DiggingProperties getDiggingProperties(const std::string toolname) + DiggingProperties get(const std::string toolname) { core::map::Node *n; n = m_digging_properties.find(toolname); @@ -80,16 +85,17 @@ public: return n->getValue(); } + void clear() + { + m_digging_properties.clear(); + } + private: // toolname="": default properties (digging by hand) // Key is toolname core::map m_digging_properties; }; -void initializeMaterialProperties(); - -// Material correspond to the CONTENT_* constants -MaterialProperties * getMaterialProperties(u8 material); // For getting the default properties, set tool="" DiggingProperties getDiggingProperties(u8 material, const std::string &tool); diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index 6822173c..1fc4c93a 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "exceptions.h" #include "inventory.h" #include +#include "content_mapnode.h" /* NodeMetadata diff --git a/src/server.cpp b/src/server.cpp index 16ad80c0..70448fbf 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "config.h" #include "servercommand.h" #include "filesys.h" +#include "content_mapnode.h" #define BLOCK_EMERGE_FLAG_FROMDISK (1<<0) diff --git a/src/servermain.cpp b/src/servermain.cpp index 907d0d2d..6eb45ea2 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) DSTACK(__FUNCTION_NAME); // Init material properties table - initializeMaterialProperties(); + //initializeMaterialProperties(); // Debug handler BEGIN_DEBUG_EXCEPTION_HANDLER diff --git a/src/test.cpp b/src/test.cpp index 07ef772e..38497136 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "voxel.h" #include #include "porting.h" +#include "content_mapnode.h" /* Asserts that the exception occurs diff --git a/src/voxel.cpp b/src/voxel.cpp index f60b641f..5938f901 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -19,10 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "voxel.h" #include "map.h" - -// For TimeTaker -#include "utility.h" +#include "utility.h" // For TimeTaker #include "gettime.h" +#include "content_mapnode.h" /* Debug stuff -- 2.30.2