[Scummvm-git-logs] scummvm master -> bee90fbc9c63817b29184672807ecf012cd4d076

mduggan mgithub at guarana.org
Sun Dec 27 08:42:10 UTC 2020


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

Summary:
6dc9c41850 ULTIMA8: Limit ambient sounds in mixer to avoid overload
8199fe4de3 ULTIMA8: more support for 16 dirs in direction util
4f7881fe8a TEST: Add direction util tests for U8
bee90fbc9c ICB: More type fixes


Commit: 6dc9c4185038aeaaa53693ae96453a7371ac1284
    https://github.com/scummvm/scummvm/commit/6dc9c4185038aeaaa53693ae96453a7371ac1284
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2020-12-27T16:44:41+09:00

Commit Message:
ULTIMA8: Limit ambient sounds in mixer to avoid overload

Changed paths:
    engines/ultima/ultima8/audio/audio_channel.h
    engines/ultima/ultima8/audio/audio_mixer.cpp
    engines/ultima/ultima8/audio/audio_mixer.h
    engines/ultima/ultima8/audio/audio_process.cpp
    engines/ultima/ultima8/audio/audio_process.h


diff --git a/engines/ultima/ultima8/audio/audio_channel.h b/engines/ultima/ultima8/audio/audio_channel.h
index 80d94a87a5..19db199658 100644
--- a/engines/ultima/ultima8/audio/audio_channel.h
+++ b/engines/ultima/ultima8/audio/audio_channel.h
@@ -48,7 +48,7 @@ private:
 	// Info for sampling
 	uint32          _frameEvenOdd;  // which buffer is 'frame0'
 	int             _lVol, _rVol;   // 0-256
-	uint32          _pitchShift;    // 0x10000 = no shift
+	uint32          _pitchShift;    // AudioProcess::PITCH_SHIFT_NONE = no shift
 	int             _priority;      // anything.
 	bool            _paused;        // true/false
 private:
