Loading objects from not an ini file. hint: sqlite

edited May 2010 in Help request
I'm sorry if this is covered in some topic somewhere. I was unable to find it in a few searches, but I'm rather sleep deprived so I may not have been searching at optimum efficiency:P

I am wanting to port my alpha version game project from Allegro to Orx2D. All the game data is stored in an sqlite3 database. Bitmaps, powers, items, stuff and more stuff. Its a roguelike, so, you know, buncha tables for random generation of things.

So the question is -- Is it possible to load things directly into Orx at runtime? Can I just build the objects as needed from serialized data, or does it all have to be in a single file upon init?

I realize I could write a routine to build an ini file with the salient data before Init(), but that would be bothersome and clunky and lack elegance.

tl;dr

Is there a way to build an object from arguments passed from code rather than from files?

Comments

  • edited May 2010
    Hello Neocognitron, welcome to the forums.

    I'm not an expert, but I think it's certainly possible to build all your objects at runtime, this is what the config files are already used for after all.
    I'd recommend taking a look at how the current object building code does it, orxConfig.c ( salient code starts at roughly line 2300). You're likely going to have to re-implement some of this function in order to handle your database instead of reading in from the ini files, but most of the basic object loading functionality should be easily reused.

    I believe there was talk a while back about changing this code to a plugin style (similar to everything else) to make such implementations easier, but I may just be imagining it. :P

    If you've any further questions, feel fee to ask. Iarwain drops in quite often and tries to answer every question it seems, so I'm sure you'll get something from him soon.

    Anyway, good luck, and once again; Welcome!

    edit: orxConfig_Load is the function I pointed out earlier, starts on line 2240. :)
  • edited May 2010
    To address another part of your question, your data can absolutely be split into many files. If you take a look at my tutorials (link at the bottom of my post) I make a point of loading up separate parts of my scenes using different files. As far as I'm aware, the only initialization that needs to happen at startup, are things like setting up the viewport, camera and various subsystems you'll use (physics et al).

    You can simply use orxConfig_Load(newfile) whenever you want new data, or in the case that you implement your own loader for your database, you'd obviously call your own version of that function.
  • edited May 2010
    Thanks for the response and also for the welcome. I'll look through the tutorials you suggested. I will also look at the object building code, thanks for the reference line.

    It would be difficult to make a single function for loading from the db. I'll have to do some serious thought about implementation for this. Right now it takes 4 tables to build the hero, 5 to build an item, 3 for a monster etc. Its not excessive, I swear! B)

    hmm, I'll just overload it to take a function pointer. The function it points to will return a properly formatted whatsit.

    Might take some work . . . oh right . . . finals. Yeah, maybe after the stupid finals are done. Stupid finals.
  • edited May 2010
    Neocognitron wrote:
    I'm sorry if this is covered in some topic somewhere. I was unable to find it in a few searches, but I'm rather sleep deprived so I may not have been searching at optimum efficiency:P

    Hi Neocognitron, welcome here! :)

    I don't think your particular question has been covered in the forums. I remembered Orgos asking me the same thing but I don't think it was on the forums.
    I am wanting to port my alpha version game project from Allegro to Orx2D. All the game data is stored in an sqlite3 database. Bitmaps, powers, items, stuff and more stuff. Its a roguelike, so, you know, buncha tables for random generation of things.

    So the question is -- Is it possible to load things directly into Orx at runtime? Can I just build the objects as needed from serialized data, or does it all have to be in a single file upon init?

    So, as Grey pointed out, everything doesn't have to be in a single file. You can have as many file as you want, either linked to the base config file or loaded at real time programmatically.

    However, right now external data needs to be loaded from files and can't be loaded from memory pointers. With the recent exception of bitmaps/textures (I needed that feature so as to be able to load the default font from memory).
    I realize I could write a routine to build an ini file with the salient data before Init(), but that would be bothersome and clunky and lack elegance.

    I don't know if it'd be of any help, but instead of creating INI-formatted data, you can use setters (orxConfig_Select*/orxConfig_Set*) to fill the content of the config module directly in memory. Of course it's a bit more tedious than feeding the module a file, but it still works at runtime and is pretty flexible.

    As Grey pointed out again, there was a talk about making plugins for the config reading (to support other formats such as JSON, XML or even databases). But I don't think there was any follow up about this.
    Is there a way to build an object from arguments passed from code rather than from files?

    As I said, it can only be done for bitmaps/textures right now. But it's something I'll definitely support in the future.

    For the config you can use setters (if there are some missing let me know, I recently added some config inheritance handling functions for Eyecreate's Pey needs), so you will only lack sound/music data support if I'm correct.

    You can have a look at orxFont.c:182 orxFont_CreateDefaultFont() to see how to load a texture/bitmap memory.

    As for what you need before init, it's only the display & physics setup info.
    Viewports, cameras and anything else can be done afterwards.

    Let me know if you have any other issues. :)

    Good luck for your finals. :)
Sign In or Register to comment.