1
0
Fork 0

(svn r24254) [1.2] -Backport from trunk:

- Fix: Change the unit of the sprite-cache size setting from megabytes to megapixels, so it depends on the blitter being used. Also increase it from 64 to 128, and change the name in the cfg file, so everyone gets the new default [FS#5162] (r24252)
- Fix: Do not immediately display error messages from parsing the cfg file, but schedule them for displaying after the GUI is prepared for it [FS#5154] (r24250, r24249, r24248, r24247)
- Fix: The object GUI did not draw objects when all objects of a class are disabled (r24176)
release/1.2
rubidium 2012-05-15 20:54:40 +00:00
parent b8abfce71d
commit b6549a448d
6 changed files with 223 additions and 136 deletions

View File

@ -13,6 +13,8 @@
#define ERROR_H #define ERROR_H
#include "strings_type.h" #include "strings_type.h"
#include "company_type.h"
#include "core/geometry_type.hpp"
/** Message severity/type */ /** Message severity/type */
enum WarningLevel { enum WarningLevel {
@ -22,6 +24,30 @@ enum WarningLevel {
WL_CRITICAL, ///< Critical errors, the MessageBox is shown in all cases WL_CRITICAL, ///< Critical errors, the MessageBox is shown in all cases
}; };
/** The data of the error message. */
class ErrorMessageData {
protected:
uint duration; ///< Length of display of the message. 0 means forever,
uint64 decode_params[20]; ///< Parameters of the message strings.
const char *strings[20]; ///< Copies of raw strings that were used.
uint textref_stack_size; ///< Number of uint32 values to put on the #TextRefStack for the error message.
uint32 textref_stack[16]; ///< Values to put on the #TextRefStack for the error message.
StringID summary_msg; ///< General error message showed in first line. Must be valid.
StringID detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID.
Point position; ///< Position of the error message window.
CompanyID face; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
public:
ErrorMessageData(const ErrorMessageData &data);
~ErrorMessageData();
ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration = 0, int x = 0, int y = 0, uint textref_stack_size = 0, const uint32 *textref_stack = NULL);
void SetDParam(uint n, uint64 v);
void SetDParamStr(uint n, const char *str);
void CopyOutDParams();
};
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, uint textref_stack_size = 0, const uint32 *textref_stack = NULL); void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, uint textref_stack_size = 0, const uint32 *textref_stack = NULL);
void ClearErrorMessages(); void ClearErrorMessages();
void ShowFirstError(); void ShowFirstError();

View File

