1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-23 08:08:47 -05:00

Add Client::getEnv() and remove some unnecessary wrappers

This commit is contained in:
Perttu Ahola 2012-03-15 23:54:10 +02:00
parent 81385682c8
commit 54917e3062
3 changed files with 17 additions and 66 deletions

View File

@ -1848,8 +1848,6 @@ void Client::sendPlayerItem(u16 item)
void Client::removeNode(v3s16 p)
{
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
core::map<v3s16, MapBlock*> 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<v3s16, MapBlock*> modified_blocks;
@ -1889,8 +1885,6 @@ void Client::addNode(v3s16 p, MapNode n)
catch(InvalidPositionException &e)
{}
//TimeTaker timer2("Client::addNode(): addUpdateMeshTaskWithEdge");
for(core::map<v3s16, MapBlock * >::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

View File

@ -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<u8> 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);

View File

@ -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();
}
/*