[Finished] [RGSS] Tilemap Data

Started by Blizzard, March 27, 2011, 07:44:52 am

Previous topic - Next topic

Blizzard

March 27, 2011, 07:44:52 am Last Edit: September 10, 2011, 03:26:47 am by Blizzard
Tilemap Data




Description

Tilemap is one of the nasty classes. The general problem spreads across properly representing the tilemap as well as all the data and calculations that need to be done. It's nuts.
The purpose of this task is to find, gather and type down all the data for Tilemap. What are the coordinate calculations for the tiles, how are autotiles composed, etc. We need this data before we can implement this class.



Priority

High.



Prerequisites

None.



Assigned

Ryex



Everything else

How you solve this task is up to you. There are existing implementations of Tilemap in Ruby so that should make this task a lot easier. Instead of a lot of thinking and calculation, it becomes a task to just gather the data and type it down into valid C++ code. Type the data down as you like it, we will decide on a proper format later. I suggest you use Tilemap::init for the data so you don't have to define a bunch of static const variables or even make arrays with new [].
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

the funny thing is that a lot of this has already bee done by me in my work on rmpy. I'll start collecting it together
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

I was hoping you'd say that. Edit my post and assign yourself to this task.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

Tile Ids

every tile set has at least 8*48=384 tile ids. the first 48 from 0-47 are reserved for the in built blank tile the next 336 ids are for the 7 autotiles in each tileset. 48-95 = first autotile, 96-143 = second, 144-191=third, 192-239=forth, 240-287=fifth, 288-355=sixth, 356-383=seventh. starting at id 384 the normal tiles in the tile set image begin. ie the first row is 384-391.



Autotiles

Autotiles are split apart into 32*32 tiles and each tiles is split apart into 16*16 squares. these 16* 16 squares are combined in different combinations to create 48 different tiles. each combination is identified by a different id.

This array is uses to put together these combinations. each position in the array

Autotiles = [
                [[27, 28, 33, 34], [5, 28, 33, 34], [27, 6, 33, 34],
                 [5, 6, 33, 34], [27, 28, 33, 12], [5, 28, 33, 12],
                 [27, 6, 33, 12], [5, 6, 33, 12] ],
                [[27, 28, 11, 34], [5, 28, 11, 34], [27, 6, 11, 34],
                 [5, 6, 11, 34], [27, 28, 11, 12], [5, 28, 11, 12],
                 [27, 6, 11, 12], [5, 6, 11, 12] ],
                [[25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12],
                 [25, 6, 31, 12], [15, 16, 21, 22], [15, 16, 21, 12],
                 [15, 16, 11, 22], [15, 16, 11, 12] ],
                [[29, 30, 35, 36], [29, 30, 11, 36], [5, 30, 35, 36],
                 [5, 30, 11, 36], [39, 40, 45, 46], [5, 40, 45, 46],
                 [39, 6, 45, 46], [5, 6, 45, 46] ],
                [[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20],
                 [13, 14, 19, 12], [17, 18, 23, 24], [17, 18, 11, 24],
                 [41, 42, 47, 48], [5, 42, 47, 48] ],
                [[37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24],
                 [13, 14, 43, 44], [37, 42, 43, 48], [17, 18, 47, 48],
                 [13, 18, 43, 48], [1, 2, 7, 8] ]
                ]


if the id of the tile is less than 384 then we know that the tile is some combination of an autotile.
index = (id / 48) - 1

gives us the index of the autotile 0 being the first of the left and 6 being the last on the right
we can get the pattern of the auto tile like so
 pattern =id % 48

this will give us a number 0-47
from there we can get a list of the 16*16 squares that we need to combine be pulling them from the array above like so
list = AUTOTILES[pattern / 8][pattern % 8]

then the 32*32 tile is constructed like so

autotile = RPG::Cache.autotile(autotile_name)
bitmap = Bitmap.new(32, 32)
(4).times do |i|
  position = list[i] - 1
  src_rect = Rect.new(position % 6 * 16, position / 6 * 16, 16, 16)
  bitmap.blit(i % 2 * 16, i / 2 * 16, autotile, src_rect)
end

bitmap is now a 32*32 tile with the proper pattern on it



Normal Tiles


to obtain a normal 32*32 tile from the tileset bitmap is fairly simple

bitmap = Bitmap.new(32, 32)
x = (id - 384) % 8 * 32
y = (id - 384) / 8 * 32
src_rect = Rect.new(x, y, 32, 32)
tileset = RPG::Cache.tileset(tileset_name)
bitmap.blit(0, 0, tileset, src_rect)


and now bitmap is a 32*32 tile from the tileset.




I've collected the data here. I'm not sure how we are going to do this yet though.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

This is how RMXP does it, which does work (I did just this in my Custom Resolution script), but I am not sure how it will work with the new proposed way of making tilemaps, nor making a user-defined number of autotiles for each map.

I would say that it would be better to store autotile data in its own object, and not include it with the normal tilemap data. We can make it so that the first tile starts at 1 and go from there. Autotiles will be handled on their own, that way any changes made to the number of autotiles for the map will not effect all the IDs that come after it. Maybe use an ID of 0 when building the map, which can be a flag telling the system to use an autotile for this square. Or us an 2 element array, one to reference the autotile index, and another to represent the autotile's configuration.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

this is just for the RGSS library as I understand it. so perhaps this isn't the best place to discuss this but I agree the more we can separate the autotiles the better
perhaps autotiles can use negative numbers?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

April 02, 2011, 05:00:23 am #6 Last Edit: April 02, 2011, 06:30:38 am by Blizzard
What Ryex said, this is the RGSS tilemap.
Yeah, negative tiles might work. We will discuss these things in detail after the RGSS library has been finished.

EDIT: I have added and committed the autotile data.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.