Page 1 of 1

CPU, memory info and lua VM

Posted: Wed Aug 17, 2016 11:46 am
by sebgggg
Hello,

Could you add a cpu and memory properties to the game object please?
It could be useful to implement "smart" coroutines for heavy calculations, it does not need to be precise, just an indication like low, mid, high.

Is it also possible to add integer and bit ops to the lua VM? It could tremendously help performance for, say, neural networks :)

Edit:
I forgot, can you also add a function get_tiles(area) ?

Thanks!

Re: CPU, memory info and lua VM

Posted: Wed Aug 17, 2016 2:32 pm
by aubergine18
Using coroutines will likely break MP games due to desync...

I thought the bitop stuff was already present (vague memory - have a root around on _G)...

For getting tiles in area, you could use these from any LuaSurface:

.get_tileproperties(x, y) → TileProperties Get tile properties.
.set_tiles(tiles, correct_tiles) Set tiles at specified locations.

Re: CPU, memory info and lua VM

Posted: Wed Aug 17, 2016 3:23 pm
by Rseding91
This already exists. Just hit F4 in-game and enable the debug times option to see how much CPU time is spent on each mod.

Re: CPU, memory info and lua VM

Posted: Tue Aug 30, 2016 5:03 am
by sebgggg
aubergine18 wrote:Using coroutines will likely break MP games due to desync...

I thought the bitop stuff was already present (vague memory - have a root around on _G)...

For getting tiles in area, you could use these from any LuaSurface:

.get_tileproperties(x, y) → TileProperties Get tile properties.
.set_tiles(tiles, correct_tiles) Set tiles at specified locations.
I meant in-game routines, based on the on_tick event, although true MP co routines would be nice :)
And about get_tiles, i meant a function returning an array of tiles.

Thanks for your answer though :)

Re: CPU, memory info and lua VM

Posted: Tue Aug 30, 2016 5:03 am
by sebgggg
Rseding91 wrote:This already exists. Just hit F4 in-game and enable the debug times option to see how much CPU time is spent on each mod.
No, i meant programatically get the CPU load, in a mod. There's nothing like that on http://lua-api.factorio.com unless i'm missing something?

Thanks for your time :)

Re: CPU, memory info and lua VM

Posted: Tue Aug 30, 2016 6:21 am
by Rseding91
sebgggg wrote:
Rseding91 wrote:This already exists. Just hit F4 in-game and enable the debug times option to see how much CPU time is spent on each mod.
No, i meant programatically get the CPU load, in a mod. There's nothing like that on http://lua-api.factorio.com unless i'm missing something?

Thanks for your time :)
That information wouldn't be deterministic at all and as such would desync and break replays if mods had access to it - which is why they don't.

Re: CPU, memory info and lua VM

Posted: Fri Sep 02, 2016 3:27 pm
by Afforess
Essentially what you really need is a way to schedule lazy execution of certain code when the game has free time slices available. Right now there isn't a way to do that, and I gather what @sebgggg is asking for would let him build one.

Sure, code execution can be smeared over on_tick but that's not a perfect solution, as it gives no indication of what else might also be running.

Re: CPU, memory info and lua VM

Posted: Sun Sep 04, 2016 8:29 pm
by aubergine18
I'm sure I read somewhere in these forums that events will wait until later tick before triggering handlers if too much time has been taken on tick where event fired (not sure if this is only vanilla events of if it works for custom events too?)