From cc25edf9f1ff64e57d04c26b1cef2c72b979b3f3 Mon Sep 17 00:00:00 2001 From: cirdan Date: Sat, 22 Feb 2014 14:37:45 +0100 Subject: [PATCH] Rework handling of ignored pylons Rework handling of ignored pylons by keeping IgnoredPCP in a much more compact way that does not store redundant information. --- src/elrail.cpp | 14 ++++++- src/table/elrail_data.h | 104 ++++++++++++------------------------------------ 2 files changed, 37 insertions(+), 81 deletions(-) diff --git a/src/elrail.cpp b/src/elrail.cpp index 1739761fa..24f3fd636 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -312,7 +312,10 @@ static void DrawCatenaryRailway(const TileInfo *ti) /* Note that ti->tileh has already been adjusted for Foundations */ home.tileh = ti->tileh; - TLG tlg = (TLG)((IsOddX(ti->tile) << 1) + IsOddY(ti->tile)); + bool odd[AXIS_END]; + odd[AXIS_X] = IsOddX(ti->tile); + odd[AXIS_Y] = IsOddY(ti->tile); + TLG tlg = (TLG)((odd[AXIS_X] << 1) + odd[AXIS_Y]); byte PCPstatus = 0; DiagDirection overridePCP = INVALID_DIAGDIR; @@ -468,8 +471,15 @@ static void DrawCatenaryRailway(const TileInfo *ti) * Delete the PCP if this is the case. * Level means that the slope is the same, or the track is flat */ if (home.tileh == nbconfig.tileh || (home.isflat && nbconfig.isflat)) { + Axis axis = DiagDirToAxis(i); for (uint k = 0; k < NUM_IGNORE_GROUPS; k++) { - if (PPPpreferred == IgnoredPCP[tlg][i][k]) ClrBit(PCPstatus, i); + if (PPPpreferred == IgnoredPCPconfigs[axis][k] ) { + /* This configuration may be subject to pylon elision. */ + bool ignore = HasBit (IgnoredPCP[axis][odd[OtherAxis(axis)]], k); + /* Toggle ignore if we are in an odd row, or heading the other way. */ + if (ignore ^ odd[axis] ^ HasBit(i, 1)) ClrBit(PCPstatus, i); + break; + } } if (!HasBit(PCPstatus, i)) continue; } diff --git a/src/table/elrail_data.h b/src/table/elrail_data.h index 190051103..0df584f37 100644 --- a/src/table/elrail_data.h +++ b/src/table/elrail_data.h @@ -111,92 +111,38 @@ static const byte PreferredPPPofTrackAtPCP[TRACK_END][DIAGDIR_END] = { #define NUM_IGNORE_GROUPS 3 -#define IGNORE_NONE 0xFF + /** * In case we have a straight line, we place pylon only every two tiles, * so there are certain tiles which we ignore. A straight line is found if * we have exactly two PPPs. */ -static const byte IgnoredPCP[TLG_END][DIAGDIR_END][NUM_IGNORE_GROUPS] = { - { // X even, Y even - { // DIAGDIR_NE - IGNORE_NONE, // Ignore group 1, X and Y tracks - 1 << DIR_E | 1 << DIR_W, // Ignore group 2, LEFT and RIGHT tracks - 1 << DIR_N | 1 << DIR_S, // Ignore group 3, UPPER and LOWER tracks - }, { // DIAGDIR_SE - 1 << DIR_NE | 1 << DIR_SW, - IGNORE_NONE, - 1 << DIR_N | 1 << DIR_S, - }, { // DIAGDIR_SW - 1 << DIR_NW | 1 << DIR_SE, - IGNORE_NONE, - IGNORE_NONE, - }, { // DIAGDIR_NW - IGNORE_NONE, - 1 << DIR_E | 1 << DIR_W, - IGNORE_NONE, - } - }, - { // X even, Y odd - { // DIAGDIR_NE - IGNORE_NONE, - IGNORE_NONE, - IGNORE_NONE, - }, { // DIAGDIR_SE - IGNORE_NONE, - 1 << DIR_E | 1 << DIR_W, - IGNORE_NONE, - }, { // DIAGDIR_SW - 1 << DIR_NW | 1 << DIR_SE, - 1 << DIR_E | 1 << DIR_W, - 1 << DIR_N | 1 << DIR_S, - }, { // DIAGDIR_NW - 1 << DIR_NE | 1 << DIR_SW, - IGNORE_NONE, - 1 << DIR_N | 1 << DIR_S, - } - }, - { // X odd, Y even - { // DIAGDIR_NE - 1 << DIR_NW | 1 << DIR_SE, - IGNORE_NONE, - IGNORE_NONE, - }, { // DIAGDIR_SE - 1 << DIR_NE | 1 << DIR_SW, - 1 << DIR_E | 1 << DIR_W, - IGNORE_NONE, - }, { // DIAGDIR_SW - IGNORE_NONE, - 1 << DIR_E | 1 << DIR_W, - 1 << DIR_N | 1 << DIR_S, - }, { // DIAGDIR_NW - IGNORE_NONE, - IGNORE_NONE, - 1 << DIR_N | 1 << DIR_S, - } - }, - { // X odd, Y odd - { // DIAGDIR_NE - 1 << DIR_NW | 1 << DIR_SE, - 1 << DIR_E | 1 << DIR_W, - 1 << DIR_N | 1 << DIR_S, - }, { // DIAGDIR_SE - IGNORE_NONE, - IGNORE_NONE, - 1 << DIR_N | 1 << DIR_S, - }, { // DIAGDIR_SW - IGNORE_NONE, - IGNORE_NONE, - IGNORE_NONE, - }, { // DIAGDIR_NW - 1 << DIR_NE | 1 << DIR_SW, - 1 << DIR_E | 1 << DIR_W, - IGNORE_NONE, - } - }, +static const byte IgnoredPCPconfigs[AXIS_END][NUM_IGNORE_GROUPS] = { + { // X axis + 1 << DIR_NW | 1 << DIR_SE, + 1 << DIR_E | 1 << DIR_W, + 1 << DIR_N | 1 << DIR_S, + }, { // Y axis + 1 << DIR_NE | 1 << DIR_SW, + 1 << DIR_E | 1 << DIR_W, + 1 << DIR_N | 1 << DIR_S, + } }; -#undef NO_IGNORE +/** + * In case we have a straight line, we place pylon only every two tiles, + * so there are certain tiles which we ignore. This struct encodes on + * which tile sides pylons are omitted. + */ +static const byte IgnoredPCP[AXIS_END][2] = { + { // X axis + 0x6, // configurations to ignore on even X and even Y tile sides + 0, // configurations to ignore on even X and odd Y tile sides + }, { // Y axis + 0x5, // configurations to ignore on odd Y and even X tile sides + 0x3, // configurations to ignore on odd Y and odd X tile sides + } +}; /** Which pylons can definitely NOT be built */ static const byte AllowedPPPofTrackAtPCP[TRACK_END] = { -- 2.11.4.GIT