Resource manager module (threaded as well!)

BlitzMax Forums/BlitzMax Programming/Resource manager module (threaded as well!)

_JIM(Posted 2008) [#1]
Hi!

Don't know if this is the right section, but here's something for the community :)

I noticed I haven't seen a resource manager around (maybe there is, but I haven't seen it) so I thought of writing one. Also, I remembered about the multi-threading in the SVN version, so I wanted to give it a try.

This is what I came up with:

*** Click here to download ***

Features:

- Loads a configuration file that contains paths categorized in groups
- Loads all resources in a folder (no subfolders yet)
- (Nice one) It's threaded!!! You can display a nice animation, mesage, video or whatever while loading your resources in a different thread.

Well, that's pretty cool, but not awesome... This should fix it:

- Custom resource loading: you define your own file extensions and your loading function for it. The manager handles the rest.

It's still in "beta" if I can say so (started working on it yesterday morning) so there might be a few bugs in there to squish.


I did this for my own use, so I may have missed some important features. If so, please point them out and I'll see what I can do :)

If you like this and you use it, some credits would be nice.

Edit:

test file:

Import jim.resman

Graphics 640,480

Global RM:RMResourceManager = New RMResourceManager
RM.Init("Data\resources.cfg")
RM.AddCustomType("txt,text",CustomLoad)

Global RL:RMResourceLoader = RM.CreateLoader("main",1,1)

RL.LoadAll()

Repeat
	Cls
	DrawText "Loaded: " + ((RL.Loaded() / Float(RL.Total())) * 100) + "%",0,0
	Flip
Until RL.IsLoaded()

Cls
Local img:TImage = RM.GetImage("test1")
DrawImage img,0,0
DrawText "Loaded!",0,0
Flip
WaitKey()

Function CustomLoad:Object(pth:String)
	Print "I am a custom loading function!"
	Return Null
EndFunction


resources.cfg
[main]
Data\Images\


I'm affraid you'll have to use your own bunch of images :) You can read the comments in the .bmx file for more info.


Czar Flavius(Posted 2008) [#2]
I'm turning to the darkside and storing all my data in an MSAccess database and using SQL to load it into Blitzmax. Muwahaha! I got so tired of editing millions of text files in notepad. Now I have nice easy GUI forms for me to use to add new data.


TaskMaster(Posted 2008) [#3]
I hope you are not serious about this MSAccess thing.

You do realize that anyone running your program will need Access installed.


Czar Flavius(Posted 2008) [#4]
Even with the database modules? I thought the whole point of them was you can access ODBC databases independently??

Please reply, I may have wasted my life.

http://code.google.com/p/maxmods/


plash(Posted 2008) [#5]
On windows you should be fine (built-in library for odbc comes with windows), for Mac and Linux you'll need to include a library with your project.


Brucey(Posted 2008) [#6]
Hehe... Access?

For ODBC, you need an ODBC driver for the particular database you wish to converse with.


Although I've found this : http://sourceforge.net/projects/mdbtools
Might be worth playing with - well, if it was for anything other than Access :-p


_JIM(Posted 2008) [#7]
Don't wanna disturb too much, but any comments about my module? So far it looks like a hijack to me.


plash(Posted 2008) [#8]
Don't wanna disturb too much, but any comments about my module? So far it looks like a hijack to me.
The threaded part of it makes sense, being able to render some sort of progress display to the user, but other than that it doesn't seem like its worth it.

And threading is not official/integrated into Max yet, so I won't even try it (I'm not in the mood to be setting up SVN BlitzMax.. ugh, module compiling).


_JIM(Posted 2008) [#9]

The threaded part of it makes sense, being able to render some sort of progress display to the user, but other than that it doesn't seem like its worth it.

And threading is not official/integrated into Max yet, so I won't even try it (I'm not in the mood to be setting up SVN BlitzMax.. ugh, module compiling).



Well, it's probably not wort it for a project with 2 images and 1 background sound, as it actually takes 4 function calls to get an image loaded. However, it may be of use for larger projects as it does most of the stuff for you, and with the custom loading types you can use it for the loading of levels for example. Then it's down to a function call to load everything.

I know about the svn part and compiling modules, but I thought maybe someone did this already :)

I could make a version without threads, but that strips away half of the fun.


plash(Posted 2008) [#10]
Well, it's probably not wort it for a project with 2 images and 1 background sound, as it actually takes 4 function calls to get an image loaded.
Of course not. I was not implying that.

I could make a version without threads, but that strips away half of the fun.
I was not recommending it.


TaskMaster(Posted 2008) [#11]
Even with the database modules? I thought the whole point of them was you can access ODBC databases independently??

Please reply, I may have wasted my life.


If I were you, I would try running it on a PC without Access and see what happens. As long as you are only accessing the data in the mdb file and not expecting the user to be able to use any of the forms in the file, I think you should be alright on a Windows box, since they usually have the dlls for access databases already. But you may also need to have them upgrade their dll as well.

I think it is called the MS Jet Database Engine or something of that nature. And Microsoft is always upgrading it. This could be a hairy path to travel with users needing to update odbc drivers.


Czar Flavius(Posted 2008) [#12]
Hm OK thankyou. The forms are just for people who want to edit the data it's not needed for anyone who just wants to play.