aboutsummaryrefslogtreecommitdiff
path: root/src/client/game.cpp
Commit message (Expand)AuthorAge
* Add z-index management to HUDPierre-Yves Rollo2019-12-06
* Run on_item_use CSM callback even if item is not marked usablesfan52019-11-11
* Fix isDead()/autoforward crash (#9031)Paramat2019-10-09
* Move Quicktune code to util/ (#8871)ANAND2019-09-29
* Simple shader fixes. (#8991)lhofhansl2019-09-26
* Move the code for meta formspec into bool Game::nodePlacement(const ItemDefin...DS-Minetest2019-09-22
* Add support for per-player FOV overrides and multipliersAnand S2019-09-19
* Trigger on_place in many situations even if prediction failedDS-Minetest2019-09-19
* Built-in formspecs: Force version 1SmallJoker2019-09-14
* Formspecs: Introduce formspec_version to modsSmallJoker2019-09-14
* Load CSM environment after the restrictions are knownSmallJoker2019-09-14
* Inventory: Send dirty lists where appropriate (#8742)SmallJoker2019-08-24
* Disable autoforward if player is deadANAND2019-08-20
* Better F6 profiler (#8750)SmallJoker2019-08-13
* Merge pull request #8776 from osjc/FixGetNodeJozef Behran2019-08-10
* Game: Fix double BS multiplicationSmallJoker2019-08-07
* Client::Interact: Use InteractAction enum instead of numeric constantsANAND2019-08-07
* Unify wield item handling (#8677)SmallJoker2019-08-07
* Hide chat when console is open (#8656)ANAND2019-08-07
* Mainmenu: Use textarea in error formspecsSmallJoker2019-08-01
* Do predict when sneak-place to node with on_rightclickDS-Minetest2019-07-08
* Formspecs: Close on metadata removal (#8348)SmallJoker2019-06-10
* Make autoforward simulate the 'up' key (#8249)DS2019-05-21
* Use player as starting point instead of camera when pointing node (#8261)Muhammad Rifqi Priyo Susanto2019-04-27
* Android: Clear chat open flag on cancel or completion (#8478)stujones112019-04-19
* Drop GUIConfirmRegistration::m_address unused fieldLoïc Blot2019-03-12
* Remove 's' from 'automatic forwards' (#8272)ANAND2019-02-23
* CSM restrictions: Make 'LOAD_CLIENT_MODS' disable loading of 'builtin' (#8000)Paramat2019-01-03
* Extend pitch fly mode to swimming (#7943)random-geek2018-12-31
* Make showOverlayMessage strings translatable (#7964)Wuzzy2018-12-13
* Raise hotbar limit to 32 slots, add associated keybinding options (#7916)Vanessa Dannenberg2018-12-02
* Added pitch fly mode (#7817)Gaël C2018-12-01
* Move client-specific files to 'src/client' (#7902)Quentin Bazin2018-11-28
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser 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. */ #pragma once #include "irrlichttypes.h" #include "exceptions.h" #include "threading/mutex_auto_lock.h" #include "threading/semaphore.h" #include <list> #include <vector> #include <map> #include <set> #include <queue> /* Queue with unique values with fast checking of value existence */ template<typename Value> class UniqueQueue { public: /* Does nothing if value is already queued. Return value: true: value added false: value already exists */ bool push_back(const Value& value) { if (m_set.insert(value).second) { m_queue.push(value); return true; } return false; } void pop_front() { m_set.erase(m_queue.front()); m_queue.pop(); } const Value& front() const { return m_queue.front(); } u32 size() const { return m_queue.size(); } private: std::set<Value> m_set; std::queue<Value> m_queue; }; template<typename Key, typename Value> class MutexedMap { public: MutexedMap() = default; void set(const Key &name, const Value &value) { MutexAutoLock lock(m_mutex); m_values[name] = value; } bool get(const Key &name, Value *result) const { MutexAutoLock lock(m_mutex); typename std::map<Key, Value>::const_iterator n = m_values.find(name); if (n == m_values.end()) return false; if (result) *result = n->second; return true; } std::vector<Value> getValues() const { MutexAutoLock lock(m_mutex); std::vector<Value> result; for (typename std::map<Key, Value>::const_iterator it = m_values.begin(); it != m_values.end(); ++it){ result.push_back(it->second); } return result; } void clear() { m_values.clear(); } private: std::map<Key, Value> m_values; mutable std::mutex m_mutex; }; // Thread-safe Double-ended queue template<typename T> class MutexedQueue { public: template<typename Key, typename U, typename Caller, typename CallerData> friend class RequestQueue; MutexedQueue() = default; bool empty() const { MutexAutoLock lock(m_mutex); return m_queue.empty(); } void push_back(T t) { MutexAutoLock lock(m_mutex); m_queue.push_back(t); m_signal.post(); } /* this version of pop_front returns a empty element of T on timeout. * Make sure default constructor of T creates a recognizable "empty" element */ T pop_frontNoEx(u32 wait_time_max_ms) { if (m_signal.wait(wait_time_max_ms)) { MutexAutoLock lock(m_mutex); T t = m_queue.front(); m_queue.pop_front(); return t; } return T(); } T pop_front(u32 wait_time_max_ms) { if (m_signal.wait(wait_time_max_ms)) { MutexAutoLock lock(m_mutex); T t = m_queue.front(); m_queue.pop_front(); return t; } throw ItemNotFoundException("MutexedQueue: queue is empty"); } T pop_frontNoEx() { m_signal.wait(); MutexAutoLock lock(m_mutex); T t = m_queue.front(); m_queue.pop_front(); return t; } T pop_back(u32 wait_time_max_ms=0) { if (m_signal.wait(wait_time_max_ms)) { MutexAutoLock lock(m_mutex); T t = m_queue.back(); m_queue.pop_back(); return t; } throw ItemNotFoundException("MutexedQueue: queue is empty"); } /* this version of pop_back returns a empty element of T on timeout. * Make sure default constructor of T creates a recognizable "empty" element */ T pop_backNoEx(u32 wait_time_max_ms) { if (m_signal.wait(wait_time_max_ms)) { MutexAutoLock lock(m_mutex); T t = m_queue.back(); m_queue.pop_back(); return t; } return T(); } T pop_backNoEx() { m_signal.wait(); MutexAutoLock lock(m_mutex); T t = m_queue.back(); m_queue.pop_back(); return t; } protected: std::mutex &getMutex() { return m_mutex; } std::deque<T> &getQueue() { return m_queue; } std::deque<T> m_queue; mutable std::mutex m_mutex; Semaphore m_signal; }; template<typename K, typename V> class LRUCache { public: LRUCache(size_t limit, void (*cache_miss)(void *data, const K &key, V *dest), void *data) { m_limit = limit; m_cache_miss = cache_miss; m_cache_miss_data = data; } void setLimit(size_t limit) { m_limit = limit; invalidate(); } void invalidate() { m_map.clear(); m_queue.clear(); } const V *lookupCache(K key) { typename cache_type::iterator it = m_map.find(key); V *ret; if (it != m_map.end()) { // found! cache_entry_t &entry = it->second; ret = &entry.second; // update the usage information m_queue.erase(entry.first); m_queue.push_front(key); entry.first = m_queue.begin(); } else { // cache miss -- enter into cache cache_entry_t &entry = m_map[key]; ret = &entry.second; m_cache_miss(m_cache_miss_data, key, &entry.second); // delete old entries if (m_queue.size() == m_limit) { const K &id = m_queue.back(); m_map.erase(id); m_queue.pop_back(); } m_queue.push_front(key); entry.first = m_queue.begin(); } return ret; } private: void (*m_cache_miss)(void *data, const K &key, V *dest); void *m_cache_miss_data; size_t m_limit; typedef typename std::template pair<typename std::template list<K>::iterator, V> cache_entry_t; typedef std::template map<K, cache_entry_t> cache_type; cache_type m_map; // we can't use std::deque here, because its iterators get invalidated std::list<K> m_queue; };