#include "griddleDefs.h" #define CLASS_MAX 256 #define SIZE_OFFSET 12 int classSize[CLASS_MAX]; byte cv[512]; int cvLength; static FILE *cvFyle; static object *inNoid[MAXNOID]; void cvByte(n) byte n; { cv[cvLength++] = n; } byte readByte(fyle) FILE *fyle; { return((byte)getc(fyle)); } word readWord(fyle) FILE *fyle; { byte lo; byte hi; lo = readByte(fyle); hi = readByte(fyle); return((hi << 8) + lo); } void readClassFile() { int i; FILE *classFyle; if ((classFyle = fopen(classFileName, "r")) == NULL) systemError("can't open class file '%s'\n", classFileName); for (i=0; iclass); } } } void cvProperties(class, buf) int class; byte *buf; { int container; int i; if (class == 0) { cvByte(0); /* style */ cvByte(getWord(buf, LIGHTLEVEL_OFFSET_REG)); cvByte(getWord(buf, DEPTH_OFFSET_REG)); cvByte(getWord(buf, CLASSGROUP_OFFSET_REG)); cvByte(0); /* who am I? */ cvByte(0); /* bank balance */ cvByte(0); cvByte(0); cvByte(0); } else if (class == 1) { container = getLong(buf, CONTAINER_OFFSET_AVA); if (container != 0 && (container < -1000-MAXNOID || -1000 <= container)) { error("specified avatar container out of range\n"); return; } cvByte(getByte(buf, STYLE_OFFSET_AVA)); cvByte(getWord(buf, X_OFFSET_AVA)); cvByte(getWord(buf, Y_OFFSET_AVA)); cvByte(getWord(buf, ORIENT_OFFSET_AVA)); cvByte(getWord(buf, GRSTATE_OFFSET_AVA)); if (container == 0) cvByte(0); else cvByte(-container-1001); for (i=0; iclass, noidArray[i]->stateVector); } boolean generateContentsVector() { int i; cvLength = 0; if (noidArray[0] == NULL || noidArray[0]->class != 0) { error("first object is not a region\n"); return(FALSE); } else for (i=1; iclass == 0) { error("more than one region given\n"); return(FALSE); } } /* cvProperties(0, noidArray[0]->stateVector);*/ cvNoidClass(); cvByte(0); cvProps(); cvByte(0); return(TRUE); } void outputContentsVector() { if (generateContentsVector()) fwrite(cv, 1, cvLength, cvFile); } void fillFromCvFile(obj) object *obj; { byte *buf; int class; int container; int i; buf = obj->stateVector; class = obj->class; if (class == 0) { readByte(cvFyle); /* skip style */ fillWord(buf, LIGHTLEVEL_OFFSET_REG, readByte(cvFyle)); fillWord(buf, DEPTH_OFFSET_REG, readByte(cvFyle)); fillWord(buf, CLASSGROUP_OFFSET_REG, readByte(cvFyle)); readByte(cvFyle); /* skip who am i */ for (i=0; i<4; ++i) readByte(cvFyle); /* skip bank balance */ } else if (class == 1) { fillByte(buf, STYLE_OFFSET_AVA, readByte(cvFyle)); fillWord(buf, X_OFFSET_AVA, readByte(cvFyle)); fillWord(buf, Y_OFFSET_AVA, readByte(cvFyle)); fillWord(buf, ORIENT_OFFSET_AVA, readByte(cvFyle)); fillWord(buf, GRSTATE_OFFSET_AVA, readByte(cvFyle)); container = getLong(inNoid[readByte(cvFyle)]->stateVector, 0); fillLong(buf, CONTAINER_OFFSET_AVA, container); for (i=0; istateVector, 0); fillLong(buf, CONTAINER_OFFSET_OBJ, container); for (i=0; iclass) { error("class mismatch: cv says %d, we say %d\n", cv[noidOffset + 1], noidArray[noid]->class); return(0); } stateOffset += deCvProperties(noidArray[noid]->class, noidArray[noid]->stateVector, stateOffset); noidOffset += 2; noidAlive[noid] = TRUE; } if (cv[stateOffset] == 0) return(0); else return(stateOffset + 1); } void degenerateContentsVector() { int offset; int noid; noidAlive[0] = TRUE; for (noid=1; noid