431a9c00a5
On Linux and macOS, using Clang to compile OpenStarbound produces about 400 MB worth of warnings during the build, making the compiler output unreadable and slowing the build down considerably. 99% of the warnings were unqualified uses of std::move and std::forward, which are now all properly qualified. Fixed a few other minor warnings about non-virtual destructors and some uses of std::move preventing copy elision on temporary objects. Most remaining warnings are now unused parameters.
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
#include "StarVehicleDatabase.hpp"
|
|
#include "StarVehicle.hpp"
|
|
#include "StarJsonExtra.hpp"
|
|
#include "StarRoot.hpp"
|
|
#include "StarAssets.hpp"
|
|
|
|
namespace Star {
|
|
|
|
VehicleDatabase::VehicleDatabase() {
|
|
auto assets = Root::singleton().assets();
|
|
auto files = assets->scanExtension("vehicle");
|
|
assets->queueJsons(files);
|
|
for (auto file : files) {
|
|
try {
|
|
auto config = assets->json(file);
|
|
String name = config.getString("name");
|
|
|
|
if (m_vehicles.contains(name))
|
|
throw VehicleDatabaseException::format("Repeat vehicle name '{}'", name);
|
|
|
|
m_vehicles.add(std::move(name), make_pair(std::move(file), std::move(config)));
|
|
} catch (StarException const& e) {
|
|
throw VehicleDatabaseException(strf("Error loading vehicle '{}'", file), e);
|
|
}
|
|
}
|
|
}
|
|
|
|
VehiclePtr VehicleDatabase::create(String const& vehicleName, Json const& extraConfig) const {
|
|
auto configPair = m_vehicles.ptr(vehicleName);
|
|
if (!configPair)
|
|
throw VehicleDatabaseException::format("No such vehicle named '{}'", vehicleName);
|
|
return make_shared<Vehicle>(configPair->second, configPair->first, extraConfig);
|
|
}
|
|
|
|
ByteArray VehicleDatabase::netStore(VehiclePtr const& vehicle) const {
|
|
DataStreamBuffer ds;
|
|
ds.write(vehicle->baseConfig().getString("name"));
|
|
ds.write(vehicle->dynamicConfig());
|
|
return ds.takeData();
|
|
}
|
|
|
|
VehiclePtr VehicleDatabase::netLoad(ByteArray const& netStore) const {
|
|
DataStreamBuffer ds(netStore);
|
|
|
|
String name = ds.read<String>();
|
|
auto dynamicConfig = ds.read<Json>();
|
|
auto vehicle = create(name, dynamicConfig);
|
|
|
|
return vehicle;
|
|
}
|
|
|
|
Json VehicleDatabase::diskStore(VehiclePtr const& vehicle) const {
|
|
return JsonObject{
|
|
{"name", vehicle->baseConfig().getString("name")},
|
|
{"dynamicConfig", vehicle->dynamicConfig()},
|
|
{"state", vehicle->diskStore()}
|
|
};
|
|
}
|
|
|
|
VehiclePtr VehicleDatabase::diskLoad(Json const& diskStore) const {
|
|
auto vehicle = create(diskStore.getString("name"), diskStore.get("dynamicConfig"));
|
|
vehicle->diskLoad(diskStore.get("state"));
|
|
return vehicle;
|
|
}
|
|
|
|
}
|