Exemplo n.º 1
0
void ModelSkin::Save(Serializer::Writer &wr) const
{
    for (unsigned int i = 0; i < 3; i++) {
        wr.Byte(m_colors[i].r);
        wr.Byte(m_colors[i].g);
        wr.Byte(m_colors[i].b);
    }
    for (unsigned int i = 0; i < MAX_DECAL_MATERIALS; i++)
        wr.String(m_decals[i]);
    wr.String(m_label);
}
Exemplo n.º 2
0
void Shields::Save(Serializer::Writer &wr)
{
	wr.Bool(m_enabled);

	wr.Int32(m_shields.size());
	for (ShieldIterator it = m_shields.begin(); it != m_shields.end(); ++it) {
		wr.Byte(it->m_colour.r);
		wr.Byte(it->m_colour.g);
		wr.Byte(it->m_colour.b);
		wr.String(it->m_mesh->GetName());
	}
}
Exemplo n.º 3
0
void NavLights::Save(Serializer::Writer &wr)
{
	wr.Float(m_time);
	wr.Bool(m_enabled);

	for (LightIterator it = m_lights.begin(); it != m_lights.end(); ++it)
		wr.Byte(it->color);
}
Exemplo n.º 4
0
void SectorView::Save(Serializer::Writer &wr)
{
    wr.Float(m_pos.x);
    wr.Float(m_pos.y);
    wr.Float(m_pos.z);
    wr.Float(m_rotX);
    wr.Float(m_rotZ);
    wr.Float(m_zoom);
    wr.Bool(m_inSystem);
    m_current.Serialize(wr);
    m_selected.Serialize(wr);
    m_hyperspaceTarget.Serialize(wr);
    wr.Bool(m_matchTargetToSelection);
    wr.Bool(m_selectionFollowsMovement);
    wr.Byte(m_detailBoxVisible);
}
Exemplo n.º 5
0
void Game::Serialize(Serializer::Writer &wr)
{
	// leading signature
	for (Uint32 i = 0; i < strlen(s_saveStart)+1; i++)
		wr.Byte(s_saveStart[i]);

	// version
	wr.Int32(s_saveVersion);

	Serializer::Writer section;

	// game state
	section.Double(m_time);
	section.Int32(Uint32(m_state));

	section.Bool(m_wantHyperspace);
	section.Double(m_hyperspaceProgress);
	section.Double(m_hyperspaceDuration);
	section.Double(m_hyperspaceEndTime);

	wr.WrSection("Game", section.GetData());


	// space, all the bodies and things
	section = Serializer::Writer();
	m_space->Serialize(section);
	section.Int32(m_space->GetIndexForBody(m_player.get()));
	wr.WrSection("Space", section.GetData());


	// space transition state
	section = Serializer::Writer();

	// hyperspace clouds being brought over from the previous system
	section.Int32(m_hyperspaceClouds.size());
	for (std::list<HyperspaceCloud*>::const_iterator i = m_hyperspaceClouds.begin(); i != m_hyperspaceClouds.end(); ++i)
		(*i)->Serialize(section, m_space.get());

	wr.WrSection("HyperspaceClouds", section.GetData());


	// system political data (crime etc)
	section = Serializer::Writer();
	Polit::Serialize(section);
	wr.WrSection("Polit", section.GetData());


	// views. must be saved in init order
	section = Serializer::Writer();
	Pi::cpan->Save(section);
	wr.WrSection("ShipCpanel", section.GetData());

	section = Serializer::Writer();
	Pi::sectorView->Save(section);
	wr.WrSection("SectorView", section.GetData());

	section = Serializer::Writer();
	Pi::worldView->Save(section);
	wr.WrSection("WorldView", section.GetData());


	// lua
	section = Serializer::Writer();
	Pi::luaSerializer->Serialize(section);
	wr.WrSection("LuaModules", section.GetData());


	// trailing signature
	for (Uint32 i = 0; i < strlen(s_saveEnd)+1; i++)
		wr.Byte(s_saveEnd[i]);
}
Exemplo n.º 6
0
void BinaryConverter::Save(const std::string& filename, const std::string& savepath, Model* m, const bool bInPlace)
{
	printf("Saving file (%s)\n", filename.c_str());
	FILE *f = nullptr;
	FileSystem::FileSourceFS newFS(FileSystem::GetDataDir());
	if (!bInPlace) {
		if (!FileSystem::userFiles.MakeDirectory(SAVE_TARGET_DIR))
			throw CouldNotOpenFileException();

		std::string newpath = savepath.substr(0, savepath.size()-filename.size());
		size_t pos = newpath.find_first_of("/", 0);
		while(pos<savepath.size()-filename.size()) {
			newpath = savepath.substr(0, pos);
			pos = savepath.find_first_of("/", pos+1);
			if (!FileSystem::userFiles.MakeDirectory(FileSystem::JoinPathBelow(SAVE_TARGET_DIR,newpath)))
				throw CouldNotOpenFileException();
			printf("Made directory (%s)\n", FileSystem::JoinPathBelow(SAVE_TARGET_DIR,newpath).c_str());
		}

		f = FileSystem::userFiles.OpenWriteStream(
			FileSystem::JoinPathBelow(SAVE_TARGET_DIR, savepath + SGM_EXTENSION));
		printf("Save file (%s)\n", FileSystem::JoinPathBelow(SAVE_TARGET_DIR, savepath + SGM_EXTENSION).c_str());
		if (!f) throw CouldNotOpenFileException();
	} else {
		f = newFS.OpenWriteStream(savepath + SGM_EXTENSION);
		if (!f) throw CouldNotOpenFileException();
	}

	Serializer::Writer wr;

	wr.Byte('S');
	wr.Byte('G');
	wr.Byte('M');
	wr.Byte('1');

	wr.Int32(SGM_VERSION);

	wr.String(m->GetName().c_str());

	SaveMaterials(wr, m);

	SaveHelperVisitor sv(&wr, m);
	m->GetRoot()->Accept(sv);

	m->GetCollisionMesh()->Save(wr);
	wr.Float(m->GetDrawClipRadius());

	SaveAnimations(wr, m);

	//save tags
	wr.Int32(m->GetNumTags());
	for (unsigned int i = 0; i < m->GetNumTags(); i++)
		wr.String(m->GetTagByIndex(i)->GetName().c_str());

	// compress in memory, write to open file 
	size_t outSize = 0;
	size_t nwritten = 0;
	const std::string& data = wr.GetData();
	void *pCompressedData = tdefl_compress_mem_to_heap(data.data(), data.length(), &outSize, 128);
	if (pCompressedData) {
		nwritten = fwrite(pCompressedData, outSize, 1, f);
		mz_free(pCompressedData);
	}
	fclose(f);

	if (nwritten != 1) throw CouldNotWriteToFileException();
}