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

dreammaster paulfgilbert at gmail.com
Mon Oct 26 01:20:09 UTC 2020


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

Summary:
b30d9ceefd GLK: COMPREHEND: Change _words array to use Common::Array
b104ca3fd5 GLK: COMPREHEND: Fix the item indexes for CLEAR_WORD/SET_WORD


Commit: b30d9ceefd251bb8c743a3f08ae3db9474745af5
    https://github.com/scummvm/scummvm/commit/b30d9ceefd251bb8c743a3f08ae3db9474745af5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-10-25T18:17:24-07:00

Commit Message:
GLK: COMPREHEND: Change _words array to use Common::Array

Changed paths:
    engines/glk/comprehend/debugger_dumper.cpp
    engines/glk/comprehend/debugger_dumper.h
    engines/glk/comprehend/dictionary.cpp
    engines/glk/comprehend/game_data.cpp
    engines/glk/comprehend/game_data.h


diff --git a/engines/glk/comprehend/debugger_dumper.cpp b/engines/glk/comprehend/debugger_dumper.cpp
index 1e6769b07b..656c585d74 100644
--- a/engines/glk/comprehend/debugger_dumper.cpp
+++ b/engines/glk/comprehend/debugger_dumper.cpp
@@ -222,36 +222,26 @@ void DebuggerDumper::dumpActionTable() {
 	}
 }
 
