KhymChanur: I'm proposing this with fountains in mind, but it could have other uses in other modules. The idea is that, once level generation is done, generate.c would iterate over all the grids in the level, check to see if the feature's flags contains ON_MAKE, and invoke it if it does; cave_set_feat() would also invoke it if present.
I'm not sure if this is the best way to go about doing things like filling fountains with potions.
DarkGod: It has the avantage of working the same way as the objects system. And if the dungeon is not completly filled with ON_MAKE features, it shouldnt be noticable. I'd say go for it
KhymChanur: I did a very rough profiling of the code, by seeing how much time it took to generate 1,000 dungeons (clock time, not CPU time). Before the change, generating 1,000 dungeons (ignoring auto-scumming) took 145 second. After adding this code to cave_set_feat():
/* Clear the terrain's name and on_walk text */
flag_remove(&c_ptr->flags, FLAG_TERRAIN_NAME);
flag_remove(&c_ptr->flags, FLAG_TERRAIN_TEXT);
/* Does the feature require any special setup? */
if (has_flag(f_ptr, FLAG_ON_MAKE))
{
open_lua_functions_registry(get_lua_functions_registry_domain("f_info"), get_flag(f_ptr, FLAG_ON_MAKE));
call_lua(NULL, "(d, d, d)", "", y, x, feat);
close_lua_functions_registry();
}
The time increased to 188 seconds, a 30% increase, even when none of the features had the ON_MAKE flag. However, this was clock-time, not cpu-time, with a mail and spam filtering and stuff running in the backgroumd so I don't know how accurate it is.
NeilStevens': I take it you're not on a unix system, where the time command will tell you wall-clock time as well as the time taken by the specific process?
KhymChanur: D'oh! I'd sort of forgotten about that. Just have to account for the startup and shutdown time of the engine...
KhymChanur: Okay, ignoring the CPU time consumed for startup and save-file loading, without the ON_MAKE stuff it take 137.8 seconds to generate 1,000 levels, and 178.31 to generate with ON_MAKE stuff. Which is still a 29% increase.
ShrikeDeCil: That's 0.04 seconds increase per level. I can't notice that.
KhymChanur: It doesn't include level regeneration, especially due to auto-scumming. If a lot of levels are generated before the engine settles on one that's good enough, you could notice a difference.
ShrikeDeCil: If auto-scumming is going to be the mainstream 'play' method, then adjusting the constants such that non-boring was a lot more common would save the generation of 50+ levels. Yes?
NeilStevens: I say don't worry about it. Design now, optimize later.
ToME Wiki