g_menuclouds->setHeight(100.0f);
g_menuclouds->update(v3f(0, 0, 0), video::SColor(255, 200, 200, 255));
scene::ICameraSceneNode* camera;
- camera = g_menucloudsmgr->addCameraSceneNode(0,
- v3f(0, 0, 0), v3f(0, 60, 100));
+ camera = g_menucloudsmgr->addCameraSceneNode(NULL, v3f(0, 0, 0), v3f(0, 60, 100));
camera->setFarValue(10000);
/*
if (!game_has_run) {
if (skip_main_menu)
break;
- else
- continue;
+
+ continue;
}
// Break out of menu-game loop to shut down cleanly
if (!RenderingEngine::get_raw_device()->run() || *kill) {
- if (g_settings_path != "")
+ if (!g_settings_path.empty())
g_settings->updateConfigFile(g_settings_path.c_str());
break;
}
* supplied on the command line
*/
address = g_settings->get("address");
- if (game_params.world_path != "" && !skip_main_menu)
+ if (!game_params.world_path.empty() && !skip_main_menu)
address = "";
else if (cmd_args.exists("address"))
address = cmd_args.get("address");
menudata.password = cmd_args.get("password");
// If a world was commanded, append and select it
- if (game_params.world_path != "") {
+ if (!game_params.world_path.empty()) {
worldspec.gameid = getWorldGameId(game_params.world_path, true);
worldspec.name = _("[--world parameter]");
- if (worldspec.gameid == "") { // Create new
+ if (worldspec.gameid.empty()) { // Create new
worldspec.gameid = g_settings->get("default_game");
worldspec.name += " [new]";
}
return false;
}
- if (menudata.name == "" && !simple_singleplayer_mode) {
+ if (menudata.name.empty() && !simple_singleplayer_mode) {
error_message = gettext("Please choose a name!");
errorstream << error_message << std::endl;
return false;
// If using simple singleplayer mode, override
if (simple_singleplayer_mode) {
- assert(skip_main_menu == false);
+ assert(!skip_main_menu);
current_playername = "singleplayer";
current_password = "";
current_address = "";
current_port = myrand_range(49152, 65535);
} else {
g_settings->set("name", playername);
- if (address != "") {
+ if (!address.empty()) {
ServerListSpec server;
server["name"] = menudata.servername;
server["address"] = menudata.address;
infostream << "Selected world: " << worldspec.name
<< " [" << worldspec.path << "]" << std::endl;
- if (current_address == "") { // If local game
- if (worldspec.path == "") {
+ if (current_address.empty()) { // If local game
+ if (worldspec.path.empty()) {
error_message = gettext("No world selected and no address "
"provided. Nothing to do.");
errorstream << error_message << std::endl;
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
infostream << "Waiting for other menus" << std::endl;
- while (RenderingEngine::get_raw_device()->run() && *kill == false) {
+ while (RenderingEngine::get_raw_device()->run() && !*kill) {
if (!isMenuActive())
break;
driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
class ClientLauncher
{
public:
- ClientLauncher() {}
+ ClientLauncher() = default;
~ClientLauncher();
};
assert(event.LogEvent.Level < ARRLEN(irr_loglev_conv));
g_logger.log(irr_loglev_conv[event.LogEvent.Level],
- std::string("Irrlicht: ") +
- (const char *)event.LogEvent.Text);
+ std::string("Irrlicht: ") + event.LogEvent.Text);
return true;
}
/* always return false in order to continue processing events */
class InputHandler
{
public:
- InputHandler() {}
- virtual ~InputHandler() {}
+ InputHandler() = default;
+
+ virtual ~InputHandler() = default;
virtual bool isKeyDown(const KeyPress &keyCode) = 0;
virtual bool wasKeyDown(const KeyPress &keyCode) = 0;
return RenderingEngine::get_raw_device()
->getCursorControl()
->getPosition();
- } else {
- return m_mousepos;
}
+
+ return m_mousepos;
+
}
virtual void setMousePos(s32 x, s32 y)
{
class RandomInputHandler : public InputHandler
{
public:
- RandomInputHandler() {}
+ RandomInputHandler() = default;
+
virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
virtual v2s32 getMousePos() { return mousepos; }
}
// spares many characters
-#define JLO_B_PB(A, B, C) jlo.button_keys.push_back(JoystickButtonCmb(A, B, C))
-#define JLO_A_PB(A, B, C, D) jlo.axis_keys.push_back(JoystickAxisCmb(A, B, C, D))
+#define JLO_B_PB(A, B, C) jlo.button_keys.emplace_back(A, B, C)
+#define JLO_A_PB(A, B, C, D) jlo.axis_keys.emplace_back(A, B, C, D)
JoystickLayout create_default_layout()
{
JoystickController::JoystickController() :
doubling_dtime(g_settings->getFloat("repeat_joystick_button_time"))
{
- for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
- m_past_pressed_time[i] = 0;
+ for (float &i : m_past_pressed_time) {
+ i = 0;
}
clear();
}
// First generate a list of keys pressed
- for (size_t i = 0; i < m_layout.button_keys.size(); i++) {
- if (m_layout.button_keys[i].isTriggered(ev)) {
- keys_pressed.set(m_layout.button_keys[i].key);
+ for (const auto &button_key : m_layout.button_keys) {
+ if (button_key.isTriggered(ev)) {
+ keys_pressed.set(button_key.key);
}
}
- for (size_t i = 0; i < m_layout.axis_keys.size(); i++) {
- if (m_layout.axis_keys[i].isTriggered(ev)) {
- keys_pressed.set(m_layout.axis_keys[i].key);
+ for (const auto &axis_key : m_layout.axis_keys) {
+ if (axis_key.isTriggered(ev)) {
+ keys_pressed.set(axis_key.key);
}
}
struct JoystickButtonCmb : public JoystickCombination {
- JoystickButtonCmb() {}
+ JoystickButtonCmb() = default;
+
JoystickButtonCmb(GameKeyType key, u32 filter_mask, u32 compare_mask) :
filter_mask(filter_mask),
compare_mask(compare_mask)
struct JoystickAxisCmb : public JoystickCombination {
- JoystickAxisCmb() {}
+ JoystickAxisCmb() = default;
+
JoystickAxisCmb(GameKeyType key, u16 axis_to_compare, int direction, s16 thresh) :
axis_to_compare(axis_to_compare),
direction(direction),
for (s32 i = 0; i != num_modes; i++) {
core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
u32 mode_depth = (u32)modelist->getVideoModeDepth(i);
- mlist.push_back(core::vector3d<u32>(
- mode_res.Width, mode_res.Height, mode_depth));
+ mlist.emplace_back(mode_res.Width, mode_res.Height, mode_depth);
}
nulldevice->drop();
#include "util/string.h"
#include "util/container.h"
#include "util/thread.h"
-#include "util/numeric.h"
-#include "irrlichttypes_extrabloated.h"
-#include "debug.h"
#include "filesys.h"
#include "settings.h"
#include "mesh.h"
-#include "log.h"
#include "gamedef.h"
#include "util/strfnd.h"
-#include "util/string.h" // for parseColorString()
#include "imagefilters.h"
#include "guiscalingfilter.h"
-#include "nodedef.h"
#include "renderingengine.h"
NULL
};
// If there is no extension, add one
- if (removeStringEnd(path, extensions) == "")
+ if (removeStringEnd(path, extensions).empty())
path = path + ".png";
// Check paths until something is found to exist
const char **ext = extensions;
do{
bool r = replace_ext(path, *ext);
- if (r == false)
+ if (!r)
return "";
if (fs::PathExists(path))
return path;
*/
std::string getTexturePath(const std::string &filename)
{
- std::string fullpath = "";
+ std::string fullpath;
/*
Check from cache
*/
Check from texture_path
*/
const std::string &texture_path = g_settings->get("texture_path");
- if (texture_path != "") {
+ if (!texture_path.empty()) {
std::string testpath = texture_path + DIR_DELIM + filename;
// Check all filename extensions. Returns "" if not found.
fullpath = getImagePath(testpath);
/*
Check from default data directory
*/
- if (fullpath == "")
+ if (fullpath.empty())
{
std::string base_path = porting::path_share + DIR_DELIM + "textures"
+ DIR_DELIM + "base" + DIR_DELIM + "pack";
{
public:
~SourceImageCache() {
- for (std::map<std::string, video::IImage*>::iterator iter = m_images.begin();
- iter != m_images.end(); ++iter) {
- iter->second->drop();
+ for (auto &m_image : m_images) {
+ m_image.second->drop();
}
m_images.clear();
}
// Try to use local texture instead if asked to
if (prefer_local){
std::string path = getTexturePath(name);
- if (path != ""){
+ if (!path.empty()) {
video::IImage *img2 = RenderingEngine::get_video_driver()->
createImageFromFile(path.c_str());
if (img2){
}
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
std::string path = getTexturePath(name);
- if (path == ""){
+ if (path.empty()) {
infostream<<"SourceImageCache::getOrLoad(): No path found for \""
<<name<<"\""<<std::endl;
return NULL;
if (cache_found)
return is_known;
// Not found in cache; find out if a local file exists
- is_known = (getTexturePath(name) != "");
+ is_known = (!getTexturePath(name).empty());
m_source_image_existence.set(name, is_known);
return is_known;
}
m_main_thread = std::this_thread::get_id();
// Add a NULL TextureInfo as the first index, named ""
- m_textureinfo_cache.push_back(TextureInfo(""));
+ m_textureinfo_cache.emplace_back("");
m_name_to_id[""] = 0;
// Cache some settings
unsigned int textures_before = driver->getTextureCount();
- for (std::vector<TextureInfo>::iterator iter =
- m_textureinfo_cache.begin();
- iter != m_textureinfo_cache.end(); ++iter)
- {
+ for (const auto &iter : m_textureinfo_cache) {
//cleanup texture
- if (iter->texture)
- driver->removeTexture(iter->texture);
+ if (iter.texture)
+ driver->removeTexture(iter.texture);
}
m_textureinfo_cache.clear();
- for (std::vector<video::ITexture*>::iterator iter =
- m_texture_trash.begin(); iter != m_texture_trash.end();
- ++iter) {
- video::ITexture *t = *iter;
-
+ for (auto t : m_texture_trash) {
//cleanup trashed texture
driver->removeTexture(t);
}
//infostream << "generateTexture(): name=\"" << name << "\"" << std::endl;
// Empty name means texture 0
- if (name == "") {
+ if (name.empty()) {
infostream<<"generateTexture(): name is empty"<<std::endl;
return 0;
}
if (name == "")
return NULL;
- std::unordered_map<std::string, Palette>::iterator it = m_palettes.find(name);
+ auto it = m_palettes.find(name);
if (it == m_palettes.end()) {
// Create palette
video::IImage *img = generateImage(name);
img->drop();
// Fill in remaining elements
while (new_palette.size() < 256)
- new_palette.push_back(video::SColor(0xFFFFFFFF));
+ new_palette.emplace_back(0xFFFFFFFF);
m_palettes[name] = new_palette;
it = m_palettes.find(name);
}
sanity_check(driver);
// Recreate textures
- for (u32 i=0; i<m_textureinfo_cache.size(); i++){
- TextureInfo *ti = &m_textureinfo_cache[i];
- video::IImage *img = generateImage(ti->name);
+ for (TextureInfo &ti : m_textureinfo_cache) {
+ video::IImage *img = generateImage(ti.name);
#ifdef __ANDROID__
img = Align2Npot2(img, driver);
#endif
// Create texture from resulting image
video::ITexture *t = NULL;
if (img) {
- t = driver->addTexture(ti->name.c_str(), img);
- guiScalingCache(io::path(ti->name.c_str()), driver, img);
+ t = driver->addTexture(ti.name.c_str(), img);
+ guiScalingCache(io::path(ti.name.c_str()), driver, img);
img->drop();
}
- video::ITexture *t_old = ti->texture;
+ video::ITexture *t_old = ti.texture;
// Replace texture
- ti->texture = t;
+ ti.texture = t;
if (t_old)
m_texture_trash.push_back(t_old);
sanity_check(driver);
// Stuff starting with [ are special commands
- if (part_of_name.size() == 0 || part_of_name[0] != '[')
- {
+ if (part_of_name.empty() || part_of_name[0] != '[') {
video::IImage *image = m_sourcecache.getOrLoad(part_of_name);
#ifdef __ANDROID__
image = Align2Npot2(image, driver);
#endif
if (image == NULL) {
- if (part_of_name != "") {
+ if (!part_of_name.empty()) {
// Do not create normalmap dummies
if (part_of_name.find("_normal.png") != std::string::npos) {
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
baseimg->fill(video::SColor(0,0,0,0));
}
- while (sf.at_end() == false) {
+ while (!sf.at_end()) {
u32 x = stoi(sf.next(","));
u32 y = stoi(sf.next("="));
std::string filename = unescape_string(sf.next_esc(":", escape), escape);
std::string mode = sf.next("");
u32 mask = 0;
- if (mode.find("a") != std::string::npos)
+ if (mode.find('a') != std::string::npos)
mask |= 0xff000000UL;
- if (mode.find("r") != std::string::npos)
+ if (mode.find('r') != std::string::npos)
mask |= 0x00ff0000UL;
- if (mode.find("g") != std::string::npos)
+ if (mode.find('g') != std::string::npos)
mask |= 0x0000ff00UL;
- if (mode.find("b") != std::string::npos)
+ if (mode.find('b') != std::string::npos)
mask |= 0x000000ffUL;
core::dimension2d<u32> dim = baseimg->getDimension();
pos++;
break;
}
- else if (!(name_i.empty()) &&
- lowercase(s.substr(pos, name_i.size())) == name_i)
- {
+
+ if (!(name_i.empty()) && lowercase(s.substr(pos, name_i.size())) == name_i) {
transform = i;
pos += name_i.size();
break;
{
if (transform % 2 == 0)
return dim;
- else
- return core::dimension2d<u32>(dim.Height, dim.Width);
+
+ return core::dimension2d<u32>(dim.Height, dim.Width);
}
void imageTransform(u32 transform, video::IImage *src, video::IImage *dst)
std::string fname_base = name;
static const char *normal_ext = "_normal.png";
static const u32 normal_ext_size = strlen(normal_ext);
- size_t pos = fname_base.find(".");
+ size_t pos = fname_base.find('.');
std::string fname_normal = fname_base.substr(0, pos) + normal_ext;
if (isKnownSourceImage(fname_normal)) {
// look for image extension and replace it
size_t i = 0;
- while ((i = fname_base.find(".", i)) != std::string::npos) {
+ while ((i = fname_base.find('.', i)) != std::string::npos) {
fname_base.replace(i, 4, normal_ext);
i += normal_ext_size;
}
if (isKnownSourceImage(tname)) {
return getTexture(tname);
- } else {
- video::IVideoDriver *driver = RenderingEngine::get_video_driver();
- video::IImage *flags_image = driver->createImage(
- video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1));
- sanity_check(flags_image != NULL);
- video::SColor c(255, normalmap_present ? 255 : 0, 0, 0);
- flags_image->setPixel(0, 0, c);
- insertSourceImage(tname, flags_image);
- flags_image->drop();
- return getTexture(tname);
}
+
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
+ video::IImage *flags_image = driver->createImage(
+ video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1));
+ sanity_check(flags_image != NULL);
+ video::SColor c(255, normalmap_present ? 255 : 0, 0, 0);
+ flags_image->setPixel(0, 0, c);
+ insertSourceImage(tname, flags_image);
+ flags_image->drop();
+ return getTexture(tname);
+
}
class ISimpleTextureSource
{
public:
- ISimpleTextureSource(){}
- virtual ~ISimpleTextureSource(){}
+ ISimpleTextureSource() = default;
+
+ virtual ~ISimpleTextureSource() = default;
+
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr) = 0;
};
class ITextureSource : public ISimpleTextureSource
{
public:
- ITextureSource(){}
- virtual ~ITextureSource(){}
+ ITextureSource() = default;
+
+ virtual ~ITextureSource() = default;
+
virtual u32 getTextureId(const std::string &name)=0;
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
class IWritableTextureSource : public ITextureSource
{
public:
- IWritableTextureSource(){}
- virtual ~IWritableTextureSource(){}
+ IWritableTextureSource() = default;
+
+ virtual ~IWritableTextureSource() = default;
+
virtual u32 getTextureId(const std::string &name)=0;
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
// Ignored if MATERIAL_FLAG_CRACK is not set.
#define MATERIAL_FLAG_CRACK_OVERLAY 0x04
#define MATERIAL_FLAG_ANIMATION 0x08
-#define MATERIAL_FLAG_HIGHLIGHTED 0x10
+//#define MATERIAL_FLAG_HIGHLIGHTED 0x10
#define MATERIAL_FLAG_TILEABLE_HORIZONTAL 0x20
#define MATERIAL_FLAG_TILEABLE_VERTICAL 0x40
*/
struct FrameSpec
{
- FrameSpec() {}
+ FrameSpec() = default;
+
u32 texture_id = 0;
video::ITexture *texture = nullptr;
video::ITexture *normal_texture = nullptr;
//! Defines a layer of a tile.
struct TileLayer
{
- TileLayer() {}
+ TileLayer() = default;
/*!
* Two layers are equal if they can be merged.
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break;
}
- material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
- ? true : false;
+ material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
}
void applyMaterialOptionsWithShaders(video::SMaterial &material) const
{
- material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
- ? true : false;
+ material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
material.TextureLayer[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE;