[Scummvm-cvs-logs] CVS: scummvm x11.cpp,1.25,1.26

Lionel Ulmer bbrox at users.sourceforge.net
Tue May 14 14:17:02 CEST 2002


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

Modified Files:
	x11.cpp 
Log Message:
Add support for the new 'timer' interface in the X11 driver.

BTW, it would be nice if the interface was properly documented in the
system.h file and one had not to go look at the SDL documentation to
understand the parameters :-)

(and having the callbacks be ScummVM specific and not inherit some
 SDL-ism would even be better :-) ).



Index: x11.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/x11.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- x11.cpp	7 May 2002 19:08:02 -0000	1.25
+++ x11.cpp	14 May 2002 21:16:01 -0000	1.26
@@ -113,6 +113,9 @@
 	// Set a parameter
 	uint32 property(int param, Property *value);
 
+	// Add a callback timer
+	void set_timer(int timer, int (*callback)(int));
+
 	static OSystem *create(int gfx_mode, bool full_screen);
 
 private:
@@ -174,6 +177,10 @@
 	byte _ms_backup[BAK_WIDTH * BAK_HEIGHT];
 	bool _mouse_drawn;
 	bool _mouse_visible;
+
+	unsigned int _timer_duration, _timer_next_expiry;
+	bool _timer_active;
+	int (*_timer_callback)(int);
 };
 
 typedef struct {
@@ -366,6 +373,9 @@
 out_of_loop:
 	create_empty_cursor();
 
+	/* Initialize the timer routines */
+	_timer_active = false;
+
 	/* And finally start the local timer */
 	gettimeofday(&start_time, NULL);
 }
@@ -467,6 +477,8 @@
 void OSystem_X11::copy_rect(const byte *buf, int pitch, int x, int y, int w, int h) {
 	unsigned char *dst;
 
+	fprintf(stderr, "%d %d %d %d %d %p\n", pitch, x, y, w, h, buf);
+
 	if (y < 0) {
 		h += y;
 		buf -= y * pitch;
@@ -486,6 +498,7 @@
 
 	AddDirtyRec(x, y, w, h);
 	while (h-- > 0) {
+	  fprintf(stderr, " => %d %p\n", h, buf);
 		memcpy(dst, buf, w);
 		dst += fb_width;
 		buf += pitch;
@@ -720,6 +733,8 @@
 	{
 		case PROP_GET_SAMPLE_RATE:
 			return 22050;
+		case PROP_GET_FULLSCREEN:
+			return 0;
 	}
 	warning("Property not implemented yet (%d) ", param);
 	return 0;
@@ -743,6 +758,14 @@
 }
 
 bool OSystem_X11::poll_event(Event *scumm_event) {
+	/* First, handle timers */
+	uint32 current_msecs = get_msecs();
+
+	if (_timer_active && (current_msecs >= _timer_next_expiry)) {
+		_timer_duration = _timer_callback(_timer_duration);
+		_timer_next_expiry = current_msecs + _timer_duration;
+	}
+
 	while (XPending(display)) {
 		XEvent event;
 
@@ -902,4 +925,15 @@
 	}
 
 	return false;
+}
+
+void OSystem_X11::set_timer(int timer, int (*callback)(int)) {
+	if (callback != NULL) {
+		_timer_duration = timer;
+		_timer_next_expiry = get_msecs() + timer;
+		_timer_callback = callback;
+		_timer_active = true;
+	} else {
+		_timer_active = false;
+	}
 }





More information about the Scummvm-git-logs mailing list