Skip to content

Commit

Permalink
Fix editor crash
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKsr committed Jul 9, 2020
1 parent 9601140 commit eb9a758
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/game/systems/editor_system.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <entt/entt.hpp>
#include "core/vs_debug_draw.h"
#include "game/components/inputs.h"
#include "game/components/ui_context.h"
#include "game/components/world_context.h"
Expand Down Expand Up @@ -32,7 +33,7 @@ void updateEditorSystem(entt::registry& mainRegistry)
else if (inputs.middleButtonState == InputState::JustUp)
{
worldContext.world->getChunkManager()->setBlock(
mouseLocation - 0.05F * inputs.mousTrace.hitNormal, 0);
mouseLocation - 0.05F * inputs.mouseTrace.hitNormal, 0);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions include/game/systems/menu_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,10 @@ void updateMenuSystem(entt::registry& mainRegistry)
uiContext.minimap.bShouldUpdate = true;
}
}

if (uiContext.bShouldResetEditor && !world->getChunkManager()->shouldReinitializeChunks())
{
uiContext.bShouldResetEditor = false;
VSTerrainGeneration::buildEditorPlane(world);
}
}
1 change: 1 addition & 0 deletions include/world/generator/vs_terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace VSTerrainGeneration
void buildDesert(VSWorld* world);
void buildMountains(VSWorld* world);
void buildStandard(VSWorld* world);
void buildEditorPlane(VSWorld* world);

void treeAt(VSWorld* world, int x, int y, int z);
void cactusAt(VSWorld* world, int x, int y, int z);
Expand Down
6 changes: 4 additions & 2 deletions source/game/voxelscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "game/systems/placement_system.h"
#include "game/systems/resource_system.h"
#include "game/systems/minimap_system.h"
#include "game/systems/editor_system.h"

#include "game/building_loader.h"

Expand Down Expand Up @@ -48,7 +49,7 @@ void Voxelscape::initializeGame(VSApp* inApp)
inApp->addWorld(uiContext.gameWorldName, gameWorld);

VSWorld* editorWorld = new VSWorld();
editorWorld->getCamera()->setPosition(glm::vec3(-50.F, -5.F, -50.F));
editorWorld->getCamera()->setPosition(glm::vec3(-50.F, 50.F, -50.F));
editorWorld->getCamera()->setPitchYaw(-10.F, 45.F);
inApp->addWorld(uiContext.editorWorldName, editorWorld);

Expand Down Expand Up @@ -114,7 +115,8 @@ void Voxelscape::update(float deltaSeconds)
}
else if (getApp()->getWorldName() == uiContext.editorWorldName)
{
// TODO updateEditorSystem()
updateInputSystem(mainRegistry);
updateEditorSystem(mainRegistry);
}
}

Expand Down
18 changes: 16 additions & 2 deletions source/world/generator/vs_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace VSTerrainGeneration
auto chunkManager = world->getChunkManager();
glm::ivec3 worldSize = chunkManager->getWorldSize();
glm::ivec3 worldSizeHalf = worldSize / 2;
VSHeightmap flatHM =
VSHeightmap(worldSize.y / 4, 3, 0.005F, worldSize.y / 4, 2.F, 0.5F);
VSHeightmap flatHM = VSHeightmap(worldSize.y / 4, 3, 0.005F, worldSize.y / 4, 2.F, 0.5F);
VSHeightmap mountainHM =
VSHeightmap(worldSize.y / 2, 2, 0.02F, worldSize.y / 2, 2.F, 0.125F);

Expand Down Expand Up @@ -186,6 +185,21 @@ namespace VSTerrainGeneration
}
}

void buildEditorPlane(VSWorld* world)
{
auto chunkManager = world->getChunkManager();
glm::ivec3 worldSize = chunkManager->getWorldSize();
glm::ivec3 worldSizeHalf = worldSize / 2;

for (int x = -worldSizeHalf.x; x < worldSizeHalf.x; x++)
{
for (int z = -worldSizeHalf.z; z < worldSizeHalf.z; z++)
{
chunkManager->setBlock({x, 0, z}, 1);
}
}
}

void treeAt(VSWorld* world, int x, int y, int z)
{
auto chunkManager = world->getChunkManager();
Expand Down

0 comments on commit eb9a758

Please sign in to comment.