![]() |
|
ALLEGRO_ANIMATED_BITMAP |
Alianix
Member #10,518
December 2008
![]() |
Nothing wrong with A5's sub bitmaps I guess,the performance loss is minimal i too, it's just that an extra data structure is needed to hold positions and size. I thought a lot about offsets before, and i think it could be completely eliminated, the sprite should be placed on the frame including the offset. This is how it's generally done I believe, (but of course this wastes the most space). Otherwise, again the loader could generate the offsets too and place it in the .ani,then the problem is solved again. (I have not yet figured out how to mark the offsets in the frames though...) Ok...if we wANT to use sprite offset data, basically we will probably need a hard set magic color for the background I'm afraid, unless I come up something better. I will think about this... Anyways to understand how the loader/.ani-generator works, just assume that it can generate offsets and position and frame count for the .ani and it can remove the unwanted pixels from the input bitmap to save some space too.)
|
SiegeLord
Member #7,827
October 2006
![]() |
Using sub-bitmaps is better for the GPU, in terms of rendering performance. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
count
Member #5,401
January 2005
|
SiegeLord said: Using sub-bitmaps is better for the GPU, in terms of rendering performance.
That's what I thought. So using the big bitmap as the source would be better? Alianix said: it's just that an extra data structure is needed to hold positions and size. I already have a data structure which contains the frametimes. Adding the offset data would be no problem. Not is size nor in performance. Quote: if we wANT to use sprite offset data
If we want to support animations with different frame sizes we have no choice.
|
Neil Walker
Member #210
April 2000
![]() |
Why do you need to store a data structure? Creating a sub-bitmap just stores a reference to the main graphic so you just create your sub-bitmap and use that. Just in case you were after features to stick in an animation library, in my animation library I allow any mix of separate graphic files and sub-bitmaps, about 6 or so different looping types, independent 'free' timers, differing animation speeds between frames, semi-automated self-destruction/cleanup, grid based and non-grid based sprite sheets, video/memory/system bitmaps, fading, etc. They are all useful. The animation/graphic file is xml based, rather than some randomly created file format. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
count
Member #5,401
January 2005
|
Neil Walker said: Why do you need to store a data structure? Creating a sub-bitmap just stores a reference to the main graphic so you just create your sub-bitmap and use that.
The data structure is currently used to store the frametimes of each frame. This has to be stored somewhere beacuse you can't store that into a bitmap. Quote: Just in case you were after...
Some of this feature are already supported as well already. Quote: The animation/graphic file is xml based, rather than some randomly created file format.
I didn't use xml on purpose.
|
Alianix
Member #10,518
December 2008
![]() |
Thanks SiegeLord , so subbitmaps are no problem then, I agree on not using XML also only c and AL5. I have a math test tomorrow so I'll think more about the offset solution after that. Another question is should it support all pixel formats or only alpha ones? Ok, I got the offset problem solved for the loader. Basically the frame corner's magic color could be used to store a pixel at the position where the sprite's upper left corner is going to be. The difference between this position and the frames corner is the offset. Again the loader could clean up the wasted space in the bitmap, and write the offset in the .ani. The good thing about the loader this way is that it can load from an original bitmap, or it can create a .ani and cleanup the bitmap so later the loading will be a breeze. By the way I wrote the code to test the speed of the loader reading pixel info from memory bitmap vs reading pixel info from a file. Reading from file was 3x faster when the bitmaps are about 100x100 pixels and almost 20x faster with large 800x800 bitmaps. This is with processing about a 100000 bitmaps of course. So this difference would probably not be realistically noticable.::)
|
count
Member #5,401
January 2005
|
Ok, new version. New stuff: TODO: Like always, first how to use it 1) Usage A) an animation created from multiple bitmaps 1// loading
2ANIMATION *animation = load_animation("test.ani");
3ANIMATION_INSTANCE *animation_instance = create_animation_instance(animation, looping, pingpong, speed);
4
5// update
6update_animation(animation_instance, delta);
7
8//draw
9draw_animation(animation_instance, pos_x, pos_y);
10
11// destroying
12void destroy_animation(ANIMATION *anim);
13void destroy_animation_instance(ANIMATION_INSTANCE *anim_instance);
B) Now the new bitmap 1// at first you load the bitmap containing ALL the animations
2// into an ANIMATION_SET
3ANIMATION_SET *set = load_animation_set("data/all.bmp");
4
5// when creating the animation the set is passed and used from
6// here on for this animation
7ANIMATION *animation = load_animation_from_set("test_big.ani", set);
8
9//creating the instance, update and draw are the same as above
10
11// destroying
12void destroy_animation(ANIMATIOanimation);
13void destroy_animation_instance(ANIMATION_INSTANCE *anim_instance);
14void destroy_animation_set(ANIMATION_SET *set);
2) File formats 1framecount
2path/bitmapname
3frametime
4offset_x
5offset_y
6...
1framecount
2frametime
3pos_in_set_x
4pos_in_set_y
5size_x
6size_y
7offset_x
8offset_y
9...
3) The code Ok.. with the code in the code tags the post is too big
|
Alianix
Member #10,518
December 2008
![]() |
I'm speechless...:-X;D Chris, Is that all the code u wrote so far for this? I just don't wanna start writing some of this if you already did it. I don't see any loader specs or .ani file structures and such.
|
count
Member #5,401
January 2005
|
Yea, the code in the attached source files is all thats needed do to the above things(loading, updating, drawing an animation either from multiple bmps or from one file). The ani file structure is not put in any structs. Are you speachless because you like it or because you don't like it/you expected more?
|
Peter Wang
Member #23
April 2000
|
It's time to move this thread to a different part of the forum. Thanks.
|
Alianix
Member #10,518
December 2008
![]() |
Hmmm, it seems like we are getting moved...anyways... ...I was speechless because I did not expect you've written all that already. It looks pretty good to me so far. Some thoughts / questions: 1) Do we really need and extra struct for ANIMATION_INSTANCE? All this could fit into ANIMATION itself, or are you thinking of having different instances of the same animation? I don't see too much use of this but u tell me... 2) I would like to see some identifiers in the ANIMATION structure, like a "char *name" string & "int id". This very handy when loading or drawing animations can be referred to by their names for example. If you have multiple animations of characters on a bitmap for example. The .ani should contain these strings for each sequence so when it's loaded they'll get a nice name & id. 3) Please, please, can we not do things like this: ANIMATION_FRAME *f = new ANIMATION_FRAME;
4) It would be nice to provide some function to load individual frames. ALLEGRO_BITMAP* get_animation_frame(ANIMATION_SET *set, char *animation_name, int frame_index); ANIMATION_FRAME* get_animation_frame(ANIMATION_SET *set, char *animation_name, int frame_index); ALLEGRO_BITMAP* load_animation_frame(const char *path, char *animation_name, int frame_index); ANIMATION_FRAME* load_animation_frame(const char *path, char *animation_name, int frame_index); I'm working on the bitmap loader so I will post it.... It should conform to whatever you have so far. ...Nice photo's...what linux distro do you use ?
|
count
Member #5,401
January 2005
|
1) ANIMATION_INSTANCE *normal = create_animation_instance(animation, looping, pingpong, 1); So you have only ONE animation in memory and you can play that animation with different speeds. One animation could be looping one not, or one of them could be a pingpong animation. So, it could fit into the animation itself, but you would loose this possibility then. 2) 3) But the answer is simple. Since this is a C lib and new is a c++ keyword this is out of question anyway. Alianix said: I'm working on the bitmap loader so I will post it.... It should conform to whatever you have so far.
Sounds good
|
Alianix
Member #10,518
December 2008
![]() |
"I don't see what this would produce? It would only contain an empty animation without any data since nothing is loaded from a file (since no file was specified)" I was trying to ask you NOT to use "new", I think you misread... ANIMATION_SET* load_animation_set(const char *path) { ALLEGRO_BITMAP *bitmap = al_iio_load(path); ANIMATION_SET *set = new ANIMATION_SET; //<- HERE set->bitmap = bitmap; return set; }
|
count
Member #5,401
January 2005
|
I'm crazy... or an idiot Will fix it later!
|
Alianix
Member #10,518
December 2008
![]() |
So the "name" thing is kinda neat, if let's say you wanna have a game editor, or you have a bitmap with animations of different objects. It just helps to work with them outside your program. I don't know if I'm making sense, but it's very useful
|
count
Member #5,401
January 2005
|
Replaced the new statments with mallocs.
|
aniquilator
Member #9,841
May 2008
![]() |
Hello dude. with this concept, you can have a obj with all your sprites and a lot of animation obj that uses a lot of sprites in this pack, you can use the same sprite a lot of time, and you will never have to allocate space for the same bitmap... |
count
Member #5,401
January 2005
|
Thanks for the tips. The only real difference is that it is not made with classes and vectors.
|
aniquilator
Member #9,841
May 2008
![]() |
When I said vector and classes my intention was to generalize them... |
LennyLen
Member #5,313
December 2004
![]() |
aniquilator said: do you know why my game topic was closed? If you mean this thread, it's because threads automatically get closed after a week of inactivity.
|
Alianix
Member #10,518
December 2008
![]() |
Chris, I'm making the offset coding now ...I was debating whether to have negative offsets also or not, but i think for now I'm going to include it even though it makes it all a lot more complicated and it's seemingly useless. All offsets will be relative to upper left corner of the sprite's always. Also ,I'm not sure exactly what set_pos_x in your frame struct refers to ?
|
count
Member #5,401
January 2005
|
Quote: Also ,I'm not sure exactly what set_pos_x refers to ?
The name is probably not the best.
|
Alianix
Member #10,518
December 2008
![]() |
I see so I guessed it right then. (Ok, I'm eliminating negative offsets, there is really no need because their effect can always be emulated by using larger positive offsets in the frame set. Done...) Chris, I found a small oversight in your code, you are allocating too much space for frame pointers... 1ANIMATION* create_animation_set(ANIMATION_SET *set, float frame_time[], int set_poss_x[], int set_poss_y[], int sizes_x[],
2 int sizes_y[], int offsets_x[], int offsets_y[], int frame_count)
3{
4 ANIMATION *anim;
5 anim = (ANIMATION*) malloc(sizeof(ANIMATION) + frame_count * sizeof(ANIMATION_FRAME));
6
7/* SHOULD BE like this
8
9 anim = (ANIMATION*) malloc(sizeof(ANIMATION) + frame_count * sizeof(ANIMATION_FRAME *)); <- allocate for pointers not the whole struct
10
11*/
12
13 anim->frame_count = frame_count;
14 anim->active_frame = 0;
15 anim->type = ANIMATION::SET;
16 anim->animation_set = set;
17
18 for (int i = 0; i < frame_count; i++)
19 {
20 ANIMATION_FRAME *f = (ANIMATION_FRAME*) malloc(sizeof(ANIMATION_FRAME));
21 f->current_time = 0;
22 f->frame_time = frame_time[i];
23 f->set_pos_x = set_poss_x[i];
24 f->set_pos_y = set_poss_y[i];
25 f->size_x = sizes_x[i];
26 f->size_y = sizes_y[i];
27 f->offset_x = offsets_x[i];
28 f->offset_y = offsets_y[i];
29 anim->frames[i] = f;
30 }
31
32 return anim;
33}
Same thing later in create_animation_multi()... Also Here this is not C: if (anim_instance->animation->type == ANIMATION::MULTIPLE_BITMAPS){} /* <-crime scene, this is C++*/
I got a super busy week at school, so I'm still working on the bitmap interpreter, I'm probably 50% done with it,hopefully by the end of the week it should be done.
|
count
Member #5,401
January 2005
|
Alianix said: I found a small oversight in your code
Good catch Quote: Also Here this is not C
My C skills are more rusty then I expected... Cons? Pros? Quote: hopefully by the end of the week it should be done.
Don't hurry! Take the time you need (for school and coding!)
|
Alianix
Member #10,518
December 2008
![]() |
Yes I would say get rid of enum and use #define. It's only a couple of different defines anyhow so make it an int I guess. Thanks ! One more thingie... for( int i = 0;... <- this is not allowed i believe either int i; for( i = 0;... <- this is OK
|
|
|