diff --git a/engines/ultima/ultima8/audio/audio_mixer.cpp b/engines/ultima/ultima8/audio/audio_mixer.cpp
index 309a1ad345..5de57a89fc 100644
--- a/engines/ultima/ultima8/audio/audio_mixer.cpp
+++ b/engines/ultima/ultima8/audio/audio_mixer.cpp
@@ -36,11 +36,16 @@ namespace Ultima8 {
 
 AudioMixer *AudioMixer::_audioMixer = nullptr;
 
+static const uint32 SAMPLE_RATE = 22050;
+static const int BASE_CHANNEL_COUNT = 16;
+static const int AMBIENT_CHANNEL_COUNT = 4;
+static const int TOTAL_CHANNEL_COUNT = BASE_CHANNEL_COUNT + AMBIENT_CHANNEL_COUNT;
+
 AudioMixer::AudioMixer(Audio::Mixer *mixer) : _mixer(mixer), _midiPlayer(nullptr) {
 	_audioMixer = this;
 	
-	_channels.resize(CHANNEL_COUNT);
-	for (int idx = 0; idx < CHANNEL_COUNT; ++idx)
+	_channels.resize(TOTAL_CHANNEL_COUNT);
+	for (int idx = 0; idx < TOTAL_CHANNEL_COUNT; ++idx)
 		_channels[idx] = new AudioChannel(_mixer, SAMPLE_RATE, true);
 
 	debugN(MM_INFO, "Creating AudioMixer...\n");
@@ -67,7 +72,7 @@ AudioMixer::~AudioMixer(void) {
 
 	closeMidiOutput();
 
-	for (int idx = 0; idx < CHANNEL_COUNT; ++idx)
+	for (int idx = 0; idx < TOTAL_CHANNEL_COUNT; ++idx)
 		delete _channels[idx];
 }
 
@@ -84,7 +89,7 @@ void AudioMixer::reset() {
 	Unlock();
 }
 
-int AudioMixer::playSample(AudioSample *sample, int loop, int priority, bool paused, uint32 pitch_shift, int lvol, int rvol) {
+int AudioMixer::playSample(AudioSample *sample, int loop, int priority, bool paused, uint32 pitch_shift, int lvol, int rvol, bool ambient) {
 	int lowest = -1;
 	int lowprior = 65536;
 
@@ -92,7 +97,9 @@ int AudioMixer::playSample(AudioSample *sample, int loop, int priority, bool pau
 	Lock();
 
 	int i;
-	for (i = 0; i < CHANNEL_COUNT; i++) {
+	const int minchan = (ambient ? BASE_CHANNEL_COUNT : 0);
+	const int maxchan = (ambient ? TOTAL_CHANNEL_COUNT : BASE_CHANNEL_COUNT);
+	for (i = minchan; i < maxchan; i++) {
 		if (!_channels[i]->isPlaying()) {
 			lowest = i;
 			break;
@@ -103,7 +110,7 @@ int AudioMixer::playSample(AudioSample *sample, int loop, int priority, bool pau
 		}
 	}
 
-	if (i != CHANNEL_COUNT || lowprior < priority)
+	if (i != maxchan || lowprior < priority)
 		_channels[lowest]->playSample(sample, loop, priority, paused, pitch_shift, lvol, rvol);
 	else
 		lowest = -1;
@@ -115,7 +122,7 @@ int AudioMixer::playSample(AudioSample *sample, int loop, int priority, bool pau
 }
 
 bool AudioMixer::isPlaying(int chan) {
-	if (chan >= CHANNEL_COUNT || chan < 0)
+	if (chan >= TOTAL_CHANNEL_COUNT || chan < 0)
 		return false;
 
 	Lock();
@@ -128,7 +135,7 @@ bool AudioMixer::isPlaying(int chan) {
 }
 
 void AudioMixer::stopSample(int chan) {
-	if (chan >= CHANNEL_COUNT || chan < 0)
+	if (chan >= TOTAL_CHANNEL_COUNT || chan < 0)
 		return;
 
 	Lock();
@@ -139,7 +146,7 @@ void AudioMixer::stopSample(int chan) {
 }
 
 void AudioMixer::setPaused(int chan, bool paused) {
-	if (chan >= CHANNEL_COUNT || chan < 0)
+	if (chan >= TOTAL_CHANNEL_COUNT || chan < 0)
 		return;
 
 	Lock();
@@ -150,7 +157,7 @@ void AudioMixer::setPaused(int chan, bool paused) {
 }
 
 bool AudioMixer::isPaused(int chan) {
-	if (chan >= CHANNEL_COUNT|| chan < 0)
+	if (chan >= TOTAL_CHANNEL_COUNT|| chan < 0)
 		return false;
 
 	Lock();
@@ -163,7 +170,8 @@ bool AudioMixer::isPaused(int chan) {
 }
 
 void AudioMixer::setVolume(int chan, int lvol, int rvol) {
-	if (chan >= CHANNEL_COUNT || chan < 0) return;
+	if (chan >= TOTAL_CHANNEL_COUNT || chan < 0)
+		return;
 
 	Lock();
 
@@ -173,7 +181,8 @@ void AudioMixer::setVolume(int chan, int lvol, int rvol) {
 }
 
 void AudioMixer::getVolume(int chan, int &lvol, int &rvol) {
-	if (chan >= CHANNEL_COUNT || chan < 0) return;
+	if (chan >= TOTAL_CHANNEL_COUNT || chan < 0)
+		return;
 
 	Lock();
 
diff --git a/engines/ultima/ultima8/audio/audio_mixer.h b/engines/ultima/ultima8/audio/audio_mixer.h
index b5e1eef4d3..87b989ff65 100644
--- a/engines/ultima/ultima8/audio/audio_mixer.h
+++ b/engines/ultima/ultima8/audio/audio_mixer.h
@@ -30,9 +30,6 @@
 namespace Ultima {
 namespace Ultima8 {
 
-#define SAMPLE_RATE 22050
-#define CHANNEL_COUNT 32
-
 class MidiPlayer;
 class AudioChannel;
 class AudioSample;
@@ -61,7 +58,7 @@ public:
 	void            reset();
 	void            createProcesses();
 
-	int             playSample(AudioSample *sample, int loop, int priority, bool paused, uint32 pitch_shift, int lvol, int rvol);
+	int             playSample(AudioSample *sample, int loop, int priority, bool paused, uint32 pitch_shift, int lvol, int rvol, bool ambient);
 	bool            isPlaying(int chan);
 	void            stopSample(int chan);
 
diff --git a/engines/ultima/ultima8/audio/audio_process.cpp b/engines/ultima/ultima8/audio/audio_process.cpp
index 3bac702e0a..89ce94ff7d 100644
--- a/engines/ultima/ultima8/audio/audio_process.cpp
+++ b/engines/ultima/ultima8/audio/audio_process.cpp
@@ -44,6 +44,7 @@ namespace Ultima8 {
 DEFINE_RUNTIME_CLASSTYPE_CODE(AudioProcess)
 
 AudioProcess *AudioProcess::_theAudioProcess = nullptr;
+const uint32 AudioProcess::PITCH_SHIFT_NONE = 0x10000;
 
 AudioProcess::AudioProcess(void) : _paused(0) {
 	_theAudioProcess = this;
@@ -213,7 +214,8 @@ bool AudioProcess::loadData(Common::ReadStream *rs, uint32 version) {
 				lVol = 255;
 				rVol = 255;
 			}
-			playSFX(sfxNum, priority, objId, loops, false, pitchShift, volume, lVol, rVol);
+			// Note: Small inconsistency for backward compatibility - reload ambient sounds as non-ambient.
+			playSFX(sfxNum, priority, objId, loops, false, pitchShift, volume, lVol, rVol, false);
 		} else {                // Speech
 			uint32 slen = rs->readUint32LE();
 
@@ -230,9 +232,9 @@ bool AudioProcess::loadData(Common::ReadStream *rs, uint32 version) {
 	return true;
 }
 
-int AudioProcess::playSample(AudioSample *sample, int priority, int loops, uint32 pitchShift, int16 lVol, int16 rVol) {
+int AudioProcess::playSample(AudioSample *sample, int priority, int loops, uint32 pitchShift, int16 lVol, int16 rVol, bool ambient) {
 	AudioMixer *mixer = AudioMixer::get_instance();
-	int channel = mixer->playSample(sample, loops, priority, false, pitchShift, lVol, rVol);
+	int channel = mixer->playSample(sample, loops, priority, false, pitchShift, lVol, rVol, ambient);
 
 	if (channel == -1) return channel;
 
@@ -251,7 +253,7 @@ int AudioProcess::playSample(AudioSample *sample, int priority, int loops, uint3
 
 void AudioProcess::playSFX(int sfxNum, int priority, ObjId objId, int loops,
                            bool no_duplicates, uint32 pitchShift, uint16 volume,
-                           int16 lVol, int16 rVol) {
+                           int16 lVol, int16 rVol, bool ambient) {
 
 	SoundFlex *soundflx = GameData::get_instance()->getSoundFlex();
 
@@ -266,7 +268,7 @@ void AudioProcess::playSFX(int sfxNum, int priority, ObjId objId, int loops,
 				// Exactly the same (and playing) so just return
 				//if (it->priority == priority)
 				if (mixer->isPlaying(it->_channel)) {
-					pout << "Sound already playing" << Std::endl;
+					pout << "Sound " << sfxNum << " already playing on obj " << objId << Std::endl;
 					return;
 				} else {
 					it = _sampleInfo.erase(it);
@@ -287,11 +289,11 @@ void AudioProcess::playSFX(int sfxNum, int priority, ObjId objId, int loops,
 		if (objId) calculateSoundVolume(objId, lVol, rVol);
 	}
 
-	int channel = playSample(sample, priority, loops, pitchShift, (lVol * volume) / 256, (rVol * volume) / 256);
+	int channel = playSample(sample, priority, loops, pitchShift, (lVol * volume) / 256, (rVol * volume) / 256, ambient);
 	if (channel == -1) return;
 
 	// Update list
-	_sampleInfo.push_back(SampleInfo(sfxNum, priority, objId, loops, channel, pitchShift, volume, lVol, rVol));
+	_sampleInfo.push_back(SampleInfo(sfxNum, priority, objId, loops, channel, pitchShift, volume, lVol, rVol, ambient));
 }
 
 void AudioProcess::stopSFX(int sfxNum, ObjId objId) {
@@ -387,7 +389,7 @@ bool AudioProcess::playSpeech(const Std::string &barked, int shapeNum, ObjId obj
 
 	// Update list
 	_sampleInfo.push_back(SampleInfo(barked, shapeNum, objId, channel,
-	                                 speech_start, speech_end, pitchShift, volume, 256, 256));
+	                                 speech_start, speech_end, pitchShift, volume, 256, 256, false));
 
 	return true;
 }
@@ -538,7 +540,7 @@ uint32 AudioProcess::I_playSFXCru(const uint8 *args, unsigned int argsize) {
 		if (ap) {
 			// Crusader stops any existing item sounds before starting the next.
 			ap->stopSFX(item->getObjId(), -1);
-			ap->playSFX(sfxNum, 0x10, item->getObjId(), 0, true);
+			ap->playSFX(sfxNum, 0x10, item->getObjId(), 0, true, PITCH_SHIFT_NONE, 0x80, false);
 		} else {
 			warning("I_playSFXCru Error: No AudioProcess");
 		}
@@ -557,12 +559,11 @@ uint32 AudioProcess::I_playAmbientSFXCru(const uint8 *args, unsigned int argsize
 	} else {
 		AudioProcess *ap = AudioProcess::get_instance();
 		if (ap)
-			ap->playSFX(sfxNum, 0x10, item->getObjId(), -1, true);
+			ap->playSFX(sfxNum, 0x10, item->getObjId(), -1, true, PITCH_SHIFT_NONE, 0xff, true);
 		else
 			warning("I_playAmbientSFXCru Error: No AudioProcess");
 	}
 	return 0;
-
 }
 
 uint32 AudioProcess::I_isSFXPlaying(const uint8 *args, unsigned int argsize) {
diff --git a/engines/ultima/ultima8/audio/audio_process.h b/engines/ultima/ultima8/audio/audio_process.h
index 4f329674c5..19bd20425d 100644
--- a/engines/ultima/ultima8/audio/audio_process.h
+++ b/engines/ultima/ultima8/audio/audio_process.h
@@ -36,6 +36,9 @@ class AudioSample;
 
 class AudioProcess : public Process {
 public:
+
+	static const uint32 PITCH_SHIFT_NONE;
+
 	struct SampleInfo {
 		int32       _sfxNum;
 		int32       _priority;
@@ -44,21 +47,22 @@ public:
 		int32       _channel;
 		Std::string _barked;
 		uint32      _curSpeechStart, _curSpeechEnd;
-		uint32      _pitchShift;    // 0x10000 is normal
-		uint16      _volume;         // 0-256
+		uint32      _pitchShift;    // PITCH_SHIFT_NONE is normal
+		uint16      _volume;         // 0-255
 		int16       _lVol;
 		int16       _rVol;
+		bool		_ambient;
 
 		SampleInfo() : _sfxNum(-1) { }
-		SampleInfo(int32 s, int32 p, ObjId o, int32 l, int32 c, uint32 ps, uint16 v, int16 lv, int16 rv) :
+		SampleInfo(int32 s, int32 p, ObjId o, int32 l, int32 c, uint32 ps, uint16 v, int16 lv, int16 rv, bool ambient) :
 			_sfxNum(s), _priority(p), _objId(o), _loops(l), _channel(c),
 			_pitchShift(ps), _volume(v), _lVol(lv), _rVol(rv),
-			_curSpeechStart(0), _curSpeechEnd(0) { }
+			_curSpeechStart(0), _curSpeechEnd(0), _ambient(ambient) { }
 		SampleInfo(const Std::string &b, int32 shpnum, ObjId o, int32 c,
-				   uint32 s, uint32 e, uint32 ps, uint16 v, int16 lv, int16 rv) :
+				   uint32 s, uint32 e, uint32 ps, uint16 v, int16 lv, int16 rv, bool ambient) :
 			_sfxNum(-1), _priority(shpnum), _objId(o), _loops(0), _channel(c), _barked(b),
 			_curSpeechStart(s), _curSpeechEnd(e), _pitchShift(ps), _volume(v),
-			_lVol(lv), _rVol(rv) { }
+			_lVol(lv), _rVol(rv), _ambient(ambient) { }
 	};
 
 	Std::list<SampleInfo> _sampleInfo;
@@ -89,12 +93,13 @@ public:
 
 	void playSFX(int sfxNum, int priority, ObjId objId, int loops,
 				 bool no_duplicates, uint32 pitchShift,
-				 uint16 volume, int16 lVol, int16 rVol);
+				 uint16 volume, int16 lVol, int16 rVol,
+				 bool ambient);
 
 	void playSFX(int sfxNum, int priority, ObjId objId, int loops,
-				 bool no_duplicates = false, uint32 pitchShift = 0x10000,
-				 uint16 volume = 0x80) {
-		playSFX(sfxNum, priority, objId, loops, no_duplicates, pitchShift, volume, -1, -1);
+				 bool no_duplicates = false, uint32 pitchShift = PITCH_SHIFT_NONE,
+				 uint16 volume = 0x80, bool ambient = false) {
+		playSFX(sfxNum, priority, objId, loops, no_duplicates, pitchShift, volume, -1, -1, ambient);
 	}
 
 	//! stop sfx on object.  set sfxNum = -1 to stop all for object.
@@ -104,7 +109,7 @@ public:
 	void setVolumeSFX(int sfxNum, uint8 volume);
 
 	bool playSpeech(const Std::string &barked, int shapenum, ObjId objId,
-					uint32 pitchShift = 0x10000, uint16 volume = 255);
+					uint32 pitchShift = PITCH_SHIFT_NONE, uint16 volume = 255);
 	void stopSpeech(const Std::string &barked, int shapenum, ObjId objId);
 	bool isSpeechPlaying(const Std::string &barked, int shapenum);
 
@@ -114,7 +119,8 @@ public:
 	//! play a sample (without storing a SampleInfo)
 	//! returns channel sample is played on, or -1
 	int playSample(AudioSample *sample, int priority, int loops,
-				   uint32 pitchShift = 0x10000, int16 lVol = 255, int16 rVol = 255);
+				   uint32 pitchShift = PITCH_SHIFT_NONE, int16 lVol = 255,
+				   int16 rVol = 255, bool ambient=false);
 
 	//! pause all currently playing samples
 	void pauseAllSamples();


Commit: 8199fe4de312d0ece61a0a966b2b9322ac9ae743
    https://github.com/scummvm/scummvm/commit/8199fe4de312d0ece61a0a966b2b9322ac9ae743
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2020-12-27T16:44:44+09:00

Commit Message:
ULTIMA8: more support for 16 dirs in direction util

Changed paths:
    engines/ultima/ultima8/misc/direction_util.h


diff --git a/engines/ultima/ultima8/misc/direction_util.h b/engines/ultima/ultima8/misc/direction_util.h
index 02892b47b6..1bc3a70202 100644
--- a/engines/ultima/ultima8/misc/direction_util.h
+++ b/engines/ultima/ultima8/misc/direction_util.h
@@ -88,49 +88,71 @@ inline Direction Direction_Get(int deltay, int deltax, DirectionMode dirmode) {
 				   : dir_northwest;
 	} else {
 		double angle = Common::rad2deg(atan2(deltay, deltax));
-		if (angle < 11.25)		 return dir_northwest;
-		else if (angle < 33.75)  return dir_nnw;
-		else if (angle < 56.25)  return dir_north;
-		else if (angle < 78.75)  return dir_nne;
-		else if (angle < 101.25) return dir_northeast;
-		else if (angle < 123.75) return dir_ene;
-		else if (angle < 146.25) return dir_east;
-		else if (angle < 168.75) return dir_ese;
-		else if (angle < 191.25) return dir_southeast;
-		else if (angle < 213.75) return dir_sse;
-		else if (angle < 236.25) return dir_south;
-		else if (angle < 258.75) return dir_ssw;
-		else if (angle < 281.25) return dir_southwest;
-		else if (angle < 303.75) return dir_wsw;
-		else if (angle < 326.25) return dir_west;
-		else if (angle < 348.75) return dir_wnw;
-		return dir_northwest;
+		if (angle < -168.75)      return dir_southwest;
+		else if (angle < -146.25) return dir_ssw;
+		else if (angle < -123.75) return dir_south;
+		else if (angle < -101.25) return dir_sse;
+		else if (angle < -78.75)  return dir_southeast;
+		else if (angle < -56.25)  return dir_ese;
+		else if (angle < -33.75)  return dir_east;
+		else if (angle < -11.25)  return dir_ene;
+		else if (angle < 11.25)   return dir_northeast;
+		else if (angle < 33.75)   return dir_nne;
+		else if (angle < 56.25)   return dir_north;
+		else if (angle < 78.75)   return dir_nnw;
+		else if (angle < 101.25)  return dir_northwest;
+		else if (angle < 123.75)  return dir_wnw;
+		else if (angle < 146.25)  return dir_west;
+		else if (angle < 168.75)  return dir_wsw;
+		return dir_southwest;
 	}
 }
 
+// Note that for WorldDir, Y goes down, so a positive Y points south.
 inline Direction Direction_GetWorldDir(int deltay, int deltax, DirectionMode dirmode) {
-	// TODO: Implement 16 directions here.
 	if (deltax == 0) {
 		if (deltay == 0) return dir_northeast; // for better compatibility with U8
 		return deltay > 0 ? dir_south : dir_north;
 	}
-	int dydx = (1024 * deltay) / deltax;
-
-	if (dydx >= 0)
-		if (deltax > 0) // south-east
-			return dydx <= 424 ? dir_east : dydx <= 2472 ? dir_southeast : dir_south;
-		else			// north-west
-			return dydx <= 424 ? dir_west : dydx <= 2472 ? dir_northwest : dir_north;
-	else if (deltax > 0) // north-east
-		return dydx >= -424 ? dir_east : dydx >= -2472 ? dir_northeast : dir_north;
-	else			// south-west
-		return dydx >= -424 ? dir_west : dydx >= -2472 ? dir_southwest : dir_south;
+
+	if (dirmode == dirmode_8dirs) {
+		int dydx = (1024 * deltay) / deltax;
+
+		if (dydx >= 0)
+			if (deltax > 0) // south-east
+				return dydx <= 424 ? dir_east : dydx <= 2472 ? dir_southeast : dir_south;
+			else			// north-west
+				return dydx <= 424 ? dir_west : dydx <= 2472 ? dir_northwest : dir_north;
+		else if (deltax > 0) // north-east
+			return dydx >= -424 ? dir_east : dydx >= -2472 ? dir_northeast : dir_north;
+		else			// south-west
+			return dydx >= -424 ? dir_west : dydx >= -2472 ? dir_southwest : dir_south;
+	} else {
+		double angle = Common::rad2deg(atan2(deltay, deltax));
+		if (angle < -168.75)      return dir_west;
+		else if (angle < -146.25) return dir_wnw;
+		else if (angle < -123.75) return dir_northwest;
+		else if (angle < -101.25) return dir_nnw;
+		else if (angle < -78.75)  return dir_north;
+		else if (angle < -56.25)  return dir_nne;
+		else if (angle < -33.75)  return dir_northeast;
+		else if (angle < -11.25)  return dir_ene;
+		else if (angle < 11.25)   return dir_east;
+		else if (angle < 33.75)   return dir_ese;
+		else if (angle < 56.25)   return dir_southeast;
+		else if (angle < 78.75)   return dir_sse;
+		else if (angle < 101.25)  return dir_south;
+		else if (angle < 123.75)  return dir_ssw;
+		else if (angle < 146.25)  return dir_southwest;
+		else if (angle < 168.75)  return dir_wsw;
+		return dir_west;
+	}
 }
 
+
+
 inline Direction Direction_GetWorldDirInRange(int deltay, int deltax, DirectionMode dirmode, Direction mindir, Direction maxdir) {
-	// TODO: Implement 16 directions here.
-	int ndirs = 8;
-	dirmode = dirmode_8dirs;
+	int ndirs = (dirmode == dirmode_8dirs ? 8 : 16);
 	Direction dir = Direction_GetWorldDir(deltay, deltax, dirmode);
 
 	if ((dir < mindir) || (dir > maxdir)) {


Commit: 4f7881fe8a81c1b6e64e1caaf272da05826129a6
    https://github.com/scummvm/scummvm/commit/4f7881fe8a81c1b6e64e1caaf272da05826129a6
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2020-12-27T16:44:44+09:00

Commit Message:
TEST: Add direction util tests for U8

Changed paths:
  A test/engines/ultima/ultima8/misc/direction_util.h


diff --git a/test/engines/ultima/ultima8/misc/direction_util.h b/test/engines/ultima/ultima8/misc/direction_util.h
new file mode 100644
index 0000000000..ea639445d0
--- /dev/null
+++ b/test/engines/ultima/ultima8/misc/direction_util.h
@@ -0,0 +1,51 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/ultima8/misc/direction.h"
+#include "engines/ultima/ultima8/misc/direction_util.h"
+/**
+ * Test suite for the functions in engines/ultima/ultima8/misc/direction_util.h
+ */
+
+class U8DirectionTestSuite : public CxxTest::TestSuite {
+	public:
+	U8DirectionTestSuite() {
+	}
+
+	// save some typing later..
+	static const Ultima::Ultima8::DirectionMode dirmode8 = Ultima::Ultima8::dirmode_8dirs;
+	static const Ultima::Ultima8::DirectionMode dirmode16 = Ultima::Ultima8::dirmode_16dirs;
+
+	// test Direction_Get(deltay, deltax, dirmode)
+	void _test_direction_get_basic(Ultima::Ultima8::DirectionMode mode) {
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get( 1,  1, mode), Ultima::Ultima8::dir_north);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get( 0,  1, mode), Ultima::Ultima8::dir_northeast);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get(-1,  1, mode), Ultima::Ultima8::dir_east);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get(-1,  0, mode), Ultima::Ultima8::dir_southeast);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get(-1, -1, mode), Ultima::Ultima8::dir_south);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get( 0, -1, mode), Ultima::Ultima8::dir_southwest);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get( 1, -1, mode), Ultima::Ultima8::dir_west);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_Get( 1,  0, mode), Ultima::Ultima8::dir_northwest);
+	}
+
+	void test_direction_get() {
+		_test_direction_get_basic(dirmode8);
+		_test_direction_get_basic(dirmode16);
+	}
+
+	void _test_direction_get_worlddir(Ultima::Ultima8::DirectionMode mode) {
+		// Note Y is flipped from what you might expect
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir(-1,  0, mode), Ultima::Ultima8::dir_north);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir(-1,  1, mode), Ultima::Ultima8::dir_northeast);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir( 0,  1, mode), Ultima::Ultima8::dir_east);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir( 1,  1, mode), Ultima::Ultima8::dir_southeast);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir( 1,  0, mode), Ultima::Ultima8::dir_south);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir( 1, -1, mode), Ultima::Ultima8::dir_southwest);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir( 0, -1, mode), Ultima::Ultima8::dir_west);
+		TS_ASSERT_EQUALS(Ultima::Ultima8::Direction_GetWorldDir(-1, -1, mode), Ultima::Ultima8::dir_northwest);
+	}
+
+	void test_direction_get_worlddir() {
+		_test_direction_get_worlddir(dirmode8);
+		_test_direction_get_worlddir(dirmode16);
+	}
+
+};


Commit: bee90fbc9c63817b29184672807ecf012cd4d076
    https://github.com/scummvm/scummvm/commit/bee90fbc9c63817b29184672807ecf012cd4d076
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2020-12-27T17:41:28+09:00

Commit Message:
ICB: More type fixes

Changed paths:
    engines/icb/fn_interact.cpp
    engines/icb/function.cpp
    engines/icb/player.cpp


diff --git a/engines/icb/fn_interact.cpp b/engines/icb/fn_interact.cpp
index 16cd716b7b..68510ac37f 100644
--- a/engines/icb/fn_interact.cpp
+++ b/engines/icb/fn_interact.cpp
@@ -251,7 +251,7 @@ mcodeFunctionReturnCodes _game_session::Core_prop_interact(int32 & /*result*/, i
 	__mega_set_names anim;
 	PXreal destx, destz;
 	PXfloat diff;
-	int retval;
+	int32 retval;
 	PXreal sub1, sub2, len, len2;
 	uint32 j;
 
diff --git a/engines/icb/function.cpp b/engines/icb/function.cpp
index 4031fd0a12..783b948ef0 100644
--- a/engines/icb/function.cpp
+++ b/engines/icb/function.cpp
@@ -793,7 +793,7 @@ mcodeFunctionReturnCodes _game_session::fn_call_socket(int32 &result, int32 *par
 	//	params   0       ascii name of target object
 	//				1     ascii name of socket script
 
-	int retval;
+	int32 retval;
 	uint32 script_hash;
 
 	const char *target_object_name = (const char *)MemoryUtil::resolvePtr(params[0]);
diff --git a/engines/icb/player.cpp b/engines/icb/player.cpp
index 6c1cf9169a..277f8fe4bb 100644
--- a/engines/icb/player.cpp
+++ b/engines/icb/player.cpp
@@ -178,7 +178,7 @@ __mode_return _player::Player_press_fire_button() {
 	//				__MORE_THIS_CYCLE
 
 	bool8 res;
-	int retval;
+	int32 retval;
 
 	// check for interact button
 	if ((being_shot == 0) && (cur_state.IsButtonSet(__ATTACK)) && (!fire_lock) && (GetNoBullets())) {




More information about the Scummvm-git-logs mailing list