[Scummvm-cvs-logs] CVS: scummvm main.cpp,1.1,1.2 scummvm.cpp,1.106,1.107 sdl.cpp,1.86,1.87

Ludvig Strigeus strigeus at users.sourceforge.net
Sat Apr 13 05:44:03 CEST 2002


Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv11446

Modified Files:
	main.cpp scummvm.cpp sdl.cpp 
Log Message:
full screen mode works now (even if SDL doesn't support it)



Index: main.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/main.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** main.cpp	12 Apr 2002 21:26:59 -0000	1.1
--- main.cpp	13 Apr 2002 12:43:02 -0000	1.2
***************
*** 56,60 ****
  		return (-1);
  
! 	OSystem *system = OSystem_SDL_create(detector._gfx_mode, false);
  
  	{
--- 56,60 ----
  		return (-1);
  
! 	OSystem *system = OSystem_SDL_create(detector._gfx_mode, detector._fullScreen);
  
  	{

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scummvm.cpp,v
retrieving revision 1.106
retrieving revision 1.107
diff -C2 -d -r1.106 -r1.107
*** scummvm.cpp	12 Apr 2002 21:26:34 -0000	1.106
--- scummvm.cpp	13 Apr 2002 12:43:02 -0000	1.107
***************
*** 1106,1121 ****
  						_saveLoadFlag = (event.kbd.flags == OSystem::KBD_SHIFT) ? 1 : 2;
  						_saveLoadCompatible = false;
! 					} else if (event.kbd.flags == OSystem::KBD_ALT|OSystem::KBD_CTRL) {
! 						if (!_system->set_param(OSystem::PARAM_HOTSWAP_GFX_MODE, event.kbd.keycode - '1'))
! 							warning("Unable to hotswap graphics mode");
! 						redrawLines(0, 200);
! 						_palDirtyMin = 0;
! 						_palDirtyMax = 255;
! 						updatePalette();
! 					}
! 				} else if (event.kbd.flags&OSystem::KBD_CTRL) {
! 					if (event.kbd.keycode=='z')
! 						_system->quit();
! 					else if (event.kbd.keycode=='f')
  						_fastMode ^= 1;
  					else if (event.kbd.keycode=='g')
--- 1106,1112 ----
  						_saveLoadFlag = (event.kbd.flags == OSystem::KBD_SHIFT) ? 1 : 2;
  						_saveLoadCompatible = false;
! 					} 
! 				} else if (event.kbd.flags==OSystem::KBD_CTRL) {
! 					if (event.kbd.keycode=='f')
  						_fastMode ^= 1;
  					else if (event.kbd.keycode=='g')
***************
*** 1125,1131 ****
  					else if (event.kbd.keycode=='s')
  						resourceStats();
- 				} else if (event.kbd.flags&OSystem::KBD_ALT) {
- 					if (!_system->set_param(OSystem::PARAM_TOGGLE_FULLSCREEN, 0))
- 						warning("Full screen failed");
  				}
  				break;
--- 1116,1119 ----

Index: sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sdl.cpp,v
retrieving revision 1.86
retrieving revision 1.87
diff -C2 -d -r1.86 -r1.87
*** sdl.cpp	13 Apr 2002 11:32:15 -0000	1.86
--- sdl.cpp	13 Apr 2002 12:43:02 -0000	1.87
***************
*** 62,66 ****
  	uint32 set_param(int param, uint32 value);
  
! 	static OSystem *create(int gfx_driver, bool full_screen);
  
  private:
--- 62,66 ----
  	uint32 set_param(int param, uint32 value);
  
! 	static OSystem *create(int gfx_mode, bool full_screen);
  
  private:
***************
*** 81,89 ****
  	};
  
! 	int _driver;
  	bool _full_screen;
  	bool _mouse_visible;
  	bool _mouse_drawn;
! 	uint32 _driver_flags;
  
  	byte _internal_scaling;
--- 81,89 ----
  	};
  
! 	int _mode;
  	bool _full_screen;
  	bool _mouse_visible;
  	bool _mouse_drawn;
! 	uint32 _mode_flags;
  
  	byte _internal_scaling;
***************
*** 129,133 ****
  	TwoXSaiProc *_sai_func;
  
! 	void copy_rect_fullscreen(const byte *buf);
  	void mk_checksums(const byte *buf);
  
--- 129,135 ----
  	TwoXSaiProc *_sai_func;
  
! 	SDL_Color *_cur_pal;
! 
! 	void add_dirty_rgn_auto(const byte *buf);
  	void mk_checksums(const byte *buf);
  
***************
*** 141,144 ****
--- 143,148 ----
  	void load_gfx_mode();
  	void unload_gfx_mode();
+ 
+ 	void hotswap_gfx_mode();
  };
  
***************
*** 157,163 ****
  }
  
! OSystem *OSystem_SDL::create(int gfx_driver, bool full_screen) {
  	OSystem_SDL *syst = new OSystem_SDL();
! 	syst->_driver = gfx_driver;
  	syst->_full_screen = full_screen;
  
--- 161,167 ----
  }
  
! OSystem *OSystem_SDL::create(int gfx_mode, bool full_screen) {
  	OSystem_SDL *syst = new OSystem_SDL();
! 	syst->_mode = gfx_mode;
  	syst->_full_screen = full_screen;
  
***************
*** 174,196 ****
  }
  
! OSystem *OSystem_SDL_create(int gfx_driver, bool full_screen) {
! 	return OSystem_SDL::create(gfx_driver, full_screen);
  }
  
  void OSystem_SDL::set_palette(const byte *colors, uint start, uint num) {
- 	SDL_Color colbuf[256];
  	const byte *b = colors;
  	uint i;
  	for(i=0;i!=num;i++) {
! 		colbuf[i].r = b[0];
! 		colbuf[i].g = b[1];
! 		colbuf[i].b = b[2];
  		b += 4;
  	}
  
! 	if (_driver_flags & DF_FORCE_FULL_ON_PALETTE)
  		force_full = true;
  
! 	SDL_SetColors(sdl_screen, colbuf, start, num);
  }
  
--- 178,199 ----
  }
  
! OSystem *OSystem_SDL_create(int gfx_mode, bool full_screen) {
! 	return OSystem_SDL::create(gfx_mode, full_screen);
  }
  
  void OSystem_SDL::set_palette(const byte *colors, uint start, uint num) {
  	const byte *b = colors;
  	uint i;
  	for(i=0;i!=num;i++) {
! 		_cur_pal[i].r = b[0];
! 		_cur_pal[i].g = b[1];
! 		_cur_pal[i].b = b[2];
  		b += 4;
  	}
  
! 	if (_mode_flags & DF_FORCE_FULL_ON_PALETTE)
  		force_full = true;
  
! 	SDL_SetColors(sdl_screen, _cur_pal, start, num);
  }
  
***************
*** 207,214 ****
  	scaling = 1;
  	_internal_scaling = 1;
! 	_driver_flags = 0;
! 	
  	_sai_func = NULL;
