Merge branch 'master' into jgrpp

# Conflicts:
#	src/network/network_server.h
#	src/pathfinder/yapf/yapf_road.cpp
#	src/viewport.cpp
This commit is contained in:
Jonathan G Rennison
2020-02-09 15:43:47 +00:00
43 changed files with 240 additions and 81 deletions

View File

@@ -22,6 +22,7 @@
*/
#include "stdafx.h"
#include <limits>
#include "currency.h"
#include "screenshot.h"
#include "network/network.h"
@@ -176,7 +177,8 @@ static size_t LookupManyOfMany(const char *many, const char *str)
* @param maxitems the maximum number of elements the integerlist-array has
* @return returns the number of items found, or -1 on an error
*/
static int ParseIntList(const char *p, int *items, int maxitems)
template<typename T>
static int ParseIntList(const char *p, T *items, int maxitems)
{
int n = 0; // number of items read so far
bool comma = false; // do we accept comma?
@@ -196,9 +198,9 @@ static int ParseIntList(const char *p, int *items, int maxitems)
default: {
if (n == maxitems) return -1; // we don't accept that many numbers
char *end;
long v = strtol(p, &end, 0);
unsigned long v = strtoul(p, &end, 0);
if (p == end) return -1; // invalid character (not a number)
if (sizeof(int) < sizeof(long)) v = ClampToI32(v);
if (sizeof(T) < sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
items[n++] = v;
p = end; // first non-number
comma = true; // we accept comma now
@@ -224,7 +226,7 @@ static int ParseIntList(const char *p, int *items, int maxitems)
*/
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
{
int items[64];
unsigned long items[64];
int i, nitems;
if (str == nullptr) {
@@ -273,7 +275,7 @@ static void MakeIntList(char *buf, const char *last, const void *array, int nele
const byte *p = (const byte *)array;
for (i = 0; i != nelems; i++) {
switch (type) {
switch (GetVarMemType(type)) {
case SLE_VAR_BL:
case SLE_VAR_I8: v = *(const int8 *)p; p += 1; break;
case SLE_VAR_U8: v = *(const uint8 *)p; p += 1; break;
@@ -283,7 +285,13 @@ static void MakeIntList(char *buf, const char *last, const void *array, int nele
case SLE_VAR_U32: v = *(const uint32 *)p; p += 4; break;
default: NOT_REACHED();
}
buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
if (IsSignedVarMemType(type)) {
buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
} else if (type & SLF_HEX) {
buf += seprintf(buf, last, (i == 0) ? "0x%X" : ",0x%X", v);
} else {
buf += seprintf(buf, last, (i == 0) ? "%u" : ",%u", v);
}
}
}
@@ -696,7 +704,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
switch (sdb->cmd) {
case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break;
case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break;
case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : (sld->conv & SLF_HEX) ? "%X" : "%u", i); break;
case SDT_ONEOFMANY: MakeOneOfMany(buf, lastof(buf), sdb->many, i); break;
case SDT_MANYOFMANY: MakeManyOfMany(buf, lastof(buf), sdb->many, i); break;
default: NOT_REACHED();
@@ -724,7 +732,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
break;
case SDT_INTLIST:
MakeIntList(buf, lastof(buf), ptr, sld->length, GetVarMemType(sld->conv));
MakeIntList(buf, lastof(buf), ptr, sld->length, sld->conv);
break;
default: NOT_REACHED();
@@ -1703,7 +1711,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
/* Parse parameters */
if (!StrEmpty(item->value)) {
int count = ParseIntList(item->value, (int*)c->param, lengthof(c->param));
int count = ParseIntList(item->value, c->param, lengthof(c->param));
if (count < 0) {
SetDParamStr(0, filename);
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);