예제 #1
0
void KeyframeAnim::loadText(TextSplitter &ts) {
	ts.expectString("section: header");
	ts.scanString("flags %x", 1, &_flags);
	ts.scanString("type %x", 1, &_type);
	ts.scanString("frames %d", 1, &_numFrames);
	ts.scanString("fps %f", 1, &_fps);
	ts.scanString("joints %d", 1, &_numJoints);

	if (strcasecmp(ts.currentLine(), "section: markers") == 0) {
		ts.nextLine();
		ts.scanString("markers %d", 1, &_numMarkers);
		_markers = new Marker[_numMarkers];
		for (int i = 0; i < _numMarkers; i++)
			ts.scanString("%f %d", 2, &_markers[i].frame, &_markers[i].val);
	} else {
		_numMarkers = 0;
		_markers = NULL;
	}

	ts.expectString("section: keyframe nodes");
	int numNodes;
	ts.scanString("nodes %d", 1, &numNodes);
	_nodes = new KeyframeNode *[_numJoints];
	for (int i = 0; i < _numJoints; i++)
		_nodes[i] = NULL;
	for (int i = 0; i < numNodes; i++) {
		int which;
		ts.scanString("node %d", 1, &which);
		_nodes[which] = new KeyframeNode;
		_nodes[which]->loadText(ts);
	}
}
예제 #2
0
void MaterialData::initEMI(Common::SeekableReadStream *data) {
    Common::Array<Common::String> texFileNames;
    char readFileName[64];

    if (_fname.hasSuffix(".sur")) {  // This expects that we want all the materials in the sur-file
        TextSplitter *ts = new TextSplitter(data);
        ts->setLineNumber(2); // Skip copyright-line
        ts->expectString("version\t1.0");
        if (ts->checkString("name:"))
            ts->scanString("name:%s", 1, readFileName);

        while(!ts->checkString("END_OF_SECTION")) {
            ts->scanString("tex:%s", 1, readFileName);
            Common::String mFileName(readFileName);
            texFileNames.push_back(mFileName);
        }
        Common::SeekableReadStream *texData;
        _textures = new Texture[texFileNames.size()];
        for (uint i = 0; i < texFileNames.size(); i++) {
            warning("SUR-file texture: %s", texFileNames[i].c_str());
            texData = g_resourceloader->openNewStreamFile(texFileNames[i].c_str(), true);
            if (!texData) {
                warning("Couldn't find tex-file: %s", texFileNames[i].c_str());
                _textures[i]._width = 0;
                _textures[i]._height = 0;
                _textures[i]._texture = new int(1); // HACK to avoid initializing.
                continue;
            }
            loadTGA(texData, _textures + i);
            delete texData;
        }
        _numImages = texFileNames.size();
        delete ts;
        return;
    } else if(_fname.hasSuffix(".tga")) {
        _numImages = 1;
        _textures = new Texture();
        loadTGA(data, _textures);
        //	texFileNames.push_back(filename);
        return;

    } else {
        warning("Unknown material-format: %s", _fname.c_str());
    }
}
예제 #3
0
void Costume::loadGRIM(TextSplitter &ts, Costume *prevCost) {
    ts.expectString("costume v0.1");
    ts.expectString("section tags");
    int numTags;
    ts.scanString(" numtags %d", 1, &numTags);
    tag32 *tags = new tag32[numTags];
    for (int i = 0; i < numTags; i++) {
        unsigned char t[4];
        int which;

        // Obtain a tag ID from the file
        ts.scanString(" %d '%c%c%c%c'", 5, &which, &t[0], &t[1], &t[2], &t[3]);
        // Force characters to upper case
        for (int j = 0; j < 4; j++)
            t[j] = toupper(t[j]);
        memcpy(&tags[which], t, sizeof(tag32));
    }

    ts.expectString("section components");
    ts.scanString(" numcomponents %d", 1, &_numComponents);
    _components = new Component *[_numComponents];
    for (int i = 0; i < _numComponents; i++) {
        int id, tagID, hash, parentID, namePos;
        const char *line = ts.getCurrentLine();
        Component *prevComponent = NULL;

        if (sscanf(line, " %d %d %d %d %n", &id, &tagID, &hash, &parentID, &namePos) < 4)
            error("Bad component specification line: `%s'", line);
        ts.nextLine();

        // A Parent ID of "-1" indicates that the component should
        // use the properties of the previous costume as a base
        if (parentID == -1) {
            if (prevCost) {
                MainModelComponent *mmc;

                // However, only the first item can actually share the
                // node hierarchy with the previous costume, so flag
                // that component so it knows what to do
                if (i == 0)
                    parentID = -2;
                prevComponent = prevCost->_components[0];
                mmc = dynamic_cast<MainModelComponent *>(prevComponent);
                // Make sure that the component is valid
                if (!mmc)
                    prevComponent = NULL;
            } else if (id > 0) {
                // Use the MainModelComponent of this costume as prevComponent,
                // so that the component can use its colormap.
                prevComponent = _components[0];
            }
        }
        // Actually load the appropriate component
        _components[id] = loadComponent(tags[tagID], parentID < 0 ? NULL : _components[parentID], parentID, line + namePos, prevComponent);
        _components[id]->setCostume(this);
    }

    delete[] tags;

    for (int i = 0; i < _numComponents; i++)
        if (_components[i]) {
            _components[i]->init();
        }

    ts.expectString("section chores");
    ts.scanString(" numchores %d", 1, &_numChores);
    _chores = new Chore[_numChores];
    for (int i = 0; i < _numChores; i++) {
        int id, length, tracks;
        char name[32];
        ts.scanString(" %d %d %d %32s", 4, &id, &length, &tracks, name);
        _chores[id]._length = length;
        _chores[id]._numTracks = tracks;
        memcpy(_chores[id]._name, name, 32);
        Debug::debug(Debug::Chores, "Loaded chore: %s\n", name);
    }

    ts.expectString("section keys");
    for (int i = 0; i < _numChores; i++) {
        int which;
        ts.scanString("chore %d", 1, &which);
        _chores[which].load(i, this, ts);
    }
}
예제 #4
0
void Set::loadText(TextSplitter &ts){
	char tempBuf[256];

	ts.expectString("section: colormaps");
	ts.scanString(" numcolormaps %d", 1, &_numCmaps);
	_cmaps = new ObjectPtr<CMap>[_numCmaps];
	char cmap_name[256];
	for (int i = 0; i < _numCmaps; i++) {
		ts.scanString(" colormap %256s", 1, cmap_name);
		_cmaps[i] = g_resourceloader->getColormap(cmap_name);
	}

	if (ts.checkString("section: objectstates") || ts.checkString("sections: object_states")) {
		ts.nextLine();
		ts.scanString(" tot_objects %d", 1, &_numObjectStates);
		char object_name[256];
		for (int l = 0; l < _numObjectStates; l++) {
			ts.scanString(" object %256s", 1, object_name);
		}
	} else {
		_numObjectStates = 0;
	}

	ts.expectString("section: setups");
	ts.scanString(" numsetups %d", 1, &_numSetups);
	_setups = new Setup[_numSetups];
	for (int i = 0; i < _numSetups; i++)
		_setups[i].load(ts);
	_currSetup = _setups;

	_lightsConfigured = false;
	_numSectors = -1;
	_numLights = -1;
	_lights = NULL;
	_sectors = NULL;

	_minVolume = 0;
	_maxVolume = 0;

	// Lights are optional
	if (ts.isEof())
		return;

	ts.expectString("section: lights");
	ts.scanString(" numlights %d", 1, &_numLights);
	_lights = new Light[_numLights];
	for (int i = 0; i < _numLights; i++)
		_lights[i].load(ts);

	// Calculate the number of sectors
	ts.expectString("section: sectors");
	if (ts.isEof())	// Sectors are optional, but section: doesn't seem to be
		return;

	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.isEof()) {
		ts.scanString(" %s", 1, tempBuf);
		if (!scumm_stricmp(tempBuf, "sector"))
			_numSectors++;
	}
	// Allocate and fill an array of sector info
	_sectors = new Sector*[_numSectors];
	ts.setLineNumber(sectorStart);
	for (int i = 0; i < _numSectors; i++) {
		// Use the ids as index for the sector in the array.
		// This way when looping they are checked from the id 0 sto the last,
		// which seems important for sets with overlapping camera sectors, like ga.set.
		Sector *s = new Sector();
		s->load(ts);
		_sectors[s->getSectorId()] = s;
	}
}