Dungeon optimization tools

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Dungeon optimization tools

Post by AndakRainor »

So I have defined an object similar to the mine_chasm object. It does not have a Pit but a Null component with a onInit function to spawn an entire room I need to repeat many times (256).

As the mine_chasm object, It does not have a minimalSaveState. If I understand correctly this is because if it had minimalSaveState, it would respawn a copy of each already spawned room each time the saved game is loaded, via its onInit function.

What should I do to make it compatible with minimalSaveState, or more generally to optimize this object ? Destroy it at the end of the onInit function so it is removed from the saved game ? Check if the room parts are already spawned then skip it ? Or is there a way to remove all spawned room parts from the saved game then respawn them when the game reloads ?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Dungeon optimization tools

Post by minmay »

Destroy it at the end, yes.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Dungeon optimization tools

Post by AndakRainor »

If the baseObject of an object has minimalSaveState = true, does the object inherit this property as any other property ?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Dungeon optimization tools

Post by minmay »

Yes.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Dungeon optimization tools

Post by AndakRainor »

Are all functions of a component saved for a non minimalState object ?

If I get it right a component with a onInit function that spawns things should not belong to a minimalState object. On the other hand saving the onInit function of such a component does not make sens as it won't run more than once.

Is there a way to get rid of the function after it is run ? Maybe giving it the nil value at the end of the function ?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Dungeon optimization tools

Post by minmay »

AndakRainor wrote:Are all functions of a component saved for a non minimalState object ?
If I get it right a component with a onInit function that spawns things should not belong to a minimalState object. On the other hand saving the onInit function of such a component does not make sens as it won't run more than once.
Yes. Every component property has to be saved. But a single function will not be saved more than once; the first time a reference to a function is found during serialization, the function gets serialized, then every future reference to that function is just saved as, well, a reference. (I explain the side effects as far as environment here, but it's not really relevant for this question.)
AndakRainor wrote:Is there a way to get rid of the function after it is run ? Maybe giving it the nil value at the end of the function ?
I doubt there is any way to remove or change an onInit hook dynamically. However, you can destroy the component or the object, then it won't have to be saved anymore. Here is an example:

Code: Select all

defineObject{
	name = "mine_chasm",
	components = {
		{
			class = "Pit",
			onInit = function(self)
				for i=0,3 do
					local dx,dy = getForward(i)
					local adjacent = false
					for e in self.go.map:entitiesAt(self.go.x + dx, self.go.y + dy) do
						if e.name == "mine_chasm" or e.name == "mcm" then
							adjacent = true
							break
						end
					end
					if not adjacent then
						spawn("mine_chasm_edge", self.go.level, self.go.x, self.go.y, i, 0)
					end
				end
				self.go:spawn("mcm")
				self.go:destroy()
			end,
		},
	},
	replacesFloor = true,
	placement = "floor",
	editorIcon = 40,
	automapTile = "chasm",
}
defineObject{
	name = "mcm",
	components = {
		{
			class = "Pit",
		},
	},
	replacesFloor = true,
	placement = "floor",
	automapTile = "chasm",
	minimalSaveState = true,
}
This adapts mine_chasm to be usable with minimalSaveState. This mine_chasm object destroys itself after spawning the chasm edges and an "mcm" object, which occurs at dungeon initialization, so it will never have to be saved. "mcm" is a hidden object that is just a PitComponent with an automap tile and minimalSaveState.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Dungeon optimization tools

Post by Duncan1246 »

Hi Minmay,
First thanks for your tool and your explanations always precise and complete. The script works well in the Editor, but I can't obtains the whole file. When I try grimrock2.exe>output_file.txt in Windows terminal, grimrock editor crashes. What can I do to edit this report?
NB: in fact, grimrock editor don't crash, but Windows says so after the command...
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Dungeon optimization tools

Post by minmay »

"grimrock editor crashes" tells me nothing useful. What's the actual error message?
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Dungeon optimization tools

Post by Duncan1246 »

minmay wrote:"grimrock editor crashes" tells me nothing useful. What's the actual error message?
Yes, I know, it's a silly message: it's windows 7 message, not LG2... so what I have done is surely wrong?
1 open editor,
2 in console, run your script
2 open terminal and select grimrock2.exe.... run and crash with W7 warning: Grimrock2 cease to work.... No other message ....
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Dungeon optimization tools

Post by minmay »

...So you're launching the editor, running the script, then launching a second instance of the game and redirecting its output, and expecting that to somehow grab the output from the first grimrock2.exe instance - that was already printed? I think you are seriously confused and need to re-read the command prompt tutorial I linked to, and the step-by-step guide in the merge function's instructions.
Duncan1246 wrote:run and crash with W7 warning: Grimrock2 cease to work.... No other message ....
There's never "no other message", but you obviously aren't interested in looking into this yourself at all, so I'll just take a guess: you probably ran out of memory. This is covered in the instructions:
If running mergeObjectsOnLevel makes you run out of memory, try setting texture
resolution to "Low", and doing a clean load of the dungeon (start the game,
start the editor, load the dungeon ONCE in the editor, without reloading it or
loading another dungeon), then running it again. If you STILL run out of memory,
your dungeon is probably beyond this sort of help in the first place - but you
can try merging fewer levels at once, e.g. merge half the levels then the other
half and copy both sets of object definitions etc.

Note that the object
definitions file will be smallest if you merge all the levels with a single
mergeObjectsOnLevels call, because it tracks duplicate strings. However, there
will be no difference in in-game performance whether you merge all the levels at
once or not.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply

Return to “Mod Creation”