mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 12:31:51 +00:00
feat: environment is primary
This commit is contained in:
parent
4aaa5b2d7e
commit
3476bddc6b
10 changed files with 60 additions and 29 deletions
|
|
@ -22,6 +22,7 @@ dv::value Environment::serialize() const {
|
|||
{"clouds", sky.clouds},
|
||||
{"sprites", std::move(skySpritesList)},
|
||||
})},
|
||||
{"generator", generator}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -44,4 +45,5 @@ void Environment::deserialize(const dv::value& src) {
|
|||
}
|
||||
}
|
||||
}
|
||||
src.at("generator").get(generator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ public:
|
|||
};
|
||||
} sky;
|
||||
|
||||
std::string generator;
|
||||
|
||||
Environment() = default;
|
||||
|
||||
dv::value serialize() const override;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ Level::Level(
|
|||
entities(std::make_unique<Entities>(*this)),
|
||||
players(std::make_unique<Players>(*this)),
|
||||
pathfinding(std::make_unique<voxels::Pathfinding>(*this)) {
|
||||
|
||||
const auto& worldInfo = world->getInfo();
|
||||
auto& cameraIndices = content.getIndices(ResourceType::CAMERA);
|
||||
for (size_t i = 0; i < cameraIndices.size(); i++) {
|
||||
|
|
|
|||
|
|
@ -65,12 +65,12 @@ void World::writeResources(const Content& content) {
|
|||
io::write_json(wfile->getResourcesFile(), root);
|
||||
}
|
||||
|
||||
void World::write(Level* level) {
|
||||
level->chunks->saveAll();
|
||||
info.nextEntityId = level->entities->peekNextID();
|
||||
void World::write(Level& level) {
|
||||
level.chunks->saveAll();
|
||||
info.nextEntityId = level.entities->peekNextID();
|
||||
wfile->write(this, &content);
|
||||
|
||||
auto playerFile = level->players->serialize();
|
||||
auto playerFile = level.players->serialize();
|
||||
io::write_json(wfile->getPlayerFile(), playerFile);
|
||||
|
||||
writeResources(content);
|
||||
|
|
@ -78,7 +78,8 @@ void World::write(Level* level) {
|
|||
|
||||
std::unique_ptr<Level> World::create(
|
||||
const std::string& name,
|
||||
const std::string& generator,
|
||||
const std::string& environment,
|
||||
const std::string& generatorOverride,
|
||||
const io::path& directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
|
|
@ -87,7 +88,8 @@ std::unique_ptr<Level> World::create(
|
|||
) {
|
||||
WorldInfo info {};
|
||||
info.name = name;
|
||||
info.generator = generator;
|
||||
info.environment = environment;
|
||||
info.explicitGenerator = generatorOverride;
|
||||
info.seed = seed;
|
||||
auto world = std::make_unique<World>(
|
||||
info,
|
||||
|
|
@ -101,7 +103,7 @@ std::unique_ptr<Level> World::create(
|
|||
logger.info() << "created world '" << name << "' ("
|
||||
<< directory.string() << ")";
|
||||
}
|
||||
logger.info() << "world seed: " << seed << " generator: " << generator;
|
||||
logger.info() << "world seed: " << seed << " environment: " << environment;
|
||||
return std::make_unique<Level>(std::move(world), content, settings);
|
||||
}
|
||||
|
||||
|
|
@ -122,16 +124,19 @@ std::unique_ptr<Level> World::load(
|
|||
<< worldFilesPtr->getFolder().string() << ")";
|
||||
logger.info() << "world version: " << info->major << "." << info->minor
|
||||
<< " seed: " << info->seed
|
||||
<< " generator: " << info->generator;
|
||||
<< " environment: " << info->environment;
|
||||
|
||||
auto world = std::make_unique<World>(
|
||||
auto worldPtr = std::make_unique<World>(
|
||||
info.value(), std::move(worldFilesPtr), content, packs
|
||||
);
|
||||
auto world = worldPtr.get();
|
||||
auto& wfile = world->wfile;
|
||||
wfile->readResourcesData(content);
|
||||
|
||||
auto level = std::make_unique<Level>(std::move(world), content, settings);
|
||||
|
||||
auto level = std::make_unique<Level>(std::move(worldPtr), content, settings);
|
||||
if (world->getEnvironment().empty()) {
|
||||
level->environment.generator = world->getInfo().explicitGenerator;
|
||||
}
|
||||
io::path file = wfile->getPlayerFile();
|
||||
if (!io::is_regular_file(file)) {
|
||||
logger.warning() << "player.json does not exists";
|
||||
|
|
@ -163,8 +168,8 @@ void World::setName(const std::string& name) {
|
|||
this->info.name = name;
|
||||
}
|
||||
|
||||
void World::setGenerator(const std::string& generator) {
|
||||
this->info.generator = generator;
|
||||
void World::setEnvironment(const std::string& environment) {
|
||||
this->info.environment = environment;
|
||||
}
|
||||
|
||||
bool World::hasPack(const std::string& id) const {
|
||||
|
|
@ -186,8 +191,8 @@ uint64_t World::getSeed() const {
|
|||
return info.seed;
|
||||
}
|
||||
|
||||
std::string World::getGenerator() const {
|
||||
return info.generator;
|
||||
std::string World::getEnvironment() const {
|
||||
return info.environment;
|
||||
}
|
||||
|
||||
const std::vector<ContentPack>& World::getPacks() const {
|
||||
|
|
@ -196,7 +201,8 @@ const std::vector<ContentPack>& World::getPacks() const {
|
|||
|
||||
void WorldInfo::deserialize(const dv::value& root) {
|
||||
name = root["name"].asString();
|
||||
generator = root["generator"].asString(generator);
|
||||
root.at("environment").get(environment);
|
||||
root.at("generator").get(explicitGenerator);
|
||||
seed = root["seed"].asInteger(seed);
|
||||
|
||||
if (root.has("version")) {
|
||||
|
|
@ -226,7 +232,11 @@ dv::value WorldInfo::serialize() const {
|
|||
versionobj["minor"] = ENGINE_VERSION_MINOR;
|
||||
|
||||
root["name"] = name;
|
||||
root["generator"] = generator;
|
||||
if (environment.empty()) {
|
||||
root["generator"] = explicitGenerator;
|
||||
} else {
|
||||
root["environment"] = environment;
|
||||
}
|
||||
root["seed"] = seed;
|
||||
|
||||
auto& timeobj = root.object("time");
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ public:
|
|||
|
||||
struct WorldInfo : public Serializable {
|
||||
std::string name;
|
||||
std::string generator;
|
||||
std::string environment;
|
||||
std::string explicitGenerator;
|
||||
uint64_t seed;
|
||||
int64_t nextInventoryId = 1;
|
||||
int64_t nextPlayerId = 0;
|
||||
|
|
@ -76,7 +77,7 @@ public:
|
|||
void updateTimers(float delta);
|
||||
|
||||
/// @brief Write all unsaved level data to the world directory
|
||||
void write(Level* level);
|
||||
void write(Level& level);
|
||||
|
||||
/// @brief Check world indices and generate ContentReport if convert required
|
||||
/// @param directory world directory
|
||||
|
|
@ -98,7 +99,8 @@ public:
|
|||
/// @return Level instance containing World instance
|
||||
static std::unique_ptr<Level> create(
|
||||
const std::string& name,
|
||||
const std::string& generator,
|
||||
const std::string& environment,
|
||||
const std::string& generatorOverride,
|
||||
const io::path& directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
|
|
@ -123,7 +125,7 @@ public:
|
|||
|
||||
void setName(const std::string& name);
|
||||
void setSeed(uint64_t seed);
|
||||
void setGenerator(const std::string& generator);
|
||||
void setEnvironment(const std::string& environment);
|
||||
|
||||
/// @brief Check if world has content-pack installed
|
||||
/// @param id content-pack id
|
||||
|
|
@ -137,7 +139,7 @@ public:
|
|||
uint64_t getSeed() const;
|
||||
|
||||
/// @brief Get world generator id
|
||||
std::string getGenerator() const;
|
||||
std::string getEnvironment() const;
|
||||
|
||||
bool isNameless() const {
|
||||
return info.name.empty();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue