Merge branch 'jgrpp' into save_ext_spp
This commit is contained in:
@@ -234,7 +234,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @note In general, it is better to use one of the SLE_* macros below.
|
||||
*/
|
||||
#define SLE_GENERAL_X(cmd, base, variable, type, length, from, to, extver) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable), cpp_sizeof(base, variable), extver}
|
||||
#define SLE_GENERAL(cmd, base, variable, type, length, from, to) SLE_GENERAL_X(cmd, base, variable, type, length, from, to, {})
|
||||
#define SLE_GENERAL(cmd, base, variable, type, length, from, to) SLE_GENERAL_X(cmd, base, variable, type, length, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a variable in some savegame versions.
|
||||
@@ -246,7 +246,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDVAR_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_VAR, base, variable, type, 0, from, to, extver)
|
||||
#define SLE_CONDVAR(base, variable, type, from, to) SLE_CONDVAR_X(base, variable, type, from, to, {})
|
||||
#define SLE_CONDVAR(base, variable, type, from, to) SLE_CONDVAR_X(base, variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a reference in some savegame versions.
|
||||
@@ -258,7 +258,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDREF_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_REF, base, variable, type, 0, from, to, extver)
|
||||
#define SLE_CONDREF(base, variable, type, from, to) SLE_CONDREF_X(base, variable, type, from, to, {})
|
||||
#define SLE_CONDREF(base, variable, type, from, to) SLE_CONDREF_X(base, variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of an array in some savegame versions.
|
||||
@@ -271,7 +271,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDARR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_ARR, base, variable, type, length, from, to, extver)
|
||||
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_CONDARR_X(base, variable, type, length, from, to, {})
|
||||
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_CONDARR_X(base, variable, type, length, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a string in some savegame versions.
|
||||
@@ -284,7 +284,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDSTR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_STR, base, variable, type, length, from, to, extver)
|
||||
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_CONDSTR_X(base, variable, type, length, from, to, {})
|
||||
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_CONDSTR_X(base, variable, type, length, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a list in some savegame versions.
|
||||
@@ -296,7 +296,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDLST_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_LST, base, variable, type, 0, from, to, extver)
|
||||
#define SLE_CONDLST(base, variable, type, from, to) SLE_CONDLST_X(base, variable, type, from, to, {})
|
||||
#define SLE_CONDLST(base, variable, type, from, to) SLE_CONDLST_X(base, variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a variable in every version of a savegame.
|
||||
@@ -354,16 +354,16 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have empty space
|
||||
*/
|
||||
#define SLE_CONDNULL_X(length, from, to, extver) SLE_CONDARR_X(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, extver)
|
||||
#define SLE_CONDNULL(length, from, to) SLE_CONDNULL_X(length, from, to, {})
|
||||
#define SLE_CONDNULL(length, from, to) SLE_CONDNULL_X(length, from, to, SlXvFeatureTest())
|
||||
|
||||
/** Translate values ingame to different values in the savegame and vv. */
|
||||
#define SLE_WRITEBYTE(base, variable, value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value)
|
||||
|
||||
#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0, {}}
|
||||
#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0, {}}
|
||||
#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0, SlXvFeatureTest()}
|
||||
#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0, SlXvFeatureTest()}
|
||||
|
||||
/** End marker of a struct/class save or load. */
|
||||
#define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL, 0, {}}
|
||||
#define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL, 0, SlXvFeatureTest()}
|
||||
|
||||
/**
|
||||
* Storage of global simple variables, references (pointers), and arrays.
|
||||
@@ -376,7 +376,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @note In general, it is better to use one of the SLEG_* macros below.
|
||||
*/
|
||||
#define SLEG_GENERAL_X(cmd, variable, type, length, from, to, extver) {true, cmd, type, length, from, to, (void*)&variable, sizeof(variable), extver}
|
||||
#define SLEG_GENERAL(cmd, variable, type, length, from, to) SLEG_GENERAL_X(cmd, variable, type, length, from, to, {})
|
||||
#define SLEG_GENERAL(cmd, variable, type, length, from, to) SLEG_GENERAL_X(cmd, variable, type, length, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global variable in some savegame versions.
|
||||
@@ -387,7 +387,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLEG_CONDVAR_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_VAR, variable, type, 0, from, to, extver)
|
||||
#define SLEG_CONDVAR(variable, type, from, to) SLEG_CONDVAR_X(variable, type, from, to, {})
|
||||
#define SLEG_CONDVAR(variable, type, from, to) SLEG_CONDVAR_X(variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global reference in some savegame versions.
|
||||
@@ -398,7 +398,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLEG_CONDREF_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_REF, variable, type, 0, from, to, extver)
|
||||
#define SLEG_CONDREF(variable, type, from, to) SLEG_CONDREF_X(variable, type, from, to, {})
|
||||
#define SLEG_CONDREF(variable, type, from, to) SLEG_CONDREF_X(variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global array in some savegame versions.
|
||||
@@ -410,7 +410,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLEG_CONDARR_X(variable, type, length, from, to, extver) SLEG_GENERAL_X(SL_ARR, variable, type, length, from, to, extver)
|
||||
#define SLEG_CONDARR(variable, type, length, from, to) SLEG_CONDARR_X(variable, type, length, from, to, {})
|
||||
#define SLEG_CONDARR(variable, type, length, from, to) SLEG_CONDARR_X(variable, type, length, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global string in some savegame versions.
|
||||
@@ -422,7 +422,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLEG_CONDSTR_X(variable, type, length, from, to, extver) SLEG_GENERAL_X(SL_STR, variable, type, length, from, to, extver)
|
||||
#define SLEG_CONDSTR(variable, type, length, from, to) SLEG_CONDSTR_X(variable, type, length, from, to, {})
|
||||
#define SLEG_CONDSTR(variable, type, length, from, to) SLEG_CONDSTR_X(variable, type, length, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global list in some savegame versions.
|
||||
@@ -433,7 +433,7 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLEG_CONDLST_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_LST, variable, type, 0, from, to, extver)
|
||||
#define SLEG_CONDLST(variable, type, from, to) SLEG_CONDLST_X(variable, type, from, to, {})
|
||||
#define SLEG_CONDLST(variable, type, from, to) SLEG_CONDLST_X(variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a global variable in every savegame version.
|
||||
@@ -477,10 +477,10 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param to Last savegame version that has the empty space.
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have empty space
|
||||
*/
|
||||
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL, {}}
|
||||
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL, SlXvFeatureTest()}
|
||||
|
||||
/** End marker of global variables save or load. */
|
||||
#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL, 0, {}}
|
||||
#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL, 0, SlXvFeatureTest()}
|
||||
|
||||
/**
|
||||
* Checks whether the savegame is below \a major.\a minor.
|
||||
|
@@ -23,30 +23,30 @@ typedef std::vector<byte> Buffer;
|
||||
|
||||
static void WriteVLI(Buffer &b, uint i)
|
||||
{
|
||||
uint lsmask = 0x7F;
|
||||
uint msmask = ~0x7F;
|
||||
while(i & msmask) {
|
||||
byte part = (i & lsmask) | 0x80;
|
||||
b.push_back(part);
|
||||
i >>= 7;
|
||||
}
|
||||
b.push_back((byte) i);
|
||||
uint lsmask = 0x7F;
|
||||
uint msmask = ~0x7F;
|
||||
while(i & msmask) {
|
||||
byte part = (i & lsmask) | 0x80;
|
||||
b.push_back(part);
|
||||
i >>= 7;
|
||||
}
|
||||
b.push_back((byte) i);
|
||||
}
|
||||
|
||||
static uint ReadVLI()
|
||||
{
|
||||
uint shift = 0;
|
||||
uint val = 0;
|
||||
byte b;
|
||||
uint shift = 0;
|
||||
uint val = 0;
|
||||
byte b;
|
||||
|
||||
b = SlReadByte();
|
||||
while(b & 0x80) {
|
||||
val |= uint(b & 0x7F) << shift;
|
||||
shift += 7;
|
||||
b = SlReadByte();
|
||||
}
|
||||
val |= uint(b) << shift;
|
||||
return val;
|
||||
b = SlReadByte();
|
||||
while(b & 0x80) {
|
||||
val |= uint(b & 0x7F) << shift;
|
||||
shift += 7;
|
||||
b = SlReadByte();
|
||||
}
|
||||
val |= uint(b) << shift;
|
||||
return val;
|
||||
}
|
||||
|
||||
static void WriteCondition(Buffer &b, SignalCondition *c)
|
||||
@@ -59,13 +59,13 @@ static void WriteCondition(Buffer &b, SignalCondition *c)
|
||||
WriteVLI(b, vc->comparator);
|
||||
WriteVLI(b, vc->value);
|
||||
} break;
|
||||
|
||||
|
||||
case PSC_SIGNAL_STATE: {
|
||||
SignalStateCondition *sc = static_cast<SignalStateCondition*>(c);
|
||||
WriteVLI(b, sc->sig_tile);
|
||||
WriteVLI(b, sc->sig_track);
|
||||
} break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -83,13 +83,13 @@ static SignalCondition *ReadCondition(SignalReference this_sig)
|
||||
c->value = ReadVLI();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
case PSC_SIGNAL_STATE: {
|
||||
TileIndex ti = (TileIndex) ReadVLI();
|
||||
Trackdir td = (Trackdir) ReadVLI();
|
||||
return new SignalStateCondition(this_sig, ti, td);
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
return new SignalSimpleCondition(code);
|
||||
}
|
||||
@@ -111,17 +111,16 @@ static void Save_SPRG()
|
||||
if(i == e) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// OK, we can now write out our programs
|
||||
Buffer b;
|
||||
WriteVLI(b, _signal_programs.size());
|
||||
for(ProgramList::iterator i = _signal_programs.begin(), e = _signal_programs.end();
|
||||
i != e; ++i) {
|
||||
SignalReference ref = i->first;
|
||||
SignalProgram *prog = i->second;
|
||||
|
||||
|
||||
prog->DebugPrintProgram();
|
||||
|
||||
|
||||
WriteVLI(b, prog->tile);
|
||||
WriteVLI(b, prog->track);
|
||||
WriteVLI(b, prog->instructions.Length());
|
||||
@@ -137,44 +136,45 @@ static void Save_SPRG()
|
||||
WriteVLI(b, s->next->Id());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PSO_LAST: break;
|
||||
|
||||
|
||||
case PSO_IF: {
|
||||
SignalIf *i = static_cast<SignalIf*>(insn);
|
||||
WriteCondition(b, i->condition);
|
||||
WriteVLI(b, i->if_true->Id());
|
||||
WriteVLI(b, i->if_true->Id());
|
||||
WriteVLI(b, i->if_false->Id());
|
||||
WriteVLI(b, i->after->Id());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PSO_IF_ELSE:
|
||||
case PSO_IF_ENDIF: {
|
||||
SignalIf::PseudoInstruction *p = static_cast<SignalIf::PseudoInstruction*>(insn);
|
||||
WriteVLI(b, p->block->Id());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PSO_SET_SIGNAL: {
|
||||
SignalSet *s = static_cast<SignalSet*>(insn);
|
||||
WriteVLI(b, s->next->Id());
|
||||
WriteVLI(b, s->to_state ? 1 : 0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint size = b.size();
|
||||
SlSetLength(size);
|
||||
for(uint i = 0; i < size; i++)
|
||||
for(uint i = 0; i < size; i++) {
|
||||
SlWriteByte(b[i]); // TODO Gotta be a better way
|
||||
}
|
||||
}
|
||||
|
||||
// We don't know the pointer values that need to be stored in various
|
||||
// We don't know the pointer values that need to be stored in various
|
||||
// instruction fields at load time, so we need to instead store the IDs and
|
||||
// then fix them up once all of the instructions have been loaded.
|
||||
//
|
||||
@@ -185,7 +185,7 @@ struct Fixup {
|
||||
Fixup(SignalInstruction **p, SignalOpcode type)
|
||||
: type(type), ptr(p)
|
||||
{}
|
||||
|
||||
|
||||
SignalOpcode type;
|
||||
SignalInstruction **ptr;
|
||||
};
|
||||
@@ -205,9 +205,9 @@ static void DoFixups(FixupList &l, InstructionList &il)
|
||||
uint id = reinterpret_cast<size_t>(*i->ptr);
|
||||
if(id >= il.Length())
|
||||
NOT_REACHED();
|
||||
|
||||
|
||||
*i->ptr = il[id];
|
||||
|
||||
|
||||
if(i->type != PSO_INVALID && (*i->ptr)->Opcode() != i->type) {
|
||||
DEBUG(sl, 0, "Expected Id %d to be %d, but was in fact %d", id, i->type, (*i->ptr)->Opcode());
|
||||
NOT_REACHED();
|
||||
@@ -224,10 +224,10 @@ static void Load_SPRG()
|
||||
Track track = (Track) ReadVLI();
|
||||
uint instructions = ReadVLI();
|
||||
SignalReference ref(tile, track);
|
||||
|
||||
|
||||
SignalProgram *sp = new SignalProgram(tile, track, true);
|
||||
_signal_programs[ref] = sp;
|
||||
|
||||
|
||||
for(uint j = 0; j < instructions; j++) {
|
||||
SignalOpcode op = (SignalOpcode) ReadVLI();
|
||||
switch(op) {
|
||||
@@ -237,24 +237,24 @@ static void Load_SPRG()
|
||||
MakeFixup(l, sp->first_instruction->next, ReadVLI());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PSO_LAST: {
|
||||
sp->last_instruction = new SignalSpecial(sp, PSO_LAST);
|
||||
sp->last_instruction->next = NULL;
|
||||
MakeFixup(l, sp->last_instruction->GetPrevHandle(), ReadVLI());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PSO_IF: {
|
||||
SignalIf *i = new SignalIf(sp, true);
|
||||
MakeFixup(l, i->GetPrevHandle(), ReadVLI());
|
||||
i->condition = ReadCondition(ref);
|
||||
MakeFixup(l, i->if_true, ReadVLI());
|
||||
MakeFixup(l, i->if_false, ReadVLI());
|
||||
MakeFixup(l, i->after, ReadVLI());
|
||||
MakeFixup(l, i->if_true, ReadVLI());
|
||||
MakeFixup(l, i->if_false, ReadVLI());
|
||||
MakeFixup(l, i->after, ReadVLI());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PSO_IF_ELSE:
|
||||
case PSO_IF_ENDIF: {
|
||||
SignalIf::PseudoInstruction *p = new SignalIf::PseudoInstruction(sp, op);
|
||||
@@ -262,7 +262,7 @@ static void Load_SPRG()
|
||||
MakeFixup(l, p->block, ReadVLI(), PSO_IF);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case PSO_SET_SIGNAL: {
|
||||
SignalSet *s = new SignalSet(sp);
|
||||
MakeFixup(l, s->GetPrevHandle(), ReadVLI());
|
||||
@@ -271,11 +271,11 @@ static void Load_SPRG()
|
||||
if(s->to_state > SIGNAL_STATE_MAX) NOT_REACHED();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DoFixups(l, sp->instructions);
|
||||
sp->DebugPrintProgram();
|
||||
}
|
||||
|
Reference in New Issue
Block a user