bool BattleMapSectorTiles::saveSector(const UString &path, bool pack, bool pretty)
{
	TRACE_FN_ARGS1("path", path);
	auto archive = SerializationArchive::createArchive();
	if (serialize(*this, archive.get()))
	{
		archive->write(path, pack, pretty);
		return true;
	}
	return false;
}
bool GameState::saveGame(const UString &path, bool pack, bool pretty)
{
	TRACE_FN_ARGS1("path", path);
	auto archive = SerializationArchive::createArchive();
	if (serialize(archive.get()))
	{
		archive->write(path, pack, pretty);
		return true;
	}
	return false;
}
Beispiel #3
0
bool BattleUnitAnimationPack::saveAnimationPack(const UString &path, bool pack, bool pretty)
{
	TRACE_FN_ARGS1("path", path);
	auto archive = SerializationArchive::createArchive();
	if (serialize(*this, archive))
	{
		archive->write(path, pack, pretty);
		return true;
	}
	return false;
}
bool BattleMapSectorTiles::loadSector(GameState &state, const UString &path)
{

	TRACE_FN_ARGS1("path", path);
	auto archive = SerializationArchive::readArchive(path);
	if (!archive)
	{
		LogError("Failed to read \"%s\"", path);
		return false;
	}

	return deserialize(*this, state, archive.get());
}
bool GameState::loadGame(const UString &path)
{

	TRACE_FN_ARGS1("path", path);
	auto archive = SerializationArchive::readArchive(path);
	if (!archive)
	{
		LogError("Failed to read \"%s\"", path);
		return false;
	}

	return deserialize(archive.get());
}
Beispiel #6
0
bool BattleUnitAnimationPack::loadAnimationPack(GameState &state, const UString &path)
{

	TRACE_FN_ARGS1("path", path);
	auto archive = SerializationArchive::readArchive(path);
	if (!archive)
	{
		LogError("Failed to read \"%s\"", path);
		return false;
	}

	return deserialize(*this, state, archive);
}
Beispiel #7
0
	sp<FrameAudio> popAudio() override
	{
		TRACE_FN_ARGS1("Frame", Strings::fromInteger(this->current_frame_audio));
		std::lock_guard<std::recursive_mutex> l(this->frame_queue_lock);
		if (this->audio_queue.empty())
		{
			if (this->readNextFrame() == false)
			{
				return nullptr;
			}
		}
		auto frame = this->audio_queue.front();
		this->audio_queue.pop();
		this->current_frame_audio++;
		return frame;
	}
Beispiel #8
0
IFile FileSystem::open(const UString &path)
{
	TRACE_FN_ARGS1("PATH", path);
	IFile f;

	auto lowerPath = path.toLower();
	if (path != lowerPath)
	{
		LogError("Path \"%s\" contains CAPITAL - cut it out!", path);
	}

	if (!PHYSFS_exists(path.cStr()))
	{
		LogInfo("Failed to find \"%s\"", path);
		LogAssert(!f);
		return f;
	}
	f.f.reset(new PhysfsIFileImpl(path));
	f.rdbuf(dynamic_cast<PhysfsIFileImpl *>(f.f.get()));
	LogInfo("Loading \"%s\" from \"%s\"", path, f.systemPath());
	return f;
}
Beispiel #9
0
void GameCore::ParseXMLDoc(UString XMLFilename)
{
	TRACE_FN_ARGS1("XMLFilename", XMLFilename);
	tinyxml2::XMLDocument doc;
	tinyxml2::XMLElement *node;
	auto file = fw().data->fs.open(XMLFilename);
	if (!file)
	{
		LogError("Failed to open XML file \"%s\"", XMLFilename.c_str());
	}

	LogInfo("Loading XML file \"%s\" - found at \"%s\"", XMLFilename.c_str(),
	        file.systemPath().c_str());

	auto xmlText = file.readAll();
	if (!xmlText)
	{
		LogError("Failed to read in XML file \"%s\"", XMLFilename.c_str());
	}

	auto err = doc.Parse(xmlText.get(), file.size());

	if (err != tinyxml2::XML_SUCCESS)
	{
		LogError("Failed to parse XML file \"%s\" - \"%s\" \"%s\"", XMLFilename.c_str(),
		         doc.GetErrorStr1(), doc.GetErrorStr2());
		return;
	}

	node = doc.RootElement();

	if (!node)
	{
		LogError("Failed to parse XML file \"%s\" - no root element", XMLFilename.c_str());
		return;
	}

	UString nodename = node->Name();

	if (nodename == "openapoc")
	{
		for (node = node->FirstChildElement(); node != nullptr; node = node->NextSiblingElement())
		{
			ApplyAliases(node);
			nodename = node->Name();
			if (nodename == "game")
			{
				ParseGameXML(node);
			}
			else if (nodename == "form")
			{
				ParseFormXML(node);
			}
			else if (nodename == "apocfont")
			{
				UString fontName = node->Attribute("name");
				if (fontName == "")
				{
					LogError("apocfont element with no name");
					continue;
				}
				auto font = ApocalypseFont::loadFont(node);
				if (!font)
				{
					LogError("apocfont element \"%s\" failed to load", fontName.c_str());
					continue;
				}

				if (this->fonts.find(fontName) != this->fonts.end())
				{
					LogError("multiple fonts with name \"%s\"", fontName.c_str());
					continue;
				}
				this->fonts[fontName] = font;
			}
			else if (nodename == "alias")
			{
				aliases[UString(node->Attribute("id"))] = UString(node->GetText());
			}
			else if (nodename == "ufopaedia")
			{
				tinyxml2::XMLElement *nodeufo;
				for (nodeufo = node->FirstChildElement(); nodeufo != nullptr;
				     nodeufo = nodeufo->NextSiblingElement())
				{
					nodename = nodeufo->Name();
					if (nodename == "category")
					{
						Ufopaedia::UfopaediaDB.push_back(mksp<UfopaediaCategory>(nodeufo));
					}
				}
			}
			else
			{
				LogError("Unknown XML element \"%s\"", nodename.c_str());
			}
		}
	}
}