[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Chris wrote:
As I just said to Peter on IRC, I think not yielding in the test's
timing loops is causing a problem. Without yielding, I get poor visual
performance (I get a good count, its just that the screen has problems
with updating and I have problems with clicking the mouse to continue)
but after adding a rest(0) it becomes very responsive and draws super
fast again. Attached is a patch that adds rest(0) to the next() function.
Here's an alternative patch. The problem that occurred in the blitting
tests seems to be that when the screen was constantly updated, Allegro
would be making heaps of calls to Xlib to request the X server to update
the window contents. However, Xlib queues up those requests and appears
to discard or merge requests that it thinks are redundant, e.g.
overwriting the same parts of the screen really quickly in succession.
... I think. It might be bullshit.
Anyhoo, talking to Chris on #allegro, I got the idea to flush Xlib's
output buffer at the end of release_bitmap(). That's what the patch
does. I guess it would cause more network traffic on a remote X
server. AFAIK the patch doesn't introduce any potential deadlock that
wasn't already present in the cvs trunk, although it might make such
deadlocks more likely.
extrans and exalpha seems to have gotten jerkier after this patch. So I
also attached another patch that makes *them* yield ;-) which I think
they should be doing regardless.
Peter
Index: include/allegro/platform/aintunix.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/platform/aintunix.h,v
retrieving revision 1.8
diff -u -r1.8 aintunix.h
--- include/allegro/platform/aintunix.h 27 Jul 2004 10:33:21 -0000 1.8
+++ include/allegro/platform/aintunix.h 11 Sep 2004 05:44:05 -0000
@@ -86,6 +86,7 @@
AL_ARRAY(_DRIVER_INFO, _xwin_mouse_driver_list);
AL_ARRAY(_DRIVER_INFO, _xwin_timer_driver_list);
+ AL_FUNC(void, _xwin_private_flush_buffers, (void));
AL_FUNC(void, _xwin_handle_input, (void));
AL_FUNC(void, _xwin_private_handle_input, (void));
Index: src/x/xvtable.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xvtable.c,v
retrieving revision 1.14
diff -u -r1.14 xvtable.c
--- src/x/xvtable.c 6 Sep 2004 22:52:45 -0000 1.14
+++ src/x/xvtable.c 11 Sep 2004 05:44:07 -0000
@@ -154,6 +154,9 @@
*/
void _xwin_unlock(BITMAP *bmp)
{
+ if (_xwin.screen_lock_count == 1)
+ _xwin_private_flush_buffers();
+
_xwin.screen_lock_count--;
if (_xwin.screen_lock_count == 0)
XUNLOCK();
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.70
diff -u -r1.70 xwin.c
--- src/x/xwin.c 6 Sep 2004 22:52:46 -0000 1.70
+++ src/x/xwin.c 11 Sep 2004 05:44:10 -0000
@@ -200,7 +200,6 @@
static void _xwin_private_set_palette_colors(AL_CONST PALETTE p, int from, int to);
static void _xwin_private_set_palette_range(AL_CONST PALETTE p, int from, int to, int vsync);
static void _xwin_private_set_window_defaults(void);
-static void _xwin_private_flush_buffers(void);
static void _xwin_private_resize_window(int w, int h);
static void _xwin_private_process_event(XEvent *event);
static void _xwin_private_set_warped_mouse_mode(int permanent);
@@ -2125,7 +2124,7 @@
/* _xwin_flush_buffers:
* Flush input and output X-buffers.
*/
-static void _xwin_private_flush_buffers(void)
+void _xwin_private_flush_buffers(void)
{
if (_xwin.display != 0)
XSync(_xwin.display, False);
Index: examples/exalpha.c
===================================================================
RCS file: /cvsroot/alleg/allegro/examples/exalpha.c,v
retrieving revision 1.4
diff -u -r1.4 exalpha.c
--- examples/exalpha.c 2 Aug 2004 11:33:09 -0000 1.4
+++ examples/exalpha.c 11 Sep 2004 05:44:04 -0000
@@ -19,7 +19,8 @@
BITMAP *buffer;
int bpp = -1;
int ret = -1;
- int x, y, c, a;
+ int x, y, ox, oy;
+ int c, a;
if (allegro_init() != 0)
return 1;
@@ -134,11 +135,22 @@
background = create_bitmap(SCREEN_W, SCREEN_H);
blit(buffer, background, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
+ ox = -1;
+ oy = -1;
+
while (!keypressed()) {
- /* draw the alpha sprite */
x = mouse_x - sprite->w/2;
y = mouse_y - sprite->h/2;
+ if ((x == ox) && (y == oy)) {
+ rest(0);
+ continue;
+ }
+
+ ox = x;
+ oy = y;
+
+ /* draw the alpha sprite */
set_alpha_blender();
draw_trans_sprite(buffer, sprite, x, y);
Index: examples/extrans.c
===================================================================
RCS file: /cvsroot/alleg/allegro/examples/extrans.c,v
retrieving revision 1.9
diff -u -r1.9 extrans.c
--- examples/extrans.c 2 Aug 2004 11:33:09 -0000 1.9
+++ examples/extrans.c 11 Sep 2004 05:44:05 -0000
@@ -30,7 +30,7 @@
BITMAP *spotlight;
BITMAP *truecolor_spotlight;
BITMAP *background;
- int i, x, y;
+ int i, x, y, ox, oy;
char buf[256];
char *filename;
@@ -88,12 +88,22 @@
color_map = &light_table;
/* display a spotlight effect */
+ ox = -1;
+ oy = -1;
do {
poll_mouse();
x = mouse_x - SCREEN_W/2 - 64 + 160;
y = mouse_y - SCREEN_H/2 - 64 + 100;
+ if ((x == ox) && (y == oy)) {
+ rest(1);
+ continue;
+ }
+
+ ox = x;
+ oy = y;
+
clear_bitmap(s);
/* unluckily we have to do something 'weird' for truecolor modes */
@@ -140,12 +150,22 @@
set_trans_blender(0, 0, 0, 128);
/* display a translucent overlay */
+ ox = -1;
+ oy = -1;
do {
poll_mouse();
x = mouse_x - SCREEN_W/2 - 64 + 160;
y = mouse_y - SCREEN_H/2 - 64 + 100;
+ if ((x == ox) && (y == oy)) {
+ rest(1);
+ continue;
+ }
+
+ ox = x;
+ oy = y;
+
blit(background, s, 0, 0, 0, 0, 320, 200);
draw_trans_sprite(s, spotlight, x, y);