Print environment and entities

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
WaterKnight
Posts: 17
Joined: Mon May 07, 2012 2:27 pm

Print environment and entities

Post 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?
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Print environment and entities

Post 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.
WaterKnight
Posts: 17
Joined: Mon May 07, 2012 2:27 pm

Re: Print environment and entities

Post by WaterKnight »

Then the environment of the lua entity.
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: Print environment and entities

Post 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.
User avatar
Eleven Warrior
Posts: 745
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Print environment and entities

Post 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
User avatar
Eleven Warrior
Posts: 745
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Print environment and entities

Post 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
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Print environment and entities

Post 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.
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: Print environment and entities

Post 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?
Post Reply