[Scummvm-git-logs] scummvm master -> 27abcdc44c023085df9ba02f98ee891367aa08ea

dreammaster paulfgilbert at gmail.com
Sun Nov 1 23:10:04 UTC 2020


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

Summary:
0e926f8ab7 GLK: COMPREHEND: Move input line buffer to a class field
25cbbb7743 GLK: COMPREHEND: Flag40 operands use parameter rather than noun
27abcdc44c GLK: COMPREHEND: Further opcodes implemented


Commit: 0e926f8ab752dece1aedbea27b3627e9db78c394
    https://github.com/scummvm/scummvm/commit/0e926f8ab752dece1aedbea27b3627e9db78c394
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-11-01T14:55:09-08:00

Commit Message:
GLK: COMPREHEND: Move input line buffer to a class field

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


diff --git a/engines/glk/comprehend/game.cpp b/engines/glk/comprehend/game.cpp
index 5df71610b7..b851eb9fc7 100644
--- a/engines/glk/comprehend/game.cpp
+++ b/engines/glk/comprehend/game.cpp
@@ -116,7 +116,8 @@ void Sentence::format() {
 
 
 ComprehendGame::ComprehendGame() : _gameStrings(nullptr), _ended(false),
-		_nounState(NOUNSTATE_INITIAL) {
+		_nounState(NOUNSTATE_INITIAL), _inputLineIndex(0) {
+	Common::fill(&_inputLine[0], &_inputLine[INPUT_LINE_SIZE], 0);
 }
 
 ComprehendGame::~ComprehendGame() {
@@ -595,12 +596,12 @@ void ComprehendGame::eval_function(uint functionNum, const Sentence *sentence) {
 	debugC(kDebugScripts, "End of function %.4x\n", functionNum);
 }
 
-void ComprehendGame::skip_whitespace(char **p) {
+void ComprehendGame::skip_whitespace(const char **p) {
 	while (**p && Common::isSpace(**p))
 		(*p)++;
 }
 
-void ComprehendGame::skip_non_whitespace(char **p) {
+void ComprehendGame::skip_non_whitespace(const char **p) {
 	while (**p && !Common::isSpace(**p) && **p != ',' && **p != '\n')
 		(*p)++;
 }
@@ -716,31 +717,31 @@ bool ComprehendGame::handle_sentence(uint tableNum, Sentence *sentence, Common::
 	return false;
 }
 
-void ComprehendGame::read_sentence(char **line,
-                          Sentence *sentence) {
+void ComprehendGame::read_sentence(Sentence *sentence) {
 	bool sentence_end = false;
-	char *word_string, *p = *line;
+	const char *word_string, *p = &_inputLine[_inputLineIndex];
 	Word *word;
 
 	sentence->clear();
-	while (1) {
+	for (;;) {
+		// Get the next word
 		skip_whitespace(&p);
 		word_string = p;
 		skip_non_whitespace(&p);
 
+		Common::String wordStr(word_string, p);
+
+		// Check for end of sentence
 		if (*p == ',' || *p == '\n') {
-			/* Sentence separator */
-			*p++ = '\0';
+			// Sentence separator
+			++p;
+			sentence_end = true;
+		} else if (*p == '\0') {
 			sentence_end = true;
-		} else {
-			if (*p == '\0')
-				sentence_end = true;
-			else
-				*p++ = '\0';
 		}
 
 		/* Find the dictionary word for this */
-		word = dict_find_word_by_string(this, word_string);
+		word = dict_find_word_by_string(this, wordStr.c_str());
 		if (!word)
 			sentence->_words[sentence->_nr_words].clear();
 		else
@@ -756,7 +757,7 @@ void ComprehendGame::read_sentence(char **line,
 	parse_sentence_word_pairs(sentence);
 	sentence->format();
 
-	*line = p;
+	_inputLineIndex = p - _inputLine;
 }
 
 void ComprehendGame::parse_sentence_word_pairs(Sentence *sentence) {
@@ -805,10 +806,8 @@ void ComprehendGame::doAfterTurn() {
 
 void ComprehendGame::read_input() {
 	Sentence tempSentence;
-	char *line = NULL, buffer[1024];
 	bool handled;
 
-
 	beforePrompt();
 	doBeforeTurn();
 	if (_ended)
@@ -821,11 +820,12 @@ void ComprehendGame::read_input() {
 
 	for (;;) {
 		g_comprehend->print("> ");
-		g_comprehend->readLine(buffer, sizeof(buffer));
+		g_comprehend->readLine(_inputLine, INPUT_LINE_SIZE);
 		if (g_comprehend->shouldQuit())
 			return;
 
-		if (strlen(buffer) != 0)
+		_inputLineIndex = 0;
+		if (strlen(_inputLine) != 0)
 			break;
 
 		// Empty line, so toggle picture window visibility
@@ -837,14 +837,11 @@ void ComprehendGame::read_input() {
 		continue;
 	}
 
-	// Re-comprehend special commands start with '!'
-	line = &buffer[0];
-
-	while (1) {
+	for (;;) {
 		NounState prevNounState = _nounState;
 		_nounState = NOUNSTATE_STANDARD;
 
-		read_sentence(&line, &tempSentence);
+		read_sentence(&tempSentence);
 		_sentence.copyFrom(tempSentence, tempSentence._formattedWords[0] || prevNounState != NOUNSTATE_QUERY);
 
 		handled = handle_sentence(&_sentence);
@@ -852,9 +849,8 @@ void ComprehendGame::read_input() {
 			doAfterTurn();
 
 		/* FIXME - handle the 'before you can continue' case */
-		if (*line == '\0')
+		if (_inputLine[_inputLineIndex] == '\0')
 			break;
-		line++;
 
 		if (handled)
 			doBeforeTurn();
diff --git a/engines/glk/comprehend/game.h b/engines/glk/comprehend/game.h
index fcaeb1fb2d..a328277c97 100644
--- a/engines/glk/comprehend/game.h
+++ b/engines/glk/comprehend/game.h
@@ -33,6 +33,7 @@ namespace Comprehend {
 #define ROOM_IS_NORMAL 0
 #define ROOM_IS_DARK 1
 #define ROOM_IS_TOO_BRIGHT 2
+#define INPUT_LINE_SIZE 1024
 
 enum NounState { NOUNSTATE_STANDARD = 0, NOUNSTATE_QUERY = 1, NOUNSTATE_INITIAL = 2 };
 
@@ -76,6 +77,8 @@ protected:
 	bool _ended;
 	NounState _nounState;
 	Sentence _sentence;
+	char _inputLine[INPUT_LINE_SIZE];
+	int _inputLineIndex;
 public:
 	const GameStrings *_gameStrings;
 
@@ -84,11 +87,11 @@ private:
 	void eval_instruction(FunctionState *func_state,
 		const Function &func, uint functionOffset,
 		const Sentence *sentence);
-	void skip_whitespace(char **p);
-	void skip_non_whitespace(char **p);
+	void skip_whitespace(const char **p);
+	void skip_non_whitespace(const char **p);
 	bool handle_sentence(Sentence *sentence);
 	bool handle_sentence(uint tableNum, Sentence *sentence, Common::Array<byte> &words);
-	void read_sentence(char **line, Sentence *sentence);
+	void read_sentence(Sentence *sentence);
 	void parse_sentence_word_pairs(Sentence *sentence);
 	void doBeforeTurn();
 	void doAfterTurn();
diff --git a/engines/glk/comprehend/game_opcodes.cpp b/engines/glk/comprehend/game_opcodes.cpp
index 7e0ee309ce..5cf8a8ad4e 100644
--- a/engines/glk/comprehend/game_opcodes.cpp
+++ b/engines/glk/comprehend/game_opcodes.cpp
@@ -189,13 +189,14 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 
 	case OPCODE_SAVE_ACTION:
 		// Causes the next sentence inputed to re-use the first word of the current one.
-		// As far as I'm aware, this is only used for handling responses to rhethorical questions
+		// As far as I'm aware, this is only used for handling responses to questions
 		_nounState = NOUNSTATE_QUERY;
 		// fall-through
 
 	case OPCODE_CLEAR_LINE:
 		// Resets the input line, removing any pending further actions that were specified
-		// TODO: Make input line a class field, and reset it here
+		Common::fill(&_inputLine[0], &_inputLine[INPUT_LINE_SIZE], 0);
+		_inputLineIndex = 0;
 		break;
 
 	case OPCODE_SET_CAN_TAKE:


Commit: 25cbbb77436bed1b872b7f5f3378fd0b00181e1a
    https://github.com/scummvm/scummvm/commit/25cbbb77436bed1b872b7f5f3378fd0b00181e1a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-11-01T14:55:09-08:00

Commit Message:
GLK: COMPREHEND: Flag40 operands use parameter rather than noun

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


diff --git a/engines/glk/comprehend/debugger_dumper.cpp b/engines/glk/comprehend/debugger_dumper.cpp
index 4754900629..4f9eef88d5 100644
--- a/engines/glk/comprehend/debugger_dumper.cpp
+++ b/engines/glk/comprehend/debugger_dumper.cpp
@@ -135,7 +135,7 @@ Common::String DebuggerDumper::dumpInstruction(ComprehendGame *game,
 
 	line += Common::String::format("  [%.2x] ", instr->_opcode);
 	if (_opcodes.contains(opcode)) {
-		if (_game->_comprehendVersion == 2 && (instr->_opcode & 0x40) != 0)
+		if (_game->_comprehendVersion == 2 && !instr->_isCommand && (instr->_opcode & 0x40) != 0)
 			line += "!";
 		line += _opcodes[opcode];
 	} else {
diff --git a/engines/glk/comprehend/game_opcodes.cpp b/engines/glk/comprehend/game_opcodes.cpp
index 5cf8a8ad4e..64796b6b9e 100644
--- a/engines/glk/comprehend/game_opcodes.cpp
+++ b/engines/glk/comprehend/game_opcodes.cpp
@@ -63,7 +63,7 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		break;
 
 	case OPCODE_CLEAR_FLAG40:
-		item = get_item_by_noun(noun);
+		item = getItem(instr);
 		item->_flags &= ~ITEMF_UNKNOWN;
 		break;
 
@@ -73,7 +73,7 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		break;
 
 	case OPCODE_CLEAR_WORD:
-		item = get_item(instr->_operand[0] - 1);
+		item = getItem(instr);
 		item->_word = 0;
 		break;
 
@@ -209,7 +209,7 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		break;
 
 	case OPCODE_SET_FLAG40:
-		item = get_item_by_noun(noun);
+		item = getItem(instr);
 		item->_flags |= ITEMF_UNKNOWN;
 		break;
 
@@ -252,7 +252,7 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		break;
 
 	case OPCODE_SET_WORD:
-		item = get_item(instr->_operand[0] - 1);
+		item = getItem(instr);
 		item->_word = instr->_operand[1];
 		break;
 


Commit: 27abcdc44c023085df9ba02f98ee891367aa08ea
    https://github.com/scummvm/scummvm/commit/27abcdc44c023085df9ba02f98ee891367aa08ea
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-11-01T15:09:44-08:00

Commit Message:
GLK: COMPREHEND: Further opcodes implemented

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 64796b6b9e..09336b9f92 100644
--- a/engines/glk/comprehend/game_opcodes.cpp
+++ b/engines/glk/comprehend/game_opcodes.cpp
@@ -218,6 +218,11 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		item->_flags |= ITEMF_INVISIBLE;
 		break;
 
+	case OPCODE_SET_OBJECT_DESCRIPTION:
+		item = getItem(instr);
+		item->_stringDesc = (instr->_operand[2] << 8) | instr->_operand[1];
+		break;
+
 	case OPCODE_SET_ROOM_DESCRIPTION:
 		room = get_room(instr->_operand[0]);
 		switch (instr->_operand[2]) {
@@ -282,6 +287,10 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		func_set_test_result(func_state, room->_flags & instr->_operand[0]);
 		break;
 
+	case OPCODE_TURN_TICK:
+		_variables[VAR_TURN_COUNT]++;
+		break;
+
 	case OPCODE_VAR_ADD:
 		_variables[instr->_operand[0]] += _variables[instr->_operand[1]];
 		break;
@@ -295,11 +304,35 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 			_variables[instr->_operand[0]] == _variables[instr->_operand[1]]);
 		break;
 
+	case OPCODE_VAR_GT1:
+		func_set_test_result(func_state,
+			_variables[0] >
+			_variables[instr->_operand[0]]);
+		break;
+
 	case OPCODE_VAR_GT2:
 		func_set_test_result(func_state, _variables[instr->_operand[0]] >
 			_variables[instr->_operand[1]]);
 		break;
 
+	case OPCODE_VAR_GTE1:
+		func_set_test_result(func_state,
+			_variables[0] >=
+			_variables[instr->_operand[0]]);
+		break;
+
+	case OPCODE_VAR_GTE2:
+		func_set_test_result(func_state,
+			_variables[instr->_operand[0]] >=
+			_variables[instr->_operand[1]]);
+		break;
+
+	case OPCODE_VAR_EQ1:
+		func_set_test_result(func_state,
+			_variables[0] ==
+			_variables[instr->_operand[0]]);
+		break;
+
 	case OPCODE_VAR_INC:
 		_variables[instr->_operand[0]]++;
 		break;
@@ -453,34 +486,6 @@ void ComprehendGameV1::execute_opcode(const Instruction *instr, const Sentence *
 
 	/*--------------------------------------*/
 
-	case OPCODE_VAR_EQ1:
-		func_set_test_result(func_state,
-			_variables[0] ==
-			_variables[instr->_operand[0]]);
-		break;
-
-	case OPCODE_VAR_GT1:
-		func_set_test_result(func_state,
-			_variables[0] >
-			_variables[instr->_operand[0]]);
-		break;
-
-	case OPCODE_VAR_GTE1:
-		func_set_test_result(func_state,
-			_variables[0] >=
-			_variables[instr->_operand[0]]);
-		break;
-
-	case OPCODE_VAR_GTE2:
-		func_set_test_result(func_state,
-			_variables[instr->_operand[0]] >=
-			_variables[instr->_operand[1]]);
-		break;
-
-	case OPCODE_TURN_TICK:
-		_variables[VAR_TURN_COUNT]++;
-		break;
-
 	case OPCODE_TEST_NOT_ROOM_FLAG:
 		func_set_test_result(func_state,
 			!(room->_flags & instr->_operand[0]));
@@ -621,18 +626,6 @@ void ComprehendGameV1::execute_opcode(const Instruction *instr, const Sentence *
 			!_flags[instr->_operand[0]]);
 		break;
 
-	case OPCODE_SET_OBJECT_DESCRIPTION:
-		item = getItem(instr);
-		item->_stringDesc = (instr->_operand[2] << 8) | instr->_operand[1];
-		break;
-
-	case OPCODE_SET_OBJECT_GRAPHIC:
-		item = getItem(instr);
-		item->_graphic = instr->_operand[1];
-		if (item->_room == _currentRoom)
-			_updateFlags |= UPDATE_GRAPHICS;
-		break;
-
 	case OPCODE_TEST_FALSE:
 		// The original had two opcodes mapped to the same code that does
 		// a test, but ignores the result, and is always false
@@ -677,7 +670,10 @@ ComprehendGameV2::ComprehendGameV2() {
 	_opcodeMap[0x05] = OPCODE_IN_ROOM;
 	_opcodeMap[0x06] = OPCODE_VAR_EQ2;
 	_opcodeMap[0x08] = OPCODE_CURRENT_IS_OBJECT;
+	_opcodeMap[0x09] = OPCODE_VAR_GT1;
+	_opcodeMap[0x0a] = OPCODE_VAR_GTE2;
 	_opcodeMap[0x0c] = OPCODE_ELSE;
+	_opcodeMap[0x0d] = OPCODE_VAR_EQ1;
 	_opcodeMap[0x11] = OPCODE_OBJECT_IS_NOWHERE;
 	_opcodeMap[0x14] = OPCODE_CURRENT_OBJECT_NOT_VALID;
 	_opcodeMap[0x15] = OPCODE_INVENTORY_FULL_X;
@@ -699,12 +695,14 @@ ComprehendGameV2::ComprehendGameV2() {
 	_opcodeMap[0x88] = OPCODE_CLEAR_LINE;
 	_opcodeMap[0x89] = OPCODE_SPECIAL;
 	_opcodeMap[0x8a] = OPCODE_VAR_SUB;
+	_opcodeMap[0x8b] = OPCODE_SET_OBJECT_DESCRIPTION;
 	_opcodeMap[0x8c] = OPCODE_MOVE_DEFAULT;
 	_opcodeMap[0x8e] = OPCODE_PRINT;
 	_opcodeMap[0x8f] = OPCODE_SET_OBJECT_LONG_DESCRIPTION;
 	_opcodeMap[0x90] = OPCODE_WAIT_KEY;
 	_opcodeMap[0x92] = OPCODE_CALL_FUNC;
 	_opcodeMap[0x95] = OPCODE_CLEAR_WORD;
+	_opcodeMap[0x98] = OPCODE_TURN_TICK;
 	_opcodeMap[0x99] = OPCODE_SET_FLAG;
 	_opcodeMap[0x9a] = OPCODE_SET_WORD;
 	_opcodeMap[0x9d] = OPCODE_CLEAR_FLAG;
@@ -729,20 +727,6 @@ ComprehendGameV2::ComprehendGameV2() {
 	_opcodeMap[0xed] = OPCODE_REMOVE_OBJECT;
 
 #if 0
-	_opcodeMap[0x09] = OPCODE_VAR_GT1;
-	_opcodeMap[0x0a] = OPCODE_VAR_GTE2;
-	_opcodeMap[0x0d] = OPCODE_VAR_EQ1;
-	_opcodeMap[0x30] = OPCODE_CURRENT_OBJECT_PRESENT;
-	_opcodeMap[0x41] = OPCODE_NOT_HAVE_OBJECT;
-	_opcodeMap[0x45] = OPCODE_NOT_IN_ROOM;
-	_opcodeMap[0x48] = OPCODE_CURRENT_OBJECT_NOT_PRESENT;
-	_opcodeMap[0x43] = OPCODE_OBJECT_NOT_IN_ROOM;
-	_opcodeMap[0x59] = OPCODE_TEST_NOT_FLAG;
-	_opcodeMap[0x5d] = OPCODE_TEST_NOT_ROOM_FLAG;
-	_opcodeMap[0x60] = OPCODE_NOT_HAVE_CURRENT_OBJECT;
-	_opcodeMap[0x70] = OPCODE_CURRENT_OBJECT_NOT_PRESENT;
-	_opcodeMap[0x8b] = OPCODE_SET_OBJECT_DESCRIPTION;
-	_opcodeMap[0x98] = OPCODE_TURN_TICK;
 	_opcodeMap[0x9e] = OPCODE_INVENTORY_ROOM;
 	_opcodeMap[0xc6] = OPCODE_SET_OBJECT_GRAPHIC;
 	_opcodeMap[0xf0] = OPCODE_DROP_CURRENT_OBJECT;
@@ -815,6 +799,13 @@ void ComprehendGameV2::execute_opcode(const Instruction *instr, const Sentence *
 		func_set_test_result(func_state, item->_flags & ITEMF_CAN_TAKE);
 		break;
 
+	case OPCODE_SET_OBJECT_GRAPHIC:
+		item = getItem(instr);
+		item->_graphic = instr->_operand[1];
+		if (item->_room == _currentRoom)
+			_updateFlags |= UPDATE_GRAPHICS;
+		break;
+
 	case OPCODE_SET_OBJECT_LONG_DESCRIPTION:
 		item = getItem(instr);
 		item->_longString = (instr->_operand[2] << 8) | instr->_operand[1];




More information about the Scummvm-git-logs mailing list