[Scummvm-cvs-logs] SF.net SVN: scummvm: [25733] scummvm/trunk/engines/parallaction
peres001 at users.sourceforge.net
peres001 at users.sourceforge.net
Mon Feb 19 23:34:04 CET 2007
Revision: 25733
http://scummvm.svn.sourceforge.net/scummvm/?rev=25733&view=rev
Author: peres001
Date: 2007-02-19 14:34:00 -0800 (Mon, 19 Feb 2007)
Log Message:
-----------
first step in parser simplification
Modified Paths:
--------------
scummvm/trunk/engines/parallaction/animation.cpp
scummvm/trunk/engines/parallaction/commands.cpp
scummvm/trunk/engines/parallaction/dialogue.cpp
scummvm/trunk/engines/parallaction/location.cpp
scummvm/trunk/engines/parallaction/parallaction.cpp
scummvm/trunk/engines/parallaction/parallaction.h
scummvm/trunk/engines/parallaction/parser.cpp
scummvm/trunk/engines/parallaction/parser.h
scummvm/trunk/engines/parallaction/zone.cpp
Modified: scummvm/trunk/engines/parallaction/animation.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/animation.cpp 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/animation.cpp 2007-02-19 22:34:00 UTC (rev 25733)
@@ -85,7 +85,7 @@
addNode(list, &vD0->_zone._node);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "endanimation")) {
// printf("token[0] = %s\n", _tokens[0]);
@@ -142,7 +142,7 @@
vD0->_zone._moveTo._y = atoi(_tokens[2]);
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
vD0->_zone.pos._oldposition._x = -1000;
Modified: scummvm/trunk/engines/parallaction/commands.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/commands.cpp 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/commands.cpp 2007-02-19 22:34:00 UTC (rev 25733)
@@ -51,7 +51,7 @@
Node root;
memset(&root, 0, sizeof(root));
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDCOMMANDS") && scumm_stricmp(_tokens[0], "ENDZONE")) {
// printf("token[0] = %s", _tokens[0]);
@@ -185,7 +185,7 @@
}
addNode(&root, &cmd->_node);
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
}
Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp 2007-02-19 22:34:00 UTC (rev 25733)
@@ -57,9 +57,8 @@
int16 _answerBalloonH[10] = { 0 };
-char *parseDialogueString();
-Dialogue *parseDialogue(ArchivedFile *file) {
+Dialogue *Parallaction::parseDialogue(ArchivedFile *file) {
// printf("parseDialogue()\n");
uint16 num_questions = 0;
uint16 v50[20];
@@ -70,7 +69,7 @@
v50[_si] = 0;
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "enddialogue")) {
if (scumm_stricmp(_tokens[0], "Question")) continue;
@@ -85,12 +84,12 @@
vB4->_text = parseDialogueString();
// printf("Question: '%s'\n", vB4->_text);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
vB4->_mood = atoi(_tokens[0]);
uint16 _di = 0;
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "endquestion")) { // parse answers
const char** v60 = const_cast<const char **>(_localFlagNames);
@@ -124,20 +123,20 @@
// printf("answer[%i]: '%s'\n", _di, vB4->_answers[_di]);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
vB4->_answer_moods[_di] = atoi(_tokens[0]);
vB4->_following._names[_di] = parseDialogueString();
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
if (!scumm_stricmp(_tokens[0], "commands")) {
vB4->_commands[_di] = parseCommands(file);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
_di++;
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
num_questions++;
}
@@ -173,13 +172,13 @@
}
-char *parseDialogueString() {
+char *Parallaction::parseDialogueString() {
char vC8[200];
char *vD0 = NULL;
do {
- vD0 = parseNextLine(vC8, 200);
+ vD0 = _locationScript->readLine(vC8, 200);
if (vD0 == 0) return NULL;
vD0 = Common::ltrim(vD0);
Modified: scummvm/trunk/engines/parallaction/location.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/location.cpp 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/location.cpp 2007-02-19 22:34:00 UTC (rev 25733)
@@ -76,13 +76,14 @@
uint32 count = file->_endOffset - file->_offset;
location_src = (char*)memAlloc(0x4000);
- parseInit(location_src);
+ _locationScript = new LocScript(location_src);
+// parseInit(location_src);
readArchivedFile(file, location_src, count);
closeArchivedFile(file);
closeArchive();
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDLOCATION")) {
// printf("token[0] = %s", _tokens[0]);
@@ -186,7 +187,7 @@
if (!scumm_stricmp(_tokens[0], "SOUND")) {
strcpy(_soundFile, _tokens[1]);
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
resolveLocationForwards();
@@ -264,7 +265,7 @@
void parseWalkNodes(ArchivedFile *file, Node *list) {
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDNODES")) {
if (!scumm_stricmp(_tokens[0], "COORD")) {
@@ -277,7 +278,7 @@
}
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
}
return;
Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp 2007-02-19 22:34:00 UTC (rev 25733)
@@ -1017,7 +1017,7 @@
uint16 count = 0;
- tableFillBuffers(stream);
+ fillBuffers(stream);
while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
@@ -1025,7 +1025,7 @@
strcpy(table[count], _tokens[0]);
count++;
- tableFillBuffers(stream);
+ fillBuffers(stream);
}
table[count] = NULL;
Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/parallaction.h 2007-02-19 22:34:00 UTC (rev 25733)
@@ -26,6 +26,7 @@
#include "engines/engine.h"
#include "parallaction/defs.h"
#include "parallaction/inventory.h"
+#include "parallaction/parser.h"
#include "common/str.h"
#include "gui/dialog.h"
#include "gui/widget.h"
@@ -240,6 +241,11 @@
void changeCursor(int32 index);
void changeCharacter(const char *name);
+ char *parseComment(ArchivedFile *file);
+ char *parseDialogueString();
+ Dialogue *parseDialogue(ArchivedFile *file);
+
+
public:
int getGameType() const;
uint32 getFeatures() const;
@@ -263,6 +269,8 @@
InventoryItem _activeItem;
+ LocScript *_locationScript;
+
protected: // data
struct InputData {
Modified: scummvm/trunk/engines/parallaction/parser.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser.cpp 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/parser.cpp 2007-02-19 22:34:00 UTC (rev 25733)
@@ -22,11 +22,13 @@
#include "parallaction/defs.h"
#include "parallaction/parser.h"
+#include "parallaction/parallaction.h"
#include "parallaction/disk.h"
namespace Parallaction {
char _tokens[20][40];
+/*
static char *_src = NULL;
@@ -54,19 +56,84 @@
return s;
}
+*/
+LocScript::LocScript(const char* s) : _src(s) {
+}
+
+char *LocScript::readLine(char *buf, size_t bufSize) {
+
+ uint16 _si;
+ char v2 = 0;
+ for ( _si = 0; _si<bufSize; _si++) {
+
+ v2 = *_src++;
+ if (v2 == 0xA || v2 == -1) break;
+ if (v2 != -1 && _si < bufSize) buf[_si] = v2;
+ }
+
+ if (_si == 0 && v2 == -1)
+ return 0;
+
+ buf[_si] = 0xA;
+ buf[_si+1] = '\0';
+
+ return buf;
+
+}
+
+uint32 LocScript::read(void *dataPtr, uint32 dataSize) {
+ error("binary read not supported on LocScript streams");
+}
+
+bool LocScript::eos() const {
+ error("EoS not supported on LocScript streams");
+}
+
+uint32 LocScript::pos() const {
+ error("position not supported on LocScript streams");
+}
+
+uint32 LocScript::size() const {
+ error("can't get size of LocScript streams");
+}
+
+void LocScript::seek(int32 offset, int whence) {
+ error("seek not supported on LocScript streams");
+}
+
+// looks for next token in a string
//
+// scans 's' until one of the stop-chars in 'brk' is found
+// builds a token and return the part of the string which hasn't been parsed
+
+char *parseNextToken(char *s, char *tok, uint16 count, const char *brk) {
+
+ while (*s != '\0') {
+
+ if (brk[0] == *s) break;
+ if (brk[1] == *s) break;
+ if (brk[2] == *s) break;
+
+ *tok++ = *s++;
+ }
+
+ *tok = '\0';
+ return s;
+}
+
+//
// a comment can appear both at location and Zone levels
// comments are displayed into rectangles on the screen
//
-char *parseComment(ArchivedFile *file) {
+char *Parallaction::parseComment(ArchivedFile *file) {
char _tmp_comment[1000] = "\0";
char *v194;
do {
char v190[400];
- v194 = parseNextLine(v190, 400);
+ v194 = _locationScript->readLine(v190, 400);
v194[strlen(v194)-1] = '\0';
if (!scumm_stricmp(v194, "endtext"))
@@ -113,26 +180,29 @@
return i;
}
-uint16 parseFillBuffers() {
+uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF) {
clearTokens();
char buf[200];
char *line = NULL;
do {
- line = parseNextLine(buf, 200);
+ line = stream.readLine(buf, 200);
if (line == NULL) {
- error("unexpected end of file while parsing");
+ if (errorOnEOF)
+ error("unexpected end of file while parsing");
+ else
+ return 0;
}
line = Common::ltrim(line);
} while (strlen(line) == 0 || line[0] == '#');
return fillTokens(line);
}
-
+/*
//
// FIXME
-// this function does the same Job as parseFillBuffers, except that
+// this function does the same Job as fillBuffers, except that
// it gets input from a SeekableStream instead of a memory buffer
//
uint16 tableFillBuffers(Common::SeekableReadStream &stream) {
@@ -151,10 +221,10 @@
return fillTokens(line);
}
+*/
-
// FIXME
-// this function does the same Job as parseFillBuffers, except that
+// this function does the same Job as fillBuffers, except that
// it gets input from an ArchivedFile instead of a memory buffer
//
uint16 scriptFillBuffers(ArchivedFile *file) {
@@ -174,26 +244,4 @@
return fillTokens(line);
}
-
-// looks for next token in a string
-//
-// scans 's' until one of the stop-chars in 'brk' is found
-// builds a token and return the part of the string which hasn't been parsed
-
-char *parseNextToken(char *s, char *tok, uint16 count, const char *brk) {
-
- while (*s != '\0') {
-
- if (brk[0] == *s) break;
- if (brk[1] == *s) break;
- if (brk[2] == *s) break;
-
- *tok++ = *s++;
- }
-
- *tok = '\0';
- return s;
-}
-
-
} // namespace Parallaction
Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/parser.h 2007-02-19 22:34:00 UTC (rev 25733)
@@ -24,7 +24,7 @@
#define PARALLACTION_PARSER_H
#include "parallaction/defs.h"
-#include "common/file.h"
+#include "common/stream.h"
namespace Parallaction {
@@ -33,7 +33,7 @@
void parseInit(char *s);
char *parseNextLine(char *s, uint16 count);
char *parseComment(ArchivedFile *file);
-uint16 parseFillBuffers();
+uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF = false);
char *parseNextToken(char *s, char *tok, uint16 count, const char *brk);
uint16 tableFillBuffers(Common::SeekableReadStream &stream);
@@ -42,6 +42,24 @@
extern char _tokens[][40];
+class LocScript : public Common::SeekableReadStream {
+
+ const char* _src;
+
+public:
+ LocScript(const char* s);
+
+ uint32 read(void *dataPtr, uint32 dataSize);
+
+ char *readLine(char *buf, size_t bufSize);
+
+ bool eos() const;
+ uint32 pos() const;
+ uint32 size() const;
+
+ void seek(int32 offset, int whence = SEEK_SET);
+};
+
} // namespace Parallaction
#endif
Modified: scummvm/trunk/engines/parallaction/zone.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/zone.cpp 2007-02-19 21:11:13 UTC (rev 25732)
+++ scummvm/trunk/engines/parallaction/zone.cpp 2007-02-19 22:34:00 UTC (rev 25733)
@@ -59,7 +59,7 @@
if (findZone(name)) {
while (scumm_stricmp(_tokens[0], "endzone")) {
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
return;
}
@@ -72,7 +72,7 @@
addNode(list, &z->_node);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "endzone")) {
// printf("token[0] = %s", _tokens[0]);
@@ -114,7 +114,7 @@
} while (!scumm_stricmp(_tokens[_si++], "|"));
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
return;
@@ -352,7 +352,7 @@
break;
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
} while (scumm_stricmp(_tokens[0], "endzone"));
return;
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