Moved some mapnode content stuff from mapnode.{h,cpp} and digging property stuff from material.cpp to content_mapnode.{h,cpp}

master
Perttu Ahola 2011-06-17 22:20:15 +03:00
parent d6b54514bf
commit dc5319b6c9
18 changed files with 514 additions and 463 deletions

View File

@ -50,6 +50,7 @@ configure_file(
)
set(common_SRCS
content_mapnode.cpp
auth.cpp
collision.cpp
nodemetadata.cpp

351
src/content_mapnode.cpp Normal file
View File

@ -0,0 +1,351 @@
/*
Minetest-c55
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
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));
}

53
src/content_mapnode.h Normal file
View File

@ -0,0 +1,53 @@
/*
Minetest-c55
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
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

View File

@ -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():

View File

@ -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

View File

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream>
#include "main.h"
#include "serverobject.h"
#include "content_mapnode.h"
/*
InventoryItem

View File

@ -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();

View File

@ -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

View File

@ -24,6 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "light.h"
#include <sstream>
// TODO: Move content-aware mesh generation to a separate file
#include "content_mapnode.h"
#ifndef SERVER
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{

View File

@ -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"<<std::endl;
}
// Read some settings
/*// Read some settings
bool new_style_water = g_settings.getBool("new_style_water");
bool new_style_leaves = g_settings.getBool("new_style_leaves");
bool new_style_leaves = g_settings.getBool("new_style_leaves");*/
/*
Initialize content feature table
@ -131,247 +132,17 @@ void init_mapnode()
{
ContentFeatures *f = &g_content_features[i];
// Re-initialize
*f = ContentFeatures();
f->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";
/*
Initialize mapnode content
*/
content_mapnode_init();
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";
// 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<<std::endl;
/*for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
{
g_content_inventory_texture_paths[i] =
g_content_features[i].inventory_image_path.c_str();
}*/
}

View File

@ -27,6 +27,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "exceptions.h"
#include "serialization.h"
#include "tile.h"
#include "materials.h"
/*
Naming scheme:
- Material = irrlicht's Material class
- Content = (u8) content of a node
- Tile = TileSpec at some side of a node of some content type
*/
/*
Initializes all kind of stuff in here.
@ -42,13 +50,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
void init_mapnode();
// Initializes g_content_inventory_texture_paths
void init_content_inventory_texture_paths();
// NOTE: This is not used appropriately everywhere.
#define MATERIALS_COUNT 256
/*
Ignored node.
@ -67,41 +68,6 @@ void init_content_inventory_texture_paths();
*/
#define CONTENT_AIR 254
/*
Suggested materials:
- Gravel
- Sand
New naming scheme:
- Material = irrlicht's Material class
- Content = (u8) content of a node
- Tile = (u16) Material ID at some side of a node
*/
#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
/*
Content feature list
*/
@ -173,10 +139,20 @@ struct ContentFeatures
// Initial metadata is cloned from this
NodeMetadata *initial_metadata;
// If the content is liquid, this is the flowing version of the liquid.
// If content is liquid, this is the same content.
u8 liquid_alternative_flowing;
// Amount of light the node emits
u8 light_source;
// Digging properties for different tools
DiggingPropertiesList digging_properties;
// NOTE: Move relevant properties to here from elsewhere
//TODO: Move more properties here
ContentFeatures()
void reset()
{
translate_to = NULL;
param_type = CPT_NONE;
@ -194,6 +170,14 @@ struct ContentFeatures
air_equivalent = false;
dug_item = "";
initial_metadata = NULL;
liquid_alternative_flowing = CONTENT_IGNORE;
light_source = 0;
digging_properties.clear();
}
ContentFeatures()
{
reset();
}
~ContentFeatures();
@ -235,6 +219,11 @@ struct ContentFeatures
*/
ContentFeatures & content_features(u8 i);
/*
Here is a bunch of DEPRECATED functions.
*/
/*
If true, the material allows light propagation and brightness is stored
in param.
@ -243,9 +232,7 @@ ContentFeatures & content_features(u8 i);
inline bool light_propagates_content(u8 m)
{
return content_features(m).light_propagates;
//return (m == CONTENT_AIR || m == CONTENT_TORCH || m == CONTENT_WATER || m == CONTENT_WATERSOURCE);
}
/*
If true, the material allows lossless sunlight propagation.
NOTE: It doesn't seem to go through torches regardlessly of this
@ -254,9 +241,7 @@ inline bool light_propagates_content(u8 m)
inline bool sunlight_propagates_content(u8 m)
{
return content_features(m).sunlight_propagates;
//return (m == CONTENT_AIR || m == CONTENT_TORCH);
}
/*
On a node-node surface, the material of the node with higher solidness
is used for drawing.
@ -268,83 +253,54 @@ inline bool sunlight_propagates_content(u8 m)
inline u8 content_solidness(u8 m)
{
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;
if(m == CONTENT_WATER || m == CONTENT_WATERSOURCE)
return 1;
return 2;*/
}
// Objects collide with walkable contents
// NOTE: Don't use, use "content_features(m).whatever" instead
inline bool content_walkable(u8 m)
{
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 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 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 content_features(m).liquid_type == LIQUID_SOURCE;
//return (m == CONTENT_WATERSOURCE);
}
// CONTENT_WATER || CONTENT_WATERSOURCE -> 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)

View File

@ -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)
DiggingPropertiesList * getDiggingPropertiesList(u8 content)
{
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));*/
return &content_features(content).digging_properties;
}
void setDirtLikeDiggingProperties(u8 material, float toughness)
DiggingProperties getDiggingProperties(u8 content, const std::string &tool)
{
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; i<MATERIAL_PROPERTIES_COUNT; i++)
{
g_material_properties[i].setDiggingProperties("MesePick",
DiggingProperties(true, 0.0, 65535./1337));
}
g_material_properties_initialized = true;
}
MaterialProperties * getMaterialProperties(u8 material)
{
assert(g_material_properties_initialized);
return &g_material_properties[material];
}
DiggingProperties getDiggingProperties(u8 material, const std::string &tool)
{
MaterialProperties *mprop = getMaterialProperties(material);
DiggingPropertiesList *mprop = getDiggingPropertiesList(content);
if(mprop == NULL)
// Not diggable
return DiggingProperties();
return mprop->getDiggingProperties(tool);
return mprop->get(tool);
}

View File

@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "common_irrlicht.h"
#include "inventory.h"
#include <string>
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<std::string, DiggingProperties>::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<std::string, DiggingProperties> 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);

View File

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "exceptions.h"
#include "inventory.h"
#include <sstream>
#include "content_mapnode.h"
/*
NodeMetadata

View File

@ -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)

View File

@ -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

View File

@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "voxel.h"
#include <sstream>
#include "porting.h"
#include "content_mapnode.h"
/*
Asserts that the exception occurs

View File

@ -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