Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Grabber With Allegro 5?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Grabber With Allegro 5?
AceBlkwell
Member #13,038
July 2011
avatar

All,

Is it possible to use Grabber files with Allegro 5? From what I'm reading, the answer is no. It looks like zip files and multiple commands for interfile locations etc. I was just hoping I was misunderstanding.

Thanks.

DanielH
Member #934
January 2001
avatar

No grabber/datafile system. I'm working on my own that loads a void pointer array similar to allegro 4 datafile. It uses an text file index.

#SelectExpand
1datafile 2{ 3 $header = "D" 4 $base_path = "$(system.directory)/$(index.directory)" 5 6 bitmap 7 { 8 $path = "$(base_path)/images" 9 $header = "BITMAP" 10 logo 11 { 12 file = "$(bitmap.path)/logo.bmp" 13 masked = true 14 } 15 icon 16 { 17 file = "$(bitmap.path)/icon.png" 18 masked = true 19 } 20 icon_sheet 21 { 22 file = "$(bitmap.path)/icon_sheet.png" 23 masked = true 24 } 25 monster 26 { 27 $path = "$(bitmap.path)/Monsters and animals" 28 file = "$(bitmap.monster.path)/*.png" 29 masked = true 30 sort = true 31 } 32 } 33}

The tags with $name are variables accessed as $(name).

Specify path & file name. If it needs alpha mask fix. Supports wildcards. I am still tweaking it and only have bitmaps supported. It has option to save a header file as well with indexing. That is important if end result is a void* array.

The above index outputs this header file

#SelectExpand
1/* */ 2/* */ 3/* Date: 10:22:19 p.m. 9/27/2023 */ 4/* Do not hand edit! */ 5 6constexpr auto D_BITMAP_LOGO = 0; /* BITMAP */ 7constexpr auto D_BITMAP_ICON_SHEET = 1; /* BITMAP */ 8constexpr auto D_BITMAP_ICON = 2; /* BITMAP */ 9constexpr auto D_BITMAP_MONSTER0000 = 3; /* BITMAP */ 10constexpr auto D_BITMAP_MONSTER0001 = 4; /* BITMAP */ 11constexpr auto D_BITMAP_MONSTER0002 = 5; /* BITMAP */ 12constexpr auto D_BITMAP_MONSTER0003 = 6; /* BITMAP */ 13constexpr auto D_BITMAP_MONSTER0004 = 7; /* BITMAP */ 14constexpr auto D_BITMAP_MONSTER0005 = 8; /* BITMAP */ 15constexpr auto D_BITMAP_MONSTER0006 = 9; /* BITMAP */ 16constexpr auto D_BITMAP_MONSTER0007 = 10; /* BITMAP */ 17constexpr auto D_BITMAP_MONSTER0008 = 11; /* BITMAP */ 18constexpr auto D_BITMAP_MONSTER0009 = 12; /* BITMAP */ 19constexpr auto D_BITMAP_MONSTER0010 = 13; /* BITMAP */ 20constexpr auto D_BITMAP_MONSTER0011 = 14; /* BITMAP */ 21constexpr auto D_BITMAP_MONSTER0012 = 15; /* BITMAP */ 22constexpr auto D_BITMAP_MONSTER0013 = 16; /* BITMAP */ 23constexpr auto D_BITMAP_MONSTER0014 = 17; /* BITMAP */ 24constexpr auto D_BITMAP_MONSTER0015 = 18; /* BITMAP */ 25constexpr auto D_BITMAP_MONSTER0016 = 19; /* BITMAP */ 26constexpr auto D_BITMAP_MONSTER0017 = 20; /* BITMAP */ 27constexpr auto D_BITMAP_MONSTER0018 = 21; /* BITMAP */ 28constexpr auto D_BITMAP_MONSTER0019 = 22; /* BITMAP */ 29constexpr auto D_BITMAP_MONSTER0020 = 23; /* BITMAP */ 30constexpr auto D_BITMAP_MONSTER0021 = 24; /* BITMAP */ 31constexpr auto D_BITMAP_MONSTER0022 = 25; /* BITMAP */ 32constexpr auto D_BITMAP_MONSTER0023 = 26; /* BITMAP */ 33constexpr auto D_BITMAP_MONSTER0024 = 27; /* BITMAP */ 34constexpr auto D_BITMAP_MONSTER0025 = 28; /* BITMAP */ 35constexpr auto D_BITMAP_MONSTER0026 = 29; /* BITMAP */ 36constexpr auto D_BITMAP_MONSTER0027 = 30; /* BITMAP */ 37constexpr auto D_BITMAP_MONSTER0028 = 31; /* BITMAP */ 38constexpr auto D_BITMAP_MONSTER0029 = 32; /* BITMAP */ 39constexpr auto D_BITMAP_MONSTER0030 = 33; /* BITMAP */ 40constexpr auto D_BITMAP_MONSTER0031 = 34; /* BITMAP */ 41constexpr auto D_BITMAP_MONSTER0032 = 35; /* BITMAP */ 42constexpr auto D_BITMAP_MONSTER0033 = 36; /* BITMAP */ 43constexpr auto D_BITMAP_MONSTER0034 = 37; /* BITMAP */ 44constexpr auto D_BITMAP_MONSTER0035 = 38; /* BITMAP */ 45constexpr auto D_BITMAP_MONSTER0036 = 39; /* BITMAP */ 46constexpr auto D_BITMAP_MONSTER0037 = 40; /* BITMAP */ 47constexpr auto D_BITMAP_MONSTER0038 = 41; /* BITMAP */ 48constexpr auto D_BITMAP_MONSTER0039 = 42; /* BITMAP */ 49constexpr auto D_BITMAP_MONSTER0040 = 43; /* BITMAP */ 50constexpr auto D_BITMAP_MONSTER0041 = 44; /* BITMAP */ 51constexpr auto D_BITMAP_MONSTER0042 = 45; /* BITMAP */ 52constexpr auto D_BITMAP_MONSTER0043 = 46; /* BITMAP */ 53constexpr auto D_BITMAP_MONSTER0044 = 47; /* BITMAP */ 54constexpr auto D_BITMAP_MONSTER0045 = 48; /* BITMAP */ 55constexpr auto D_BITMAP_MONSTER0046 = 49; /* BITMAP */ 56constexpr auto D_BITMAP_MONSTER0047 = 50; /* BITMAP */ 57constexpr auto D_BITMAP_MONSTER0048 = 51; /* BITMAP */ 58constexpr auto D_BITMAP_MONSTER0049 = 52; /* BITMAP */ 59constexpr auto D_BITMAP_MONSTER0050 = 53; /* BITMAP */ 60constexpr auto D_BITMAP_MONSTER0051 = 54; /* BITMAP */ 61constexpr auto D_BITMAP_MONSTER0052 = 55; /* BITMAP */ 62constexpr auto D_BITMAP_MONSTER0053 = 56; /* BITMAP */ 63constexpr auto D_BITMAP_MONSTER0054 = 57; /* BITMAP */ 64constexpr auto D_BITMAP_MONSTER0055 = 58; /* BITMAP */ 65constexpr auto D_BITMAP_MONSTER0056 = 59; /* BITMAP */ 66constexpr auto D_BITMAP_MONSTER0057 = 60; /* BITMAP */

Also, it's C++ not C.

Once it's all tweaked, I'm going to work it so that loads directly from a zip file. One convenient package.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

That looks like a good way to deal with it. What are your internals like?

In my FileSystem I can load a manuscript with simple lines like this :

mouse = mysha.png
cat = garfield.jpg
meow = meow.ogg
eek = eek.ogg
music = backgroundmusic.ogg

and it will load them all and make them available under the shortcut names.

Simple enough for my needs and supports zip files transparently as if they were a folder :

