#### Archived

This topic is now archived and is closed to further replies.

# Allegro .dat files...

This topic is 6364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all, I was just wondering... i've been trying to use allegro's datafiles in my latest game, but the trouble is they only seem to work in C, and i'm coding in C++, classes and all... I really need to use the datafiles, i've got it all set up ok (the .dat file and loading routines are fine), but when I try and compile it (with djgpp), i get the error: ANSI C++ forbids implicit conversion from 'void*' in argument passing So, i tried casting all the files, to BITMAP*, SAMPLE* etc, (that seemed incredibely ambitious to me ) and it compiles, but when i run the program it immediately crashes with all sorts of 'signal errors'... Basically then, can I use the Allegro datafile system in c++? Cheers, Nick - Head Designer, Llamasoft.net -- Visit our website... Llamasoft.net Games, goodies and ingenuity Edited by - Llamasoft.net on 7/13/00 2:24:15 PM

##### Share on other sites
The datafiles should work with DJGPP C++... You're doing it the right way (casting the void pointers). Maybe it's not the casting that's the problem? Can you post some of the code where you use the datafiles? Maybe you're loading them the wrong way? Do you check the return value of load_datafile() (lots of questions )?

- Muzzafarath

The Field Marshals

Edited by - Muzzafarath on July 13, 2000 4:19:38 PM

##### Share on other sites
Muzzy to the rescue again, eh?
Ok, instead of posting some of my code, I wrote a quick simple program that should get 320*240, wait for a key press, load the bitmap from the datafile, wait again, then quit...
The code is this:

  #include #include #include "allegro.h"#include "fileindex.h" //This is where the #defines the grabber made are...int main(){ DATAFILE *data; PALLETE main_pallete; allegro_init(); install_keyboard(); data = load_datafile("shooting.dat"); if (!data) //Did it screw up? { printf("Uh oh!"); allegro_exit(); return 0; }//Dunno if that would work, don't usually do much error checking yet set_gfx_mode(GFX_AUTODETECT, 320, 240, 0, 0); set_pallete(main_pallete); readkey(); //just wait so we can decide when to blit the bitmap... blit((BITMAP*)data[WELCOME].dat, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); readkey(); unload_datafile(data); return 0;}

Ok, this seems to work, to some extent (so i'll go back through my code and make sure it's all the same). Now a new problem (and one that I always thought might occur...), the pallete for the bitmap is wrong . As you told me in another post (cheers again ) when we load a bitmap, we must give it a pallete too... i've got all that fine now, and normally make all my .bmps use one pallete... the trouble using the datafile seems to be that when we load the datafile (and, subsequently the bitmaps, sounds, etc in it), we can't give the bitmaps a pallete, if you see what I mean . So, I assume we give the bitmaps in the .dat a pallete when we make the .dat file... enter question 2: How?

--

Llamasoft.net
Games, goodies and ingenuity

Edited by - Llamasoft.net on July 13, 2000 4:56:58 PM

Edited by - Llamasoft.net on July 13, 2000 4:57:51 PM

##### Share on other sites
When you are creating the .dat file, one of the data types you can import to it is a palette. Just create a pal in the .dat dile and then you can select the bitmap from which to get the pal from. Then when you program your game, use the pal from the .dat file to set the palette.

You muse IMPLICITLY cast your data from the data files to the correct form like you did in your example program you posted.

blit((BITMAP*)data[WELCOME].dat, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

if you leave off the BITMAP* it wont compile.

You must ALWAYS ALWAYS ALWAYS error check your programs. If you dont then that is the sure fire way to have alot of things go wrong.

"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

##### Share on other sites
Cheers ncsu121978, I thought it might be something simple like that
And yeah, I do get around to error checking in my programs, but i''m fairly new to c++ and prefer to just get something on screen before I do... and since i''ve never used datafiles before, I didn''t know how to check if it had failed or not, thassal

--

Llamasoft.net
Games, goodies and ingenuity

##### Share on other sites
ncsu is right. You can import the palette into the datafile as a "palette" object and then just set_palette((PALETTE)data[PAL].dat). Or maybe it was set_palette((RGB*)data[PAL].dat)?

>> Muzzy to the rescue again, eh? <<

- Muzzafarath

The Field Marshals

Edited by - Muzzafarath on July 14, 2000 6:51:04 AM

##### Share on other sites
also, instead of calling, unload_datafile, you can just call, allegro_exit() and it unloads, un-installs anything that you have installed.

JoeMont001@aol.com www.polarisoft.n3.net

##### Share on other sites

Btw, you don't have to call allegro_exit() either, Allegro installs it as an atexit() thingy so it will be called automatically when main() returns (or when exit() is called).

Edited by - Muzzafarath on July 14, 2000 12:22:54 PM

• ### Forum Statistics

• Total Topics
628722
• Total Posts
2984397

• 25
• 11
• 10
• 16
• 14