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;
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");
}
{
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)
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()
{
#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"
private:
JMutex m_mutex;
std::string m_banfilepath;
- std::map<std::string, std::string> m_ips;
+ StringMap m_ips;
bool m_modified;
};
}
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();
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);
}
}
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");
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);
}
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
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();
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;
#include "mapnode.h"
#include "nodedef.h"
#include "nameidmapping.h"
-#include <map>
+#include "util/string.h"
/*
Legacy node content type IDs
}
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;
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);
}
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);
}
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()) {
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;
}
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++;
}
}
}
/******************************************************************************/
-void TextDestGuiEngine::gotText(std::map<std::string, std::string> fields)
+void TextDestGuiEngine::gotText(const StringMap &fields)
{
m_engine->getScriptIface()->handleMainMenuButtons(fields);
}
* 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
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());
{
if(m_text_dst)
{
- std::map<std::string, std::string> fields;
+ StringMap fields;
if (quitmode == quit_mode_accept) {
fields["quit"] = "true";
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;};
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(),
} 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);
#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
// 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;
}
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;
}
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)
// 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;
{
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: "
{
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: "
*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;
*pkt >> formname >> num;
- std::map<std::string, std::string> fields;
+ StringMap fields;
for (u16 k = 0; k < num; k++) {
std::string fieldname;
*pkt >> fieldname;
{
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);
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);
}
#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.
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;
};
scriptError();
}
-void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string> fields)
+void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
// 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());
#define S_MAINMENU_H_
#include "cpp_api/s_base.h"
-#include <map>
+#include "util/string.h"
class ScriptApiMainMenu
: virtual public ScriptApiBase
* 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_ */
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
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());
#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;
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);
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
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;
void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname,
- const std::map<std::string, std::string> &fields)
+ const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
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()
+{
}
#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;
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);
};
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());
}
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
}
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);
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();
}
}
-u32 ShaderSource::getShader(const std::string &name,
+u32 ShaderSource::getShader(const std::string &name,
const u8 material_type, const u8 drawtype)
{
/*
/*
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;
void ShaderSource::processQueue()
{
-
+
}
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
}
-
+
bool enable_shaders = g_settings->getBool("enable_shaders");
if(!enable_shaders)
return shaderinfo;
"NDT_FIRELIKE",
"NDT_GLASSLIKE_FRAMED_OPTIONAL"
};
-
+
for (int i = 0; i < 14; i++){
shaders_header += "#define ";
shaders_header += drawTypes[i];
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