KeldorKatarn wrote:Every single AAA game out there uses scripting languages for their logic so I beg to differ.
For high level logic, sure. Now name a few that use scripting to decide the graphics to draw every single frame in the animation, for all things visible. I am pretty sure it's very close to 0, if not actually 0. (Pointing to an animation as a whole does not count!)
Whether doing a callback for an image every single frame is sane is of course also an issue, but openttd does it in this way currently. For fair comparison the scripting language of your choice should also do that.
KeldorKatarn wrote:Nobody writes game logic in C++ anymore unless that happens to be used as a scripting language like Unreal does it. but that's just the syntax, it's still a scripting language.
Even OpenTTD moves away from that, new things are often opened up as gamescript interface, so you can write a game script for your game logic.
KeldorKatarn wrote:I don't claim to know exactly what NewGRFs do or rather how they do it, but all profiling shows they're very slow and a major bottleneck and looking through the forums it's also pretty clear that they're anything but easy to write outside of a group of people that worked with them for decades since their inception.
Profiling is showing you the performance gap between native code and interpreted byte-code, you'd also see that gap with any scripting language, unless it gets translates to real native code in a smart way.
As Patchman said, NewGRF is the byte-code of the graphics engine of OpenTTD, the assembly-language of graphics, so to say.
The big problem of NewGRF byte-code is that it's quite complicated to get into. It's all "action X", without high level overview of what X-es exist, what the purpose is of each of them, and how they work together. It's not unlike the problem of studying assembly language by means of opcodes without a processor model in your head.
However, about 95% of more of the code is very simple, a few "if" statements, and that's it. Mostly a one-liner in a typical scripting language. Th trick is to avoid understanding NFO as a set of seperate actions, and see it as functions.
Almost all NewGRF authors do pretty much just copy/paste of existing code from other projects, which doesn't need deep understanding at first.
Seeing NewGRF as the one and only true way to write graphics code would be sub-optimal imho, much like we don't write assembly language anymore, we write C++, and let the compiler do the conversion. In NewGRF, we have nml and other compilers that give a high-level view of the functions. No need to hack nfo, unless you like NFO bytes, write openttd interface code, or extend one of the compilers.
Before attempting any form of replacement of newgrf by a scripting language, I'd start with an experiment of a scripting language returning the image to draw for a vehicle, for every frame, for all the vehicles running in the game. If that runs smooth, try adding some simple logic based on game year or so. If the game hasn't exploded by then, try a few extreme openttdcoop games for speed comparison. If that works, start thinking about replacement.
I quite doubt however you can be as fast as newgrf is today. Simple straightforward scripting languages using byte-code won't get the job done, as something general purpose is highly unlikely competitive with a language dedicated for the job at hand.
KeldorKatarn wrote:I'm not bashing anything, I'm just saying this could probably be improved. And the fact that constantly "specs" have to be designed when changing them is also not ideal.
Specs are the public interface between the program and the newgrf, ie the set of callbacks, provided properties by openttd, etc. You have to define them to have a clear interface definition between the grf byte-code and the openttd program.
KeldorKatarn wrote:Any scripting language would simply define a new function or change one and be done with it. This seems such an elaborate process that any change takes months or years to be finalized. That's just a horrible workflow in my book.
So how is your newly invented callback function called by openttd at the proper time then? How can you differentiate between grfs that have the new callback and those that don't?
NewGRF is not a main function with a lot of logic where you have to partition work into some functions. It's a large set of callback functions, each function being very short, a few statements only in general.
KeldorKatarn wrote:But as I said.. ripping all that out and replacing it would be a huge undertaking. Adding a proper scripting environment isn't exactly easy. But it's the way to go. Every modern engine does it like that. In some engines the scripts are not even precompiled and just lying around as source files, and then compiled right before game start, then cashed for later game runs with checksum and recompiled if necessary.
Do the experiment, I think you'll be surprised how slow a general purpose scripting language is.
JGR wrote:Adding more efficient callback interfaces to the NewGRF spec could work, but the existing (less efficient) ones also need to be supported indefinitely, and existing GRFs are highly unlikely to be upgraded.
In my observation, GRF authors and devs/patchpack authors tend to optimise for different things. Marginal run-time performance improvements at the expense of additional NewGRF development effort/complexity doesn't sound like a vote-winner on the GRF side to me, (especially as the base development difficulty is already high).
It's not more work for a NewGRF author, he already has to specify the exact conditions when an industry can be built, for example. To them, it's just shifting code to a new callback, or transforming it into a new form.
If it also improves user experience, I think many authors would update. Some existing grfs would not, so yep, you can't kill the "repeat random placement attempt" code, unless you drop backwards compability, but it becomes legacy much like all the legacy that already exists.
Many users however eventually play with newer grfs, and get the benefits of them.
Being a retired OpenTTD developer does not mean I know what I am doing.