There is no cache and the $dataMap is completely overwritten but the Game_Map is only partially refreshed.
Let's retrace the steps RM MV takes when returning to the map again after closing the menu:
Spoiler
Scene_Map.prototype.create = function() { Scene_Base.prototype.create.call(this); this._transfer = $gamePlayer.isTransferring(); var mapId = this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId(); DataManager.loadMapData(mapId); // <<<<<<<<<<<<<<<<<<<<<<<<};DataManager.loadMapData = function(mapId) { if (mapId > 0) { var filename = 'Map%1.json'.format(mapId.padZero(3)); this.loadDataFile('$dataMap', filename); // <<<<<<<<<<<<<<<<<<<<<<<< } else { this.makeEmptyMap(); }};DataManager.loadDataFile = function(name, src) { var xhr = new XMLHttpRequest(); var url = 'data/' + src; xhr.open('GET', url); xhr.overrideMimeType('application/json'); xhr.onload = function() { if (xhr.status < 400) { window[name] = JSON.parse(xhr.responseText); // <<<<<<<<<<<<<<<<<<<<<<<< Overwrites $dataMap completely. The old object will most likely be GC-ed unless you referenced it yourself. DataManager.onLoad(window[name]); } }; xhr.onerror = function() { DataManager._errorUrl = DataManager._errorUrl || url; }; window[name] = null; xhr.send();};Also this is called again:
Scene_Map.prototype.createDisplayObjects = function() { this.createSpriteset(); // Wait... Even a whole new spriteset is created? this.createMapNameWindow(); this.createWindowLayer(); this.createAllWindows();};Judging from the above code, I might have alias my minimap plugin also wrong, I aliased the Game_Map.setup instead of Scene_Map.createDisplayObjects. But the setup is not called when the map is (partially) recreated. So this may affect more plugins.
// This line of code is NOT called, which is (I think) the reason the events and such don't lose their position.// Events are reloaded in the $dataMap but this new data is not actually pushed onto the old Game_Map instance.// This causes a difference between the $dataMap and the actual data on the map...Game_Map.prototype.setup()
The whole $dataMap is completely overwritten (there is no cache that I could find). And because RM skips the
Game_Map.prototype.setup() the events only work because they are simply not refreshed from the $mapData. They are still from the old Game_Map instance that simply never refreshed this part of the data. But by overwriting the $mapData there could not be a 'desynch'/difference between the $mapData and the actual events and such on the map.
This would also mean that if you change anything in the spriteset, you must manually cache this (like I did with $dataMap.data) because otherwise the menus will reset it all.
There are so many things wrong with this. I do not understand why they did this:
- Scripters will now have to manually cache their data, If multiple scripts do this, you end up with a lot of duplicate caching.
- $mapData no longer matches the actual (non-tile)-data on the map, not even with default RM code. Everyone can imagine why this is extremely bad.
- It's very confusing.
- It's not efficient. Loading the entire $dataMap from disk every time you return from a menu or such will cause hiccups for bigger and more complex maps. It does already for me in fact.