Expose map thumbnail and minimap to lua
As title says, let lua access map thumbnail and minimap patches because thats the only way that those can be accessed by lua.
mapheaderinfo[map].thumbnail
gives the map thumbnail patch and mapheaderinfo[map].minimap
gives the minimap patch. If for some reasons those arent loaded or valid then loads "BLANKLVL" youfuckedup patch as a failsafe
results using simple lua coding to display maps thumbnails and minimaps on screen.
Merge request reports
Activity
This is a really good and logical addition for scripts. Unfortunately, though, the
minimapPic
andthumbnailPic
are statically allocated and freed if a map is replaced at runtime. This will work seamlessly if the mapheader is polled every render tic, but can crash via invalid memory access if somebody tries to be smart and caches either graphic for drawing across muliple tics.I don't know the proper solution to this, but off the top of my head you should look into how
LUA_InvalidateUserdata
is called across the codebase and find a way to integrate it intoP_InitMapData
.this is a little too much for my smol brain, i do have a plan on mind:
1- use
LUA_InvalidateUserdata
on the patch fields before (or after, i dunno!) theyre freed from memory so i clears data from the Lua side of things inp_setup.cpp
line9174
to9184
so this way it avoids crash on random memory access2- that way, users storing mapheader patch data would have to update it everytime a new map is added (to avoid errors because is not certain that a fresh laoded map will use a pre existing slot) , best way would probably be on map load sinde game reloads maps when this happens.
but wouldnt that leave the user with invalid data ready to give a loud Lua warning on the user when it tries to do something with ? wouldnt there be a way to push the updated patch data to the lua user stored data so it does not throw erros on unawae users?
I tested the build with the current commit to see how the game would handle that.
Storing the patches somewhere once and using them to draw things on screen resulted on the Lua giving a error about them not being available anymore and its correct since they got freed when the pk3 got loaded overwriting already existing map headers and its pictures got free'd to accomodate for the new ones. the error can be easily avoided by checking for
valid
on the patches to store them back again.I also tested storing the mapheaders instead of the patches, i expected that a crash would be guaranteed but instead its better than storing the patches. I assume the game first alocates the mapheaders and if it gets overwriten, it just update its data then frees the pictures info to update them, since its the same location in memory Lua handles it well and updates it with no hassle making more reliable to do it this way instead of storing the patches directly
below videos of results.
this one when patches stored gets freed by the game, giving a error.
this one when the mapheader is stored instead, pay attention to the pictures on the left, top to bottom and how they got changed after the file gets loaded , with no errors.
mentioned in merge request !81