Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » ".dat" files? what, who, were and why?

This thread is locked; no one can reply to it. rss feed Print
".dat" files? what, who, were and why?
jaime barrachina
Member #6,780
January 2006
avatar

I've recently started whith C++ (and with programming, come to that) and everyday I find surprises, today, the winner is the ".dat" file. While cheking out the code to make a RPG's map I come to find that all the images and data concerning them are in a misterious file, sealed off from mortal eyes, called "data.dat".

So, what exactly is a .dat file? what does it do, how does it work, and how can I open and edit it? Plese escuse my incredibly basic question but as ignorance ain't a crime (yet) I think I'll do my best to put a remedy to it, if any of you can help me out, I'd be realy thankfull cause its really frustrating to go trught the page of code labeled map.cpp only to find lonelly drawing functions there (which come to it I still don't fully understand xD)

Cheers and thanks! ;)

"Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi"
"When all else fails, read the manual - Dad"

Arthur Kalliokoski
Second in Command
February 2005
avatar

You're talking about Allegro? If you've downloaded & installed it, check out the manuals in /allegro/docs/html or /allegro/docs/text etc. In the tools section there's a "grabber.exe" program that'll show you what's in the .dat files & import/export bitmaps, wave files, etc.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

ReyBrujo
Moderator
January 2001
avatar

It is basically a compressed file, like a tar.gz or a .zip. You can either load it all in memory, or load just chuncks as you need them. Check grabber.txt and datafile.txt somewhere in Allegro source to learn more about the technical details.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

jaime barrachina
Member #6,780
January 2006
avatar

Oks thanks people :)
(wow that was quick, 5 minutes since i posted O.O )

"Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi"
"When all else fails, read the manual - Dad"

Elverion
Member #6,239
September 2005
avatar

Like others have said, the .dat files are generally produced by grabber (in Allegro programs, anyways). This isn't always the case, though. the .dat extension could be used for virtually anything. Someone might want to serialize their classes out into a random-access .dat file (in short - a simple database), which is much different than a compressed file that could contain several medias.

--
SolarStrike Software - MicroMacro home - Automation software.

Johan Halmén
Member #1,550
September 2001

The Allegro dat files don't have to be compressed. If they aren't, they are there only to keep everything in as few file as possible. You could have your 100 sprites in 100 bmp files or in one dat file.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

jaime barrachina
Member #6,780
January 2006
avatar

Mmm, ive managed to open the file whith the grabber and it shows a kind of bunched up images compresed into a single drawing, pieces and bits of trees, fences, grass, ect. I supose the program somehow cuts the picture like if it were on a grid, how does it do that? Anyone could post a simple example of the code needed to slice my rectangular pizza? Txs a bunch people, i dont know wht i'd do whithout this forum (Rott in some forgoten room, surrounded by empty coke cans and pizza boxes i supose)

Cheers!!

"Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi"
"When all else fails, read the manual - Dad"

Kitty Cat
Member #2,815
October 2002
avatar

That's called a tileset. It's a single big image that holds many different tiles and/or sprites used for a specific area of a game. Typically, each tile/sprite is a fixed size (16x16 or 32x32 usually), so you just need to use create_sub_bitmap at 16 or 32 pixel intervals to grab each one.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Johan Halmén
Member #1,550
September 2001

Quote:

i dont know wht i'd do whithout this forum

You would be having a life. Like we would.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

gnolam
Member #2,030
March 2002
avatar

Johan Halmén said:

You would be having a life. Like we would.

And still you let your children in here? :)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

jaime barrachina
Member #6,780
January 2006
avatar

I supose xDDD

"Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi"
"When all else fails, read the manual - Dad"

DanielH
Member #934
January 2001
avatar

The following is an assumption:

You are looking at my datafile that I created. The bitmap itself is a complete set of tiles. There are simple ways of accessing which tile I need at any point. The bitmap is arranged as 256x1024 or 8x32 of 32x32 pixel tiles.

#define TILESIZE        32
#define SHIFT           5 // 2^SHIFT = TILESIZE
#define TILE_SET_WIDTH  8


void draw_tile( BITMAP *buffer, BITMAP *tiles, int p, int x, int y )
{
    int tx = ( p % TILE_SET_WIDTH ) << SHIFT;
    int ty = ( p / TILE_SET_WIDTH ) << SHIFT;

    blit( tiles, buffer, tx, ty, x, y, TILESIZE, TILESIZE );
}

Let's say that you want to draw the tile at 2 rows down and 4 from left at screen position 128x128. That would be tile ( 2 * TILE_SET_WIDTH ) + 4 = 20;

draw_tile( buffer, (BITMAP*)datafile[ BMP_TILES ].dat, 20, 128, 128 );

20 is broken down in the function as

tx = ( 20 % 8 ) << 5 = 128
ty = ( 20 / 8 ) << 5 = 64

So the section of the bitmap with be drawn like:

blit( tiles, buffer, 128, 64, 128, 128, 32, 32 );

Or for a grid

1#define SCREEN_GRID_WIDTH 20
2#define SCREEN_GRID_HEIGHT 15
3 
4void draw_map( BITMAP *buffer )
5{
6 for ( int j = 0; j < SCREEN_GRID_HEIGHT; j++ )
7 {
8 for ( int i = 0; i < SCREEN_GRID_WIDTH; i++ )
9 {
10 int p = get_from_map( i, j );
11 
12 draw_tile( buffer, (BITMAP*)datafile[ BMP_TILES ].dat, p, i << SHIFT, j << SHIFT );
13 }
14 }
15}

POINT

If you need to do special things to the tiles such as transparency, translucency, etc. This will not be possible. You would then need to separate the entire tile bitmap into 256 bitmaps. This can be done easily enough in the grabber program.

1. Read in a bitmap
2. Grab from Grid
3. Set the tile size you need
4. Enter the name such as TILES

You will end up with 256 tiles named TILES000 to TILES255

Or you could do it yourself in a function

1BITMAP *tiles[ 256 ];
2 
3int tilefy( BITMAP *bitmap )
4{
5 for ( int i = 0; i < 256; i++ )
6 {
7 if ( tiles[ i ] )
8 {
9 destroy_bitmap( tiles[ i ] );
10 tiles[ i ] = NULL;
11 }
12 
13 tiles[ i ] = create_bitmap( TILESIZE, TILESIZE );
14 if ( !tiles[ i ] )
15 {
16 return -1;
17 }
18 
19 blit( bitmap, tiles[ i ], ( i % TILE_SET_WIDTH ) << SHIFT, ( i / TILE_SET_WIDTH ) << SHIFT, 0, 0, TILESIZE, TILESIZE );
20 
21 }
22 
23 return 0;
24}

jaime barrachina
Member #6,780
January 2006
avatar

TXS for all the replies!! I'll try and see if anithing comes out xD
Cheers and txs again!!

"Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi"
"When all else fails, read the manual - Dad"

Go to: