mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
cleanup World references
This commit is contained in:
parent
ac00c561ee
commit
c73b036099
18 changed files with 45 additions and 45 deletions
|
|
@ -57,7 +57,7 @@ void ServerMainloop::run() {
|
|||
}
|
||||
process->update();
|
||||
if (controller) {
|
||||
controller->getLevel()->getWorld()->updateTimers(delta);
|
||||
controller->getLevel()->getWorld().updateTimers(delta);
|
||||
controller->update(glm::min(delta, 0.2), false);
|
||||
}
|
||||
engine.applicationTick();
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ std::shared_ptr<UINode> create_debug_panel(
|
|||
}
|
||||
}));
|
||||
panel->add(create_label(gui, [&]() {
|
||||
return L"seed: " + std::to_wstring(level.getWorld()->getSeed());
|
||||
return L"seed: " + std::to_wstring(level.getWorld().getSeed());
|
||||
}));
|
||||
|
||||
for (int ax = 0; ax < 3; ax++) {
|
||||
|
|
@ -294,7 +294,7 @@ std::shared_ptr<UINode> create_debug_panel(
|
|||
sub->add(box, glm::vec2(20, 0));
|
||||
panel->add(sub);
|
||||
}
|
||||
auto& worldInfo = level.getWorld()->getInfo();
|
||||
auto& worldInfo = level.getWorld().getInfo();
|
||||
panel->add(create_label(gui, [&]() {
|
||||
int hour, minute, second;
|
||||
timeutil::from_value(worldInfo.daytime, hour, minute, second);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ LevelScreen::LevelScreen(
|
|||
Engine& engine, std::unique_ptr<Level> levelPtr, int64_t localPlayer
|
||||
)
|
||||
: Screen(engine),
|
||||
world(*levelPtr->getWorld()),
|
||||
world(levelPtr->getWorld()),
|
||||
postProcessing(std::make_unique<PostProcessing>(
|
||||
levelPtr->content.getIndices(ResourceType::POST_EFFECT_SLOT).size()
|
||||
)),
|
||||
|
|
@ -98,7 +98,7 @@ LevelScreen::LevelScreen(
|
|||
return false;
|
||||
}));
|
||||
controller->preQuitCallbacks.listen([this]() {
|
||||
if (!controller->getLevel()->getWorld()->isNameless()) {
|
||||
if (!controller->getLevel()->getWorld().isNameless()) {
|
||||
saveWorldPreview();
|
||||
}
|
||||
});
|
||||
|
|
@ -109,7 +109,7 @@ LevelScreen::LevelScreen(
|
|||
}
|
||||
|
||||
LevelScreen::~LevelScreen() {
|
||||
if (!controller->getLevel()->getWorld()->isNameless()) {
|
||||
if (!controller->getLevel()->getWorld().isNameless()) {
|
||||
saveDecorations();
|
||||
}
|
||||
scripting::on_frontend_close();
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ void Shadows::setup(Shader& shader, const Weather& weather) {
|
|||
if (!shadows) {
|
||||
return;
|
||||
}
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
const auto& worldInfo = level.getWorld().getInfo();
|
||||
float cloudsIntensity = weather.clouds();
|
||||
float shadowsOpacity = 1.0f - cloudsIntensity;
|
||||
shadowsOpacity *= glm::sqrt(glm::abs(
|
||||
|
|
@ -158,8 +158,8 @@ void Shadows::generateShadowsMap(
|
|||
float scale,
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
) {
|
||||
auto world = level.getWorld();
|
||||
const auto& worldInfo = world->getInfo();
|
||||
const auto& world = level.getWorld();
|
||||
const auto& worldInfo = world.getInfo();
|
||||
|
||||
int resolution = shadowMap.getResolution();
|
||||
float shadowMapScale = 0.32f / (1 << glm::max(0, quality)) * scale;
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ void WorldRenderer::setupWorldShader(
|
|||
shader.uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
|
||||
shader.uniform1i("u_debugLights", lightsDebug);
|
||||
shader.uniform1i("u_debugNormals", false);
|
||||
shader.uniform1f("u_dayTime", level.getWorld()->getInfo().daytime);
|
||||
shader.uniform1f("u_dayTime", level.getWorld().getInfo().daytime);
|
||||
shader.uniform2f("u_lightDir", skybox->getLightDir());
|
||||
shader.uniform1i("u_skybox", advanced_pipeline::TARGET_SKYBOX);
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ void WorldRenderer::renderFrameClassic(
|
|||
bool hudVisible,
|
||||
PostProcessing& postProcessing
|
||||
) {
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
const auto& worldInfo = level.getWorld().getInfo();
|
||||
|
||||
DrawContext ctx = pctx.sub();
|
||||
ctx.setDepthTest(true);
|
||||
|
|
@ -381,7 +381,7 @@ void WorldRenderer::renderFrameAdvanced(
|
|||
PostProcessing& postProcessing
|
||||
) {
|
||||
const auto& settings = engine.getSettings();
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
const auto& worldInfo = level.getWorld().getInfo();
|
||||
float fogFactor = calcFogFactor();
|
||||
|
||||
shadowMapping->refresh(camera, pctx, [this, &camera](Camera& shadowCamera) {
|
||||
|
|
@ -401,8 +401,6 @@ void WorldRenderer::renderFrameAdvanced(
|
|||
ctx.useTexture(advanced_pipeline::TARGET_COLOR, nullptr);
|
||||
|
||||
postProcessing.bindDepthBuffer();
|
||||
|
||||
// Background sky plane
|
||||
skybox->draw(
|
||||
level.environment, ctx, camera, worldInfo.daytime, weather.clouds()
|
||||
);
|
||||
|
|
@ -441,7 +439,7 @@ void WorldRenderer::renderFrame(
|
|||
dirtySettings = false;
|
||||
}
|
||||
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
const auto& worldInfo = level.getWorld().getInfo();
|
||||
float clouds = weather.clouds();
|
||||
|
||||
float random = rand() / static_cast<float>(RAND_MAX);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ Inventories::Inventories(Level& level) : level(level) {
|
|||
Inventories::~Inventories() = default;
|
||||
|
||||
std::shared_ptr<Inventory> Inventories::create(size_t size) {
|
||||
int64_t id = level.getWorld()->getNextInventoryId();
|
||||
int64_t id = level.getWorld().getNextInventoryId();
|
||||
auto inv = std::make_shared<Inventory>(id, size);
|
||||
store(inv);
|
||||
return inv;
|
||||
|
|
@ -52,7 +52,7 @@ std::shared_ptr<Inventory> Inventories::clone(int64_t id) {
|
|||
auto original = get(id);
|
||||
if (original == nullptr) return nullptr;
|
||||
auto clone = std::make_shared<Inventory>(*original);
|
||||
clone->setId(level.getWorld()->getNextInventoryId());
|
||||
clone->setId(level.getWorld().getNextInventoryId());
|
||||
store(clone);
|
||||
return clone;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ ChunksController::ChunksController(Level& level)
|
|||
generator(std::make_unique<WorldGenerator>(
|
||||
level.content.generators.require(level.environment.generator),
|
||||
level.content,
|
||||
level.getWorld()->getSeed()
|
||||
level.getWorld().getSeed()
|
||||
)) {}
|
||||
|
||||
ChunksController::~ChunksController() = default;
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ void EngineController::createWorld(
|
|||
|
||||
// generator-based environments must die in 1.0
|
||||
bool genBasedEnv = false;
|
||||
if (auto genDef = generators.find(environment)) {
|
||||
if (generators.find(environment)) {
|
||||
genBasedEnv = true;
|
||||
}
|
||||
|
||||
|
|
@ -314,8 +314,8 @@ void EngineController::setLocalPlayer(int64_t player) {
|
|||
localPlayer = player;
|
||||
}
|
||||
|
||||
void EngineController::reopenWorld(World* world) {
|
||||
std::string name = world->wfile->getFolder().name();
|
||||
void EngineController::reopenWorld(World& world) {
|
||||
std::string name = world.wfile->getFolder().name();
|
||||
engine.onWorldClosed();
|
||||
openWorld(name, true);
|
||||
}
|
||||
|
|
@ -384,16 +384,16 @@ void EngineController::reconfigPacks(
|
|||
}
|
||||
} else {
|
||||
auto level = controller->getLevel();
|
||||
auto world = level->getWorld();
|
||||
auto& world = level->getWorld();
|
||||
controller->processBeforeQuit();
|
||||
controller->saveWorld();
|
||||
|
||||
auto names = PacksManager::getNames(world->getPacks());
|
||||
auto names = PacksManager::getNames(world.getPacks());
|
||||
auto& manager = contentControl.scan();
|
||||
reconfig_packs_inside(manager, names, packsToAdd, packsToRemove);
|
||||
|
||||
const auto& settings = engine.getSettings();
|
||||
auto& wfile = *world->wfile;
|
||||
auto& wfile = *world.wfile;
|
||||
if (!settings.debug.generatorTestMode.get()) {
|
||||
wfile.removeIndices(packsToRemove);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,5 +41,5 @@ public:
|
|||
|
||||
void setLocalPlayer(int64_t player);
|
||||
|
||||
void reopenWorld(World* world);
|
||||
void reopenWorld(World& world);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -141,16 +141,16 @@ void LevelController::processBeforeQuit() {
|
|||
}
|
||||
|
||||
void LevelController::saveWorld() {
|
||||
auto world = level->getWorld();
|
||||
if (world->isNameless()) {
|
||||
auto& world = level->getWorld();
|
||||
if (world.isNameless()) {
|
||||
logger.info() << "nameless world will not be saved";
|
||||
return;
|
||||
}
|
||||
logger.info() << "writing world '" << world->getName() << "'";
|
||||
world->wfile->createDirectories();
|
||||
logger.info() << "writing world '" << world.getName() << "'";
|
||||
world.wfile->createDirectories();
|
||||
scripting::on_world_save();
|
||||
level->onSave();
|
||||
level->getWorld()->write(*level);
|
||||
level->getWorld().write(*level);
|
||||
}
|
||||
|
||||
void LevelController::onWorldQuit() {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ static Level& require_level() {
|
|||
}
|
||||
|
||||
static WorldInfo& require_world_info() {
|
||||
return require_level().getWorld()->getInfo();
|
||||
return require_level().getWorld().getInfo();
|
||||
}
|
||||
|
||||
static int l_is_open(lua::State* L) {
|
||||
|
|
@ -136,7 +136,7 @@ static int l_get_chunk_data(lua::State* L) {
|
|||
auto voxelData = std::make_unique<ubyte[]>(CHUNK_DATA_LEN);
|
||||
std::vector<ubyte> chunkData;
|
||||
if (chunk == nullptr) {
|
||||
auto& regions = level->getWorld()->wfile->getRegions();
|
||||
auto& regions = level->getWorld().wfile->getRegions();
|
||||
if (!regions.getVoxels(x, z, voxelData.get())) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -215,7 +215,7 @@ static int l_save_chunk_data(lua::State* L) {
|
|||
reinterpret_cast<const ubyte*>(buffer.data()),
|
||||
reinterpret_cast<const ubyte*>(buffer.data()) + buffer.size()
|
||||
),
|
||||
level->getWorld()->wfile->getRegions()
|
||||
level->getWorld().wfile->getRegions()
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ void scripting::on_world_load(LevelController* controller) {
|
|||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldopen", [](auto L) {
|
||||
return lua::pushboolean(
|
||||
L, !scripting::level->getWorld()->getInfo().isLoaded
|
||||
L, !scripting::level->getWorld().getInfo().isLoaded
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ Player* Players::getNearest(const glm::vec3& position) const {
|
|||
}
|
||||
|
||||
Player* Players::create(int64_t id) {
|
||||
int64_t& nextPlayerID = level.getWorld()->getInfo().nextPlayerId;
|
||||
int64_t& nextPlayerID = level.getWorld().getInfo().nextPlayerId;
|
||||
if (id == NONE) {
|
||||
id = nextPlayerID++;
|
||||
} else {
|
||||
|
|
@ -146,7 +146,7 @@ void Players::deserialize(const dv::value& src) {
|
|||
auto& inventory = player->getInventory();
|
||||
// invalid inventory id pre 0.25
|
||||
if (inventory->getId() == 0) {
|
||||
inventory->setId(level.getWorld()->getNextInventoryId());
|
||||
inventory->setId(level.getWorld().getNextInventoryId());
|
||||
}
|
||||
level.inventories->store(inventory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ std::shared_ptr<Chunk> GlobalChunks::create(int x, int z, bool lighting) {
|
|||
chunks_pool.create(x, z, lighting ? lightmaps_pool.create() : nullptr);
|
||||
chunksMap[keyfrom(x, z)] = chunk;
|
||||
|
||||
World& world = *level.getWorld();
|
||||
World& world = level.getWorld();
|
||||
auto& regions = world.wfile.get()->getRegions();
|
||||
|
||||
if (regions.getVoxels(chunk->x, chunk->z, voxelDataBuffer.get())) {
|
||||
|
|
@ -197,7 +197,7 @@ void GlobalChunks::save(Chunk* chunk) {
|
|||
if (!entities.empty()) {
|
||||
chunk->flags.entities = true;
|
||||
}
|
||||
level.getWorld()->wfile->getRegions().put(
|
||||
level.getWorld().wfile->getRegions().put(
|
||||
chunk,
|
||||
chunk->flags.entities ? json::to_binary(root, true)
|
||||
: std::vector<ubyte>()
|
||||
|
|
|
|||
|
|
@ -71,12 +71,12 @@ Level::Level(
|
|||
|
||||
Level::~Level() = default;
|
||||
|
||||
World* Level::getWorld() {
|
||||
return world.get();
|
||||
World& Level::getWorld() {
|
||||
return *world;
|
||||
}
|
||||
|
||||
const World* Level::getWorld() const {
|
||||
return world.get();
|
||||
const World& Level::getWorld() const {
|
||||
return *world;
|
||||
}
|
||||
|
||||
void Level::onSave() {
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ public:
|
|||
);
|
||||
~Level();
|
||||
|
||||
World* getWorld();
|
||||
World& getWorld();
|
||||
|
||||
const World* getWorld() const;
|
||||
const World& getWorld() const;
|
||||
|
||||
void onSave();
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ std::unique_ptr<Level> World::load(
|
|||
|
||||
if (!playerRoot["players"].empty()) {
|
||||
if (!playerRoot["players"][0].has("id")) {
|
||||
level->getWorld()->getInfo().nextPlayerId++;
|
||||
level->getWorld().getInfo().nextPlayerId++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ public:
|
|||
const std::vector<ContentPack>& packs
|
||||
);
|
||||
|
||||
World(const World&) = delete;
|
||||
|
||||
~World();
|
||||
|
||||
/// @brief Update world day-time and total time
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue