Josh Posted November 16, 2016 Share Posted November 16, 2016 If you add a call to GCSuspend before clearing the world, and call GCResume after, the engine won't delete and reload all the resources that are shared between maps. This also helps if you are reloading a map to restart the level. --Handle map change if changemapname~=nil then --Pause the clock Time:Pause() --Pause garbage collection System:GCSuspend() --Clear all entities world:Clear() --Load the next map if Map:Load("Maps/"..changemapname..".map")==false then return end --Resume garbage collection System:GCResume() --Resume the clock Time:Resume() changemapname = nil end 10 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted November 16, 2016 Share Posted November 16, 2016 Cool, so any assets that aren't in the new map will be released when GCResume() is called?? 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
gamecreator Posted November 16, 2016 Share Posted November 16, 2016 That's good to know. Don't forget to add this to the docs if this is official. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted November 16, 2016 Share Posted November 16, 2016 That sounds like very useful functionality. Are there any downsides to using this function? Perhaps addding this as a boolean parameter to the load Map function for clean coding. A lot of users will forget this exists if it not a default behaviour. 1 Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted November 16, 2016 Share Posted November 16, 2016 This is exactly what I've been looking for! 1 Quote Link to comment Share on other sites More sharing options...
Genebris Posted November 16, 2016 Share Posted November 16, 2016 Thanks! I was always wondering why restarting the map is so slow. Quote Link to comment Share on other sites More sharing options...
Josh Posted November 16, 2016 Author Share Posted November 16, 2016 That sounds like very useful functionality. Are there any downsides to using this function? Perhaps addding this as a boolean parameter to the load Map function for clean coding. A lot of users will forget this exists if it not a default behaviour. As the code was written before, the engine would clear the world, deleting all textures and models, and then reload whatever was needed. The GCSuspend command makes it so when an object's reference count hits zero, it is added to a list of deleted objects, but its destructor isn't called yet. The destructors will all be called and the list cleared when the GCResume call is made. Another way this could be done is to create a new world and load the map into that, then delete the old one: --Handle map change if changemapname~=nil then --Pause the clock Time:Pause() local prevworld = world world = World:Create() --Load the next map if Map:Load("Maps/"..changemapname..".map")==false then return end prevworld:Release() --Resume the clock Time:Resume() changemapname = nil end 3 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.