void HyperspaceCloud::Load(Serializer::Reader &rd, Space *space) { Body::Load(rd, space); m_vel = rd.Vector3d(); m_birthdate = rd.Double(); m_due = rd.Double(); m_isArrival = rd.Bool(); if (rd.Bool()) { m_ship = static_cast<Ship*>(Body::Unserialize(rd, space)); } }
AIParagonCmdGoTo::AIParagonCmdGoTo(Serializer::Reader &rd) : AICommand(rd, CMD_PARAGON_GOTO) { m_targetFrameIndex = rd.Int32(); m_targetPosition = rd.Vector3d(); m_toTransit = rd.Bool(); if(Game::s_loadedGameVersion >= 77) { // Save game upgrade: 76 -> 77 m_targetOrient = matrix3x3d::FromVectors( rd.Vector3d(), rd.Vector3d(), rd.Vector3d()); m_startPO.pos = rd.Vector3d(); m_startPO.xaxis = rd.Vector3d(); m_startPO.yaxis = rd.Vector3d(); m_startPO.zaxis = rd.Vector3d(); m_endPO.pos = rd.Vector3d(); m_endPO.xaxis = rd.Vector3d(); m_endPO.yaxis = rd.Vector3d(); m_endPO.zaxis = rd.Vector3d(); m_speedLimit = rd.Double(); m_arrivalSpeed = rd.Double(); m_mode = static_cast<EGoToMode>(rd.Int32()); } }
void BinaryConverter::LoadAnimations(Serializer::Reader &rd) { //load channels and PRS keys const Uint32 numAnims = rd.Int32(); for (Uint32 i = 0; i < numAnims; i++) { const std::string animName = rd.String(); const double duration = rd.Double(); Animation *anim = new Animation(animName, duration); const Uint32 numChans = rd.Int32(); for (Uint32 j = 0; j < numChans; j++) { const std::string tgtName = rd.String(); MatrixTransform* tgtNode = dynamic_cast<MatrixTransform*>(m_model->m_root->FindNode(tgtName)); anim->m_channels.push_back(AnimationChannel(tgtNode)); auto& chan = anim->m_channels.back(); for (Uint32 numKeys = rd.Int32(); numKeys > 0; numKeys--) { const double ktime = rd.Double(); const vector3f kpos = rd.Vector3f(); chan.positionKeys.push_back(PositionKey(ktime, kpos)); } for (Uint32 numKeys = rd.Int32(); numKeys > 0; numKeys--) { const double ktime = rd.Double(); const Quaternionf krot = rd.RdQuaternionf(); chan.rotationKeys.push_back(RotationKey(ktime, krot)); } for (Uint32 numKeys = rd.Int32(); numKeys > 0; numKeys--) { const double ktime = rd.Double(); const vector3f kscale = rd.Vector3f(); chan.scaleKeys.push_back(ScaleKey(ktime, kscale)); } } m_model->m_animations.push_back(anim); } }
void Body::Load(Serializer::Reader &rd, Space *space) { m_frame = space->GetFrameByIndex(rd.Int32()); m_label = rd.String(); Properties().Set("label", m_label); m_dead = rd.Bool(); m_pos = rd.Vector3d(); for (int i=0; i<9; i++) m_orient[i] = rd.Double(); m_physRadius = rd.Double(); m_clipRadius = rd.Double(); }
void DynamicBody::Load(Serializer::Reader &rd, Space *space) { ModelBody::Load(rd, space); m_force = rd.Vector3d(); m_torque = rd.Vector3d(); m_vel = rd.Vector3d(); m_angVel = rd.Vector3d(); m_mass = rd.Double(); m_massRadius = rd.Double(); m_angInertia = rd.Double(); m_isMoving = rd.Bool(); }
void Ship::Load(Serializer::Reader &rd, Space *space) { DynamicBody::Load(rd, space); // needs fixups m_angThrusters = rd.Vector3d(); m_thrusters = rd.Vector3d(); m_wheelTransition = rd.Int32(); m_wheelState = rd.Float(); m_launchLockTimeout = rd.Float(); m_testLanded = rd.Bool(); m_flightState = FlightState(rd.Int32()); m_alertState = AlertState(rd.Int32()); m_lastFiringAlert = rd.Double(); m_hyperspace.dest = SystemPath::Unserialize(rd); m_hyperspace.countdown = rd.Float(); for (int i=0; i<ShipType::GUNMOUNT_MAX; i++) { m_gunState[i] = rd.Int32(); m_gunRecharge[i] = rd.Float(); m_gunTemperature[i] = rd.Float(); } m_ecmRecharge = rd.Float(); m_shipFlavour.Load(rd); m_type = &ShipType::types[m_shipFlavour.id]; m_dockedWithPort = rd.Int32(); m_dockedWithIndex = rd.Int32(); m_equipment.InitSlotSizes(m_shipFlavour.id); m_equipment.Load(rd); Init(); m_stats.hull_mass_left = rd.Float(); // must be after Init()... m_stats.shield_mass_left = rd.Float(); if(rd.Int32()) m_curAICmd = AICommand::Load(rd); else m_curAICmd = 0; m_aiMessage = AIError(rd.Int32()); SetFuel(rd.Double()); m_stats.fuel_tank_mass_left = GetShipType().fuelTankMass * GetFuel(); m_reserveFuel = rd.Double(); UpdateStats(); // this is necessary, UpdateStats() in Ship::Init has wrong values of m_thrusterFuel after Load m_controller = 0; const ShipController::Type ctype = static_cast<ShipController::Type>(rd.Int32()); if (ctype == ShipController::PLAYER) SetController(new PlayerShipController()); else SetController(new ShipController()); m_controller->Load(rd); m_equipment.onChange.connect(sigc::mem_fun(this, &Ship::OnEquipmentChange)); }
void DynamicBody::Load(Serializer::Reader &rd) { ModelBody::Load(rd); for (int i=0; i<16; i++) m_orient[i] = rd.Double(); m_oldOrient = m_orient; m_force = rd.Vector3d(); m_torque = rd.Vector3d(); m_vel = rd.Vector3d(); m_angVel = rd.Vector3d(); m_mass = rd.Double(); m_massRadius = rd.Double(); m_angInertia = rd.Double(); m_enabled = rd.Bool(); }
void Pi::Unserialize(Serializer::Reader &rd) { Serializer::Reader section; SetTimeAccel(0); requestedTimeAccelIdx = 0; Space::Clear(); if (Pi::player) { Pi::player->MarkDead(); Space::bodies.remove(Pi::player); delete Pi::player; Pi::player = 0; } section = rd.RdSection("PiMisc"); gameTime = section.Double(); selectedSystem = StarSystem::Unserialize(section); currentSystem = StarSystem::Unserialize(section); section = rd.RdSection("Space"); Space::Unserialize(section); section = rd.RdSection("Polit"); Polit::Unserialize(section); section = rd.RdSection("SectorView"); sectorView->Load(section); section = rd.RdSection("WorldView"); worldView->Load(section); section = rd.RdSection("LuaModules"); PiLuaModules::Unserialize(section); }
void SpaceStation::Load(Serializer::Reader &rd, Space *space) { ModelBody::Load(rd, space); MarketAgent::Load(rd); int num = rd.Int32(); if (num > Equip::TYPE_MAX) throw SavedGameCorruptException(); for (int i=0; i<Equip::TYPE_MAX; i++) { m_equipmentStock[i] = 0; } for (int i=0; i<num; i++) { m_equipmentStock[i] = static_cast<Equip::Type>(rd.Int32()); } // load shityard int numShipsForSale = rd.Int32(); for (int i=0; i<numShipsForSale; i++) { ShipFlavour s; s.Load(rd); m_shipsOnSale.push_back(s); } for (int i=0; i<MAX_DOCKING_PORTS; i++) { m_shipDocking[i].shipIndex = rd.Int32(); m_shipDocking[i].stage = rd.Int32(); m_shipDocking[i].stagePos = rd.Float(); m_shipDocking[i].fromPos = rd.Vector3d(); m_shipDocking[i].fromRot = rd.RdQuaternionf(); m_openAnimState[i] = rd.Float(); m_dockAnimState[i] = rd.Float(); } m_bbCreated = rd.Bool(); m_lastUpdatedShipyard = rd.Double(); m_sbody = space->GetSystemBodyByIndex(rd.Int32()); m_numPoliceDocked = rd.Int32(); InitStation(); }
void Missile::Load(Serializer::Reader &rd) { Ship::Load(rd); m_ownerIndex = rd.Int32(); m_targetIndex = rd.Int32(); m_distToTarget = rd.Double(); m_power = rd.Int32(); }
void SpaceStation::Load(Serializer::Reader &rd, Space *space) { ModelBody::Load(rd, space); m_oldAngDisplacement = 0.0; int num = rd.Int32(); if (num > Equip::TYPE_MAX) throw SavedGameCorruptException(); const Uint32 numShipDocking = rd.Int32(); m_shipDocking.reserve(numShipDocking); for (Uint32 i=0; i<numShipDocking; i++) { m_shipDocking.push_back(shipDocking_t()); shipDocking_t &sd = m_shipDocking.back(); sd.shipIndex = rd.Int32(); sd.stage = rd.Int32(); sd.stagePos = rd.Float(); sd.fromPos = rd.Vector3d(); sd.fromRot = rd.RdQuaternionf(); } // retrieve each of the bay groupings const Uint32 numBays = rd.Int32(); mBayGroups.reserve(numBays); for (Uint32 i=0; i<numBays; i++) { mBayGroups.push_back(SpaceStationType::SBayGroup()); SpaceStationType::SBayGroup &bay = mBayGroups.back(); bay.minShipSize = rd.Int32(); bay.maxShipSize = rd.Int32(); bay.inUse = rd.Bool(); const Uint32 numBayIds = rd.Int32(); bay.bayIDs.reserve(numBayIds); for (Uint32 j=0; j<numBayIds; j++) { const Uint32 ID = rd.Int32(); bay.bayIDs.push_back(ID); } } m_sbody = space->GetSystemBodyByIndex(rd.Int32()); m_numPoliceDocked = rd.Int32(); m_doorAnimationStep = rd.Double(); m_doorAnimationState = rd.Double(); InitStation(); m_navLights->Load(rd); }
void Model::Load(Serializer::Reader &rd) { LoadVisitor lv(&rd); m_root->Accept(lv); for (AnimationContainer::const_iterator i = m_animations.begin(); i != m_animations.end(); ++i) (*i)->SetProgress(rd.Double()); UpdateAnimations(); }
void Player::Load(Serializer::Reader &rd) { Pi::player = this; Ship::Load(rd); m_flightControlState = static_cast<FlightControlState>(rd.Int32()); m_setSpeed = rd.Double(); m_killCount = rd.Int32(); m_knownKillCount = rd.Int32(); }
void Projectile::Load(Serializer::Reader &rd, Space *space) { Body::Load(rd, space); for (int i=0; i<16; i++) m_orient[i] = rd.Double(); m_baseVel = rd.Vector3d(); m_dirVel = rd.Vector3d(); m_age = rd.Float(); m_type = rd.Int32(); m_parentIndex = rd.Int32(); }
void PlayerShipController::Load(Serializer::Reader &rd) { m_flightControlState = static_cast<FlightControlState>(rd.Int32()); m_setSpeed = rd.Double(); m_lowThrustPower = rd.Float(); //figure out actual bodies in PostLoadFixup - after Space body index has been built m_combatTargetIndex = rd.Int32(); m_navTargetIndex = rd.Int32(); m_setSpeedTargetIndex = rd.Int32(); }
void Player::Load(Serializer::Reader &rd, Space *space) { Pi::player = this; Ship::Load(rd, space); MarketAgent::Load(rd); m_flightControlState = static_cast<FlightControlState>(rd.Int32()); m_setSpeed = rd.Double(); m_killCount = rd.Int32(); m_knownKillCount = rd.Int32(); m_combatTargetIndex = rd.Int32(); m_navTargetIndex = rd.Int32(); m_setSpeedTargetIndex = rd.Int32(); }
void CollMesh::Load(Serializer::Reader &rd) { m_aabb.max = rd.Vector3d(); m_aabb.min = rd.Vector3d(); m_aabb.radius = rd.Double(); m_geomTree = new GeomTree(rd); const Uint32 numDynGeomTrees = rd.Int32(); m_dynGeomTrees.reserve(numDynGeomTrees); for (Uint32 it = 0; it < numDynGeomTrees; ++it) { m_dynGeomTrees.push_back(new GeomTree(rd)); } m_totalTris = rd.Int32(); }
Body *Body::Unserialize(Serializer::Reader &_rd, Space *space) { Serializer::Reader rd = _rd.RdSection("Body"); Body *b = 0; Object::Type type = Object::Type(rd.Int32()); switch (type) { case Object::STAR: b = new Star(); break; case Object::PLANET: b = new Planet(); break; case Object::SPACESTATION: b = new SpaceStation(); break; case Object::SHIP: b = new Ship(); break; case Object::PLAYER: b = new Player(); break; case Object::MISSILE: b = new Missile(); break; case Object::PROJECTILE: b = new Projectile(); break; case Object::CARGOBODY: b = new CargoBody(); break; case Object::HYPERSPACECLOUD: b = new HyperspaceCloud(); break; default: assert(0); } b->Load(rd, space); // must SetFrame() correctly so ModelBodies can add geom to space Frame *f = b->m_frame; b->m_frame = 0; b->SetFrame(f); // b->SetPosition(rd.Vector3d()); matrix4x4d m; for (int i=0; i<16; i++) m[i] = rd.Double(); b->SetRotMatrix(m); return b; }
void SpaceStation::Load(Serializer::Reader &rd, Space *space) { ModelBody::Load(rd, space); MarketAgent::Load(rd); int num = rd.Int32(); if (num > Equip::TYPE_MAX) throw SavedGameCorruptException(); for (int i=0; i<Equip::TYPE_MAX; i++) { m_equipmentStock[i] = 0; } for (int i=0; i<num; i++) { m_equipmentStock[i] = static_cast<Equip::Type>(rd.Int32()); } // load shityard int numShipsForSale = rd.Int32(); for (int i=0; i<numShipsForSale; i++) { ShipType::Id id(rd.String()); std::string regId(rd.String()); SceneGraph::ModelSkin skin; skin.Load(rd); ShipOnSale sos(id, regId, skin); m_shipsOnSale.push_back(sos); } for (int i=0; i<MAX_DOCKING_PORTS; i++) { m_shipDocking[i].shipIndex = rd.Int32(); m_shipDocking[i].stage = rd.Int32(); m_shipDocking[i].stagePos = rd.Float(); m_shipDocking[i].fromPos = rd.Vector3d(); m_shipDocking[i].fromRot = rd.RdQuaternionf(); } m_dockingLock = rd.Bool(); m_bbCreated = rd.Bool(); m_lastUpdatedShipyard = rd.Double(); m_sbody = space->GetSystemBodyByIndex(rd.Int32()); m_numPoliceDocked = rd.Int32(); InitStation(); m_navLights->Load(rd); }
Game::Game(Serializer::Reader &rd) : m_timeAccel(TIMEACCEL_PAUSED), m_requestedTimeAccel(TIMEACCEL_PAUSED), m_forceTimeAccel(false) { // signature check for (Uint32 i = 0; i < strlen(s_saveStart)+1; i++) if (rd.Byte() != s_saveStart[i]) throw SavedGameCorruptException(); // version check rd.SetStreamVersion(rd.Int32()); Output("savefile version: %d\n", rd.StreamVersion()); if (rd.StreamVersion() != s_saveVersion) { Output("can't load savefile, expected version: %d\n", s_saveVersion); throw SavedGameWrongVersionException(); } // XXX This must be done after loading sectors once we can change them in game Pi::FlushCaches(); Serializer::Reader section; // Preparing the Lua stuff LuaRef::InitLoad(); Pi::luaSerializer->InitTableRefs(); // galaxy generator section = rd.RdSection("GalaxyGen"); std::string genName = section.String(); GalaxyGenerator::Version genVersion = section.Int32(); if (genName != Pi::GetGalaxy()->GetGeneratorName() || genVersion != Pi::GetGalaxy()->GetGeneratorVersion()) { if (!Pi::CreateGalaxy(genName, genVersion)) { Output("can't load savefile, unsupported galaxy generator %s, version %d\n", genName.c_str(), genVersion); throw SavedGameWrongVersionException(); } } // game state section = rd.RdSection("Game"); m_time = section.Double(); m_state = State(section.Int32()); m_wantHyperspace = section.Bool(); m_hyperspaceProgress = section.Double(); m_hyperspaceDuration = section.Double(); m_hyperspaceEndTime = section.Double(); // space, all the bodies and things section = rd.RdSection("Space"); m_space.reset(new Space(this, section, m_time)); m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32()))); assert(!m_player->IsDead()); // Pioneer does not support necromancy // space transition state section = rd.RdSection("HyperspaceClouds"); // hyperspace clouds being brought over from the previous system Uint32 nclouds = section.Int32(); for (Uint32 i = 0; i < nclouds; i++) m_hyperspaceClouds.push_back(static_cast<HyperspaceCloud*>(Body::Unserialize(section, 0))); // system political stuff section = rd.RdSection("Polit"); Polit::Unserialize(section); // views LoadViews(rd); // lua section = rd.RdSection("LuaModules"); Pi::luaSerializer->Unserialize(section); Pi::luaSerializer->UninitTableRefs(); LuaRef::UninitLoad(); // signature check for (Uint32 i = 0; i < strlen(s_saveEnd)+1; i++) if (rd.Byte() != s_saveEnd[i]) throw SavedGameCorruptException(); EmitPauseState(IsPaused()); }
void SpaceStation::Load(Serializer::Reader &rd, Space *space) { ModelBody::Load(rd, space); MarketAgent::Load(rd); int num = rd.Int32(); if (num > Equip::TYPE_MAX) throw SavedGameCorruptException(); for (int i=0; i<Equip::TYPE_MAX; i++) { m_equipmentStock[i] = 0; } for (int i=0; i<num; i++) { m_equipmentStock[i] = static_cast<Equip::Type>(rd.Int32()); } // load shityard int numShipsForSale = rd.Int32(); for (int i=0; i<numShipsForSale; i++) { ShipType::Id id(rd.String()); std::string regId(rd.String()); SceneGraph::ModelSkin skin; skin.Load(rd); ShipOnSale sos(id, regId, skin); m_shipsOnSale.push_back(sos); } const int32_t numShipDocking = rd.Int32(); m_shipDocking.reserve(numShipDocking); for (int i=0; i<numShipDocking; i++) { m_shipDocking.push_back(shipDocking_t()); shipDocking_t &sd = m_shipDocking.back(); sd.shipIndex = rd.Int32(); sd.stage = rd.Int32(); sd.stagePos = rd.Float(); sd.fromPos = rd.Vector3d(); sd.fromRot = rd.RdQuaternionf(); } // retrieve each of the bay groupings const int32_t numBays = rd.Int32(); mBayGroups.reserve(numBays); for (int32_t i=0; i<numBays; i++) { mBayGroups.push_back(SpaceStationType::SBayGroup()); SpaceStationType::SBayGroup &bay = mBayGroups.back(); bay.minShipSize = rd.Int32(); bay.maxShipSize = rd.Int32(); bay.inUse = rd.Bool(); const int32_t numBayIds = rd.Int32(); bay.bayIDs.reserve(numBayIds); for (int32_t j=0; j<numBayIds; j++) { const int32_t ID = rd.Int32(); bay.bayIDs.push_back(ID); } } m_bbCreated = rd.Bool(); m_lastUpdatedShipyard = rd.Double(); m_sbody = space->GetSystemBodyByIndex(rd.Int32()); m_numPoliceDocked = rd.Int32(); m_doorAnimationStep = rd.Double(); m_doorAnimationState = rd.Double(); InitStation(); m_navLights->Load(rd); }
Game::Game(Serializer::Reader &rd) : m_timeAccel(TIMEACCEL_PAUSED), m_requestedTimeAccel(TIMEACCEL_PAUSED), m_forceTimeAccel(false) { // signature check for (Uint32 i = 0; i < strlen(s_saveStart)+1; i++) if (rd.Byte() != s_saveStart[i]) throw SavedGameCorruptException(); // version check rd.SetStreamVersion(rd.Int32()); Output("savefile version: %d\n", rd.StreamVersion()); if (rd.StreamVersion() != s_saveVersion) { Output("can't load savefile, expected version: %d\n", s_saveVersion); throw SavedGameWrongVersionException(); } // XXX This must be done after loading sectors once we can change them in game Pi::FlushCaches(); Serializer::Reader section; // game state section = rd.RdSection("Game"); m_time = section.Double(); m_state = State(section.Int32()); m_wantHyperspace = section.Bool(); m_hyperspaceProgress = section.Double(); m_hyperspaceDuration = section.Double(); m_hyperspaceEndTime = section.Double(); // space, all the bodies and things section = rd.RdSection("Space"); m_space.reset(new Space(this, section, m_time)); m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32()))); // space transition state section = rd.RdSection("HyperspaceClouds"); // hyperspace clouds being brought over from the previous system Uint32 nclouds = section.Int32(); for (Uint32 i = 0; i < nclouds; i++) m_hyperspaceClouds.push_back(static_cast<HyperspaceCloud*>(Body::Unserialize(section, 0))); // system political stuff section = rd.RdSection("Polit"); Polit::Unserialize(section); // views LoadViews(rd); // lua section = rd.RdSection("LuaModules"); Pi::luaSerializer->Unserialize(section); // signature check for (Uint32 i = 0; i < strlen(s_saveEnd)+1; i++) if (rd.Byte() != s_saveEnd[i]) throw SavedGameCorruptException(); }
GeomTree::GeomTree(Serializer::Reader &rd) { m_numVertices = rd.Int32(); m_numEdges = rd.Int32(); m_numTris = rd.Int32(); m_radius = rd.Double(); m_aabb.max = rd.Vector3d(); m_aabb.min = rd.Vector3d(); m_aabb.radius = rd.Double(); const Uint32 numAabbs = rd.Int32(); m_aabbs.resize(numAabbs); for (Uint32 iAabb = 0; iAabb < numAabbs; ++iAabb) { m_aabbs[iAabb].max = rd.Vector3d(); m_aabbs[iAabb].min = rd.Vector3d(); m_aabbs[iAabb].radius = rd.Double(); } m_edges.resize(m_numEdges); for (Sint32 iEdge = 0; iEdge < m_numEdges; ++iEdge) { m_edges[iEdge].Load(rd); } m_vertices.resize(m_numVertices); for (Sint32 iVert = 0; iVert < m_numVertices; ++iVert) { m_vertices[iVert] = rd.Vector3f(); } const int numIndicies(m_numTris * 3); m_indices.resize(numIndicies); for (Sint32 iIndi = 0; iIndi < numIndicies; ++iIndi) { m_indices[iIndi] = rd.Int16(); } m_triFlags.resize(m_numTris); for (Sint32 iTri = 0; iTri < m_numTris; ++iTri) { m_triFlags[iTri] = rd.Int32(); } // activeTris = tris we are still trying to put into leaves std::vector<int> activeTris; activeTris.reserve(m_numTris); // So, we ignore tris with flag >= 0x8000 for (int i = 0; i<m_numTris; i++) { if (m_triFlags[i] >= IGNORE_FLAG) continue; activeTris.push_back(i * 3); } // regenerate the aabb data Aabb *aabbs = new Aabb[activeTris.size()]; for (unsigned int i = 0; i<activeTris.size(); i++) { const vector3d v1 = vector3d(m_vertices[m_indices[activeTris[i] + 0]]); const vector3d v2 = vector3d(m_vertices[m_indices[activeTris[i] + 1]]); const vector3d v3 = vector3d(m_vertices[m_indices[activeTris[i] + 2]]); aabbs[i].min = aabbs[i].max = v1; aabbs[i].Update(v2); aabbs[i].Update(v3); } m_triTree.reset(new BVHTree(activeTris.size(), &activeTris[0], aabbs)); delete[] aabbs; // int *edgeIdxs = new int[m_numEdges]; memset(edgeIdxs, 0, sizeof(int)*m_numEdges); for (int i = 0; i<m_numEdges; i++) { edgeIdxs[i] = i; } m_edgeTree.reset(new BVHTree(m_numEdges, edgeIdxs, &m_aabbs[0])); }