|
This thread is locked; no one can reply to it. |
1
2
|
What is this exactly? (BITMAP related) |
julian_boolean
Member #8,201
January 2007
|
I was searching around for posts that discuss movement and collision using Mappy and found this: http://www.allegro.cc/forums/thread/588658 Inside I found some code and this is what I'm trying to understand: BITMAP *grabframe(BITMAP *source, int width, int height, int startx, int starty, int columns, int frame) { BITMAP *temp = create_bitmap(width,height); int x = startx + (frame % columns) * width; int y = starty + (frame / columns) * height; masked_blit(source,temp,x,y,0,0,width,height); return temp; } I mean, I KNOW what it's suppose to do.. But, what the hell? Is it some kind of bitmap function? I was trying to use this particular piece of code (in C++), but it's kinda sketchy and I'm getting weird errors like undefined reference to vtable. Suppose I should also mention I'm trying to use it in a class. |
Kris Asick
Member #1,424
July 2001
|
It returns a pointer to a freshly created bitmap using the following arguments: <b>BITMAP source int width, int height int startx, int starty int columns int frame Since this routine actually creates the BITMAP object, you must store the result into a BITMAP pointer that hasn't been initialized, or is NULL. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Elverion
Member #6,239
September 2005
|
An "undefined reference to vtable" error generally means you haven't defined a function for a baseclass or one of it's children. The error has to do with your code in the class and not the function you posted, so it's hard to pinpoint with what we were given. If you are unable to find the error in your code, post the declaration and definition of your baseclass (and childrens') member functions, as well as the class itself. -- |
23yrold3yrold
Member #1,134
March 2001
|
Quote: undefined reference to vtable I can't imagine how the code you posted could possibly generate that ... -- |
Kibiz0r
Member #6,203
September 2005
|
23yrold3yrold said:
Quote: undefined reference to vtable I can't imagine how the code you posted could possibly generate that ...
julian_boolean said: Suppose I should also mention I'm trying to use it in a class.
Quote: Since this routine actually creates the BITMAP object, you must store the result into a BITMAP pointer that hasn't been initialized, or is NULL. It's worth mentioning that you are also responsible for destroying the object Just making sure you don't forget to manage your memory properly. --- |
bamccaig
Member #7,536
July 2006
|
julian_boolean said: BITMAP *temp = create_bitmap(width,height); temp isn't a very good identifier for this variable. It's temporary in the sense that all local variables are temporary, but in the context of the function it actually stores the BITMAP of the frame you're grabbing. Kris Asick said: It returns a pointer to a freshly created bitmap... Out of curiosity, is there an advantage to storing your frames as a sheet of sprites as opposed to an array of BITMAPs or self-defined FRAME objects? It seems that memory usage should be slightly less then if each frame had a separate BITMAP object. Is the processing time of ripping frames from a sheet of sprites small enough to make it worthwhile getting them from a sheet every time you access them or is it better to store them as separate BITMAPs? Or was that function designed to initialize an ANIMATION object with FRAME objects?
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
ImLeftFooted
Member #3,935
October 2003
|
Ever heard of create_sub_bitmap |
bamccaig
Member #7,536
July 2006
|
Dustin Dettmer said: Ever heard of create_sub_bitmap() sounds somewhat more appropriate for this function (maybe), however, my question still remains. Is it common/good practice to leave your sprites on a sheet-bitmap and rip them over and over again to save memory or is it better to rip them once into memory (when loading the game or level and reuse them)?
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Elverion
Member #6,239
September 2005
|
It doesn't mater much how you load them, but a sprite sheet is generally easier to work with. You should load all sprites at the beginning of the game, and not unload them until game exit, unless you're making a really big game and targeting older systems. -- |
julian_boolean
Member #8,201
January 2007
|
Thanks everyone, I think I'm going to try out create_sub_bitmap. I guess that's what this guy was trying to make. |
m c
Member #5,337
December 2004
|
separate images is better. the big bitmap is stored as a sequence of bits like so: 1478f92379e97397a7893478bc8976d987f for example. "image 1" (a box inside the bigger image) might be stored in 1478f92379e97397a7893478bc8976d987f... whilest "image 2" (a different box inside the same bigger image) might be stored in 1478f92379e97397a7893478bc8976d987f.... etc. If they are separate then each image is stored completely sequentially. This probably has a very mimor performance improvement as the memory prefetch system gets more of what you want (as it has finite capability and is wasting less time). That's about all there is to it. QED etc. (\ /) |
Kibiz0r
Member #6,203
September 2005
|
Of course, you're using more HD space by keeping them separate. But then there's the argument for taking them in as one big bitmap and splitting them up on initialization. --- |
Tobias Dammers
Member #2,604
August 2002
|
Quote: Out of curiosity, is there an advantage to storing your frames as a sheet of sprites as opposed to an array of BITMAPs or self-defined FRAME objects? It seems that memory usage should be slightly less then if each frame had a separate BITMAP object. This question has been done to death on the forum. Bottom line is, it doesn't really matter that much. Sprite sheets are generally a bit easier to work with, especially if you use a sub-standard sprite editor (say, MS Paint), and provide a natural way of bundling related sprites together, while single frames are a tiny bit more efficient speed-wise and will probably produce slightly cleaner code. The differences, especially performance-wise, are really negligible, so you should really just use what you feel more comfortable with and enjoy. No need to ponder. --- |
julian_boolean
Member #8,201
January 2007
|
I'm not so sure if I can really use create_sub_bitmap. It seems to be missing some parameters that this other function has, namely int columns and int frame. My sprite sheet (bmp) looks sorta like this (each number represents the frame): // yeah.. please try to picture this as 40x80 sprites. hehe n n n n n // north 0 1 2 3 4 e e e e e // east 5 6 7 8 9 s s s s s // south 10 11 12 13 14 w w w w w // west 15 16 17 18 19
|
Jakub Wasilewski
Member #3,653
June 2003
|
You would use it instead of this part: BITMAP *temp = create_bitmap(width,height); int x = startx + (frame % columns) * width; int y = starty + (frame / columns) * height; masked_blit(source,temp,x,y,0,0,width,height); Like this: int x = startx + (frame % columns) * width; int y = starty + (frame / columns) * height; return create_sub_bitmap(source, x, y, width, height); This way you can spare some memory space on those temporary bitmaps. --------------------------- |
julian_boolean
Member #8,201
January 2007
|
Hm.. But, how would that work if those two variables aren't even being used? |
Jakub Wasilewski
Member #3,653
June 2003
|
Err, they are being used. Specifically, they are being used for calculating the x and y a specific frame starts at. Once you know those, you have all the information about the frame (because the width and height is fixed), so you can create a subbitmap (look them up if you like) that represents the single frame. --------------------------- |
julian_boolean
Member #8,201
January 2007
|
I'm trying to avoid using the whole BITMAP *grabframe function thing since I can't seem to get it to work properly. Edit: What does "%" and "/" mean and do anyhow? |
GullRaDriel
Member #3,861
September 2003
|
julian_boolean said: What does "%" and "/" mean and do anyhow? You really should start at the beginning. Learn coding. "Code is like shit - it only smells if it is not yours" |
julian_boolean
Member #8,201
January 2007
|
Um. Just because I don't know what those two mean, means I don't know how to code? If you don't have a helpful reply, please don't reply at all. Edit: NM asked someone else about it. Thanks for your help. |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: Just because I don't know what those two mean, means I don't know how to code? Nor do you know math They are absolutely fundamental operators in coding. If you don't know what they are, you've missed a TON of stuff. -- |
julian_boolean
Member #8,201
January 2007
|
I may have missed a thing or two along the way. I've just never used these before, or seen them being used.. Well until now. |
Rampage
Member #3,035
December 2002
|
Quote: What does "%" and "/" mean and do anyhow? Sigged! -R |
julian_boolean
Member #8,201
January 2007
|
Isn't there a bridge you should be guarding? Like I said, there's the odd thing I didn't learn when I started c++ (like half a year ago.) |
Rampage
Member #3,035
December 2002
|
Quote: Isn't there a bridge you should be guarding? Like I said, there's the odd thing I didn't learn when I started c++ (like half a year ago.) No, and yes, everybody misses the basic arithmetic operators when learning C++. -R |
|
1
2
|