Removed unused camera_position and camera_direction fields from Client. Moved ClientEnvironment::drawPostFx to ClientMap::renderPostFx -- this will make the camera management classes easier to write, as ClientMap already knows the camera position but ClientEnvironment doesn't and has to be told about it. This also eliminates the need for Client::getEnv(). Made the post effect color a content feature defined in content_mapnode.h.

master
Kahrl 2011-09-07 19:21:28 +02:00
parent d28ea57083
commit c0b35fa429
9 changed files with 61 additions and 53 deletions

View File

@ -189,8 +189,6 @@ Client::Client(
),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_device(device),
camera_position(0,0,0),
camera_direction(0,0,1),
m_server_ser_ver(SER_FMT_VER_INVALID),
m_inventory_updated(false),
m_time_of_day(0),
@ -1983,8 +1981,11 @@ void Client::addNode(v3s16 p, MapNode n)
void Client::updateCamera(v3f pos, v3f dir)
{
m_env.getClientMap().updateCamera(pos, dir);
camera_position = pos;
camera_direction = dir;
}
void Client::renderPostFx()
{
m_env.getClientMap().renderPostFx();
}
MapNode Client::getNode(v3s16 p)
@ -1998,6 +1999,11 @@ NodeMetadata* Client::getNodeMetadata(v3s16 p)
return m_env.getMap().getNodeMetadata(p);
}
LocalPlayer* Client::getLocalPlayer()
{
return m_env.getLocalPlayer();
}
v3f Client::getPlayerPosition(v3f *eye_position)
{
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out

View File

@ -201,14 +201,16 @@ public:
void updateCamera(v3f pos, v3f dir);
void renderPostFx();
// Returns InvalidPositionException if not found
MapNode getNode(v3s16 p);
// Wrapper to Map
NodeMetadata* getNodeMetadata(v3s16 p);
// Get the player position, and optionally put the
// eye position in *eye_position
v3f getPlayerPosition(v3f *eye_position=NULL);
LocalPlayer* getLocalPlayer();
v3f getPlayerPosition(v3f *eye_position);
void setPlayerControl(PlayerControl &control);
@ -302,15 +304,6 @@ public:
{
return m_access_denied_reason;
}
/*
This should only be used for calling the special drawing stuff in
ClientEnvironment
*/
ClientEnvironment * getEnv()
{
return &m_env;
}
private:
@ -342,9 +335,6 @@ private:
IrrlichtDevice *m_device;
v3f camera_position;
v3f camera_direction;
// Server serialization version
u8 m_server_ser_ver;

View File

@ -385,6 +385,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_WATERSOURCE;
f->liquid_viscosity = WATER_VISC;
f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200);
if(f->special_material == NULL && g_texturesource)
{
// Flowing water material
@ -433,6 +434,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_WATERSOURCE;
f->liquid_viscosity = WATER_VISC;
f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200);
if(f->special_material == NULL && g_texturesource)
{
// Flowing water material
@ -465,6 +467,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_LAVASOURCE;
f->liquid_viscosity = LAVA_VISC;
f->damage_per_second = 4*2;
f->post_effect_color = video::SColor(192, 255, 64, 0);
if(f->special_material == NULL && g_texturesource)
{
// Flowing lava material
@ -514,6 +517,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_LAVASOURCE;
f->liquid_viscosity = LAVA_VISC;
f->damage_per_second = 4*2;
f->post_effect_color = video::SColor(192, 255, 64, 0);
if(f->special_material == NULL && g_texturesource)
{
// Flowing lava material

View File

@ -1940,29 +1940,6 @@ ClientEnvEvent ClientEnvironment::getClientEvent()
return m_client_event_queue.pop_front();
}
void ClientEnvironment::drawPostFx(video::IVideoDriver* driver, v3f camera_pos)
{
/*LocalPlayer *player = getLocalPlayer();
assert(player);
v3f pos_f = player->getPosition() + v3f(0,BS*1.625,0);*/
v3f pos_f = camera_pos;
v3s16 p_nodes = floatToInt(pos_f, BS);
MapNode n = m_map->getNodeNoEx(p_nodes);
if(n.getContent() == CONTENT_WATER || n.getContent() == CONTENT_WATERSOURCE)
{
v2u32 ss = driver->getScreenSize();
core::rect<s32> rect(0,0, ss.X, ss.Y);
driver->draw2DRectangle(video::SColor(64, 100, 100, 200), rect);
}
else if(content_features(n).solidness == 2 &&
g_settings.getBool("free_move") == false)
{
v2u32 ss = driver->getScreenSize();
core::rect<s32> rect(0,0, ss.X, ss.Y);
driver->draw2DRectangle(video::SColor(255, 0, 0, 0), rect);
}
}
#endif // #ifndef SERVER

View File

@ -406,9 +406,6 @@ public:
// Get event from queue. CEE_NONE is returned if queue is empty.
ClientEnvEvent getClientEvent();
// Post effects
void drawPostFx(video::IVideoDriver* driver, v3f camera_pos);
private:
ClientMap *m_map;

View File

@ -2032,7 +2032,7 @@ void the_game(
update_skybox(driver, smgr, skybox, brightness);
/*
Update coulds
Update clouds
*/
if(clouds)
{
@ -2313,6 +2313,13 @@ void the_game(
driver->draw3DBox(*i, video::SColor(255,0,0,0));
}
/*
Post effects
*/
{
client.renderPostFx();
}
/*
Frametime log
*/
@ -2352,13 +2359,6 @@ void the_game(
// 0-1ms
guienv->drawAll();
/*
Environment post fx
*/
{
client.getEnv()->drawPostFx(driver, camera_position);
}
/*
Draw hotbar
*/

View File

@ -3925,6 +3925,35 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
<<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
}
void ClientMap::renderPostFx()
{
// Sadly ISceneManager has no "post effects" render pass, in that case we
// could just register for that and handle it in renderMap().
m_camera_mutex.Lock();
v3f camera_position = m_camera_position;
m_camera_mutex.Unlock();
MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
// - If the player is in a solid node, make everything black.
// - If the player is in liquid, draw a semi-transparent overlay.
ContentFeatures& features = content_features(n);
video::SColor post_effect_color = features.post_effect_color;
if(features.solidness == 2 && g_settings.getBool("free_move") == false)
{
post_effect_color = video::SColor(255, 0, 0, 0);
}
if (post_effect_color.getAlpha() != 0)
{
// Draw a full-screen rectangle
video::IVideoDriver* driver = SceneManager->getVideoDriver();
v2u32 ss = driver->getScreenSize();
core::rect<s32> rect(0,0, ss.X, ss.Y);
driver->draw2DRectangle(post_effect_color, rect);
}
}
bool ClientMap::setTempMod(v3s16 p, NodeMod mod,
core::map<v3s16, MapBlock*> *affected_blocks)
{

View File

@ -552,6 +552,8 @@ public:
void renderMap(video::IVideoDriver* driver, s32 pass);
void renderPostFx();
/*
Methods for setting temporary modifications to nodes for
drawing.

View File

@ -160,6 +160,8 @@ struct ContentFeatures
u8 liquid_viscosity;
// Used currently for flowing liquids
u8 vertex_alpha;
// Post effect color, drawn when the camera is inside the node.
video::SColor post_effect_color;
// Special irrlicht material, used sometimes
video::SMaterial *special_material;
AtlasPointer *special_atlas;
@ -197,6 +199,7 @@ struct ContentFeatures
liquid_alternative_source = CONTENT_IGNORE;
liquid_viscosity = 0;
vertex_alpha = 255;
post_effect_color = video::SColor(0, 0, 0, 0);
special_material = NULL;
special_atlas = NULL;
light_source = 0;