Modernize client code (#6250)
* Various code style fixes * Use range based for loops * Use empty instead of empty objects * Use C++11 default keyword for trivial constructors and destructors * Drop some useless casts * Use emplace_back instead of push_back to improve performance of some vectors push
This commit is contained in:
parent
64c7a689ad
commit
9dd0f952e0
@ -132,8 +132,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
|
|||||||
g_menuclouds->setHeight(100.0f);
|
g_menuclouds->setHeight(100.0f);
|
||||||
g_menuclouds->update(v3f(0, 0, 0), video::SColor(255, 200, 200, 255));
|
g_menuclouds->update(v3f(0, 0, 0), video::SColor(255, 200, 200, 255));
|
||||||
scene::ICameraSceneNode* camera;
|
scene::ICameraSceneNode* camera;
|
||||||
camera = g_menucloudsmgr->addCameraSceneNode(0,
|
camera = g_menucloudsmgr->addCameraSceneNode(NULL, v3f(0, 0, 0), v3f(0, 60, 100));
|
||||||
v3f(0, 0, 0), v3f(0, 60, 100));
|
|
||||||
camera->setFarValue(10000);
|
camera->setFarValue(10000);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -192,13 +191,13 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
|
|||||||
if (!game_has_run) {
|
if (!game_has_run) {
|
||||||
if (skip_main_menu)
|
if (skip_main_menu)
|
||||||
break;
|
break;
|
||||||
else
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Break out of menu-game loop to shut down cleanly
|
// Break out of menu-game loop to shut down cleanly
|
||||||
if (!RenderingEngine::get_raw_device()->run() || *kill) {
|
if (!RenderingEngine::get_raw_device()->run() || *kill) {
|
||||||
if (g_settings_path != "")
|
if (!g_settings_path.empty())
|
||||||
g_settings->updateConfigFile(g_settings_path.c_str());
|
g_settings->updateConfigFile(g_settings_path.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -285,7 +284,7 @@ void ClientLauncher::init_args(GameParams &game_params, const Settings &cmd_args
|
|||||||
* supplied on the command line
|
* supplied on the command line
|
||||||
*/
|
*/
|
||||||
address = g_settings->get("address");
|
address = g_settings->get("address");
|
||||||
if (game_params.world_path != "" && !skip_main_menu)
|
if (!game_params.world_path.empty() && !skip_main_menu)
|
||||||
address = "";
|
address = "";
|
||||||
else if (cmd_args.exists("address"))
|
else if (cmd_args.exists("address"))
|
||||||
address = cmd_args.get("address");
|
address = cmd_args.get("address");
|
||||||
@ -355,11 +354,11 @@ bool ClientLauncher::launch_game(std::string &error_message,
|
|||||||
menudata.password = cmd_args.get("password");
|
menudata.password = cmd_args.get("password");
|
||||||
|
|
||||||
// If a world was commanded, append and select it
|
// 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.gameid = getWorldGameId(game_params.world_path, true);
|
||||||
worldspec.name = _("[--world parameter]");
|
worldspec.name = _("[--world parameter]");
|
||||||
|
|
||||||
if (worldspec.gameid == "") { // Create new
|
if (worldspec.gameid.empty()) { // Create new
|
||||||
worldspec.gameid = g_settings->get("default_game");
|
worldspec.gameid = g_settings->get("default_game");
|
||||||
worldspec.name += " [new]";
|
worldspec.name += " [new]";
|
||||||
}
|
}
|
||||||
@ -400,7 +399,7 @@ bool ClientLauncher::launch_game(std::string &error_message,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menudata.name == "" && !simple_singleplayer_mode) {
|
if (menudata.name.empty() && !simple_singleplayer_mode) {
|
||||||
error_message = gettext("Please choose a name!");
|
error_message = gettext("Please choose a name!");
|
||||||
errorstream << error_message << std::endl;
|
errorstream << error_message << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -416,14 +415,14 @@ bool ClientLauncher::launch_game(std::string &error_message,
|
|||||||
|
|
||||||
// If using simple singleplayer mode, override
|
// If using simple singleplayer mode, override
|
||||||
if (simple_singleplayer_mode) {
|
if (simple_singleplayer_mode) {
|
||||||
assert(skip_main_menu == false);
|
assert(!skip_main_menu);
|
||||||
current_playername = "singleplayer";
|
current_playername = "singleplayer";
|
||||||
current_password = "";
|
current_password = "";
|
||||||
current_address = "";
|
current_address = "";
|
||||||
current_port = myrand_range(49152, 65535);
|
current_port = myrand_range(49152, 65535);
|
||||||
} else {
|
} else {
|
||||||
g_settings->set("name", playername);
|
g_settings->set("name", playername);
|
||||||
if (address != "") {
|
if (!address.empty()) {
|
||||||
ServerListSpec server;
|
ServerListSpec server;
|
||||||
server["name"] = menudata.servername;
|
server["name"] = menudata.servername;
|
||||||
server["address"] = menudata.address;
|
server["address"] = menudata.address;
|
||||||
@ -436,8 +435,8 @@ bool ClientLauncher::launch_game(std::string &error_message,
|
|||||||
infostream << "Selected world: " << worldspec.name
|
infostream << "Selected world: " << worldspec.name
|
||||||
<< " [" << worldspec.path << "]" << std::endl;
|
<< " [" << worldspec.path << "]" << std::endl;
|
||||||
|
|
||||||
if (current_address == "") { // If local game
|
if (current_address.empty()) { // If local game
|
||||||
if (worldspec.path == "") {
|
if (worldspec.path.empty()) {
|
||||||
error_message = gettext("No world selected and no address "
|
error_message = gettext("No world selected and no address "
|
||||||
"provided. Nothing to do.");
|
"provided. Nothing to do.");
|
||||||
errorstream << error_message << std::endl;
|
errorstream << error_message << std::endl;
|
||||||
@ -488,7 +487,7 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
|
|||||||
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
|
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
|
||||||
|
|
||||||
infostream << "Waiting for other menus" << std::endl;
|
infostream << "Waiting for other menus" << std::endl;
|
||||||
while (RenderingEngine::get_raw_device()->run() && *kill == false) {
|
while (RenderingEngine::get_raw_device()->run() && !*kill) {
|
||||||
if (!isMenuActive())
|
if (!isMenuActive())
|
||||||
break;
|
break;
|
||||||
driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
|
driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
|
||||||
|
@ -29,7 +29,7 @@ class RenderingEngine;
|
|||||||
class ClientLauncher
|
class ClientLauncher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClientLauncher() {}
|
ClientLauncher() = default;
|
||||||
|
|
||||||
~ClientLauncher();
|
~ClientLauncher();
|
||||||
|
|
||||||
|
@ -102,8 +102,7 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
|
|||||||
};
|
};
|
||||||
assert(event.LogEvent.Level < ARRLEN(irr_loglev_conv));
|
assert(event.LogEvent.Level < ARRLEN(irr_loglev_conv));
|
||||||
g_logger.log(irr_loglev_conv[event.LogEvent.Level],
|
g_logger.log(irr_loglev_conv[event.LogEvent.Level],
|
||||||
std::string("Irrlicht: ") +
|
std::string("Irrlicht: ") + event.LogEvent.Text);
|
||||||
(const char *)event.LogEvent.Text);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* always return false in order to continue processing events */
|
/* always return false in order to continue processing events */
|
||||||
|
@ -180,8 +180,9 @@ private:
|
|||||||
class InputHandler
|
class InputHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InputHandler() {}
|
InputHandler() = default;
|
||||||
virtual ~InputHandler() {}
|
|
||||||
|
virtual ~InputHandler() = default;
|
||||||
|
|
||||||
virtual bool isKeyDown(const KeyPress &keyCode) = 0;
|
virtual bool isKeyDown(const KeyPress &keyCode) = 0;
|
||||||
virtual bool wasKeyDown(const KeyPress &keyCode) = 0;
|
virtual bool wasKeyDown(const KeyPress &keyCode) = 0;
|
||||||
@ -243,9 +244,10 @@ public:
|
|||||||
return RenderingEngine::get_raw_device()
|
return RenderingEngine::get_raw_device()
|
||||||
->getCursorControl()
|
->getCursorControl()
|
||||||
->getPosition();
|
->getPosition();
|
||||||
} else {
|
|
||||||
return m_mousepos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return m_mousepos;
|
||||||
|
|
||||||
}
|
}
|
||||||
virtual void setMousePos(s32 x, s32 y)
|
virtual void setMousePos(s32 x, s32 y)
|
||||||
{
|
{
|
||||||
@ -287,7 +289,8 @@ private:
|
|||||||
class RandomInputHandler : public InputHandler
|
class RandomInputHandler : public InputHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RandomInputHandler() {}
|
RandomInputHandler() = default;
|
||||||
|
|
||||||
virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
|
virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
|
||||||
virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
|
virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
|
||||||
virtual v2s32 getMousePos() { return mousepos; }
|
virtual v2s32 getMousePos() { return mousepos; }
|
||||||
|
@ -41,8 +41,8 @@ bool JoystickAxisCmb::isTriggered(const irr::SEvent::SJoystickEvent &ev) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// spares many characters
|
// spares many characters
|
||||||
#define JLO_B_PB(A, B, C) jlo.button_keys.push_back(JoystickButtonCmb(A, B, C))
|
#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.push_back(JoystickAxisCmb(A, B, C, D))
|
#define JLO_A_PB(A, B, C, D) jlo.axis_keys.emplace_back(A, B, C, D)
|
||||||
|
|
||||||
JoystickLayout create_default_layout()
|
JoystickLayout create_default_layout()
|
||||||
{
|
{
|
||||||
@ -157,8 +157,8 @@ JoystickLayout create_xbox_layout()
|
|||||||
JoystickController::JoystickController() :
|
JoystickController::JoystickController() :
|
||||||
doubling_dtime(g_settings->getFloat("repeat_joystick_button_time"))
|
doubling_dtime(g_settings->getFloat("repeat_joystick_button_time"))
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
|
for (float &i : m_past_pressed_time) {
|
||||||
m_past_pressed_time[i] = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
@ -203,15 +203,15 @@ bool JoystickController::handleEvent(const irr::SEvent::SJoystickEvent &ev)
|
|||||||
|
|
||||||
// First generate a list of keys pressed
|
// First generate a list of keys pressed
|
||||||
|
|
||||||
for (size_t i = 0; i < m_layout.button_keys.size(); i++) {
|
for (const auto &button_key : m_layout.button_keys) {
|
||||||
if (m_layout.button_keys[i].isTriggered(ev)) {
|
if (button_key.isTriggered(ev)) {
|
||||||
keys_pressed.set(m_layout.button_keys[i].key);
|
keys_pressed.set(button_key.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < m_layout.axis_keys.size(); i++) {
|
for (const auto &axis_key : m_layout.axis_keys) {
|
||||||
if (m_layout.axis_keys[i].isTriggered(ev)) {
|
if (axis_key.isTriggered(ev)) {
|
||||||
keys_pressed.set(m_layout.axis_keys[i].key);
|
keys_pressed.set(axis_key.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,8 @@ struct JoystickCombination {
|
|||||||
|
|
||||||
struct JoystickButtonCmb : public JoystickCombination {
|
struct JoystickButtonCmb : public JoystickCombination {
|
||||||
|
|
||||||
JoystickButtonCmb() {}
|
JoystickButtonCmb() = default;
|
||||||
|
|
||||||
JoystickButtonCmb(GameKeyType key, u32 filter_mask, u32 compare_mask) :
|
JoystickButtonCmb(GameKeyType key, u32 filter_mask, u32 compare_mask) :
|
||||||
filter_mask(filter_mask),
|
filter_mask(filter_mask),
|
||||||
compare_mask(compare_mask)
|
compare_mask(compare_mask)
|
||||||
@ -68,7 +69,8 @@ struct JoystickButtonCmb : public JoystickCombination {
|
|||||||
|
|
||||||
struct JoystickAxisCmb : public JoystickCombination {
|
struct JoystickAxisCmb : public JoystickCombination {
|
||||||
|
|
||||||
JoystickAxisCmb() {}
|
JoystickAxisCmb() = default;
|
||||||
|
|
||||||
JoystickAxisCmb(GameKeyType key, u16 axis_to_compare, int direction, s16 thresh) :
|
JoystickAxisCmb(GameKeyType key, u16 axis_to_compare, int direction, s16 thresh) :
|
||||||
axis_to_compare(axis_to_compare),
|
axis_to_compare(axis_to_compare),
|
||||||
direction(direction),
|
direction(direction),
|
||||||
|
@ -419,8 +419,7 @@ std::vector<core::vector3d<u32>> RenderingEngine::getSupportedVideoModes()
|
|||||||
for (s32 i = 0; i != num_modes; i++) {
|
for (s32 i = 0; i != num_modes; i++) {
|
||||||
core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
|
core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
|
||||||
u32 mode_depth = (u32)modelist->getVideoModeDepth(i);
|
u32 mode_depth = (u32)modelist->getVideoModeDepth(i);
|
||||||
mlist.push_back(core::vector3d<u32>(
|
mlist.emplace_back(mode_res.Width, mode_res.Height, mode_depth);
|
||||||
mode_res.Width, mode_res.Height, mode_depth));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nulldevice->drop();
|
nulldevice->drop();
|
||||||
|
@ -23,19 +23,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "util/container.h"
|
#include "util/container.h"
|
||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
#include "util/numeric.h"
|
|
||||||
#include "irrlichttypes_extrabloated.h"
|
|
||||||
#include "debug.h"
|
|
||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "log.h"
|
|
||||||
#include "gamedef.h"
|
#include "gamedef.h"
|
||||||
#include "util/strfnd.h"
|
#include "util/strfnd.h"
|
||||||
#include "util/string.h" // for parseColorString()
|
|
||||||
#include "imagefilters.h"
|
#include "imagefilters.h"
|
||||||
#include "guiscalingfilter.h"
|
#include "guiscalingfilter.h"
|
||||||
#include "nodedef.h"
|
|
||||||
#include "renderingengine.h"
|
#include "renderingengine.h"
|
||||||
|
|
||||||
|
|
||||||
@ -96,13 +90,13 @@ std::string getImagePath(std::string path)
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
// If there is no extension, add one
|
// If there is no extension, add one
|
||||||
if (removeStringEnd(path, extensions) == "")
|
if (removeStringEnd(path, extensions).empty())
|
||||||
path = path + ".png";
|
path = path + ".png";
|
||||||
// Check paths until something is found to exist
|
// Check paths until something is found to exist
|
||||||
const char **ext = extensions;
|
const char **ext = extensions;
|
||||||
do{
|
do{
|
||||||
bool r = replace_ext(path, *ext);
|
bool r = replace_ext(path, *ext);
|
||||||
if (r == false)
|
if (!r)
|
||||||
return "";
|
return "";
|
||||||
if (fs::PathExists(path))
|
if (fs::PathExists(path))
|
||||||
return path;
|
return path;
|
||||||
@ -124,7 +118,7 @@ std::string getImagePath(std::string path)
|
|||||||
*/
|
*/
|
||||||
std::string getTexturePath(const std::string &filename)
|
std::string getTexturePath(const std::string &filename)
|
||||||
{
|
{
|
||||||
std::string fullpath = "";
|
std::string fullpath;
|
||||||
/*
|
/*
|
||||||
Check from cache
|
Check from cache
|
||||||
*/
|
*/
|
||||||
@ -136,7 +130,7 @@ std::string getTexturePath(const std::string &filename)
|
|||||||
Check from texture_path
|
Check from texture_path
|
||||||
*/
|
*/
|
||||||
const std::string &texture_path = g_settings->get("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;
|
std::string testpath = texture_path + DIR_DELIM + filename;
|
||||||
// Check all filename extensions. Returns "" if not found.
|
// Check all filename extensions. Returns "" if not found.
|
||||||
fullpath = getImagePath(testpath);
|
fullpath = getImagePath(testpath);
|
||||||
@ -145,7 +139,7 @@ std::string getTexturePath(const std::string &filename)
|
|||||||
/*
|
/*
|
||||||
Check from default data directory
|
Check from default data directory
|
||||||
*/
|
*/
|
||||||
if (fullpath == "")
|
if (fullpath.empty())
|
||||||
{
|
{
|
||||||
std::string base_path = porting::path_share + DIR_DELIM + "textures"
|
std::string base_path = porting::path_share + DIR_DELIM + "textures"
|
||||||
+ DIR_DELIM + "base" + DIR_DELIM + "pack";
|
+ DIR_DELIM + "base" + DIR_DELIM + "pack";
|
||||||
@ -193,9 +187,8 @@ class SourceImageCache
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~SourceImageCache() {
|
~SourceImageCache() {
|
||||||
for (std::map<std::string, video::IImage*>::iterator iter = m_images.begin();
|
for (auto &m_image : m_images) {
|
||||||
iter != m_images.end(); ++iter) {
|
m_image.second->drop();
|
||||||
iter->second->drop();
|
|
||||||
}
|
}
|
||||||
m_images.clear();
|
m_images.clear();
|
||||||
}
|
}
|
||||||
@ -216,7 +209,7 @@ public:
|
|||||||
// Try to use local texture instead if asked to
|
// Try to use local texture instead if asked to
|
||||||
if (prefer_local){
|
if (prefer_local){
|
||||||
std::string path = getTexturePath(name);
|
std::string path = getTexturePath(name);
|
||||||
if (path != ""){
|
if (!path.empty()) {
|
||||||
video::IImage *img2 = RenderingEngine::get_video_driver()->
|
video::IImage *img2 = RenderingEngine::get_video_driver()->
|
||||||
createImageFromFile(path.c_str());
|
createImageFromFile(path.c_str());
|
||||||
if (img2){
|
if (img2){
|
||||||
@ -249,7 +242,7 @@ public:
|
|||||||
}
|
}
|
||||||
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
|
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
|
||||||
std::string path = getTexturePath(name);
|
std::string path = getTexturePath(name);
|
||||||
if (path == ""){
|
if (path.empty()) {
|
||||||
infostream<<"SourceImageCache::getOrLoad(): No path found for \""
|
infostream<<"SourceImageCache::getOrLoad(): No path found for \""
|
||||||
<<name<<"\""<<std::endl;
|
<<name<<"\""<<std::endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -351,7 +344,7 @@ public:
|
|||||||
if (cache_found)
|
if (cache_found)
|
||||||
return is_known;
|
return is_known;
|
||||||
// Not found in cache; find out if a local file exists
|
// 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);
|
m_source_image_existence.set(name, is_known);
|
||||||
return is_known;
|
return is_known;
|
||||||
}
|
}
|
||||||
@ -438,7 +431,7 @@ TextureSource::TextureSource()
|
|||||||
m_main_thread = std::this_thread::get_id();
|
m_main_thread = std::this_thread::get_id();
|
||||||
|
|
||||||
// Add a NULL TextureInfo as the first index, named ""
|
// 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;
|
m_name_to_id[""] = 0;
|
||||||
|
|
||||||
// Cache some settings
|
// Cache some settings
|
||||||
@ -455,21 +448,14 @@ TextureSource::~TextureSource()
|
|||||||
|
|
||||||
unsigned int textures_before = driver->getTextureCount();
|
unsigned int textures_before = driver->getTextureCount();
|
||||||
|
|
||||||
for (std::vector<TextureInfo>::iterator iter =
|
for (const auto &iter : m_textureinfo_cache) {
|
||||||
m_textureinfo_cache.begin();
|
|
||||||
iter != m_textureinfo_cache.end(); ++iter)
|
|
||||||
{
|
|
||||||
//cleanup texture
|
//cleanup texture
|
||||||
if (iter->texture)
|
if (iter.texture)
|
||||||
driver->removeTexture(iter->texture);
|
driver->removeTexture(iter.texture);
|
||||||
}
|
}
|
||||||
m_textureinfo_cache.clear();
|
m_textureinfo_cache.clear();
|
||||||
|
|
||||||
for (std::vector<video::ITexture*>::iterator iter =
|
for (auto t : m_texture_trash) {
|
||||||
m_texture_trash.begin(); iter != m_texture_trash.end();
|
|
||||||
++iter) {
|
|
||||||
video::ITexture *t = *iter;
|
|
||||||
|
|
||||||
//cleanup trashed texture
|
//cleanup trashed texture
|
||||||
driver->removeTexture(t);
|
driver->removeTexture(t);
|
||||||
}
|
}
|
||||||
@ -586,7 +572,7 @@ u32 TextureSource::generateTexture(const std::string &name)
|
|||||||
//infostream << "generateTexture(): name=\"" << name << "\"" << std::endl;
|
//infostream << "generateTexture(): name=\"" << name << "\"" << std::endl;
|
||||||
|
|
||||||
// Empty name means texture 0
|
// Empty name means texture 0
|
||||||
if (name == "") {
|
if (name.empty()) {
|
||||||
infostream<<"generateTexture(): name is empty"<<std::endl;
|
infostream<<"generateTexture(): name is empty"<<std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -690,7 +676,7 @@ Palette* TextureSource::getPalette(const std::string &name)
|
|||||||
if (name == "")
|
if (name == "")
|
||||||
return NULL;
|
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()) {
|
if (it == m_palettes.end()) {
|
||||||
// Create palette
|
// Create palette
|
||||||
video::IImage *img = generateImage(name);
|
video::IImage *img = generateImage(name);
|
||||||
@ -728,7 +714,7 @@ Palette* TextureSource::getPalette(const std::string &name)
|
|||||||
img->drop();
|
img->drop();
|
||||||
// Fill in remaining elements
|
// Fill in remaining elements
|
||||||
while (new_palette.size() < 256)
|
while (new_palette.size() < 256)
|
||||||
new_palette.push_back(video::SColor(0xFFFFFFFF));
|
new_palette.emplace_back(0xFFFFFFFF);
|
||||||
m_palettes[name] = new_palette;
|
m_palettes[name] = new_palette;
|
||||||
it = m_palettes.find(name);
|
it = m_palettes.find(name);
|
||||||
}
|
}
|
||||||
@ -775,22 +761,21 @@ void TextureSource::rebuildImagesAndTextures()
|
|||||||
sanity_check(driver);
|
sanity_check(driver);
|
||||||
|
|
||||||
// Recreate textures
|
// Recreate textures
|
||||||
for (u32 i=0; i<m_textureinfo_cache.size(); i++){
|
for (TextureInfo &ti : m_textureinfo_cache) {
|
||||||
TextureInfo *ti = &m_textureinfo_cache[i];
|
video::IImage *img = generateImage(ti.name);
|
||||||
video::IImage *img = generateImage(ti->name);
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
img = Align2Npot2(img, driver);
|
img = Align2Npot2(img, driver);
|
||||||
#endif
|
#endif
|
||||||
// Create texture from resulting image
|
// Create texture from resulting image
|
||||||
video::ITexture *t = NULL;
|
video::ITexture *t = NULL;
|
||||||
if (img) {
|
if (img) {
|
||||||
t = driver->addTexture(ti->name.c_str(), img);
|
t = driver->addTexture(ti.name.c_str(), img);
|
||||||
guiScalingCache(io::path(ti->name.c_str()), driver, img);
|
guiScalingCache(io::path(ti.name.c_str()), driver, img);
|
||||||
img->drop();
|
img->drop();
|
||||||
}
|
}
|
||||||
video::ITexture *t_old = ti->texture;
|
video::ITexture *t_old = ti.texture;
|
||||||
// Replace texture
|
// Replace texture
|
||||||
ti->texture = t;
|
ti.texture = t;
|
||||||
|
|
||||||
if (t_old)
|
if (t_old)
|
||||||
m_texture_trash.push_back(t_old);
|
m_texture_trash.push_back(t_old);
|
||||||
@ -1185,14 +1170,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
|
|||||||
sanity_check(driver);
|
sanity_check(driver);
|
||||||
|
|
||||||
// Stuff starting with [ are special commands
|
// 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);
|
video::IImage *image = m_sourcecache.getOrLoad(part_of_name);
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
image = Align2Npot2(image, driver);
|
image = Align2Npot2(image, driver);
|
||||||
#endif
|
#endif
|
||||||
if (image == NULL) {
|
if (image == NULL) {
|
||||||
if (part_of_name != "") {
|
if (!part_of_name.empty()) {
|
||||||
|
|
||||||
// Do not create normalmap dummies
|
// Do not create normalmap dummies
|
||||||
if (part_of_name.find("_normal.png") != std::string::npos) {
|
if (part_of_name.find("_normal.png") != std::string::npos) {
|
||||||
@ -1343,7 +1327,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
|
|||||||
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
||||||
baseimg->fill(video::SColor(0,0,0,0));
|
baseimg->fill(video::SColor(0,0,0,0));
|
||||||
}
|
}
|
||||||
while (sf.at_end() == false) {
|
while (!sf.at_end()) {
|
||||||
u32 x = stoi(sf.next(","));
|
u32 x = stoi(sf.next(","));
|
||||||
u32 y = stoi(sf.next("="));
|
u32 y = stoi(sf.next("="));
|
||||||
std::string filename = unescape_string(sf.next_esc(":", escape), escape);
|
std::string filename = unescape_string(sf.next_esc(":", escape), escape);
|
||||||
@ -1896,13 +1880,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
|
|||||||
|
|
||||||
std::string mode = sf.next("");
|
std::string mode = sf.next("");
|
||||||
u32 mask = 0;
|
u32 mask = 0;
|
||||||
if (mode.find("a") != std::string::npos)
|
if (mode.find('a') != std::string::npos)
|
||||||
mask |= 0xff000000UL;
|
mask |= 0xff000000UL;
|
||||||
if (mode.find("r") != std::string::npos)
|
if (mode.find('r') != std::string::npos)
|
||||||
mask |= 0x00ff0000UL;
|
mask |= 0x00ff0000UL;
|
||||||
if (mode.find("g") != std::string::npos)
|
if (mode.find('g') != std::string::npos)
|
||||||
mask |= 0x0000ff00UL;
|
mask |= 0x0000ff00UL;
|
||||||
if (mode.find("b") != std::string::npos)
|
if (mode.find('b') != std::string::npos)
|
||||||
mask |= 0x000000ffUL;
|
mask |= 0x000000ffUL;
|
||||||
|
|
||||||
core::dimension2d<u32> dim = baseimg->getDimension();
|
core::dimension2d<u32> dim = baseimg->getDimension();
|
||||||
@ -2240,9 +2224,8 @@ u32 parseImageTransform(const std::string& s)
|
|||||||
pos++;
|
pos++;
|
||||||
break;
|
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;
|
transform = i;
|
||||||
pos += name_i.size();
|
pos += name_i.size();
|
||||||
break;
|
break;
|
||||||
@ -2269,8 +2252,8 @@ core::dimension2d<u32> imageTransformDimension(u32 transform, core::dimension2d<
|
|||||||
{
|
{
|
||||||
if (transform % 2 == 0)
|
if (transform % 2 == 0)
|
||||||
return dim;
|
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)
|
void imageTransform(u32 transform, video::IImage *src, video::IImage *dst)
|
||||||
@ -2325,12 +2308,12 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name)
|
|||||||
std::string fname_base = name;
|
std::string fname_base = name;
|
||||||
static const char *normal_ext = "_normal.png";
|
static const char *normal_ext = "_normal.png";
|
||||||
static const u32 normal_ext_size = strlen(normal_ext);
|
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;
|
std::string fname_normal = fname_base.substr(0, pos) + normal_ext;
|
||||||
if (isKnownSourceImage(fname_normal)) {
|
if (isKnownSourceImage(fname_normal)) {
|
||||||
// look for image extension and replace it
|
// look for image extension and replace it
|
||||||
size_t i = 0;
|
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);
|
fname_base.replace(i, 4, normal_ext);
|
||||||
i += normal_ext_size;
|
i += normal_ext_size;
|
||||||
}
|
}
|
||||||
@ -2384,15 +2367,16 @@ video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present)
|
|||||||
|
|
||||||
if (isKnownSourceImage(tname)) {
|
if (isKnownSourceImage(tname)) {
|
||||||
return getTexture(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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,10 @@ struct TextureFromMeshParams
|
|||||||
class ISimpleTextureSource
|
class ISimpleTextureSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ISimpleTextureSource(){}
|
ISimpleTextureSource() = default;
|
||||||
virtual ~ISimpleTextureSource(){}
|
|
||||||
|
virtual ~ISimpleTextureSource() = default;
|
||||||
|
|
||||||
virtual video::ITexture* getTexture(
|
virtual video::ITexture* getTexture(
|
||||||
const std::string &name, u32 *id = nullptr) = 0;
|
const std::string &name, u32 *id = nullptr) = 0;
|
||||||
};
|
};
|
||||||
@ -99,8 +101,10 @@ public:
|
|||||||
class ITextureSource : public ISimpleTextureSource
|
class ITextureSource : public ISimpleTextureSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ITextureSource(){}
|
ITextureSource() = default;
|
||||||
virtual ~ITextureSource(){}
|
|
||||||
|
virtual ~ITextureSource() = default;
|
||||||
|
|
||||||
virtual u32 getTextureId(const std::string &name)=0;
|
virtual u32 getTextureId(const std::string &name)=0;
|
||||||
virtual std::string getTextureName(u32 id)=0;
|
virtual std::string getTextureName(u32 id)=0;
|
||||||
virtual video::ITexture* getTexture(u32 id)=0;
|
virtual video::ITexture* getTexture(u32 id)=0;
|
||||||
@ -126,8 +130,10 @@ public:
|
|||||||
class IWritableTextureSource : public ITextureSource
|
class IWritableTextureSource : public ITextureSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IWritableTextureSource(){}
|
IWritableTextureSource() = default;
|
||||||
virtual ~IWritableTextureSource(){}
|
|
||||||
|
virtual ~IWritableTextureSource() = default;
|
||||||
|
|
||||||
virtual u32 getTextureId(const std::string &name)=0;
|
virtual u32 getTextureId(const std::string &name)=0;
|
||||||
virtual std::string getTextureName(u32 id)=0;
|
virtual std::string getTextureName(u32 id)=0;
|
||||||
virtual video::ITexture* getTexture(u32 id)=0;
|
virtual video::ITexture* getTexture(u32 id)=0;
|
||||||
@ -170,7 +176,7 @@ enum MaterialType{
|
|||||||
// Ignored if MATERIAL_FLAG_CRACK is not set.
|
// Ignored if MATERIAL_FLAG_CRACK is not set.
|
||||||
#define MATERIAL_FLAG_CRACK_OVERLAY 0x04
|
#define MATERIAL_FLAG_CRACK_OVERLAY 0x04
|
||||||
#define MATERIAL_FLAG_ANIMATION 0x08
|
#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_HORIZONTAL 0x20
|
||||||
#define MATERIAL_FLAG_TILEABLE_VERTICAL 0x40
|
#define MATERIAL_FLAG_TILEABLE_VERTICAL 0x40
|
||||||
|
|
||||||
@ -180,7 +186,8 @@ enum MaterialType{
|
|||||||
*/
|
*/
|
||||||
struct FrameSpec
|
struct FrameSpec
|
||||||
{
|
{
|
||||||
FrameSpec() {}
|
FrameSpec() = default;
|
||||||
|
|
||||||
u32 texture_id = 0;
|
u32 texture_id = 0;
|
||||||
video::ITexture *texture = nullptr;
|
video::ITexture *texture = nullptr;
|
||||||
video::ITexture *normal_texture = nullptr;
|
video::ITexture *normal_texture = nullptr;
|
||||||
@ -192,7 +199,7 @@ struct FrameSpec
|
|||||||
//! Defines a layer of a tile.
|
//! Defines a layer of a tile.
|
||||||
struct TileLayer
|
struct TileLayer
|
||||||
{
|
{
|
||||||
TileLayer() {}
|
TileLayer() = default;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Two layers are equal if they can be merged.
|
* Two layers are equal if they can be merged.
|
||||||
@ -232,8 +239,7 @@ struct TileLayer
|
|||||||
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
|
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
|
||||||
? true : false;
|
|
||||||
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
||||||
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
||||||
}
|
}
|
||||||
@ -244,8 +250,7 @@ struct TileLayer
|
|||||||
|
|
||||||
void applyMaterialOptionsWithShaders(video::SMaterial &material) const
|
void applyMaterialOptionsWithShaders(video::SMaterial &material) const
|
||||||
{
|
{
|
||||||
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
|
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
|
||||||
? true : false;
|
|
||||||
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
||||||
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
||||||
material.TextureLayer[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
material.TextureLayer[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user