Question

This is a very general question that's not related to a specific language. I'm having this array of int's:

int[100][100] map;

This contains just tile numbers, and is rendered as 256x256 tiles. So it's basically just a tile map or whatever it should be called. Thing is I want to be able to write anything to the map, anywhere, and it should stay there. For example be able to paint on stuff on the ground such as grass, flowers, stones and other stuff making the terrain more varied without having to render each of these sprites a huge number of times every time it renders. But making each tile contain it's own texture to write to would be terribly memory consuming at that would be 256x256x100x100 = 655360000 pixels to store. Would'nt that be like gigabytes of data or something!?

Does anyone know of a good general sulotion to make what I'm trying to do without killing too much memory?

If someone wonders I'm using C++ with HGE (Haaf's Game Engine).

EDIT: I've choosen to limit the amount of stuff on screen so that it can render. But look here so maybe you'll understand what I try to achieve: Link to image because I'm not allowed to use image tags :(

Was it helpful?

Solution

I'm not exactly sure what you are trying to do, but you should probably have the tiles in separate layers. So say that for each "tile" you have a list of textures ordered bottom-up that you blend together, that way you only store the tile indexes.

OTHER TIPS

If it's just tile based then you only store one instance of each unique tile and each unique "overlay" (flower, rock, etc.). You reference it by id or memory location as you have been doing.

You'd simply store a location (tile number and location on tile) and a reference to an overlay to "paint" it without consuming a lot of memory.

Also, I'm sure you know this but you only render what's on screen. So memory usage is pretty much constant once everything is loaded up.

Instead of storing just the tile number, store the overlay number and offset position also.

struct map_zone {
    int tile; // tile number
    int overlay; // overlay number (flower, rock, etc). In most cases will be zero
    int overlay_offset_x; // draw overlay at X pixels across from left
    int overlay_offset_y; // draw overlay at Y pixels down from top
}

map_zone[100][100] map;

And for rendering:

int x, y;
for(y = 0; y < 100; ++y) {
    for(x = 0; x < 100; ++x) {
        render_tile(map[y][x].tile)
        render_overlay(map[y][x].overlay, map[y][x].overlay_offset_x, map[y][x].overlay_offset_y);
    }
}

It's arguably faster to store the overlays and offsets in separate arrays from the tiles, but having each area on the map self-contained like this is easier to understand.

you have to use alpha maps..

you are going to paint a texture 256x256 which maps your whole terrain. for each channel r,g,b,a you will tile your terrain with your another texture..

r = sand.jpg g = grass.jpg b = water.jpg a = soil.jpg

in shader, you will check the color of alpha map and paint with these textures..

i am doing such a thing now and i did like that

alt text

alt text

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top