Initial implementation of NewGRF custom signal styles

This commit is contained in:
Jonathan G Rennison
2022-06-18 23:37:35 +01:00
parent 098bb74ed2
commit 6e4c4b35e7
34 changed files with 536 additions and 75 deletions

View File

@@ -12,6 +12,7 @@
#include "tunnelbridge_map.h"
#include "bridge_signal_map.h"
#include "debug.h"
#include "newgrf_newsignals.h"
#include "safeguards.h"
@@ -169,3 +170,36 @@ void ClearBridgeSimulatedSignalMapping()
{
_long_bridge_signal_sim_map.clear();
}
btree::btree_set<uint32> _bridge_signal_style_map;
static_assert(MAX_MAP_TILES_BITS + 4 <= 32);
static_assert(1 << 4 <= MAX_NEW_SIGNAL_STYLES + 1);
void SetBridgeSignalStyle(TileIndex t, uint8 style)
{
if (style == 0) {
/* No style allocated before */
if (!HasBit(_m[t].m3, 7)) return;
auto iter = _bridge_signal_style_map.lower_bound(t << 4);
if (iter != _bridge_signal_style_map.end() && *iter >> 4 == t) _bridge_signal_style_map.erase(iter);
ClrBit(_m[t].m3, 7);
} else {
auto iter = _bridge_signal_style_map.lower_bound(t << 4);
if (iter != _bridge_signal_style_map.end() && *iter >> 4 == t) iter = _bridge_signal_style_map.erase(iter);
_bridge_signal_style_map.insert(iter, (t << 4) | style);
SetBit(_m[t].m3, 7);
}
}
uint8 GetBridgeSignalStyleExtended(TileIndex t)
{
auto iter = _bridge_signal_style_map.lower_bound(t << 4);
if (iter != _bridge_signal_style_map.end() && *iter >> 4 == t) return (*iter) & 0xF;
return 0;
}
void ClearBridgeSignalStyleMapping()
{
_bridge_signal_style_map.clear();
}