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

Replace hardcoded tilesets with mod-defined tileset loaders #18728

Merged
merged 9 commits into from
Jan 11, 2021

Conversation

pchote
Copy link
Member

@pchote pchote commented Oct 16, 2020

This PR implements the long-delayed move from a hardcoded and limiting tileset format to engine-side interfaces + mod-defined parsers, like we have for sequences.

The goal for this PR is to implement appropriately abstracted interfaces without significant changes to logic, so things like merging Theater (now DefaultTileCache) with TerrainRenderer or adding support for map-defined tileset overrides are out of scope. This PR is already uncomfortably large without having to consider disruptive changes like these. I expect that we will refine the interfaces and implementation over the next couple of years once mods start trying to use the new capabilities and find the friction points.

The main design goal is to remove the hardcoded assumptions that a tileset contains a set of templates that each have a single static sprite for each cell on the map. This allows the engine to support mods that want to use animated tiles (like the C&C remasters), 3D terrain models, or no tiles at all (e.g painting terrain types and having the renderer auto-LAT the transitions, or a single baked terrain image like classic KKnD). For this reason I have named most of the new abstractions around TerrainInfo, which better describes the new basic use.

The main new interfaces classes are:

  • ITerrainLoader: This is the terrain equivalent to ISpriteSequenceLoader - the new TerrainFormat: mod.yaml entry points to a class implementing this interface, which is created to parse the (now arbitrary) tileset yaml.
  • ITerrainInfo: This is the terrain equivalent to ISpriteSequence, except it makes no assumptions about sprites or artwork. The core engine only needs to know about terrain types and a couple of things for map previews, so this is all it defines.
  • ITemplatedTerrainInfo: This adds the concept of templates to ITerrainInfo for the benefit of the map editor and bridges/concrete. This is implemented in Mods.Common, and mods that don't want a templated terrain model can happily ignore it if they substitute the default map editor UI logic with their own.
  • ITiledTerrainRenderer: This interface expands the existing TerrainRenderer with methods that other traits can use to query template information and sprites without having to harcode references to a specific terrain implementation. The expectation is for mods to provide a matched pair of classes implementing this and ITerrainLoader. The terrain renderer then casts the generic map.Rules.TerrainInfo back to its concrete type so it can access the implementation specific information needed to render the terrain.

The main testcase here should be obvious: make sure that the existing mods continue to work as expected, focusing on the map editor and things like bridges/concrete that use the new interfaces.

I already have a local branch that implements animated terrain rendering, but that depends heavily on the other open remaster PRs so I expect it will be a while before anyone else can reasonably test it.

Depends on #18701. I suggest reviewing by commit.

@pchote
Copy link
Member Author

pchote commented Dec 14, 2020

Fixed, but now depends on #18927.

@phrohdoh
Copy link
Member

phrohdoh commented Jan 2, 2021

Attempting to manage Tiberian Sun's content causes a crash:

$ git rev-parse --short HEAD
ab4a8b90e3

$ ./launch-game.sh Game.Mod=ts
Loading mod: ts
Loading mod: modcontent
Exception of type `System.NullReferenceException`: Object reference not set to an instance of an object
  at OpenRA.Manifest.Get[T] () [0x00027] in OpenRA.Game/Manifest.cs:234 
  at OpenRA.ModData..ctor (OpenRA.Manifest mod, OpenRA.InstalledMods mods, System.Boolean useLoadScreen) [0x0015a] in OpenRA.Game/ModData.cs:76 
  at OpenRA.Game.InitializeMod (System.String mod, OpenRA.Arguments args) [0x00147] in OpenRA.Game/Game.cs:438 
  at OpenRA.Mods.Common.Widgets.Logic.MainMenuLogic+<>c__DisplayClass11_0.<.ctor>b__24 () [0x00011] in OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs:72 
  at OpenRA.Primitives.ActionQueue.PerformActions (System.Int64 currentTime) [0x0006f] in OpenRA.Game/Primitives/ActionQueue.cs:53 
  at OpenRA.Game.PerformDelayedActions () [0x00000] in OpenRA.Game/Game.cs:657 
  at OpenRA.Game.LogicTick () [0x00000] in OpenRA.Game/Game.cs:642 
  at OpenRA.Game.Loop () [0x000f1] in OpenRA.Game/Game.cs:815 
  at OpenRA.Game.Run () [0x0003c] in OpenRA.Game/Game.cs:856 
  at OpenRA.Game.InitializeAndRun (System.String[] args) [0x00010] in OpenRA.Game/Game.cs:274 
  at OpenRA.Launcher.Program.Main (System.String[] args) [0x00044] in OpenRA.Launcher/Program.cs:30 

Copy link
Member

@phrohdoh phrohdoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pchote
Copy link
Member Author

pchote commented Jan 2, 2021

Fixed.

@pchote
Copy link
Member Author

pchote commented Jan 6, 2021

Rebased.

@pchote pchote dismissed phrohdoh’s stale review January 7, 2021 22:10

Changes addressed

@reaperrr
Copy link
Contributor

Looks good to me and can confirm TS manage content no longer crashes, but needs another rebase.

@pchote
Copy link
Member Author

pchote commented Jan 11, 2021

Rebased.

@reaperrr reaperrr merged commit 53db123 into OpenRA:bleed Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants