From c0b35fa429c68b49b2d6a5124aff6dcc31400b63 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Wed, 7 Sep 2011 19:21:28 +0200 Subject: [PATCH] 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. --- src/client.cpp | 14 ++++++++++---- src/client.h | 20 +++++--------------- src/content_mapnode.cpp | 4 ++++ src/environment.cpp | 23 ----------------------- src/environment.h | 3 --- src/game.cpp | 16 ++++++++-------- src/map.cpp | 29 +++++++++++++++++++++++++++++ src/map.h | 2 ++ src/mapnode.h | 3 +++ 9 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index a5ed6f61b..df792d116 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -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 diff --git a/src/client.h b/src/client.h index 1a7ef924a..9c942ff9a 100644 --- a/src/client.h +++ b/src/client.h @@ -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; diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 51f2f9736..89171755e 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -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 diff --git a/src/environment.cpp b/src/environment.cpp index 8103b7110..80f41f9fd 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -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 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 rect(0,0, ss.X, ss.Y); - driver->draw2DRectangle(video::SColor(255, 0, 0, 0), rect); - } -} - #endif // #ifndef SERVER diff --git a/src/environment.h b/src/environment.h index d9248d2ad..055e2b1f6 100644 --- a/src/environment.h +++ b/src/environment.h @@ -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; diff --git a/src/game.cpp b/src/game.cpp index dc3ed2456..afe1ce80f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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 */ diff --git a/src/map.cpp b/src/map.cpp index 7de79c75d..6f22498fe 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3925,6 +3925,35 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) <<", rendered "<getVideoDriver(); + v2u32 ss = driver->getScreenSize(); + core::rect rect(0,0, ss.X, ss.Y); + driver->draw2DRectangle(post_effect_color, rect); + } +} + bool ClientMap::setTempMod(v3s16 p, NodeMod mod, core::map *affected_blocks) { diff --git a/src/map.h b/src/map.h index e0b67eb6e..5bea4a137 100644 --- a/src/map.h +++ b/src/map.h @@ -552,6 +552,8 @@ public: void renderMap(video::IVideoDriver* driver, s32 pass); + void renderPostFx(); + /* Methods for setting temporary modifications to nodes for drawing. diff --git a/src/mapnode.h b/src/mapnode.h index 3ad67aaf6..19dfb2802 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -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; -- 2.25.1