![]() |
|
HOW TO LOAD DATA FILE OBJECT...!!!!!!!! |
tibgamer
Member #6,859
February 2006
![]() |
HI fellaws.. I am new to the data file concept...so..I wrote the below code in C to load a datafile containing only one object called "image0.bmp". It get compiled fine without error but during the runtime..it shows window error and couldn't able to load the dat file..help me out please... I have three files namely: main.c, grab_exp.h, and input.h =================================================================================== #include <stdio.h> int main(int argc, char *argv[]) data_object = load_datafile_object ("grab_exp.dat", "image0"); if (!data_object) { =================================================================================== /* Allegro datafile object indexes, produced by grabber v4.0.3, MinGW32 */ #define image0 0 /* BMP */ =================================================================================== extern DATAFILE *data_object; =================================================================================== So...actually what I want to do is to...load one object of datafile...I had thoroughly went through both vivace examples and allegro examples..still i couldn't able to load dat file...help needed in any form and in any way... PEACE software is not written, it is rewritten |
Thomas Fjellstrom
Member #476
June 2000
![]() |
You have a small error, the datafile code, in this case, the load_datafile_object creates the bitmap for you. There is no need to create_bitmap the bmp variable before hand, and leads to your actuall error, the destroy_bitmap (Freeing the bmp pointer twice), just use unload_datafile_object and you'll be fine. -- |
Corelian
Member #3,376
March 2003
![]() |
What Tomasu said, plus there are some errors and unnecessary lines. These includes are useless: You don't need the input.h file. You need to set gfx mode to display graphics! Quote:
if (!data_object) { The return here should return a numeric value, because it terminates the program's main function. E.g. return 1; It would be a good idea to e.g. wait for a key press before ending the program. Otherwise it'll execute in a fraction of a second. Calling allegro_exit() is unnecessary. |
BAF
Member #2,981
December 2002
![]() |
And please put [code] and [/code] tags around your code. |
tibgamer
Member #6,859
February 2006
![]() |
hi guys...as you had pointed out the errors..i had made the required changes...but still its not showing the dat object...whats wrong this time..help... <CODE> #include <allegro.h> int main(int argc, char *argv[]) blit(data_object, screen, 0, 0, 0, 0, 30, 30); </CODE> software is not written, it is rewritten |
Corelian
Member #3,376
March 2003
![]() |
Quote: blit(data_object, screen, 0, 0, 0, 0, 30, 30); Completely off the top of my head, but shouldn't it be data_object->dat there? Read the Allegro manual pages about datafiles. They contain plenty of examples. Use [ and ] for those code tags. To see the available tags, click the "[url http://www.allegro.cc/mockup.html] |
tibgamer
Member #6,859
February 2006
![]() |
[quote ]shouldn't it be data_object->dat well..i am new to allegro..so thats why am making lots of mistake..anway..i read the manual..and it says that struct DATAFILE consist: void *dat; - pointer to the actual data software is not written, it is rewritten |
Tobias Dammers
Member #2,604
August 2002
![]() |
Here's how it works. A DATAFILE object holds information about a single datafile record. Not only the actual object data, but also its size, what kind of object it is, its name, original filename, and a few more properties.
Also, make sure that: --- |
umperio
Member #3,474
April 2003
![]() |
This works perfectly here, if you don't want to look at the manual or at the examples please at least listen to others suggestions. If it's not working, please describe exactly in which way is not working, assuming you didn't create a corrupted datafile. |
tibgamer
Member #6,859
February 2006
![]() |
hi all the guys above... now..i am getting really cleared up..about the datafile concept..thanx a lot..now i could able to load one object of datafile on to the screen..,,now..i am trying to load more than one object onto the screen, i.e i had added one more object called "image1" in my dat file..and could successfully able to load it...though i have doubt like..there could be better way to load more than one object by using kinda arrays or stuff like that..so could you suggest any better way than the below codes....thanks a lot again...:-) PEACEEEE
software is not written, it is rewritten |
CursedTyrant
Member #7,080
April 2006
![]() |
Why don't you use a for loop for loading the objects? It should work fine. I remember doing this a very different way, but unfortunately I don't have the time now to check and post my code here. I might be able to do that later when I'm back home. --------- |
Tobias Dammers
Member #2,604
August 2002
![]() |
That's exactly what load_datafile() is for. Instead of painstakingly loading individual objects and managing memory for them, you can load an entire datafile into memory. RTFM to see what I mean. The basic idea is this: DATAFILE* data; allegro_init() // etc.; set up allegro nicely data = load_datafile("data.dat"); 5. data now contains an array of DATAFILE objects, and the header you included gives you handy defines to access them directly and with virtually no performance overhead, like this: // assuming you have loaded the datafile, and there is an image called "image1.bmp" in it: draw_sprite(screen, (BITMAP*)data[IMAGE1_BMP]->dat, 100, 100); And at the end of your program, you should free the memory allocated by the datafile array by calling: unload_datafile(data);
--- |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: That's exactly what load_datafile() is for. Instead of painstakingly loading individual objects and managing memory for them, you can load an entire datafile into memory.
Which is a horrible idea if you're only going to need a small portion of the datafile loaded into memory at any given time. Not wasting memory is A Good Thing(tm) -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
Not over-complicating code is also a Good Thing. A typical newbie game is small, so small that the amount of data in memory is a non-issue. Loading datafile objects one by one requires you to keep track of each one individually, and every time you add an object to the datafile, you need to change the loading code. This creates a lot of opportunities for nasty bugs and memory leaks - not exactly what a beginning programmer is waiting for. --- |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: Loading datafile objects one by one requires you to keep track of each one individually, and every time you add an object to the datafile, you need to change the loading code.
No you don't. -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
Of course this is absolutely true. On the other hand, one typically loads the objects in one part of the program (initialization), while using them in another part (main loop, or even entity member func). If these parts are in different files, things get hackish. If they aren't, you just use indices into the global sprite list; if you try to use something that's not there, the compiler will throw it in your face. To be safe, you can set up your compile process to create the header every time, or use find_datafile_object(). --- |
tibgamer
Member #6,859
February 2006
![]() |
hi guys... now..i am trying to add SAMPLE file in my dat file..but i couldn't able to play it through dat file..though i could play it separately like below...tell me how to load the SAMPLE file called "frog" from dat file and play it from dat file....
software is not written, it is rewritten |
HoHo
Member #4,534
April 2004
![]() |
You should use it just the same as bitmap objects: DATAFILE *music_object; music_object = load_sample("Frog.wav"); play_sample((SAMPLE*)music_object->dat, 300, 128, 1000, TRUE); Of course you could wrap some stuff around loading datafile to get the pointers to the dat fields when loading files. I once did a very cleaver datafile loading class for my Xcom engine. All it needed was the datafile name and a text file describing the tile layers. When I loaded the file everything else worked automagically [edit] oops, I think I made a mistake. I have never used sounds in Allegro and I didn't notice that load_sample returs sample directly. That code should work if you replace the load_sample with load_datafile_object. Also, it seems like load_sample loads stuff frome external files, not from datafiles. If you would check the return values I'm sure you would have an error in the load_sample function. __________ |
umperio
Member #3,474
April 2003
![]() |
Quote: tell me how to load the SAMPLE file called "frog" from dat file and play it from dat file.... ...please Since it seems to me you're still learning, I'd go for a complete datafile instead of loading all the objects separately.
Here I used the file running.dat from the allegro examples. Did you ever take a look at them? |
BAF
Member #2,981
December 2002
![]() |
You can always do load_bitmap("datafile.dat#bitmapname") too. |
tibgamer
Member #6,859
February 2006
![]() |
Quote: it seems to me you're still learning yes..i have just started out with allegro..and i have been going through the vivace tutorial..for a week or so....thats why am making lots of errors..anway..thanx for helping me out...i have been learning a lot from this forum.... oh..yes..now i could able to play SAMPLE file from dat file..Could any one tell me how to create header file index of objects from grabber..i tried going to Object menu and click export...but couldn't able to make header file...help me...! software is not written, it is rewritten |
umperio
Member #3,474
April 2003
![]() |
Why don't you read how to do it? Quote:
=========================================== Various options can be set using the buttons and text fields at the top of Regards |
Tobias Dammers
Member #2,604
August 2002
![]() |
My, umperio, that's a mighty friendly RTFM, I say. --- |
tibgamer
Member #6,859
February 2006
![]() |
thanks..i will check out...! software is not written, it is rewritten |
|