Can someone explain to me how 2cc train set in NML is coded?
Moderator: Graphics Moderators
- TrainLover
- Engineer
- Posts: 107
- Joined: 01 Jul 2015 15:03
Can someone explain to me how 2cc train set in NML is coded?
I jumped in the source code of 2cc trains in NML. I am stumped because the are so many pnmls and I only have seen NML in the way that NFO has been written, like huge blocks of text (see wiki post on NML tutorial). I really want to code my train set, with huge amounts of sprites and a lot of livery refits. Does that work with pnmls? Also please explain on why they used that pnml method instead of the regular method that is used in the tutorial? Is it more effective and easier to read?
Developer of North American Passenger Liveries: viewtopic.php?f=26&t=87228
Re: Can someone explain to me how 2cc train set in NML is coded?
This thread covers the topic.
2cc in nml uses C preprocessor to break nml code into separate files, and also use other macros and conditionals and such to make the coding life easier.
Then, once it's ready for compilation, the pnml file is processed by a C compiler (most probably gcc), which creates nml file.
Then compiling the nml into grf is same as any other nml project.
To make those multi-step process automated, 2cc train set uses GNU make.
2cc in nml uses C preprocessor to break nml code into separate files, and also use other macros and conditionals and such to make the coding life easier.
Then, once it's ready for compilation, the pnml file is processed by a C compiler (most probably gcc), which creates nml file.
Then compiling the nml into grf is same as any other nml project.
To make those multi-step process automated, 2cc train set uses GNU make.
Re: Can someone explain to me how 2cc train set in NML is coded?
It's about scaling and keeping things modular (mostly I think).TrainLover wrote:I really want to code my train set, with huge amounts of sprites and a lot of livery refits. Does that work with pnmls? Also please explain on why they used that pnml method instead of the regular method that is used in the tutorial? Is it more effective and easier to read?
With a single vehicle, the tutorial method is fine. When you scale up to more vehicles, you don't want to have a single NML file with all stuff in it (50 vehicles with say 30 lines of code for each vehicle makes 1500 lines of file, and 2cc set has many more vehicles!). It takes forever finding the point that you need to change.
What you really want is a number of sprites + a small nml-ish file together for each vehicle. That way, you have a source file dedicated for each vehicle. Easy to find and change.
The puzzle is now that nml wants a single file, and you have say 5 vehicles, thus 5 sprite sheets + 5 nml-ish files.
This is solved by the C pre-processor. That program is designed to collect separate files and make it into one big file at its output. It uses a #include mechanism to insert a file, and it has #define for macro processing magic, if you need it.
To avoid confusion between regular nml files that go into the nmlc compiler, and partial nml files that contains a single vehicle (or a single industry, or ...), the latter are named .pnml (partial-nml).
In short, the .pnml file is a normal nml file, but only for the one thing you code in it. It has a bit of context and available templates (I assume) that you can just use. The main .pnml file is run through the C preprocessor to make the nml file, which is then compiled by nmlc as normal to make the .grf.
Being a retired OpenTTD developer does not mean I know what I am doing.
Who is online
Users browsing this forum: No registered users and 11 guests