From ba762bcd49c9f3ffa3cc4ecac73b13365c2047ec Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 15 Nov 2011 21:00:39 +0200 Subject: Clean mapnode.h and fix other files accordingly --- src/client.h | 1 + src/content_cao.cpp | 1 + src/content_mapnode.cpp | 1 + src/content_nodemeta.cpp | 1 + src/content_sao.cpp | 1 + src/farmesh.cpp | 9 ++++---- src/inventory.cpp | 22 ++++++++++++++++++ src/inventory.h | 23 ++----------------- src/map.h | 1 + src/mapblock_mesh.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++-- src/mapnode.cpp | 56 +------------------------------------------- src/mapnode.h | 18 --------------- src/player.cpp | 5 ++++ src/player.h | 5 +--- src/server.h | 1 + 15 files changed, 101 insertions(+), 104 deletions(-) diff --git a/src/client.h b/src/client.h index 148acc072..b160a3bc9 100644 --- a/src/client.h +++ b/src/client.h @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct MeshMakeData; class IGameDef; +class IWritableTextureSource; class IWritableToolDefManager; class IWritableNodeDefManager; diff --git a/src/content_cao.cpp b/src/content_cao.cpp index c6ec0761a..bd99787c0 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "environment.h" #include "settings.h" #include +#include "serialization.h" // For decompressZlib core::map ClientActiveObject::m_types; diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 58eaff108..1ef3fe0d1 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapnode.h" #include "content_nodemeta.h" #include "nodedef.h" +#include "utility.h" #define WATER_ALPHA 160 diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index adaee33b4..50dcbd080 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventory.h" #include "content_mapnode.h" #include "log.h" +#include "utility.h" /* SignNodeMetadata diff --git a/src/content_sao.cpp b/src/content_sao.cpp index a7cee83ab..dc112275f 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include "main.h" // For g_profiler #include "profiler.h" +#include "serialization.h" // For compressZlib core::map ServerActiveObject::m_types; diff --git a/src/farmesh.cpp b/src/farmesh.cpp index 8f91e3a1a..fdc81057b 100644 --- a/src/farmesh.cpp +++ b/src/farmesh.cpp @@ -23,13 +23,15 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "farmesh.h" + #include "constants.h" #include "debug.h" #include "noise.h" #include "map.h" #include "client.h" +#include "tile.h" // ITextureSource -#include "mapgen.h" +#include "mapgen.h" // Shouldn't really be done this way FarMesh::FarMesh( scene::ISceneNode* parent, @@ -47,7 +49,7 @@ FarMesh::FarMesh( { dstream<<__FUNCTION_NAME<getVideoDriver(); + //video::IVideoDriver* driver = mgr->getVideoDriver(); m_materials[0].setFlag(video::EMF_LIGHTING, false); m_materials[0].setFlag(video::EMF_BACK_FACE_CULLING, true); @@ -62,8 +64,7 @@ FarMesh::FarMesh( m_materials[1].setFlag(video::EMF_BACK_FACE_CULLING, false); m_materials[1].setFlag(video::EMF_BILINEAR_FILTER, false); m_materials[1].setFlag(video::EMF_FOG_ENABLE, false); - m_materials[1].setTexture - (0, driver->getTexture(getTexturePath("treeprop.png").c_str())); + m_materials[1].setTexture(0, client->tsrc()->getTextureRaw("treeprop.png")); m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; m_materials[1].setFlag(video::EMF_FOG_ENABLE, true); diff --git a/src/inventory.cpp b/src/inventory.cpp index 8ddbd3ac8..1929761a5 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -800,6 +800,28 @@ static std::string describeC(const struct InventoryContext *c) return std::string("current_player=") + c->current_player->getName(); } +IMoveAction::IMoveAction(std::istream &is) +{ + std::string ts; + + std::getline(is, ts, ' '); + count = stoi(ts); + + std::getline(is, from_inv, ' '); + + std::getline(is, from_list, ' '); + + std::getline(is, ts, ' '); + from_i = stoi(ts); + + std::getline(is, to_inv, ' '); + + std::getline(is, to_list, ' '); + + std::getline(is, ts, ' '); + to_i = stoi(ts); +} + void IMoveAction::apply(InventoryContext *c, InventoryManager *mgr) { Inventory *inv_from = mgr->getInventory(c, from_inv); diff --git a/src/inventory.h b/src/inventory.h index 29b97ccad..5401ff1b9 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -520,27 +520,8 @@ struct IMoveAction : public InventoryAction from_i = -1; to_i = -1; } - IMoveAction(std::istream &is) - { - std::string ts; - - std::getline(is, ts, ' '); - count = stoi(ts); - - std::getline(is, from_inv, ' '); - - std::getline(is, from_list, ' '); - - std::getline(is, ts, ' '); - from_i = stoi(ts); - - std::getline(is, to_inv, ' '); - - std::getline(is, to_list, ' '); - - std::getline(is, ts, ' '); - to_i = stoi(ts); - } + + IMoveAction(std::istream &is); u16 getType() const { diff --git a/src/map.h b/src/map.h index 3def571b8..413a7fc05 100644 --- a/src/map.h +++ b/src/map.h @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock_nodemod.h" #include "constants.h" #include "voxel.h" +#include "utility.h" // Needed for UniqueQueue, a member of Map extern "C" { #include "sqlite3.h" diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 5d8c0b737..c051dda50 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tile.h" #include "gamedef.h" #include "content_mapblock.h" +#include "mineral.h" // For mineral_block_texture void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block) { @@ -249,6 +250,61 @@ static void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p, dest.push_back(face); } +static TileSpec getTile(const MapNode &node, v3s16 dir, + ITextureSource *tsrc, INodeDefManager *nodemgr) +{ + const ContentFeatures &f = nodemgr->get(node); + + if(f.param_type == CPT_FACEDIR_SIMPLE) + dir = facedir_rotate(node.param1, dir); + + TileSpec spec; + + s32 dir_i = -1; + + if(dir == v3s16(0,0,0)) + dir_i = -1; + else 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) + // Non-directional + spec = f.tiles[0]; + else + spec = f.tiles[dir_i]; + + /* + If it contains some mineral, change texture id + */ + if(f.param_type == CPT_MINERAL && tsrc) + { + u8 mineral = node.getMineral(nodemgr); + std::string mineral_texture_name = mineral_block_texture(mineral); + if(mineral_texture_name != "") + { + u32 orig_id = spec.texture.id; + std::string texture_name = tsrc->getTextureName(orig_id); + //texture_name += "^blit:"; + texture_name += "^"; + texture_name += mineral_texture_name; + u32 new_id = tsrc->getTextureId(texture_name); + spec.texture = tsrc->getTexture(new_id); + } + } + + return spec; +} + /* Gets node tile from any place relative to block. Returns TILE_NODE if doesn't exist or should not be drawn. @@ -257,7 +313,7 @@ static TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, NodeModMap &temp_mods, ITextureSource *tsrc, INodeDefManager *ndef) { TileSpec spec; - spec = mn.getTile(face_dir, tsrc, ndef); + spec = getTile(mn, face_dir, tsrc, ndef); /* Check temporary modifications on this node @@ -274,7 +330,7 @@ static TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, if(mod.type == NODEMOD_CHANGECONTENT) { MapNode mn2(mod.param); - spec = mn2.getTile(face_dir, tsrc, ndef); + spec = getTile(mn2, face_dir, tsrc, ndef); } if(mod.type == NODEMOD_CRACK) { diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 1e8915b03..2fbc81dd2 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 "main.h" // For g_settings #include "nodedef.h" #include "content_mapnode.h" // For mapnode_translate_*_internal +#include "serialization.h" // For ser_ver_supported #ifndef SERVER /* @@ -208,61 +209,6 @@ u8 MapNode::getLightBanksWithSource(INodeDefManager *nodemgr) const return (lightday&0x0f) | ((lightnight<<4)&0xf0); } -#ifndef SERVER -TileSpec MapNode::getTile(v3s16 dir, ITextureSource *tsrc, - INodeDefManager *nodemgr) const -{ - if(nodemgr->get(*this).param_type == CPT_FACEDIR_SIMPLE) - dir = facedir_rotate(param1, dir); - - TileSpec spec; - - s32 dir_i = -1; - - if(dir == v3s16(0,0,0)) - dir_i = -1; - else 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) - // Non-directional - spec = nodemgr->get(*this).tiles[0]; - else - spec = nodemgr->get(*this).tiles[dir_i]; - - /* - If it contains some mineral, change texture id - */ - if(nodemgr->get(*this).param_type == CPT_MINERAL && tsrc) - { - u8 mineral = getMineral(nodemgr); - std::string mineral_texture_name = mineral_block_texture(mineral); - if(mineral_texture_name != "") - { - u32 orig_id = spec.texture.id; - std::string texture_name = tsrc->getTextureName(orig_id); - //texture_name += "^blit:"; - texture_name += "^"; - texture_name += mineral_texture_name; - u32 new_id = tsrc->getTextureId(texture_name); - spec.texture = tsrc->getTexture(new_id); - } - } - - return spec; -} -#endif - u8 MapNode::getMineral(INodeDefManager *nodemgr) const { if(nodemgr->get(*this).param_type == CPT_MINERAL) diff --git a/src/mapnode.h b/src/mapnode.h index 7fe205463..12dbf45c5 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -20,14 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef MAPNODE_HEADER #define MAPNODE_HEADER -#include #include "irrlichttypes.h" #include "light.h" -#include "exceptions.h" -#include "serialization.h" -#ifndef SERVER -#include "tile.h" -#endif class INodeDefManager; @@ -215,18 +209,6 @@ struct MapNode return mix; }*/ - // In mapnode.cpp -#ifndef SERVER - /* - 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, ITextureSource *tsrc, - INodeDefManager *nodemgr) const; -#endif - /* Gets mineral content of node, if there is any. MINERAL_NONE if doesn't contain or isn't able to contain mineral. diff --git a/src/player.cpp b/src/player.cpp index 8e73f3501..4dc7ff219 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -108,6 +108,11 @@ void Player::accelerate(v3f target_speed, f32 max_increase) #endif } +v3s16 Player::getLightPosition() const +{ + return floatToInt(m_position + v3f(0,BS+BS/2,0), BS); +} + void Player::serialize(std::ostream &os) { // Utilize a Settings object for storing values diff --git a/src/player.h b/src/player.h index ecde59ce1..56bb5083c 100644 --- a/src/player.h +++ b/src/player.h @@ -62,10 +62,7 @@ public: return m_position; } - v3s16 getLightPosition() const - { - return floatToInt(m_position + v3f(0,BS+BS/2,0), BS); - } + v3s16 getLightPosition() const; v3f getEyeOffset() { diff --git a/src/server.h b/src/server.h index a8cdd1a85..4ba28e332 100644 --- a/src/server.h +++ b/src/server.h @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "auth.h" #include "ban.h" #include "gamedef.h" +#include "serialization.h" // For SER_FMT_VER_INVALID struct LuaState; typedef struct lua_State lua_State; class IWritableToolDefManager; -- cgit v1.2.3