darkgriffin

Villager
Member
Joined
Sep 3, 2013
Messages
23
Reaction score
3
First Language
English
Primarily Uses
I'm a bit sick today, so you'll have to bear with my rambling mind a bit.


Anyway, in an effort to try and understand the map structure, I managed to make a plugin that floods an entire map with the tile in 0,0,0 of a map.


Yes, it's as useless as that sounds.  Even more so because there is no way to skip affecting any maps.  So you can't really make much more then "adventures of Ralph in the infinite carpet dimension." :p


I just thought some other coders might like to see a possible way into the map loading code.  This provides a way to modify a copy of the data being fed into the map rendering in game.  I've tested and it appears this particular function is only run on map load.  It will run once for every time the game loads map data from the database.


I was intending to code a dungeon generator using this method, though that is still a very, very, very distant goal right now.  


It seems the map data this time is not a 3 depth array like the manual claims it is.  At least, not at this level of access.  Instead, it's a single list of tiles for each layer of the map, which can be accessed through a few "magic formulas" to find the numerical data in a certain x,y,z position.  It's all very clever till one tries to comprehend how to step all around in it.


My next step I suppose is trying to figure out how deep the data for a single tile is, and how autotiles work.  The manual is much less then helpful with how things are structured, I got this far only with a lot of sniffing around using the F8 debugger.  But I will keep hammering away.


Any advice for dealing with tile data would be greatly appreciated.  I'm mostly stumbling round in the dark poking and breaking things.

View attachment DarkGriffin_Newbie.js
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,699
Reaction score
939
First Language
English
Primarily Uses
N/A
I'm on my phone so I just skimmed this and can't look at the script itself, but technically a multidimensional array issue still stored in a continuous line. Other programming language that have the multidimensional syntax implicitly do the calculations to get the element in the straight line, so technically it still is a three dimensional array. I'm uncertain if js supports multidimensional array access like you're thinking of. 


Auto tiles are a set of similar numbers based on which form of the tile is to be shown. I'm not sure exactly how much they change or what formula is used to transform the time's sheet and index into a number though. 
 

darkgriffin

Villager
Member
Joined
Sep 3, 2013
Messages
23
Reaction score
3
First Language
English
Primarily Uses
$dataMap.data[(z*height+y)*width+x];




The above is how they get a tile in the original code.  x,y,z are passed values to their GetTile(x,y,z) function.


Javascript does support arrays of arrays, so something like the following works  (using it right now to give myself a temporary dungeon carving array, so it works even in rpg maker mv):


var dungeon = new Array(width);
        for (x=0;x<width;x++){
            dungeon[x] = new Array(height)
            for (y=0;y<height;y++){
                dungeon[x][y] = flood_tile;
            }
        }


The array I made can then be read/written from/to with dungeon[x][y] = tile number or any data to put in


I think they were trying to save memory by using a single dimension array for all the layers.  My method does require Javascript to make a new object for each row of tiles.  Which means a lot of extra overhead from all the data for those objects in Javascript.  Their method is probably a lot easier on the memory.


By looping over my dungeon data array using their formula above, I can pass back my own 2 dimensional array system back into their single dimensional array.  So now I can work with sane xy values when dungeon carving, then push it all back.  It's not as memory saving as editing the original tiles directly, but it lets me carve in xy space on a single layer.  


I'm planning on doing the dungeon passage/room carving on my own array, and then "render" my resulting array back into their tile format in the end.  It's lazy on my part, but my array only needs to exist when the map first loads anyway.
 

darkgriffin

Villager
Member
Joined
Sep 3, 2013
Messages
23
Reaction score
3
First Language
English
Primarily Uses
How do passables work?  I don't think I need to know the bit shift code itself, but I need to know the structure of passable data in the map object, and any "gotcha"s with replacing/storing that in global values.  Plus any other data from dataMap.data that is needed to "reconstruct" them from scratch.


Edit: I'm just going with the more memory intensive rebuilding the map each time instead for now.  There's a lot of other features I still have to nail down, and it turns out the memory hit isn't that much since the generator itself won't be running.  It's still going to bother me forever why this didn't work though, the arrays appear to be perfect copies.  Oh well, moving on.


----


Full explanation below, it's not for the feint of heart though and dives deep into the map data.  Honestly, answers to the above would suffice, I include the below only to help people grasp what I need to do. 


Ok, so I have the following functions to get from $dataMap.data, and then set the same values in my own copy of it.


