Skip to content

Commit

Permalink
Remove workaround in itemdef.cpp to enable/disable/enable "enable_sha…
Browse files Browse the repository at this point in the history
…ders" setting

* Increase performance (client)
* Avoid changing a global value to solve a local problem
  • Loading branch information
Zeno- committed Feb 11, 2015
1 parent cfca5f9 commit d25ff8f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Client::Client(
}

m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
m_cache_enable_shaders = g_settings->getBool("enable_shaders");
}

void Client::Stop()
Expand Down Expand Up @@ -2681,7 +2682,7 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
Create a task to update the mesh of the block
*/

MeshMakeData *data = new MeshMakeData(this);
MeshMakeData *data = new MeshMakeData(this, m_cache_enable_shaders);

{
//TimeTaker timer("data fill");
Expand Down
3 changes: 2 additions & 1 deletion src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
Database *localdb;
Server *localserver;

// TODO: Add callback to update this when g_settings changes
// TODO: Add callback to update these when g_settings changes
bool m_cache_smooth_lighting;
bool m_cache_enable_shaders;
};

#endif // !CLIENT_HEADER
11 changes: 1 addition & 10 deletions src/itemdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ class CItemDefManager: public IWritableItemDefManager

scene::IMesh *node_mesh = NULL;

bool reenable_shaders = false;

if (need_rtt_mesh || need_wield_mesh) {
u8 param1 = 0;
if (f.param_type == CPT_LIGHT)
Expand All @@ -372,11 +370,7 @@ class CItemDefManager: public IWritableItemDefManager
/*
Make a mesh from the node
*/
if (g_settings->getBool("enable_shaders")) {
reenable_shaders = true;
g_settings->setBool("enable_shaders", false);
}
MeshMakeData mesh_make_data(gamedef);
MeshMakeData mesh_make_data(gamedef, false);
u8 param2 = 0;
if (f.param_type_2 == CPT2_WALLMOUNTED)
param2 = 1;
Expand Down Expand Up @@ -443,9 +437,6 @@ class CItemDefManager: public IWritableItemDefManager

if (node_mesh)
node_mesh->drop();

if (reenable_shaders)
g_settings->setBool("enable_shaders",true);
}

// Put in cache
Expand Down
5 changes: 3 additions & 2 deletions src/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ static void applyFacesShading(video::SColor& color, float factor)
MeshMakeData
*/

MeshMakeData::MeshMakeData(IGameDef *gamedef):
MeshMakeData::MeshMakeData(IGameDef *gamedef, bool use_shaders):
m_vmanip(),
m_blockpos(-1337,-1337,-1337),
m_crack_pos_relative(-1337, -1337, -1337),
m_highlighted_pos_relative(-1337, -1337, -1337),
m_smooth_lighting(false),
m_show_hud(false),
m_highlight_mesh_color(255, 255, 255, 255),
m_gamedef(gamedef)
m_gamedef(gamedef),
m_use_shaders(use_shaders)
{}

void MeshMakeData::fill(MapBlock *block)
Expand Down
3 changes: 2 additions & 1 deletion src/mapblock_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ struct MeshMakeData
video::SColor m_highlight_mesh_color;

IGameDef *m_gamedef;
bool m_use_shaders;

MeshMakeData(IGameDef *gamedef);
MeshMakeData(IGameDef *gamedef, bool use_shaders);

/*
Copy central data directly from block, and other data from
Expand Down
4 changes: 3 additions & 1 deletion src/wieldmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef)
} else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES) {
setCube(f.tiles, def.wield_scale, tsrc);
} else {
MeshMakeData mesh_make_data(gamedef);
//// TODO: Change false in the following constructor args to
//// appropriate value when shader is added for wield items (if applicable)
MeshMakeData mesh_make_data(gamedef, false);
MapNode mesh_make_node(id, 255, 0);
mesh_make_data.fillSingleNode(&mesh_make_node);
MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
Expand Down

0 comments on commit d25ff8f

Please sign in to comment.