More flexible API / using flags

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
Factoruser
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Sep 16, 2014 5:48 pm
Contact:

More flexible API / using flags

Post 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.

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: More flexible API / using flags

Post by Adil »

Would be nice. Would require ground up rewrite. Seems never to be implemented viewtopic.php?f=28&t=24064&p=151436
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Factoruser
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Sep 16, 2014 5:48 pm
Contact:

Re: More flexible API / using flags

Post 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.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: More flexible API / using flags

Post 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: More flexible API / using flags

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Factoruser
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Sep 16, 2014 5:48 pm
Contact:

Re: More flexible API / using flags

Post 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.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: More flexible API / using flags

Post by ssilk »

I think this discussion is not useful in any direction until some game-code (C++) is known and understood. :)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

Post Reply

Return to “Ideas and Suggestions”