Example #1
0
void SpaceStation::Save(Serializer::Writer &wr, Space *space)
{
	ModelBody::Save(wr, space);
	MarketAgent::Save(wr);
	wr.Int32(Equip::TYPE_MAX);
	for (int i=0; i<Equip::TYPE_MAX; i++) {
		wr.Int32(int(m_equipmentStock[i]));
	}
	// save shipyard
	wr.Int32(m_shipsOnSale.size());
	for (std::vector<ShipFlavour>::iterator i = m_shipsOnSale.begin();
			i != m_shipsOnSale.end(); ++i) {
		(*i).Save(wr);
	}
	for (int i=0; i<MAX_DOCKING_PORTS; i++) {
		wr.Int32(space->GetIndexForBody(m_shipDocking[i].ship));
		wr.Int32(m_shipDocking[i].stage);
		wr.Float(float(m_shipDocking[i].stagePos));
		wr.Vector3d(m_shipDocking[i].fromPos);
		wr.WrQuaternionf(m_shipDocking[i].fromRot);

		wr.Float(float(m_openAnimState[i]));
		wr.Float(float(m_dockAnimState[i]));
	}
	wr.Bool(m_bbCreated);
	wr.Double(m_lastUpdatedShipyard);
	wr.Int32(space->GetIndexForSystemBody(m_sbody));
	wr.Int32(m_numPoliceDocked);
}
Example #2
0
void ShipFlavour::SaveLmrMaterial(Serializer::Writer &wr, LmrMaterial *m)
{
	for (int i=0; i<4; i++) wr.Float(m->diffuse[i]);
	for (int i=0; i<4; i++) wr.Float(m->specular[i]);
	for (int i=0; i<4; i++) wr.Float(m->emissive[i]);
	wr.Float(m->shininess);
}
void ScannerWidget::Save(Serializer::Writer &wr)
{
	wr.Int32(Sint32(m_mode));
	wr.Float(m_currentRange);
	wr.Float(m_manualRange);
	wr.Float(m_targetRange);
}
Example #4
0
void Ship::Save(Serializer::Writer &wr)
{
	DynamicBody::Save(wr);
	wr.Vector3d(m_angThrusters);
	wr.Vector3d(m_thrusters);
	wr.Int32(m_wheelTransition);
	wr.Float(m_wheelState);
	wr.Float(m_launchLockTimeout);
	wr.Bool(m_testLanded);
	wr.Int32(int(m_flightState));
	wr.Int32(int(m_alertState));
	wr.Float(m_lastFiringAlert);

	m_hyperspace.dest.Serialize(wr);
	wr.Float(m_hyperspace.countdown);

	for (int i=0; i<ShipType::GUNMOUNT_MAX; i++) {
		wr.Int32(m_gunState[i]);
		wr.Float(m_gunRecharge[i]);
		wr.Float(m_gunTemperature[i]);
	}
	wr.Float(m_ecmRecharge);
	m_shipFlavour.Save(wr);
	wr.Int32(m_dockedWithPort);
	wr.Int32(Serializer::LookupBody(m_dockedWith));
	m_equipment.Save(wr);
	wr.Float(m_stats.hull_mass_left);
	wr.Float(m_stats.shield_mass_left);
	if(m_curAICmd) { wr.Int32(1); m_curAICmd->Save(wr); }
	else wr.Int32(0);
}
Example #5
0
void Sfx::Save(Serializer::Writer &wr)
{
	wr.Vector3d(m_pos);
	wr.Vector3d(m_vel);
	wr.Float(m_age);
	wr.Int32(m_type);
}
Example #6
0
void SpaceStation::Save(Serializer::Writer &wr, Space *space)
{
	ModelBody::Save(wr, space);
	wr.Int32(Equip::TYPE_MAX);
	wr.Int32(m_shipDocking.size());
	for (Uint32 i=0; i<m_shipDocking.size(); i++) {
		wr.Int32(space->GetIndexForBody(m_shipDocking[i].ship));
		wr.Int32(m_shipDocking[i].stage);
		wr.Float(float(m_shipDocking[i].stagePos));
		wr.Vector3d(m_shipDocking[i].fromPos);
		wr.WrQuaternionf(m_shipDocking[i].fromRot);
	}
	// store each of the bay groupings
	wr.Int32(mBayGroups.size());
	for (Uint32 i=0; i<mBayGroups.size(); i++) {
		wr.Int32(mBayGroups[i].minShipSize);
		wr.Int32(mBayGroups[i].maxShipSize);
		wr.Bool(mBayGroups[i].inUse);
		wr.Int32(mBayGroups[i].bayIDs.size());
		for (Uint32 j=0; j<mBayGroups[i].bayIDs.size(); j++) {
			wr.Int32(mBayGroups[i].bayIDs[j]);
		}
	}

	wr.Int32(space->GetIndexForSystemBody(m_sbody));
	wr.Int32(m_numPoliceDocked);

	wr.Double(m_doorAnimationStep);
	wr.Double(m_doorAnimationState);

	m_navLights->Save(wr);
}
Example #7
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);
}
Example #8
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);
}
Example #9
0
void Projectile::Save(Serializer::Writer &wr, Space *space)
{
	Body::Save(wr, space);
	wr.Vector3d(m_baseVel);
	wr.Vector3d(m_dirVel);
	wr.Float(m_age);
	wr.Int32(m_type);
	wr.Int32(space->GetIndexForBody(m_parent));
}
Example #10
0
void PlayerShipController::Save(Serializer::Writer &wr, Space *space)
{
	wr.Int32(static_cast<int>(m_flightControlState));
	wr.Double(m_setSpeed);
	wr.Float(m_lowThrustPower);
	wr.Int32(space->GetIndexForBody(m_combatTarget));
	wr.Int32(space->GetIndexForBody(m_navTarget));
	wr.Int32(space->GetIndexForBody(m_setSpeedTarget));
}
Example #11
0
void AICommand::Save(Serializer::Writer &wr)
{
	Space *space = Pi::game->GetSpace();
	wr.Int32(m_cmdName);
	wr.Float(m_fuelEconomy);
	wr.Int32(space->GetIndexForBody(m_ship));
	if (m_child) m_child->Save(wr);
	else wr.Int32(CMD_NONE);
}
Example #12
0
void Projectile::Save(Serializer::Writer &wr, Space *space)
{
	Body::Save(wr, space);
	for (int i=0; i<16; i++) wr.Double(m_orient[i]);
	wr.Vector3d(m_baseVel);
	wr.Vector3d(m_dirVel);
	wr.Float(m_age);
	wr.Int32(m_type);
	wr.Int32(space->GetIndexForBody(m_parent));
}
Example #13
0
void SpaceStation::Save(Serializer::Writer &wr, Space *space)
{
	ModelBody::Save(wr, space);
	MarketAgent::Save(wr);
	wr.Int32(Equip::TYPE_MAX);
	for (int i=0; i<Equip::TYPE_MAX; i++) {
		wr.Int32(int(m_equipmentStock[i]));
	}
	// save shipyard
	wr.Int32(m_shipsOnSale.size());
	for (std::vector<ShipOnSale>::iterator i = m_shipsOnSale.begin();
			i != m_shipsOnSale.end(); ++i) {
		wr.String((*i).id);
		wr.String((*i).regId);
		(*i).skin.Save(wr);
	}
	wr.Int32(m_shipDocking.size());
	for (uint32_t i=0; i<m_shipDocking.size(); i++) {
		wr.Int32(space->GetIndexForBody(m_shipDocking[i].ship));
		wr.Int32(m_shipDocking[i].stage);
		wr.Float(float(m_shipDocking[i].stagePos));
		wr.Vector3d(m_shipDocking[i].fromPos);
		wr.WrQuaternionf(m_shipDocking[i].fromRot);
	}
	// store each of the bay groupings
	wr.Int32(mBayGroups.size());
	for (uint32_t i=0; i<mBayGroups.size(); i++) {
		wr.Int32(mBayGroups[i].minShipSize);
		wr.Int32(mBayGroups[i].maxShipSize);
		wr.Bool(mBayGroups[i].inUse);
		wr.Int32(mBayGroups[i].bayIDs.size());
		for (uint32_t j=0; j<mBayGroups[i].bayIDs.size(); j++) {
			wr.Int32(mBayGroups[i].bayIDs[j]);
		}
	}

	wr.Bool(m_bbCreated);
	wr.Double(m_lastUpdatedShipyard);
	wr.Int32(space->GetIndexForSystemBody(m_sbody));
	wr.Int32(m_numPoliceDocked);

	wr.Double(m_doorAnimationStep);
	wr.Double(m_doorAnimationState);

	m_navLights->Save(wr);
}
Example #14
0
void Ship::Save(Serializer::Writer &wr, Space *space)
{
	DynamicBody::Save(wr, space);
	wr.Vector3d(m_angThrusters);
	wr.Vector3d(m_thrusters);
	wr.Int32(m_wheelTransition);
	wr.Float(m_wheelState);
	wr.Float(m_launchLockTimeout);
	wr.Bool(m_testLanded);
	wr.Int32(int(m_flightState));
	wr.Int32(int(m_alertState));
	wr.Double(m_lastFiringAlert);

	// XXX make sure all hyperspace attrs and the cloud get saved
	m_hyperspace.dest.Serialize(wr);
	wr.Float(m_hyperspace.countdown);

	for (int i=0; i<ShipType::GUNMOUNT_MAX; i++) {
		wr.Int32(m_gunState[i]);
		wr.Float(m_gunRecharge[i]);
		wr.Float(m_gunTemperature[i]);
	}
	wr.Float(m_ecmRecharge);
	m_shipFlavour.Save(wr);
	wr.Int32(m_dockedWithPort);
	wr.Int32(space->GetIndexForBody(m_dockedWith));
	m_equipment.Save(wr);
	wr.Float(m_stats.hull_mass_left);
	wr.Float(m_stats.shield_mass_left);
	if(m_curAICmd) { wr.Int32(1); m_curAICmd->Save(wr); }
	else wr.Int32(0);
	wr.Int32(int(m_aiMessage));
	wr.Double(m_thrusterFuel);
	wr.Double(m_reserveFuel);

	wr.Int32(static_cast<int>(m_controller->GetType()));
	m_controller->Save(wr, space);
}
Example #15
0
void CargoBody::Save(Serializer::Writer &wr, Space *space)
{
	DynamicBody::Save(wr, space);
	wr.Int32(static_cast<int>(m_type));
	wr.Float(m_hitpoints);
}
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.Int32(SGM_STRING_ID.value);

	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();
}