Skip to content

Commit

Permalink
CGE: Remove some more VFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Sep 11, 2011
1 parent 918d79f commit 5c256f9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 90 deletions.
85 changes: 29 additions & 56 deletions engines/cge/cge_main.cpp
Expand Up @@ -477,11 +477,11 @@ void CGEEngine::tooFar() {
void CGEEngine::loadHeroXY() {
debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()");

VFile cf("CGE.HXY");
EncryptedStream cf("CGE.HXY");
uint16 x, y;

memset(_heroXY, 0, sizeof(_heroXY));
if (!cf._error) {
if (!cf.err()) {
for (int i = 0; i < kCaveMax; ++i) {
cf.read((byte *)&x, 2);
cf.read((byte *)&y, 2);
Expand All @@ -496,8 +496,8 @@ void CGEEngine::loadMapping() {
debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()");

if (_now <= kCaveMax) {
VFile cf("CGE.TAB");
if (!cf._error) {
EncryptedStream cf("CGE.TAB");
if (!cf.err()) {
// Move to the data for the given room
cf.seek((_now - 1) * kMapArrSize);

Expand Down Expand Up @@ -1030,23 +1030,24 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int
bool tran = false;
int i, lcnt = 0;

char line[kLineMax];
mergeExt(line, fname, kSprExt);
char tmpStr[kLineMax + 1];
Common::String line;
mergeExt(tmpStr, fname, kSprExt);

if (_cat->exist(line)) { // sprite description file exist
VFile sprf(line);
if (sprf._error)
error("Bad SPR [%s]", line);
if (_cat->exist(tmpStr)) { // sprite description file exist
EncryptedStream sprf(tmpStr);
if (sprf.err())
error("Bad SPR [%s]", tmpStr);

uint16 len;
while ((len = sprf.read((uint8 *)line)) != 0) {
for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) {
len = line.size();
lcnt++;
if (len && line[len - 1] == '\n')
line[--len] = '\0';
if (len == 0 || *line == '.')
strcpy(tmpStr, line.c_str());
if (len == 0 || *tmpStr == '.')
continue;

if ((i = takeEnum(Comd, strtok(line, " =\t"))) < 0)
if ((i = takeEnum(Comd, strtok(tmpStr, " =\t"))) < 0)
error("Bad line %d [%s]", lcnt, fname);


Expand All @@ -1073,7 +1074,8 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int
}
if (! shpcnt)
error("No shapes [%s]", fname);
} else { // no sprite description: mono-shaped sprite with only .BMP file
} else {
// no sprite description: mono-shaped sprite with only .BMP file
++shpcnt;
}

Expand All @@ -1084,7 +1086,6 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int
_sprite = new Sprite(this, NULL);
if (_sprite) {
_sprite->gotoxy(col, row);
//Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$
}
break;
case 2:
Expand All @@ -1099,45 +1100,14 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int
_sprite = w;
break;
}
/*
case 3 : // NEWTON
NEWTON * n = new NEWTON(NULL);
if (n)
{
n->Ay = (bottom-n->H);
n->By = 90;
n->Cy = 3;
n->Bx = 99;
n->Cx = 3;
n->Goto(col, row);
}
_sprite = n;
break;
*/
case 4:
// LISSAJOUS
case 3: // NEWTON
case 4: // LISSAJOUS
error("Bad type [%s]", fname);
/*
LISSAJOUS * l = new LISSAJOUS(NULL);
if (l)
{
l->Ax = SCR_WID/2;
l->Ay = SCR_HIG/2;
l->Bx = 7;
l->By = 13;
l->Cx = 300;
l->Cy = 500;
*(long *) &l->Dx = 0; // movex * cnt
l->Goto(col, row);
}
_sprite = l;
*/
break;
case 5:
{ // FLY
Fly *f = new Fly(this, NULL);
_sprite = f;
//////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$
break;
}
default:
Expand Down Expand Up @@ -1170,26 +1140,29 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int
}

void CGEEngine::loadScript(const char *fname) {
VFile scrf(fname);
EncryptedStream scrf(fname);

if (scrf._error)
if (scrf.err())
return;

bool ok = true;
int lcnt = 0;

char line[kLineMax];
while (scrf.read((uint8 *)line) != 0) {
char tmpStr[kLineMax+1];
Common::String line;

for (line = scrf.readLine(); !scrf.eos(); line = scrf.readLine()) {
char *p;

lcnt++;
if (*line == 0 || *line == '\n' || *line == '.')
strcpy(tmpStr, line.c_str());
if ((line.size() == 0) || (*tmpStr == '.'))
continue;

ok = false; // not OK if break

// sprite ident number
if ((p = strtok(line, " \t\n")) == NULL)
if ((p = strtok(tmpStr, " \t\n")) == NULL)
break;
int SpI = atoi(p);

Expand Down
71 changes: 37 additions & 34 deletions engines/cge/vga13h.cpp
Expand Up @@ -209,66 +209,69 @@ Sprite *Sprite::expand() {
return this;

static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL };
char line[kLineMax], fname[kPathMax];
char fname[kPathMax];

Common::Array<BitmapPtr> shplist;
for (int i = 0; i < _shpCnt + 1; ++i)
shplist.push_back(NULL);

Seq *seq = NULL;
int shpcnt = 0,
seqcnt = 0,
neacnt = 0,
takcnt = 0,
int shapeCount = 0,
seqCount = 0,
nearCount = 0,
takeCount = 0,
maxnow = 0,
maxnxt = 0;

Snail::Com *nea = NULL;
Snail::Com *tak = NULL;
Snail::Com *near = NULL;
Snail::Com *take = NULL;
mergeExt(fname, _file, kSprExt);
if (_cat->exist(fname)) { // sprite description file exist
VFile sprf(fname);
if (!(sprf._error==0))
EncryptedStream sprf(fname);
if (sprf.err())
error("Bad SPR [%s]", fname);
Common::String line;
char tmpStr[kLineMax + 1];
int len = 0, lcnt = 0;
while ((len = sprf.read((uint8 *)line)) != 0) {

for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) {
len = line.size();
strcpy(tmpStr, line.c_str());
lcnt++;
if (len && line[len - 1] == '\n')
line[--len] = '\0';
if (len == 0 || *line == '.')
if (len == 0 || *tmpStr == '.')
continue;

Snail::Com *c;
switch (takeEnum(Comd, strtok(line, " =\t"))) {
switch (takeEnum(Comd, strtok(tmpStr, " =\t"))) {
case 0:
// Name
setName(strtok(NULL, ""));
break;
case 1:
// Phase
// In case the shape index gets too high, increase the array size
while ((shpcnt + 1) >= (int)shplist.size()) {
while ((shapeCount + 1) >= (int)shplist.size()) {
shplist.push_back(NULL);
++_shpCnt;
}
shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/"));
shplist[shapeCount++] = new Bitmap(strtok(NULL, " \t,;/"));
break;
case 2:
// Seq
seq = (Seq *) realloc(seq, (seqcnt + 1) * sizeof(*seq));
seq = (Seq *)realloc(seq, (seqCount + 1) * sizeof(*seq));
assert(seq != NULL);
Seq *s;
s = &seq[seqcnt++];
s = &seq[seqCount++];
s->_now = atoi(strtok(NULL, " \t,;/"));
if (s->_now > maxnow)
maxnow = s->_now;
s->_next = atoi(strtok(NULL, " \t,;/"));
switch (s->_next) {
case 0xFF:
s->_next = seqcnt;
s->_next = seqCount;
break;
case 0xFE:
s->_next = seqcnt - 1;
s->_next = seqCount - 1;
break;
}
if (s->_next > maxnxt)
Expand All @@ -281,9 +284,9 @@ Sprite *Sprite::expand() {
// Near
if (_nearPtr == kNoPtr)
break;
nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea));
assert(nea != NULL);
c = &nea[neacnt++];
near = (Snail::Com *)realloc(near, (nearCount + 1) * sizeof(*near));
assert(near != NULL);
c = &near[nearCount++];
if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0)
error("Bad NEAR in %d [%s]", lcnt, fname);
c->_ref = atoi(strtok(NULL, " \t,;/"));
Expand All @@ -294,9 +297,9 @@ Sprite *Sprite::expand() {
// Take
if (_takePtr == kNoPtr)
break;
tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak));
assert(tak != NULL);
c = &tak[takcnt++];
take = (Snail::Com *)realloc(take, (takeCount + 1) * sizeof(*take));
assert(take != NULL);
c = &take[takeCount++];
if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0)
error("Bad NEAR in %d [%s]", lcnt, fname);
c->_ref = atoi(strtok(NULL, " \t,;/"));
Expand All @@ -307,14 +310,14 @@ Sprite *Sprite::expand() {
}
} else {
// no sprite description: try to read immediately from .BMP
shplist[shpcnt++] = new Bitmap(_file);
shplist[shapeCount++] = new Bitmap(_file);
}

shplist[shpcnt] = NULL;
shplist[shapeCount] = NULL;
if (seq) {
if (maxnow >= shpcnt)
if (maxnow >= shapeCount)
error("Bad PHASE in SEQ [%s]", fname);
if (maxnxt >= seqcnt)
if (maxnxt >= seqCount)
error("Bad JUMP in SEQ [%s]", fname);
setSeq(seq);
} else
Expand All @@ -327,12 +330,12 @@ Sprite *Sprite::expand() {

setShapeList(shapeList);

if (nea)
nea[neacnt - 1]._ptr = _ext->_near = nea;
if (near)
near[nearCount - 1]._ptr = _ext->_near = near;
else
_nearPtr = kNoPtr;
if (tak)
tak[takcnt - 1]._ptr = _ext->_take = tak;
if (take)
take[takeCount - 1]._ptr = _ext->_take = take;
else
_takePtr = kNoPtr;

Expand Down

0 comments on commit 5c256f9

Please sign in to comment.