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
Richard Phipps
Member #1,632
November 2001
avatar

In chris's code it's :

buffer = create_bitmap(SCREEN_W, SCREEN_H);
And so it should work. I don't know why it doesn't. However buffer itself is not being checked to see if it was created properly. Or indeed cleared of any old data..

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

However buffer itself is not being checked to see if it was created properly. Or indeed cleared of any old data.

    buffer = create_bitmap(SCREEN_W, SCREEN_H);
      
    if(pages[0] && pages[1] && buffer)
    {
      clear_bitmap(pages[0]);
      clear_bitmap(pages[1]);
      clear_bitmap(buffer);

      ...

:P

Anyway, I'm going to check this now ...

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

Richard Phipps
Member #1,632
November 2001
avatar

In the zip I downloaded it is:

1if((gfx_capabilities & GFX_CAN_TRIPLE_BUFFER))
2 {
3 pages[0] = create_video_bitmap(SCREEN_W, SCREEN_H);
4 pages[1] = create_video_bitmap(SCREEN_W, SCREEN_H);
5 pages[2] = create_video_bitmap(SCREEN_W, SCREEN_H);
6 if(pages[0] && pages[1] && pages[2])
7 {
8 clear_bitmap(pages[0]);
9 clear_bitmap(pages[1]);
10 clear_bitmap(pages[2]);
11 active_page = pages[0];
12 buffer = create_bitmap(SCREEN_W, SCREEN_H);
13 show_video_bitmap(pages[2]);
14 updatemethod = TRIPLEBUFFERWMB;
15 return updatemethod;
16 }

So I must have an earlier version. Sorry about that..

23yrold3yrold
Member #1,134
March 2001
avatar

That's both old, and the triple buffering code. :)

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

Richard Phipps
Member #1,632
November 2001
avatar

But you still have:
buffer = create_bitmap(SCREEN_W, SCREEN_H);
In the middle of there. :)

Your new code looks much better. :D

23yrold3yrold
Member #1,134
March 2001
avatar

I'll be buggered. Steve was right; something I copied and pasted over from PAGE_FLIP to PAGEFLIP_WMB assigned a video bitmap to the buffer (after it had already been assigned the memory buffer) in the drawing code. The main program now reports the type of buffer for any given mode, but now that it's working correctly it's kind of not necessary. :)

Fixed and attached.

Page flipping is indeed choppy for me in windowed mode too, but I don't think you can get away from that ...

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

Richard Phipps
Member #1,632
November 2001
avatar

I think page flipping in a window is just choppy what ever you do. Glad to see you fixed the code. :)

Steve Terry
Member #1,989
March 2002
avatar

Cool it works now :) I still suggest doing the #ifndef UPDATE_SCREEN_H part for multiple file projects... otherwise you are going to get errors.

Hey do I get to go on the beta tester list now I found and helped fix a bug :)

___________________________________
[ 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

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

I still suggest doing the #ifndef UPDATE_SCREEN_H part for multiple file projects ...

Right; I forgot that. Added.

Quote:

Hey do I get to go on the beta tester list now I found and helped fix a bug

List? There's a list?

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

Richard Phipps
Member #1,632
November 2001
avatar

Chris, would you be prepared to add in a DRS system if Axilmar or someone else was to code it?

Steve Terry
Member #1,989
March 2002
avatar

You need at least a README in there for those who wish to use it, not everyone is inclined to dig through .c files to figure out how to use it :)

___________________________________
[ 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

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

Chris, would you be prepared to add in a DRS system if Axilmar or someone else was to code it?

Depends on how its done. I have no idea what a DRS system entails and I don't know what it'll do to the API. If can be written to work alongside my API, bodacious. I'm definitely open to the idea.

Quote:

You need at least a README in there for those who wish to use it

Well, yeah. :) But that's when it's ready to be "released", and especially after a bug like you found, it ain't. :P Plus a DRS might muck up the API, so ...

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

Richard Phipps
Member #1,632
November 2001
avatar

It shouldn't mess up the API or your system at all if done right. Maybe Axilmar can help with this. I'm going to be a bit busy setting everything up..

axilmar
Member #1,204
April 2001

Yes, a DRS system is completely independent from what Chris does. It is only conceptually that they belong together.

EDIT: as for me doing it, come on people! activate yourselves! I am busy designing the gui! I can't do it all!

23yrold3yrold
Member #1,134
March 2001
avatar

I've had my say. I don't know how and I don't care how. ;D

Haven't a few of you guys already made DRS systems? Clean it up and post it ...

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

Richard Phipps
Member #1,632
November 2001
avatar

There are plenty of people here who unlike me aren't busy.. cough X-G, cough.. :P

Steve Terry
Member #1,989
March 2002
avatar

