Chaos Project

Featured Projects => Tasks => Advanced RPG Creator => Finished Tasks => Topic started by: Blizzard on March 27, 2011, 07:44:52 am

Title: [Finished] [RGSS] Tilemap Data
Post by: Blizzard on March 27, 2011, 07:44:52 am
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 [].
Title: Re: Tilemap Data
Post by: Ryex on April 01, 2011, 05:25:53 pm
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
Title: Re: Tilemap Data
Post by: Blizzard on April 01, 2011, 05:27:45 pm
I was hoping you'd say that. Edit my post and assign yourself to this task.
Title: Re: Tilemap Data
Post by: Ryex on April 01, 2011, 06:54:28 pm
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.
Title: Re: Tilemap Data
Post by: ForeverZer0 on April 01, 2011, 07:27:49 pm
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.
Title: Re: Tilemap Data
Post by: Ryex on April 01, 2011, 07:36:57 pm
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?
Title: Re: Tilemap Data
Post by: Blizzard on April 02, 2011, 05:00:23 am
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.