Merge branch 'optimise-archiving' into 'next'
Optimise net-archiving of Lua strings, numbers and booleans See merge request STJr/SRB2!904
This commit is contained in:
commit
62d5d16f5c
|
@ -730,9 +730,13 @@ void LUA_InvalidatePlayer(player_t *player)
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ARCH_NULL=0,
|
ARCH_NULL=0,
|
||||||
ARCH_BOOLEAN,
|
ARCH_TRUE,
|
||||||
ARCH_SIGNED,
|
ARCH_FALSE,
|
||||||
ARCH_STRING,
|
ARCH_INT8,
|
||||||
|
ARCH_INT16,
|
||||||
|
ARCH_INT32,
|
||||||
|
ARCH_SMALLSTRING,
|
||||||
|
ARCH_LARGESTRING,
|
||||||
ARCH_TABLE,
|
ARCH_TABLE,
|
||||||
|
|
||||||
ARCH_MOBJINFO,
|
ARCH_MOBJINFO,
|
||||||
|
@ -817,22 +821,33 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
|
||||||
WRITEUINT8(save_p, ARCH_NULL);
|
WRITEUINT8(save_p, ARCH_NULL);
|
||||||
return 2;
|
return 2;
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
WRITEUINT8(save_p, ARCH_BOOLEAN);
|
WRITEUINT8(save_p, lua_toboolean(gL, myindex) ? ARCH_TRUE : ARCH_FALSE);
|
||||||
WRITEUINT8(save_p, lua_toboolean(gL, myindex));
|
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMBER:
|
||||||
{
|
{
|
||||||
lua_Integer number = lua_tointeger(gL, myindex);
|
lua_Integer number = lua_tointeger(gL, myindex);
|
||||||
WRITEUINT8(save_p, ARCH_SIGNED);
|
if (number >= INT8_MIN && number <= INT8_MAX)
|
||||||
WRITEFIXED(save_p, number);
|
{
|
||||||
|
WRITEUINT8(save_p, ARCH_INT8);
|
||||||
|
WRITESINT8(save_p, number);
|
||||||
|
}
|
||||||
|
else if (number >= INT16_MIN && number <= INT16_MAX)
|
||||||
|
{
|
||||||
|
WRITEUINT8(save_p, ARCH_INT16);
|
||||||
|
WRITEINT16(save_p, number);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WRITEUINT8(save_p, ARCH_INT32);
|
||||||
|
WRITEFIXED(save_p, number);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
{
|
{
|
||||||
UINT16 len = (UINT16)lua_objlen(gL, myindex); // get length of string, including embedded zeros
|
UINT32 len = (UINT32)lua_objlen(gL, myindex); // get length of string, including embedded zeros
|
||||||
const char *s = lua_tostring(gL, myindex);
|
const char *s = lua_tostring(gL, myindex);
|
||||||
UINT16 i = 0;
|
UINT32 i = 0;
|
||||||
WRITEUINT8(save_p, ARCH_STRING);
|
|
||||||
// if you're wondering why we're writing a string to save_p this way,
|
// if you're wondering why we're writing a string to save_p this way,
|
||||||
// it turns out that Lua can have embedded zeros ('\0') in the strings,
|
// it turns out that Lua can have embedded zeros ('\0') in the strings,
|
||||||
// so we can't use WRITESTRING as that cuts off when it finds a '\0'.
|
// so we can't use WRITESTRING as that cuts off when it finds a '\0'.
|
||||||
|
@ -840,7 +855,16 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
|
||||||
// fixing the awful crashes previously encountered for reading strings longer than 1024
|
// fixing the awful crashes previously encountered for reading strings longer than 1024
|
||||||
// (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?)
|
// (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?)
|
||||||
// -- Monster Iestyn 05/08/18
|
// -- Monster Iestyn 05/08/18
|
||||||
WRITEUINT16(save_p, len); // save size of string
|
if (len < 255)
|
||||||
|
{
|
||||||
|
WRITEUINT8(save_p, ARCH_SMALLSTRING);
|
||||||
|
WRITEUINT8(save_p, len); // save size of string
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WRITEUINT8(save_p, ARCH_LARGESTRING);
|
||||||
|
WRITEUINT32(save_p, len); // save size of string
|
||||||
|
}
|
||||||
while (i < len)
|
while (i < len)
|
||||||
WRITECHAR(save_p, s[i++]); // write chars individually, including the embedded zeros
|
WRITECHAR(save_p, s[i++]); // write chars individually, including the embedded zeros
|
||||||
break;
|
break;
|
||||||
|
@ -1170,21 +1194,36 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
|
||||||
case ARCH_NULL:
|
case ARCH_NULL:
|
||||||
lua_pushnil(gL);
|
lua_pushnil(gL);
|
||||||
break;
|
break;
|
||||||
case ARCH_BOOLEAN:
|
case ARCH_TRUE:
|
||||||
lua_pushboolean(gL, READUINT8(save_p));
|
lua_pushboolean(gL, true);
|
||||||
break;
|
break;
|
||||||
case ARCH_SIGNED:
|
case ARCH_FALSE:
|
||||||
|
lua_pushboolean(gL, false);
|
||||||
|
break;
|
||||||
|
case ARCH_INT8:
|
||||||
|
lua_pushinteger(gL, READSINT8(save_p));
|
||||||
|
break;
|
||||||
|
case ARCH_INT16:
|
||||||
|
lua_pushinteger(gL, READINT16(save_p));
|
||||||
|
break;
|
||||||
|
case ARCH_INT32:
|
||||||
lua_pushinteger(gL, READFIXED(save_p));
|
lua_pushinteger(gL, READFIXED(save_p));
|
||||||
break;
|
break;
|
||||||
case ARCH_STRING:
|
case ARCH_SMALLSTRING:
|
||||||
|
case ARCH_LARGESTRING:
|
||||||
{
|
{
|
||||||
UINT16 len = READUINT16(save_p); // length of string, including embedded zeros
|
UINT32 len;
|
||||||
char *value;
|
char *value;
|
||||||
UINT16 i = 0;
|
UINT32 i = 0;
|
||||||
|
|
||||||
// See my comments in the ArchiveValue function;
|
// See my comments in the ArchiveValue function;
|
||||||
// it's much the same for reading strings as writing them!
|
// it's much the same for reading strings as writing them!
|
||||||
// (i.e. we can't use READSTRING either)
|
// (i.e. we can't use READSTRING either)
|
||||||
// -- Monster Iestyn 05/08/18
|
// -- Monster Iestyn 05/08/18
|
||||||
|
if (type == ARCH_SMALLSTRING)
|
||||||
|
len = READUINT8(save_p); // length of string, including embedded zeros
|
||||||
|
else
|
||||||
|
len = READUINT32(save_p); // length of string, including embedded zeros
|
||||||
value = malloc(len); // make temp buffer of size len
|
value = malloc(len); // make temp buffer of size len
|
||||||
// now read the actual string
|
// now read the actual string
|
||||||
while (i < len)
|
while (i < len)
|
||||||
|
|
Loading…
Reference in New Issue