Jeija 2016-10-07 21:37:03 +02:00
commit 719bd6bf7e
30 changed files with 152 additions and 185 deletions

View File

@ -552,7 +552,7 @@ void Camera::drawNametags()
// shadow can remain.
continue;
}
v3f pos = nametag->parent_node->getPosition() + v3f(0.0, 1.1 * BS, 0.0);
v3f pos = nametag->parent_node->getAbsolutePosition() + v3f(0.0, 1.1 * BS, 0.0);
f32 transformed_pos[4] = { pos.X, pos.Y, pos.Z, 1.0f };
trans.multiplyWith1x4Matrix(transformed_pos);
if (transformed_pos[3] > 0) {

View File

@ -623,10 +623,8 @@ void Client::step(float dtime)
Update positions of sounds attached to objects
*/
{
for(std::map<int, u16>::iterator
i = m_sounds_to_objects.begin();
i != m_sounds_to_objects.end(); ++i)
{
for(UNORDERED_MAP<int, u16>::iterator i = m_sounds_to_objects.begin();
i != m_sounds_to_objects.end(); ++i) {
int client_id = i->first;
u16 object_id = i->second;
ClientActiveObject *cao = m_env.getActiveObject(object_id);
@ -645,8 +643,7 @@ void Client::step(float dtime)
m_removed_sounds_check_timer = 0;
// Find removed sounds and clear references to them
std::vector<s32> removed_server_ids;
for(std::map<s32, int>::iterator
i = m_sounds_server_to_client.begin();
for(UNORDERED_MAP<s32, int>::iterator i = m_sounds_server_to_client.begin();
i != m_sounds_server_to_client.end();) {
s32 server_id = i->first;
int client_id = i->second;

View File

@ -663,11 +663,11 @@ private:
// Sounds
float m_removed_sounds_check_timer;
// Mapping from server sound ids to our sound ids
std::map<s32, int> m_sounds_server_to_client;
UNORDERED_MAP<s32, int> m_sounds_server_to_client;
// And the other way!
std::map<int, s32> m_sounds_client_to_server;
UNORDERED_MAP<int, s32> m_sounds_client_to_server;
// And relations to objects
std::map<int, u16> m_sounds_to_objects;
UNORDERED_MAP<int, u16> m_sounds_to_objects;
// Privileges
UNORDERED_SET<std::string> m_privileges;

View File

@ -43,12 +43,11 @@ ClientActiveObject* ClientActiveObject::create(ActiveObjectType type,
IGameDef *gamedef, ClientEnvironment *env)
{
// Find factory function
std::map<u16, Factory>::iterator n;
n = m_types.find(type);
UNORDERED_MAP<u16, Factory>::iterator n = m_types.find(type);
if(n == m_types.end()) {
// If factory is not found, just return.
warningstream<<"ClientActiveObject: No factory for type="
<<(int)type<<std::endl;
warningstream << "ClientActiveObject: No factory for type="
<< (int)type << std::endl;
return NULL;
}
@ -59,8 +58,7 @@ ClientActiveObject* ClientActiveObject::create(ActiveObjectType type,
void ClientActiveObject::registerType(u16 type, Factory f)
{
std::map<u16, Factory>::iterator n;
n = m_types.find(type);
UNORDERED_MAP<u16, Factory>::iterator n = m_types.find(type);
if(n != m_types.end())
return;
m_types[type] = f;

View File

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "activeobject.h"
#include <map>
#include "util/cpp11_container.h"
/*
@ -103,7 +104,7 @@ protected:
ClientEnvironment *m_env;
private:
// Used for creating objects based on type
static std::map<u16, Factory> m_types;
static UNORDERED_MAP<u16, Factory> m_types;
};
struct DistanceSortedActiveObject

View File

@ -51,7 +51,7 @@ struct ToolCapabilities;
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
std::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
UNORDERED_MAP<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
SmoothTranslator::SmoothTranslator():
vect_old(0,0,0),

View File

@ -374,8 +374,10 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
if(m_bone_position_sent == false){
m_bone_position_sent = true;
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
std::string str = gob_cmd_update_bone_position((*ii).first,
(*ii).second.X, (*ii).second.Y);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom);
@ -410,8 +412,10 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
os<<serializeLongString(gob_cmd_update_animation(
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
os << serializeLongString(gob_cmd_update_bone_position((*ii).first,
(*ii).second.X, (*ii).second.Y)); // m_bone_position.size
}
os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
}
@ -889,7 +893,8 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
os<<serializeLongString(gob_cmd_update_animation(
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
}
os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
@ -1034,19 +1039,22 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_messages_out.push(aom);
}
if(m_bone_position_sent == false){
if (!m_bone_position_sent) {
m_bone_position_sent = true;
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
std::string str = gob_cmd_update_bone_position((*ii).first,
(*ii).second.X, (*ii).second.Y);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom);
}
}
if(m_attachment_sent == false){
if (!m_attachment_sent){
m_attachment_sent = true;
std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
std::string str = gob_cmd_update_attachment(m_attachment_parent_id,
m_attachment_bone, m_attachment_position, m_attachment_rotation);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom);

View File

@ -112,7 +112,7 @@ private:
bool m_animation_loop;
bool m_animation_sent;
std::map<std::string, core::vector2d<v3f> > m_bone_position;
UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
bool m_bone_position_sent;
int m_attachment_parent_id;
@ -321,7 +321,8 @@ private:
bool m_animation_loop;
bool m_animation_sent;
std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
// Stores position and rotation for each bone name
UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
bool m_bone_position_sent;
int m_attachment_parent_id;

View File

@ -409,8 +409,6 @@ protected:
std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
ItemSpec *m_selected_item;
f32 m_timer1;
f32 m_timer2;
u32 m_selected_amount;
bool m_selected_dragging;
@ -462,7 +460,7 @@ private:
GUITable::TableOptions table_options;
GUITable::TableColumns table_columns;
// used to restore table selection/scroll/treeview state
std::map<std::string, GUITable::DynamicData> table_dyndata;
UNORDERED_MAP<std::string, GUITable::DynamicData> table_dyndata;
} parserData;
typedef struct {

View File

@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "voxel.h"
#include "modifiedstate.h"
#include "util/container.h"
#include "util/cpp11_container.h"
#include "nodetimer.h"
#include "map_settings_manager.h"

View File

@ -1035,7 +1035,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
m_enable_shaders = data->m_use_shaders;
m_use_tangent_vertices = data->m_use_tangent_vertices;
m_enable_vbo = g_settings->getBool("enable_vbo");
if (g_settings->getBool("enable_minimap")) {
m_minimap_mapblock = new MinimapMapblock;
m_minimap_mapblock->getMinimapNodes(
@ -1300,10 +1300,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
// Cracks
if(crack != m_last_crack)
{
for(std::map<u32, std::string>::iterator
i = m_crack_materials.begin();
i != m_crack_materials.end(); ++i)
{
for (UNORDERED_MAP<u32, std::string>::iterator i = m_crack_materials.begin();
i != m_crack_materials.end(); ++i) {
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
std::string basename = i->second;
@ -1317,9 +1315,9 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
// If the current material is also animated,
// update animation info
std::map<u32, TileSpec>::iterator anim_iter =
m_animation_tiles.find(i->first);
if(anim_iter != m_animation_tiles.end()){
UNORDERED_MAP<u32, TileSpec>::iterator anim_iter =
m_animation_tiles.find(i->first);
if (anim_iter != m_animation_tiles.end()){
TileSpec &tile = anim_iter->second;
tile.texture = new_texture;
tile.texture_id = new_texture_id;
@ -1332,10 +1330,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
}
// Texture animation
for(std::map<u32, TileSpec>::iterator
i = m_animation_tiles.begin();
i != m_animation_tiles.end(); ++i)
{
for (UNORDERED_MAP<u32, TileSpec>::iterator i = m_animation_tiles.begin();
i != m_animation_tiles.end(); ++i) {
const TileSpec &tile = i->second;
// Figure out current frame
int frameoffset = m_animation_frame_offsets[i->first];
@ -1454,7 +1450,7 @@ void MeshCollector::append(const TileSpec &tile,
vertices[i].Color, vertices[i].TCoords);
p->vertices.push_back(vert);
}
}
}
for (u32 i = 0; i < numIndices; i++) {
u32 j = indices[i] + vertex_count;
@ -1510,7 +1506,7 @@ void MeshCollector::append(const TileSpec &tile,
vertices[i].Normal, c, vertices[i].TCoords);
p->vertices.push_back(vert);
}
}
}
for (u32 i = 0; i < numIndices; i++) {
u32 j = indices[i] + vertex_count;

View File

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "client/tile.h"
#include "voxel.h"
#include "util/cpp11_container.h"
#include <map>
class IGameDef;
@ -121,7 +122,7 @@ public:
if(m_animation_force_timer > 0)
m_animation_force_timer--;
}
void updateCameraOffset(v3s16 camera_offset);
void updatePlanetOffset(v3s16 planet_offset);
@ -145,20 +146,20 @@ private:
// Last crack value passed to animate()
int m_last_crack;
// Maps mesh buffer (i.e. material) indices to base texture names
std::map<u32, std::string> m_crack_materials;
UNORDERED_MAP<u32, std::string> m_crack_materials;
// Animation info: texture animationi
// Maps meshbuffers to TileSpecs
std::map<u32, TileSpec> m_animation_tiles;
std::map<u32, int> m_animation_frames; // last animation frame
std::map<u32, int> m_animation_frame_offsets;
UNORDERED_MAP<u32, TileSpec> m_animation_tiles;
UNORDERED_MAP<u32, int> m_animation_frames; // last animation frame
UNORDERED_MAP<u32, int> m_animation_frame_offsets;
// Animation info: day/night transitions
// Last daynight_ratio value passed to animate()
u32 m_last_daynight_ratio;
// For each meshbuffer, maps vertex indices to (day,night) pairs
std::map<u32, std::map<u32, std::pair<u8, u8> > > m_daynight_diffs;
// Camera offset info -> do we have to translate the mesh?
v3s16 m_camera_offset;

View File

@ -812,9 +812,7 @@ void Client::handleCommand_StopSound(NetworkPacket* pkt)
*pkt >> server_id;
std::map<s32, int>::iterator i =
m_sounds_server_to_client.find(server_id);
UNORDERED_MAP<s32, int>::iterator i = m_sounds_server_to_client.find(server_id);
if (i != m_sounds_server_to_client.end()) {
int client_id = i->second;
m_sound->stopSound(client_id);

View File

@ -1693,9 +1693,7 @@ void Server::handleCommand_RemovedSounds(NetworkPacket* pkt)
*pkt >> id;
std::map<s32, ServerPlayingSound>::iterator i =
m_playing_sounds.find(id);
UNORDERED_MAP<s32, ServerPlayingSound>::iterator i = m_playing_sounds.find(id);
if (i == m_playing_sounds.end())
continue;

View File

@ -81,6 +81,7 @@ bool AsyncEngine::registerFunction(const char* name, lua_CFunction func)
if (initDone) {
return false;
}
functionList[name] = func;
return true;
}
@ -203,7 +204,7 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) {
/******************************************************************************/
void AsyncEngine::prepareEnvironment(lua_State* L, int top)
{
for (std::map<std::string, lua_CFunction>::iterator it = functionList.begin();
for (UNORDERED_MAP<std::string, lua_CFunction>::iterator it = functionList.begin();
it != functionList.end(); it++) {
lua_pushstring(L, it->first.c_str());
lua_pushcfunction(L, it->second);

View File

@ -132,7 +132,7 @@ private:
bool initDone;
// Internal store for registred functions
std::map<std::string, lua_CFunction> functionList;
UNORDERED_MAP<std::string, lua_CFunction> functionList;
// Internal counter to create job IDs
unsigned int jobIdCounter;

View File

@ -244,7 +244,7 @@ bool read_schematic_def(lua_State *L, int index,
schem->schemdata = new MapNode[numnodes];
size_t names_base = names->size();
std::map<std::string, content_t> name_id_map;
UNORDERED_MAP<std::string, content_t> name_id_map;
u32 i = 0;
for (lua_pushnil(L); lua_next(L, -2); i++, lua_pop(L, 1)) {
@ -266,7 +266,7 @@ bool read_schematic_def(lua_State *L, int index,
u8 param2 = getintfield_default(L, -1, "param2", 0);
//// Find or add new nodename-to-ID mapping
std::map<std::string, content_t>::iterator it = name_id_map.find(name);
UNORDERED_MAP<std::string, content_t>::iterator it = name_id_map.find(name);
content_t name_index;
if (it != name_id_map.end()) {
name_index = it->second;

View File

@ -794,7 +794,7 @@ void Server::AsyncRunStep(bool initial_step)
// Key = object id
// Value = data sent by object
std::map<u16, std::vector<ActiveObjectMessage>* > buffered_messages;
UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* > buffered_messages;
// Get active object messages from environment
for(;;) {
@ -803,7 +803,7 @@ void Server::AsyncRunStep(bool initial_step)
break;
std::vector<ActiveObjectMessage>* message_list = NULL;
std::map<u16, std::vector<ActiveObjectMessage>* >::iterator n;
UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator n;
n = buffered_messages.find(aom.id);
if (n == buffered_messages.end()) {
message_list = new std::vector<ActiveObjectMessage>;
@ -824,7 +824,7 @@ void Server::AsyncRunStep(bool initial_step)
std::string reliable_data;
std::string unreliable_data;
// Go through all objects in message buffer
for (std::map<u16, std::vector<ActiveObjectMessage>* >::iterator
for (UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator
j = buffered_messages.begin();
j != buffered_messages.end(); ++j) {
// If object is not known by client, skip it
@ -868,7 +868,7 @@ void Server::AsyncRunStep(bool initial_step)
m_clients.unlock();
// Clear buffered_messages
for(std::map<u16, std::vector<ActiveObjectMessage>* >::iterator
for (UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator
i = buffered_messages.begin();
i != buffered_messages.end(); ++i) {
delete i->second;
@ -2016,16 +2016,15 @@ s32 Server::playSound(const SimpleSoundSpec &spec,
void Server::stopSound(s32 handle)
{
// Get sound reference
std::map<s32, ServerPlayingSound>::iterator i =
m_playing_sounds.find(handle);
if(i == m_playing_sounds.end())
UNORDERED_MAP<s32, ServerPlayingSound>::iterator i = m_playing_sounds.find(handle);
if (i == m_playing_sounds.end())
return;
ServerPlayingSound &psound = i->second;
NetworkPacket pkt(TOCLIENT_STOP_SOUND, 4);
pkt << handle;
for(std::set<u16>::iterator i = psound.clients.begin();
for (UNORDERED_SET<u16>::iterator i = psound.clients.begin();
i != psound.clients.end(); ++i) {
// Send as reliable
m_clients.send(*i, 0, &pkt, true);
@ -2322,7 +2321,7 @@ void Server::sendMediaAnnouncement(u16 peer_id)
NetworkPacket pkt(TOCLIENT_ANNOUNCE_MEDIA, 0, peer_id);
pkt << (u16) m_media.size();
for (std::map<std::string, MediaInfo>::iterator i = m_media.begin();
for (UNORDERED_MAP<std::string, MediaInfo>::iterator i = m_media.begin();
i != m_media.end(); ++i) {
pkt << i->first << i->second.sha1_digest;
}
@ -2367,7 +2366,7 @@ void Server::sendRequestedMedia(u16 peer_id,
i != tosend.end(); ++i) {
const std::string &name = *i;
if(m_media.find(name) == m_media.end()) {
if (m_media.find(name) == m_media.end()) {
errorstream<<"Server::sendRequestedMedia(): Client asked for "
<<"unknown file \""<<(name)<<"\""<<std::endl;
continue;
@ -2628,13 +2627,11 @@ void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason)
/*
Clear references to playing sounds
*/
for(std::map<s32, ServerPlayingSound>::iterator
i = m_playing_sounds.begin();
i != m_playing_sounds.end();)
{
for (UNORDERED_MAP<s32, ServerPlayingSound>::iterator
i = m_playing_sounds.begin(); i != m_playing_sounds.end();) {
ServerPlayingSound &psound = i->second;
psound.clients.erase(peer_id);
if(psound.clients.empty())
if (psound.clients.empty())
m_playing_sounds.erase(i++);
else
++i;
@ -2757,7 +2754,7 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
std::wstringstream ws;
ws << L"You cannot send more messages. You are limited to "
<< g_settings->getFloat("chat_message_limit_per_10sec")
<< " messages per 10 seconds.";
<< L" messages per 10 seconds.";
return ws.str();
}
case RPLAYER_CHATRESULT_KICK:
@ -2770,7 +2767,7 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
if (m_max_chatmessage_length > 0 && wmessage.length() > m_max_chatmessage_length) {
return L"Your message exceed the maximum chat message limit set on the server. "
"It was refused. Send a shorter message";
L"It was refused. Send a shorter message";
}
// Commands are implemented in Lua, so only catch invalid

View File

@ -157,7 +157,7 @@ struct ServerSoundParams
struct ServerPlayingSound
{
ServerSoundParams params;
std::set<u16> clients; // peer ids
UNORDERED_SET<u16> clients; // peer ids
};
class Server : public con::PeerHandler, public MapEventReceiver,
@ -243,11 +243,9 @@ public:
std::wstring getStatusString();
// read shutdown state
inline bool getShutdownRequested()
{ return m_shutdown_requested; }
inline bool getShutdownRequested() const { return m_shutdown_requested; }
// request server to shutdown
inline void requestShutdown() { m_shutdown_requested = true; }
void requestShutdown(const std::string &msg, bool reconnect)
{
m_shutdown_requested = true;
@ -323,8 +321,7 @@ public:
const ModSpec* getModSpec(const std::string &modname) const;
void getModNames(std::vector<std::string> &modlist);
std::string getBuiltinLuaPath();
inline std::string getWorldPath() const
{ return m_path_world; }
inline std::string getWorldPath() const { return m_path_world; }
inline bool isSingleplayer()
{ return m_simple_singleplayer_mode; }
@ -356,8 +353,7 @@ public:
bool setSky(Player *player, const video::SColor &bgcolor,
const std::string &type, const std::vector<std::string> &params);
bool overrideDayNightRatio(Player *player, bool do_override,
float brightness);
bool overrideDayNightRatio(Player *player, bool do_override, float brightness);
/* con::PeerHandler implementation. */
void peerAdded(con::Peer *peer);
@ -654,12 +650,12 @@ private:
u16 m_ignore_map_edit_events_peer_id;
// media files known to server
std::map<std::string,MediaInfo> m_media;
UNORDERED_MAP<std::string, MediaInfo> m_media;
/*
Sounds
*/
std::map<s32, ServerPlayingSound> m_playing_sounds;
UNORDERED_MAP<s32, ServerPlayingSound> m_playing_sounds;
s32 m_next_sound_id;
/*

View File

@ -27,8 +27,8 @@ DEALINGS IN THE SOFTWARE.
Event::Event()
{
#if __cplusplus < 201103L
# ifdef _WIN32
#ifndef USE_CPP11_MUTEX
# if USE_WIN_MUTEX
event = CreateEvent(NULL, false, false, NULL);
# else
pthread_cond_init(&cv, NULL);
@ -38,10 +38,10 @@ Event::Event()
#endif
}
#if __cplusplus < 201103L
#ifndef USE_CPP11_MUTEX
Event::~Event()
{
#ifdef _WIN32
#if USE_WIN_MUTEX
CloseHandle(event);
#else
pthread_cond_destroy(&cv);
@ -53,13 +53,13 @@ Event::~Event()
void Event::wait()
{
#if __cplusplus >= 201103L
#if USE_CPP11_MUTEX
MutexAutoLock lock(mutex);
while (!notified) {
cv.wait(lock);
}
notified = false;
#elif defined(_WIN32)
#elif USE_WIN_MUTEX
WaitForSingleObject(event, INFINITE);
#else
pthread_mutex_lock(&mutex);
@ -74,11 +74,11 @@ void Event::wait()
void Event::signal()
{
#if __cplusplus >= 201103L
#if USE_CPP11_MUTEX
MutexAutoLock lock(mutex);
notified = true;
cv.notify_one();
#elif defined(_WIN32)
#elif USE_WIN_MUTEX
SetEvent(event);
#else
pthread_mutex_lock(&mutex);

View File

@ -26,17 +26,12 @@ DEALINGS IN THE SOFTWARE.
#ifndef THREADING_EVENT_H
#define THREADING_EVENT_H
#if __cplusplus >= 201103L
#include "threads.h"
#if USE_CPP11_MUTEX
#include <condition_variable>
#include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#elif defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#else
#include <pthread.h>
#endif
@ -49,18 +44,18 @@ DEALINGS IN THE SOFTWARE.
class Event {
public:
Event();
#if __cplusplus < 201103L
#ifndef USE_CPP11_MUTEX
~Event();
#endif
void wait();
void signal();
private:
#if __cplusplus >= 201103L
#if USE_CPP11_MUTEX
std::condition_variable cv;
Mutex mutex;
bool notified;
#elif defined(_WIN32)
#elif USE_WIN_MUTEX
HANDLE event;
#else
pthread_cond_t cv;

View File

@ -23,14 +23,13 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// Windows std::mutex is much slower than the critical section API
#if __cplusplus < 201103L || defined(_WIN32)
#include "threads.h"
#ifndef USE_CPP11_MUTEX
#include "threading/mutex.h"
#ifndef _WIN32
#include <cassert>
#endif
#include <cassert>
#define UNUSED(expr) do { (void)(expr); } while (0)
@ -47,7 +46,7 @@ Mutex::Mutex(bool recursive)
void Mutex::init_mutex(bool recursive)
{
#ifdef _WIN32
#if USE_WIN_MUTEX
// Windows critical sections are recursive by default
UNUSED(recursive);
@ -69,7 +68,7 @@ void Mutex::init_mutex(bool recursive)
Mutex::~Mutex()
{
#ifdef _WIN32
#if USE_WIN_MUTEX
DeleteCriticalSection(&mutex);
#else
int ret = pthread_mutex_destroy(&mutex);
@ -80,7 +79,7 @@ Mutex::~Mutex()
void Mutex::lock()
{
#ifdef _WIN32
#if USE_WIN_MUTEX
EnterCriticalSection(&mutex);
#else
int ret = pthread_mutex_lock(&mutex);
@ -91,7 +90,7 @@ void Mutex::lock()
void Mutex::unlock()
{
#ifdef _WIN32
#if USE_WIN_MUTEX
LeaveCriticalSection(&mutex);
#else
int ret = pthread_mutex_unlock(&mutex);
@ -104,5 +103,5 @@ RecursiveMutex::RecursiveMutex()
: Mutex(true)
{}
#endif
#endif // C++11

View File

@ -26,14 +26,15 @@ DEALINGS IN THE SOFTWARE.
#ifndef THREADING_MUTEX_H
#define THREADING_MUTEX_H
// Windows std::mutex is much slower than the critical section API
#if __cplusplus >= 201103L && !defined(_WIN32)
#include "threads.h"
#if USE_CPP11_MUTEX
#include <mutex>
using Mutex = std::mutex;
using RecursiveMutex = std::recursive_mutex;
#else
#ifdef _WIN32
#if USE_WIN_MUTEX
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
@ -41,7 +42,7 @@ DEALINGS IN THE SOFTWARE.
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#else // pthread
#else
#include <pthread.h>
#endif
@ -59,9 +60,9 @@ protected:
Mutex(bool recursive);
void init_mutex(bool recursive);
private:
#ifdef _WIN32
#if USE_WIN_MUTEX
CRITICAL_SECTION mutex;
#else // pthread
#else
pthread_mutex_t mutex;
#endif
@ -76,6 +77,6 @@ public:
DISABLE_CLASS_COPY(RecursiveMutex);
};
#endif // C++11
#endif // C++11
#endif

View File

@ -26,7 +26,9 @@ DEALINGS IN THE SOFTWARE.
#ifndef THREADING_MUTEX_AUTO_LOCK_H
#define THREADING_MUTEX_AUTO_LOCK_H
#if __cplusplus >= 201103L
#include "threads.h"
#if USE_CPP11_MUTEX
#include <mutex>
using MutexAutoLock = std::unique_lock<std::mutex>;
using RecursiveMutexAutoLock = std::unique_lock<std::recursive_mutex>;

View File

@ -198,7 +198,7 @@ bool Thread::kill()
m_running = false;
#ifdef _WIN32
#if USE_WIN_THREADS
TerminateThread(m_thread_handle, 0);
CloseHandle(m_thread_handle);
#else
@ -310,10 +310,16 @@ void Thread::setName(const std::string &name)
unsigned int Thread::getNumberOfProcessors()
{
#if __cplusplus >= 201103L
#if USE_CPP11_THREADS
return std::thread::hardware_concurrency();
#elif USE_WIN_THREADS
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#elif defined(_SC_NPROCESSORS_ONLN)
return sysconf(_SC_NPROCESSORS_ONLN);
@ -335,12 +341,6 @@ unsigned int Thread::getNumberOfProcessors()
return get_nprocs();
#elif defined(_WIN32)
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#elif defined(PTW32_VERSION) || defined(__hpux)
return pthread_num_processors_np();
@ -359,7 +359,7 @@ bool Thread::bindToProcessor(unsigned int proc_number)
return false;
#elif defined(_WIN32)
#elif USE_WIN_THREADS
return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number);
@ -407,7 +407,7 @@ bool Thread::bindToProcessor(unsigned int proc_number)
bool Thread::setPriority(int prio)
{
#if defined(_WIN32)
#if USE_WIN_THREADS
return SetThreadPriority(getThreadHandle(), prio);

View File

@ -32,9 +32,6 @@ DEALINGS IN THE SOFTWARE.
#include "threads.h"
#include <string>
#if USE_CPP11_THREADS
#include <thread> // for std::thread
#endif
#ifdef _AIX
#include <sys/thread.h> // for tid_t
#endif
@ -157,9 +154,11 @@ private:
Atomic<bool> m_running;
Mutex m_mutex;
#ifndef USE_CPP11_THREADS
#if USE_CPP11_THREADS
std::thread *m_thread_obj;
#else
threadhandle_t m_thread_handle;
# if _WIN32
# if USE_WIN_THREADS
threadid_t m_thread_id;
# endif
#endif
@ -172,10 +171,6 @@ private:
tid_t m_kernel_thread_id;
#endif
#if USE_CPP11_THREADS
std::thread *m_thread_obj;
#endif
DISABLE_CLASS_COPY(Thread);
};

View File

@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define THREADS_HEADER
//
// Determine which threading API we will use
// Determine which threading APIs we will use
//
#if __cplusplus >= 201103L
#define USE_CPP11_THREADS 1
@ -31,11 +31,27 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define USE_POSIX_THREADS 1
#endif
#if defined(_WIN32)
// Prefer critical section API because std::mutex is much slower on Windows
#define USE_WIN_MUTEX 1
#elif __cplusplus >= 201103L
#define USE_CPP11_MUTEX 1
#else
#define USE_POSIX_MUTEX 1
#endif
///////////////
#if USE_CPP11_THREADS
#include <thread>
#elif USE_POSIX_THREADS
#include <pthread.h>
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#endif
#include "threading/mutex.h"

View File

@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string.h>
#include <iostream>
std::map<u16, std::vector<v3s16> > FacePositionCache::m_cache;
UNORDERED_MAP<u16, std::vector<v3s16> > FacePositionCache::m_cache;
Mutex FacePositionCache::m_cache_mutex;
// Calculate the borders of a "d-radius" cube
// TODO: Make it work without mutex and data races, probably thread-local

View File

@ -26,8 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "../irr_v3d.h"
#include "../irr_aabb3d.h"
#include "../threading/mutex.h"
#include "cpp11_container.h"
#include <list>
#include <map>
#include <vector>
@ -41,26 +41,10 @@ public:
static std::vector<v3s16> getFacePositions(u16 d);
private:
static void generateFacePosition(u16 d);
static std::map<u16, std::vector<v3s16> > m_cache;
static UNORDERED_MAP<u16, std::vector<v3s16> > m_cache;
static Mutex m_cache_mutex;
};
class IndentationRaiser
{
public:
IndentationRaiser(u16 *indentation)
{
m_indentation = indentation;
(*m_indentation)++;
}
~IndentationRaiser()
{
(*m_indentation)--;
}
private:
u16 *m_indentation;
};
inline s16 getContainerPos(s16 p, s16 d)
{
return (p>=0 ? p : p-d+1) / d;
@ -149,23 +133,6 @@ inline bool isInArea(v3s16 p, v3s16 d)
#define rangelim(d, min, max) ((d) < (min) ? (min) : ((d)>(max)?(max):(d)))
#define myfloor(x) ((x) > 0.0 ? (int)(x) : (int)(x) - 1)
inline v3s16 arealim(v3s16 p, s16 d)
{
if(p.X < 0)
p.X = 0;
if(p.Y < 0)
p.Y = 0;
if(p.Z < 0)
p.Z = 0;
if(p.X > d-1)
p.X = d-1;
if(p.Y > d-1)
p.Y = d-1;
if(p.Z > d-1)
p.Z = d-1;
return p;
}
// The naive swap performs better than the xor version
#define SWAP(t, x, y) do { \
t temp = x; \

View File

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define UTIL_STRING_HEADER
#include "irrlichttypes_bloated.h"
#include "cpp11_container.h"
#include <stdlib.h>
#include <string>
#include <cstring>
@ -54,7 +55,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
(((unsigned char)(x) < 0xe0) ? 2 : \
(((unsigned char)(x) < 0xf0) ? 3 : 4))
typedef std::map<std::string, std::string> StringMap;
typedef UNORDERED_MAP<std::string, std::string> StringMap;
struct FlagDesc {
const char *name;