From 4ba5cd580d86710b54f4b523db4e8710fb56fdb6 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 26 Dec 2010 13:33:20 +0200 Subject: drawing range updater update and myrand() (but not usage of it) --- src/client.cpp | 9 +--- src/client.h | 4 +- src/main.cpp | 120 ++++++++++++++++++++++++++--------------------------- src/map.cpp | 50 ++++++++++------------ src/map.h | 35 ++++++++++++---- src/servermain.cpp | 1 + src/utility.cpp | 14 +++++++ src/utility.h | 5 +++ 8 files changed, 131 insertions(+), 107 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index d43b97a3c..af2b375f4 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -66,14 +66,9 @@ void * ClientUpdateThread::Thread() Client::Client( IrrlichtDevice *device, const char *playername, - JMutex &range_mutex, - float &viewing_range_nodes, - bool &viewing_range_all): + MapDrawControl &control): m_thread(this), - m_env(new ClientMap(this, - range_mutex, - viewing_range_nodes, - viewing_range_all, + m_env(new ClientMap(this, control, device->getSceneManager()->getRootSceneNode(), device->getSceneManager(), 666), dout_client), diff --git a/src/client.h b/src/client.h index e48c8ec69..c56b615cb 100644 --- a/src/client.h +++ b/src/client.h @@ -110,9 +110,7 @@ public: Client( IrrlichtDevice *device, const char *playername, - JMutex &range_mutex, - float &viewing_range_nodes, - bool &viewing_range_all + MapDrawControl &control ); ~Client(); diff --git a/src/main.cpp b/src/main.cpp index b7a1b6b32..2f22caeb0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -253,25 +253,7 @@ TODO: Fix viewing range updater's oscillation when there is large non- IrrlichtWrapper *g_irrlicht; -// All range-related stuff below is locked behind this -JMutex g_range_mutex; - -// Blocks are viewed in this range from the player -float g_viewing_range_nodes = 60; -//s16 g_viewing_range_nodes = 0; - -// This is updated by the client's fetchBlocks routine -//s16 g_actual_viewing_range_nodes = VIEWING_RANGE_NODES_DEFAULT; - -// If true, the preceding value has no meaning and all blocks -// already existing in memory are drawn -bool g_viewing_range_all = false; - -// This is the freetime ratio imposed by the dynamic viewing -// range changing code. -// It is controlled by the main loop to the smallest value that -// inhibits glitches (dtime jitter) in the main loop. -//float g_freetime_ratio = FREETIME_RATIO_MAX; +MapDrawControl draw_control; /* Settings. @@ -455,15 +437,14 @@ public: // Viewing range selection if(event.KeyInput.Key == irr::KEY_KEY_R) { - JMutexAutoLock lock(g_range_mutex); - if(g_viewing_range_all) + if(draw_control.range_all) { - g_viewing_range_all = false; + draw_control.range_all = false; dstream< viewing_range_nodes_max) @@ -956,20 +937,20 @@ void updateViewingRange(f32 frametime, Client *client) bool can_change = true; - if(client->isFetchingBlocks() == true && n > g_viewing_range_nodes) + if(client->isFetchingBlocks() == true && n > draw_control.wanted_range) can_change = false; if(can_change) - g_viewing_range_nodes = n; + draw_control.wanted_range = n; - /*dstream<<"g_viewing_range_nodes = " - <setFog( @@ -2435,13 +2433,13 @@ int main(int argc, char *argv[]) wchar_t temptext[150]; static float drawtime_avg = 0; - drawtime_avg = drawtime_avg * 0.98 + (float)drawtime*0.02; + drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05; static float beginscenetime_avg = 0; - beginscenetime_avg = beginscenetime_avg * 0.98 + (float)beginscenetime*0.02; + beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05; static float scenetime_avg = 0; - scenetime_avg = scenetime_avg * 0.98 + (float)scenetime*0.02; + scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05; static float endscenetime_avg = 0; - endscenetime_avg = endscenetime_avg * 0.98 + (float)endscenetime*0.02; + endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05; swprintf(temptext, 150, L"Minetest-c55 (" L"F: item=%i" @@ -2449,7 +2447,7 @@ int main(int argc, char *argv[]) L")" L" drawtime=%.0f, beginscenetime=%.0f, scenetime=%.0f, endscenetime=%.0f", g_selected_item, - g_viewing_range_all, + draw_control.range_all, drawtime_avg, beginscenetime_avg, scenetime_avg, @@ -2472,7 +2470,7 @@ int main(int argc, char *argv[]) busytime_jitter1_min_sample, busytime_jitter1_max_sample, dtime_jitter1_max_fraction * 100.0, - g_viewing_range_nodes + draw_control.wanted_range ); guitext2->setText(temptext); diff --git a/src/map.cpp b/src/map.cpp index d5a61d408..b092e1fa5 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2889,9 +2889,7 @@ void ServerMap::PrintInfo(std::ostream &out) ClientMap::ClientMap( Client *client, - JMutex &range_mutex, - float &viewing_range_nodes, - bool &viewing_range_all, + MapDrawControl &control, scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id @@ -2900,9 +2898,7 @@ ClientMap::ClientMap( scene::ISceneNode(parent, mgr, id), m_client(client), mesh(NULL), - m_range_mutex(range_mutex), - m_viewing_range_nodes(viewing_range_nodes), - m_viewing_range_all(viewing_range_all) + m_control(control) { mesh_mutex.Init(); @@ -3003,24 +2999,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) */ int time1 = time(0); - //s32 daynight_i = m_client->getDayNightIndex(); u32 daynight_ratio = m_client->getDayNightRatio(); - /* - Collect all blocks that are in the view range - - Should not optimize more here as we want to auto-update - all changed nodes in viewing range at the next step. - */ - - float viewing_range_nodes; - bool viewing_range_all; - { - JMutexAutoLock lock(m_range_mutex); - viewing_range_nodes = m_viewing_range_nodes; - viewing_range_all = m_viewing_range_all; - } - m_camera_mutex.Lock(); v3f camera_position = m_camera_position; v3f camera_direction = m_camera_direction; @@ -3035,7 +3015,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) camera_position.Y / BS, camera_position.Z / BS); - v3s16 box_nodes_d = viewing_range_nodes * v3s16(1,1,1); + v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1); v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d; v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d; @@ -3054,12 +3034,14 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) // For limiting number of mesh updates per frame u32 mesh_update_count = 0; + + u32 blocks_would_have_drawn = 0; + u32 blocks_drawn = 0; //NOTE: The sectors map should be locked but we're not doing it // because it'd cause too much delays int timecheck_counter = 0; - core::map::Iterator si; si = m_sectors.getIterator(); for(; si.atEnd() == false; si++) @@ -3082,7 +3064,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) MapSector *sector = si.getNode()->getValue(); v2s16 sp = sector->getPos(); - if(viewing_range_all == false) + if(m_control.range_all == false) { if(sp.X < p_blocks_min.X || sp.X > p_blocks_max.X @@ -3126,12 +3108,12 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) // Total distance f32 d = blockpos_relative.getLength(); - if(viewing_range_all == false) + if(m_control.range_all == false) { // If block is far away, don't draw it - if(d > viewing_range_nodes * BS) + if(d > m_control.wanted_range * BS) // This is nicer when fog is used - //if((dforward+d)/2 > viewing_range_nodes * BS) + //if((dforward+d)/2 > m_control.wanted_range * BS) continue; } @@ -3175,7 +3157,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) } f32 faraway = BS*50; - //f32 faraway = viewing_range_nodes * BS; + //f32 faraway = m_control.wanted_range * BS; /* This has to be done with the mesh_mutex unlocked @@ -3217,6 +3199,13 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) if(mesh == NULL) continue; + + blocks_would_have_drawn++; + if(blocks_drawn >= m_control.wanted_max_blocks + && m_control.range_all == false + && d > m_control.wanted_min_range * BS) + continue; + blocks_drawn++; u32 c = mesh->getMeshBufferCount(); @@ -3238,6 +3227,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) } } // foreach sectorblocks } + + m_control.blocks_drawn = blocks_drawn; + m_control.blocks_would_have_drawn = blocks_would_have_drawn; /*dstream<<"renderMap(): is_transparent_pass="< > m_queue; }; +// Pseudo-random (VC++ rand() sucks) +int myrand(void); +void mysrand(unsigned seed); +#define MYRAND_MAX 32767 + #endif -- cgit v1.2.3