Page 1 of 1

Print environment and entities

Posted: Wed Sep 18, 2013 6:09 pm
by WaterKnight
Hello there,

For starters, I would like to investigate the possibilities of lua scripts ingame programmatically. In standard lua, you could simply print _G (the global environment) with

Code: Select all

for k, v in pairs(_G) do
    print(k, v)
end
in order to view the provided base variables and functions. In Grimrock, it's nil.

Furthermore, although entities are tables and possess some fields as documented in http://www.grimrock.net/modding/scripting-reference/, pairs and ipairs yield nothing on them. So I guess the functions were overwritten and metatables set for safety reasons. Any backdoor?

Re: Print environment and entities

Posted: Wed Sep 18, 2013 11:09 pm
by petri
There is no global environment because every script entity lives in its own environment. Otherwise global variables would easily collide and cause hard to find bugs.

Re: Print environment and entities

Posted: Thu Sep 19, 2013 12:18 am
by WaterKnight
Then the environment of the lua entity.

Re: Print environment and entities

Posted: Thu Sep 19, 2013 4:03 am
by Diarmuid
petri wrote:There is no global environment because every script entity lives in its own environment. Otherwise global variables would easily collide and cause hard to find bugs.
That's interesting... but there has to a global state of sorts which allows you to write snail_1:destroy(), unless references to all entities' ids are "registered" as global variables in every single script entity environment (?). If this is a case, does a large number of script entites have an impact on performance/memory usage? I'm wondering as the ORRR2 is getting quite sluggish on the CPU side (not rendering), and I suspect a large number of objects in the dungeon might be the problem. If we could target particularly demanding ones it would be easier to optimize.

Re: Print environment and entities

Posted: Thu Sep 19, 2013 8:27 am
by Eleven Warrior
Diarmuid I know imam new at this, but if you destroy all the Entities on the LVL would that help with the Slowness.. sorry I know you know better than me, I don't mean to question anyone.. I have Destroyed things on my LVl's and performance is better..... Ummm ill leave it to u guys u are much better coders than im

Re: Print environment and entities

Posted: Thu Sep 19, 2013 8:35 am
by Eleven Warrior
Eleven Warrior wrote:Diarmuid I know imam new at this, but if you destroy all the Entities on the LVL would that help with the Slowness.. sorry I know you know better than me, I don't mean to question anyone.. I have Destroyed things on my LVl's and performance is better..... Ummm ill leave it to u guys u are much better coders than im
man imam sorry I should not have said anything here.. Imma just trying to learn from you guys

Re: Print environment and entities

Posted: Thu Sep 19, 2013 11:46 am
by petri
Diarmuid wrote:
petri wrote:There is no global environment because every script entity lives in its own environment. Otherwise global variables would easily collide and cause hard to find bugs.
That's interesting... but there has to a global state of sorts which allows you to write snail_1:destroy(), unless references to all entities' ids are "registered" as global variables in every single script entity environment (?). If this is a case, does a large number of script entites have an impact on performance/memory usage? I'm wondering as the ORRR2 is getting quite sluggish on the CPU side (not rendering), and I suspect a large number of objects in the dungeon might be the problem. If we could target particularly demanding ones it would be easier to optimize.
Entity references are handled with metatables so they don't need to be stored in scripts environments.

Log1 engine was not originally designed with modding/scripting in mind, so there are some inefficiencies. For example, resolving entity references becomes slow with large number of entities (this has been fixed for LoG2). Try to avoid using lots of entity references per frame (e.g. in timers that run at high frequency) or try to cut down the number of entities in the dungeon.

Re: Print environment and entities

Posted: Fri Sep 20, 2013 2:57 pm
by Diarmuid
petri wrote:Entity references are handled with metatables so they don't need to be stored in scripts environments.

Log1 engine was not originally designed with modding/scripting in mind, so there are some inefficiencies. For example, resolving entity references becomes slow with large number of entities (this has been fixed for LoG2). Try to avoid using lots of entity references per frame (e.g. in timers that run at high frequency) or try to cut down the number of entities in the dungeon.
Great, thanks petri. So for example if we serialized away all static items (decorations, pillars, statues, lights...) NOT on the current level, that could unclutter the entities list and make indexing faster for the rest?

Also, was AI in LoG1 resource-intensive? I mean, is it worth it to remove all monsters that are standing on Guard in remote locations and only spawn them when the player approaches?