//get a tile as a tile array for dungeon building
dg_get_tile = function(x,y) {
var ret = new Array(6);
var width = $dataMap.width;
var height = $dataMap.height;
ret[0] = $dataMap.data[(0*height+y)*width+x];
ret[1] = $dataMap.data[(1*height+y)*width+x];
ret[2] = $dataMap.data[(2*height+y)*width+x];
ret[3] = $dataMap.data[(3*height+y)*width+x];
ret[4] = $dataMap.data[(4*height+y)*width+x];
ret[5] = $dataMap.data[(5*height+y)*width+x];
return ret;
}

//set map data on a rendered tile to a tile gotten with dg_get_tile
dg_set_rend_tile = function(x,y,dg_tile) {
var width = $dataMap.width;
var height = $dataMap.height;
dg_rendered_dungeon[(0*height+y)*width+x] = dg_tile[0];
dg_rendered_dungeon[(1*height+y)*width+x] = dg_tile[1];
dg_rendered_dungeon[(2*height+y)*width+x] = dg_tile[2];
dg_rendered_dungeon[(3*height+y)*width+x] = dg_tile[3];
dg_rendered_dungeon[(4*height+y)*width+x] = dg_tile[4];
dg_rendered_dungeon[(5*height+y)*width+x] = dg_tile[5];
}




Now, when the dungeon first generates, it makes a copy by using


dg_dungeon =  dataMap.data;


Then I mod the data by pasting my own tiles onto the copy dg_dungeon object, using some rules and a seperate global array I have for building "dungeon layouts".  Let's call this Method 1.


In Method 1, passables work fine and match the new map layout.  All I do is return my copy of the dataMap.data object (dg_dungeon), and everything works automagically.  The global dg_dungeon is a valid replacement return for the original dataMap.data return line.


Now when a menu or battle happens, I do things a tiny bit differently.


Instead of rebuilding a rendered out dungeon tileset onto the map, I just pass my previously generated copy  (The dg_dungeon global, which still exists in memory because it is a global attached to window).  Let's call this Method 2.


The expected outcome of Method 2 would be the same as the above, that is, the passables and everything else with the tile data would survive the transfer.  After all, the data "should" be the same, right?


Instead, with Method 2, all the passables are reset back to the original MV editor map passable flags instead, resulting in the player being stuck.  The super weird thing is that the tiles themselves LOOK correct, meaning all the rest of the visual data is still being set correctly.


(I've tested extensively, it's using the editor data original for passable data despite clearly using my visual data from the copy when Method 1 ran.  Once again, it's only the passables that are affected, the dungeon "looks" fine after coming back into the map from the menu.)


The only difference between the two is that in the second case, I just try to copy the data from the same global I was using before.


I've also tried it out for kicks, and if I "rebuild" the dungeon by doing Method 1 instead (just copying Method 1 but skipping the carve floor part to use the existing dungeon), the passables now work like the first method again.  Though this makes a LOT of slowdown on the menu/combat/events/ect since it's running the dungeon "renderer" every time the game needs to ask for the map data again.  Which is kind of what I was trying to avoid in the first place by making Method 2.


Obviously, I am missing some passable data from my copy of the tile data when recalling purely from the global.  Or something is being garbage collected or no longer exists on my copy of the data.  So the question is, what data did I miss?


(I don't think the dungeon itself is being garbage collected, since the second method still works visually, and also because if I check both globals I am using in the debugger they are still valid arrays matching the original generated dungeon tiles.)


I think tile data was just a 6 layer array using the lookup xyz formulas to find a single index in the array, since asking for a seventh z value resulted in undefined in my tile data objects returned from dg_get_tile().  So is the passable data elsewhere in gameMap.data?  Or perhaps there is a second part of data needed in my clone that gets lost once $gameMap.data reloads itself coming out of a menu?


I'll keep at it myself, but if someone has experience with passables I'd much appreciate any input.  I'm at a bit of a brick wall.  Running out of ideas what else could be missing from my virtual copy of gameMap.data and all that.
 
Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

This one is less showing off and more 'I really don't know how I feel about this one.' The 'child' sprite template I made either works great or doesn't at times. (She is a fairy, so I made her small).
Morgan.png
I am new to RPG maker MV, please be harsh with me :D
Shaz wrote on Tohtori_Jamba's profile.
Hi, you can post a thread for your game in the Completed Games forum. Please check the pinned thread there and make sure you provide all the requested information.
and_remember_tomorrow_more_redesigns_4.jpg

edit: The complete redesign of my player HUD, Time rewind message, mini map and puzzle map.... I'll toss up an animated version later. :LZSexcite:

Forum statistics

Threads
110,632
Messages
1,054,838
Members
143,759
Latest member
Alexis353
Top