[Scummvm-cvs-logs] CVS: scummvm/backends/sdl sdl-common.cpp,1.5,1.6 sdl-common.h,1.3,1.4 sdl.cpp,1.6,1.7 sdl_gl.cpp,1.4,1.5

Max Horn fingolfin at users.sourceforge.net
Fri Sep 27 06:06:04 CEST 2002


Update of /cvsroot/scummvm/scummvm/backends/sdl
In directory usw-pr-cvs1:/tmp/cvs-serv25782/sdl

Modified Files:
	sdl-common.cpp sdl-common.h sdl.cpp sdl_gl.cpp 
Log Message:
made init_size in the SDL backend reentrant

Index: sdl-common.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl-common.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- sdl-common.cpp	20 Sep 2002 00:12:58 -0000	1.5
+++ sdl-common.cpp	27 Sep 2002 13:05:53 -0000	1.6
@@ -69,21 +69,39 @@
 	SDL_SetTimer(timer, (SDL_TimerCallback) callback);
 }
 
+OSystem_SDL_Common::OSystem_SDL_Common()
+	: sdl_screen(0), SCREEN_WIDTH(0), SCREEN_HEIGHT(0),
+	_dirty_checksums(0), _current_shake_pos(0), _new_shake_pos(0)
+{
+	// allocate palette storage
+	_cur_pal = (SDL_Color*)calloc(sizeof(SDL_Color), 256);
+
+	// allocate the dirty rect storage
+	_mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2);
+}
+
+OSystem_SDL_Common::~OSystem_SDL_Common()
+{
+	if (_dirty_checksums)
+		free(_dirty_checksums);
+	free(_cur_pal);
+	free(_mouse_backup);
+}
+
 void OSystem_SDL_Common::init_size(uint w, uint h) {
-	//if (w != SCREEN_WIDTH && h != SCREEN_HEIGHT)
-	//	error("320x200 is the only game resolution supported");
+
+	// Avoid redundant res changes
+	if (w == SCREEN_WIDTH && h == SCREEN_HEIGHT)
+		return;
 
 	SCREEN_WIDTH = w;
 	SCREEN_HEIGHT = h;
 	CKSUM_NUM = (SCREEN_WIDTH*SCREEN_HEIGHT/(8*8));
-	/* allocate palette, it needs to be persistent across
-	 * driver changes, so i'll alloc it here */
-	_cur_pal = (SDL_Color*)calloc(sizeof(SDL_Color), 256);
-
-	dirty_rect_list = (SDL_Rect*)calloc(NUM_DIRTY_RECT, sizeof(SDL_Rect));
-	_mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2);
-	dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32));
+	if (_dirty_checksums)
+		free(_dirty_checksums);
+	_dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32));
 
+	unload_gfx_mode();
 	load_gfx_mode();
 
 #ifdef MACOSX		// Work around a bug in OS X 10.1 related to OpenGL in windowed mode
@@ -179,7 +197,7 @@
 	if (num_dirty_rects == NUM_DIRTY_RECT)
 		force_full = true;
 	else {
-		SDL_Rect *r = &dirty_rect_list[num_dirty_rects++];
+		SDL_Rect *r = &_dirty_rect_list[num_dirty_rects++];
 		
 		/* Update the dirty region by 1 pixel for graphics drivers
 		 * that "smear" the screen */
@@ -206,7 +224,7 @@
 #define ROL(a,n) a = (a<<(n)) | (a>>(32-(n)))
 #define DOLINE(x) a ^= ((uint32*)buf)[0+(x)*(SCREEN_WIDTH/4)]; b ^= ((uint32*)buf)[1+(x)*(SCREEN_WIDTH/4)]
 void OSystem_SDL_Common::mk_checksums(const byte *buf) {
-	uint32 *sums = dirty_checksums;
+	uint32 *sums = _dirty_checksums;
 	uint x,y;
 	const uint last_x = (uint)SCREEN_WIDTH/8;
 	const uint last_y = (uint)SCREEN_HEIGHT/8;
@@ -255,7 +273,7 @@
 		 into bigger ones in a simple way */
 	if (!force_full) {
 		int x,y,w;
-		uint32 *ck = dirty_checksums;
+		uint32 *ck = _dirty_checksums;
 		
 		for(y=0; y!=SCREEN_HEIGHT/8; y++) {
 			for(x=0; x!=SCREEN_WIDTH/8; x++,ck++) {
@@ -278,7 +296,7 @@
 	} else {
 		get_out:;
 		/* Copy old checksums to new */
-		memcpy(dirty_checksums + CKSUM_NUM, dirty_checksums, CKSUM_NUM * sizeof(uint32));
+		memcpy(_dirty_checksums + CKSUM_NUM, _dirty_checksums, CKSUM_NUM * sizeof(uint32));
 	}
 }
 

Index: sdl-common.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl-common.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sdl-common.h	19 Sep 2002 16:06:47 -0000	1.3
+++ sdl-common.h	27 Sep 2002 13:05:54 -0000	1.4
@@ -133,9 +133,9 @@
 	};
 
 	int SCREEN_WIDTH, SCREEN_HEIGHT, CKSUM_NUM;
-	SDL_Rect *dirty_rect_list;
+	SDL_Rect _dirty_rect_list[100];
 	int num_dirty_rects;
-	uint32 *dirty_checksums;
+	uint32 *_dirty_checksums;
 
 	int scaling;
 
@@ -165,7 +165,8 @@
 
 	uint _palette_changed_first, _palette_changed_last;
 
-	OSystem_SDL_Common() : _current_shake_pos(0), _new_shake_pos(0) {}
+	OSystem_SDL_Common();
+	virtual ~OSystem_SDL_Common();
 
 	void add_dirty_rgn_auto(const byte *buf);
 	void mk_checksums(const byte *buf);

Index: sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- sdl.cpp	22 Sep 2002 16:12:37 -0000	1.6
+++ sdl.cpp	27 Sep 2002 13:05:54 -0000	1.7
@@ -27,6 +27,8 @@
 
 class OSystem_SDL_Normal : public OSystem_SDL_Common {
 public:
+	OSystem_SDL_Normal() : sdl_tmpscreen(0), sdl_hwscreen(0) {}
+
 	// Set colors of the palette
 	void set_palette(const byte *colors, uint start, uint num);
 
@@ -337,10 +339,10 @@
 	if (force_full) {
 		num_dirty_rects = 1;
 
-		dirty_rect_list[0].x = 0;
-		dirty_rect_list[0].y = 0;
-		dirty_rect_list[0].w = SCREEN_WIDTH;
-		dirty_rect_list[0].h = SCREEN_HEIGHT;
+		_dirty_rect_list[0].x = 0;
+		_dirty_rect_list[0].y = 0;
+		_dirty_rect_list[0].w = SCREEN_WIDTH;
+		_dirty_rect_list[0].h = SCREEN_HEIGHT;
 	}
 
 	// Only draw anything if necessary
@@ -348,12 +350,12 @@
 	
 		SDL_Rect *r; 
 		uint32 srcPitch, dstPitch;
-		SDL_Rect *last_rect = dirty_rect_list + num_dirty_rects;
+		SDL_Rect *last_rect = _dirty_rect_list + num_dirty_rects;
 	
 		// Convert appropriate parts of the 8bpp image into 16bpp
 		if (!_overlay_visible) {
 			SDL_Rect dst;
-			for(r=dirty_rect_list; r!=last_rect; ++r) {
+			for(r=_dirty_rect_list; r!=last_rect; ++r) {
 				dst = *r;
 				dst.x++;	// Shift rect by one since 2xSai needs to acces the data around
 				dst.y++;	// any pixel to scale it, and we want to avoid mem access crashes.
@@ -368,7 +370,7 @@
 		srcPitch = sdl_tmpscreen->pitch;
 		dstPitch = sdl_hwscreen->pitch;
 	
-		for(r=dirty_rect_list; r!=last_rect; ++r) {
+		for(r=_dirty_rect_list; r!=last_rect; ++r) {
 			register int dst_y = r->y + _current_shake_pos;
 			register int dst_h = 0;
 			if (dst_y < SCREEN_HEIGHT) {
@@ -389,8 +391,8 @@
 		}
 	
 		if (force_full) {
-			dirty_rect_list[0].y = 0;
-			dirty_rect_list[0].h = SCREEN_HEIGHT * scaling;
+			_dirty_rect_list[0].y = 0;
+			_dirty_rect_list[0].h = SCREEN_HEIGHT * scaling;
 		}
 		
 		SDL_UnlockSurface(sdl_tmpscreen);
@@ -399,7 +401,7 @@
 	
 	if (num_dirty_rects > 0) {
 		/* Finally, blit all our changes to the screen */
-		SDL_UpdateRects(sdl_hwscreen, num_dirty_rects, dirty_rect_list);
+		SDL_UpdateRects(sdl_hwscreen, num_dirty_rects, _dirty_rect_list);
 	}
 
 	num_dirty_rects = 0;

Index: sdl_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl_gl.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- sdl_gl.cpp	19 Sep 2002 16:06:48 -0000	1.4
+++ sdl_gl.cpp	27 Sep 2002 13:05:54 -0000	1.5
@@ -141,6 +141,7 @@
 		_palette_changed_last = 0;
 	}
 
+	// FIXME - this seems to be tied to 320x200 - what about Zak256 which needs 320x240 ?
 	fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos);
 
 }





More information about the Scummvm-git-logs mailing list