-int DebuggerDumper::wordIndexCompare(const void *a, const void *b) {
-	const Word *word_a = (const Word *)a, *word_b = (const Word *)b;
-
-	if (word_a->_index > word_b->_index)
+int DebuggerDumper::wordIndexCompare(const Word &a, const Word &b) {
+	if (a._index > b._index)
 		return 1;
-	if (word_a->_index < word_b->_index)
+	if (a._index < b._index)
 		return -1;
 	return 0;
 }
 
 void DebuggerDumper::dumpDictionary() {
-	Word *dictionary;
-	Word *words;
-	uint i;
+	Common::Array<Word> dictionary;
 
 	/* Sort the dictionary by index */
-	dictionary = (Word *)malloc(sizeof(*words) * _game->_nr_words);
-	memcpy(dictionary, _game->_words,
-	       sizeof(*words) * _game->_nr_words);
-	qsort(dictionary, _game->_nr_words, sizeof(*words),
-	      wordIndexCompare);
-
-	print("Dictionary (%u words)\n", (uint)_game->_nr_words);
-	for (i = 0; i < _game->_nr_words; i++) {
-		words = &dictionary[i];
-		print("  [%.2x] %.2x %s\n", words->_index, words->_type,
-		      words->_word);
-	}
+	dictionary = _game->_words;
+	Common::sort(dictionary.begin(), dictionary.end(), wordIndexCompare);
 
-	free(dictionary);
+	print("Dictionary (%u words)\n", dictionary.size());
+	for (uint i = 0; i < dictionary.size(); i++) {
+		const Word &word = dictionary[i];
+		print("  [%.2x] %.2x %s\n", word._index, word._type, word._word);
+	}
 }
 
 void DebuggerDumper::dumpWordMap() {
@@ -321,7 +311,7 @@ void DebuggerDumper::dumpItems() {
 			      _game->stringLookup(item->_longString).c_str());
 
 		print("    words: ");
-		for (j = 0; j < _game->_nr_words; j++)
+		for (j = 0; j < _game->_words.size(); j++)
 			if (_game->_words[j]._index == item->_word &&
 			        (_game->_words[j]._type & WORD_TYPE_NOUN_MASK))
 				print("%s ", _game->_words[j]._word);
diff --git a/engines/glk/comprehend/debugger_dumper.h b/engines/glk/comprehend/debugger_dumper.h
index 5a952f22ad..59b9d98f66 100644
--- a/engines/glk/comprehend/debugger_dumper.h
+++ b/engines/glk/comprehend/debugger_dumper.h
@@ -32,6 +32,7 @@ namespace Comprehend {
 class ComprehendGame;
 struct FunctionState;
 struct Instruction;
+struct Word;
 
 class DebuggerDumper {
 private:
@@ -42,7 +43,7 @@ private:
 	void dumpFunctions();
 	void dumpFunction(uint functionNum);
 	void dumpActionTable();
-	static int wordIndexCompare(const void *a, const void *b);
+	static int wordIndexCompare(const Word &a, const Word &b);
 	void dumpDictionary();
 	void dumpWordMap();
 	void dumpRooms();
diff --git a/engines/glk/comprehend/dictionary.cpp b/engines/glk/comprehend/dictionary.cpp
index f7c99f1d48..10ebd977ba 100644
--- a/engines/glk/comprehend/dictionary.cpp
+++ b/engines/glk/comprehend/dictionary.cpp
@@ -43,7 +43,7 @@ Word *dict_find_word_by_string(ComprehendGame *game,
 	if (!string)
 		return NULL;
 
-	for (i = 0; i < game->_nr_words; i++)
+	for (i = 0; i < game->_words.size(); i++)
 		if (word_match(&game->_words[i], string))
 			return &game->_words[i];
 
@@ -54,7 +54,7 @@ Word *dict_find_word_by_index_type(ComprehendGame *game,
                                    uint8 index, uint8 type) {
 	uint i;
 
-	for (i = 0; i < game->_nr_words; i++) {
+	for (i = 0; i < game->_words.size(); i++) {
 		if (game->_words[i]._index == index &&
 		        game->_words[i]._type == type)
 			return &game->_words[i];
@@ -67,7 +67,7 @@ Word *find_dict_word_by_index(ComprehendGame *game,
                               uint8 index, uint8 type_mask) {
 	uint i;
 
-	for (i = 0; i < game->_nr_words; i++) {
+	for (i = 0; i < game->_words.size(); i++) {
 		if (game->_words[i]._index == index &&
 		        (game->_words[i]._type & type_mask) != 0)
 			return &game->_words[i];
@@ -80,7 +80,7 @@ bool dict_match_index_type(ComprehendGame *game, const char *word,
                            uint8 index, uint8 type_mask) {
 	uint i;
 
-	for (i = 0; i < game->_nr_words; i++)
+	for (i = 0; i < game->_words.size(); i++)
 		if (game->_words[i]._index == index &&
 		        ((game->_words[i]._type & type_mask) != 0) &&
 		        word_match(&game->_words[i], word))
diff --git a/engines/glk/comprehend/game_data.cpp b/engines/glk/comprehend/game_data.cpp
index ec4db6fc7f..ed01b1edd1 100644
--- a/engines/glk/comprehend/game_data.cpp
+++ b/engines/glk/comprehend/game_data.cpp
@@ -156,8 +156,6 @@ void GameData::clearGame() {
 	_comprehendVersion = 0;
 	_startRoom = 0;
 	_currentRoom = 0;
-	_words = nullptr;
-	_nr_words = 0;
 	_currentReplaceWord = 0;
 	_updateFlags = 0;
 	_colorTable = 0;
@@ -273,13 +271,9 @@ void GameData::parse_action_tables(FileBuffer *fb) {
 }
 
 void GameData::parse_dictionary(FileBuffer *fb) {
-	uint i;
-
-	// FIXME - fixed size 0xff array?
-	_words = (Word *)malloc(_nr_words * sizeof(Word));
-
 	fb->seek(_header.addr_dictionary);
-	for (i = 0; i < _nr_words; i++)
+
+	for (uint i = 0; i < _words.size(); i++)
 		_words[i].load(fb);
 }
 
@@ -621,9 +615,7 @@ void GameData::parse_header(FileBuffer *fb) {
 	_rooms.resize(header->room_direction_table[DIRECTION_SOUTH] -
 	                    header->room_direction_table[DIRECTION_NORTH] + 1);
 
-	_nr_words = (addr_dictionary_end -
-	                   header->addr_dictionary) /
-	                  8;
+	_words.resize((addr_dictionary_end - header->addr_dictionary) / 8);
 }
 
 void GameData::load_extra_string_file(const StringFile &stringFile) {
diff --git a/engines/glk/comprehend/game_data.h b/engines/glk/comprehend/game_data.h
index 4a6931f086..cc6c6ed8fc 100644
--- a/engines/glk/comprehend/game_data.h
+++ b/engines/glk/comprehend/game_data.h
@@ -387,9 +387,7 @@ public:
 	uint8 _totalInventoryWeight;
 
 	Common::Array<Item> _items;
-
-	Word *_words;
-	size_t _nr_words;
+	Common::Array<Word> _words;
 
 	StringTable _strings;
 	StringTable _strings2;


Commit: b104ca3fd5d37e863342ed00e03c607b84c72091
    https://github.com/scummvm/scummvm/commit/b104ca3fd5d37e863342ed00e03c607b84c72091
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-10-25T18:17:24-07:00

Commit Message:
GLK: COMPREHEND: Fix the item indexes for CLEAR_WORD/SET_WORD

Changed paths:
    engines/glk/comprehend/game_opcodes.cpp


diff --git a/engines/glk/comprehend/game_opcodes.cpp b/engines/glk/comprehend/game_opcodes.cpp
index 11ed59d641..f3c61198c5 100644
--- a/engines/glk/comprehend/game_opcodes.cpp
+++ b/engines/glk/comprehend/game_opcodes.cpp
@@ -73,7 +73,7 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		break;
 
 	case OPCODE_CLEAR_WORD:
-		item = get_item(instr->_operand[0]);
+		item = get_item(instr->_operand[0] - 1);
 		item->_word = 0;
 		break;
 
@@ -253,7 +253,7 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		break;
 
 	case OPCODE_SET_WORD:
-		item = get_item(instr->_operand[0]);
+		item = get_item(instr->_operand[0] - 1);
 		item->_word = instr->_operand[1];
 		break;
 




More information about the Scummvm-git-logs mailing list