diff --git a/data/libs/SpaceStation.lua b/data/libs/SpaceStation.lua index e6a21ac6ab2..dc71c4cbc4a 100644 --- a/data/libs/SpaceStation.lua +++ b/data/libs/SpaceStation.lua @@ -41,6 +41,7 @@ local function updateEquipmentStock (station) assert(station and station:exists()) if equipmentStock[station] then return end equipmentStock[station] = {} + local hydrogen = Equipment.cargo.hydrogen for key, e in pairs(Equipment.cargo) do if e.purchasable then @@ -65,6 +66,7 @@ local function updateEquipmentStock (station) equipmentStock[station][e] = 0 -- commodity that cant be bought end end + for _,slot in pairs{"laser", "hyperspace", "misc"} do for key, e in pairs(Equipment[slot]) do equipmentStock[station][e] = Engine.rand:Integer(0,100) @@ -289,13 +291,6 @@ local function addRandomShipAdvert(station, num) end end -local function createShipMarket (station) - shipsOnSale[station] = {} - - local shipAdsToSpawn = Engine.rand:Poisson(N_equilibrium(station)) - addRandomShipAdvert(station, shipAdsToSpawn) -end - local function updateShipsOnSale (station) if not shipsOnSale[station] then shipsOnSale[station] = {} end local shipsOnSale = shipsOnSale[station] @@ -612,11 +607,8 @@ function SpaceStation:LockAdvert (ref) end local function updateAdverts (station) - -- XXX this should really just be a single event - -- XXX don't create for stations we haven't visited if not SpaceStation.adverts[station] then - SpaceStation.adverts[station] = {} - Event.Queue("onCreateBB", station) + logWarning("SpaceStation.lua: updateAdverts called for station that hasn't been visited") else Event.Queue("onUpdateBB", station) end @@ -662,18 +654,23 @@ end local function updateSystem () local stations = Space.GetBodies(function (b) return b.superType == "STARPORT" end) - for i=1,#stations do - updateEquipmentStock(stations[i]) - updateShipsOnSale(stations[i]) - updateAdverts(stations[i]) + for i, station in ipairs(stations) do + if SpaceStation.adverts[station] then + updateEquipmentStock(station) + updateShipsOnSale(station) + updateAdverts(station) + end end end -local function createSystem() - local stations = Space.GetBodies(function (b) return b.superType == "STARPORT" end) - for i=1,#stations do - createShipMarket(stations[i]) - end +local function createStationMarket (station) + SpaceStation.adverts[station] = {} + shipsOnSale[station] = {} + + updateEquipmentStock(station) + local shipAdsToSpawn = Engine.rand:Poisson(N_equilibrium(station)) + addRandomShipAdvert(station, shipAdsToSpawn) + Event.Queue("onCreateBB", station) end local function destroySystem () @@ -717,14 +714,12 @@ Event.Register("onGameStart", function () loaded_data = nil end - createSystem() - updateSystem() Timer:CallEvery(3600, updateSystem) end) -Event.Register("onEnterSystem", function (ship) + +Event.Register("onShipDocked", function (ship, station) if ship ~= Game.player then return end - createSystem() - updateSystem() + createStationMarket(station) end) Event.Register("onLeaveSystem", function (ship) diff --git a/src/posix/FileSystemPosix.cpp b/src/posix/FileSystemPosix.cpp index fc76cc64e5c..bd1606a7225 100644 --- a/src/posix/FileSystemPosix.cpp +++ b/src/posix/FileSystemPosix.cpp @@ -82,8 +82,6 @@ namespace FileSystem { CFRelease(resourcesURL); return path; #else - printf("Init!\n"); - if (!getenv("PIONEER_LOCAL_DATA_ONLY")) { /* PIONEER_DATA_DIR should point to ${prefix}/share/pioneer/data. * If this directory does not exist, try to use the "data" folder diff --git a/src/scenegraph/MatrixTransform.h b/src/scenegraph/MatrixTransform.h index 644ee55e9f3..f854541a0f7 100644 --- a/src/scenegraph/MatrixTransform.h +++ b/src/scenegraph/MatrixTransform.h @@ -3,16 +3,24 @@ #ifndef _MATRIXTRANSFORM_H #define _MATRIXTRANSFORM_H -/* - * Applies a matrix transform to child nodes - */ + #include "Group.h" #include "matrix4x4.h" + namespace Graphics { class Renderer; } namespace SceneGraph { + + /* + * Applies a matrix transform to child nodes + * + * Note: transforms are not automatically serialized when saving to disk; + * they are derived from the original model and animations. + * If you have programmatically positioned a MatrixTransform, it is your + * responsibility to ensure the new position is properly serialized. + */ class MatrixTransform : public Group { public: MatrixTransform(Graphics::Renderer *r, const matrix4x4f &m); diff --git a/src/scenegraph/Model.cpp b/src/scenegraph/Model.cpp index f5d5e2bd498..640aedc7e34 100644 --- a/src/scenegraph/Model.cpp +++ b/src/scenegraph/Model.cpp @@ -526,32 +526,10 @@ namespace SceneGraph { } } - class SaveVisitorJson : public NodeVisitor { - public: - SaveVisitorJson(Json &jsonObj) : - m_jsonArray(jsonObj) {} - - void ApplyMatrixTransform(MatrixTransform &node) - { - const matrix4x4f &m = node.GetTransform(); - Json matrixTransformObj({}); // Create JSON object to contain matrix transform data. - matrixTransformObj["m"] = m; - m_jsonArray.push_back(matrixTransformObj); // Append matrix transform object to array. - } - - private: - Json &m_jsonArray; - }; - void Model::SaveToJson(Json &jsonObj) const { Json modelObj({}); // Create JSON object to contain model data. - Json visitorArray = Json::array(); // Create JSON array to contain visitor data. - SaveVisitorJson sv(visitorArray); - m_root->Accept(sv); - modelObj["visitor"] = visitorArray; // Add visitor array to model object. - Json animationArray = Json::array(); // Create JSON array to contain animation data. for (auto i : m_animations) animationArray.push_back(i->GetProgress()); @@ -562,44 +540,11 @@ namespace SceneGraph { jsonObj["model"] = modelObj; // Add model object to supplied object. } - class LoadVisitorJson : public NodeVisitor { - public: - LoadVisitorJson(const Json &jsonObj) : - m_jsonArray(jsonObj), - m_arrayIndex(0), - hadError(false) {} - - void ApplyMatrixTransform(MatrixTransform &node) - { - // do nothing if the model has corruption issues - if (m_arrayIndex >= m_jsonArray.size()) { - hadError = true; - return; - } - - node.SetTransform(m_jsonArray[m_arrayIndex++]["m"]); - } - - bool success() const { return !hadError; } - - private: - const Json &m_jsonArray; - unsigned int m_arrayIndex; - bool hadError; - }; - void Model::LoadFromJson(const Json &jsonObj) { try { Json modelObj = jsonObj["model"]; - Json visitorArray = modelObj["visitor"].get(); - LoadVisitorJson lv(visitorArray); - m_root->Accept(lv); - if (!lv.success()) { - Log::Info("Error(s) occurred while loading saved data for model '{}'. The model file may have changed on disk.\n", m_name); - } - Json animationArray = modelObj["animations"].get(); if (m_animations.size() == animationArray.size()) { unsigned int arrayIndex = 0; diff --git a/src/scenegraph/ModelSkin.cpp b/src/scenegraph/ModelSkin.cpp index 9173f7ee6f8..62e6594dede 100644 --- a/src/scenegraph/ModelSkin.cpp +++ b/src/scenegraph/ModelSkin.cpp @@ -103,15 +103,14 @@ namespace SceneGraph { Json colorsArray = modelSkinObj["colors"].get(); if (colorsArray.size() != 3) throw SavedGameCorruptException(); for (unsigned int i = 0; i < 3; i++) { - Json arrayElem = colorsArray[i]; - m_colors[i] = arrayElem["color"]; + if (colorsArray[i].is_array()) + m_colors[i] = colorsArray[i]; } Json decalsArray = modelSkinObj["decals"].get(); - if (decalsArray.size() != MAX_DECAL_MATERIALS) throw SavedGameCorruptException(); for (unsigned int i = 0; i < MAX_DECAL_MATERIALS; i++) { - Json arrayElem = decalsArray[i]; - m_decals[i] = arrayElem["decal"].get(); + if (decalsArray.size() > i && decalsArray[i].is_string()) + m_decals[i] = decalsArray[i].get(); } m_label = modelSkinObj["label"].get(); @@ -138,18 +137,14 @@ namespace SceneGraph { Json colorsArray = Json::array(); // Create JSON array to contain colors data. for (unsigned int i = 0; i < 3; i++) { - Json arrayElem({}); - arrayElem["color"] = m_colors[i]; - colorsArray.push_back(arrayElem); + colorsArray.push_back(m_colors[i]); } modelSkinObj["colors"] = colorsArray; // Add colors array to model skin object. Json decalsArray = Json::array(); // Create JSON array to contain decals data. for (unsigned int i = 0; i < MAX_DECAL_MATERIALS; i++) { - Json arrayElem({}); - arrayElem["decal"] = m_decals[i]; - decalsArray.push_back(arrayElem); + decalsArray.push_back(m_decals[i]); } modelSkinObj["decals"] = decalsArray; // Add decals array to model skin object.