Allow texture error message to be used in STKTexManager
This commit is contained in:
parent
874d3d347d
commit
3bffe1f1a7
@ -1544,32 +1544,6 @@ void IrrDriver::removeCameraSceneNode(scene::ICameraSceneNode *camera)
|
||||
camera->remove();
|
||||
} // removeCameraSceneNode
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets an error message to be displayed when a texture is not found. This
|
||||
* error message is shown before the "Texture '%s' not found" message. It can
|
||||
* be used to supply additional details like what kart is currently being
|
||||
* loaded.
|
||||
* \param error Error message, potentially with a '%' which will be replaced
|
||||
* with detail.
|
||||
* \param detail String to replace a '%' in the error message.
|
||||
*/
|
||||
void IrrDriver::setTextureErrorMessage(const std::string &error,
|
||||
const std::string &detail)
|
||||
{
|
||||
if(detail=="")
|
||||
m_texture_error_message = error;
|
||||
else
|
||||
m_texture_error_message = StringUtils::insertValues(error, detail);
|
||||
} // setTextureErrorMessage
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Disables the texture error message again.
|
||||
*/
|
||||
void IrrDriver::unsetTextureErrorMessage()
|
||||
{
|
||||
m_texture_error_message = "";
|
||||
} // unsetTextureErrorMessage
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Loads a texture from a file and returns the texture object. This is just
|
||||
* a convenient wrapper which loads the texture from a STK asset directory.
|
||||
|
@ -99,10 +99,6 @@ private:
|
||||
|
||||
core::dimension2du m_actual_screen_size;
|
||||
|
||||
/** Additional details to be shown in case that a texture is not found.
|
||||
* This is used to specify details like: "while loading kart '...'" */
|
||||
std::string m_texture_error_message;
|
||||
|
||||
/** The main MRT setup. */
|
||||
core::array<video::IRenderTarget> m_mrt;
|
||||
|
||||
@ -293,9 +289,6 @@ public:
|
||||
void printRenderStats();
|
||||
bool supportsSplatting();
|
||||
void requestScreenshot();
|
||||
void setTextureErrorMessage(const std::string &error,
|
||||
const std::string &detail="");
|
||||
void unsetTextureErrorMessage();
|
||||
class GPUTimer &getGPUTimer(unsigned);
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
@ -312,56 +305,7 @@ public:
|
||||
m_clear_color = color;
|
||||
} // setClearbackBufferColor
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Convenience function that loads a texture with default parameters
|
||||
* but includes an error message.
|
||||
* \param filename File name of the texture to load.
|
||||
* \param error Error message, potentially with a '%' which will be replaced
|
||||
* with detail.
|
||||
* \param detail String to replace a '%' in the error message.
|
||||
*/
|
||||
video::ITexture* getTexture(const std::string &filename,
|
||||
const std::string &error_message,
|
||||
const std::string &detail="")
|
||||
{
|
||||
setTextureErrorMessage(error_message, detail);
|
||||
video::ITexture *tex = getTexture(filename);
|
||||
unsetTextureErrorMessage();
|
||||
return tex;
|
||||
} // getTexture
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Convenience function that loads a texture with default parameters
|
||||
* but includes an error message.
|
||||
* \param filename File name of the texture to load.
|
||||
* \param error Error message, potentially with a '%' which will be replaced
|
||||
* with detail.
|
||||
* \param detail String to replace a '%' in the error message.
|
||||
*/
|
||||
video::ITexture* getTexture(const std::string &filename,
|
||||
char *error_message,
|
||||
char *detail=NULL)
|
||||
{
|
||||
if(!detail)
|
||||
return getTexture(filename, std::string(error_message),
|
||||
std::string(""));
|
||||
|
||||
return getTexture(filename, std::string(error_message),
|
||||
std::string(detail));
|
||||
} // getTexture
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the currently defined texture error message, which is used
|
||||
* by event_handler.cpp to print additional info about irrlicht
|
||||
* internal errors or warnings. If no error message is currently
|
||||
* defined, the error message is "".
|
||||
*/
|
||||
const std::string &getTextureErrorMessage()
|
||||
{
|
||||
return m_texture_error_message;
|
||||
} // getTextureErrorMessage
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns a list of all video modes supports by the graphics card. */
|
||||
const std::vector<VideoMode>& getVideoModes() const { return m_modes; }
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -36,7 +36,9 @@ STKTexture* STKTexManager::findTextureInFileSystem(const std::string& filename,
|
||||
io::path relative_path = file_manager->searchTexture(filename).c_str();
|
||||
if (relative_path.empty())
|
||||
{
|
||||
Log::warn("STKTexManager", "Failed to load %s.", filename.c_str());
|
||||
if (!m_texture_error_message.empty())
|
||||
Log::error("STKTexManager", "%s", m_texture_error_message.c_str());
|
||||
Log::error("STKTexManager", "Failed to load %s.", filename.c_str());
|
||||
return NULL;
|
||||
}
|
||||
*full_path =
|
||||
@ -81,7 +83,15 @@ video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
|
||||
single_channel);
|
||||
if (new_texture->getOpenGLTextureName() == 0 && !no_upload)
|
||||
{
|
||||
m_all_textures[new_texture->getName().getPtr()] = NULL;
|
||||
const char* name = new_texture->getName().getPtr();
|
||||
if (!m_texture_error_message.empty())
|
||||
{
|
||||
Log::error("STKTexManager", "%s",
|
||||
m_texture_error_message.c_str());
|
||||
}
|
||||
Log::error("STKTexManager", "Texture %s not found or invalid.",
|
||||
name);
|
||||
m_all_textures[name] = NULL;
|
||||
delete new_texture;
|
||||
return NULL;
|
||||
}
|
||||
@ -243,3 +253,21 @@ void STKTexManager::reset()
|
||||
ObjectPass1Shader::getInstance()->recreateTrilinearSampler(0);
|
||||
#endif
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets an error message to be displayed when a texture is not found. This
|
||||
* error message is shown before the "Texture %s not found or invalid"
|
||||
* message. It can be used to supply additional details like what kart is
|
||||
* currently being loaded.
|
||||
* \param error Error message, potentially with a '%' which will be replaced
|
||||
* with detail.
|
||||
* \param detail String to replace a '%' in the error message.
|
||||
*/
|
||||
void STKTexManager::setTextureErrorMessage(const std::string &error,
|
||||
const std::string &detail)
|
||||
{
|
||||
if (detail=="")
|
||||
m_texture_error_message = error;
|
||||
else
|
||||
m_texture_error_message = StringUtils::insertValues(error, detail);
|
||||
} // setTextureErrorMessage
|
||||
|
@ -39,6 +39,10 @@ class STKTexManager : public Singleton<STKTexManager>, NoCopy
|
||||
private:
|
||||
std::unordered_map<std::string, STKTexture*> m_all_textures;
|
||||
|
||||
/** Additional details to be shown in case that a texture is not found.
|
||||
* This is used to specify details like: "while loading kart '...'" */
|
||||
std::string m_texture_error_message;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
STKTexture* findTextureInFileSystem(const std::string& filename,
|
||||
std::string* full_path);
|
||||
@ -70,6 +74,59 @@ public:
|
||||
irr::core::stringw reloadTexture(const irr::core::stringw& name);
|
||||
// ------------------------------------------------------------------------
|
||||
void reset();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the currently defined texture error message, which is used
|
||||
* by event_handler.cpp to print additional info about irrlicht
|
||||
* internal errors or warnings. If no error message is currently
|
||||
* defined, the error message is "".
|
||||
*/
|
||||
const std::string &getTextureErrorMessage()
|
||||
{
|
||||
return m_texture_error_message;
|
||||
} // getTextureErrorMessage
|
||||
// ------------------------------------------------------------------------
|
||||
void setTextureErrorMessage(const std::string &error,
|
||||
const std::string &detail="");
|
||||
// ------------------------------------------------------------------------
|
||||
/** Disables the texture error message again.
|
||||
*/
|
||||
void unsetTextureErrorMessage() { m_texture_error_message = ""; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Convenience function that loads a texture with default parameters
|
||||
* but includes an error message.
|
||||
* \param filename File name of the texture to load.
|
||||
* \param error Error message, potentially with a '%' which will be
|
||||
* replaced with detail.
|
||||
* \param detail String to replace a '%' in the error message.
|
||||
*/
|
||||
irr::video::ITexture* getTexture(const std::string &filename,
|
||||
const std::string &error_message,
|
||||
const std::string &detail="")
|
||||
{
|
||||
setTextureErrorMessage(error_message, detail);
|
||||
irr::video::ITexture *tex = getTexture(filename);
|
||||
unsetTextureErrorMessage();
|
||||
return tex;
|
||||
} // getTexture
|
||||
// ------------------------------------------------------------------------
|
||||
/** Convenience function that loads a texture with default parameters
|
||||
* but includes an error message.
|
||||
* \param filename File name of the texture to load.
|
||||
* \param error Error message, potentially with a '%' which will be
|
||||
* replaced with detail.
|
||||
* \param detail String to replace a '%' in the error message.
|
||||
*/
|
||||
irr::video::ITexture* getTexture(const std::string &filename,
|
||||
char *error_message,
|
||||
char *detail = NULL)
|
||||
{
|
||||
if (!detail)
|
||||
return getTexture(filename, std::string(error_message),
|
||||
std::string(""));
|
||||
|
||||
return getTexture(filename, std::string(error_message),
|
||||
std::string(detail));
|
||||
} // getTexture
|
||||
|
||||
}; // STKTexManager
|
||||
|
||||
|
@ -161,15 +161,12 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data,
|
||||
irr_driver->getVideoDriver()->createImageFromFile(NamedPath);
|
||||
if (orig_img == NULL)
|
||||
{
|
||||
Log::warn("STKTexture", "No image %s.", NamedPath.getPtr());
|
||||
return;
|
||||
}
|
||||
|
||||
if (orig_img->getDimension().Width == 0 ||
|
||||
orig_img->getDimension().Height == 0)
|
||||
{
|
||||
Log::warn("STKTexture", "image %s has 0 size.",
|
||||
NamedPath.getPtr());
|
||||
orig_img->drop();
|
||||
return;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "guiengine/abstract_state_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
@ -256,7 +257,7 @@ bool EventHandler::OnEvent (const SEvent &event)
|
||||
#else
|
||||
return true; // EVENT_BLOCK
|
||||
#endif
|
||||
const std::string &error_info = irr_driver->getTextureErrorMessage();
|
||||
const std::string &error_info = STKTexManager::getInstance()->getTextureErrorMessage();
|
||||
if (event.LogEvent.Level == irr::ELL_WARNING)
|
||||
{
|
||||
if(error_info.size()>0)
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "addons/addon.hpp"
|
||||
#include "config/stk_config.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
@ -229,8 +228,8 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
file_manager->pushModelSearchPath(m_root);
|
||||
file_manager->pushTextureSearchPath(m_root, unique_id);
|
||||
|
||||
irr_driver->setTextureErrorMessage("Error while loading kart '%s':",
|
||||
m_name);
|
||||
STKTexManager::getInstance()
|
||||
->setTextureErrorMessage("Error while loading kart '%s':", m_name);
|
||||
|
||||
// addShared makes sure that these textures/material infos stay in memory
|
||||
material_manager->addSharedMaterial(materials_file);
|
||||
@ -245,8 +244,11 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
/*make_permanent*/true,
|
||||
/*complain_if_not_found*/true,
|
||||
/*strip_path*/false);
|
||||
if(m_minimap_icon_file!="")
|
||||
m_minimap_icon = irr_driver->getTexture(m_root+m_minimap_icon_file);
|
||||
if (m_minimap_icon_file!="")
|
||||
{
|
||||
m_minimap_icon = STKTexManager::getInstance()
|
||||
->getTexture(m_root+m_minimap_icon_file);
|
||||
}
|
||||
else
|
||||
m_minimap_icon = NULL;
|
||||
|
||||
@ -296,9 +298,9 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
// used.
|
||||
m_wheel_base = fabsf(m_kart_model->getLength() - 2*0.25f);
|
||||
|
||||
m_shadow_texture = irr_driver->getTexture(m_shadow_file);
|
||||
m_shadow_texture = STKTexManager::getInstance()->getTexture(m_shadow_file);
|
||||
|
||||
irr_driver->unsetTextureErrorMessage();
|
||||
STKTexManager::getInstance()->unsetTextureErrorMessage();
|
||||
file_manager->popTextureSearchPath();
|
||||
file_manager->popModelSearchPath();
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
@ -179,7 +179,7 @@ void EasterEggScreen::init()
|
||||
buildTrackList();
|
||||
|
||||
// select old track for the game master (if found)
|
||||
irr_driver->setTextureErrorMessage(
|
||||
STKTexManager::getInstance()->setTextureErrorMessage(
|
||||
"While loading screenshot in track screen for last track '%s':",
|
||||
UserConfigParams::m_last_track);
|
||||
if (!tracks_widget->setSelection(UserConfigParams::m_last_track,
|
||||
@ -187,7 +187,7 @@ void EasterEggScreen::init()
|
||||
{
|
||||
tracks_widget->setSelection(0, PLAYER_ID_GAME_MASTER, true);
|
||||
}
|
||||
irr_driver->unsetTextureErrorMessage();
|
||||
STKTexManager::getInstance()->unsetTextureErrorMessage();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/saved_grand_prix.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
@ -286,9 +286,9 @@ void GPInfoScreen::addScreenshot()
|
||||
screenshot->m_properties[PROP_ICON] = "gui/main_help.png";
|
||||
|
||||
const Track *track = track_manager->getTrack(m_gp.getTrackId(0));
|
||||
video::ITexture* image = irr_driver->getTexture(track->getScreenshotFile(),
|
||||
"While loading screenshot for track '%s':",
|
||||
track->getFilename() );
|
||||
video::ITexture* image = STKTexManager::getInstance()
|
||||
->getTexture(track->getScreenshotFile(),
|
||||
"While loading screenshot for track '%s':", track->getFilename());
|
||||
if (image != NULL)
|
||||
screenshot->setImage(image);
|
||||
} // addScreenShot
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widgets/button_widget.hpp"
|
||||
@ -128,14 +128,13 @@ void TrackInfoScreen::init()
|
||||
// temporary icon, will replace it just after (but it will be shown if the given icon is not found)
|
||||
screenshot->m_properties[PROP_ICON] = "gui/main_help.png";
|
||||
|
||||
ITexture* image = irr_driver->getTexture(m_track->getScreenshotFile(),
|
||||
"While loading screenshot for track '%s':",
|
||||
m_track->getFilename() );
|
||||
ITexture* image = STKTexManager::getInstance()
|
||||
->getTexture(m_track->getScreenshotFile(),
|
||||
"While loading screenshot for track '%s':", m_track->getFilename());
|
||||
if(!image)
|
||||
{
|
||||
image = irr_driver->getTexture("main_help.png",
|
||||
"While loading screenshot for track '%s':",
|
||||
m_track->getFilename());
|
||||
image = STKTexManager::getInstance()->getTexture("main_help.png",
|
||||
"While loading screenshot for track '%s':", m_track->getFilename());
|
||||
}
|
||||
if (image != NULL)
|
||||
screenshot->setImage(image);
|
||||
@ -311,7 +310,8 @@ void TrackInfoScreen::updateHighScores()
|
||||
if (prop != NULL)
|
||||
{
|
||||
const std::string &icon_path = prop->getAbsoluteIconFile();
|
||||
ITexture* kart_icon_texture = irr_driver->getTexture( icon_path );
|
||||
ITexture* kart_icon_texture =
|
||||
STKTexManager::getInstance()->getTexture( icon_path );
|
||||
m_kart_icons[n]->setImage(kart_icon_texture);
|
||||
}
|
||||
line = name + "\t" + core::stringw(time_string.c_str());
|
||||
@ -321,9 +321,9 @@ void TrackInfoScreen::updateHighScores()
|
||||
//I18N: for empty highscores entries
|
||||
line = _("(Empty)");
|
||||
|
||||
ITexture* no_kart_texture = irr_driver->getTexture(
|
||||
file_manager->getAsset(FileManager::GUI,
|
||||
"random_kart.png") );
|
||||
ITexture* no_kart_texture =
|
||||
STKTexManager::getInstance()->getTexture
|
||||
(file_manager->getAsset(FileManager::GUI, "random_kart.png"));
|
||||
m_kart_icons[n]->setImage(no_kart_texture);
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
@ -223,7 +223,7 @@ void TracksAndGPScreen::init()
|
||||
buildTrackList();
|
||||
|
||||
// select old track for the game master (if found)
|
||||
irr_driver->setTextureErrorMessage(
|
||||
STKTexManager::getInstance()->setTextureErrorMessage(
|
||||
"While loading screenshot in track screen for last track '%s':",
|
||||
UserConfigParams::m_last_track);
|
||||
if (!tracks_widget->setSelection(UserConfigParams::m_last_track,
|
||||
@ -231,7 +231,7 @@ void TracksAndGPScreen::init()
|
||||
{
|
||||
tracks_widget->setSelection(0, PLAYER_ID_GAME_MASTER, true);
|
||||
}
|
||||
irr_driver->unsetTextureErrorMessage();
|
||||
STKTexManager::getInstance()->unsetTextureErrorMessage();
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
@ -162,7 +162,7 @@ void TracksScreen::init()
|
||||
buildTrackList();
|
||||
|
||||
// select old track for the game master (if found)
|
||||
irr_driver->setTextureErrorMessage(
|
||||
STKTexManager::getInstance()->setTextureErrorMessage(
|
||||
"While loading screenshot in track screen for last track '%s':",
|
||||
UserConfigParams::m_last_track);
|
||||
if (!tracks_widget->setSelection(UserConfigParams::m_last_track,
|
||||
@ -170,7 +170,7 @@ void TracksScreen::init()
|
||||
{
|
||||
tracks_widget->setSelection(0, PLAYER_ID_GAME_MASTER, true);
|
||||
}
|
||||
irr_driver->unsetTextureErrorMessage();
|
||||
STKTexManager::getInstance()->unsetTextureErrorMessage();
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -1563,8 +1563,8 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
||||
assert(!m_current_track);
|
||||
|
||||
// Use m_filename to also get the path, not only the identifier
|
||||
irr_driver->setTextureErrorMessage("While loading track '%s'",
|
||||
m_filename );
|
||||
STKTexManager::getInstance()
|
||||
->setTextureErrorMessage("While loading track '%s'", m_filename);
|
||||
if(!m_reverse_available)
|
||||
{
|
||||
reverse_track = false;
|
||||
@ -1902,7 +1902,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
||||
easter_world->readData(dir+"/easter_eggs.xml");
|
||||
}
|
||||
|
||||
irr_driver->unsetTextureErrorMessage();
|
||||
STKTexManager::getInstance()->unsetTextureErrorMessage();
|
||||
#ifndef SERVER_ONLY
|
||||
if (CVS->isGLSL())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user