Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Screen Update API: final draft

This thread is locked; no one can reply to it. rss feed Print
Screen Update API: final draft
Oscar Giner
Member #2,207
April 2002
avatar

Quote:

..edit..

You should think more before posting; too many edits to save your donkey, lately ;)

Steve Terry
Member #1,989
March 2002
avatar

Uhm that still doesn't answer it... other than what I already knew about #define...

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Mars
Member #971
February 2001
avatar

With defines your error messages often won't match you code.

--
This posting is a natural product. The slight variations in spelling and grammar enhance its individual character and beauty and in no way are to be considered flaws or defects.

Steve Terry
Member #1,989
March 2002
avatar

Pfft I NEVER get errors ;D

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

spellcaster
Member #1,493
September 2001
avatar

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.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Rash
Member #2,374
May 2002
avatar

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
avatar

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
avatar

Yup; that was the first thing that occured to me. Just curious if anyone else had any ideas ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Richard Phipps
Member #1,632
November 2001
avatar

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
avatar

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. ;D

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Richard Phipps
Member #1,632
November 2001
avatar

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
avatar

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. :P

The vsync setup is mostly for testing. Besides, since the waitforvsync variable is static, I really have no choice there. :)

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Richard Phipps
Member #1,632
November 2001
avatar

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
avatar

Looks good Chris (from what I saw in the headerfile at least)!
Depending on what is going to happen with Allegro's GFX API in the near future, I'd say this could be merged with Allegro rather than being offered as an add-on.

23yrold3yrold
Member #1,134
March 2001
avatar

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? :)

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Evert
Member #794
November 2000
avatar

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).
I won't comment on indentation and other source layout issues because those are not as important unless it actually is included.

#ifndef __cplusplus
  extern "C" {
#endif

That actually is an error. It should be #ifdef __cplusplus

enum {
I think that'd have to be changed to use #defines. Maybe change the names too.

char initialize_screen_updating(char i);
char -> int, in all three functions.

alert("Well ... crap!", NULL, NULL, "dsjkd", "sdkffd", 1, 1);
:)
Well, a popup box when a function fails is evil. It should probably also return NOUPDATEMETHOD on error. Better yet, in your code you could use a named emum instead of int for the return or argument type.

if(active_page) active_page = EraseBitmap(active_page);
You can lose the if(...) on this one and it's brethern.

23yrold3yrold
Member #1,134
March 2001
avatar

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?

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Kitty Cat
Member #2,815
October 2002
avatar

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.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Rash
Member #2,374
May 2002
avatar

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
avatar

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?

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Rash
Member #2,374
May 2002
avatar

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
avatar

Okay, I fixed everything but changing the enum back to defines. Rash said he'd blow my brains out above. :)

Anything else?

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Rash
Member #2,374
May 2002
avatar

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
avatar

Could you be a little clearer? Comparing what?

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Rash
Member #2,374
May 2002
avatar

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;



Go to: