Page 1 of 1

More flexible API / using flags

Posted: Sun Oct 16, 2016 11:48 am
by Factoruser
the entity concept should be changed to a flag-based system - and all entity-types should have prototypes.

I.e. you should be able to easily add e.g. electricity consumption to any new or existing entity without writing an OnTick() subroutine. Flags are something like: consumesElectricity, hasInputInventory, hasFuelInventory, hasStorageInventory, wireConnectable etc. The entity-type prototypes are pre-setting them, and can be overwritten by derived entity prototypes.

Re: More flexible API / using flags

Posted: Sun Oct 16, 2016 12:06 pm
by Adil
Would be nice. Would require ground up rewrite. Seems never to be implemented viewtopic.php?f=28&t=24064&p=151436

Re: More flexible API / using flags

Posted: Sun Oct 16, 2016 2:12 pm
by Factoruser
Adil wrote:Would be nice. Would require ground up rewrite.
Going in a similar direction... But all to do would be "just" to exchange everywhere e.g. "if (type="electric-pole")" with "if (distributesElectricity())". Never underestimate such changes of course.

Re: More flexible API / using flags

Posted: Sun Oct 16, 2016 2:31 pm
by aubergine18
It's not that simple, you have to factor in branch predication and a bunch of other stuff. Having masses of if statements would dramatically slow the game down.

An alternate approach might be to group entities with similar flags, effectively creating crankenshaft-style pseudo-classes. But that's going to be huge amount of work with no guarantee of success.

Re: More flexible API / using flags

Posted: Sun Oct 16, 2016 10:47 pm
by Rseding91
Factoruser wrote:the entity concept should be changed to a flag-based system - and all entity-types should have prototypes.

I.e. you should be able to easily add e.g. electricity consumption to any new or existing entity without writing an OnTick() subroutine. Flags are something like: consumesElectricity, hasInputInventory, hasFuelInventory, hasStorageInventory, wireConnectable etc. The entity-type prototypes are pre-setting them, and can be overwritten by derived entity prototypes.
You've never written any large piece of performance intensive software have you? There have been multiple suggestions to do this and my response is the same to every one of them:

Until I see *anyone* else implement such a system at the scale that Factorio runs and be successful doing so it's just not even something worth thinking about.

Re: More flexible API / using flags

Posted: Mon Oct 17, 2016 12:30 am
by Factoruser
Rseding91 wrote:
Factoruser wrote:the entity concept should be changed to a flag-based system - and all entity-types should have prototypes.

I.e. you should be able to easily add e.g. electricity consumption to any new or existing entity without writing an OnTick() subroutine. Flags are something like: consumesElectricity, hasInputInventory, hasFuelInventory, hasStorageInventory, wireConnectable etc. The entity-type prototypes are pre-setting them, and can be overwritten by derived entity prototypes.
You've never written any large piece of performance intensive software have you?
Öööhm... I've had once to deal with very limited hardware of 1 MiB RAM, 8 MHz and such stuff... But I don't know your code and how the LUA interpreter is integrated into projects. Normally, checking flags IS performant (AND gate). Especially compared to instead using an OnTick()-subroutine for each entity written in LUA Script. But if you have to rewrite nearly the whole core, it's just not worth it.

Re: More flexible API / using flags

Posted: Mon Oct 17, 2016 5:31 pm
by ssilk
I think this discussion is not useful in any direction until some game-code (C++) is known and understood. :)