mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Progsig: Fix various formatting issues
This commit is contained in:
parent
a52db2113c
commit
c47b401402
@ -196,7 +196,7 @@ void SignalSlotCondition::SetSlot(TraceRestrictSlotID slot_id)
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ bool SignalSlotCondition::Evaluate(SignalVM& vm)
|
||||
/*virtual*/ bool SignalSlotCondition::Evaluate(SignalVM &vm)
|
||||
{
|
||||
if (!this->CheckSlotValid()) {
|
||||
DEBUG(misc, 1, "Signal (%x, %d) has an invalid condition", this->this_sig.tile, this->this_sig.track);
|
||||
@ -260,7 +260,7 @@ void SignalCounterCondition::SetCounter(TraceRestrictCounterID ctr_id)
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ bool SignalCounterCondition::Evaluate(SignalVM& vm)
|
||||
/*virtual*/ bool SignalCounterCondition::Evaluate(SignalVM &vm)
|
||||
{
|
||||
if (!this->CheckCounterValid()) {
|
||||
DEBUG(misc, 1, "Signal (%x, %d) has an invalid condition", this->this_sig.tile, this->this_sig.track);
|
||||
@ -275,9 +275,9 @@ SignalStateCondition::SignalStateCondition(SignalReference this_sig,
|
||||
: SignalCondition(PSC_SIGNAL_STATE), this_sig(this_sig), sig_tile(sig_tile)
|
||||
, sig_track(sig_track)
|
||||
{
|
||||
if (this->CheckSignalValid())
|
||||
AddSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)),
|
||||
this->this_sig);
|
||||
if (this->CheckSignalValid()) {
|
||||
AddSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)), this->this_sig);
|
||||
}
|
||||
}
|
||||
|
||||
bool SignalStateCondition::IsSignalValid() const
|
||||
@ -299,17 +299,16 @@ void SignalStateCondition::Invalidate()
|
||||
this->sig_tile = INVALID_TILE;
|
||||
}
|
||||
|
||||
|
||||
void SignalStateCondition::SetSignal(TileIndex tile, Trackdir track)
|
||||
{
|
||||
if (this->IsSignalValid())
|
||||
RemoveSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)),
|
||||
this->this_sig);
|
||||
if (this->IsSignalValid()) {
|
||||
RemoveSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)), this->this_sig);
|
||||
}
|
||||
this->sig_tile = tile;
|
||||
this->sig_track = track;
|
||||
if (this->CheckSignalValid())
|
||||
AddSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)),
|
||||
this->this_sig);
|
||||
if (this->CheckSignalValid()) {
|
||||
AddSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)), this->this_sig);
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ SignalStateCondition::~SignalStateCondition()
|
||||
@ -317,12 +316,11 @@ void SignalStateCondition::SetSignal(TileIndex tile, Trackdir track)
|
||||
if (_cleaning_signal_programs) return;
|
||||
|
||||
if (this->IsSignalValid()) {
|
||||
RemoveSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)),
|
||||
this->this_sig);
|
||||
RemoveSignalDependency(SignalReference(this->sig_tile, TrackdirToTrack(sig_track)), this->this_sig);
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ bool SignalStateCondition::Evaluate(SignalVM& vm)
|
||||
/*virtual*/ bool SignalStateCondition::Evaluate(SignalVM &vm)
|
||||
{
|
||||
if (!this->CheckSignalValid()) {
|
||||
DEBUG(misc, 1, "Signal (%x, %d) has an invalid condition", this->this_sig.tile, this->this_sig.track);
|
||||
@ -366,7 +364,9 @@ SignalSpecial::SignalSpecial(SignalProgram *prog, SignalOpcode op)
|
||||
if (opcode == PSO_FIRST) {
|
||||
while (this->next->Opcode() != PSO_LAST) this->next->Remove();
|
||||
} else if (opcode == PSO_LAST) {
|
||||
} else NOT_REACHED();
|
||||
} else {
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ void SignalSpecial::link(SignalSpecial *first, SignalSpecial *last)
|
||||
@ -403,7 +403,9 @@ SignalIf::PseudoInstruction::PseudoInstruction(SignalProgram *prog, SignalIf *bl
|
||||
previous = block;
|
||||
} else if (op == PSO_IF_ENDIF) {
|
||||
previous = block->if_true;
|
||||
} else NOT_REACHED();
|
||||
} else {
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ void SignalIf::PseudoInstruction::Remove()
|
||||
@ -413,7 +415,9 @@ SignalIf::PseudoInstruction::PseudoInstruction(SignalProgram *prog, SignalIf *bl
|
||||
while(this->block->if_false) this->block->if_false->Remove();
|
||||
} else if (opcode == PSO_IF_ENDIF) {
|
||||
this->block->if_false = nullptr;
|
||||
} else NOT_REACHED();
|
||||
} else {
|
||||
NOT_REACHED();
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
@ -429,7 +433,9 @@ SignalIf::PseudoInstruction::PseudoInstruction(SignalProgram *prog, SignalIf *bl
|
||||
this->block->if_false = next_insn;
|
||||
} else if (this->opcode == PSO_IF_ENDIF) {
|
||||
this->block->after = next_insn;
|
||||
} else NOT_REACHED();
|
||||
} else {
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
SignalIf::SignalIf(SignalProgram *prog, bool raw)
|
||||
@ -561,7 +567,7 @@ void FreeSignalPrograms()
|
||||
SignalState RunSignalProgram(SignalReference ref, uint num_exits, uint num_green)
|
||||
{
|
||||
SignalProgram *program = GetExistingSignalProgram(ref);
|
||||
if (!program) return SIGNAL_STATE_RED;
|
||||
if (program == nullptr) return SIGNAL_STATE_RED;
|
||||
SignalVM vm;
|
||||
vm.program = program;
|
||||
vm.num_exits = num_exits;
|
||||
@ -579,10 +585,10 @@ SignalState RunSignalProgram(SignalReference ref, uint num_exits, uint num_green
|
||||
void RemoveProgramDependencies(SignalReference dependency_target, SignalReference signal_to_update)
|
||||
{
|
||||
SignalProgram *prog = GetExistingSignalProgram(signal_to_update);
|
||||
if (!prog) return;
|
||||
if (prog == nullptr) return;
|
||||
for (SignalInstruction *insn : prog->instructions) {
|
||||
if (insn->Opcode() == PSO_IF) {
|
||||
SignalIf* ifi = static_cast<SignalIf*>(insn);
|
||||
SignalIf *ifi = static_cast<SignalIf *>(insn);
|
||||
if (ifi->condition->ConditionCode() == PSC_SIGNAL_STATE) {
|
||||
SignalStateCondition* c = static_cast<SignalStateCondition*>(ifi->condition);
|
||||
if (c->sig_tile == dependency_target.tile && TrackdirToTrack(c->sig_track) == dependency_target.track) {
|
||||
@ -600,12 +606,12 @@ void RemoveProgramDependencies(SignalReference dependency_target, SignalReferenc
|
||||
void RemoveProgramSlotDependencies(TraceRestrictSlotID slot_being_removed, SignalReference signal_to_update)
|
||||
{
|
||||
SignalProgram *prog = GetExistingSignalProgram(signal_to_update);
|
||||
if (!prog) return;
|
||||
if (prog == nullptr) return;
|
||||
for (SignalInstruction *insn : prog->instructions) {
|
||||
if (insn->Opcode() == PSO_IF) {
|
||||
SignalIf* ifi = static_cast<SignalIf*>(insn);
|
||||
SignalIf *ifi = static_cast<SignalIf *>(insn);
|
||||
if (ifi->condition->ConditionCode() == PSC_SLOT_OCC || ifi->condition->ConditionCode() == PSC_SLOT_OCC_REM) {
|
||||
SignalSlotCondition* c = static_cast<SignalSlotCondition*>(ifi->condition);
|
||||
SignalSlotCondition *c = static_cast<SignalSlotCondition *>(ifi->condition);
|
||||
if (c->slot_id == slot_being_removed) {
|
||||
c->Invalidate();
|
||||
}
|
||||
@ -621,12 +627,12 @@ void RemoveProgramSlotDependencies(TraceRestrictSlotID slot_being_removed, Signa
|
||||
void RemoveProgramCounterDependencies(TraceRestrictCounterID ctr_being_removed, SignalReference signal_to_update)
|
||||
{
|
||||
SignalProgram *prog = GetExistingSignalProgram(signal_to_update);
|
||||
if (!prog) return;
|
||||
if (prog == nullptr) return;
|
||||
for (SignalInstruction *insn : prog->instructions) {
|
||||
if (insn->Opcode() == PSO_IF) {
|
||||
SignalIf* ifi = static_cast<SignalIf*>(insn);
|
||||
SignalIf *ifi = static_cast<SignalIf *>(insn);
|
||||
if (ifi->condition->ConditionCode() == PSC_COUNTER) {
|
||||
SignalCounterCondition* c = static_cast<SignalCounterCondition*>(ifi->condition);
|
||||
SignalCounterCondition *c = static_cast<SignalCounterCondition *>(ifi->condition);
|
||||
if (c->ctr_id == ctr_being_removed) {
|
||||
c->Invalidate();
|
||||
}
|
||||
@ -772,21 +778,22 @@ CommandCost CmdModifySignalInstruction(TileIndex tile, DoCommandFlag flags, uint
|
||||
switch (insn->Opcode()) {
|
||||
case PSO_SET_SIGNAL: {
|
||||
SignalState state = (SignalState) p2;
|
||||
if (state > SIGNAL_STATE_MAX)
|
||||
if (state > SIGNAL_STATE_MAX) {
|
||||
return_cmd_error(STR_ERR_PROGSIG_INVALID_SIGNAL_STATE);
|
||||
if (!exec)
|
||||
return CommandCost();
|
||||
}
|
||||
if (!exec) return CommandCost();
|
||||
SignalSet *ss = static_cast<SignalSet*>(insn);
|
||||
ss->to_state = state;
|
||||
} break;
|
||||
|
||||
case PSO_IF: {
|
||||
SignalIf *si = static_cast<SignalIf*>(insn);
|
||||
SignalIf *si = static_cast<SignalIf *>(insn);
|
||||
uint8_t act = GB(p2, 0, 1);
|
||||
if (act == 0) { // Set code
|
||||
SignalConditionCode code = (SignalConditionCode) GB(p2, 1, 8);
|
||||
if (code > PSC_MAX)
|
||||
if (code > PSC_MAX) {
|
||||
return_cmd_error(STR_ERR_PROGSIG_INVALID_CONDITION);
|
||||
}
|
||||
if (!exec) return CommandCost();
|
||||
|
||||
SignalCondition *cond;
|
||||
@ -846,8 +853,9 @@ CommandCost CmdModifySignalInstruction(TileIndex tile, DoCommandFlag flags, uint
|
||||
TileIndex ti = (TileIndex) GB(p2, 5, 27);
|
||||
|
||||
if (!IsValidTile(ti) || !IsValidTrackdir(td) || !HasSignalOnTrackdir(ti, td)
|
||||
|| GetTileOwner(ti) != _current_company)
|
||||
|| GetTileOwner(ti) != _current_company) {
|
||||
return_cmd_error(STR_ERR_PROGSIG_INVALID_SIGNAL);
|
||||
}
|
||||
if (!exec) return CommandCost();
|
||||
sc->SetSignal(ti, td);
|
||||
} break;
|
||||
@ -874,7 +882,7 @@ CommandCost CmdModifySignalInstruction(TileIndex tile, DoCommandFlag flags, uint
|
||||
} break;
|
||||
|
||||
case PSC_COUNTER: {
|
||||
SignalCounterCondition *sc = static_cast<SignalCounterCondition*>(si->condition);
|
||||
SignalCounterCondition *sc = static_cast<SignalCounterCondition *>(si->condition);
|
||||
SignalConditionField f = (SignalConditionField) GB(p2, 1, 2);
|
||||
uint32_t val = GB(p2, 3, 27);
|
||||
if (f == SCF_COMPARATOR) {
|
||||
@ -965,14 +973,13 @@ CommandCost CmdRemoveSignalInstruction(TileIndex tile, DoCommandFlag flags, uint
|
||||
|
||||
static void CloneInstructions(SignalProgram *prog, SignalInstruction *insert_before, SignalInstruction *si)
|
||||
{
|
||||
while(true) {
|
||||
if(si == nullptr) break;
|
||||
switch(si->Opcode()) {
|
||||
while (si != nullptr) {
|
||||
switch (si->Opcode()) {
|
||||
case PSO_SET_SIGNAL: {
|
||||
SignalSet *set = new SignalSet(prog, ((SignalSet*)si)->to_state);
|
||||
SignalSet *set = new SignalSet(prog, ((SignalSet *)si)->to_state);
|
||||
set->Insert(insert_before);
|
||||
|
||||
si = ((SignalSet*)si)->next;
|
||||
si = ((SignalSet *)si)->next;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -980,8 +987,8 @@ static void CloneInstructions(SignalProgram *prog, SignalInstruction *insert_bef
|
||||
SignalIf *if_ins = new SignalIf(prog);
|
||||
if_ins->Insert(insert_before);
|
||||
|
||||
CloneInstructions(prog, if_ins->if_true, ((SignalIf*)si)->if_true);
|
||||
CloneInstructions(prog, if_ins->if_false, ((SignalIf*)si)->if_false);
|
||||
CloneInstructions(prog, if_ins->if_true, ((SignalIf *)si)->if_true);
|
||||
CloneInstructions(prog, if_ins->if_false, ((SignalIf *)si)->if_false);
|
||||
|
||||
SignalCondition *src_cond = ((SignalIf *) si)->condition;
|
||||
SignalConditionCode code = src_cond->ConditionCode();
|
||||
@ -1028,7 +1035,7 @@ static void CloneInstructions(SignalProgram *prog, SignalInstruction *insert_bef
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
si = ((SignalIf*)si)->after;
|
||||
si = ((SignalIf *)si)->after;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1092,7 +1099,7 @@ CommandCost CmdSignalProgramMgmt(TileIndex tile, DoCommandFlag flags, uint32_t p
|
||||
|
||||
if (exec) {
|
||||
prog->first_instruction->Remove();
|
||||
CloneInstructions(prog, prog->last_instruction, ((SignalSpecial*) src_prog->first_instruction)->next);
|
||||
CloneInstructions(prog, prog->last_instruction, ((SignalSpecial *) src_prog->first_instruction)->next);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -77,9 +77,7 @@ public:
|
||||
inline SignalInstruction *Previous() const { return this->previous; }
|
||||
|
||||
/// Get the Id of this instruction
|
||||
inline int Id() const
|
||||
// Const cast is safe (perculiarity of SmallVector)
|
||||
{ return find_index(program->instructions, const_cast<SignalInstruction*>(this)); }
|
||||
inline int Id() const { return find_index(program->instructions, const_cast<SignalInstruction *>(this)); }
|
||||
|
||||
/// Insert this instruction, placing it before @p before_insn
|
||||
virtual void Insert(SignalInstruction *before_insn);
|
||||
@ -97,13 +95,12 @@ public:
|
||||
|
||||
/// Gets a reference to the previous member. This is only intended for use by
|
||||
/// the saveload code.
|
||||
inline SignalInstruction *&GetPrevHandle()
|
||||
{ return previous; }
|
||||
inline SignalInstruction *&GetPrevHandle() { return previous; }
|
||||
|
||||
/// Sets the previous instruction of this instruction. This is only intended
|
||||
/// to be used by instructions to update links during insertion and removal.
|
||||
inline void SetPrevious(SignalInstruction *prev)
|
||||
{ previous = prev; }
|
||||
inline void SetPrevious(SignalInstruction *prev) { previous = prev; }
|
||||
|
||||
/// Set the next instruction. This is only intended to be used by instructions
|
||||
/// to update links during insertion and removal
|
||||
virtual void SetNext(SignalInstruction *next_insn) = 0;
|
||||
@ -112,7 +109,7 @@ protected:
|
||||
/// Constructs an instruction
|
||||
/// @param prog the program to add this instruction to
|
||||
/// @param op the opcode of the instruction
|
||||
SignalInstruction(SignalProgram *prog, SignalOpcode op) ;
|
||||
SignalInstruction(SignalProgram *prog, SignalOpcode op);
|
||||
virtual ~SignalInstruction();
|
||||
|
||||
const SignalOpcode opcode;
|
||||
@ -144,7 +141,7 @@ public:
|
||||
inline SignalConditionCode ConditionCode() const { return this->cond_code; }
|
||||
|
||||
/// Evaluate the condition
|
||||
virtual bool Evaluate(SignalVM& vm) = 0;
|
||||
virtual bool Evaluate(SignalVM &vm) = 0;
|
||||
|
||||
/// Destroy the condition. Any children should also be destroyed
|
||||
virtual ~SignalCondition();
|
||||
@ -162,7 +159,7 @@ protected:
|
||||
class SignalSimpleCondition: public SignalCondition {
|
||||
public:
|
||||
SignalSimpleCondition(SignalConditionCode code);
|
||||
bool Evaluate(SignalVM& vm) override;
|
||||
bool Evaluate(SignalVM &vm) override;
|
||||
};
|
||||
|
||||
/** Comparator to use for variable conditions. */
|
||||
@ -222,7 +219,7 @@ class SignalStateCondition: public SignalCondition {
|
||||
bool CheckSignalValid();
|
||||
void Invalidate();
|
||||
|
||||
bool Evaluate(SignalVM& vm) override;
|
||||
bool Evaluate(SignalVM &vm) override;
|
||||
virtual ~SignalStateCondition();
|
||||
|
||||
SignalReference this_sig;
|
||||
@ -240,7 +237,7 @@ class SignalSlotCondition: public SignalConditionComparable {
|
||||
bool CheckSlotValid();
|
||||
void Invalidate();
|
||||
|
||||
bool Evaluate(SignalVM& vm) override;
|
||||
bool Evaluate(SignalVM &vm) override;
|
||||
virtual ~SignalSlotCondition();
|
||||
|
||||
SignalReference this_sig;
|
||||
@ -257,7 +254,7 @@ class SignalCounterCondition: public SignalConditionComparable {
|
||||
bool CheckCounterValid();
|
||||
void Invalidate();
|
||||
|
||||
bool Evaluate(SignalVM& vm) override;
|
||||
bool Evaluate(SignalVM &vm) override;
|
||||
virtual ~SignalCounterCondition();
|
||||
|
||||
SignalReference this_sig;
|
||||
@ -416,7 +413,7 @@ extern ProgramList _signal_programs;
|
||||
inline bool HasProgrammableSignals(SignalReference ref)
|
||||
{
|
||||
return IsTileType(ref.tile, MP_RAILWAY) && GetRailTileType(ref.tile) == RAIL_TILE_SIGNALS
|
||||
&& IsPresignalProgrammable(ref.tile, ref.track);
|
||||
&& IsPresignalProgrammable(ref.tile, ref.track);
|
||||
}
|
||||
|
||||
/// Shows the programming window for the signal identified by @p tile and
|
||||
|
Loading…
Reference in New Issue
Block a user