[Scummvm-cvs-logs] CVS: residual textsplit.cpp,1.12,1.13 textsplit.h,1.7,1.8 walkplane.cpp,1.16,1.17 walkplane.h,1.13,1.14 scene.cpp,1.46,1.47
Erich Edgar Hoover
compholio at users.sourceforge.net
Tue Dec 27 21:23:04 CET 2005
- Previous message: [Scummvm-cvs-logs] CVS: scummvm NEWS,1.132.2.5,1.132.2.6
- Next message: [Scummvm-cvs-logs] CVS: scummvm/kyra kyra.cpp,1.98,1.99 kyra.h,1.55,1.56 script_v1.cpp,1.50,1.51 staticres.cpp,1.29,1.30
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27086
Modified Files:
textsplit.cpp textsplit.h walkplane.cpp walkplane.h scene.cpp
Log Message:
TextSplit rewind support, support for sectors in reverse order
Index: textsplit.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/textsplit.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- textsplit.cpp 25 Dec 2005 06:06:38 -0000 1.12
+++ textsplit.cpp 28 Dec 2005 05:22:18 -0000 1.13
@@ -55,10 +55,34 @@
}
TextSplitter::TextSplitter(const char *data, int len) {
- _data = new char[len + 1];
- std::memcpy(_data, data, len);
- _data[len] = '\0';
- _currLine = _data;
+ char *line, *tmpData;
+ int i;
+
+ tmpData = new char[len+1];
+ std::memcpy(tmpData, data, len);
+ tmpData[len] = '\0';
+ // Find out how many lines of text there are
+ _numLines = _lineIndex = 0;
+ line = (char *) tmpData;
+ while (line != NULL) {
+ line = std::strchr(line, '\n');
+ if (line != NULL) {
+ _numLines++;
+ line++;
+ }
+ }
+ // Allocate an array of the lines
+ _lines = new TextLines[_numLines];
+ line = (char *) tmpData;
+ for (i=0;i<_numLines;i++) {
+ char *lastLine = line;
+
+ line = std::strchr(lastLine, '\n');
+ _lines[i].setData(lastLine, line-lastLine);
+ line++;
+ }
+ delete[] tmpData;
+ _currLine = NULL;
processLine();
}
@@ -74,7 +98,7 @@
}
void TextSplitter::expectString(const char *expected) {
- if (eof())
+ if (_currLine == NULL)
error("Expected `%s', got EOF\n", expected);
if (std::strcmp(currentLine(), expected) != 0)
error("Expected `%s', got `%s'\n", expected, currentLine());
@@ -82,7 +106,7 @@
}
void TextSplitter::scanString(const char *fmt, int field_count, ...) {
- if (eof())
+ if (_currLine == NULL)
error("Expected line of format `%s', got EOF\n", fmt);
std::va_list va;
@@ -104,11 +128,7 @@
if (eof())
return;
- _nextLine = std::strchr(_currLine, '\n');
- if (_nextLine != NULL) {
- *_nextLine = '\0';
- _nextLine++;
- }
+ _currLine = _lines[_lineIndex++].getData();
// Cut off comments
char *comment_start = std::strchr(_currLine, '#');
@@ -130,3 +150,11 @@
for (char *s = _currLine; *s != '\0'; s++)
*s = std::tolower(*s);
}
+
+void TextSplitter::TextLines::setData(char *data, int length) {
+ int _lineLength = length;
+
+ _lineData = new char[_lineLength];
+ std::memcpy(_lineData, data, _lineLength);
+ _lineData[_lineLength-1] = 0;
+}
Index: textsplit.h
===================================================================
RCS file: /cvsroot/scummvm/residual/textsplit.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- textsplit.h 24 Dec 2005 18:19:53 -0000 1.7
+++ textsplit.h 28 Dec 2005 05:22:18 -0000 1.8
@@ -29,14 +29,15 @@
TextSplitter(const char *data, int len);
char *nextLine() {
- _currLine = _nextLine;
processLine();
return _currLine;
}
char *currentLine() { return _currLine; }
const char *currentLine() const { return _currLine; }
- bool eof() const { return _currLine == NULL; }
+ bool eof() const { return _lineIndex == _numLines; }
+ int getLineNumber() { return _lineIndex; }
+ void setLineNumber(int line) { _lineIndex = line-1; processLine(); }
// Check if the current line contains 'needle'
bool checkString(const char *needle);
@@ -53,11 +54,26 @@
__attribute__((format (scanf, 2, 4)))
#endif
;
+ class TextLines {
+ public:
+ TextLines() {};
+ ~TextLines() { delete[] _lineData; }
+ void setData(char *data, int length);
+ char *getData() { return _lineData; }
- ~TextSplitter() { delete[] _data; }
+ protected:
+ char *_lineData;
+ int _lineLength;
+
+ friend class TextSplitter;
+ };
+
+ ~TextSplitter() { delete[] _lines; }
private:
- char *_data, *_currLine, *_nextLine;
+ char *_currLine;
+ int _numLines, _lineIndex;
+ TextLines *_lines;
void processLine();
};
Index: walkplane.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- walkplane.cpp 1 Aug 2005 03:49:02 -0000 1.16
+++ walkplane.cpp 28 Dec 2005 05:22:18 -0000 1.17
@@ -20,8 +20,10 @@
#include "textsplit.h"
void Sector::load(TextSplitter &ts) {
+// float height = 12345.f; // Yaz: this is in the original code...
char buf[256];
- int id = 0;
+ int id = 0, i = 0;
+ Vector3d tempVert;
// Sector NAMES can be null, but ts isn't flexible enough
if (strlen(ts.currentLine()) > strlen(" sector"))
@@ -32,16 +34,8 @@
}
ts.scanString(" id %d", 1, &id);
- load0(ts, buf, id);
-}
-
-void Sector::load0(TextSplitter &ts, char *name, int id) {
- char buf[256];
- int i = 0;
-// float height = 12345.f; // Yaz: this is in the original code...
- Vector3d tempVert;
- _name = name;
+ _name = buf;
_id = id;
ts.scanString(" type %256s", 1, buf);
Index: walkplane.h
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- walkplane.h 28 Mar 2005 01:56:40 -0000 1.13
+++ walkplane.h 28 Dec 2005 05:22:18 -0000 1.14
@@ -31,7 +31,6 @@
class Sector {
public:
void load(TextSplitter &ts);
- void load0(TextSplitter &ts, char *name, int id);
void setVisible(bool visible);
Index: scene.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/scene.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- scene.cpp 27 Aug 2005 16:08:44 -0000 1.46
+++ scene.cpp 28 Dec 2005 05:22:18 -0000 1.47
@@ -84,21 +84,20 @@
if (ts.eof()) // Sectors are optional, but section: doesn't seem to be
return;
- // Sector NAMES can be null, but ts doesn't seem flexible enough to allow this
- if (strlen(ts.currentLine()) > strlen(" sector"))
- ts.scanString(" sector %256s", 1, tempBuf);
- else {
- ts.nextLine();
- strcpy(tempBuf, "");
+ int sectorStart = ts.getLineNumber();
+ _numSectors = 0;
+ // Find the number of sectors (while the sectors usually
+ // count down from the highest number there are a few
+ // cases where they count up, see hh.set for example)
+ while (!ts.eof()) {
+ ts.scanString(" %s", 1, tempBuf);
+ if(!std::strcmp(tempBuf, "sector"))
+ _numSectors++;
}
-
- ts.scanString(" id %d", 1, &_numSectors);
- _numSectors++;
+ // Allocate and fill an array of sector info
_sectors = new Sector[_numSectors];
- // FIXME: This would be nicer if we could rewind the textsplitter
- // stream
- _sectors[0].load0(ts, tempBuf, _numSectors);
- for (int i = 1; i < _numSectors; i++)
+ ts.setLineNumber(sectorStart);
+ for (int i = 0; i < _numSectors; i++)
_sectors[i].load(ts);
}
- Previous message: [Scummvm-cvs-logs] CVS: scummvm NEWS,1.132.2.5,1.132.2.6
- Next message: [Scummvm-cvs-logs] CVS: scummvm/kyra kyra.cpp,1.98,1.99 kyra.h,1.55,1.56 script_v1.cpp,1.50,1.51 staticres.cpp,1.29,1.30
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list