@ -66,26 +66,12 @@ static const WindowDesc _errmsg_face_desc(
_nested_errmsg_face_widgets, lengthof(_nested_errmsg_face_widgets) _nested_errmsg_face_widgets, lengthof(_nested_errmsg_face_widgets)
); );
/** The data of the error message. */ /**
class ErrorMessageData {
protected:
uint duration; ///< Length of display of the message. 0 means forever,
uint64 decode_params[20]; ///< Parameters of the message strings.
const char *strings[20]; ///< Copies of raw strings that were used.
uint textref_stack_size; ///< Number of uint32 values to put on the #TextRefStack for the error message.
uint32 textref_stack[16]; ///< Values to put on the #TextRefStack for the error message.
StringID summary_msg; ///< General error message showed in first line. Must be valid.
StringID detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID.
Point position; ///< Position of the error message window.
CompanyID face; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
public:
/**
* Copy the given data into our instace. * Copy the given data into our instace.
* @param data The data to copy. * @param data The data to copy.
*/ */
ErrorMessageData(const ErrorMessageData &data) ErrorMessageData::ErrorMessageData(const ErrorMessageData &data)
{ {
*this = data; *this = data;
for (size_t i = 0; i < lengthof(this->strings); i++) { for (size_t i = 0; i < lengthof(this->strings); i++) {
if (this->strings[i] != NULL) { if (this->strings[i] != NULL) {
@ -93,15 +79,15 @@ public:
this->decode_params[i] = (size_t)this->strings[i]; this->decode_params[i] = (size_t)this->strings[i];
} }
} }
} }
/** Free all the strings. */ /** Free all the strings. */
~ErrorMessageData() ErrorMessageData::~ErrorMessageData()
{ {
for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]); for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]);
} }
/** /**
* Display an error message in a window. * Display an error message in a window.
* @param summary_msg General error message showed in first line. Must be valid. * @param summary_msg General error message showed in first line. Must be valid.
* @param detailed_msg Detailed error message showed in second line. Can be INVALID_STRING_ID. * @param detailed_msg Detailed error message showed in second line. Can be INVALID_STRING_ID.
@ -111,27 +97,65 @@ public:
* @param textref_stack_size Number of uint32 values to put on the #TextRefStack for the error message; 0 if the #TextRefStack shall not be used. * @param textref_stack_size Number of uint32 values to put on the #TextRefStack for the error message; 0 if the #TextRefStack shall not be used.
* @param textref_stack Values to put on the #TextRefStack. * @param textref_stack Values to put on the #TextRefStack.
*/ */
ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration, int x, int y, uint textref_stack_size, const uint32 *textref_stack) : ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration, int x, int y, uint textref_stack_size, const uint32 *textref_stack) :
duration(duration), duration(duration),
textref_stack_size(textref_stack_size), textref_stack_size(textref_stack_size),
summary_msg(summary_msg), summary_msg(summary_msg),
detailed_msg(detailed_msg) detailed_msg(detailed_msg),
{ face(INVALID_COMPANY)
{
this->position.x = x; this->position.x = x;
this->position.y = y; this->position.y = y;
if (textref_stack_size > 0) StartTextRefStackUsage(textref_stack_size, textref_stack);
CopyOutDParam(this->decode_params, this->strings, detailed_msg == INVALID_STRING_ID ? summary_msg : detailed_msg, lengthof(this->decode_params));
if (textref_stack_size > 0) {
StopTextRefStackUsage();
MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
}
CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2); memset(this->decode_params, 0, sizeof(this->decode_params));
this->face = (this->detailed_msg == STR_ERROR_OWNED_BY && company < MAX_COMPANIES) ? company : INVALID_COMPANY; memset(this->strings, 0, sizeof(this->strings));
if (textref_stack_size > 0) MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
assert(summary_msg != INVALID_STRING_ID); assert(summary_msg != INVALID_STRING_ID);
}
/**
* Copy error parameters from current DParams.
*/
void ErrorMessageData::CopyOutDParams()
{
/* Reset parameters */
for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]);
memset(this->decode_params, 0, sizeof(this->decode_params));
memset(this->strings, 0, sizeof(this->strings));
/* Get parameters using type information */
if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_size, this->textref_stack);
CopyOutDParam(this->decode_params, this->strings, this->detailed_msg == INVALID_STRING_ID ? this->summary_msg : this->detailed_msg, lengthof(this->decode_params));
if (this->textref_stack_size > 0) StopTextRefStackUsage();
if (this->detailed_msg == STR_ERROR_OWNED_BY) {
CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2);
if (company < MAX_COMPANIES) face = company;
} }
}; }
/**
* Set a error string parameter.
* @param n Parameter index
* @param v Parameter value
*/
void ErrorMessageData::SetDParam(uint n, uint64 v)
{
this->decode_params[n] = v;
}
/**
* Set a rawstring parameter.
* @param n Parameter index
* @param str Raw string
*/
void ErrorMessageData::SetDParamStr(uint n, const char *str)
{
free(this->strings[n]);
this->strings[n] = strdup(str);
}
/** Define a queue with errors. */ /** Define a queue with errors. */
typedef std::list<ErrorMessageData> ErrorList; typedef std::list<ErrorMessageData> ErrorList;
@ -367,6 +391,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return; if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return;
ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? 0 : _settings_client.gui.errmsg_duration, x, y, textref_stack_size, textref_stack); ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? 0 : _settings_client.gui.errmsg_duration, x, y, textref_stack_size, textref_stack);
data.CopyOutDParams();
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
if (w != NULL && w->IsCritical()) { if (w != NULL && w->IsCritical()) {
@ -382,3 +407,13 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
new ErrmsgWindow(data); new ErrmsgWindow(data);
} }
} }
/**
* Schedule a list of errors.
* Note: This does not try to display the error now. This is useful if the window system is not yet running.
* @param data Error message datas; cleared afterwards
*/
void ScheduleErrorMessage(ErrorList &datas)
{
_error_list.splice(_error_list.end(), datas);
}

View File

@ -192,8 +192,6 @@ public:
} }
case WID_BO_SELECT_IMAGE: { case WID_BO_SELECT_IMAGE: {
if (_selected_object_index < 0) break;
int obj_index = GB(widget, 16, 16); int obj_index = GB(widget, 16, 16);
const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, obj_index); const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, obj_index);
if (spec == NULL) break; if (spec == NULL) break;

View File

@ -77,6 +77,10 @@ GameSettings _settings_newgame; ///< Game settings for new games (updated from
VehicleDefaultSettings _old_vds; ///< Used for loading default vehicles settings from old savegames VehicleDefaultSettings _old_vds; ///< Used for loading default vehicles settings from old savegames
char *_config_file; ///< Configuration file of OpenTTD char *_config_file; ///< Configuration file of OpenTTD
typedef std::list<ErrorMessageData> ErrorList;
static ErrorList _settings_error_list; ///< Errors while loading minimal settings.
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object); typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list); typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list);
@ -344,14 +348,16 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
char *end; char *end;
size_t val = strtoul(str, &end, 0); size_t val = strtoul(str, &end, 0);
if (end == str) { if (end == str) {
SetDParamStr(0, str); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
SetDParamStr(1, desc->name); msg.SetDParamStr(0, str);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL); msg.SetDParamStr(1, desc->name);
_settings_error_list.push_back(msg);
return desc->def; return desc->def;
} }
if (*end != '\0') { if (*end != '\0') {
SetDParamStr(0, desc->name); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS, WL_CRITICAL); msg.SetDParamStr(0, desc->name);
_settings_error_list.push_back(msg);
} }
return (void*)val; return (void*)val;
} }
@ -362,27 +368,31 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
if (r == (size_t)-1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str); if (r == (size_t)-1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str);
if (r != (size_t)-1) return (void*)r; // and here goes converted value if (r != (size_t)-1) return (void*)r; // and here goes converted value
SetDParamStr(0, str); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
SetDParamStr(1, desc->name); msg.SetDParamStr(0, str);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL); msg.SetDParamStr(1, desc->name);
_settings_error_list.push_back(msg);
return desc->def; return desc->def;
} }
case SDT_MANYOFMANY: { case SDT_MANYOFMANY: {
size_t r = LookupManyOfMany(desc->many, str); size_t r = LookupManyOfMany(desc->many, str);
if (r != (size_t)-1) return (void*)r; if (r != (size_t)-1) return (void*)r;
SetDParamStr(0, str); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
SetDParamStr(1, desc->name); msg.SetDParamStr(0, str);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL); msg.SetDParamStr(1, desc->name);
_settings_error_list.push_back(msg);
return desc->def; return desc->def;
} }
case SDT_BOOLX: case SDT_BOOLX: {
if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true; if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true;
if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false; if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false;
SetDParamStr(0, str); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
SetDParamStr(1, desc->name); msg.SetDParamStr(0, str);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL); msg.SetDParamStr(1, desc->name);
_settings_error_list.push_back(msg);
return desc->def; return desc->def;
}
case SDT_STRING: return orig_str; case SDT_STRING: return orig_str;
case SDT_INTLIST: return str; case SDT_INTLIST: return str;
@ -500,7 +510,8 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
case SDT_NUMX: case SDT_NUMX:
case SDT_ONEOFMANY: case SDT_ONEOFMANY:
case SDT_MANYOFMANY: case SDT_MANYOFMANY:
Write_ValidateSetting(ptr, sd, (int32)(size_t)p); break; Write_ValidateSetting(ptr, sd, (int32)(size_t)p);
break;
case SDT_STRING: case SDT_STRING:
switch (GetVarMemType(sld->conv)) { switch (GetVarMemType(sld->conv)) {
@ -520,8 +531,12 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
case SDT_INTLIST: { case SDT_INTLIST: {
if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) { if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
SetDParamStr(0, sdb->name); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL); msg.SetDParamStr(0, sdb->name);
_settings_error_list.push_back(msg);
/* Use default */
LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
} else if (sd->desc.proc_cnvt != NULL) { } else if (sd->desc.proc_cnvt != NULL) {
sd->desc.proc_cnvt((const char*)p); sd->desc.proc_cnvt((const char*)p);
} }
@ -1626,6 +1641,11 @@ void LoadFromConfig(bool minimal)
HandleOldDiffCustom(false); HandleOldDiffCustom(false);
ValidateSettings(); ValidateSettings();
/* Display sheduled errors */
extern void ScheduleErrorMessage(ErrorList &datas);
ScheduleErrorMessage(_settings_error_list);
if (FindWindowById(WC_ERRMSG, 0) == NULL) ShowFirstError();
} }
delete ini; delete ini;

View File

@ -79,6 +79,7 @@ struct MemBlock {
static uint _sprite_lru_counter; static uint _sprite_lru_counter;
static MemBlock *_spritecache_ptr; static MemBlock *_spritecache_ptr;
static uint _allocated_sprite_cache_size = 0;
static int _compact_cache_counter; static int _compact_cache_counter;
static void CompactSpriteCache(); static void CompactSpriteCache();
@ -843,10 +844,17 @@ void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator)
static void GfxInitSpriteCache() static void GfxInitSpriteCache()
{ {
/* initialize sprite cache heap */ /* initialize sprite cache heap */
if (_spritecache_ptr == NULL) _spritecache_ptr = (MemBlock*)MallocT<byte>(_sprite_cache_size * 1024 * 1024); int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
uint target_size = _sprite_cache_size * 1024 * 1024 * max(1, bpp / 8);
if (_spritecache_ptr == NULL || _allocated_sprite_cache_size != target_size) {
free(_spritecache_ptr);
_allocated_sprite_cache_size = target_size;
_spritecache_ptr = (MemBlock*)MallocT<byte>(_allocated_sprite_cache_size);
}
/* A big free block */ /* A big free block */
_spritecache_ptr->size = ((_sprite_cache_size * 1024 * 1024) - sizeof(MemBlock)) | S_FREE_MASK; _spritecache_ptr->size = (_allocated_sprite_cache_size - sizeof(MemBlock)) | S_FREE_MASK;
/* Sentinel block (identified by size == 0) */ /* Sentinel block (identified by size == 0) */
NextBlock(_spritecache_ptr)->size = 0; NextBlock(_spritecache_ptr)->size = 0;
} }

View File

@ -212,10 +212,10 @@ var = _freetype.mono_aa
def = false def = false
[SDTG_VAR] [SDTG_VAR]
name = ""max_sprite_cache_size"" name = ""sprite_cache_size_px""
type = SLE_UINT type = SLE_UINT
var = _sprite_cache_size var = _sprite_cache_size
def = 64 def = 128
min = 1 min = 1
max = 512 max = 512