void Unserialize(Serializer::Reader &rd) { // XXX TODO XXX keep saved data for modules not enabled, // so we can re-save it an not lose it std::string modname; std::string moddata; for (;;) { modname = rd.String(); if (modname == "") break; moddata = rd.String(); bool found = false; for (std::list<std::string>::const_iterator i = s_modules.begin(); i != s_modules.end(); ++i) { if ((*i) == modname) { ModCall(modname.c_str(), "Unserialize", 0, moddata); found = true; break; } } if (!found) { // XXX this isn't good. we should keep the data for re-saving in case the module is enabled again Warning("Could not find the module '%s'. Continuing, but module data will be lost.", modname.c_str()); } } }
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 BinaryConverter::LoadMaterials(Serializer::Reader &rd) { for (Uint32 numMats = rd.Int32(); numMats > 0; numMats--) { MaterialDefinition m(""); m.name = rd.String(); m.tex_diff = rd.String(); m.tex_spec = rd.String(); m.tex_glow = rd.String(); m.tex_ambi = rd.String(); m.tex_norm = rd.String(); m.diffuse = rd.Color4UB(); m.specular = rd.Color4UB(); m.ambient = rd.Color4UB(); m.emissive = rd.Color4UB(); m.shininess = rd.Int16(); m.opacity = rd.Int16(); m.alpha_test = rd.Bool(); m.unlit = rd.Bool(); m.use_pattern = rd.Bool(); if (m.use_pattern) m_patternsUsed = true; ConvertMaterialDefinition(m); } }
BBAdvert BBAdvert::Load(Serializer::Reader &rd) { std::string luaMod = rd.String(); int luaRef = rd.Int32(); std::string desc = rd.String(); return BBAdvert(luaMod, luaRef, desc); }
void ShipFlavour::Load(Serializer::Reader &rd) { id = rd.String(); price = rd.Int32(); regid = rd.String(); LoadLmrMaterial(rd, &primaryColor); LoadLmrMaterial(rd, &secondaryColor); }
void ModelSkin::Load(Serializer::Reader &rd) { for (unsigned int i = 0; i < 3; i++) { m_colors[i].r = rd.Byte(); m_colors[i].g = rd.Byte(); m_colors[i].b = rd.Byte(); } for (unsigned int i = 0; i < MAX_DECAL_MATERIALS; i++) m_decals[i] = rd.String(); m_label = rd.String(); }
void Body::Load(Serializer::Reader &rd, Space *space) { m_frame = space->GetFrameByIndex(rd.Int32()); m_label = rd.String(); m_dead = rd.Bool(); m_hasDoubleFrame = rd.Bool(); }
void ModelBody::Load(Serializer::Reader &rd, Space *space) { Body::Load(rd, space); m_isStatic = rd.Bool(); m_colliding = rd.Bool(); SetModel(rd.String().c_str()); m_model->Load(rd); }
void Body::Load(Serializer::Reader &rd) { m_frame = Serializer::LookupFrame(rd.Int32()); m_label = rd.String(); m_onscreen = rd.Bool(); m_projectedPos = rd.Vector3d(); m_dead = rd.Bool(); m_hasDoubleFrame = rd.Bool(); }
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 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); }
void LuaSerializer::Unserialize(Serializer::Reader &rd) { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); lua_newtable(l); lua_setfield(l, LUA_REGISTRYINDEX, "PiSerializerTableRefs"); std::string pickled = rd.String(); const char *start = pickled.c_str(); const char *end = unpickle(l, start); if (size_t(end - start) != pickled.length()) throw SavedGameCorruptException(); if (!lua_istable(l, -1)) throw SavedGameCorruptException(); int savetable = lua_gettop(l); lua_pushnil(l); lua_setfield(l, LUA_REGISTRYINDEX, "PiSerializerTableRefs"); lua_getfield(l, LUA_REGISTRYINDEX, "PiSerializerCallbacks"); if (lua_isnil(l, -1)) { lua_pop(l, 1); lua_newtable(l); lua_pushvalue(l, -1); lua_setfield(l, LUA_REGISTRYINDEX, "PiSerializerCallbacks"); } lua_pushnil(l); while (lua_next(l, -2) != 0) { lua_pushvalue(l, -2); lua_pushinteger(l, 2); lua_gettable(l, -3); lua_getfield(l, savetable, lua_tostring(l, -2)); if (lua_isnil(l, -1)) { lua_pop(l, 1); lua_newtable(l); } pi_lua_protected_call(l, 1, 0); lua_pop(l, 2); } lua_pop(l, 2); LUA_DEBUG_END(l, 0); }
void Shields::Load(Serializer::Reader &rd) { m_enabled = rd.Bool(); const Uint32 NumShields = rd.Int32(); assert(NumShields == m_shields.size()); for (Uint32 iRead = 0; iRead < NumShields; iRead++ ) { const Uint8 r = rd.Byte(); const Uint8 g = rd.Byte(); const Uint8 b = rd.Byte(); const std::string name = rd.String(); for (ShieldIterator it = m_shields.begin(); it != m_shields.end(); ++it) { if(name==it->m_mesh->GetName()) { it->m_colour = Color3ub(r, g, b); break; } } } }
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; // 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 ShipFlavour::Load(Serializer::Reader &rd) { id = rd.String(); price = rd.Int32(); regid = rd.String(); }