MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / setSignalState

Function setSignalState

src/OpenLoco/src/Vehicles/Routing.cpp:310–421  ·  view source on GitHub ↗

0x0048963F

Source from the content-addressed store, hash-verified

308
309 // 0x0048963F
310 void setSignalState(const World::Pos3& loc, const TrackAndDirection::_TrackAndDirection trackAndDirection, const uint8_t trackType, uint32_t flags)
311 {
312 const auto unk1 = flags & 0xFFFF;
313 assert(unk1 != 10); // Only happens if wrong function was called call getSignalState
314 auto trackStart = loc;
315 if (trackAndDirection.isReversed())
316 {
317 auto& trackSize = World::TrackData::getUnkTrack(trackAndDirection._data);
318 trackStart += trackSize.pos;
319 if (trackSize.rotationEnd < 12)
320 {
321 trackStart -= World::Pos3{ World::kRotationOffset[trackSize.rotationEnd], 0 };
322 }
323 flags ^= (1ULL << 31);
324 }
325
326 auto& trackPieces = World::TrackData::getTrackPiece(trackAndDirection.id());
327 for (auto& trackPiece : trackPieces)
328 {
329 auto signalLoc = trackStart + World::Pos3{ Math::Vector::rotate(World::Pos2{ trackPiece.x, trackPiece.y }, trackAndDirection.cardinalDirection()), 0 };
330 signalLoc.z += trackPiece.z;
331 auto res = findSignalOnTrack(signalLoc, trackAndDirection, trackType, trackPiece.index);
332
333 if (!res)
334 {
335 // This shouldn't happen I think. Either way useful in debug to know.
336 assert(false);
337 return;
338 }
339
340 auto [elSignal, foundTrack] = *res;
341
342 // edx
343 auto& signalSide = (flags & (1ULL << 31)) ? elSignal->getRight() : elSignal->getLeft();
344 if (unk1 == 16)
345 {
346 uint8_t lightStates = 0;
347 if (flags & (1ULL << 30))
348 {
349 lightStates |= 1 << 2;
350 if (flags & (1ULL << 28))
351 {
352 lightStates |= 1 << 0;
353 }
354 }
355 if (flags & (1ULL << 29))
356 {
357 lightStates |= 1 << 3;
358 if (flags & (1ULL << 27))
359 {
360 lightStates |= 1 << 1;
361 }
362 }
363
364 if (signalSide.allLights() != lightStates)
365 {
366 bool shouldInvalidate = false;
367 signalSide.setAllLights(lightStates);

Callers 9

sub_4AD778Method · 0.85
sub_4ACEF1Function · 0.85
sub_4AD93AMethod · 0.85
sub_4ADB47Method · 0.85
updateMethod · 0.85
liftUpTailFunction · 0.85
setSignalsOccupiedStateFunction · 0.85
setReverseSignalOccupiedFunction · 0.85

Calls 14

getTrackPieceFunction · 0.85
findSignalOnTrackFunction · 0.85
createAnimationFunction · 0.85
allLightsMethod · 0.80
setAllLightsMethod · 0.80
isFlag6Method · 0.80
setIsOccupiedMethod · 0.80
setUnk4Method · 0.80
rotateFunction · 0.50
invalidateFunction · 0.50
isReversedMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected