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
23yrold3yrold
Member #1,134
March 2001
avatar

I guess it's worth the effort. :) Last attachment updated.

Anything else?

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

Rash
Member #2,374
May 2002
avatar

A couple of style issues:

do { } while (poll_scroll());

Is this deliberately chosen instead of just a while statement?

active_page = active_page == pages[0] ? pages[1] : pages[0];
buffer = active_page = active_page == pages[0] ? pages[1] : pages[0];

I would have put the RHS between parentheses.

23yrold3yrold
Member #1,134
March 2001
avatar

That while (poll_scroll()); with just a terminator at the end always looks suspicious to me. ;D Sorry; that's just me. I implemented both style suggestions, even thought the RHS evaluates just fine (I guess it's clearer now). Updated attachment.

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

Rash
Member #2,374
May 2002
avatar

Actually I was looking for the parentheses being put around the assigned expressions instead. :)

23yrold3yrold
Member #1,134
March 2001
avatar

... Why?

Also, I caught a bug; destroying all the bitmaps like that in shutdown_screen_updating() is a bad move because buffer and active_page could be pointing at the same bitmap. Calling destroy_bitmap() on both would be bad, yes? Fixed up.

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

Rash
Member #2,374
May 2002
avatar

Quote:

... Why?

The way I see it, you would want to draw attention to the fact that the statement is in fact an assignment.

Quote:

Also, I caught a bug; destroying all the bitmaps like that in shutdown_screen_updating() is a bad move because buffer and active_page could be pointing at the same bitmap. Calling destroy_bitmap() on both would be bad, yes?

Just like calling delete or free twice on the same value.

Marcello
Member #1,860
January 2002
avatar

If you are assuming the first update method is 0, I'd suggest for clarity, simply explicitly setting the first item in the enum:

enum {
        NOUPDATEMETHOD = 0,
        TRIPLEBUFFER,
        PAGEFLIP,
        SYSTEMBUFFER,
        DOUBLEBUFFER,
        TRIPLEBUFFERWMB,
        PAGEFLIPWMB,
        LASTVALUE
};

And personally I'd add underscores in those, cause they're kinda hard to read. Or in this case, since they're global constants, perhaps:

enum {
        UPDATE_NONE = 0,
        UPDATE_DOUBLE_BUFFER, // Or take out _BUFFER?
        UPDATE_TRIPLE_BUFFER,
        UPDATE_PAGE_FLIP,
        UPDATE_SYSTEM_BUFFER,
        UPDATE_TRIPLE_WMB,    // WMB is a bit odd... maybe MEM or MEMORY instead
        UPDATE_PAGEFLIP_WMB,
        UPDATE_MAX            // this is just personal style for me when doing enums
};

Marcello

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

do { } while (poll_scroll());
Is this deliberately chosen instead of just a while statement?

Allegro tends to use

do {
} while (...);

though I personalyl prefer doing

while(...)
   ;

Personal preference, though.

Quote:

active_page = active_page == pages[0] ? pages[1] : pages[0];
buffer = active_page = active_page == pages[0] ? pages[1] : pages[0];

And I thought *ptr++ was bad. :P I'd clarrify that to:

active_page = ((active_page == pages[0]) ? pages[1] : pages[0]);
buffer = active_page = ((active_page == pages[0]) ? pages[1] : pages[0]);

The ?: operators are generally quite anal when it comes to operator precedence, so I prefer to leave little room for errors (I would even put parenthesis around the two "return" values, though when it's just a single word like that I usually omit it).

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

23yrold3yrold
Member #1,134
March 2001
avatar

I like Marcello's enum name suggestions. I'm gonna keep the WMB (With Memory Buffer) though.

New update; you can now toggle vsync by pressing 2, and cycle through screen update methods by pressing 1 (that's a change to the example code, not the API). Calling the initialization function now let's you switch update methods with a single function call (it calls the shutdown function internally if there's already an update method in operation). Also streamlined main.cpp a bit and added more comments. I think it's bulletproof now ...

EDIT: Oddly, Double Buffering is twice as fast as System Buffering for me. I thought the latter was supposed to be faster ... maybe I should omit it?

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

Rash
Member #2,374
May 2002
avatar

I'm a bit skeptical about the idea of falling back to triple buffering in case an illegal value is supplied by the user. I guess it depends on whether you're "defensively" or "offensively" minded programming wise.

How about implementing dirty rectangles too? ;)

X-G
Member #856
December 2000
avatar

Quote:

EDIT: Oddly, Double Buffering is twice as fast as System Buffering for me. I thought the latter was supposed to be faster ... maybe I should omit it?

Maybe, maybe not. I know that for me, page flipping nets worse results both in terms of tearing and flicker than double buffering does. (Disclaimer: I didn't write the programs referred to here. They might have used some dodgy methods.)

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

I'm a bit skeptical about the idea of falling back to triple buffering in case an illegal value is supplied by the user. I guess it depends on whether you're "defensively" or "offensively" minded programming wise.

The return value can be checked, if the programmer definitely wants to avoid triple buffering. Perhaps more wisely, let the user determine what's best for their system themselves (dirt easy now, isn't it? ;))

Quote:

How about implementing dirty rectangles too?

Firstly, I don't want to bloat the API too much. Screen updating is fine, especially since a seperate DRS could probably be built seperately. Secondly, I have no need or use for a DRS, so a) I personally won't waste my time and b) I wouldn't know where to start anyway. :)

Let's just worry about problems with the current setup. Does all look good?

X-G: Yeah, but page flipping isn't as comparable to double buffering as system buffering is.

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

Rash
Member #2,374
May 2002
avatar

One comment of yours fails the spell checker test.
Yes, "pedantic" is my middle name.

Marcello
Member #1,860
January 2002
avatar

omg "seperately"

Marcello

23yrold3yrold
Member #1,134
March 2001
avatar

Can't see it.

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

Rash
Member #2,374
May 2002
avatar

"self-explanitory"

23yrold3yrold
Member #1,134
March 2001
avatar

Huh. Thought it was spelt with an 'i'. :-X

Oh well. If that's my worst bug I'm happy.

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

Rash
Member #2,374
May 2002
avatar

Well to be perfectly honest, I haven't bothered delving into the semantic aspect of the program as I'm not familiar with this aspect of Allegro.

23yrold3yrold
Member #1,134
March 2001
avatar

Final call ...

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

Richard Phipps
Member #1,632
November 2001
avatar

Steve Terry
Member #1,989
March 2002
avatar

One thing I noticed that could be added is documentation ... even though it's simple it's needed anyway for reference whenever you need to use a function, that way you don't have to go diggin through source code or header files to find something. Also in screen.h it is best to add:

1#ifndef SCREEN_UPDATE_H
2#define SCREEN_UPDATE_H
3 
4#include <allegro.h>
5 
6#ifdef __cplusplus
7 extern "C" {
8#endif
9 
10// Blah
11 
12#ifdef __cplusplus
13 }
14#endif
15 
16#endif

This keeps it from being defined twice if it's included in multiple files in a project :)
I had to use SCREEN_UPDATE_H because I think allegro already uses SCREEN_H therefore it refused to compile the header file ;D

I utilized your screen update code into my little game, which works well since it has the *_WMB ability and I use fades, etc. That way I get ultra smooth motion with Triple buffering fullscreen and fast fades. However for some odd reason in windowed mode triple buffering is actually a bit choppy and not smooth, double buffering is excellent windowed and somewhat ok fullscreen, but at least you get to choose :P

___________________________________
[ My Pictures ]
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

Oscar Giner
Member #2,207
April 2002
avatar

Quote:

However for some odd reason in windowed mode triple buffering is actually a bit choppy and not smooth

tripple buffering in windowed mode doesn't exist. You're probably getting page flipping (it depends on 23 implementation).

Steve Terry
Member #1,989
March 2002
avatar

Ooh just noticed that UPDATE_PAGEFLIP_WMB doesn't work like it should, somehow I'm getting a video bitmap to draw to, this makes it extremely slow at times.

___________________________________
[ My Pictures ]
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

23yrold3yrold
Member #1,134
March 2001
avatar

You can page flip in windowed mode?

I haven't checked to see how the lib reacts to windowed modes. I should check that tomorrow. But like you said, at least you get to choose. :) Glad to hear it works for you.

Quote:

One thing I noticed that could be added is documentation ...

Well, yeah. But right now it's pretty easy to read from the code. I'll make docs once it's done, fully and completely. :)

Quote:

Ooh just noticed that UPDATE_PAGEFLIP_WMB doesn't work like it should, somehow I'm getting a video bitmap to draw to, this makes it extremely slow at times.

Huh? That shouldn't be ... from the code that's impossible. is_video_bitmap() == true?!

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

Steve Terry
Member #1,989
March 2002
avatar

if(is_video_bitmap(get_buffer())){
  allegro_message("OMG VIDEO BITMAP!!!!!DIEKTHXBYE");
  exit(1);
}

You can guess what pops up on the screen ;D
That's using the update method of page flip WMB so somehow I'm getting a video buffer :-/

___________________________________
[ My Pictures ]
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



Go to: