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,72 +66,96 @@ 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 { * Copy the given data into our instace.
protected: * @param data The data to copy.
uint duration; ///< Length of display of the message. 0 means forever, */
uint64 decode_params[20]; ///< Parameters of the message strings. ErrorMessageData::ErrorMessageData(const ErrorMessageData &data)
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. *this = data;
uint32 textref_stack[16]; ///< Values to put on the #TextRefStack for the error message. for (size_t i = 0; i < lengthof(this->strings); i++) {
StringID summary_msg; ///< General error message showed in first line. Must be valid. if (this->strings[i] != NULL) {
StringID detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID. this->strings[i] = strdup(this->strings[i]);
Point position; ///< Position of the error message window. this->decode_params[i] = (size_t)this->strings[i];
CompanyID face; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
public:
/**
* Copy the given data into our instace.
* @param data The data to copy.
*/
ErrorMessageData(const ErrorMessageData &data)
{
*this = data;
for (size_t i = 0; i < lengthof(this->strings); i++) {
if (this->strings[i] != NULL) {
this->strings[i] = strdup(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.
* @param duration The amount of time to show this error message. * @param duration The amount of time to show this error message.
* @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile. * @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
* @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile. * @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
* @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.y = y; this->position.x = x;
if (textref_stack_size > 0) StartTextRefStackUsage(textref_stack_size, textref_stack); this->position.y = y;
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);
}
memset(this->decode_params, 0, sizeof(this->decode_params));
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);
}
/**
* 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); CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2);
this->face = (this->detailed_msg == STR_ERROR_OWNED_BY && company < MAX_COMPANIES) ? company : INVALID_COMPANY; if (company < MAX_COMPANIES) face = company;
assert(summary_msg != INVALID_STRING_ID);
} }
}; }
/**
* 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);
@ -340,53 +344,59 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
{ {
const char *str = orig_str == NULL ? "" : orig_str; const char *str = orig_str == NULL ? "" : orig_str;
switch (desc->cmd) { switch (desc->cmd) {
case SDT_NUMX: { case SDT_NUMX: {
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;
}
if (*end != '\0') {
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
msg.SetDParamStr(0, desc->name);
_settings_error_list.push_back(msg);
}
return (void*)val;
}
case SDT_ONEOFMANY: {
size_t r = LookupOneOfMany(desc->many, str);
/* if the first attempt of conversion from string to the appropriate value fails,
* look if we have defined a converter from old value to new value. */
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
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
msg.SetDParamStr(0, str);
msg.SetDParamStr(1, desc->name);
_settings_error_list.push_back(msg);
return desc->def; return desc->def;
} }
if (*end != '\0') { case SDT_MANYOFMANY: {
SetDParamStr(0, desc->name); size_t r = LookupManyOfMany(desc->many, str);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS, WL_CRITICAL); if (r != (size_t)-1) return (void*)r;
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
msg.SetDParamStr(0, str);
msg.SetDParamStr(1, desc->name);
_settings_error_list.push_back(msg);
return desc->def;
} }
return (void*)val; case SDT_BOOLX: {
} if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true;
case SDT_ONEOFMANY: { if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false;
size_t r = LookupOneOfMany(desc->many, str);
/* if the first attempt of conversion from string to the appropriate value fails,
* look if we have defined a converter from old value to new value. */
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
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);
return desc->def; _settings_error_list.push_back(msg);
} return desc->def;
case SDT_MANYOFMANY: { }
size_t r = LookupManyOfMany(desc->many, str);
if (r != (size_t)-1) return (void*)r;
SetDParamStr(0, str);
SetDParamStr(1, desc->name);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
return desc->def;
}
case SDT_BOOLX:
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;
SetDParamStr(0, str); case SDT_STRING: return orig_str;
SetDParamStr(1, desc->name); case SDT_INTLIST: return str;
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL); default: break;
return desc->def;
case SDT_STRING: return orig_str;
case SDT_INTLIST: return str;
default: break;
} }
return NULL; return NULL;
@ -496,38 +506,43 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
ptr = GetVariableAddress(object, sld); ptr = GetVariableAddress(object, sld);
switch (sdb->cmd) { switch (sdb->cmd) {
case SDT_BOOLX: // All four are various types of (integer) numbers case SDT_BOOLX: // All four are various types of (integer) numbers
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)) {
case SLE_VAR_STRB: case SLE_VAR_STRB:
case SLE_VAR_STRBQ: case SLE_VAR_STRBQ:
if (p != NULL) ttd_strlcpy((char*)ptr, (const char*)p, sld->length); if (p != NULL) ttd_strlcpy((char*)ptr, (const char*)p, sld->length);
break; break;
case SLE_VAR_STR: case SLE_VAR_STR:
case SLE_VAR_STRQ: case SLE_VAR_STRQ:
free(*(char**)ptr); free(*(char**)ptr);
*(char**)ptr = p == NULL ? NULL : strdup((const char*)p); *(char**)ptr = p == NULL ? NULL : strdup((const char*)p);
break; break;
case SLE_VAR_CHAR: if (p != NULL) *(char *)ptr = *(const char *)p; break; case SLE_VAR_CHAR: if (p != NULL) *(char *)ptr = *(const char *)p; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
break; break;
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);
} else if (sd->desc.proc_cnvt != NULL) { _settings_error_list.push_back(msg);
sd->desc.proc_cnvt((const char*)p);
/* Use default */
LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
} else if (sd->desc.proc_cnvt != NULL) {
sd->desc.proc_cnvt((const char*)p);
}
break;
} }
break; default: NOT_REACHED();
}
default: NOT_REACHED();
} }
} }
} }
@ -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