archive = Data/data.7z
music = Data/data.7z/music.ogg

Sadly it still involves a cast from a base* or a void* at some point. Can't be avoided completely.

AceBlkwell
Member #13,038
July 2011
avatar

Nice All. I wish I had your gray matter, I'd just write mine too. Meanwhile I'll just keep all the bitmaps, ttf, and WAV files in the folder with the executable. Works fine, just not as clean as I was hoping for.

Daniel, let me know when you have something to trial. I'd like to see how it works.

DanielH
Member #934
January 2001
avatar

loading

#SelectExpand
1// from init function 2std::cout << "Loading Datafile File: "; 3this->m_data_file = datafile::read("data\\datafile\\index.ini"); 4if (!m_data_file) 5{ 6 std::cout << "failed" << std::endl; 7 return wind::failure; 8} 9std::cout << "pass" << std::endl; 10 11 12// if you need the header file 13//if (!al_filename_exists("include\\datafile.h")) 14//{ 15 //datafile::write_header(this->m_data_file, "include\\datafile.h"); 16//}

destroying

//from kill/shutdown function
if (m_data_file)
{
  delete this->m_data_file;
  this->m_data_file = nullptr;
  std::cout << "Datafile Destroyed" << std::endl;
}

using

// draw function
ALLEGRO_BITMAP* logo = this->m_data_file->get<ALLEGRO_BITMAP*>(DATAFILE_BITMAP_LOGO);

al_draw_scaled_bitmap(logo,
  0.0f, 0.0f,
  (float*)al_get_bitmap_width(logo),
  (float*)al_get_bitmap_height(logo),
  0.0f, 0.0f,
  (float*)al_get_bitmap_width(this->m_buffer),
  (float*)al_get_bitmap_height(this->m_buffer), 0);

ALLEGRO_FONT* font = this->m_data_file->get<ALLEGRO_FONT*>(DATAFILE_FONT_MYSTICORA);
string_t* text = this->m_data_file->get<string_t*>(DATAFILE_TEXT_TITLE);
al_draw_text(font, color::map(0xffffff), 50, 200, 0, text->c_str());

If you're ambitious and realize I will probably update/modify the code in the future, you can check out my github repository.

EDIT: Modified what the code, so what I wrote here is not valid. You'll just have to check out the app that is in the repository that uses the library.

AceBlkwell
Member #13,038
July 2011
avatar

Daniel,

Forgive my ignorance. I get most of what is being done between the two post, but "datafile" is throwing me. It's not a struct or not a type I'm familiar with. It's not a function. Later you use it like a struct or class datafile::read etc. I'm just not understanding what is represents.

I understand the index (header file) and that is what indexs an array. I get that concept anyway.

In any case, is this the process you use or you creating as we speak? Thanks

DanielH
Member #934
January 2001
avatar

Are you knowledgeable on STL? Or maybe namespaces?

My naming convention might be confusing:
"datafile" is the name of the namespace
"datafile_t" is a class that wraps an std::vector<void*>

// how to open file and create datafile_t object
datafile_t* dfile = datafile::read(const string_t& filename);

// how to access the objects (pointers)
ALLEGRO_BITMAP* bitmap = (ALLEGRO_BITMAP*)(*dfile)[index];
ALLEGRO_BITMAP* bitmap = (ALLEGRO_BITMAP*)dfile->get(index);

Seems I didn't upload the latest also, I changed it so vector now wraps a std::shared_ptr<void>. However, it also removed ability to directly access the void* array. Object access is still the same.

// no longer valid
void** array_data = datafile_t::data();
ALLEGRO_BITMAP*bitmap = (ALLEGRO_BITMAP*)array_data[index];

Can't do that now that they are shared pointers.

AceBlkwell
Member #13,038
July 2011
avatar

Daniel, Namespace I should have recognized it. Now it makes more sense to me. Still a little over my head but I get the gist of it. Thanks for the detail.

DanielH
Member #934
January 2001
avatar

