[Scummvm-git-logs] scummvm master -> 6b80c13467df4253b19454d7fdb17a6c2c290d97

dreammaster dreammaster at scummvm.org
Wed Jul 26 04:08:23 CEST 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6b80c13467 TITANIC: Fix the CBilgeDispensorEvent not firing


Commit: 6b80c13467df4253b19454d7fdb17a6c2c290d97
    https://github.com/scummvm/scummvm/commit/6b80c13467df4253b19454d7fdb17a6c2c290d97
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-07-25T22:04:28-04:00

Commit Message:
TITANIC: Fix the CBilgeDispensorEvent not firing

It seems in the original CGameManager::update, and thus frameMessage,
is called at an ultra high rate, allowing the dispensor's counter to
quickly reach a trigger level. Whereas in the ScummVM implementation,
the update method is only called at most a few times per frame.

Rather than needlessly increasing the rate the update method is called,
I've refactored CBilgeDispensorEvent to not need the counter. Though
it still derives from CAutoSoundEvent so savegame loading still works.

Changed paths:
    engines/titanic/messages/auto_sound_event.cpp
    engines/titanic/messages/auto_sound_event.h
    engines/titanic/messages/bilge_dispensor_event.cpp
    engines/titanic/messages/bilge_dispensor_event.h


diff --git a/engines/titanic/messages/auto_sound_event.cpp b/engines/titanic/messages/auto_sound_event.cpp
index bc2cd7d..942a85e 100644
--- a/engines/titanic/messages/auto_sound_event.cpp
+++ b/engines/titanic/messages/auto_sound_event.cpp
@@ -28,28 +28,28 @@ BEGIN_MESSAGE_MAP(CAutoSoundEvent, CGameObject)
 	ON_MESSAGE(FrameMsg)
 END_MESSAGE_MAP()
 
-CAutoSoundEvent::CAutoSoundEvent() : CGameObject(), _value1(0), _value2(0xFFFFFF) {
+CAutoSoundEvent::CAutoSoundEvent() : CGameObject(), _counter(0), _mask(0xFFFFFF) {
 }
 
 void CAutoSoundEvent::save(SimpleFile *file, int indent) {
 	file->writeNumberLine(1, indent);
-	file->writeNumberLine(_value1, indent);
-	file->writeNumberLine(_value2, indent);
+	file->writeNumberLine(_counter, indent);
+	file->writeNumberLine(_mask, indent);
 
 	CGameObject::save(file, indent);
 }
 
 void CAutoSoundEvent::load(SimpleFile *file) {
 	file->readNumber();
-	_value1 = file->readNumber();
-	_value2  = file->readNumber();
+	_counter = file->readNumber();
+	_mask  = file->readNumber();
 
 	CGameObject::load(file);
 }
 
 bool CAutoSoundEvent::FrameMsg(CFrameMsg *msg) {
-	if (_value1 >= 0)
-		_value1 = (_value1 + 1) & _value2;
+	if (_counter >= 0)
+		_counter = (_counter + 1) & _mask;
 
 	return true;
 }
diff --git a/engines/titanic/messages/auto_sound_event.h b/engines/titanic/messages/auto_sound_event.h
index d889767..085e624 100644
--- a/engines/titanic/messages/auto_sound_event.h
+++ b/engines/titanic/messages/auto_sound_event.h
@@ -31,8 +31,8 @@ class CAutoSoundEvent : public CGameObject {
 	DECLARE_MESSAGE_MAP;
 	bool FrameMsg(CFrameMsg *msg);
 public:
-	int _value1;
-	int _value2;
+	int _counter;
+	int _mask;
 public:
 	CLASSDEF;
 	CAutoSoundEvent();
diff --git a/engines/titanic/messages/bilge_dispensor_event.cpp b/engines/titanic/messages/bilge_dispensor_event.cpp
index 584da00..336a1ca 100644
--- a/engines/titanic/messages/bilge_dispensor_event.cpp
+++ b/engines/titanic/messages/bilge_dispensor_event.cpp
@@ -21,6 +21,7 @@
  */
 
 #include "titanic/messages/bilge_dispensor_event.h"
+#include "titanic/titanic.h"
 
 namespace Titanic {
 
@@ -42,22 +43,31 @@ void CBilgeDispensorEvent::load(SimpleFile *file) {
 }
 
 bool CBilgeDispensorEvent::EnterRoomMsg(CEnterRoomMsg *msg) {
-	_value1 = 0;
+	_counter = 0;
+	_ticksDelayEnd = 0;
+	_soundHandle = -1;
 	return true;
 }
 
 bool CBilgeDispensorEvent::LeaveRoomMsg(CLeaveRoomMsg *msg) {
-	_value1 = -1;
+	_counter = -1;
 	return true;
 }
 
 bool CBilgeDispensorEvent::FrameMsg(CFrameMsg *msg) {
-	if (_value1 >= 0 && (_value1 & 0xffff) == 0x4000) {
-		int volume = 20 + getRandomNumber(30);
-		int val3 = getRandomNumber(20) - 10;
+	uint32 ticks = g_vm->_events->getTicksCount();
+
+	if ((_ticksDelayEnd && ticks >= _ticksDelayEnd) ||
+			_soundHandle == -1 || !isSoundActive(_soundHandle)) {
+		_soundHandle = -1;
+		_ticksDelayEnd = 0;
 
 		if (getRandomNumber(2) == 0) {
-			playSound("b#18.wav", volume, val3);
+			int volume = 20 + getRandomNumber(30);
+			int balance = getRandomNumber(20) - 10;
+			_soundHandle = playSound("b#18.wav", volume, balance);
+		} else {
+			_ticksDelayEnd = ticks + 1000;
 		}
 	}
 
@@ -67,9 +77,9 @@ bool CBilgeDispensorEvent::FrameMsg(CFrameMsg *msg) {
 
 bool CBilgeDispensorEvent::StatusChangeMsg(CStatusChangeMsg *msg) {
 	if (msg->_newStatus == 1)
-		_value1 = -1;
+		_counter = -1;
 	else if (msg->_newStatus == 2)
-		_value1 = 0;
+		_counter = 0;
 
 	return true;
 }
diff --git a/engines/titanic/messages/bilge_dispensor_event.h b/engines/titanic/messages/bilge_dispensor_event.h
index 61d3116..64e0f30 100644
--- a/engines/titanic/messages/bilge_dispensor_event.h
+++ b/engines/titanic/messages/bilge_dispensor_event.h
@@ -34,9 +34,12 @@ class CBilgeDispensorEvent : public CAutoSoundEvent {
 	bool LeaveRoomMsg(CLeaveRoomMsg *msg);
 	bool FrameMsg(CFrameMsg *msg);
 	bool StatusChangeMsg(CStatusChangeMsg *msg);
+private:
+	uint _ticksDelayEnd;
+	int _soundHandle;
 public:
 	CLASSDEF;
-	CBilgeDispensorEvent() : CAutoSoundEvent() {}
+	CBilgeDispensorEvent() : CAutoSoundEvent(), _ticksDelayEnd(0), _soundHandle(-1) {}
 
 	/**
 	 * Save the data for the class to file





More information about the Scummvm-git-logs mailing list