From 0650568aeeb821fd2088d2641389b0823db671f4 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 15 Aug 2015 23:39:35 +0100 Subject: [PATCH 01/10] Improved breakdowns: Fix setting string being in the middle of a string range. Looking at or selecting the gui.stop_location setting triggered an assertion failure. Move the string out of the setting range. --- src/lang/english.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 5428087f95..cf08b94031 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1219,8 +1219,8 @@ STR_CONFIG_SETTING_STOP_LOCATION :New train order STR_CONFIG_SETTING_STOP_LOCATION_HELPTEXT :Place where a train will stop at the platform by default. The 'near end' means close to the entry point, 'middle' means in the middle of the platform, and 'far end' means far away from the entry point. Note, that this setting only defines a default value for new orders. Individual orders can be set explicitly to either behaviour nevertheless STR_CONFIG_SETTING_STOP_LOCATION_NEAR_END :near end STR_CONFIG_SETTING_STOP_LOCATION_MIDDLE :middle -STR_CONFIG_SETTING_IMPROVED_BREAKDOWNS :Enable improved breakdowns: {STRING2} STR_CONFIG_SETTING_STOP_LOCATION_FAR_END :far end +STR_CONFIG_SETTING_IMPROVED_BREAKDOWNS :Enable improved breakdowns: {STRING2} STR_CONFIG_SETTING_AUTOSCROLL :Pan window when mouse is at the edge: {STRING2} STR_CONFIG_SETTING_AUTOSCROLL_HELPTEXT :When enabled, viewports will start to scroll when the mouse is near the edge of the window STR_CONFIG_SETTING_AUTOSCROLL_DISABLED :Disabled From 01482ba6b4fc3af25917deb647fa855abacfd2af Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 16 Aug 2015 14:25:53 +0100 Subject: [PATCH 02/10] Fix findversion.sh using descendant instead of ancestor tags for the version string. --- findversion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/findversion.sh b/findversion.sh index 6be52b696f..639d2a0eeb 100755 --- a/findversion.sh +++ b/findversion.sh @@ -99,7 +99,7 @@ elif [ -d "$ROOT_DIR/.git" ]; then # No rev? Maybe it is a custom git-svn clone REV_NR=`LC_ALL=C git log --pretty=format:%b --grep="git-svn-id:.*@[0-9]*" -1 | sed "s@.*\@\([0-9]*\).*@\1@"` fi - TAG="`git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed 's@\^0$@@'`" + TAG="`git describe --tags 2>/dev/null`" if [ -n "$TAG" ]; then BRANCH="" REV="$TAG" From a8cc81d054ec20b6a70774597d7d1d610b8ba9b8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 16 Aug 2015 14:36:07 +0100 Subject: [PATCH 03/10] Initialiser list fixes for legacy compilers. --- src/saveload/saveload.h | 36 ++++++++++++++++----------------- src/table/company_settings.ini | 2 +- src/table/currency_settings.ini | 2 +- src/table/gameopt_settings.ini | 2 +- src/table/misc_settings.ini | 2 +- src/table/settings.ini | 2 +- src/table/win32_settings.ini | 2 +- src/table/window_settings.ini | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 711d9ac7ac..e34d4f3e9e 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -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. diff --git a/src/table/company_settings.ini b/src/table/company_settings.ini index 5c839c2af7..e49f4094fa 100644 --- a/src/table/company_settings.ini +++ b/src/table/company_settings.ini @@ -34,7 +34,7 @@ load = NULL from = 0 to = SL_MAX_VERSION cat = SC_ADVANCED -extver = {} +extver = SlXvFeatureTest() diff --git a/src/table/currency_settings.ini b/src/table/currency_settings.ini index 3c476ee5df..6a8665379a 100644 --- a/src/table/currency_settings.ini +++ b/src/table/currency_settings.ini @@ -28,7 +28,7 @@ load = NULL from = 0 to = SL_MAX_VERSION cat = SC_ADVANCED -extver = {} +extver = SlXvFeatureTest() diff --git a/src/table/gameopt_settings.ini b/src/table/gameopt_settings.ini index 9e5fa3d0ff..a5bc766ecb 100644 --- a/src/table/gameopt_settings.ini +++ b/src/table/gameopt_settings.ini @@ -62,7 +62,7 @@ load = NULL from = 0 to = SL_MAX_VERSION cat = SC_ADVANCED -extver = {} +extver = SlXvFeatureTest() diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini index 11197692c8..06bae18013 100644 --- a/src/table/misc_settings.ini +++ b/src/table/misc_settings.ini @@ -35,7 +35,7 @@ load = NULL from = 0 to = SL_MAX_VERSION cat = SC_ADVANCED -extver = {} +extver = SlXvFeatureTest() diff --git a/src/table/settings.ini b/src/table/settings.ini index 0b5e55a643..3a951f9b62 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -91,7 +91,7 @@ load = NULL from = 0 to = SL_MAX_VERSION cat = SC_ADVANCED -extver = {} +extver = SlXvFeatureTest() patxname = NULL diff --git a/src/table/win32_settings.ini b/src/table/win32_settings.ini index 6f62db63f6..a22e1a54e7 100644 --- a/src/table/win32_settings.ini +++ b/src/table/win32_settings.ini @@ -33,7 +33,7 @@ load = NULL from = 0 to = SL_MAX_VERSION cat = SC_ADVANCED -extver = {} +extver = SlXvFeatureTest() diff --git a/src/table/window_settings.ini b/src/table/window_settings.ini index 4565d9b35f..a7b1742040 100644 --- a/src/table/window_settings.ini +++ b/src/table/window_settings.ini @@ -29,7 +29,7 @@ load = NULL from = 0 to = SL_MAX_VERSION cat = SC_ADVANCED -extver = {} +extver = SlXvFeatureTest() From 0693d3678aab4122664405cf454b041548da87d9 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 16 Aug 2015 16:57:24 +0100 Subject: [PATCH 04/10] Progsig: Fix some benign compiler warnings and whitespace issues. --- src/programmable_signals_gui.cpp | 14 +++-- src/saveload/signal_sl.cpp | 100 +++++++++++++++---------------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/src/programmable_signals_gui.cpp b/src/programmable_signals_gui.cpp index ed4c0049f7..29cba83c96 100644 --- a/src/programmable_signals_gui.cpp +++ b/src/programmable_signals_gui.cpp @@ -355,6 +355,7 @@ public: { uint64 p1 = 0; while(true) { + if(si == NULL) break; switch(si->Opcode()) { case PSO_SET_SIGNAL: { SB(p1, 0, 3, this->track); @@ -365,6 +366,7 @@ public: this->RebuildInstructionList(); si = ((SignalSet*)si)->next; } break; + case PSO_IF: { SB(p1, 0, 3, this->track); SB(p1, 3, 16, next); @@ -393,11 +395,15 @@ public: si = ((SignalIf*)si)->after; } break; + + case PSO_LAST: + case PSO_IF_ELSE: + case PSO_IF_ENDIF: + return; + + default: + NOT_REACHED(); } - if(si == NULL) break; - if(si->Opcode() == PSO_LAST) break; - if(si->Opcode() == PSO_IF_ELSE) break; - if(si->Opcode() == PSO_IF_ENDIF) break; } } diff --git a/src/saveload/signal_sl.cpp b/src/saveload/signal_sl.cpp index e0198b109d..173b484f9f 100644 --- a/src/saveload/signal_sl.cpp +++ b/src/saveload/signal_sl.cpp @@ -23,30 +23,30 @@ typedef std::vector 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(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(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(insn); WriteVLI(b, p->block->Id()); break; } - + case PSO_SET_SIGNAL: { SignalSet *s = static_cast(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(*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(); } From 3e8611fca12de0444d184f51740ffd8f63dfb90f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 16 Aug 2015 17:05:49 +0100 Subject: [PATCH 05/10] House placing: Fix uninitialised variable. --- src/town_gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 68f8eab962..4ffae13bb2 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -1314,7 +1314,7 @@ public: /* list house sets */ this->house_sets.Clear(); - const GRFFile *last_set; + const GRFFile *last_set = NULL; for (uint i = 0; i < this->Length(); i++) { const HouseSpec *hs = HouseSpec::Get((*this)[i]); /* add house set */ From 20f1f48983b989a68d1ef2429ab1e0f7522b868a Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 16 Aug 2015 17:31:34 +0100 Subject: [PATCH 06/10] Fix add/removing signals on bridges/tunnels not checking train occupancy. Fix compiler warning. --- src/rail_cmd.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index d1255fc827..c8f0adaa27 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1016,7 +1016,9 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return CMD_ERROR; CommandCost ret = EnsureNoTrainOnTrack(GetOtherTunnelBridgeEnd(tile), track); - //if (ret.Failed()) return ret; + if (ret.Failed()) return ret; + ret = EnsureNoTrainOnTrack(tile, track); + if (ret.Failed()) return ret; } else if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) { return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK); } @@ -1483,6 +1485,8 @@ CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1 CommandCost ret = EnsureNoTrainOnTrack(GetOtherTunnelBridgeEnd(tile), track); if (ret.Failed()) return ret; + ret = EnsureNoTrainOnTrack(tile, track); + if (ret.Failed()) return ret; } else { if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) { return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK); From 01c938e1e9826d0c17ee81d5b57a832bc469e330 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 16 Aug 2015 22:01:40 +0100 Subject: [PATCH 07/10] Include GRFs in bundle output. --- Makefile.bundle.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile.bundle.in b/Makefile.bundle.in index 63edb62d97..a04a0a31e7 100644 --- a/Makefile.bundle.in +++ b/Makefile.bundle.in @@ -45,6 +45,7 @@ bundle: all $(Q)mkdir -p "$(BUNDLE_DIR)/docs" $(Q)mkdir -p "$(BUNDLE_DIR)/media" $(Q)mkdir -p "$(BUNDLE_DIR)/scripts" + $(Q)mkdir -p "$(BUNDLE_DIR)/data" $(Q)mkdir -p "$(TTD_DIR)" $(Q)mkdir -p "$(AI_DIR)" $(Q)mkdir -p "$(GAME_DIR)" @@ -82,6 +83,7 @@ endif $(Q)cp "$(ROOT_DIR)/media/openttd.32.xpm" "$(BUNDLE_DIR)/media/" $(Q)cp "$(ROOT_DIR)/media/openttd."*.png "$(BUNDLE_DIR)/media/" $(Q)cp "$(BIN_DIR)/scripts/"* "$(BUNDLE_DIR)/scripts/" + $(Q)cp "$(BIN_DIR)/data/"*.grf "$(BUNDLE_DIR)/data/" ifdef MENU_DIR $(Q)cp "$(ROOT_DIR)/media/openttd.desktop" "$(BUNDLE_DIR)/media/" $(Q)$(AWK) -f "$(ROOT_DIR)/media/openttd.desktop.translation.awk" "$(SRC_DIR)/lang/"*.txt | $(SORT) | $(AWK) -f "$(ROOT_DIR)/media/openttd.desktop.filter.awk" >> "$(BUNDLE_DIR)/media/openttd.desktop" From 614b3d8ab55f3e3b92c367f82f9d8502951c6e16 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 19 Aug 2015 18:52:49 +0100 Subject: [PATCH 08/10] Trace restrict: Handle removing mapping from refcount 2 empty program. Instead of leaving the other mapping pointing to an empty unshared program, find and delete it. --- src/tracerestrict.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 5b9ee86c3a..968a22c8ea 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -49,11 +49,10 @@ * This is not done for shared programs as this would delete the shared aspect whenever * the program became empty. * - * Empty programs with a refcount of 1 may still exist due to the edge case where: - * 1: There is an empty program with refcount 2 - * 2: One of the two mappings is deleted - * Finding the other mapping would entail a linear search of the mappings, and there is little - * to be gained by doing so. + * Special case: In the case where an empty program with refcount 2 has one of its + * mappings removed, the other mapping is left pointing to an empty unshared program. + * This other mapping is then removed by performing a linear search of the mappings, + * and removing the reference to that program ID. */ TraceRestrictProgramPool _tracerestrictprogram_pool("TraceRestrictProgram"); @@ -604,7 +603,13 @@ void TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref) TraceRestrictMapping::iterator iter = _tracerestrictprogram_mapping.find(ref); if (iter != _tracerestrictprogram_mapping.end()) { // Found - _tracerestrictprogram_pool.Get(iter->second.program_id)->DecrementRefCount(); + TraceRestrictProgram *prog = _tracerestrictprogram_pool.Get(iter->second.program_id); + + // check to see if another mapping needs to be removed as well + // do this before decrementing the refcount + bool remove_other_mapping = prog->refcount == 2 && prog->items.empty(); + + prog->DecrementRefCount(); _tracerestrictprogram_mapping.erase(iter); TileIndex tile = GetTraceRestrictRefIdTileIndex(ref); @@ -612,6 +617,17 @@ void TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref) SetIsSignalRestrictedBit(tile); MarkTileDirtyByTile(tile); YapfNotifyTrackLayoutChange(tile, track); + + if (remove_other_mapping) { + TraceRestrictProgramID id = prog->index; + for (TraceRestrictMapping::iterator rm_iter = _tracerestrictprogram_mapping.begin(); + rm_iter != _tracerestrictprogram_mapping.end(); ++rm_iter) { + if (rm_iter->second.program_id == id) { + TraceRestrictRemoveProgramMapping(rm_iter->first); + break; + } + } + } } } From 8faead7e7a1f407c34b5ee3e83ba7ffd1209755b Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 19 Aug 2015 21:56:22 +0100 Subject: [PATCH 09/10] Graphically indicate restricted signals by recolouring the signal post. Recolour signal posts from grey to blue for restricted signals which are not semaphores and are not custom sprites. --- bin/data/tracerestrict.grf | Bin 0 -> 526 bytes src/gfxinit.cpp | 3 +++ src/rail_cmd.cpp | 15 ++++++++++++++- src/table/sprites.h | 6 +++++- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 bin/data/tracerestrict.grf diff --git a/bin/data/tracerestrict.grf b/bin/data/tracerestrict.grf new file mode 100644 index 0000000000000000000000000000000000000000..b71ee80c1713778d8886e3aeca4568644b075d93 GIT binary patch literal 526 zcmZQ%{LjF^$i&RT%Er#Y$;HjX%f~MuC?qT*Dkd%=DJ3l ztEX>ZXk=_+YG!U>X=QC=YiIA^=;Z9;>gMj@>E-R?>*pU37!({58WtWA85JE98yBCD zn3SB7nwFlCnU$TBo0nfuSX5k6T2@|BSyf$ATUXyOY4Vh*)26p~bar+3^!D{nm}`JIdkXDU$Ah|;w4L$Enl&6)#^2C*R9{Mant54TeofBv2)k%J$v`DsiM$a%fg9rl# GFaQ8SISHfy literal 0 HcmV?d00001 diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 10bc0afa17..440cf5bb1a 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -170,6 +170,9 @@ static void LoadSpriteTables() _palette_remap_grf[i] = (PAL_DOS != used_set->palette); LoadGrfFile(used_set->files[GFT_BASE].filename, 0, i++); + /* Tracerestrict sprites. */ + LoadGrfFile("tracerestrict.grf", SPR_TRACERESTRICT_BASE, i++); + /* * The second basic file always starts at the given location and does * contain a different amount of sprites depending on the "type"; DOS diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index e1b956bad9..3b706c69ea 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1862,6 +1862,7 @@ static void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track trac SignalVariant variant = GetSignalVariant(tile, track); SpriteID sprite = GetCustomSignalSprite(rti, tile, type, variant, condition); + bool is_custom_sprite = (sprite != 0); if (sprite != 0) { sprite += image; } else { @@ -1870,7 +1871,19 @@ static void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track trac sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0); } - AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSaveSlopeZ(x, y, track)); + if (!is_custom_sprite && variant == SIG_ELECTRIC && IsRestrictedSignal(tile) && GetExistingTraceRestrictProgram(tile, track) != NULL) { + if (type == SIGTYPE_PBS || type == SIGTYPE_PBS_ONEWAY) { + static const SubSprite lower_part { -50, -10, 50, 50 }; + static const SubSprite upper_part { -50, -50, 50, -11 }; + + AddSortableSpriteToDraw(sprite, SPR_TRACERESTRICT_BASE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSaveSlopeZ(x, y, track), false, 0, 0, 0, &lower_part); + AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSaveSlopeZ(x, y, track), false, 0, 0, 0, &upper_part); + } else { + AddSortableSpriteToDraw(sprite, SPR_TRACERESTRICT_BASE + 1, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSaveSlopeZ(x, y, track)); + } + } else { + AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSaveSlopeZ(x, y, track)); + } } static uint32 _drawtile_track_palette; diff --git a/src/table/sprites.h b/src/table/sprites.h index 81d5388f99..3bd7fdffeb 100644 --- a/src/table/sprites.h +++ b/src/table/sprites.h @@ -296,8 +296,12 @@ static const uint16 EMPTY_BOUNDING_BOX_SPRITE_COUNT = 1; static const SpriteID SPR_PALETTE_BASE = SPR_EMPTY_BOUNDING_BOX + EMPTY_BOUNDING_BOX_SPRITE_COUNT; static const uint16 PALETTE_SPRITE_COUNT = 1; +/* Tracerestrict sprites */ +static const SpriteID SPR_TRACERESTRICT_BASE = SPR_PALETTE_BASE + PALETTE_SPRITE_COUNT; +static const uint16 TRACERESTRICT_SPRITE_COUNT = 2; + /* From where can we start putting NewGRFs? */ -static const SpriteID SPR_NEWGRFS_BASE = SPR_PALETTE_BASE + PALETTE_SPRITE_COUNT; +static const SpriteID SPR_NEWGRFS_BASE = SPR_TRACERESTRICT_BASE + TRACERESTRICT_SPRITE_COUNT; /* Manager face sprites */ static const SpriteID SPR_GRADIENT = 874; // background gradient behind manager face From 46817994bfd4f7f6f184d42604fb89ce2b2290a8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 16 Aug 2015 22:01:40 +0100 Subject: [PATCH 10/10] Include GRFs in bundle output. --- Makefile.bundle.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile.bundle.in b/Makefile.bundle.in index 63edb62d97..a04a0a31e7 100644 --- a/Makefile.bundle.in +++ b/Makefile.bundle.in @@ -45,6 +45,7 @@ bundle: all $(Q)mkdir -p "$(BUNDLE_DIR)/docs" $(Q)mkdir -p "$(BUNDLE_DIR)/media" $(Q)mkdir -p "$(BUNDLE_DIR)/scripts" + $(Q)mkdir -p "$(BUNDLE_DIR)/data" $(Q)mkdir -p "$(TTD_DIR)" $(Q)mkdir -p "$(AI_DIR)" $(Q)mkdir -p "$(GAME_DIR)" @@ -82,6 +83,7 @@ endif $(Q)cp "$(ROOT_DIR)/media/openttd.32.xpm" "$(BUNDLE_DIR)/media/" $(Q)cp "$(ROOT_DIR)/media/openttd."*.png "$(BUNDLE_DIR)/media/" $(Q)cp "$(BIN_DIR)/scripts/"* "$(BUNDLE_DIR)/scripts/" + $(Q)cp "$(BIN_DIR)/data/"*.grf "$(BUNDLE_DIR)/data/" ifdef MENU_DIR $(Q)cp "$(ROOT_DIR)/media/openttd.desktop" "$(BUNDLE_DIR)/media/" $(Q)$(AWK) -f "$(ROOT_DIR)/media/openttd.desktop.translation.awk" "$(SRC_DIR)/lang/"*.txt | $(SORT) | $(AWK) -f "$(ROOT_DIR)/media/openttd.desktop.filter.awk" >> "$(BUNDLE_DIR)/media/openttd.desktop"