I am thinking about making a similar product, but much much simpler. Still uses the same text file processing, but the datafile itself is simple.

Header file will be something simple like this:

#SelectExpand
1typedef struct datafile_t 2{ 3 void* data; 4 int type; 5} datafile_t; 6 7// main load/destroy functions 8datafile_t* load_datafile(const char* filename); 9void destroy_datafile(datafile_t* datafile); 10 11// standalone function 12bool write_datafile_header(const char* filename); 13 14// type creation functions for custom types 15void register_object_type(int type, const char*name, void* (*parser)(), void* (*deleter)(void*));

load_datafile will return an array of datafile_t;

AceBlkwell
Member #13,038
July 2011
avatar

Daniel, I'm just trying to learn somethings here. If you get bored with the questions, you can drop out. Don't feel obligated.

Will load_datafile return an array or a pointer to the first element in an array. Probably the same thing but the latter would imply the array size is known.

Will this create a data file or read from it. If create, how do you write to a file with multiple types? If it reads from one, does it look for a EOF to determine when a file with in the overall file is complete?

Thanks.

DanielH
Member #934
January 2001
avatar

Will load_datafile return an array or a pointer to the first element in an array.

It would return an array. The last element's data pointing to null.

Quote:

Will this create a data file or read from it

The datafile array is the end product of parsing a text file. Do not confuse the two.

This does not function the same was as Allegro4's datafile loading. That was a complete file with all objects stored in it. Mine only reads a single text file in a folder that has other files and folders where assets are stored.

I wrote individual functions that parse each type.

#SelectExpand
1datafile 2{ 3 $base_path = "$(system.directory)/$(index.directory)" 4 5 bitmap 6 { 7 $path = "$(base_path)/images" 8 logo 9 { 10 file = "$(bitmap.path)/logo.bmp" 11 masked = true 12 } 13 icon 14 { 15 file = "$(bitmap.path)/icon.png" 16 masked = true 17 } 18 icon_sheet 19 { 20 file = "$(bitmap.path)/icon_sheet.png" 21 masked = true 22 } 23 #monster 24 #{ 25 #$path = "$(bitmap.path)/Monsters and animals" 26 #file = "$(bitmap.monster.path)/*.png" 27 #masked = true 28 #sort = true 29 #} 30 } 31 font 32 { 33 $path = "$(base_path)/fonts" 34 mysticora 35 { 36 file = "$(font.path)/mysticora.ttf" 37 38 #size in pixels 39 size = 20 40 #truetype (optional) 41 truetype = true 42 #flags (optional) 43 #flags = no_kerning|monochrome|no_premultified_alpha 44 } 45 } 46 text 47 { 48 title = The Great Escape! 49 } 50}

All I'm doing is writing some functions to simplify loading multiple files.

AceBlkwell
Member #13,038
July 2011
avatar

Thanks Daniel,

So if I'm understanding correctly. In short, you use a header to basically allow you to use easily understood names as an index for an array that holds various pictures and wav files. But the BMPs and WAV themselves are separate files in the programs folder or designated path?

My only concern (or preference) is the amount of files. Example, my last A4 game had 15+ BMPs between backgrounds, player pieces, game board pieces. Then couple that with 5 to 7 WAV files, not includeing 2-3 font files. Under A5 I would have 25+ files to be included with the game, where under A4 I have 2. Program file and grabber data file. Again, not a deal breaker where game function is concerned. It just increases the risk of a missing file or user manipulated file affecting game function.

DanielH
Member #934
January 2001
avatar

Put it all in a zip file and use PhysFS.

Option one: Open files
{"name":"613356","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/b\/fbccfce10e1c37d0267b1afeaf350d4e.png","w":248,"h":278,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/b\/fbccfce10e1c37d0267b1afeaf350d4e"}613356

Option two: zip file
{"name":"613357","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/a\/4a35a423e83698b3918ef8ee86867f46.png","w":249,"h":295,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/a\/4a35a423e83698b3918ef8ee86867f46"}613357

I plan on implementing option two. Eventually.

Yesterday, I started working on a standalone app that just outputs the header file. I kept changing thing and the header file would get corrupt, which would lead to errors in my app.

I also implemented nested datafiles. Don't know if needed, but older Grabber/Datafile had nested datafiles.

#SelectExpand
1# This is a comment 2main 3{ 4 $base_path = "$(system.directory)/$(index.directory)" 5 6 bitmap 7 { 8 $path = "$(base_path)/images" 9 logo 10 { 11 file = "$(bitmap.path)/logo.bmp" 12 masked = true 13 } 14 icon 15 { 16 file = "$(bitmap.path)/icon.png" 17 masked = true 18 } 19 icon_sheet 20 { 21 file = "$(bitmap.path)/icon_sheet.png" 22 masked = true 23 } 24 #monster 25 #{ 26 #$path = "$(bitmap.path)/Monsters and animals" 27 #file = "$(bitmap.monster.path)/*.png" 28 #masked = true 29 #sort = true 30 #} 31 } 32 font 33 { 34 $path = "$(base_path)/fonts" 35 mysticora 36 { 37 file = "$(font.path)/mysticora.ttf" 38 39 #size in pixels 40 size = 20 41 42 #truetype (optional) 43 truetype = true 44 45 #flags (optional) 46 #flags = no_kerning|monochrome|no_premultified_alpha 47 } 48 } 49 text 50 { 51 title = The Great Escape! 52 } 53 datafile 54 { 55 buster 56 { 57 text 58 { 59 title2 = The Mouseketeers! 60 } 61 } 62 } 63}

/* */
/* */
/* Date:  7:12:01 a.m. 10/08/2023 */ 
/* Do not hand edit! */

constexpr auto DATAFILE_TEXT_TITLE = 0;            /* TEXT */
constexpr auto DATAFILE_BITMAP_LOGO = 1;           /* BITMAP */
constexpr auto DATAFILE_BITMAP_ICON = 2;           /* BITMAP */
constexpr auto DATAFILE_BITMAP_ICON_SHEET = 3;     /* BITMAP */
constexpr auto DATAFILE_FONT_MYSTICORA = 4;        /* FONT */
constexpr auto DATAFILE_BUSTER = 5;                /* DATAFILE */
constexpr auto DATAFILE_BUSTER_TEXT_TITLE2 = 0;    /* TEXT */

AceBlkwell
Member #13,038
July 2011
avatar

Thanks Daniel. I browsed PhysFS. I think I get the skinny of it. I'd need to generate a test run program to understand exactly how it works.

DanielH
Member #934
January 2001
avatar

I do too. I haven't used PhysFS either. Working on other issues first. I'll get around to it.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

DanielH
Member #934
January 2001
avatar

Simplified things a bit. I messed with it last night. Thought I was done, but realized it's broken. It works as is as long as you don't use nested datafiles. Will fix that in a bit. It's a fairly simple fix.

also think about just making it it's own repository.

#SelectExpand
1#ifndef _WIND_DATAFILE_H_ 2#define _WIND_DATAFILE_H_ 3 4#include "w_base.h" 5 6namespace wind 7{ 8 typedef struct datafile_t 9 { 10 void* data; 11 int32_t type; 12 } datafile_t; 13 14 namespace datafile 15 { 16 enum element_type 17 { 18 bitmap, 19 font, 20 text, 21 datafile, 22 user_defined = 0x100 23 }; 24 25 namespace parser 26 { 27 typedef struct parse_data_t parse_data_t; 28 29 using deleter_t = void (*)(void*); 30 using parser_t = void* (*)(const parse_data_t& data); 31 32 deleter_t get_deleter(int32_t type); 33 bool has_children(const parse_data_t& data); 34 bool contains(const parse_data_t& data, const string_t& name); 35 parse_data_t get_child(parse_data_t& data, const string_t& name); 36 const parse_data_t get_child(const parse_data_t& data, const string_t& name); 37 bool has_content(const parse_data_t& data); 38 wind::string_t get_content_as_string(const parse_data_t& data); 39 int32_t get_content_as_integer(const parse_data_t& data); 40 double get_content_as_real(const parse_data_t& data); 41 bool get_content_as_boolean(const parse_data_t& data); 42 void register_object_type(int32_t type, const string_t& name, parser_t parser, deleter_t deleter); 43 } 44 45 datafile_t* load(const string_t& filename); 46 void destroy(datafile_t* datafile); 47 } 48} 49 50#endif // !_WIND_DATAFILE_H_

AceBlkwell
Member #13,038
July 2011
avatar

Daniel,
Looks more concise though I'm not sure I know what I'm looking at entirely.

Edgar,
I jumped on your site. I checked out Eagle. I downloaded the binaries and the program ran, however, I'm not sure what it does. I tried to pull up a bmp but it wouldn't do anything. In short, what is the programs purpose?

DanielH
Member #934
January 2001
avatar

If you don't care about adding custom types, then all you need is these two functions:

datafile_t* load(const string_t& filename);
void destroy(datafile_t* datafile);

It will parse your text file, load the assets, create an datafile_t array. The size of the array 1 more than the number of objects. The data value of the last argument is NULL. That's how you know it's the end of the array.

In your game, you can use as such

ALLEGRO_BITMAP* bitmap = (ALLEGRO_BITMAP*)datafile[index].data;

I tried to make the final product similar to Allegro 4's datafile. It's just the loading is different as it's not one file.

If you want custom objects, then you can register your own type with custom parse and deleter. the other functions are used to access the data from the text file. I hid the actual data inside parse_data_t to make it cleaner.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

AceBlkwell
Member #13,038
July 2011
avatar

Sorry Edgar, I meant no disrespect. I wasn't implying the program didn't work as intended, only that i didn't know what it ws supposed to do. The included picture is what I ran. I clicked on file and tried to open a BMP file but nothing happened.

Nice Daniel. Thanks for the update.

DanielH
Member #934
January 2001
avatar

Click "Formatting Help". However, there is an issue with attachments. You cannot use the link that is given right after it is attached. You have to submit/update post first and use the link from the post itself. A little annoying.

{"name":"613358","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/d\/0ddad389091e36509ce80cc844869e70.jpg","w":825,"h":658,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/d\/0ddad389091e36509ce80cc844869e70"}613358

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

AceBlkwell
Member #13,038
July 2011
avatar

Thanks Guys,

I've gotten the A5 version, but still don't know what to do or the purpose of the program. Meaning, Like Word is a word processing program, Doom is a game program, Eagle 5 is a ..... program. Is it a compression program, or a cooler version of a grabber type program?

When I click on the Upper left Upper right etc, nothing happens. I figure it's my ignorance more than the program. Just curious.

Daniel, I've worked with the Formatting Help- for images for 20 mins. I just keep getting a hyperlink to this entry for edit. In any case the picture seems to be working. It's just a snapshot of the Eagle 5 program.

{"name":"613361","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/5\/45b12507f1c3329bae11a2dbbe1612b1.jpg","w":791,"h":620,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/5\/45b12507f1c3329bae11a2dbbe1612b1"}613361

DanielH
Member #934
January 2001
avatar

{"name":"613362","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/8\/58a979be29f12e7989bec37a31556fb2.png","w":1030,"h":534,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/8\/58a979be29f12e7989bec37a31556fb2"}613362
Oops. I forgot the closing " at end of tag in picture

{"name":"613361","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/5\/45b12507f1c3329bae11a2dbbe1612b1.jpg","w":791,"h":620,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/5\/45b12507f1c3329bae11a2dbbe1612b1"}613361

As for Eagle, that is a GUI, and I'm sure Edgar can explain more.

 1   2 


Go to: