[Scummvm-cvs-logs] CVS: scummvm/saga events.cpp,1.42,1.43 events.h,1.15,1.16 gfx.cpp,1.40,1.41 gfx.h,1.20,1.21 interface.h,1.20,1.21 scene.cpp,1.74,1.75 script.h,1.46,1.47 sfuncs.cpp,1.69,1.70

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Thu Jan 6 08:08:26 CET 2005


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4236

Modified Files:
	events.cpp events.h gfx.cpp gfx.h interface.h scene.cpp 
	script.h sfuncs.cpp 
Log Message:
Placard functions are now event-driven, so the blocking palette faders are
no longer needed.


Index: events.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/events.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- events.cpp	2 Jan 2005 15:45:38 -0000	1.42
+++ events.cpp	6 Jan 2005 16:07:45 -0000	1.43
@@ -259,6 +259,7 @@
 int Events::handleOneShot(EVENT *event) {
 	SURFACE *back_buf;
 	SCRIPT_THREAD *sthread;
+	Rect rect;
 
 	static SCENE_BGINFO bginfo;
 
@@ -372,29 +373,48 @@
 		case EVENT_ACTIVATE:
 			_vm->_interface->activate();
 			break;
+		case EVENT_DEACTIVATE:
+			_vm->_interface->deactivate();
+			break;
+		case EVENT_SET_STATUS:
+			_vm->_interface->setStatusText((const char*)event->data);
+			_vm->_interface->drawStatusBar(_vm->_gfx->getBackBuffer());
+			break;
+		case EVENT_CLEAR_STATUS:
+			_vm->_interface->setStatusText("");
+			_vm->_interface->drawStatusBar(_vm->_gfx->getBackBuffer());
+			break;
 		default:
 			break;
 		}
 		break;
 	case SCRIPT_EVENT:
-		debug(0, "Starting start script #%d", event->param);
+		switch (event->op) {
+		case EVENT_EXEC_BLOCKING:
+		case EVENT_EXEC_NONBLOCKING:
+			debug(0, "Starting start script #%d", event->param);
 		
-		sthread = _vm->_script->SThreadCreate();
-		if (sthread == NULL) {
-			_vm->_console->DebugPrintf("Thread creation failed.\n");
-			break;
-		}
+			sthread = _vm->_script->SThreadCreate();
+			if (sthread == NULL) {
+				_vm->_console->DebugPrintf("Thread creation failed.\n");
+				break;
+			}
 
-		sthread->threadVars[kVarAction] = TO_LE_16(event->param2);
-		sthread->threadVars[kVarObject] = TO_LE_16(event->param3);
-		sthread->threadVars[kVarWithObject] = TO_LE_16(event->param4);
-		sthread->threadVars[kVarActor] = TO_LE_16(event->param5);
+			sthread->threadVars[kVarAction] = TO_LE_16(event->param2);
+			sthread->threadVars[kVarObject] = TO_LE_16(event->param3);
+			sthread->threadVars[kVarWithObject] = TO_LE_16(event->param4);
+			sthread->threadVars[kVarActor] = TO_LE_16(event->param5);
 
-		_vm->_script->SThreadExecute(sthread, event->param);
+			_vm->_script->SThreadExecute(sthread, event->param);
 
-		if (event->op == EVENT_BLOCKING)
-			_vm->_script->SThreadCompleteThread();
+			if (event->op == EVENT_EXEC_BLOCKING)
+				_vm->_script->SThreadCompleteThread();
 
+			break;
+		case EVENT_THREAD_WAKE:
+			_vm->_script->wakeUpThreads(event->param);
+			break;
+		}
 		break;
 	case CURSOR_EVENT:
 		switch (event->op) {
@@ -407,6 +427,25 @@
 		default:
 			break;
 		}
+		break;
+	case GRAPHICS_EVENT:
+		switch (event->op) {
+		case EVENT_FILL_RECT:
+			rect.top = event->param2;
+			rect.bottom = event->param3;
+			rect.left = event->param4;
+			rect.right = event->param5;
+			drawRect((SURFACE *)event->data, &rect, event->param);
+			break;
+		case EVENT_SETFLAG:
+			_vm->_render->setFlag(event->param);
+			break;
+		case EVENT_CLEARFLAG:
+			_vm->_render->clearFlag(event->param);
+			break;
+		default:
+			break;
+		}
 	default:
 		break;
 	}

Index: events.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/events.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- events.h	2 Jan 2005 15:45:38 -0000	1.15
+++ events.h	6 Jan 2005 16:07:45 -0000	1.16
@@ -31,10 +31,10 @@
 namespace Saga {
 
 enum EVENT_TYPES {
-	ONESHOT_EVENT,
-	CONTINUOUS_EVENT,
-	INTERVAL_EVENT,
-	IMMEDIATE_EVENT
+	ONESHOT_EVENT,    // Event takes no time
+	CONTINUOUS_EVENT, // Event takes time; next event starts immediately
+	INTERVAL_EVENT,   // Not yet implemented
+	IMMEDIATE_EVENT   // Event takes time; next event starts when event is done
 };
 
 enum EVENT_FLAGS {
@@ -56,7 +56,8 @@
 	INTERFACE_EVENT,
 	ACTOR_EVENT,
 	SCRIPT_EVENT,
-	CURSOR_EVENT
+	CURSOR_EVENT,
+	GRAPHICS_EVENT
 };
 
 enum EVENT_OPS {
@@ -82,15 +83,22 @@
 	EVENT_CYCLESTEP = 2,
 	// INTERFACE events
 	EVENT_ACTIVATE = 1,
-	EVENT_DEACTIVATE,
+	EVENT_DEACTIVATE = 2,
+	EVENT_SET_STATUS = 3,
+	EVENT_CLEAR_STATUS = 4,
 	// ACTOR events
 	EVENT_MOVE = 1,
 	// SCRIPT events
-	EVENT_BLOCKING = 1,
-	EVENT_NONBLOCKING = 2,
+	EVENT_EXEC_BLOCKING = 1,
+	EVENT_EXEC_NONBLOCKING = 2,
+	EVENT_THREAD_WAKE = 3,
 	// CURSOR events
 	EVENT_SHOW = 1,
 	// EVENT_HIDE = 2, // reused
+	// GRAPHICS events
+	EVENT_FILL_RECT = 1,
+	// EVENT_SETFLAG = 4, // reused
+	// EVENT_CLEARFLAG = 5, // reused
 
 	// CONTINUOUS events
 	// PALETTE events

Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/gfx.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- gfx.cpp	1 Jan 2005 16:18:36 -0000	1.40
+++ gfx.cpp	6 Jan 2005 16:07:45 -0000	1.41
@@ -986,34 +986,6 @@
 	return SUCCESS;
 }
 
-void Gfx::palToBlackWait(SURFACE *surface, PALENTRY *src_pal, int duration) {
-	uint32 start_time = _vm->_system->getMillis();
-	uint32 cur_time;
-
-	do {
-		cur_time = _vm->_system->getMillis();
-
-		palToBlack(surface, src_pal, (double) (cur_time - start_time) / duration);
-		_vm->processInput();
-		_vm->_system->updateScreen();
-		_vm->_system->delayMillis(50);
-	} while (cur_time < start_time + duration);
-}
-
-void Gfx::blackToPalWait(SURFACE *surface, PALENTRY *src_pal, int duration) {
-	uint32 start_time = _vm->_system->getMillis();
-	uint32 cur_time;
-
-	do {
-		cur_time = _vm->_system->getMillis();
-
-		blackToPal(surface, src_pal, (double) (cur_time - start_time) / duration);
-		_vm->processInput();
-		_vm->_system->updateScreen();
-		_vm->_system->delayMillis(50);
-	} while (cur_time < start_time + duration);
-}
-
 void Gfx::showCursor(bool state) {
 	updateCursor();
 	g_system->showMouse(state);

Index: gfx.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/gfx.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- gfx.h	1 Jan 2005 16:18:36 -0000	1.20
+++ gfx.h	6 Jan 2005 16:07:45 -0000	1.21
@@ -107,8 +107,6 @@
 	int getCurrentPal(PALENTRY *src_pal);
 	int palToBlack(SURFACE *surface, PALENTRY *src_pal, double percent);
 	int blackToPal(SURFACE *surface, PALENTRY *src_pal, double percent);
-	void palToBlackWait(SURFACE *surface, PALENTRY *src_pal, int duration);
-	void blackToPalWait(SURFACE *surface, PALENTRY *src_pal, int duration);
 	void updateCursor() { setCursor(getWhite()); }
 	void showCursor(bool state);
 

Index: interface.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/interface.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- interface.h	6 Jan 2005 14:49:47 -0000	1.20
+++ interface.h	6 Jan 2005 16:07:45 -0000	1.21
@@ -220,6 +220,7 @@
 	int setLeftPortrait(int portrait);
 	int setRightPortrait(int portrait);
 	int draw();
+	int drawStatusBar(SURFACE *ds);
 	int update(const Point& imousePt, int update_flag);
 
 	void addToInventory(int sprite);
@@ -229,7 +230,6 @@
 
 private:
 	int hitTest(const Point& imousePt, int *ibutton);
-	int drawStatusBar(SURFACE *ds);
 	int handleCommandUpdate(SURFACE *ds, const Point& imousePt);
 	int handleCommandClick(SURFACE *ds, const Point& imousePt);
 	int handlePlayfieldUpdate(SURFACE *ds, const Point& imousePt);

Index: scene.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/scene.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- scene.cpp	6 Jan 2005 14:32:14 -0000	1.74
+++ scene.cpp	6 Jan 2005 16:07:45 -0000	1.75
@@ -644,7 +644,7 @@
 		if (_desc.startScriptNum > 0) {
 			event.type = ONESHOT_EVENT;
 			event.code = SCRIPT_EVENT;
-			event.op = EVENT_BLOCKING;
+			event.op = EVENT_EXEC_BLOCKING;
 			event.time = 0;
 			event.param = _desc.startScriptNum;
 			event.param2 = 0;		// Action
@@ -1106,7 +1106,7 @@
 		if (_desc.sceneScriptNum > 0) {
 			event.type = ONESHOT_EVENT;
 			event.code = SCRIPT_EVENT;
-			event.op = EVENT_NONBLOCKING;
+			event.op = EVENT_EXEC_NONBLOCKING;
 			event.time = 0;
 			event.param = _desc.sceneScriptNum;
 			event.param2 = 0;		// Action

Index: script.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/script.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- script.h	6 Jan 2005 14:02:53 -0000	1.46
+++ script.h	6 Jan 2005 16:07:46 -0000	1.47
@@ -95,7 +95,8 @@
 	kWaitTypeDialogBegin = 4,	// waiting for other dialog to finish
 	kWaitTypeWalk = 5,			// waiting to finish walking
 	kWaitTypeRequest = 6,		// a request is up
-	kWaitTypePause = 7
+	kWaitTypePause = 7,
+	kWaitTypePlacard = 8
 };
 
 enum OpCodes {

Index: sfuncs.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sfuncs.cpp,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- sfuncs.cpp	6 Jan 2005 14:49:47 -0000	1.69
+++ sfuncs.cpp	6 Jan 2005 16:07:46 -0000	1.70
@@ -29,6 +29,7 @@
 #include "saga/actor.h"
 #include "saga/animation.h"
 #include "saga/console.h"
+#include "saga/events.h"
 #include "saga/font.h"
 #include "saga/interface.h"
 #include "saga/music.h"
@@ -932,29 +933,69 @@
 	return SUCCESS;
 }
 
+static TEXTLIST_ENTRY *placardTextEntry;
+
 // Script function #48 (0x30)
 // Param1: string rid
 int Script::sfPlacard(SCRIPTFUNC_PARAMS) {
 	int stringId;
-	const char *string;
 	GAME_DISPLAYINFO disp;
 	SURFACE *back_buf = _vm->_gfx->getBackBuffer();
-	PALENTRY cur_pal[PAL_ENTRIES];
+	static PALENTRY cur_pal[PAL_ENTRIES];
 	PALENTRY *pal;
-	
-	stringId = thread->pop();
-	string = getString(stringId);
+	EVENT event;
+	EVENT *q_event;
+
+	thread->wait(kWaitTypePlacard);
+
+	_vm->_interface->rememberMode();
+	_vm->_interface->setMode(kPanelPlacard);
 
 	_vm->getDisplayInfo(&disp);
 
-	_vm->_gfx->showCursor(false);
+	stringId = thread->pop();
+
+	event.type = ONESHOT_EVENT;
+	event.code = CURSOR_EVENT;
+	event.op = EVENT_HIDE;
+
+	q_event = _vm->_events->queue(&event);
+
 	_vm->_gfx->getCurrentPal(cur_pal);
-	_vm->_gfx->palToBlackWait(back_buf, cur_pal, kNormalFadeDuration);
 
-	_vm->_interface->setStatusText("");
+	event.type = IMMEDIATE_EVENT;
+	event.code = PAL_EVENT;
+	event.op = EVENT_PALTOBLACK;
+	event.time = 0;
+	event.duration = kNormalFadeDuration;
+	event.data = cur_pal;
 
-	Rect rect(disp.logical_w, disp.scene_h);
-	drawRect(back_buf, &rect, 138);
+	q_event = _vm->_events->chain(q_event, &event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = INTERFACE_EVENT;
+	event.op = EVENT_CLEAR_STATUS;
+
+	q_event = _vm->_events->chain(q_event, &event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = GRAPHICS_EVENT;
+	event.op = EVENT_SETFLAG;
+	event.param = RF_PLACARD;
+
+	q_event = _vm->_events->chain(q_event, &event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = GRAPHICS_EVENT;
+	event.op = EVENT_FILL_RECT;
+	event.data = back_buf;
+	event.param = 138;
+	event.param2 = 0;
+	event.param3 = disp.scene_h;
+	event.param4 = 0;
+	event.param5 = disp.logical_w;
+
+	q_event = _vm->_events->chain(q_event, &event);
 
 	// Put the text in the center of the viewport, assuming it will fit on
 	// one line. If we cannot make that assumption we'll need to extend
@@ -962,44 +1003,108 @@
 	// It doesn't end up in exactly the same spot as the original did it,
 	// but it's close enough for now at least.
 
-	_vm->textDraw(MEDIUM_FONT_ID, back_buf, string,
-		disp.logical_w / 2,
-		(disp.scene_h - _vm->_font->getHeight(MEDIUM_FONT_ID)) / 2,
-		_vm->_gfx->getWhite(), _vm->_gfx->getBlack(),
-		FONT_OUTLINE | FONT_CENTERED);
+	TEXTLIST_ENTRY text_entry;
+	SCENE_INFO scene_info;
 
-	_vm->_render->setFlag(RF_PLACARD);
-	_vm->_render->drawScene();
+	_vm->_scene->getInfo(&scene_info);
+
+	text_entry.color = _vm->_gfx->getWhite();
+	text_entry.effect_color = _vm->_gfx->getBlack();
+	text_entry.text_x = disp.logical_w / 2;
+	text_entry.text_y = (disp.scene_h - _vm->_font->getHeight(MEDIUM_FONT_ID)) / 2;
+	text_entry.font_id = MEDIUM_FONT_ID;
+	text_entry.flags = FONT_OUTLINE | FONT_CENTERED;
+	text_entry.string = getString(stringId);
+
+	placardTextEntry = _vm->textAddEntry(scene_info.text_list, &text_entry);
+
+	event.type = ONESHOT_EVENT;
+	event.code = TEXT_EVENT;
+	event.op = EVENT_DISPLAY;
+	event.data = placardTextEntry;
+
+	q_event = _vm->_events->chain(q_event, &event);
 
 	_vm->_scene->getBGPal(&pal);
-	_vm->_gfx->blackToPalWait(back_buf, pal, kNormalFadeDuration);
 
-	_vm->_interface->rememberMode();
-	_vm->_interface->setMode(kPanelPlacard);
+	event.type = IMMEDIATE_EVENT;
+	event.code = PAL_EVENT;
+	event.op = EVENT_BLACKTOPAL;
+	event.time = 0;
+	event.duration = kNormalFadeDuration;
+	event.data = pal;
+
+	q_event = _vm->_events->chain(q_event, &event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = SCRIPT_EVENT;
+	event.op = EVENT_THREAD_WAKE;
+	event.param = kWaitTypePlacard;
+
+	q_event = _vm->_events->chain(q_event, &event);
 
 	return SUCCESS;
 }
 
 // Script function #49 (0x31)
 int Script::sfPlacardOff(SCRIPTFUNC_PARAMS) {
-	SURFACE *back_buf = _vm->_gfx->getBackBuffer();
-	PALENTRY cur_pal[PAL_ENTRIES];
+	static PALENTRY cur_pal[PAL_ENTRIES];
 	PALENTRY *pal;
+	EVENT event;
+	EVENT *q_event;
+
+	thread->wait(kWaitTypePlacard);
+
+	_vm->_interface->restoreMode();
 
-	// Fade down
 	_vm->_gfx->getCurrentPal(cur_pal);
-	_vm->_gfx->palToBlackWait(back_buf, cur_pal, kNormalFadeDuration);
 
-	_vm->_render->clearFlag(RF_PLACARD);
-	_vm->_render->drawScene();
+	event.type = IMMEDIATE_EVENT;
+	event.code = PAL_EVENT;
+	event.op = EVENT_PALTOBLACK;
+	event.time = 0;
+	event.duration = kNormalFadeDuration;
+	event.data = cur_pal;
+
+	q_event = _vm->_events->queue(&event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = GRAPHICS_EVENT;
+	event.op = EVENT_CLEARFLAG;
+	event.param = RF_PLACARD;
+
+	q_event = _vm->_events->chain(q_event, &event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = TEXT_EVENT;
+	event.op = EVENT_REMOVE;
+	event.data = placardTextEntry;
+
+	q_event = _vm->_events->chain(q_event, &event);
 
-	// Fade up
 	_vm->_scene->getBGPal(&pal);
 
-	_vm->_gfx->showCursor(true);
-	_vm->_gfx->blackToPalWait(back_buf, pal, kNormalFadeDuration);
+	event.type = IMMEDIATE_EVENT;
+	event.code = PAL_EVENT;
+	event.op = EVENT_BLACKTOPAL;
+	event.time = 0;
+	event.duration = kNormalFadeDuration;
+	event.data = pal;
 
-	_vm->_interface->restoreMode();
+	q_event = _vm->_events->chain(q_event, &event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = CURSOR_EVENT;
+	event.op = EVENT_SHOW;
+
+	q_event = _vm->_events->chain(q_event, &event);
+
+	event.type = ONESHOT_EVENT;
+	event.code = SCRIPT_EVENT;
+	event.op = EVENT_THREAD_WAKE;
+	event.param = kWaitTypePlacard;
+
+	q_event = _vm->_events->chain(q_event, &event);
 
 	return SUCCESS;
 }





More information about the Scummvm-git-logs mailing list