[Scummvm-cvs-logs] SF.net SVN: scummvm:[43289] scummvm/trunk/engines/sci/engine

waltervn at users.sourceforge.net waltervn at users.sourceforge.net
Tue Aug 11 22:18:16 CEST 2009


Revision: 43289
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43289&view=rev
Author:   waltervn
Date:     2009-08-11 20:18:15 +0000 (Tue, 11 Aug 2009)

Log Message:
-----------
SCI: Added a crude speed throttler.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kernel.h
    scummvm/trunk/engines/sci/engine/kevent.cpp
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/engine/vm.cpp

Modified: scummvm/trunk/engines/sci/engine/kernel.h
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.h	2009-08-11 19:12:06 UTC (rev 43288)
+++ scummvm/trunk/engines/sci/engine/kernel.h	2009-08-11 20:18:15 UTC (rev 43289)
@@ -402,12 +402,6 @@
 #define _K_SOUND_STATUS_PLAYING 3
 
 
-
-/* Kernel optimization flags */
-#define KERNEL_OPT_FLAG_GOT_EVENT (1<<0)
-#define KERNEL_OPT_FLAG_GOT_2NDEVENT (1<<1)
-
-
 /******************** Kernel functions ********************/
 
 // New kernel functions

Modified: scummvm/trunk/engines/sci/engine/kevent.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kevent.cpp	2009-08-11 19:12:06 UTC (rev 43288)
+++ scummvm/trunk/engines/sci/engine/kevent.cpp	2009-08-11 20:18:15 UTC (rev 43289)
@@ -42,12 +42,6 @@
 	int oldx, oldy;
 	int modifier_mask = s->_version <= SCI_VERSION_0 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK;
 
-	if (s->kernel_opt_flags & KERNEL_OPT_FLAG_GOT_2NDEVENT) {
-		// Penalty time- too many requests to this function without waiting!
-		int delay = s->script_000->locals_block->_locals[SCI_VARIABLE_GAME_SPEED].offset;
-		gfxop_sleep(s->gfx_state, delay * 1000 / 60);
-	}
-
 	// If there's a simkey pending, and the game wants a keyboard event, use the
 	// simkey instead of a normal event
 	if (g_debug_simulated_key && (mask & SCI_EVT_KEYBOARD)) {
@@ -71,15 +65,6 @@
 
 	//gfxop_set_pointer_position(s->gfx_state, Common::Point(s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y));
 
-	if (e.type)
-		s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT);
-	else {
-		if (s->kernel_opt_flags & KERNEL_OPT_FLAG_GOT_EVENT)
-			s->kernel_opt_flags |= KERNEL_OPT_FLAG_GOT_2NDEVENT;
-		else
-			s->kernel_opt_flags |= KERNEL_OPT_FLAG_GOT_EVENT;
-	}
-
 	switch (e.type) {
 	case SCI_EVT_QUIT:
 		quit_vm();

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-08-11 19:12:06 UTC (rev 43288)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-08-11 20:18:15 UTC (rev 43289)
@@ -664,12 +664,13 @@
 	s->r_acc = make_reg(0, ((long)time - (long)s->last_wait_time) * 60 / 1000);
 	s->last_wait_time = time;
 
-	// Reset optimization flags: Game is playing along nicely anyway
-	s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT);
-
 	sleep_time *= g_debug_sleeptime_factor;
 	GFX_ASSERT(gfxop_sleep(s->gfx_state, sleep_time * 1000 / 60));
 
+	// Reset speed throttler: Game is playing along nicely anyway
+	if (sleep_time > 0)
+		s->speedThrottler->reset();
+
 	return s->r_acc;
 }
 

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2009-08-11 19:12:06 UTC (rev 43288)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2009-08-11 20:18:15 UTC (rev 43289)
@@ -114,9 +114,12 @@
 	gc_countdown = 0;
 
 	successor = 0;
+
+	speedThrottler = new SpeedThrottler(version);
 }
 
 EngineState::~EngineState() {
+	delete speedThrottler;
 }
 
 uint16 EngineState::currentRoomNumber() const {

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2009-08-11 19:12:06 UTC (rev 43288)
+++ scummvm/trunk/engines/sci/engine/state.h	2009-08-11 20:18:15 UTC (rev 43289)
@@ -119,6 +119,46 @@
 	bool isOpen() const;
 };
 
+
+class SpeedThrottler {
+public:
+	enum {
+		kSegmentLength = 20 /**< Time segment length in ms */
+	};
+
+	SpeedThrottler(sci_version_t version) {
+		if (version >= SCI_VERSION_1_1)
+			_maxInstructions = 3300;
+		else if (version >= SCI_VERSION_1)
+			_maxInstructions = 2200;
+		else
+			_maxInstructions = 1100;
+		reset();
+	}
+
+	void postInstruction() {
+		if (++_curInstructions >= _maxInstructions) {
+			uint32 time = g_system->getMillis();
+			uint32 elapsed = time - _timestamp;
+
+			if (elapsed < kSegmentLength)
+				g_system->delayMillis(kSegmentLength - elapsed);
+
+			reset();
+		}
+	}
+
+	void reset() {
+		_timestamp = g_system->getMillis();
+		_curInstructions = 0;
+	}
+
+private:
+	uint32 _timestamp; /**< Timestamp of current time segment */
+	uint32 _maxInstructions; /**< Maximum amount of instructions per time segment */
+	uint32 _curInstructions; /**< Amount of instructions executed in current time segment */
+};
+
 struct EngineState : public Common::Serializable {
 public:
 	EngineState(ResourceManager *res, sci_version_t version, uint32 flags);
@@ -258,6 +298,8 @@
 
 	MessageState _msgState;
 
+	SpeedThrottler *speedThrottler;
+
 	EngineState *successor; /**< Successor of this state: Used for restoring */
 
 private:

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-08-11 19:12:06 UTC (rev 43288)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-08-11 20:18:15 UTC (rev 43289)
@@ -1424,6 +1424,8 @@
 		}
 //#endif
 		++script_step_counter;
+
+		s->speedThrottler->postInstruction();
 	}
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list