aboutsummaryrefslogtreecommitdiff
path: root/src/game.cpp
Commit message (Collapse)AuthorAge
* Autorun: Change to 'autoforward' (#5926)Paramat2017-06-08
| | | | | Minetest does not have 'run'. Automatic forwards is very often used while flying or swimming, so a general word is more suitable.
* Fix segmentation fault with tool capabilities (#5899)ShadowNinja2017-06-03
|
* Snake case for screen options in minetest.conf (#5792)Vincent Glize2017-06-03
|
* Close formspec on client shutdown. (#5811)red-0012017-05-25
| | | This ensures the shutting down progress bar is correctly rendered. This fixes #3050.
* Client crashfix: load meta after digging (#5801)Paramat2017-05-23
| | | | | | | Fixes a crash caused in MTGame by breaking and right-clicking a chest. If loading meta, digging, node can disappear and we looked at meta, which is wrong because meta became NULL. Pointer is invalidated and we read wrong memory area
* Fix instant digging (#5785)you2017-05-20
| | | | Use runData.dig_time_complete instead of params.time to find out whether it's instant digging. runData.dig_time_complete is set to something very big if the node can't be dug, whereas param.time is 0 when digging is impossible or it's instant digging. So not using param.time fixes #5728.
* When minimap is disabled in configuration, really disable it (#5771)Loïc Blot2017-05-19
| | | | * When minimap is disabled in configuration, really disable it
* No cursor lock when window inactive (#5754)SmallJoker2017-05-13
|
* Limit properly the sound setting at updateSound runtime step (#5753)Loïc Blot2017-05-13
| | | | | | | | * Limit properly the sound setting at updateSound runtime step Fix #5026 * Add a comment
* Move KeyList & InputHandler from game.h to client/inputhandler.h (#5752)Loïc Blot2017-05-13
| | | | | | | | | | * Move KeyList & InputHandler from game.h to client/inputhandler.h We have a header for inputs, move inputhandler class & related keylist object to it Also introduce a cpp file for MyEventReceiver::OnEvent function in inputhandler.h because a so huge function doesn't needs to be inlined * Pass clang-format on inputhandler.{cpp,h} (compatible)
* Android build fixLoic Blot2017-05-13
|
* Minor pause/escape menu improvements (#5751)red-0012017-05-13
| | | | | | - Split movement keys into separate entries. - Increase buffer size due to the above change. - Change capitalisation. - Remove code-style violating white spaces.
* Rework escape/pause menu (#5719)red-0012017-05-11
| | | | | | | | | | | | * Rework escape/pause menu - Remove build information - Use current controls instead of default controls - Add information about the current server in place of the build information - Add text saying the game is paused to if in singleplayer mode. rework pause/escape menu * improve consistency + display server_name
* Add configurable key bindings for hotbar scrolling, and for changing volume.Wuzzy2017-05-06
|
* [CSM] add `on_item_use` (#5544)red-0012017-05-06
|
* Make players respect makes_footstep_sound in the object propertiesTeTpaAka2017-05-06
|
* Save minetest screen width/height options when modified (#5683)Loïc Blot2017-05-05
| | | | | | | | * Save minetest screen width/height options when modified * Add autosave_screensize setting (default true) * Fix @SmallJoker comments
* Add function to get server info.red-0012017-05-04
|
* Set sky API: Add bool for clouds in front of custom skyboxparamat2017-05-02
| | | | | | | Default true. Add 'm_clouds_enabled' bool to sky.h, set from new bool in 'set sky' API. Make 'getCloudsVisible()' depend on 'm_clouds_enabled' instead of 'm_visible' (whether normal sky is visible).
* Add clouds APIBen Deutsch2017-04-30
|
* Client & ClientEnvirnment: don't create fake events (#5676)Loïc Blot2017-04-29
| | | | | | | Instead of create fake events on the stack on each loop call (Game::run), verify is queue is empty or not and handle event directly if there is. This prevents fake ClientEvent creation & memory allocations Same fix is also applied on ClientEnvironment, & rename getClientEvent to getClientEnvEvent to match ClientEnvEvent object
* [CSM] Add event on_place_node API lua (#5548)Vincent Glize2017-04-29
| | | | * [CSM] Add event on_place_node API lua
* Fix click-digging torches (#5652)you2017-04-28
| | | | Torches are dug instantly again. When the digging time is 0, a delay of 0.15 seconds is added between digging nodes. If the left mouse button is released, the delay is set to 0, thus click-digging.
* Search user path for sounds (#5657)Louis Pearson2017-04-27
|
* Rename Scripting API files for consistencyShadowNinja2017-04-25
|
* Fix various points reported by cppcheck (#5656)Loïc Blot2017-04-25
| | | | | | | | | | | | * Fix various performance issues reported by cppcheck + code style (CI) * Make CI happy with code style on master * guiFileSelectMenu: remove useless includes * some performance fixes pointed by cppcheck * remove some useless casts * TextDest: remove unused setFormSpec function * Fix various iterator post-increment reported by cppcheck
* Fix various copy instead of const ref reported by cppcheck (#5615)Loïc Blot2017-04-19
| | | | * Also remove InventoryList::peekItem unused function * Fix some post increment to preincrement reported by cppcheck
* Tools: Fix tool digging speed limitHybrid Dog2017-04-19
|
* Fix various variables passed by copy instead of const ref (#5610)Loïc Blot2017-04-19
| | | Pointed by cppcheck
* Android progressbar fix (#5601)Loïc Blot2017-04-16
| | | | | | | | | | | | | | | | | * Fix progressbar for Android Fixes #5599 Fixed #5403 * draw_load_screen: use texturesource this permits to unify texture loading code * scale progress bar * Add gl version check for GL_OES_texture_npot. This fixed the texture on loading screen * Remove two sanity checks pointed by @celeron55 * sfan5 comments + android ratio fixes
* Fix spacingEkdohibs2017-04-06
|
* Fix problems when overriding the hand:Ekdohibs2017-04-06
| | | | | - If the hand can dig a node the item wielded can't, allow to dig it anyway. - Fix the API callbacks from setting the hand instead of the wielded item.
* Show media download progress in percent on progress screen (#5498)orwell962017-04-07
|
* Change command prefix to "." and add "help" command.red-0012017-03-26
|
* Some performance optimizations (#5424)Loïc Blot2017-03-22
| | | | | | | | | | | | | | | | | | | * Some performance optimizations This is globally removing some memory useless copy * use a const ref return on std::string Settings::get to prevent data copy on getters which doesn't need to copy it * pass some stack created strings to static const as they are not modified anywhere * Camera: return nametags per const ref instead of a list pointer, we only need to read it * INodeDefManager: getAll should be a result ref writer instead of a return copy * INodeDefManager: getAlias should return a const std::string ref * Minimap: unroll a Scolor creation in blitMinimapPixersToImageRadar to prvent many variable construct/destruct which are unneeded (we rewrite the content in the loop) * CNodeDefManager::updateAliases: prevent a idef getall copy * Profiler: constness * rollback_interface: create real_name later, and use const ref * MapBlockMesh updateFastFaceRow: unroll TileSpec next_tile, which has a cost of 1.8% CPU due to variable allocation/destruction, * MapBlockMesh updateFastFaceRow: copy next_tile to tile only if it's a different tilespec * MapBlockMesh updateFastFaceRow: use memcpy to copy next_lights to lights to do it in a single cpu operation
* Refactored client event if-else cascade to switch statementBen Deutsch2017-03-20
|
* Refactor Game class (part 2) (#5422)Loïc Blot2017-03-19
| | | | | | | | | | | | | | * showPauseMenu is now part of game * remove many flags parameters passed to game functions, use the member. * rename VolatileRunFlags to GameUIFlags (this will permit to share structure with client and CSM * updatePointedThing: remove pointer ref, we already have the pointer in rundata * move some attributes outside of VolatileRunFlags after renaming, to game class * rename statustext to m_statustext * make some const variables static * All those changes permit to reduce a little bit function class cost and will permit to interface CSM with some interesting Game flags * Expose GameUIFlags to client * Client now have GameUIFlags parameter and setters for other classes * Fix minimap show/hide in Lua because we now have access to the real flag
* Server list cleanupShadowNinja2017-03-18
| | | | This removes the hacky server_dedicated pseudo-setting.
* TOGGLE_CHAT keymap should togglechat not HUDLoic Blot2017-03-18
| | | | Fixes #5413
* Reduce memory & function cost of Game class functions (#5406)Loïc Blot2017-03-17
| | | | GameRunData is passed on many game functions, or one of its attributes whereas it's a member of the class. Remove it from functions arguments and call object directly from concerned functions. This will reduce a little bit the Game class loop usage & very little bit the memory usage (due to non creation of pointer/references)
* [CSM] Fix minimap problems (#5405)Loïc Blot2017-03-17
| | | This fixes issue #5404
* [CSM] Add minimap API modifiers (#5399)Loïc Blot2017-03-16
| | | | | | | | * Rename Mapper (too generic) to Minimap * Add lua functions to get/set position, angle, mode for minimap * Client: rename m_mapper to m_minimap * Add minimap to core.ui namespace (core.ui.minimap) * Add various functions to manage minimap (show, hide, toggle_shape) * Cleanup trivial declaration in client
* [CSM] Add enable_client_modding param (default: false)nerzhul2017-03-13
|
* [CSM] Add `on_punchnode` callbackred-0012017-03-13
|
* [CSM] Add `on_dignode` callback (#5140)red-0012017-03-13
|
* [CSM] Add local formspecs. (#5094)red-0012017-03-13
|
* [CSM] Add on_death, on_hp_modification & oh_damage_taken callbacks (#5093)Loïc Blot2017-03-13
| | | | | | * Add on_death callback * Add on_hp_modification & on_damage_taken callbacks * move preview code to preview.lua
* [CSM] Client side moddingLoic Blot2017-03-13
| | | | | | | | | | * rename GameScripting to ServerScripting * Make getBuiltinLuaPath static serverside * Add on_shutdown callback * Add on_receiving_chat_message & on_sending_chat_message callbacks * ScriptApiBase: use IGameDef instead of Server This permits to share common attribute between client & server * Enable mod security in client side modding without conditions
* Fixes for colorwallmounted and colorfacedir nodesDániel Juhász2017-02-18
| | | | | | Correct node placement prediction for attached colorwallmounted nodes. Correct placement direction for colorfacedir and colorwallmounted nodes. Correct detatch mechanism for attached colorwallmounted nodes.
* Footsteps: Fix offset footstep and shallow water sound bugsparamat2017-02-12
| | | | | | | | | | | | | | | Fix footstep sounds coming from nodes to either side when walking on a 1 node wide row of nodebox slabs such as default:snow. Fix sand footsteps when swimming in 1 node deep water. Use a new function 'getFootstepNodePos()' instead of 'getStandingNodePos()' to avoid using a horizontally-offset 'sneak node' for sounds. Sound is selected from the node BS * 0.05 below the player's feet, so that 1/16th slabs will play the slab sound but 1/32nd slabs will not. If the player is not 'touching ground' the node detection position is changed to BS * 0.5 below to preserve footstep sounds when landing after a jump or fall.
dev), m_parent(parent), m_menumanager(menumgr), m_smgr(smgr), m_data(data), m_texture_source(NULL), m_sound_manager(NULL), m_formspecgui(0), m_buttonhandler(0), m_menu(0), m_kill(kill), m_startgame(false), m_script(0), m_scriptdir(""), m_irr_toplefttext(0), m_clouds_enabled(true), m_cloud() { //initialize texture pointers for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { m_textures[i].texture = NULL; } // is deleted by guiformspec! m_buttonhandler = new TextDestGuiEngine(this); //create texture source m_texture_source = new MenuTextureSource(m_device->getVideoDriver()); //create soundmanager MenuMusicFetcher soundfetcher; #if USE_SOUND m_sound_manager = createOpenALSoundManager(&soundfetcher); #endif if(!m_sound_manager) m_sound_manager = &dummySoundManager; //create topleft header std::wstring t = utf8_to_wide(std::string(PROJECT_NAME_C " ") + g_version_hash); core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight()); rect += v2s32(4, 0); m_irr_toplefttext = m_device->getGUIEnvironment()->addStaticText(t.c_str(), rect,false,true,0,-1); //create formspecsource m_formspecgui = new FormspecFormSource(""); /* Create menu */ m_menu = new GUIFormSpecMenu(m_device, m_parent, -1, m_menumanager, NULL /* &client */, NULL /* gamedef */, m_texture_source, m_formspecgui, m_buttonhandler, NULL, false); m_menu->allowClose(false); m_menu->lockSize(true,v2u32(800,600)); // Initialize scripting infostream << "GUIEngine: Initializing Lua" << std::endl; m_script = new MainMenuScripting(this); try { m_script->setMainMenuData(&m_data->script_data); m_data->script_data.errormessage = ""; if (!loadMainMenuScript()) { errorstream << "No future without mainmenu" << std::endl; abort(); } run(); } catch (LuaError &e) { errorstream << "MAINMENU ERROR: " << e.what() << std::endl; m_data->script_data.errormessage = e.what(); } m_menu->quitMenu(); m_menu->drop(); m_menu = NULL; } /******************************************************************************/ bool GUIEngine::loadMainMenuScript() { // Try custom menu script (main_menu_path) m_scriptdir = g_settings->get("main_menu_path"); if (m_scriptdir.empty()) { m_scriptdir = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "mainmenu"; } std::string script = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "init.lua"; try { m_script->loadScript(script); // Menu script loaded return true; } catch (const ModError &e) { errorstream << "GUIEngine: execution of menu script failed: " << e.what() << std::endl; } return false; } /******************************************************************************/ void GUIEngine::run() { // Always create clouds because they may or may not be // needed based on the game selected video::IVideoDriver* driver = m_device->getVideoDriver(); cloudInit(); unsigned int text_height = g_fontengine->getTextHeight(); while(m_device->run() && (!m_startgame) && (!m_kill)) { //check if we need to update the "upper left corner"-text if (text_height != g_fontengine->getTextHeight()) { updateTopLeftTextSize(); text_height = g_fontengine->getTextHeight(); } driver->beginScene(true, true, video::SColor(255,140,186,250)); if (m_clouds_enabled) { cloudPreProcess(); drawOverlay(driver); } else drawBackground(driver); drawHeader(driver); drawFooter(driver); m_device->getGUIEnvironment()->drawAll(); driver->endScene(); if (m_clouds_enabled) cloudPostProcess(); else sleep_ms(25); m_script->step(); #ifdef __ANDROID__ m_menu->getAndroidUIInput(); #endif } } /******************************************************************************/ GUIEngine::~GUIEngine() { video::IVideoDriver* driver = m_device->getVideoDriver(); FATAL_ERROR_IF(driver == 0, "Could not get video driver"); if(m_sound_manager != &dummySoundManager){ delete m_sound_manager; m_sound_manager = NULL; } infostream<<"GUIEngine: Deinitializing scripting"<<std::endl; delete m_script; m_irr_toplefttext->setText(L""); //clean up texture pointers for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { if (m_textures[i].texture != NULL) driver->removeTexture(m_textures[i].texture); } delete m_texture_source; if (m_cloud.clouds) m_cloud.clouds->drop(); } /******************************************************************************/ void GUIEngine::cloudInit() { m_cloud.clouds = new Clouds(m_smgr->getRootSceneNode(), m_smgr, -1, rand(), 100); m_cloud.clouds->update(v2f(0, 0), video::SColor(255,200,200,255)); m_cloud.camera = m_smgr->addCameraSceneNode(0, v3f(0,0,0), v3f(0, 60, 100)); m_cloud.camera->setFarValue(10000); m_cloud.lasttime = m_device->getTimer()->getTime(); } /******************************************************************************/ void GUIEngine::cloudPreProcess() { u32 time = m_device->getTimer()->getTime(); if(time > m_cloud.lasttime) m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0; else m_cloud.dtime = 0; m_cloud.lasttime = time; m_cloud.clouds->step(m_cloud.dtime*3); m_cloud.clouds->render(); m_smgr->drawAll(); } /******************************************************************************/ void GUIEngine::cloudPostProcess() { float fps_max = g_settings->getFloat("fps_max"); // Time of frame without fps limit u32 busytime_u32; // not using getRealTime is necessary for wine u32 time = m_device->getTimer()->getTime(); if(time > m_cloud.lasttime) busytime_u32 = time - m_cloud.lasttime; else busytime_u32 = 0; // FPS limiter u32 frametime_min = 1000./fps_max; if(busytime_u32 < frametime_min) { u32 sleeptime = frametime_min - busytime_u32; m_device->sleep(sleeptime); } } /******************************************************************************/ void GUIEngine::drawBackground(video::IVideoDriver* driver) { v2u32 screensize = driver->getScreenSize(); video::ITexture* texture = m_textures[TEX_LAYER_BACKGROUND].texture; /* If no texture, draw background of solid color */ if(!texture){ video::SColor color(255,80,58,37); core::rect<s32> rect(0, 0, screensize.X, screensize.Y); driver->draw2DRectangle(color, rect, NULL); return; } v2u32 sourcesize = texture->getOriginalSize(); if (m_textures[TEX_LAYER_BACKGROUND].tile) { v2u32 tilesize( MYMAX(sourcesize.X,m_textures[TEX_LAYER_BACKGROUND].minsize), MYMAX(sourcesize.Y,m_textures[TEX_LAYER_BACKGROUND].minsize)); for (unsigned int x = 0; x < screensize.X; x += tilesize.X ) { for (unsigned int y = 0; y < screensize.Y; y += tilesize.Y ) { draw2DImageFilterScaled(driver, texture, core::rect<s32>(x, y, x+tilesize.X, y+tilesize.Y), core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, true); } } return; } /* Draw background texture */ draw2DImageFilterScaled(driver, texture, core::rect<s32>(0, 0, screensize.X, screensize.Y), core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, true); } /******************************************************************************/ void GUIEngine::drawOverlay(video::IVideoDriver* driver) { v2u32 screensize = driver->getScreenSize(); video::ITexture* texture = m_textures[TEX_LAYER_OVERLAY].texture; /* If no texture, draw background of solid color */ if(!texture) return; /* Draw background texture */ v2u32 sourcesize = texture->getOriginalSize(); draw2DImageFilterScaled(driver, texture, core::rect<s32>(0, 0, screensize.X, screensize.Y), core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, true); } /******************************************************************************/ void GUIEngine::drawHeader(video::IVideoDriver* driver) { core::dimension2d<u32> screensize = driver->getScreenSize(); video::ITexture* texture = m_textures[TEX_LAYER_HEADER].texture; /* If no texture, draw nothing */ if(!texture) return; f32 mult = (((f32)screensize.Width / 2.0)) / ((f32)texture->getOriginalSize().Width); v2s32 splashsize(((f32)texture->getOriginalSize().Width) * mult, ((f32)texture->getOriginalSize().Height) * mult); // Don't draw the header is there isn't enough room s32 free_space = (((s32)screensize.Height)-320)/2; if (free_space > splashsize.Y) { core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y); splashrect += v2s32((screensize.Width/2)-(splashsize.X/2), ((free_space/2)-splashsize.Y/2)+10); video::SColor bgcolor(255,50,50,50); draw2DImageFilterScaled(driver, texture, splashrect, core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(texture->getOriginalSize())), NULL, NULL, true); } } /******************************************************************************/ void GUIEngine::drawFooter(video::IVideoDriver* driver) { core::dimension2d<u32> screensize = driver->getScreenSize(); video::ITexture* texture = m_textures[TEX_LAYER_FOOTER].texture; /* If no texture, draw nothing */ if(!texture) return; f32 mult = (((f32)screensize.Width)) / ((f32)texture->getOriginalSize().Width); v2s32 footersize(((f32)texture->getOriginalSize().Width) * mult, ((f32)texture->getOriginalSize().Height) * mult); // Don't draw the footer if there isn't enough room s32 free_space = (((s32)screensize.Height)-320)/2; if (free_space > footersize.Y) { core::rect<s32> rect(0,0,footersize.X,footersize.Y); rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y); rect -= v2s32(footersize.X/2, 0); draw2DImageFilterScaled(driver, texture, rect, core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(texture->getOriginalSize())), NULL, NULL, true); } } /******************************************************************************/ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath, bool tile_image, unsigned int minsize) { video::IVideoDriver* driver = m_device->getVideoDriver(); FATAL_ERROR_IF(driver == 0, "Could not get video driver"); if (m_textures[layer].texture != NULL) { driver->removeTexture(m_textures[layer].texture); m_textures[layer].texture = NULL; } if ((texturepath == "") || !fs::PathExists(texturepath)) { return false; } m_textures[layer].texture = driver->getTexture(texturepath.c_str()); m_textures[layer].tile = tile_image; m_textures[layer].minsize = minsize; if (m_textures[layer].texture == NULL) { return false; } return true; } /******************************************************************************/ bool GUIEngine::downloadFile(std::string url, std::string target) { #if USE_CURL std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary); if (!target_file.good()) { return false; } HTTPFetchRequest fetch_request; HTTPFetchResult fetch_result; fetch_request.url = url; fetch_request.caller = HTTPFETCH_SYNC; fetch_request.timeout = g_settings->getS32("curl_file_download_timeout"); httpfetch_sync(fetch_request, fetch_result); if (!fetch_result.succeeded) { return false; } target_file << fetch_result.data; return true; #else return false; #endif } /******************************************************************************/ void GUIEngine::setTopleftText(std::string append) { std::wstring toset = utf8_to_wide(std::string(PROJECT_NAME_C " ") + g_version_hash); if (append != "") { toset += L" / "; toset += utf8_to_wide(append); } m_irr_toplefttext->setText(toset.c_str()); updateTopLeftTextSize(); } /******************************************************************************/ void GUIEngine::updateTopLeftTextSize() { std::wstring text = m_irr_toplefttext->getText(); core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(text), g_fontengine->getTextHeight()); rect += v2s32(4, 0); m_irr_toplefttext->remove(); m_irr_toplefttext = m_device->getGUIEnvironment()->addStaticText(text.c_str(), rect,false,true,0,-1); } /******************************************************************************/ s32 GUIEngine::playSound(SimpleSoundSpec spec, bool looped) { s32 handle = m_sound_manager->playSound(spec, looped); return handle; } /******************************************************************************/ void GUIEngine::stopSound(s32 handle) { m_sound_manager->stopSound(handle); } /******************************************************************************/ unsigned int GUIEngine::queueAsync(std::string serialized_func, std::string serialized_params) { return m_script->queueAsync(serialized_func, serialized_params); }