I have mine, axilmar has his, both are completely independent of a screen update API, however if you want mine just copy nas_drs.h and nas_drs.c from the NAS library :P

___________________________________
[ 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

23yrold3yrold
Member #1,134
March 2001
avatar

DOKUMINTASHUN!!1

1 
2int initialize_screen_updating(int i);
3Initializes the screen update system. This function must be called after set_gfx_mode() and can be called with the following values:
4 
5 UPDATE_TRIPLE_BUFFER - standard triple buffering setup
6 UPDATE_PAGE_FLIP - standard page flipping setup
7 UPDATE_SYSTEM_BUFFER - double buffering system using a system bitmap
8 UPDATE_DOUBLE_BUFFER - double buffering system using a memory bitmap
9 UPDATE_TRIPLE_WMB - triple buffering, but with a memory bitmap buffer instead of a video bitmap
10 UPDATE_PAGEFLIP_WMB - page flipping, but with a memory bitmap buffer instead of a video bitmap
11 
12UPDATE_TRIPLE_WMB and UPDATE_PAGEFLIP_WMB are for times you're using a lot of blending or whatnot, and don't want your program slowed
13down due to reading from video memory. UPDATE_SYSTEM_BUFFER and UPDATE_DOUBLE_BUFFER don't synchronize to the vertical retrace of the
14screen unless vsync is enabled (by calling enable_vsync()). Note that these two mode alone are affected by the vsync functions; the
15triple buffering and page flipping modes automatically handle vertical retrace synchronisation.
16
17You can call this function multiple times in one program. So if you want the user to be able to switch between update methods to find
18one best suited to their system, it's as easy as calling initialize_screen_updating() again.
19 
20 
21void shutdown_screen_updating();
22Does what it says. Call this at the end of your program to prevent memory leaks.
23 
24 
25BITMAP* get_buffer();
26This function returns the drawing surface. Do all your drawing to this bitmap during your drawing code. It doesn't affect the screen
27until you call update_screen().
28
29
30void update_screen();
31Blits the buffer to the screen.
32
33
34int get_update_method();
35Returns the update method in the form of one of the six values listed under initialize_screen_updating().
36
37
38void enable_vsync();
39Makes update_screen() wait for a vertical retrace to end before updating the screen. Note this only affects UPDATE_SYSTEM_BUFFER and
40UPDATE_DOUBLE_BUFFER.
41
42
43void disable_vsync();
44Disables vertical retrace synchronisation for UPDATE_SYSTEM_BUFFER and UPDATE_DOUBLE_BUFFER modes.
45
46
47void toggle_vsync();
48Toggles vertical retrace synchronisation for UPDATE_SYSTEM_BUFFER and UPDATE_DOUBLE_BUFFER modes.
49
50
51int vsync_is_enabled();
52Returns whether vertical retrace synchronisation is enabled.

Anything to add?

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

Richard Phipps
Member #1,632
November 2001
avatar

Evert
Member #794
November 2000
avatar

Ah yes, I meant to ask about this:

Quote:

UPDATE_TRIPLE_WMB and UPDATE_PAGEFLIP_WMB are for times you're using a lot of blending or whatnot

What's the advantage over using a plain double buffer for this case? I don't see any, to be honest.

I have yet to merge the code with the current Allegro tree and API, although I have integrated it with a start for an improved graphics API (with a few changes - the initialization fails if a mode isn't supported rather than trying another one, for instance).

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

What's the advantage over using a plain double buffer for this case? I don't see any, to be honest.

Neither do I. I just put it in at the request of others, and the more I think about it the dumber it seems. ::)

Quote:

the initialization fails if a mode isn't supported rather than trying another one, for instance

What?! I was so proud of that! :'( ;)

PS: Would it be safe to install shutdown_screen_updating() as one of those atexit() function calls?

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

Richard Phipps
Member #1,632
November 2001
avatar

I use it. Trust me it's very good. Especially with a scrolling screen as you have the advantages of a memory bitmap with smooth updating without flickering. :)

Evert
Member #794
November 2000
avatar

Quote:

What?! I was so proud of that! :'( ;)

Well, it went into what is basically a replacement for set_gfx_mode(), and it felt a bit too complicated. My take here was to have the function do what it's asked to do and not try to be smart if it can't do it. ;)
Anyway, for the curious, my initial draft sitting on top of Allegro's current API is attached. This'll be post 4.2 material though.

Quote:

Especially with a scrolling screen as you have the advantages of a memory bitmap with smooth updating without flickering.

I still don't really see the advantage over a plain double buffer, actually...

23yrold3yrold
Member #1,134
March 2001
avatar

Oh, okay. You've made some huge changes there. :)

I'll submit it as is to the code resource then.

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

Evert
Member #794
November 2000
avatar

I plan to backport it to 4.1 though. Don't let that stop you anyway. ;)



Go to: