Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow diagonal tracks on level crossings #8556

Draft
wants to merge 3 commits into
base: master
from

Conversation

@Eddi-z
Copy link
Contributor

@Eddi-z Eddi-z commented Jan 11, 2021

Motivation / Problem

Currently, rails and roads can only cross at a right angle.

Track layouts could be more compact or more flexible if also diagonal rails could cross roads.

Description

This is essentially a resurrerction of an old patch by Maedhros https://www.tt-forums.net/viewtopic.php?f=33&t=26584

A major problem with the old patch was that two diagonal trackbits can be on one tile, and trains passing simultaneously through them could leave locked crossings behind. this is why this update builds upon #8444 (so this PR includes the same changes)

Limitations

I could not resurrect the graphics part of the patch, so all level crossings show as "road in X direction"
Drawing level crossings works only for cases where no newgrf railtype is loaded that uses overlays to draw level crossings
(drawing reservation overlay and catenary need another look)

Since i did most of this work before newgrf roadtypes were introduced, i might have fudged a few bits when updating to current master, i cannot guarantee correct functionality in all corner cases.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
@Eddi-z Eddi-z force-pushed the Eddi-z:level_diag branch from e9cafc0 to c62d3ed Jan 14, 2021
@Eddi-z
Copy link
Contributor Author

@Eddi-z Eddi-z commented Jan 14, 2021

After updating the nfo format to version 32 (boy, 2011 was such a long time ago), openttd.grf now actually contains the missing sprites (there's still no code that actually draws the sprites, though)

@Eddi-z Eddi-z force-pushed the Eddi-z:level_diag branch 3 times, most recently from 6273d1b to f255e8d Jan 14, 2021
@Eddi-z
Copy link
Contributor Author

@Eddi-z Eddi-z commented Jan 15, 2021

Added an updated version of the old drawing code, works only on railtypes which do not add level crossing overlays (i.e. pretty much no NewGRF railtypes)

@Eddi-z
Copy link
Contributor Author

@Eddi-z Eddi-z commented Jan 15, 2021

patch for nforenum:

diff --git a/src/data.cpp b/src/data.cpp
index 0781240..6834d68 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -186,6 +186,7 @@ NDF_HEADER(0x04, 17),
 /*16*/ OFFSET,          OPTIONS(1), 0x09,
 /*17*/ OFFSET,          OPTIONS(1), 0x10,
 /*18*/ RECOLOUR,        OPTIONS(1), 0x01,
+/*19*/ OFFSET,          OPTIONS(1), 0x34,
 00,
 NDF_END
 };
@DorpsGek DorpsGek temporarily deployed to preview-pr-8556 Jan 15, 2021 Inactive
@ldpl
Copy link
Contributor

@ldpl ldpl commented Feb 12, 2021

Dunno how finished is this supposed to be but I played a bit with preview and noticed it does weird stuff when you try to cross half-tile road and then crashes when road is removed.
Screenshot from 2021-02-12 12-12-40

exception thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.,abort@https://preview.openttd.org/pr8556/openttd.js:1516:11
_abort@https://preview.openttd.org/pr8556/openttd.js:6430:7
error(char const*, ...)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[5860]:0x429f96
RemoveRoad(unsigned int, DoCommandFlag, RoadBits, RoadTramType, bool, bool)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[6131]:0x4765c7
ClearTile_Road(unsigned int, DoCommandFlag) (.llvm.12948475216051914217)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[6144]:0x47e99d
CmdLandscapeClear(unsigned int, DoCommandFlag, unsigned int, unsigned int, char const*)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[5008]:0x38e805
DoCommand(unsigned int, unsigned int, unsigned int, DoCommandFlag, unsigned int, char const*)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[3769]:0x2b2ed6
CmdClearArea(unsigned int, DoCommandFlag, unsigned int, unsigned int, char const*)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[5009]:0x38edbb
invoke_viiiiii@https://preview.openttd.org/pr8556/openttd.js:12100:25
DoCommandPInternal(unsigned int, unsigned int, unsigned int, unsigned int, void (*)(CommandCost const&, unsigned int, unsigned int, unsigned int, unsigned int), char const*, bool, bool)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[3771]:0x2b3ba0
DoCommandP(unsigned int, unsigned int, unsigned int, unsigned int, void (*)(CommandCost const&, unsigned int, unsigned int, unsigned int, unsigned int), char const*, bool)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[3770]:0x2b3133
GUIPlaceProcDragXY(ViewportDragDropSelectionProcess, unsigned int, unsigned int)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[6898]:0x5307e0
TerraformToolbarWindow::OnPlaceMouseUp(ViewportPlaceMethod, ViewportDragDropSelectionProcess, Point, unsigned int, unsigned int)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[6914]:0x531985
VpHandlePlaceSizingDrag()@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[7606]:0x5c5d34
HandleMouseEvents()@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[7787]:0x5e308b
VideoDriver_SDL::EmscriptenLoop(void*)@https://preview.openttd.org/pr8556/openttd.wasm:wasm-function[3434]:0x27c0ba
browserIterationFunc@https://preview.openttd.org/pr8556/openttd.js:9986:66
runIter@https://preview.openttd.org/pr8556/openttd.js:6627:13
Browser_mainLoop_runner@https://preview.openttd.org/pr8556/openttd.js:6566:26
pr8556:130:21

@Eddi-z Eddi-z force-pushed the Eddi-z:level_diag branch from f255e8d to fa39761 Feb 14, 2021
@DorpsGek DorpsGek temporarily deployed to preview-pr-8556 Feb 14, 2021 Inactive
@Eddi-z
Copy link
Contributor Author

@Eddi-z Eddi-z commented Feb 14, 2021

it does weird stuff when you try to cross half-tile road and then crashes when road is removed.

building on halftile roads should be working correctly now, which should also avoid the crash on removing it later

@ldpl
Copy link
Contributor

@ldpl ldpl commented Feb 14, 2021

When there are two crossings on one tile removing one rail removes the other.
Screenshot from 2021-02-14 23-34-17

Also half-diagonal crossings are kinda weird, they don't have signals on one side and vehicle stopping position looks wrong even though they don't seem to rly crash.
Screenshot from 2021-02-14 23-38-11

UPD. Opening settings crashes the game, at least in preview.

@J0anJosep
Copy link
Contributor

@J0anJosep J0anJosep commented Mar 7, 2021

The path reservation track sprite is not right.

imatge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants