aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ban.cpp49
-rw-r--r--src/ban.h5
-rw-r--r--src/client.cpp31
-rw-r--r--src/client.h8
-rw-r--r--src/content_mapnode.cpp11
-rw-r--r--src/game.cpp26
-rw-r--r--src/guiEngine.cpp2
-rw-r--r--src/guiEngine.h2
-rw-r--r--src/guiFileSelectMenu.cpp2
-rw-r--r--src/guiFormSpecMenu.cpp2
-rw-r--r--src/guiFormSpecMenu.h2
-rw-r--r--src/httpfetch.cpp9
-rw-r--r--src/httpfetch.h5
-rw-r--r--src/itemdef.cpp51
-rw-r--r--src/network/serverpackethandler.cpp8
-rw-r--r--src/nodemetadata.cpp16
-rw-r--r--src/nodemetadata.h9
-rw-r--r--src/script/cpp_api/s_mainmenu.cpp6
-rw-r--r--src/script/cpp_api/s_mainmenu.h4
-rw-r--r--src/script/cpp_api/s_node.cpp6
-rw-r--r--src/script/cpp_api/s_node.h5
-rw-r--r--src/script/cpp_api/s_player.cpp21
-rw-r--r--src/script/cpp_api/s_player.h10
-rw-r--r--src/script/lua_api/l_nodemeta.cpp22
-rw-r--r--src/shader.cpp61
25 files changed, 180 insertions, 193 deletions
diff --git a/src/ban.cpp b/src/ban.cpp
index 55d9b22fe..7c1a68d45 100644
--- a/src/ban.cpp
+++ b/src/ban.cpp
@@ -56,7 +56,7 @@ void BanManager::load()
infostream<<"BanManager: failed loading from "<<m_banfilepath<<std::endl;
throw SerializationError("BanManager::load(): Couldn't open file");
}
-
+
while(!is.eof() && is.good())
{
std::string line;
@@ -74,18 +74,14 @@ void BanManager::load()
void BanManager::save()
{
JMutexAutoLock lock(m_mutex);
- infostream<<"BanManager: saving to "<<m_banfilepath<<std::endl;
+ infostream << "BanManager: saving to " << m_banfilepath << std::endl;
std::ostringstream ss(std::ios_base::binary);
- for(std::map<std::string, std::string>::iterator
- i = m_ips.begin();
- i != m_ips.end(); i++)
- {
- ss << i->first << "|" << i->second << "\n";
- }
+ for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it)
+ ss << it->first << "|" << it->second << "\n";
- if(!fs::safeWriteToFile(m_banfilepath, ss.str())) {
- infostream<<"BanManager: failed saving to "<<m_banfilepath<<std::endl;
+ if (!fs::safeWriteToFile(m_banfilepath, ss.str())) {
+ infostream << "BanManager: failed saving to " << m_banfilepath << std::endl;
throw SerializationError("BanManager::save(): Couldn't write file");
}
@@ -102,25 +98,23 @@ std::string BanManager::getBanDescription(const std::string &ip_or_name)
{
JMutexAutoLock lock(m_mutex);
std::string s = "";
- for(std::map<std::string, std::string>::iterator
- i = m_ips.begin();
- i != m_ips.end(); i++)
- {
- if(i->first == ip_or_name || i->second == ip_or_name
- || ip_or_name == "")
- s += i->first + "|" + i->second + ", ";
+ for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it) {
+ if (it->first == ip_or_name || it->second == ip_or_name
+ || ip_or_name == "") {
+ s += it->first + "|" + it->second + ", ";
+ }
}
- s = s.substr(0, s.size()-2);
+ s = s.substr(0, s.size() - 2);
return s;
}
std::string BanManager::getBanName(const std::string &ip)
{
JMutexAutoLock lock(m_mutex);
- std::map<std::string, std::string>::iterator i = m_ips.find(ip);
- if(i == m_ips.end())
+ StringMap::iterator it = m_ips.find(ip);
+ if (it == m_ips.end())
return "";
- return i->second;
+ return it->second;
}
void BanManager::add(const std::string &ip, const std::string &name)
@@ -133,19 +127,16 @@ void BanManager::add(const std::string &ip, const std::string &name)
void BanManager::remove(const std::string &ip_or_name)
{
JMutexAutoLock lock(m_mutex);
- for(std::map<std::string, std::string>::iterator
- i = m_ips.begin();
- i != m_ips.end();)
- {
- if((i->first == ip_or_name) || (i->second == ip_or_name)) {
- m_ips.erase(i++);
+ for (StringMap::iterator it = m_ips.begin(); it != m_ips.end();) {
+ if ((it->first == ip_or_name) || (it->second == ip_or_name)) {
+ m_ips.erase(it++);
} else {
- ++i;
+ ++it;
}
}
m_modified = true;
}
-
+
bool BanManager::isModified()
{
diff --git a/src/ban.h b/src/ban.h
index 02a472f51..5db7179de 100644
--- a/src/ban.h
+++ b/src/ban.h
@@ -20,8 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef BAN_HEADER
#define BAN_HEADER
-#include <map>
-#include <string>
+#include "util/string.h"
#include "jthread/jthread.h"
#include "jthread/jmutex.h"
#include "exceptions.h"
@@ -43,7 +42,7 @@ public:
private:
JMutex m_mutex;
std::string m_banfilepath;
- std::map<std::string, std::string> m_ips;
+ StringMap m_ips;
bool m_modified;
};
diff --git a/src/client.cpp b/src/client.cpp
index 1d0245c45..de8131875 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1102,7 +1102,7 @@ void Client::sendRemovedSounds(std::vector<s32> &soundList)
}
void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
- const std::map<std::string, std::string> &fields)
+ const StringMap &fields)
{
size_t fields_size = fields.size();
@@ -1112,10 +1112,10 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
pkt << p << formname << (u16) (fields_size & 0xFFFF);
- for(std::map<std::string, std::string>::const_iterator
- i = fields.begin(); i != fields.end(); i++) {
- const std::string &name = i->first;
- const std::string &value = i->second;
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
+ const std::string &name = it->first;
+ const std::string &value = it->second;
pkt << name;
pkt.putLongString(value);
}
@@ -1124,7 +1124,7 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
}
void Client::sendInventoryFields(const std::string &formname,
- const std::map<std::string, std::string> &fields)
+ const StringMap &fields)
{
size_t fields_size = fields.size();
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields");
@@ -1132,10 +1132,10 @@ void Client::sendInventoryFields(const std::string &formname,
NetworkPacket pkt(TOSERVER_INVENTORY_FIELDS, 0);
pkt << formname << (u16) (fields_size & 0xFFFF);
- for(std::map<std::string, std::string>::const_iterator
- i = fields.begin(); i != fields.end(); i++) {
- const std::string &name = i->first;
- const std::string &value = i->second;
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
+ const std::string &name = it->first;
+ const std::string &value = it->second;
pkt << name;
pkt.putLongString(value);
}
@@ -1918,14 +1918,13 @@ ParticleManager* Client::getParticleManager()
scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
{
- std::map<std::string, std::string>::const_iterator i =
- m_mesh_data.find(filename);
- if(i == m_mesh_data.end()){
- errorstream<<"Client::getMesh(): Mesh not found: \""<<filename<<"\""
- <<std::endl;
+ StringMap::const_iterator it = m_mesh_data.find(filename);
+ if (it == m_mesh_data.end()) {
+ errorstream << "Client::getMesh(): Mesh not found: \"" << filename
+ << "\"" << std::endl;
return NULL;
}
- const std::string &data = i->second;
+ const std::string &data = it->second;
scene::ISceneManager *smgr = m_device->getSceneManager();
// Create the mesh, remove it from cache and return it
diff --git a/src/client.h b/src/client.h
index 87cf8ce45..56f040909 100644
--- a/src/client.h
+++ b/src/client.h
@@ -405,13 +405,13 @@ public:
void interact(u8 action, const PointedThing& pointed);
void sendNodemetaFields(v3s16 p, const std::string &formname,
- const std::map<std::string, std::string> &fields);
+ const StringMap &fields);
void sendInventoryFields(const std::string &formname,
- const std::map<std::string, std::string> &fields);
+ const StringMap &fields);
void sendInventoryAction(InventoryAction *a);
void sendChatMessage(const std::wstring &message);
void sendChangePassword(const std::string &oldpassword,
- const std::string &newpassword);
+ const std::string &newpassword);
void sendDamage(u8 damage);
void sendBreath(u16 breath);
void sendRespawn();
@@ -648,7 +648,7 @@ private:
std::map<std::string, Inventory*> m_detached_inventories;
// Storage for mesh data for creating multiple instances of the same mesh
- std::map<std::string, std::string> m_mesh_data;
+ StringMap m_mesh_data;
// own state
LocalClientState m_state;
diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp
index 44d0b8e38..5e2a5c816 100644
--- a/src/content_mapnode.cpp
+++ b/src/content_mapnode.cpp
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h"
#include "nodedef.h"
#include "nameidmapping.h"
-#include <map>
+#include "util/string.h"
/*
Legacy node content type IDs
@@ -218,14 +218,13 @@ public:
}
std::string get(const std::string &old)
{
- std::map<std::string, std::string>::const_iterator i;
- i = old_to_new.find(old);
- if(i == old_to_new.end())
+ StringMap::const_iterator it = old_to_new.find(old);
+ if (it == old_to_new.end())
return "";
- return i->second;
+ return it->second;
}
private:
- std::map<std::string, std::string> old_to_new;
+ StringMap old_to_new;
};
NewNameGetter newnamegetter;
diff --git a/src/game.cpp b/src/game.cpp
index e27ec37dd..7e3ab802c 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -87,11 +87,11 @@ struct TextDestNodeMetadata : public TextDest {
std::string ntext = wide_to_narrow(text);
infostream << "Submitting 'text' field of node at (" << m_p.X << ","
<< m_p.Y << "," << m_p.Z << "): " << ntext << std::endl;
- std::map<std::string, std::string> fields;
+ StringMap fields;
fields["text"] = ntext;
m_client->sendNodemetaFields(m_p, "", fields);
}
- void gotText(std::map<std::string, std::string> fields)
+ void gotText(const StringMap &fields)
{
m_client->sendNodemetaFields(m_p, "", fields);
}
@@ -111,7 +111,7 @@ struct TextDestPlayerInventory : public TextDest {
m_client = client;
m_formname = formname;
}
- void gotText(std::map<std::string, std::string> fields)
+ void gotText(const StringMap &fields)
{
m_client->sendInventoryFields(m_formname, fields);
}
@@ -138,7 +138,7 @@ struct LocalFormspecHandler : public TextDest {
errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
}
- void gotText(std::map<std::string, std::string> fields)
+ void gotText(const StringMap &fields)
{
if (m_formname == "MT_PAUSE_MENU") {
if (fields.find("btn_sound") != fields.end()) {
@@ -180,9 +180,9 @@ struct LocalFormspecHandler : public TextDest {
if ((fields.find("btn_send") != fields.end()) ||
(fields.find("quit") != fields.end())) {
- if (fields.find("f_text") != fields.end()) {
- m_client->typeChatMessage(narrow_to_wide(fields["f_text"]));
- }
+ StringMap::const_iterator it = fields.find("f_text");
+ if (it != fields.end())
+ m_client->typeChatMessage(narrow_to_wide(it->second));
return;
}
@@ -210,12 +210,14 @@ struct LocalFormspecHandler : public TextDest {
return;
}
- errorstream << "LocalFormspecHandler::gotText unhandled >" << m_formname << "< event" << std::endl;
- int i = 0;
+ errorstream << "LocalFormspecHandler::gotText unhandled >"
+ << m_formname << "< event" << std::endl;
- for (std::map<std::string, std::string>::iterator iter = fields.begin();
- iter != fields.end(); iter++) {
- errorstream << "\t" << i << ": " << iter->first << "=" << iter->second << std::endl;
+ int i = 0;
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
+ errorstream << "\t" << i << ": " << it->first
+ << "=" << it->second << std::endl;
i++;
}
}
diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp
index 752f9ddd2..3248ef112 100644
--- a/src/guiEngine.cpp
+++ b/src/guiEngine.cpp
@@ -53,7 +53,7 @@ TextDestGuiEngine::TextDestGuiEngine(GUIEngine* engine)
}
/******************************************************************************/
-void TextDestGuiEngine::gotText(std::map<std::string, std::string> fields)
+void TextDestGuiEngine::gotText(const StringMap &fields)
{
m_engine->getScriptIface()->handleMainMenuButtons(fields);
}
diff --git a/src/guiEngine.h b/src/guiEngine.h
index e57573220..d527f7222 100644
--- a/src/guiEngine.h
+++ b/src/guiEngine.h
@@ -73,7 +73,7 @@ public:
* receive fields transmitted by guiFormSpecMenu
* @param fields map containing formspec field elements currently active
*/
- void gotText(std::map<std::string, std::string> fields);
+ void gotText(const StringMap &fields);
/**
* receive text/events transmitted by guiFormSpecMenu
diff --git a/src/guiFileSelectMenu.cpp b/src/guiFileSelectMenu.cpp
index e98b025c6..9b43ab602 100644
--- a/src/guiFileSelectMenu.cpp
+++ b/src/guiFileSelectMenu.cpp
@@ -84,7 +84,7 @@ void GUIFileSelectMenu::drawMenu()
void GUIFileSelectMenu::acceptInput() {
if ((m_text_dst != 0) && (this->m_formname != "")){
- std::map<std::string, std::string> fields;
+ StringMap fields;
if (m_accepted)
fields[m_formname + "_accepted"] = wide_to_narrow(m_fileOpenDialog->getFileName());
diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp
index 5f67bb22a..d53c9b3af 100644
--- a/src/guiFormSpecMenu.cpp
+++ b/src/guiFormSpecMenu.cpp
@@ -2579,7 +2579,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
{
if(m_text_dst)
{
- std::map<std::string, std::string> fields;
+ StringMap fields;
if (quitmode == quit_mode_accept) {
fields["quit"] = "true";
diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h
index 73dc7af62..f72595782 100644
--- a/src/guiFormSpecMenu.h
+++ b/src/guiFormSpecMenu.h
@@ -56,7 +56,7 @@ struct TextDest
virtual ~TextDest() {};
// This is deprecated I guess? -celeron55
virtual void gotText(std::wstring text){}
- virtual void gotText(std::map<std::string, std::string> fields) = 0;
+ virtual void gotText(const StringMap &fields) = 0;
virtual void setFormName(std::string formname)
{ m_formname = formname;};
diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp
index c60e141fc..56cdad2b1 100644
--- a/src/httpfetch.cpp
+++ b/src/httpfetch.cpp
@@ -266,8 +266,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
} else if (request.multipart) {
curl_httppost *last = NULL;
- for (std::map<std::string, std::string>::iterator it =
- request.post_fields.begin();
+ for (StringMap::iterator it = request.post_fields.begin();
it != request.post_fields.end(); ++it) {
curl_formadd(&post, &last,
CURLFORM_NAMELENGTH, it->first.size(),
@@ -282,10 +281,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
} else if (request.post_data.empty()) {
curl_easy_setopt(curl, CURLOPT_POST, 1);
std::string str;
- for (std::map<std::string, std::string>::iterator it =
- request.post_fields.begin();
- it != request.post_fields.end();
- ++it) {
+ for (StringMap::iterator it = request.post_fields.begin();
+ it != request.post_fields.end(); ++it) {
if (str != "")
str += "&";
str += urlencode(it->first);
diff --git a/src/httpfetch.h b/src/httpfetch.h
index 50a4c93d8..c44c8d2d3 100644
--- a/src/httpfetch.h
+++ b/src/httpfetch.h
@@ -20,9 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef HTTPFETCH_HEADER
#define HTTPFETCH_HEADER
-#include <string>
#include <vector>
-#include <map>
+#include "util/string.h"
#include "config.h"
// Can be used in place of "caller" in asynchronous transfers to discard result
@@ -54,7 +53,7 @@ struct HTTPFetchRequest
// POST fields. Fields are escaped properly.
// If this is empty a GET request is done instead.
- std::map<std::string, std::string> post_fields;
+ StringMap post_fields;
// Raw POST data, overrides post_fields.
std::string post_data;
diff --git a/src/itemdef.cpp b/src/itemdef.cpp
index 95c1e47fc..0133b1b3f 100644
--- a/src/itemdef.cpp
+++ b/src/itemdef.cpp
@@ -280,26 +280,23 @@ public:
}
virtual std::string getAlias(const std::string &name) const
{
- std::map<std::string, std::string>::const_iterator i;
- i = m_aliases.find(name);
- if(i != m_aliases.end())
- return i->second;
+ StringMap::const_iterator it = m_aliases.find(name);
+ if (it != m_aliases.end())
+ return it->second;
return name;
}
virtual std::set<std::string> getAll() const
{
std::set<std::string> result;
- for(std::map<std::string, ItemDefinition*>::const_iterator
- i = m_item_definitions.begin();
- i != m_item_definitions.end(); i++)
- {
- result.insert(i->first);
+ for(std::map<std::string, ItemDefinition *>::const_iterator
+ it = m_item_definitions.begin();
+ it != m_item_definitions.end(); ++it) {
+ result.insert(it->first);
}
- for(std::map<std::string, std::string>::const_iterator
- i = m_aliases.begin();
- i != m_aliases.end(); i++)
- {
- result.insert(i->first);
+ for (StringMap::const_iterator
+ it = m_aliases.begin();
+ it != m_aliases.end(); ++it) {
+ result.insert(it->first);
}
return result;
}
@@ -571,22 +568,24 @@ public:
writeU8(os, 0); // version
u16 count = m_item_definitions.size();
writeU16(os, count);
- for(std::map<std::string, ItemDefinition*>::const_iterator
- i = m_item_definitions.begin();
- i != m_item_definitions.end(); i++)
- {
- ItemDefinition *def = i->second;
+
+ for (std::map<std::string, ItemDefinition *>::const_iterator
+ it = m_item_definitions.begin();
+ it != m_item_definitions.end(); ++it) {
+ ItemDefinition *def = it->second;
// Serialize ItemDefinition and write wrapped in a string
std::ostringstream tmp_os(std::ios::binary);
def->serialize(tmp_os, protocol_version);
- os<<serializeString(tmp_os.str());
+ os << serializeString(tmp_os.str());
}
+
writeU16(os, m_aliases.size());
- for(std::map<std::string, std::string>::const_iterator
- i = m_aliases.begin(); i != m_aliases.end(); i++)
- {
- os<<serializeString(i->first);
- os<<serializeString(i->second);
+
+ for (StringMap::const_iterator
+ it = m_aliases.begin();
+ it != m_aliases.end(); ++it) {
+ os << serializeString(it->first);
+ os << serializeString(it->second);
}
}
void deSerialize(std::istream &is)
@@ -633,7 +632,7 @@ private:
// Key is name
std::map<std::string, ItemDefinition*> m_item_definitions;
// Aliases
- std::map<std::string, std::string> m_aliases;
+ StringMap m_aliases;
#ifndef SERVER
// The id of the thread that is allowed to use irrlicht directly
threadid_t m_main_thread;
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index ea1528c64..f658e106f 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -192,7 +192,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
{
std::string reason;
- if(m_script->on_prejoinplayer(playername, addr_s, reason)) {
+ if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
actionstream << "Server: Player with the name \"" << playerName << "\" "
<< "tried to connect from " << addr_s << " "
<< "but it was disallowed for the following reason: "
@@ -480,7 +480,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
{
std::string reason;
- if (m_script->on_prejoinplayer(playername, addr_s, reason)) {
+ if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
actionstream << "Server: Player with the name \"" << playername << "\" "
<< "tried to connect from " << addr_s << " "
<< "but it was disallowed for the following reason: "
@@ -1742,7 +1742,7 @@ void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt)
*pkt >> p >> formname >> num;
- std::map<std::string, std::string> fields;
+ StringMap fields;
for (u16 k = 0; k < num; k++) {
std::string fieldname;
*pkt >> fieldname;
@@ -1792,7 +1792,7 @@ void Server::handleCommand_InventoryFields(NetworkPacket* pkt)
*pkt >> formname >> num;
- std::map<std::string, std::string> fields;
+ StringMap fields;
for (u16 k = 0; k < num; k++) {
std::string fieldname;
*pkt >> fieldname;
diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp
index bd54d2256..d4da7a5ed 100644
--- a/src/nodemetadata.cpp
+++ b/src/nodemetadata.cpp
@@ -45,10 +45,11 @@ void NodeMetadata::serialize(std::ostream &os) const
{
int num_vars = m_stringvars.size();
writeU32(os, num_vars);
- for(std::map<std::string, std::string>::const_iterator
- i = m_stringvars.begin(); i != m_stringvars.end(); i++){
- os<<serializeString(i->first);
- os<<serializeLongString(i->second);
+ for (StringMap::const_iterator
+ it = m_stringvars.begin();
+ it != m_stringvars.end(); ++it) {
+ os << serializeString(it->first);
+ os << serializeLongString(it->second);
}
m_inventory->serialize(os);
@@ -203,11 +204,10 @@ void NodeMetadataList::clear()
std::string NodeMetadata::getString(const std::string &name,
unsigned short recursion) const
{
- std::map<std::string, std::string>::const_iterator it;
- it = m_stringvars.find(name);
- if (it == m_stringvars.end()) {
+ StringMap::const_iterator it = m_stringvars.find(name);
+ if (it == m_stringvars.end())
return "";
- }
+
return resolveString(it->second, recursion);
}
diff --git a/src/nodemetadata.h b/src/nodemetadata.h
index acd45bdf9..8e84e5af3 100644
--- a/src/nodemetadata.h
+++ b/src/nodemetadata.h
@@ -21,10 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define NODEMETADATA_HEADER
#include "irr_v3d.h"
-#include <string>
#include <iostream>
#include <vector>
-#include <map>
+#include "util/string.h"
/*
NodeMetadata stores arbitary amounts of data for special blocks.
@@ -54,19 +53,19 @@ public:
void setString(const std::string &name, const std::string &var);
// Support variable names in values
std::string resolveString(const std::string &str, unsigned short recursion = 0) const;
- std::map<std::string, std::string> getStrings() const
+ StringMap getStrings() const
{
return m_stringvars;
}
// The inventory
- Inventory* getInventory()
+ Inventory *getInventory()
{
return m_inventory;
}
private:
- std::map<std::string, std::string> m_stringvars;
+ StringMap m_stringvars;
Inventory *m_inventory;
};
diff --git a/src/script/cpp_api/s_mainmenu.cpp b/src/script/cpp_api/s_mainmenu.cpp
index ef8cea6c9..0bb247fa0 100644
--- a/src/script/cpp_api/s_mainmenu.cpp
+++ b/src/script/cpp_api/s_mainmenu.cpp
@@ -53,7 +53,7 @@ void ScriptApiMainMenu::handleMainMenuEvent(std::string text)
scriptError();
}
-void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string> fields)
+void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
@@ -69,8 +69,8 @@ void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string>
// Convert fields to a Lua table
lua_newtable(L);
- std::map<std::string, std::string>::const_iterator it;
- for (it = fields.begin(); it != fields.end(); it++){
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushstring(L, name.c_str());
diff --git a/src/script/cpp_api/s_mainmenu.h b/src/script/cpp_api/s_mainmenu.h
index 53dcd37e9..6994b578b 100644
--- a/src/script/cpp_api/s_mainmenu.h
+++ b/src/script/cpp_api/s_mainmenu.h
@@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define S_MAINMENU_H_
#include "cpp_api/s_base.h"
-#include <map>
+#include "util/string.h"
class ScriptApiMainMenu
: virtual public ScriptApiBase
@@ -43,7 +43,7 @@ public:
* process field data recieved from formspec
* @param fields data in field format
*/
- void handleMainMenuButtons(std::map<std::string, std::string> fields);
+ void handleMainMenuButtons(const StringMap &fields);
};
#endif /* S_MAINMENU_H_ */
diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp
index e3d3fb58b..7df712ca0 100644
--- a/src/script/cpp_api/s_node.cpp
+++ b/src/script/cpp_api/s_node.cpp
@@ -200,7 +200,7 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
void ScriptApiNode::node_on_receive_fields(v3s16 p,
const std::string &formname,
- const std::map<std::string, std::string> &fields,
+ const StringMap &fields,
ServerActiveObject *sender)
{
SCRIPTAPI_PRECHECKHEADER
@@ -220,8 +220,8 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
push_v3s16(L, p); // pos
lua_pushstring(L, formname.c_str()); // formname
lua_newtable(L); // fields
- std::map<std::string, std::string>::const_iterator it;
- for (it = fields.begin(); it != fields.end(); it++){
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); it++) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushstring(L, name.c_str());
diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h
index b3a6c83b5..fe1180cb3 100644
--- a/src/script/cpp_api/s_node.h
+++ b/src/script/cpp_api/s_node.h
@@ -20,11 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef S_NODE_H_
#define S_NODE_H_
-#include <map>
-
#include "irr_v3d.h"
#include "cpp_api/s_base.h"
#include "cpp_api/s_nodemeta.h"
+#include "util/string.h"
struct MapNode;
class ServerActiveObject;
@@ -47,7 +46,7 @@ public:
bool node_on_timer(v3s16 p, MapNode node, f32 dtime);
void node_on_receive_fields(v3s16 p,
const std::string &formname,
- const std::map<std::string, std::string> &fields,
+ const StringMap &fields,
ServerActiveObject *sender);
void node_falling_update(v3s16 p);
void node_falling_update_single(v3s16 p);
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp
index d56766824..9b2c3753c 100644
--- a/src/script/cpp_api/s_player.cpp
+++ b/src/script/cpp_api/s_player.cpp
@@ -83,7 +83,10 @@ bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player)
return positioning_handled_by_some;
}
-bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::string &reason)
+bool ScriptApiPlayer::on_prejoinplayer(
+ const std::string &name,
+ const std::string &ip,
+ std::string *reason)
{
SCRIPTAPI_PRECHECKHEADER
@@ -94,7 +97,7 @@ bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::st
lua_pushstring(L, ip.c_str());
script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_OR);
if (lua_isstring(L, -1)) {
- reason.assign(lua_tostring(L, -1));
+ reason->assign(lua_tostring(L, -1));
return true;
}
return false;
@@ -142,7 +145,7 @@ void ScriptApiPlayer::on_cheat(ServerActiveObject *player,
void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname,
- const std::map<std::string, std::string> &fields)
+ const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
@@ -156,17 +159,19 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
lua_pushstring(L, formname.c_str());
// param 3
lua_newtable(L);
- for(std::map<std::string, std::string>::const_iterator
- i = fields.begin(); i != fields.end(); i++){
- const std::string &name = i->first;
- const std::string &value = i->second;
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
+ const std::string &name = it->first;
+ const std::string &value = it->second;
lua_pushstring(L, name.c_str());
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_OR_SC);
}
-ScriptApiPlayer::~ScriptApiPlayer() {
+
+ScriptApiPlayer::~ScriptApiPlayer()
+{
}
diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h
index a0f764cd5..9c8d1d1ad 100644
--- a/src/script/cpp_api/s_player.h
+++ b/src/script/cpp_api/s_player.h
@@ -20,10 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef S_PLAYER_H_
#define S_PLAYER_H_
-#include <map>
-
#include "cpp_api/s_base.h"
#include "irr_v3d.h"
+#include "util/string.h"
struct ToolCapabilities;
@@ -36,17 +35,16 @@ public:
void on_newplayer(ServerActiveObject *player);
void on_dieplayer(ServerActiveObject *player);
bool on_respawnplayer(ServerActiveObject *player);
- bool on_prejoinplayer(std::string name, std::string ip, std::string &reason);
+ bool on_prejoinplayer(const std::string &name, const std::string &ip,
+ std::string *reason);
void on_joinplayer(ServerActiveObject *player);
void on_leaveplayer(ServerActiveObject *player);
void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
bool on_punchplayer(ServerActiveObject *player,
ServerActiveObject *hitter, float time_from_last_punch,
const ToolCapabilities *toolcap, v3f dir, s16 damage);
-
void on_playerReceiveFields(ServerActiveObject *player,
- const std::string &formname,
- const std::map<std::string, std::string> &fields);
+ const std::string &formname, const StringMap &fields);
};
diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp
index 906cc3172..6cdbe5c68 100644
--- a/src/script/lua_api/l_nodemeta.cpp
+++ b/src/script/lua_api/l_nodemeta.cpp
@@ -190,32 +190,34 @@ int NodeMetaRef::l_to_table(lua_State *L)
NodeMetaRef *ref = checkobject(L, 1);
NodeMetadata *meta = getmeta(ref, true);
- if(meta == NULL){
+ if (meta == NULL) {
lua_pushnil(L);
return 1;
}
lua_newtable(L);
+
// fields
lua_newtable(L);
{
- std::map<std::string, std::string> fields = meta->getStrings();
- for(std::map<std::string, std::string>::const_iterator
- i = fields.begin(); i != fields.end(); i++){
- const std::string &name = i->first;
- const std::string &value = i->second;
+ StringMap fields = meta->getStrings();
+ for (StringMap::const_iterator
+ it = fields.begin(); it != fields.end(); ++it) {
+ const std::string &name = it->first;
+ const std::string &value = it->second;
lua_pushlstring(L, name.c_str(), name.size());
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
}
lua_setfield(L, -2, "fields");
+
// inventory
lua_newtable(L);
Inventory *inv = meta->getInventory();
- if(inv){
- std::vector<const InventoryList*> lists = inv->getLists();
- for(std::vector<const InventoryList*>::const_iterator
- i = lists.begin(); i != lists.end(); i++){
+ if (inv) {
+ std::vector<const InventoryList *> lists = inv->getLists();
+ for(std::vector<const InventoryList *>::const_iterator
+ i = lists.begin(); i != lists.end(); i++) {
push_inventory_list(L, inv, (*i)->getName().c_str());
lua_setfield(L, -2, (*i)->getName().c_str());
}
diff --git a/src/shader.cpp b/src/shader.cpp
index ea2de3f1e..a467c2ea9 100644
--- a/src/shader.cpp
+++ b/src/shader.cpp
@@ -103,10 +103,8 @@ std::string getShaderPath(const std::string &name_of_shader,
class SourceShaderCache
{
public:
- void insert(const std::string &name_of_shader,
- const std::string &filename,
- const std::string &program,
- bool prefer_local)
+ void insert(const std::string &name_of_shader, const std::string &filename,
+ const std::string &program, bool prefer_local)
{
std::string combined = name_of_shader + DIR_DELIM + filename;
// Try to use local shader instead if asked to
@@ -122,42 +120,43 @@ public:
}
m_programs[combined] = program;
}
+
std::string get(const std::string &name_of_shader,
- const std::string &filename)
+ const std::string &filename)
{
std::string combined = name_of_shader + DIR_DELIM + filename;
- std::map<std::string, std::string>::iterator n;
- n = m_programs.find(combined);
- if(n != m_programs.end())
+ StringMap::iterator n = m_programs.find(combined);
+ if (n != m_programs.end())
return n->second;
return "";
}
+
// Primarily fetches from cache, secondarily tries to read from filesystem
std::string getOrLoad(const std::string &name_of_shader,
- const std::string &filename)
+ const std::string &filename)
{
std::string combined = name_of_shader + DIR_DELIM + filename;
- std::map<std::string, std::string>::iterator n;
- n = m_programs.find(combined);
- if(n != m_programs.end())
+ StringMap::iterator n = m_programs.find(combined);
+ if (n != m_programs.end())
return n->second;
std::string path = getShaderPath(name_of_shader, filename);
- if(path == ""){
- infostream<<"SourceShaderCache::getOrLoad(): No path found for \""
- <<combined<<"\""<<std::endl;
+ if (path == "") {
+ infostream << "SourceShaderCache::getOrLoad(): No path found for \""
+ << combined << "\"" << std::endl;
return "";
}
- infostream<<"SourceShaderCache::getOrLoad(): Loading path \""<<path
- <<"\""<<std::endl;
+ infostream << "SourceShaderCache::getOrLoad(): Loading path \""
+ << path << "\"" << std::endl;
std::string p = readFile(path);
- if(p != ""){
+ if (p != "") {
m_programs[combined] = p;
return p;
}
return "";
}
private:
- std::map<std::string, std::string> m_programs;
+ StringMap m_programs;
+
std::string readFile(const std::string &path)
{
std::ifstream is(path.c_str(), std::ios::binary);
@@ -274,23 +273,23 @@ public:
The id 0 points to a null shader. Its material is EMT_SOLID.
*/
- u32 getShaderIdDirect(const std::string &name,
+ u32 getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype);
/*
If shader specified by the name pointed by the id doesn't
- exist, create it, then return id.
+ exist, create it, then return id.
Can be called from any thread. If called from some other thread
and not found in cache, the call is queued to the main thread
for processing.
*/
-
+
u32 getShader(const std::string &name,
const u8 material_type, const u8 drawtype);
-
+
ShaderInfo getShaderInfo(u32 id);
-
+
// Processes queued shader requests from other threads.
// Shall be called from the main thread.
void processQueue();
@@ -391,7 +390,7 @@ ShaderSource::~ShaderSource()
}
}
-u32 ShaderSource::getShader(const std::string &name,
+u32 ShaderSource::getShader(const std::string &name,
const u8 material_type, const u8 drawtype)
{
/*
@@ -435,7 +434,7 @@ u32 ShaderSource::getShader(const std::string &name,
/*
This method generates all the shaders
*/
-u32 ShaderSource::getShaderIdDirect(const std::string &name,
+u32 ShaderSource::getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype)
{
//infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;
@@ -494,7 +493,7 @@ ShaderInfo ShaderSource::getShaderInfo(u32 id)
void ShaderSource::processQueue()
{
-
+
}
@@ -572,7 +571,7 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
}
-
+
bool enable_shaders = g_settings->getBool("enable_shaders");
if(!enable_shaders)
return shaderinfo;
@@ -648,7 +647,7 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
"NDT_FIRELIKE",
"NDT_GLASSLIKE_FRAMED_OPTIONAL"
};
-
+
for (int i = 0; i < 14; i++){
shaders_header += "#define ";
shaders_header += drawTypes[i];
@@ -741,10 +740,10 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
shaders_header += "#define ENABLE_WAVING_LEAVES ";
if (g_settings->getBool("enable_waving_leaves"))
shaders_header += "1\n";
- else
+ else
shaders_header += "0\n";
- shaders_header += "#define ENABLE_WAVING_PLANTS ";
+ shaders_header += "#define ENABLE_WAVING_PLANTS ";
if (g_settings->getBool("enable_waving_plants"))
shaders_header += "1\n";
else