|
Screen Update API: final draft |
Oscar Giner
Member #2,207
April 2002
|
Quote: ..edit.. You should think more before posting; too many edits to save your donkey, lately -- |
Steve Terry
Member #1,989
March 2002
|
Uhm that still doesn't answer it... other than what I already knew about #define... ___________________________________ |
Mars
Member #971
February 2001
|
With defines your error messages often won't match you code. -- |
Steve Terry
Member #1,989
March 2002
|
Pfft I NEVER get errors ___________________________________ |
spellcaster
Member #1,493
September 2001
|
Quote: Anyway my question is what is the advantage/reason for using enum instead of #define? It's mainly a style question. It also allows you to see the name of the constant instead of it's name in case of any errors. Another reason is that if you use enums, you have a better compile time control. If you use defines, your constants could change values (by using defines and undefs). But mainly style. The discussion started as part of the C vs C++ vars. -- |
Rash
Member #2,374
May 2002
|
It's not mainly style! Macros can silently change the behavior of your program without the compiler giving a peep! |
Matthew Leverton
Supreme Loser
January 1999
|
The API should be consistant with Allegro's if you want it to be considered an "add-on" lib. (Ie, underscores instead of MixedCaps.) |
23yrold3yrold
Member #1,134
March 2001
|
Yup; that was the first thing that occured to me. Just curious if anyone else had any ideas ... -- |
Richard Phipps
Member #1,632
November 2001
|
The only thing I can think of is a change_update function which acts as a wrapper around the shutdown and the setup update functions. It would only take 4 lines, but I use something similar.. |
23yrold3yrold
Member #1,134
March 2001
|
Hmmm. It's true that it's trivial ... I wouldn't have to worry about video bitmaps getting destroyed or any crap like that, would I? Nah. Just make the end user call two functions instead of one. -- |
Richard Phipps
Member #1,632
November 2001
|
Don't you have the option to change the screen update system ingame in TMS? I don't think it's trivial, when you have a function to toggle the vsync variable, or return it. |
23yrold3yrold
Member #1,134
March 2001
|
Quote: Don't you have the option to change the screen update system ingame in TMS? Sure, and then you restart, and forget the option ever existed. It's not like you have to switch between update methods 20 times per game or something. The vsync setup is mostly for testing. Besides, since the waitforvsync variable is static, I really have no choice there. -- |
Richard Phipps
Member #1,632
November 2001
|
Well it's up to you, people would only use it once in a program, but I personally would include it. |
Evert
Member #794
November 2000
|
Looks good Chris (from what I saw in the headerfile at least)! |
23yrold3yrold
Member #1,134
March 2001
|
Okay, here's the final version AFAIAC. I've added support for triple buffering and page flipping with a memory bitmap buffer, for those who might be reading from said buffer and don't want it to be a video bitmap. If triple buffering fails, it tries for page flipping. If triple buffering with a buffer fails, it tries for page flipping with a buffer. If either page flipping setup fails, it tries for system buffering, and then double buffering. I had to change the internals a bit to make that work, but I don't think I introduced any bugs. Also, I switched to allegro_naming_conventions. I guess that's that then. Anything else? -- |
Evert
Member #794
November 2000
|
Again, looks good. I'll forward this to AD to see if we want it included. This depends on where we want to go with the graphics API I guess... Some nitpicking in case it is merged with Allegro (not saying I have issues with your coding style, just pointing out where Allegro's conventions differ). #ifndef __cplusplus extern "C" { #endif That actually is an error. It should be #ifdef __cplusplus enum { char initialize_screen_updating(char i); alert("Well ... crap!", NULL, NULL, "dsjkd", "sdkffd", 1, 1); if(active_page) active_page = EraseBitmap(active_page); |
23yrold3yrold
Member #1,134
March 2001
|
Quote: That actually is an error. It should be #ifdef __cplusplus Oops. I just copied spellcaster's post above. Quote: Well, a popup box when a function fails is evil ... Aw, right. I was having a bit of trouble last night and was trying to get it to tell me why. That shouldn't still be in there; I'll remove it ... Quote: char -> int, in all three functions. Does it matter? -- |
Kitty Cat
Member #2,815
October 2002
|
23 said: Quote: char -> int, in all three functions. Does it matter? It's cleaner, looks better, and is more CPU friendly. The memory difference is negligible. -- |
Rash
Member #2,374
May 2002
|
Like I said before, there's no need to set the values explicitly with the enum. Otherwise, it might seem those values are somehow relevant in some way possibly leading to confusion and/or errors: enum { NOUPDATEMETHOD, TRIPLEBUFFER, PAGEFLIP, SYSTEMBUFFER, DOUBLEBUFFER, TRIPLEBUFFERWMB, PAGEFLIPWMB };
|
23yrold3yrold
Member #1,134
March 2001
|
Yeah; I'm just being paranoid, I guess. I'm assuming enum's are guarenteed to start at 0? If so, I'll remove that bit ... Quote: You can lose the if(...) on this one and it's brethern. What happens if I destroy_bitmap() on a NULL pointer? -- |
Rash
Member #2,374
May 2002
|
the Allegro manual said: void destroy_bitmap(BITMAP *bitmap); Destroys a memory bitmap, sub-bitmap, video memory bitmap, or system bitmap when you are finished with it. If you pass a NULL pointer this function won't do anything. See above for the restrictions as to when you are allowed to destroy the various types of bitmaps. Emphasis mine. |
23yrold3yrold
Member #1,134
March 2001
|
Okay, I fixed everything but changing the enum back to defines. Rash said he'd blow my brains out above. Anything else? -- |
Rash
Member #2,374
May 2002
|
Yes, add a dummy value at the end of the enum and use that for comparison. Makes the code clearer and less error prone. |
23yrold3yrold
Member #1,134
March 2001
|
Could you be a little clearer? Comparing what? -- |
Rash
Member #2,374
May 2002
|
Something like this: // in screen.h enum { NOUPDATEMETHOD, TRIPLEBUFFER, PAGEFLIP, SYSTEMBUFFER, DOUBLEBUFFER, TRIPLEBUFFERWMB, PAGEFLIPWMB, LASTVALUE }; // in screen.c if(i <= NOUPDATEMETHOD || i >= LASTVALUE) i = TRIPLEBUFFER;
|
|
|