! 	switch(_driver) {
  	case GFX_2XSAI:
  		_sai_func = _2xSaI;
--- 210,217 ----
  	scaling = 1;
  	_internal_scaling = 1;
! 	_mode_flags = 0;
! 
  	_sai_func = NULL;
! 	switch(_mode) {
  	case GFX_2XSAI:
  		_sai_func = _2xSaI;
***************
*** 222,227 ****
--- 225,235 ----
  
  	case GFX_DOUBLESIZE:
+ 		if (_full_screen) {
+ 			warning("full screen in useless in doublesize mode, reverting to normal mode");
+ 			goto normal_mode;
+ 		}
  		scaling = 2;
  		_internal_scaling = 2;
+ 		_mode_flags = DF_WANT_RECT_OPTIM;
  		
  		sdl_hwscreen = sdl_screen = SDL_SetVideoMode(640, 400, 8, SDL_SWSURFACE);
***************
*** 231,244 ****
  
  	case GFX_TRIPLESIZE:
  		scaling = 3;
  		_internal_scaling = 3;
! 		sdl_hwscreen = sdl_screen = SDL_SetVideoMode(960, 600, 8, SDL_SWSURFACE);
  		if (sdl_screen == NULL)
  			error("sdl_screen failed");
- 		break;
  
  
  	case GFX_NORMAL:
! 		sdl_hwscreen = sdl_screen = SDL_SetVideoMode(320, 200, 8, SDL_SWSURFACE);
  		if (sdl_screen == NULL)
  			error("sdl_screen failed");
--- 239,265 ----
  
  	case GFX_TRIPLESIZE:
+ 		if (_full_screen) {
+ 			warning("full screen in useless in triplesize mode, reverting to normal mode");
+ 			goto normal_mode;
+ 		}
  		scaling = 3;
  		_internal_scaling = 3;
! 		_mode_flags = DF_WANT_RECT_OPTIM;
! 
! 		sdl_hwscreen = sdl_screen = SDL_SetVideoMode(960, 600, 8, 
! 			_full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
! 		);
  		if (sdl_screen == NULL)
  			error("sdl_screen failed");
  
  
+ 		break;
+ 
  	case GFX_NORMAL:
! normal_mode:;
! 		_mode_flags = DF_WANT_RECT_OPTIM;
! 		sdl_hwscreen = sdl_screen = SDL_SetVideoMode(320, 200, 8, 
! 			_full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
! 		);
  		if (sdl_screen == NULL)
  			error("sdl_screen failed");
***************
*** 248,252 ****
  	if (_sai_func) {
  		uint16 *tmp_screen = (uint16*)calloc(320*204 + 16,sizeof(uint16));
! 		_driver_flags = DF_FORCE_FULL_ON_PALETTE | DF_WANT_RECT_OPTIM | DF_2xSAI | DF_SEPARATE_HWSCREEN | DF_UPDATE_EXPAND_1_PIXEL;
  
  		Init_2xSaI(565);
--- 269,273 ----
  	if (_sai_func) {
  		uint16 *tmp_screen = (uint16*)calloc(320*204 + 16,sizeof(uint16));
! 		_mode_flags = DF_FORCE_FULL_ON_PALETTE | DF_WANT_RECT_OPTIM | DF_2xSAI | DF_SEPARATE_HWSCREEN | DF_UPDATE_EXPAND_1_PIXEL;
  
  		Init_2xSaI(565);
***************
*** 255,259 ****
  			error("SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0) failed");
  
! 		sdl_hwscreen = SDL_SetVideoMode(640, 400, 16, SDL_SWSURFACE);
  		if (sdl_hwscreen == NULL)
  			error("sdl_hwscreen failed");
--- 276,282 ----
  			error("SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0) failed");
  
! 		sdl_hwscreen = SDL_SetVideoMode(640, 400, 16, 
! 			_full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
! 		);
  		if (sdl_hwscreen == NULL)
  			error("sdl_hwscreen failed");
***************
*** 265,269 ****
  			error("sdl_tmpscreen failed");
  
- 		dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32));
  		scaling = 2;		
  	}
--- 288,291 ----
***************
*** 275,279 ****
  	surf=sdl_screen; sdl_screen=NULL; SDL_FreeSurface(surf);
  
! 	if (_driver_flags & DF_SEPARATE_HWSCREEN) {
  		surf=sdl_hwscreen; sdl_hwscreen=NULL; SDL_FreeSurface(surf);
  	}
--- 297,301 ----
  	surf=sdl_screen; sdl_screen=NULL; SDL_FreeSurface(surf);
  
! 	if (_mode_flags & DF_SEPARATE_HWSCREEN) {
  		surf=sdl_hwscreen; sdl_hwscreen=NULL; SDL_FreeSurface(surf);
  	}
***************
*** 304,307 ****
--- 326,333 ----
  	}
  
+ 	/* 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);
+ 
  	load_gfx_mode();
  
***************
*** 309,312 ****
--- 335,340 ----
  
  	_ms_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING);
+ 
+ 	dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32));
  }
  
***************
*** 315,343 ****
  		return;
  
! 	if (pitch == SCREEN_WIDTH && x==0 && y==0 && w==SCREEN_WIDTH && h==SCREEN_HEIGHT && _driver_flags&DF_WANT_RECT_OPTIM) {
  		/* Special, optimized case for full screen updates.
  		 * It tries to determine what areas were actually changed,
  		 * and just updates those, on the actual display. */
! 		if (buf)
! 			copy_rect_fullscreen(buf);
! 		return;
! 	}
! 
! 	/* Clip the coordinates */
! 	if (x < 0) { w+=x; buf-=x; x = 0; }
! 	if (y < 0) { h+=y; buf-=y*pitch; y = 0; }
! 	if (w >= SCREEN_WIDTH-x) { w = SCREEN_WIDTH - x; }
! 	if (h >= SCREEN_HEIGHT-y) { h = SCREEN_HEIGHT - y; }
! 		
! 	if (w<=0 || h<=0)
! 		return;
  
! 	/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
! 	if (_mouse_drawn)
! 		undraw_mouse();
! 		
! 	cksum_valid = false;
  
! 	add_dirty_rect(x, y, w, h);
  
  	if (SDL_LockSurface(sdl_screen) == -1)
--- 343,370 ----
  		return;
  
! 	if (pitch == SCREEN_WIDTH && x==0 && y==0 && w==SCREEN_WIDTH && h==SCREEN_HEIGHT && _mode_flags&DF_WANT_RECT_OPTIM) {
  		/* Special, optimized case for full screen updates.
  		 * It tries to determine what areas were actually changed,
  		 * and just updates those, on the actual display. */
! 	
! 		add_dirty_rgn_auto(buf);
! 	} else {
! 		/* Clip the coordinates */
! 		if (x < 0) { w+=x; buf-=x; x = 0; }
! 		if (y < 0) { h+=y; buf-=y*pitch; y = 0; }
! 		if (w >= SCREEN_WIDTH-x) { w = SCREEN_WIDTH - x; }
! 		if (h >= SCREEN_HEIGHT-y) { h = SCREEN_HEIGHT - y; }
! 			
! 		if (w<=0 || h<=0)
! 			return;
  
! 		/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
! 		if (_mouse_drawn)
! 			undraw_mouse();
! 			
! 		cksum_valid = false;
  
! 		add_dirty_rect(x, y, w, h);
! 	}
  
  	if (SDL_LockSurface(sdl_screen) == -1)
***************
*** 399,403 ****
  		/* Update the dirty region by 1 pixel for graphics drivers
  		 * that "smear" the screen */
! 		if (_driver_flags & DF_UPDATE_EXPAND_1_PIXEL) {
  			x--;
  			y--;
--- 426,430 ----
  		/* Update the dirty region by 1 pixel for graphics drivers
  		 * that "smear" the screen */
! 		if (_mode_flags & DF_UPDATE_EXPAND_1_PIXEL) {
  			x--;
  			y--;
***************
*** 460,464 ****
  
  
! void OSystem_SDL::copy_rect_fullscreen(const byte *buf) {
  	if (_mouse_drawn)
  		undraw_mouse();
--- 487,491 ----
  
  
! void OSystem_SDL::add_dirty_rgn_auto(const byte *buf) {
  	if (_mouse_drawn)
  		undraw_mouse();
***************
*** 511,520 ****
  		memcpy(dirty_checksums + CKSUM_NUM, dirty_checksums, CKSUM_NUM * sizeof(uint32));
  	}
- 
- 	/* Copy screen */
- 	if (SDL_LockSurface(sdl_screen)==-1)
- 		error("SDL_LockSurface failed: %s.\n", SDL_GetError());
- 	memcpy(sdl_screen->pixels, buf, SCREEN_WIDTH * SCREEN_HEIGHT);
- 	SDL_UnlockSurface(sdl_screen);
  }
  
--- 538,541 ----
***************
*** 538,542 ****
  		return;
  		
! 	if (_driver_flags & DF_2xSAI) {
  		SDL_Rect *r;
  		uint32 area = 0;
--- 559,563 ----
  		return;
  		
! 	if (_mode_flags & DF_2xSAI) {
  		SDL_Rect *r;
  		uint32 area = 0;
***************
*** 659,665 ****
  				if (ev.key.keysym.mod & KMOD_CTRL) b |= KBD_CTRL;
  				if (ev.key.keysym.mod & KMOD_ALT) b |= KBD_ALT;
  
  				event->event_code = EVENT_KEYDOWN;
- 				event->kbd.flags = b;
  				event->kbd.keycode = ev.key.keysym.sym;
  				event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod);
--- 680,704 ----
  				if (ev.key.keysym.mod & KMOD_CTRL) b |= KBD_CTRL;
  				if (ev.key.keysym.mod & KMOD_ALT) b |= KBD_ALT;
+ 				event->kbd.flags = b;
+ 
+ 				/* internal keypress? */				
+ 				if (b == KBD_ALT && ev.key.keysym.sym==SDLK_RETURN) {
+ 					set_param(PARAM_TOGGLE_FULLSCREEN, 0);
+ 					break;
+ 				}
+ 
+ 				if (b == KBD_CTRL && ev.key.keysym.sym=='z') {
+ 					quit();
+ 					break;
+ 				}
+ 
+ 				if (b == (KBD_CTRL|KBD_ALT) && 
+ 						ev.key.keysym.sym>='1' && ev.key.keysym.sym<='6') {
+ 					set_param(PARAM_HOTSWAP_GFX_MODE, ev.key.keysym.sym - '1');
+ 					break;
+ 				}
+ 
  
  				event->event_code = EVENT_KEYDOWN;
  				event->kbd.keycode = ev.key.keysym.sym;
  				event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod);
***************
*** 715,723 ****
  }
  
  uint32 OSystem_SDL::set_param(int param, uint32 value) {
  	switch(param) {
  
  	case PARAM_TOGGLE_FULLSCREEN:
! 		return SDL_WM_ToggleFullScreen(sdl_hwscreen);
  
  	case PARAM_WINDOW_CAPTION:
--- 754,804 ----
  }
  
+ void OSystem_SDL::hotswap_gfx_mode() {
+ 	/* hmm, need to allocate a 320x200 bitmap
+ 	 * which will contain the "backup" of the screen during the change.
+ 	 * then draw that to the new screen right after it's setup.
+ 	 */
+ 	
+ 	byte *bak_mem = (byte*)malloc(320*200);
+ 
+ 	SDL_Surface *bak = SDL_CreateRGBSurfaceFrom(bak_mem, 320, 200, 8, 320, 0, 0, 0, 0);
+ 	if (bak == NULL) {
+ 		error("hotswap_gfx_mode::bak==NULL");
+ 	}
+ 
+ 	SDL_SetColors(bak, _cur_pal, 0, 256);
+ 
+ 	SDL_Rect src_rect = {0, 0, 320 * _internal_scaling, 200 * _internal_scaling };
+ 	static SDL_Rect dst_rect = {0, 0, 320, 200 };
+ 
+ 	if (SDL_BlitSurface(sdl_screen, &src_rect, bak, &dst_rect) != 0)
+ 		error("hotswap_gfx_mode::blit failed = %s", SDL_GetError());
+ 
+ 	/* destroy the temp surface, the backup bitmap is in bak_mem now */
+ 	SDL_FreeSurface(bak);
+ 
+ 	unload_gfx_mode();
+ 	load_gfx_mode();
+ 
+ 	/* reset palette */
+ 	SDL_SetColors(sdl_screen, _cur_pal, 0, 256);
+ 
+ 	/* blit image */
+ 	OSystem_SDL::copy_rect(bak_mem, 320, 0, 0, 320, 200);
+ 
+ 	free(bak_mem);
+ }
+ 
  uint32 OSystem_SDL::set_param(int param, uint32 value) {
  	switch(param) {
  
  	case PARAM_TOGGLE_FULLSCREEN:
! 		_full_screen ^= true;
! 		
! 		if (!SDL_WM_ToggleFullScreen(sdl_hwscreen)) {
! 			/* if ToggleFullScreen fails, achieve the same effect with hotswap gfx mode */
! 			hotswap_gfx_mode();
! 		}
! 		return 1;
  
  	case PARAM_WINDOW_CAPTION:
***************
*** 741,747 ****
  			return 0;
  
! 		unload_gfx_mode();
! 		_driver = value;
! 		load_gfx_mode();
  		return 1;
  
--- 822,828 ----
  			return 0;
  
! 		_mode = value;
! 		hotswap_gfx_mode();
! 
  		return 1;
  





More information about the Scummvm-git-logs mailing list