From 63611932ebae93620386b26cfa82f7c4552b22ff Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 29 May 2011 21:11:16 +0300 Subject: player passwords and privileges in world/auth.txt --HG-- extra : rebase_source : 7260636295d9068fbeeddf4143c89f2b8a91446c --- minetest.conf.example | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'minetest.conf.example') diff --git a/minetest.conf.example b/minetest.conf.example index acdc19b0a..5e6393228 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -102,6 +102,11 @@ #enable_damage = false +#default_password = + +# Available privileges: build, teleport, settime, privs, shout +#default_privs = build, shout + # Gives some stuff to players at the beginning #give_initial_stuff = false -- cgit v1.2.3 From 9f7c21a0b48285fe03bef1060557f6e75976d625 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 29 May 2011 21:13:29 +0300 Subject: invert_mouse config option --HG-- extra : rebase_source : 2695ad71185244cefbcf6e3e28ba1ab5e54c882f --- doc/changelog.txt | 1 + minetest.conf.example | 2 ++ src/defaultsettings.cpp | 1 + src/game.cpp | 4 ++++ 4 files changed, 8 insertions(+) (limited to 'minetest.conf.example') diff --git a/doc/changelog.txt b/doc/changelog.txt index cb3594a98..e886370a6 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -14,6 +14,7 @@ X: - Player passwords - All textures first searched from texture_path - Map directory ("map") has been renamed to "world" (just rename it to load an old world) +- Mouse inversion (invert_mouse) 2011-04-24: - Smooth lighting with simple ambient occlusion diff --git a/minetest.conf.example b/minetest.conf.example index 5e6393228..1a1dbe0fc 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -42,6 +42,8 @@ #keymap_special1 = KEY_KEY_E #keymap_print_debug_stacks = KEY_KEY_P +#invert_mouse = false + # The desired FPS #wanted_fps = 30 diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 1d758a2a4..6fcdc1dbb 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -65,6 +65,7 @@ void set_default_settings() g_settings.setDefault("free_move", "false"); g_settings.setDefault("continuous_forward", "false"); g_settings.setDefault("fast_move", "false"); + g_settings.setDefault("invert_mouse", "false"); // Server stuff g_settings.setDefault("enable_experimental", "false"); diff --git a/src/game.cpp b/src/game.cpp index cc758be7e..6932b45f1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -894,6 +894,8 @@ void the_game( core::list frametime_log; float damage_flash_timer = 0; + + bool invert_mouse = g_settings.getBool("invert_mouse"); /* Main loop @@ -1306,6 +1308,8 @@ void the_game( else{ s32 dx = input->getMousePos().X - displaycenter.X; s32 dy = input->getMousePos().Y - displaycenter.Y; + if(invert_mouse) + dy = -dy; //std::cout<<"window active, pos difference "< Date: Tue, 31 May 2011 00:15:43 +0300 Subject: Reduced the CPU usage of the sent block selector algorithm --- minetest.conf.example | 11 +-- src/defaultsettings.cpp | 3 +- src/game.cpp | 19 +++++ src/main.cpp | 33 ++++++++- src/main.h | 4 ++ src/map.cpp | 6 +- src/mapblock.cpp | 4 +- src/profiler.h | 131 ++++++++++++++++++++++++++++++++++ src/server.cpp | 185 +++++++++++++++++++++++++++++++++++++----------- src/server.h | 11 +++ src/utility.h | 3 + 11 files changed, 355 insertions(+), 55 deletions(-) create mode 100644 src/profiler.h (limited to 'minetest.conf.example') diff --git a/minetest.conf.example b/minetest.conf.example index 1a1dbe0fc..743186853 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -92,10 +92,6 @@ # Server side stuff # -# Set to true to enable experimental features -# (varies from version to version, see wiki) -#enable_experimental = false - # Map directory (everything in the world is stored here) #map-dir = /home/palle/custom_map @@ -112,6 +108,13 @@ # Gives some stuff to players at the beginning #give_initial_stuff = false +# Set to true to enable experimental features +# (varies from version to version, see wiki) +#enable_experimental = false + +# Profiler data print interval. 0 = disable. +#profiler_print_interval = 10 + # Player and object positions are sent at intervals specified by this #objectdata_inverval = 0.2 diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 6fcdc1dbb..73f22a7f7 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -74,12 +74,13 @@ void set_default_settings() g_settings.setDefault("give_initial_stuff", "false"); g_settings.setDefault("default_password", ""); g_settings.setDefault("default_privs", "build, shout"); + g_settings.setDefault("profiler_print_interval", "0"); g_settings.setDefault("objectdata_interval", "0.2"); g_settings.setDefault("active_object_range", "2"); g_settings.setDefault("max_simultaneous_block_sends_per_client", "1"); //g_settings.setDefault("max_simultaneous_block_sends_per_client", "2"); - g_settings.setDefault("max_simultaneous_block_sends_server_total", "4"); + g_settings.setDefault("max_simultaneous_block_sends_server_total", "8"); g_settings.setDefault("max_block_send_distance", "8"); g_settings.setDefault("max_block_generate_distance", "8"); g_settings.setDefault("time_send_interval", "20"); diff --git a/src/game.cpp b/src/game.cpp index 6932b45f1..e8e6cb71f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -903,6 +903,10 @@ void the_game( bool first_loop_after_window_activation = true; + // TODO: Convert the static interval timers to these + // Interval limiter for profiler + IntervalLimiter m_profiler_interval; + // Time is in milliseconds // NOTE: getRealTime() causes strange problems in wine (imprecision?) // NOTE: So we have to use getTime() and call run()s between them @@ -1089,6 +1093,21 @@ void the_game( } } + /* + Profiler + */ + float profiler_print_interval = + g_settings.getFloat("profiler_print_interval"); + if(profiler_print_interval != 0) + { + if(m_profiler_interval.step(0.030, profiler_print_interval)) + { + dstream<<"Profiler:"< diff --git a/src/map.cpp b/src/map.cpp index a49de3c46..f9809e9fd 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -5692,9 +5692,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) p_nodes_min.Y / MAP_BLOCKSIZE - 1, p_nodes_min.Z / MAP_BLOCKSIZE - 1); v3s16 p_blocks_max( - p_nodes_max.X / MAP_BLOCKSIZE + 1, - p_nodes_max.Y / MAP_BLOCKSIZE + 1, - p_nodes_max.Z / MAP_BLOCKSIZE + 1); + p_nodes_max.X / MAP_BLOCKSIZE, + p_nodes_max.Y / MAP_BLOCKSIZE, + p_nodes_max.Z / MAP_BLOCKSIZE); u32 vertex_count = 0; diff --git a/src/mapblock.cpp b/src/mapblock.cpp index c448ef236..b2f972dde 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -540,10 +540,10 @@ void updateFastFaceRow( v3s16 p_next; - bool next_makes_face; + bool next_makes_face = false; v3s16 next_p_corrected; v3s16 next_face_dir_corrected; - u8 next_lights[4]; + u8 next_lights[4] = {0,0,0,0}; TileSpec next_tile; // If at last position, there is nothing to compare to and diff --git a/src/profiler.h b/src/profiler.h new file mode 100644 index 000000000..a30e34a7c --- /dev/null +++ b/src/profiler.h @@ -0,0 +1,131 @@ +/* +Minetest-c55 +Copyright (C) 2011 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef PROFILER_HEADER +#define PROFILER_HEADER + +#include "common_irrlicht.h" +#include +#include "utility.h" +#include +#include + +/* + Time profiler +*/ + +class Profiler +{ +public: + Profiler() + { + m_mutex.Init(); + } + + void add(const std::string &name, u32 duration) + { + JMutexAutoLock lock(m_mutex); + core::map::Node *n = m_data.find(name); + if(n == NULL) + { + m_data[name] = duration; + } + else + { + n->setValue(n->getValue()+duration); + } + } + + void clear() + { + JMutexAutoLock lock(m_mutex); + for(core::map::Iterator + i = m_data.getIterator(); + i.atEnd() == false; i++) + { + i.getNode()->setValue(0); + } + } + + void print(std::ostream &o) + { + JMutexAutoLock lock(m_mutex); + for(core::map::Iterator + i = m_data.getIterator(); + i.atEnd() == false; i++) + { + std::string name = i.getNode()->getKey(); + o<getValue(); + o< m_data; +}; + +class ScopeProfiler +{ +public: + ScopeProfiler(Profiler *profiler, const std::string &name): + m_profiler(profiler), + m_name(name), + m_timer(NULL) + { + if(m_profiler) + m_timer = new TimeTaker(m_name.c_str()); + } + // name is copied + ScopeProfiler(Profiler *profiler, const char *name): + m_profiler(profiler), + m_name(name), + m_timer(NULL) + { + if(m_profiler) + m_timer = new TimeTaker(m_name.c_str()); + } + ~ScopeProfiler() + { + if(m_timer) + { + u32 duration = m_timer->stop(true); + if(m_profiler) + m_profiler->add(m_name, duration); + delete m_timer; + } + } +private: + Profiler *m_profiler; + std::string m_name; + TimeTaker *m_timer; +}; + +#endif + diff --git a/src/server.cpp b/src/server.cpp index 56874c46c..6f1f1e6e8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -312,11 +312,14 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime, TimeTaker timer("RemoteClient::GetNextBlocks", &timer_result);*/ // Increment timers - m_nearest_unsent_reset_timer += dtime; m_nothing_to_send_pause_timer -= dtime; if(m_nothing_to_send_pause_timer >= 0) + { + // Keep this reset + m_nearest_unsent_reset_timer = 0; return; + } // Won't send anything if already sending if(m_blocks_sending.size() >= g_settings.getU16 @@ -326,14 +329,21 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime, return; } + //TimeTaker timer("RemoteClient::GetNextBlocks"); + Player *player = server->m_env.getPlayer(peer_id); assert(player != NULL); v3f playerpos = player->getPosition(); v3f playerspeed = player->getSpeed(); + v3f playerspeeddir(0,0,0); + if(playerspeed.getLength() > 1.0*BS) + playerspeeddir = playerspeed / playerspeed.getLength(); + // Predict to next block + v3f playerpos_predicted = playerpos + playerspeeddir*MAP_BLOCKSIZE*BS; - v3s16 center_nodepos = floatToInt(playerpos, BS); + v3s16 center_nodepos = floatToInt(playerpos_predicted, BS); v3s16 center = getNodeBlockPos(center_nodepos); @@ -344,6 +354,9 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime, camera_dir.rotateYZBy(player->getPitch()); camera_dir.rotateXZBy(player->getYaw()); + /*dstream<<"camera_dir=("<getPlayerName(peer_id)< d_start+1) + d_max = d_start+1; + /*if(d_max_gen > d_start+2) + d_max_gen = d_start+2;*/ + //dstream<<"Starting from "<= 3) + if((s16)m_nothing_to_send_counter >= + g_settings.getS16("max_block_send_distance")) { // Pause time in seconds - m_nothing_to_send_pause_timer = 2.0; + m_nothing_to_send_pause_timer = 1.0; + dstream<<"nothing to send to " + <getPlayerName(peer_id) + <<" (d="< modified_blocks; m_env.getMap().transformLiquids(modified_blocks); #if 0 @@ -1298,10 +1360,11 @@ void Server::AsyncRunStep() */ { //dstream<<"Server: Checking added and deleted active objects"<* > buffered_messages; @@ -1598,6 +1663,9 @@ void Server::AsyncRunStep() { JMutexAutoLock lock1(m_env_mutex); JMutexAutoLock lock2(m_con_mutex); + + ScopeProfiler sp(&g_profiler, "Server: sending mbo positions"); + SendObjectData(counter); counter = 0.0; @@ -1612,7 +1680,9 @@ void Server::AsyncRunStep() JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock conlock(m_con_mutex); - + + ScopeProfiler sp(&g_profiler, "Server: stepping node metadata"); + core::map changed_blocks; m_env.getMap().nodeMetadataStep(dtime, changed_blocks); @@ -1655,6 +1725,8 @@ void Server::AsyncRunStep() { counter = 0.0; + ScopeProfiler sp(&g_profiler, "Server: saving stuff"); + // Auth stuff m_authmanager.save(); @@ -3646,20 +3718,24 @@ void Server::SendBlocks(float dtime) core::array queue; s32 total_sending = 0; - - for(core::map::Iterator - i = m_clients.getIterator(); - i.atEnd() == false; i++) + { - RemoteClient *client = i.getNode()->getValue(); - assert(client->peer_id == i.getNode()->getKey()); + ScopeProfiler sp(&g_profiler, "Server: selecting blocks for sending"); - total_sending += client->SendingCount(); - - if(client->serialization_version == SER_FMT_VER_INVALID) - continue; - - client->GetNextBlocks(this, dtime, queue); + for(core::map::Iterator + i = m_clients.getIterator(); + i.atEnd() == false; i++) + { + RemoteClient *client = i.getNode()->getValue(); + assert(client->peer_id == i.getNode()->getKey()); + + total_sending += client->SendingCount(); + + if(client->serialization_version == SER_FMT_VER_INVALID) + continue; + + client->GetNextBlocks(this, dtime, queue); + } } // Sort. @@ -4531,25 +4607,48 @@ void dedicated_server_loop(Server &server, bool &kill) { DSTACK(__FUNCTION_NAME); - std::cout<PrintLine(&std::cout); + i->PrintLine(&dstream); } } sum_old = sum; diff --git a/src/server.h b/src/server.h index 7b73e476c..6bee10685 100644 --- a/src/server.h +++ b/src/server.h @@ -500,6 +500,15 @@ private: // When called, connection mutex should be locked RemoteClient* getClient(u16 peer_id); + // When called, environment mutex should be locked + std::string getPlayerName(u16 peer_id) + { + Player *player = m_env.getPlayer(peer_id); + if(player == NULL) + return "[id="+itos(peer_id); + return player->getName(); + } + /* Get a player from memory or creates one. If player is already connected, return NULL @@ -627,6 +636,8 @@ private: */ u16 m_ignore_map_edit_events_peer_id; + Profiler *m_profiler; + friend class EmergeThread; friend class RemoteClient; }; diff --git a/src/utility.h b/src/utility.h index f18d31278..534aea483 100644 --- a/src/utility.h +++ b/src/utility.h @@ -244,6 +244,9 @@ inline f32 readF1000(std::istream &is) { char buf[2]; is.read(buf, 2); + // TODO: verify if this gets rid of the valgrind warning + //if(is.gcount() != 2) + // return 0; return readF1000((u8*)buf); } -- cgit v1.2.3 From 72e742c24eb70fdf8aacb7d3043b6a1537ca14fb Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 7 Jun 2011 22:08:16 +0300 Subject: Added an experimental "far view" thing. Doesn't work exactly like it should and not suitable for real use yet, and might never be. --- minetest.conf.example | 6 ++ src/CMakeLists.txt | 1 + src/clouds.cpp | 2 +- src/defaultsettings.cpp | 3 +- src/farmesh.cpp | 253 ++++++++++++++++++++++++++++++++++++++++++++++++ src/farmesh.h | 84 ++++++++++++++++ src/game.cpp | 42 +++++++- 7 files changed, 386 insertions(+), 5 deletions(-) create mode 100644 src/farmesh.cpp create mode 100644 src/farmesh.h (limited to 'minetest.conf.example') diff --git a/minetest.conf.example b/minetest.conf.example index 743186853..6e8a82bac 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -58,6 +58,12 @@ # Whether to fog out the end of the visible area #enable_fog = true +# Enable/disable clouds +#enable_clouds = true + +# Experimental +#enable_farmesh = false + # Enable a bit lower water surface; disable for speed #new_style_water = true diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 367b38818..558c28027 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,6 +85,7 @@ set(common_SRCS # Client sources set(minetest_SRCS ${common_SRCS} + farmesh.cpp keycode.cpp clouds.cpp clientobject.cpp diff --git a/src/clouds.cpp b/src/clouds.cpp index 70d19fde5..122beedac 100644 --- a/src/clouds.cpp +++ b/src/clouds.cpp @@ -58,8 +58,8 @@ void Clouds::OnRegisterSceneNode() { if(IsVisible) { - SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); //SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); + SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); } ISceneNode::OnRegisterSceneNode(); diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 73f22a7f7..e57157a82 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -61,11 +61,12 @@ void set_default_settings() g_settings.setDefault("enable_texture_atlas", "true"); g_settings.setDefault("texture_path", ""); g_settings.setDefault("video_driver", "opengl"); - g_settings.setDefault("free_move", "false"); g_settings.setDefault("continuous_forward", "false"); g_settings.setDefault("fast_move", "false"); g_settings.setDefault("invert_mouse", "false"); + g_settings.setDefault("enable_farmesh", "false"); + g_settings.setDefault("enable_clouds", "true"); // Server stuff g_settings.setDefault("enable_experimental", "false"); diff --git a/src/farmesh.cpp b/src/farmesh.cpp new file mode 100644 index 000000000..e4847966f --- /dev/null +++ b/src/farmesh.cpp @@ -0,0 +1,253 @@ +/* +Part of Minetest-c55 +Copyright (C) 2011 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +/* + A quick messy implementation of terrain rendering for a long + distance according to map seed +*/ + +#include "farmesh.h" +#include "constants.h" +#include "debug.h" +#include "noise.h" +#include "map.h" + +FarMesh::FarMesh( + scene::ISceneNode* parent, + scene::ISceneManager* mgr, + s32 id, + u64 seed +): + scene::ISceneNode(parent, mgr, id), + m_seed(seed), + m_camera_pos(0,0), + m_time(0) +{ + dstream<<__FUNCTION_NAME<(-BS*1000000,-BS*31000,-BS*1000000, + BS*1000000,BS*31000,BS*1000000); + +} + +FarMesh::~FarMesh() +{ + dstream<<__FUNCTION_NAME<registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); + //SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); + SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX); + } + + ISceneNode::OnRegisterSceneNode(); +} + +#define MYROUND(x) (x > 0.0 ? (int)x : (int)x - 1) + +// Temporary hack +core::map g_heights; + +float ground_height(u64 seed, v2s16 p2d) +{ + core::map::Node *n = g_heights.find(p2d); + if(n) + return n->getValue(); + float avg_mud_amount = 4; + float gh = BS*base_rock_level_2d(seed, p2d) + avg_mud_amount*BS; + //gh *= 10; + g_heights[p2d] = gh; + return gh; +} + +void FarMesh::render() +{ + video::IVideoDriver* driver = SceneManager->getVideoDriver(); + + /*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT) + return;*/ + /*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID) + return;*/ + if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SKY_BOX) + return; + + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); + driver->setMaterial(m_material); + + const s16 grid_radius_i = 12; + const float grid_size = BS*50; + const v2f grid_speed(-BS*0, 0); + + // Position of grid noise origin in world coordinates + v2f world_grid_origin_pos_f(0,0); + // Position of grid noise origin from the camera + v2f grid_origin_from_camera_f = world_grid_origin_pos_f - m_camera_pos; + // The center point of drawing in the noise + v2f center_of_drawing_in_noise_f = -grid_origin_from_camera_f; + // The integer center point of drawing in the noise + v2s16 center_of_drawing_in_noise_i( + MYROUND(center_of_drawing_in_noise_f.X / grid_size), + MYROUND(center_of_drawing_in_noise_f.Y / grid_size) + ); + // The world position of the integer center point of drawing in the noise + v2f world_center_of_drawing_in_noise_f = v2f( + center_of_drawing_in_noise_i.X * grid_size, + center_of_drawing_in_noise_i.Y * grid_size + ) + world_grid_origin_pos_f; + + for(s16 zi=-grid_radius_i; zi h_max) + h_max = noise[i]; + } + float steepness = (h_max - h_min)/grid_size; + + float h_avg = (noise[0]+noise[1]+noise[2]+noise[3])/4.0; + float light_f = noise[0]+noise[1]-noise[2]-noise[3]; + light_f /= 100; + if(light_f < -1.0) light_f = -1.0; + if(light_f > 1.0) light_f = 1.0; + //light_f += 1.0; + //light_f /= 2.0; + + v2f p1 = p0 + v2f(1,1)*grid_size; + + video::SColor c; + // Detect water + if(h_avg < WATER_LEVEL*BS && h_max < (WATER_LEVEL+5)*BS) + { + c = video::SColor(128,59,86,146); + /*// Set to water level + for(u32 i=0; i<4; i++) + { + if(noise[i] < BS*WATER_LEVEL) + noise[i] = BS*WATER_LEVEL; + }*/ + light_f = 0; + } + else if(steepness > 2.0) + c = video::SColor(128,128,128,128); + else + c = video::SColor(128,107,134,51); + + // Set to water level + for(u32 i=0; i<4; i++) + { + if(noise[i] < BS*WATER_LEVEL) + noise[i] = BS*WATER_LEVEL; + } + + float b = m_brightness + light_f*0.1*m_brightness; + if(b < 0) b = 0; + if(b > 2) b = 2; + + c = video::SColor(128, b*c.getRed(), b*c.getGreen(), b*c.getBlue()); + + video::S3DVertex vertices[4] = + { + video::S3DVertex(p0.X,noise[0],p0.Y, 0,0,0, c, 0,1), + video::S3DVertex(p0.X,noise[1],p1.Y, 0,0,0, c, 1,1), + video::S3DVertex(p1.X,noise[2],p1.Y, 0,0,0, c, 1,0), + video::S3DVertex(p1.X,noise[3],p0.Y, 0,0,0, c, 0,0), + }; + u16 indices[] = {0,1,2,2,3,0}; + driver->drawVertexPrimitiveList(vertices, 4, indices, 2, + video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT); + } + + driver->clearZBuffer(); +} + +void FarMesh::step(float dtime) +{ + m_time += dtime; +} + +void FarMesh::update(v2f camera_p, float brightness) +{ + m_camera_pos = camera_p; + m_brightness = brightness; +} + diff --git a/src/farmesh.h b/src/farmesh.h new file mode 100644 index 000000000..12f587942 --- /dev/null +++ b/src/farmesh.h @@ -0,0 +1,84 @@ +/* +Part of Minetest-c55 +Copyright (C) 2010-2011 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef FARMESH_HEADER +#define FARMESH_HEADER + +/* + A quick messy implementation of terrain rendering for a long + distance according to map seed +*/ + +#include "common_irrlicht.h" + +class FarMesh : public scene::ISceneNode +{ +public: + FarMesh( + scene::ISceneNode* parent, + scene::ISceneManager* mgr, + s32 id, + u64 seed + ); + + ~FarMesh(); + + /* + ISceneNode methods + */ + + virtual void OnRegisterSceneNode(); + + virtual void render(); + + virtual const core::aabbox3d& getBoundingBox() const + { + return m_box; + } + + virtual u32 getMaterialCount() const + { + return 1; + } + + virtual video::SMaterial& getMaterial(u32 i) + { + return m_material; + } + + /* + Other stuff + */ + + void step(float dtime); + + void update(v2f camera_p, float brightness); + +private: + video::SMaterial m_material; + core::aabbox3d m_box; + float m_cloud_y; + float m_brightness; + u32 m_seed; + v2f m_camera_pos; + float m_time; +}; + +#endif + diff --git a/src/game.cpp b/src/game.cpp index e8e6cb71f..ef574c348 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "config.h" #include "clouds.h" #include "keycode.h" +#include "farmesh.h" /* Setting this to 1 enables a special camera mode that forces @@ -595,6 +596,10 @@ void update_skybox(video::IVideoDriver* driver, skybox->remove(); } + // Disable skybox if FarMesh is enabled + if(g_settings.getBool("enable_farmesh")) + return; + if(brightness >= 0.5) { skybox = smgr->addSkyBoxSceneNode( @@ -815,8 +820,21 @@ void the_game( float cloud_height = BS*100; Clouds *clouds = NULL; - clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, - cloud_height, time(0)); + if(g_settings.getBool("enable_clouds")) + { + clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, + cloud_height, time(0)); + } + + /* + FarMesh + */ + + FarMesh *farmesh = NULL; + if(g_settings.getBool("enable_farmesh")) + { + farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed()); + } /* Move into game @@ -1789,6 +1807,16 @@ void the_game( 0.05+brightness*0.95); } + /* + Update farmesh (TODO: Remove from here) + */ + if(farmesh) + { + farmesh->step(dtime); + farmesh->update(v2f(player_position.X, player_position.Z), + 0.05+brightness*0.95); + } + // Store brightness value old_brightness = brightness; @@ -1999,6 +2027,13 @@ void the_game( //driver->beginScene(false, true, bgcolor); beginscenetime = timer.stop(true); } + + /* + Draw farmesh before everything else + */ + { + //farmesh->render(); + } //timer3.stop(); @@ -2131,7 +2166,8 @@ void the_game( /* Drop stuff */ - clouds->drop(); + if(clouds) + clouds->drop(); /* Draw a "shutting down" screen, which will be shown while the map -- cgit v1.2.3