From 54917e306256d4d39b95335986fce93b8c56a6e3 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 15 Mar 2012 23:54:10 +0200 Subject: [PATCH] Add Client::getEnv() and remove some unnecessary wrappers --- src/client.cpp | 32 -------------------------------- src/client.h | 25 +++++-------------------- src/game.cpp | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 66 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 203a905b..17b24c15 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1848,8 +1848,6 @@ void Client::sendPlayerItem(u16 item) void Client::removeNode(v3s16 p) { - //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - core::map modified_blocks; try @@ -1875,8 +1873,6 @@ void Client::removeNode(v3s16 p) void Client::addNode(v3s16 p, MapNode n) { - //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - TimeTaker timer1("Client::addNode()"); core::map modified_blocks; @@ -1889,8 +1885,6 @@ void Client::addNode(v3s16 p, MapNode n) catch(InvalidPositionException &e) {} - //TimeTaker timer2("Client::addNode(): addUpdateMeshTaskWithEdge"); - for(core::map::Iterator i = modified_blocks.getIterator(); i.atEnd() == false; i++) @@ -1900,32 +1894,6 @@ void Client::addNode(v3s16 p, MapNode n) } } -void Client::updateCamera(v3f pos, v3f dir, f32 fov) -{ - m_env.getClientMap().updateCamera(pos, dir, fov); -} - -void Client::renderPostFx() -{ - m_env.getClientMap().renderPostFx(); -} - -MapNode Client::getNode(v3s16 p) -{ - //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - return m_env.getMap().getNode(p); -} - -NodeMetadata* Client::getNodeMetadata(v3s16 p) -{ - return m_env.getMap().getNodeMetadata(p); -} - -LocalPlayer* Client::getLocalPlayer() -{ - return m_env.getLocalPlayer(); -} - void Client::setPlayerControl(PlayerControl &control) { //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out diff --git a/src/client.h b/src/client.h index ea377689..a71d965c 100644 --- a/src/client.h +++ b/src/client.h @@ -42,6 +42,7 @@ class IWritableTextureSource; class IWritableItemDefManager; class IWritableNodeDefManager; //class IWritableCraftDefManager; +class ClientEnvironment; class ClientNotReadyException : public BaseException { @@ -197,19 +198,12 @@ public: */ void step(float dtime); - // Called from updater thread - // Returns dtime - //float asyncStep(); - void ProcessData(u8 *data, u32 datasize, u16 sender_peer_id); // Returns true if something was received bool AsyncProcessPacket(); bool AsyncProcessData(); void Send(u16 channelnum, SharedBuffer data, bool reliable); - // Pops out a packet from the packet queue - //IncomingPacket getPacket(); - void interact(u8 action, const PointedThing& pointed); void sendSignNodeText(v3s16 p, std::string text); @@ -219,23 +213,14 @@ public: const std::wstring newpassword); void sendDamage(u8 damage); void sendRespawn(); + + ClientEnvironment& getEnv() + { return m_env; } - // locks envlock + // Causes urgent mesh updates (unlike Map::add/removeNodeWithEvent) void removeNode(v3s16 p); - // locks envlock void addNode(v3s16 p, MapNode n); - void updateCamera(v3f pos, v3f dir, f32 fov); - - void renderPostFx(); - - // Returns InvalidPositionException if not found - MapNode getNode(v3s16 p); - // Wrapper to Map - NodeMetadata* getNodeMetadata(v3s16 p); - - LocalPlayer* getLocalPlayer(); - void setPlayerControl(PlayerControl &control); void selectPlayerItem(u16 item); diff --git a/src/game.cpp b/src/game.cpp index b1cc0bfe..09b1a396 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -284,6 +284,7 @@ PointedThing getPointedThing(Client *client, v3f player_position, selected_object = NULL; INodeDefManager *nodedef = client->getNodeDefManager(); + ClientMap &map = client->getEnv().getClientMap(); // First try to find a pointed at active object if(look_for_object) @@ -337,7 +338,7 @@ PointedThing getPointedThing(Client *client, v3f player_position, MapNode n; try { - n = client->getNode(v3s16(x,y,z)); + n = map.getNode(v3s16(x,y,z)); } catch(InvalidPositionException &e) { @@ -1818,7 +1819,7 @@ void the_game( Update camera */ - LocalPlayer* player = client.getLocalPlayer(); + LocalPlayer* player = client.getEnv().getLocalPlayer(); float full_punch_interval = playeritem_toolcap.full_punch_interval; float tool_reload_ratio = time_from_last_punch / full_punch_interval; tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0); @@ -1831,7 +1832,7 @@ void the_game( f32 camera_fov = camera.getFovMax(); if(!disable_camera_update){ - client.updateCamera(camera_position, + client.getEnv().getClientMap().updateCamera(camera_position, camera_direction, camera_fov); } @@ -1929,15 +1930,13 @@ void the_game( /* Check information text of node */ - - NodeMetadata *meta = client.getNodeMetadata(nodepos); - if(meta) - { + + ClientMap &map = client.getEnv().getClientMap(); + NodeMetadata *meta = map.getNodeMetadata(nodepos); + if(meta){ infotext = narrow_to_wide(meta->infoText()); - } - else - { - MapNode n = client.getNode(nodepos); + } else { + MapNode n = map.getNode(nodepos); if(nodedef->get(n).tname_tiles[0] == "unknown_block.png"){ infotext = L"Unknown node: "; infotext += narrow_to_wide(nodedef->get(n).name); @@ -1948,7 +1947,6 @@ void the_game( Handle digging */ - if(nodig_delay_timer <= 0.0 && input->getLeftState()) { if(!digging) @@ -1958,7 +1956,7 @@ void the_game( digging = true; ldown_for_dig = true; } - MapNode n = client.getNode(nodepos); + MapNode n = client.getEnv().getClientMap().getNode(nodepos); // Get digging parameters DigParams params = getDigParams(nodedef->get(n).groups, @@ -2501,7 +2499,7 @@ void the_game( Post effects */ { - client.renderPostFx(); + client.getEnv().getClientMap().renderPostFx(); } /* -- 2.30.2