Exemple #1
0
bool AnimationTemplateRegistry::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	// Das nächste zu vergebene Handle wieder herstellen.
	reader.read(_nextHandle);

	// Alle vorhandenen BS_AnimationTemplates zerstören.
	while (!_handle2PtrMap.empty())
		delete _handle2PtrMap.begin()->_value;

	// Anzahl an BS_AnimationTemplates einlesen.
	uint animationTemplateCount;
	reader.read(animationTemplateCount);

	// Alle gespeicherten BS_AnimationTemplates wieder herstellen.
	for (uint i = 0; i < animationTemplateCount; ++i) {
		// Handle lesen.
		uint handle;
		reader.read(handle);

		// BS_AnimationTemplate wieder herstellen.
		result &= (AnimationTemplate::create(reader, handle) != 0);
	}

	return reader.isGood() && result;
}
Exemple #2
0
bool InputEngine::unpersist(InputPersistenceBlock &reader) {
	Common::String callbackFunctionName;

	// Read number of command callbacks and their names.
	// Note: We do this only for compatibility with older engines resp.
	// the original engine.
	uint32 commandCallbackCount;
	reader.read(commandCallbackCount);
	assert(commandCallbackCount == 1);

	reader.readString(callbackFunctionName);
	assert(callbackFunctionName == "LuaCommandCB");

	// Read number of character callbacks and their names.
	// Note: We do this only for compatibility with older engines resp.
	// the original engine.
	uint32 characterCallbackCount;
	reader.read(characterCallbackCount);
	assert(characterCallbackCount == 1);

	reader.readString(callbackFunctionName);
	assert(callbackFunctionName == "LuaCharacterCB");

	return reader.isGood();
}
bool RenderObjectManager::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	// Alle Kinder des Wurzelknotens löschen. Damit werden alle BS_RenderObjects gelöscht.
	_rootPtr->deleteAllChildren();

	// Alle BS_RenderObjects wieder hestellen.
	if (!_rootPtr->unpersistChildren(reader))
		return false;

	reader.read(_frameStarted);

	// Momentan gespeicherte Referenzen auf TimedRenderObjects löschen.
	_timedRenderObjects.resize(0);

	// Referenzen auf die TimedRenderObjects wieder herstellen.
	uint32 timedObjectCount;
	reader.read(timedObjectCount);
	for (uint32 i = 0; i < timedObjectCount; ++i) {
		uint32 handle;
		reader.read(handle);
		_timedRenderObjects.push_back(handle);
	}

	// Alle BS_AnimationTemplates wieder herstellen.
	result &= AnimationTemplateRegistry::instance().unpersist(reader);

	return result;
}
bool AnimationTemplate::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	// Parent wieder herstellen.
	result &= AnimationDescription::unpersist(reader);

	// Frameanzahl lesen.
	uint frameCount;
	reader.read(frameCount);

	// Frames einzeln wieder herstellen.
	for (uint i = 0; i < frameCount; ++i) {
		Frame frame;
		reader.read(frame.hotspotX);
		reader.read(frame.hotspotY);
		reader.read(frame.flipV);
		reader.read(frame.flipH);
		reader.readString(frame.fileName);
		reader.readString(frame.action);

		_frames.push_back(frame);
	}

	// Die Animations-Resource wird für die gesamte Lebensdauer des Objektes gelockt
	Common::String sourceAnimation;
	reader.readString(sourceAnimation);
	_sourceAnimationPtr = requestSourceAnimation(sourceAnimation);

	reader.read(_valid);

	return _sourceAnimationPtr && reader.isGood() && result;
}
Exemple #5
0
bool StaticBitmap::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	result &= Bitmap::unpersist(reader);
	Common::String resourceFilename;
	reader.readString(resourceFilename);
	// We may not have saves, and we actually do not need to
	// restore them. So do not even try to load them.
	if (!resourceFilename.hasPrefix("/saves"))
		result &= initBitmapResource(resourceFilename);

	result &= RenderObject::unpersistChildren(reader);

	return reader.isGood() && result;
}
Exemple #6
0
bool Polygon::unpersist(InputPersistenceBlock &reader) {
	int storedvertexCount;
	reader.read(storedvertexCount);

	Common::Array<Vertex> storedvertices;
	for (int i = 0; i < storedvertexCount; ++i) {
		int x, y;
		reader.read(x);
		reader.read(y);
		storedvertices.push_back(Vertex(x, y));
	}

	init(storedvertexCount, &storedvertices[0]);

	return reader.isGood();
}
Exemple #7
0
bool RenderObject::unpersistChildren(InputPersistenceBlock &reader) {
	bool result = true;

	// Kinderanzahl einlesen.
	uint childrenCount;
	reader.read(childrenCount);
	if (!reader.isGood())
		return false;

	// Alle Kinder rekursiv wieder herstellen.
	for (uint i = 0; i < childrenCount; ++i) {
		if (!recreatePersistedRenderObject(reader).isValid())
			return false;
	}

	return result && reader.isGood();
}
Exemple #8
0
bool Text::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	result &= RenderObject::unpersist(reader);

	// Read color and alpha
	reader.read(_modulationColor);

	// Run all methods on loading relevant members.
	// So, the layout is automatically updated and all necessary logic is executed.

	Common::String font;
	reader.readString(font);
	setFont(font);

	Common::String text;
	reader.readString(text);
	setText(text);

	bool autoWrap;
	reader.read(autoWrap);
	setAutoWrap(autoWrap);

	uint32 autoWrapThreshold;
	reader.read(autoWrapThreshold);
	setAutoWrapThreshold(autoWrapThreshold);

	result &= RenderObject::unpersistChildren(reader);

	return reader.isGood() && result;
}
Exemple #9
0
bool Text::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	result &= RenderObject::unpersist(reader);

	// Farbe und Alpha einlesen.
	reader.read(_modulationColor);

	// Beim Laden der anderen Member werden die Set-Methoden benutzt statt der tatsächlichen Member.
	// So wird das Layout automatisch aktualisiert und auch alle anderen notwendigen Methoden ausgeführt.

	Common::String font;
	reader.readString(font);
	setFont(font);

	Common::String text;
	reader.readString(text);
	setText(text);

	bool autoWrap;
	reader.read(autoWrap);
	setAutoWrap(autoWrap);

	uint autoWrapThreshold;
	reader.read(autoWrapThreshold);
	setAutoWrapThreshold(autoWrapThreshold);

	result &= RenderObject::unpersistChildren(reader);

	return reader.isGood() && result;
}
Exemple #10
0
RenderObjectPtr<RenderObject> RenderObject::recreatePersistedRenderObject(InputPersistenceBlock &reader) {
	RenderObjectPtr<RenderObject> result;

	// Typ und Handle auslesen.
	uint type;
	uint handle;
	reader.read(type);
	reader.read(handle);
	if (!reader.isGood())
		return result;

	switch (type) {
	case TYPE_PANEL:
		result = (new Panel(reader, this->getHandle(), handle))->getHandle();
		break;

	case TYPE_STATICBITMAP:
		result = (new StaticBitmap(reader, this->getHandle(), handle))->getHandle();
		break;

	case TYPE_DYNAMICBITMAP:
		// Videos are not normally saved: this probably indicates a bug, thus die here.
		//result = (new DynamicBitmap(reader, this->getHandle(), handle))->getHandle();
		error("Request to recreate a video. This is either a corrupted saved game, or a bug");
		break;

	case TYPE_TEXT:
		result = (new Text(reader, this->getHandle(), handle))->getHandle();
		break;

	case TYPE_ANIMATION:
		result = (new Animation(reader, this->getHandle(), handle))->getHandle();
		break;

	default:
		error("Cannot recreate render object of unknown type %d.", type);
	}

	return result;
}
Exemple #11
0
RenderObjectPtr<RenderObject> RenderObject::recreatePersistedRenderObject(InputPersistenceBlock &reader) {
	RenderObjectPtr<RenderObject> result;

	// Typ und Handle auslesen.
	uint type;
	uint handle;
	reader.read(type);
	reader.read(handle);
	if (!reader.isGood())
		return result;

	switch (type) {
	case TYPE_PANEL:
		result = (new Panel(reader, this->getHandle(), handle))->getHandle();
		break;

	case TYPE_STATICBITMAP:
		result = (new StaticBitmap(reader, this->getHandle(), handle))->getHandle();
		break;

	case TYPE_DYNAMICBITMAP:
		result = (new DynamicBitmap(reader, this->getHandle(), handle))->getHandle();
		break;

	case TYPE_TEXT:
		result = (new Text(reader, this->getHandle(), handle))->getHandle();
		break;

	case TYPE_ANIMATION:
		result = (new Animation(reader, this->getHandle(), handle))->getHandle();
		break;

	default:
		BS_LOG_ERRORLN("Cannot recreate render object of unknown type %d.", type);
	}

	return result;
}
Exemple #12
0
uint Region::create(InputPersistenceBlock &reader, uint handle) {
	// Read type
	uint32 type;
	reader.read(type);

	// Depending on the type, create a new BS_Region or BS_WalkRegion object
	Region *regionPtr = NULL;
	if (type == RT_REGION) {
		regionPtr = new Region(reader, handle);
	} else if (type == RT_WALKREGION) {
		regionPtr = new WalkRegion(reader, handle);
	} else {
		assert(false);
	}

	return RegionRegistry::instance().resolvePtr(regionPtr);
}
Exemple #13
0
bool Region::unpersist(InputPersistenceBlock &reader) {
	reader.read(_valid);
	reader.read(_position.x);
	reader.read(_position.y);

	_polygons.clear();
	uint32 PolygonCount;
	reader.read(PolygonCount);
	for (uint i = 0; i < PolygonCount; ++i) {
		_polygons.push_back(Polygon(reader));
	}

	reader.read(_boundingBox.left);
	reader.read(_boundingBox.top);
	reader.read(_boundingBox.right);
	reader.read(_boundingBox.bottom);

	return reader.isGood();
}
Exemple #14
0
bool DynamicBitmap::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	result &= Bitmap::unpersist(reader);

	// Ein RenderedImage mit den gespeicherten Maßen erstellen.
	result &= createRenderedImage(_width, _height);

	// Bilddaten werden nicht gespeichert (s.o.).
	BS_LOG_WARNINGLN("Unpersisting a BS_DynamicBitmap. Bitmap contents are missing.");

	// Bild mit durchsichtigen Bilddaten initialisieren.
	byte *transparentImageData = (byte *)calloc(_width * _height * 4, 1);
	_image->setContent(transparentImageData, _width * _height);
	free(transparentImageData);

	result &= RenderObject::unpersistChildren(reader);

	return reader.isGood() && result;
}
Exemple #15
0
bool DynamicBitmap::unpersist(InputPersistenceBlock &reader) {
#if 0
	bool result = true;

	result &= Bitmap::unpersist(reader);
	result &= createRenderedImage(_width, _height);

	warning("Unpersisting a BS_DynamicBitmap. Bitmap contents are missing.");

	// Initialize a transparent image.
	byte *transparentImageData = (byte *)calloc(_width * _height * 4, 1);
	_image->setContent(transparentImageData, _width * _height);
	free(transparentImageData);

	result &= RenderObject::unpersistChildren(reader);

	return reader.isGood() && result;
#endif

	error("Request to unpersist a dynamic bitmap (video) - probably a corrupted saved game or a bug");
}
Exemple #16
0
bool Bitmap::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	result &= RenderObject::unpersist(reader);
	reader.read(_flipH);
	reader.read(_flipV);
	reader.read(_scaleFactorX);
	reader.read(_scaleFactorY);
	reader.read(_modulationColor);
	reader.read(_originalWidth);
	reader.read(_originalHeight);

	forceRefresh();

	return reader.isGood() && result;
}
Exemple #17
0
bool WalkRegion::unpersist(InputPersistenceBlock &reader) {
	bool result = true;

	// The parent object was already loaded in the constructor of BS_Region, so at
	// this point only the additional data from BS_WalkRegion needs to be loaded

	// Node load
	uint32 nodeCount;
	reader.read(nodeCount);
	_nodes.clear();
	_nodes.resize(nodeCount);
	Common::Array<Vertex>::iterator it = _nodes.begin();
	while (it != _nodes.end()) {
		reader.read(it->x);
		reader.read(it->y);
		++it;
	}

	// Visibility matrix load
	uint32 rowCount;
	reader.read(rowCount);
	_visibilityMatrix.clear();
	_visibilityMatrix.resize(rowCount);
	Common::Array< Common::Array<int> >::iterator rowIter = _visibilityMatrix.begin();
	while (rowIter != _visibilityMatrix.end()) {
		uint32 colCount;
		reader.read(colCount);
		rowIter->resize(colCount);
		Common::Array<int>::iterator colIter = rowIter->begin();
		while (colIter != rowIter->end()) {
			int32 t;
			reader.read(t);
			*colIter = t;
			++colIter;
		}

		++rowIter;
	}

	return result && reader.isGood();
}
Exemple #18
0
bool RenderObject::unpersist(InputPersistenceBlock &reader) {
	// Typ und Handle wurden schon von RecreatePersistedRenderObject() ausgelesen. Jetzt werden die restlichen Objekteigenschaften ausgelesen.
	reader.read(_x);
	reader.read(_y);
	reader.read(_absoluteX);
	reader.read(_absoluteY);
	reader.read(_z);
	reader.read(_width);
	reader.read(_height);
	reader.read(_visible);
	reader.read(_childChanged);
	reader.read(_initSuccess);
	reader.read(_bbox.left);
	reader.read(_bbox.top);
	reader.read(_bbox.right);
	reader.read(_bbox.bottom);
	reader.read(_oldBbox.left);
	reader.read(_oldBbox.top);
	reader.read(_oldBbox.right);
	reader.read(_oldBbox.bottom);
	reader.read(_oldX);
	reader.read(_oldY);
	reader.read(_oldZ);
	reader.read(_oldVisible);
	uint parentHandle;
	reader.read(parentHandle);
	_parentPtr = RenderObjectPtr<RenderObject>(parentHandle);
	reader.read(_refreshForced);

	updateAbsolutePos();
	updateObjectState();

	return reader.isGood();
}
Exemple #19
0
bool LuaScriptEngine::unpersist(InputPersistenceBlock &reader) {
	// Empty the Lua stack. pluto_persist() xepects that the stack is empty except for its parameters
	lua_settop(_state, 0);

	// Permanents table is placed on the stack. This has already happened at this point, because
	// to create the table all permanents must be accessible. This is the case only for the
	// beginning of the function, because the global table is emptied below
	pushPermanentsTable(_state, PTT_UNPERSIST);

	// All items from global table of _G and __METATABLES are removed.
	// After a garbage collection is performed, and thus all managed objects deleted

	// __METATABLES is not immediately removed becausen the Metatables are needed
	// for the finalisers of objects.
	static const char *clearExceptionsFirstPass[] = {
		"_G",
		"__METATABLES",
		0
	};
	clearGlobalTable(_state, clearExceptionsFirstPass);

	// In the second pass, the Metatables are removed
	static const char *clearExceptionsSecondPass[] = {
		"_G",
		0
	};
	clearGlobalTable(_state, clearExceptionsSecondPass);

	// Persisted Lua data
	Common::Array<byte> chunkData;
	reader.readByteArray(chunkData);

	// Chunk-Reader initialisation. It is used with pluto_unpersist to restore read data
	ChunkreaderData cd;
	cd.BufferPtr = &chunkData[0];
	cd.Size = chunkData.size();
	cd.BufferReturned = false;

	pluto_unpersist(_state, chunkreader, &cd);

	// Permanents-Table is removed from stack
	lua_remove(_state, -2);

	// The read elements in the global table about
	lua_pushnil(_state);
	while (lua_next(_state, -2) != 0) {
		// The referenec to the global table (_G) must not be overwritten, or ticks from Lua total
		bool isGlobalReference = lua_isstring(_state, -2) && strcmp(lua_tostring(_state, -2), "_G") == 0;
		if (!isGlobalReference) {
			lua_pushvalue(_state, -2);
			lua_pushvalue(_state, -2);

			lua_settable(_state, LUA_GLOBALSINDEX);
		}

		// Pop value from the stack. The index is then ready for the next call to lua_next()
		lua_pop(_state, 1);
	}

	// The table with the loaded data is popped from the stack
	lua_pop(_state, 1);

	// Force garbage collection
	lua_gc(_state, LUA_GCCOLLECT, 0);

	return true;
}
Exemple #20
0
bool SoundEngine::unpersist(InputPersistenceBlock &reader) {
	_mixer->stopAll();

	if (reader.getVersion() < 2)
		return true;

	reader.read(_maxHandleId);

	for (uint i = 0; i < SOUND_HANDLES; i++) {
		reader.read(_handles[i].id);

		Common::String fileName;
		int32 sndType;
		float volume;
		float pan;
		bool loop;
		int32 loopStart;
		int32 loopEnd;
		uint32 layer;

		reader.readString(fileName);
		reader.read(sndType);
		reader.read(volume);
		reader.read(pan);
		reader.read(loop);
		reader.read(loopStart);
		reader.read(loopEnd);
		reader.read(layer);

		if (reader.isGood()) {
			if (sndType != -1)
				playSoundEx(fileName, (SOUND_TYPES)sndType, volume, pan, loop, loopStart, loopEnd, layer, i);
		} else
			return false;
	}

	return reader.isGood();
}