I think I'm about to give up on SDL :(

Sorry if this is a repost, I tried putting this up before but I don’t think it made it. The filters must
have not liked me attaching my coded tarred and zip.

Here’s the low down on what’s going on:

I've written a little sdl app that blits 64x48 tiles to screen and does scrolling by continuously

redrawing all the tiles in different spots based on the position of an SDL_Rect I call VRect (for View
Rectangle). It’s slow, painfully slow. But if I hold a key while scrolling it speeds up a lot. The scrolling
will take about half the time with a key down (I’ve measured it with SDL_GetTicks and can see with my own
eyes how much faster the scrolling is). That’s when the app has got focus. Here’s where it gets worse.
If the app is out of focus it’ll speed up; and if I hold a key in whatever app I just switched to my little
scroll app speeds up even more. At that point it looks like I’m getting a full
frame rate (30+).

What's even worse is I'm able to replicate the error in the test code

include with the api. I modified testsprite.c so that it dies with a mouse
down event instead of a keydown event (Just changed KEYDOWN to MOUSEBUTTONDOWN
in the event loop). Sure enough testsprite behaves exactly like my scroll app.
On the other hand I have the Raptor demo and don’t get this behavior, nor in
any other X widows game.

Here’s my system:

Redhat 6.1 with kernel 2.2.5-15
XFree86 4.01, Nvidia kernel driver v095 loading and running, GLX is broken
kde with kwm running
All surfaces appear to be software (At least that’s what testsprite reports).

Here’s what I’ve tried so far:

Made sure I’m only initializing the video subsystem, but I know it initializes the event polling mechanism.

Disabled loading of the GLX Driver, I’ve had problems with it so I thought it might be a problem

Ran a simple x server without a window manager with only and xterm and the
scroll app running (exec xterm in my .xinitrc)

Renice the scroll app to a higher priority

Removed ALL explicit input function calls (i.e. event polling). I can’t remove the implicit initialization of
the SDL event handling system done when the video subsystem is initialized, at least not right now since
I don’t know how.

Tried both the official nvidia driver for my tnt1 and the one that came with x4.0

I haven’t tried disabling DGA in X4.0, my tvcard needs it so it’s enabled right
now, but that seems like a long shot

At this point I'd like to know if there's some way to disable event

polling. It’s the only thing I can think of to try. I’m going to attach my
code at the end. If anyone has some free time and some clue about what’s
going on I’d appreciate it. If there’s anything I left out please let me know.
I’m pretty much at my wits end and I’m a sad to say I’m starting to miss
win32 and directx. Is Linux ever going to have an easy to configure multimedia
api?

/*Here’s my little 'ol app. spot_tile.bmp and brick.bmp are just 64x48 bitmaps I use for tiles
A Word or two about how it (suppositly) works: A retangle representing the area of the TileMap
that is visable on screen is maintained. I call this the ViewRectangle or VRect for short.It’s
passes to a function called DrawTiles() that uses the VRect to index the tile map and also to
figure out where to start drawing tiles. It’s a brute force approach but it works
*/

//includes
#include <stdio.h>
#include “SDL.h”
#include <SDL/SDL_thread.h>
//end includes

//typedefs
#define X_TILE_SIZE 64
#define Y_TILE_SIZE 48
#define SCREEN_EXTENT_X 640
#define SCREEN_EXTENT_Y 480
#define NUM_TILES_X 10
#define NUM_TILES_Y 40
#define WORLD_MAP_EXTENT_X (X_TILE_SIZE * NUM_TILES_X)
#define WORLD_MAP_EXTENT_Y (Y_TILE_SIZE * NUM_TILES_Y)
//end of typedefs

//function decs
SDL_Surface* LoadImage( char* file );
int DrawTiles(SDL_Rect* WorldCoordsRect);
int TileDrawThread(void *DrawTiles_Thread_Local);
//end function decs

//globals
SDL_Surface screen;
int done = 0;
int exit_flag = 0;
SDL_Event event;
char TileMap[NUM_TILES_X][NUM_TILES_Y];
SDL_Surface
Tiles[2];
SDL_Rect VRect;
//end globals

int main(){

    int initial_ticks;//I'll use this to mesure how long it takes to do the scroll
int final_ticks;

VRect.x = 0;
VRect.y = 0;//WORLD_MAP_EXTENT_Y - 640;
    VRect.w = 640;
VRect.h = 640;//WORLD_MAP_EXTENT_Y;

/* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
	fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
	exit(1);
}

if ( (screen=SDL_SetVideoMode(640,480, 16, SDL_ANYFORMAT )) == NULL ) {
	fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
							SDL_GetError());
	exit(2);
}

//load the tiles
Tiles[0] = LoadImage( “spot_tile.bmp” );
Tiles[1] = LoadImage( “brick.bmp” );

//initialize the tilemap with 0’s and 1’s to point to the two tiles I just loaded
for(int j = 0; j < 40; j++){

	for(int i = 0; i < 10; i++){

		TileMap[i][j] = i % 2;

	}//end for loop i

}//end for loop j

initial_ticks = SDL_GetTicks(); //time how long it takes to scroll the map twice

//Here’s where the scrolling is done. VRect stands for view rectangle and is an SDL_Rect. VRect
//is the size of one screen (640x480) and it’s position is used to indicate which tiles are
//currently visable. By moving the VRect and Calling DrawTiles with VRect as and argument
//scrolling is done.
while ( VRect.y > 0 ){

    	DrawTiles(&VRect);
	VRect.y -= 5;
	VRect.h -= 5;

}//end while ( VRect.y > 0 )

while ( VRect.h < WORLD_MAP_EXTENT_Y ){

     	DrawTiles(&VRect);
	VRect.y += 5;
	VRect.h += 5;

}//end while ( VRect.h < WORLD_MAP_EXTENT_Y )

final_ticks = SDL_GetTicks();
printf("Time to do 2 scrolls: %d\n", final_ticks);		

SDL_Quit();

return 0;

}//end main

SDL_Surface* LoadImage( char* file ){

SDL_Surface* temp = NULL;

/* Load an image */
temp = SDL_LoadBMP(file);
if ( temp == NULL ) {
fprintf(stderr, “Couldn’t load %s: %s\n”, file, SDL_GetError());////////
exit(1);
}

/* Convert image to video format */
temp = SDL_DisplayFormat(temp);

if ( temp == NULL ) {
	fprintf(stderr, "Couldn't convert background: %s\n",
						SDL_GetError());
	exit(1);
}

return temp;

}//end methond LoadImage

//Right now this function only works for drawing a full screen of tiles, there are some overdraw issues
// to fix (i.e. drawing more tiles then it needs to). Also, right now it assumes if you pass it a Rect
// with tiles to draw that you want those tiles drawn, wheather the VRect is over them or not. This
// is an engine issue more than anything else
int DrawTiles(SDL_Rect* WorldCoordsRect){

SDL_Rect destpts, Blit_Tiles_Extents, SDL_Blit_Rect;
int first_destpts_x;

destpts.x = -(WorldCoordsRect->x % X_TILE_SIZE);
destpts.y = -(WorldCoordsRect->y % Y_TILE_SIZE);

first_destpts_x = destpts.x;

Blit_Tiles_Extents.x = WorldCoordsRect->x / X_TILE_SIZE;
Blit_Tiles_Extents.y = WorldCoordsRect->y / Y_TILE_SIZE;
    Blit_Tiles_Extents.w = WorldCoordsRect->w / X_TILE_SIZE;
Blit_Tiles_Extents.h = WorldCoordsRect->h / Y_TILE_SIZE;

// The following lines of code make sure that when Blit_Tiles_Extents’ members are use to form
//Tile map indexes those indexes don’t overrun the bounds of the array
if ( Blit_Tiles_Extents.x < 0 )
Blit_Tiles_Extents.x = 0;
if ( Blit_Tiles_Extents.y < 0 )
Blit_Tiles_Extents.y = 0;
if ( Blit_Tiles_Extents.w > (NUM_TILES_X) )
Blit_Tiles_Extents.w = (NUM_TILES_X-1);
if ( Blit_Tiles_Extents.h > (NUM_TILES_Y) )
Blit_Tiles_Extents.h = (NUM_TILES_Y-1);

// The following lines of code make sure that partial tile get blited, SDL handles the clipping here
if( Blit_Tiles_Extents.x > 0 )
Blit_Tiles_Extents.x–;
if( Blit_Tiles_Extents.y > 0 )
Blit_Tiles_Extents.y–;
if( Blit_Tiles_Extents.w < (NUM_TILES_X) )
Blit_Tiles_Extents.w++;
if( Blit_Tiles_Extents.h < (NUM_TILES_Y) )
Blit_Tiles_Extents.h++;

for( int j = Blit_Tiles_Extents.y; j < Blit_Tiles_Extents.h; j++){

	for( int i = Blit_Tiles_Extents.x; i < Blit_Tiles_Extents.w; i++){
		SDL_Blit_Rect.x = destpts.x;
		SDL_Blit_Rect.y = destpts.y;	

	//HERE'S THE BLIT
		SDL_BlitSurface(Tiles[ TileMap[i][j] ], NULL, screen, &SDL_Blit_Rect );


		destpts.x += X_TILE_SIZE;

	}//end for loop i

	destpts.y += Y_TILE_SIZE;
	destpts.x = first_destpts_x;

}//end for loop j

//right now I’m just redrawing the whole screen, I’ll fix that when I start optimizing
SDL_UpdateRect(screen, 0,0,640,480);

return 0;

}//end of program main–
Jeremy Gregorio
jgreg at azstarnet.com


Jeremy Gregorio
jgreg at azstarnet.com

Jeremy Gregorio wrote:

If there’s anything I left out please let me know.

Well, you never metion testing it on a machine with different hardware. Most problems people find with
GNU/Linux has to do with hardware (since I know that the SDL event polling system works fine on my computer). I
tested the attached source, and did NOT get the observed functionality.

My setup:

200 Mhz Intel Pentium I w/ MMX
S3 Virge Video card
RedHat 6.1

It’ll problably be good feed back if more people test your code (and by the way, more people would problably try
if you sent it in an easier to use format. A tar-gz is very nice.)

I’m pretty much at my wits end and I’m a sad to say I’m starting to miss
win32 and directx.

I think you’re the only person I have ever heard utter those words…

-- David Snopek

Thanks for testing my code, It’s reasurring to know it’s not my
hardware. I tied sending the message with a tared gz once before and it didn’t
show up, so I figured the list bot filtered it out for some reason. In defence
of windows and directx once you’ve got the positivly gastly initialization
process out of the way you can fall back on blits and ansi c.

Anyway, I'm gonna try attaching the code to this message in tarred and

gz form with the bitmaps included. I’m sure it’s a problem with my system, and
it’s probably a software configuration issue. What really bugs me is that
raptor doesn’t exibit the problem. I’m wondering if it handles input
differently?–
Jeremy Gregorio
jgreg at azstarnet.com
-------------- next part --------------
A non-text attachment was scrubbed…
Name: scroll.tar.gz
Type: application/x-gzip
Size: 20 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20001112/6995972a/attachment.bin

Thanks for testing my code, It’s reasurring to know it’s not my
hardware. I tied sending the message with a tared gz once before and it didn’t
show up, so I figured the list bot filtered it out for some reason. In defence
of windows and directx once you’ve got the positivly gastly initialization
process out of the way you can fall back on blits and ansi c.

Anyway, I’m gonna try attaching the code to this message in tarred and
gz form with the bitmaps included. I’m sure it’s a problem with my system, and
it’s probably a software configuration issue. What really bugs me is that
raptor doesn’t exibit the problem. I’m wondering if it handles input
differently?

It’s possible. Can you reattach your code? Your attachment was only 21
bytes long. :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

It’s possible. Can you reattach your code? Your attachment was only 21
bytes long. :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sorry, I think I tried to send a file owned by my root account in my

user account, got my file permissions cleared up now (if you can’t tell I’m a
newbie :)…).–
Jeremy Gregorio
jgreg at azstarnet.com
-------------- next part --------------
A non-text attachment was scrubbed…
Name: scroll.tar.gz
Type: application/x-gzip
Size: 4012 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20001112/9b734888/attachment.bin

I do not experience the speedup you describe (i386/debian woody/xfree86-4.0.1/SDL-1.1.6)

BLiP!

Unfortunately, I’ve heard very similar statements (although very
few, and usually stemming from temporary irritation due to setup
problems) from other Linux developers.

I’m seriously annoyed myself at times (latest example; being forced
to manually figure out and fix everything that a Red Hat 7.0
"upgrade" broke on my system - DON’T try it! Wait for 7.1…), but
some previous experiences with Windows have ensured that I’ll never
go there again, possibly except for supporting it as a lower priority
target platform. Delphi is about the only reason why I still do some
application development at work.

Anyway, these kind of comments will probably be heard occasionally
until all functionality that’s readily available on a standard
Windows installation comes with the average Linux distro installer,
and is rock solid on any supported hardware.

Also, the generally high quality of the major Linux software packages

  • development versions included - seems to have resulted in people
    forgetting what development versions actually are…

//David

.- M u C o S -------------------------. .- David Olofson --------.
| A Free/Open Source | | Audio Hacker |
| Plugin and Integration Standard | | Linux Advocate |
| for | | Open Source Advocate |
| Professional and Consumer | | Singer |
| Multimedia | | Songwriter |
-----> http://www.linuxdj.com/mucos -'—> david at linuxdj.com -'On Mon, 13 Nov 2000, David Snopek wrote:

I’m pretty much at my wits end and I’m a sad to say I’m starting to miss
win32 and directx.

I think you’re the only person I have ever heard utter those words…

[…]

Disabled loading of the GLX Driver, I’ve had problems with it so I thought it might be a problem

Are we speaking Utah-GLX? AFAIK, there’s still no version for 4.x,
and there probably won’t be, as the preferred 3D acceleration driver
API for 4.x is DRI.

(And I still can’t seem to get the G400 DRI driver to work, BTW. GLX
0.1.0-pre1 on 3.3.6 works great, though, so I’m using a dual X
install for now.)

Ran a simple x server without a window manager with only and xterm and the
scroll app running (exec xterm in my .xinitrc)

Renice the scroll app to a higher priority

Removed ALL explicit input function calls (i.e. event polling). I can’t remove the implicit initialization of
the SDL event handling system done when the video subsystem is initialized, at least not right now since
I don’t know how.

Tried both the official nvidia driver for my tnt1 and the one that came with x4.0

I haven’t tried disabling DGA in X4.0, my tvcard needs it so it’s enabled right
now, but that seems like a long shot

Nothing is a long shot when you’re hunting weird bugs…! :wink:

At this point I’d like to know if there’s some way to disable event
polling. It’s the only thing I can think of to try. I’m going to attach my
code at the end. If anyone has some free time and some clue about what’s
going on I’d appreciate it. If there’s anything I left out please let me know.
I’m pretty much at my wits end and I’m a sad to say I’m starting to miss
win32 and directx. Is Linux ever going to have an easy to configure multimedia
api?

Well, it has worked pretty smoothly for me so far, but it’s
inherently complicated to make packages such as SDL install and work
nicely on all these possible configurations. Choice is Good in
general, but nothing comes for free…

It’ll probably take some time to get Linux based systems to where
Windows is now in this respect, but then again, developers being able
to help out by tracking down and fixing problems that show up on
their systems, should help. I firmly believe that this model works
better in the long run, especially for drivers, system software and
other low level stuff that many applications use.

I’m off to work soon, but I’ll try your code tonight.

//David

.- M u C o S -------------------------. .- David Olofson --------.
| A Free/Open Source | | Audio Hacker |
| Plugin and Integration Standard | | Linux Advocate |
| for | | Open Source Advocate |
| Professional and Consumer | | Singer |
| Multimedia | | Songwriter |
-----> http://www.linuxdj.com/mucos -'—> david at linuxdj.com -'On Mon, 13 Nov 2000, Jeremy Gregorio wrote:

Jeremy Gregorio wrote:

    Thanks for testing my code, It's reasurring to know it's not my

hardware.

I believe you misinterpreted what I wrote. I DID NOT experience a speed up
during a test press. I was saying that the problem DOES sounds like a conflict
with your hardware, since I (and I believe many others) do not experiece any
problems with the SDL event polling system.

-- David Snopek

If someone is still interested, this piece of code works perfectly for
me… :).

Linux 2.2.16 (slackware 7.1), v3 1000 & xfree 3.3.6, K6III-429 :slight_smile:

Come on man, cheer up & don’t give up. SDL rocks :). I’m sorry I can’t help
you, but I simply don’t see any problem :).–
//////////////\

//////////////

Thanks for trying out my code. At this point I’m wondering if it’s maybe just
my hardware. My motherboard isn’t exatly high quality (tried to track down the
manufacturer and found out the bios code points to nobody). Right now I’m
trying to figure out how to get SDL running with svgalib as a basis instead of
X windows. I’ve got svgalib working great with games like doom and heretic,
it’s really impressed me, but I really like SDL’s interface. It’s got the
cleanest framebuffer abstraction I’ve seen so far, and the free image loader
libraries are great. It’s all so simple and to the point. It’s what I wanted
directx to be when I was programing that. Besides, it bugs the heck out of me
to have something in my system doing something for no good reason. That’s half
the reason I switched over to Linux in the first place :)…On Tue, 14 Nov 2000, you wrote:

If someone is still interested, this piece of code works perfectly for
me… :).

Linux 2.2.16 (slackware 7.1), v3 1000 & xfree 3.3.6, K6III-429 :slight_smile:

Come on man, cheer up & don’t give up. SDL rocks :). I’m sorry I can’t help
you, but I simply don’t see any problem :).


//////////////\

//////////////

Jeremy Gregorio
jgreg at azstarnet.com

Please send code again!!!

My be able to help.
And what the problem is.
Must have missed the first post.

Rdrio> ----- Original Message -----

From: jgreg@azstarnet.com (Jeremy Gregorio)
To:
Sent: Saturday, November 18, 2000 1:13 AM
Subject: Re: [SDL] I think I’m about to give up on SDL :(…

On Tue, 14 Nov 2000, you wrote:

If someone is still interested, this piece of code works perfectly for
me… :).

Linux 2.2.16 (slackware 7.1), v3 1000 & xfree 3.3.6, K6III-429 :slight_smile:

Come on man, cheer up & don’t give up. SDL rocks :). I’m sorry I can’t
help

you, but I simply don’t see any problem :).


//////////////\

//////////////
Thanks for trying out my code. At this point I’m wondering if it’s maybe
just
my hardware. My motherboard isn’t exatly high quality (tried to track down
the
manufacturer and found out the bios code points to nobody). Right now I’m
trying to figure out how to get SDL running with svgalib as a basis
instead of
X windows. I’ve got svgalib working great with games like doom and
heretic,
it’s really impressed me, but I really like SDL’s interface. It’s got the
cleanest framebuffer abstraction I’ve seen so far, and the free image
loader
libraries are great. It’s all so simple and to the point. It’s what I
wanted
directx to be when I was programing that. Besides, it bugs the heck out of
me
to have something in my system doing something for no good reason. That’s
half
the reason I switched over to Linux in the first place :)…


Jeremy Gregorio
jgreg at azstarnet.com

Thanks for trying out my code. At this point I’m wondering if it’s maybe just
my hardware. My motherboard isn’t exatly high quality (tried to track down the
manufacturer and found out the bios code points to nobody). Right now I’m
trying to figure out how to get SDL running with svgalib as a basis instead of
X windows.

What problems are you having? Try dropping by the SDL IRC channel today
(irc.openprojects.net #SDL) and I’m sure somebody there can give you a hand.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

My problem’s pretty strange, I wrote a simple sdl app that draws a
screen full of tiles to the display over and over to do scrolling. It’s pretty
slow, which I expected since I’m using a brute force approach. But whenever
input (mouse or keybord it seems) goes into the system the app will speed up
messurably. The app doesn’t even need to have focus. Although at first
I thought not having focus itself would speed up the app, later I
realized that wasn’t the case (my highly optimized X server wasn’t
drawing what wasn’t visable so the app would speed up then :slight_smile: ).

Here’s a quick list of stuff I tried:

  1. Wrote in an event filter to stop all events from being qued.

  2. tried a simple X session (xinit exec xterm). No window manager or anything.

  3. when around randomly killing suspicous processes.

  4. Tried both nvida’s driver and the default X driver

  5. Tried disabling glx support. It wasn’t properly configured to begin with, so
    I thought it might be a problem.

  6. Tried putting the input in it’s own thread just for the heck of it.

Here’s my system:

redhat 6.1 with X4.0 running nvidia’s X driver\kernel module, kde 1.1,
kernel version 2.2.5-15,
sdl 1.1.6

later tonight (I’ll be out all day today unfortunatly) I’m gonna try
recompiling sdl with svgalib support and try without the x server at all.

Oh, and BTW, thanks to everybody who’s helped me along so far. SDL’s got a
really great community of programmers going for it :).On Sat, 18 Nov 2000, you wrote:

Please send code again!!!

My be able to help.
And what the problem is.
Must have missed the first post.


Jeremy Gregorio
jgreg at azstarnet.com