|
This thread is locked; no one can reply to it. |
1
2
|
Resource manager |
Trezker
Member #1,739
December 2001
|
I need a resource manager. I've been searching for examples but haven't found any really good stuff. |
ReyBrujo
Moderator
January 2001
|
Something like an Allegro datafile? -- |
X-G
Member #856
December 2000
|
Here's the one I use. I'm quite fond of it. Resource manager:
Resource interface:
Example of a resource:
Usage example: ResourceManager *gRsrc = new ResourceManager(); Sprite *ninja = gRsrc->load<Sprite>("data/ninja.spr"); It will cache already loaded data and will clean everything up when the ResourceManager dies. Just remember to delete it. You may ignore references to gLog. Just remove them. This was copied straight from a project so references to other parts of it are still in there. -- |
Trezker
Member #1,739
December 2001
|
Thanks X-G! Have a little fluffy dragon. I'm putting it in my old singleton. Now I just have to make those resources... work, work, work... [edit] |
X-G
Member #856
December 2000
|
Quote: Wondering why you're doing this... So that you can load the same file twice as different types. For instance, a .png file might be used as a Texture or a Bitmap or perhaps both in the same program. It would not be good if you loaded it expecting one thing and got something else entirely back. -- |
Trezker
Member #1,739
December 2001
|
Ahh, smart. I'll add a comment. |
Johan Halmén
Member #1,550
September 2001
|
How about Grabber? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Wetimer
Member #1,622
November 2001
|
So, your resource manager doesn't provide unloading unused objects? All objects are only deallocated at the end? <code>if(Windows.State = Crash) Computer.halt();</code> |
X-G
Member #856
December 2000
|
It's very easy to add such functionality. It's not in right now because I don't use it, but absolutely nothing keeps you from implementing it. -- |
Erkle
Member #3,493
May 2003
|
Another thing I didn't know you could do with templates:). Where do the spr files come from? Is it a standard file or is there an editor for it somewhere in the depot?
If the writing above has offended you, you've read it wrong.....fool. |
X-G
Member #856
December 2000
|
It's not standard, it's my own. I would show the code, but it's several files and I'm too tired to do much right now. -- |
Trezker
Member #1,739
December 2001
|
Hey, would you like to give me the right to use your code straight off? |
X-G
Member #856
December 2000
|
Knock yourself out. Use it, change it, just don't say you wrote it. There's more where it came from too, if you'd like. -- |
Richard Phipps
Member #1,632
November 2001
|
Keep going and you'll have a plug 'n' play game making kit for us all to use. |
Trezker
Member #1,739
December 2001
|
You don't happen to have a trans+alpha blit function? As I mentioned in the loadpng thread I want to blit a RGBA with extra trans. As I see it I have to get the pixels from the source, put together their alphavalue with the trans factor and mix them with the destination. |
umperio
Member #3,474
April 2003
|
Hey Trezker, you're still connected to my IRC channel so you can ask Hammerbear and Zenogais about our resource manager. |
X-G
Member #856
December 2000
|
Afraid not. I use OpenGL for projects that require that sort of functionality. -- |
Trezker
Member #1,739
December 2001
|
Ok I've written a function now. But I guess it's not the best... I just gotta figure out how to use the alpha channel...
[edit twice] int c=((int *)src->line[y])[x]; int a=int(geta32(c)*fact); a=(c&0xFFFFFF)|a<<24; ((int *)temp->line[y])[x]=a;
Some testing has also been performed. That's not so bad imho. |
Fladimir da Gorf
Member #1,565
October 2001
|
You're creating a bitmap everytime you want to render the bitmap? You could try if this code using MMX gives you better results (I simply added my own blending routines to your function below):
Even if it doesn't make a big difference now (the real CPU power is consumed somewhere else), at least you can use the function more often in your game without a serious slowdown. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Trezker
Member #1,739
December 2001
|
that code has some errors in it. unsgined two times From this line. |
Fladimir da Gorf
Member #1,565
October 2001
|
Ouch, a big, evil copy paste error, and I managed to typo "unsigned" as "unsgined". I also forgot the fundamental: factor = (globalFactor * pixelAlpha) / 255;
Also, this works only if the destination bitmap is 32-bit as well... OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Trezker
Member #1,739
December 2001
|
These were still wrong... And it doesn't work... it's all black. |
Fladimir da Gorf
Member #1,565
October 2001
|
Hmm... I was just testing it myself. Let's see where the problem is. It's my bad habit to write a post and edit it over and over, like if I'd save a text document and continue editing it Just be patient EDIT: When I changed the function header to OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Trezker
Member #1,739
December 2001
|
I'm exited to see if it actually is better than my code Though when I run it I only get 30 fps, my code gives 50. |
Fladimir da Gorf
Member #1,565
October 2001
|
OK, see the edit. I bet it should be faster, at least it doesn't need to create a bitmap every call, processes each pixel only once, doesn't use allegro's slow blenders, uses MMX and doesn't need int->float->int conversions for each pixel. I'll test if there's a cause for the slowdown... EDIT: I tested it and at least in my PC, it was a lot faster, though not several times faster as I would've expected. EDIT2: OUCH! When I changed my code to use direct bitmap memory access, it became about 4x (!!) faster, taking only 15-20% of the time as your original function (not that it wasn't good code as well). Also, I needed to change "unsigned long" to "unsigned int", maybe because with my 64-bit processor they were 64-bit ints as well and thus slower (?)
Test results when drawing 1000 quite large bitmaps: Original: 14858 ms New: 2650 ms OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
|
1
2
|