SHAPETOOL: render the world
parent
e594749c30
commit
43ce398b14
|
@ -158,7 +158,6 @@ void Client::afterUI() {
|
|||
|
||||
core::AppState Client::onCleanup() {
|
||||
core::AppState state = UIApp::onCleanup();
|
||||
// TODO: destroy the gl buffers
|
||||
_world->destroy();
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
namespace frontend {
|
||||
|
||||
// TODO: destroy the gl buffers
|
||||
|
||||
WorldRenderer::WorldRenderer(const voxel::WorldPtr& world) :
|
||||
_world(world) {
|
||||
}
|
||||
|
|
|
@ -130,12 +130,12 @@ void World::calculateAO(const PolyVox::Region& region) {
|
|||
// Extract the surface for the specified region of the volume.
|
||||
// The surface extractor outputs the mesh in an efficient compressed format which
|
||||
// is not directly suitable for rendering.
|
||||
void World::scheduleMeshExtraction(const glm::ivec2& p) {
|
||||
bool World::scheduleMeshExtraction(const glm::ivec2& p) {
|
||||
const int size = _chunkSize->intVal();
|
||||
const glm::ivec2& pos = getGridPos(p);
|
||||
if (_meshesExtracted.find(pos) != _meshesExtracted.end()) {
|
||||
Log::trace("mesh is already extracted for %i:%i", p.x, p.y);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
_meshesExtracted.insert(pos);
|
||||
|
||||
|
@ -164,6 +164,7 @@ void World::scheduleMeshExtraction(const glm::ivec2& p) {
|
|||
core::ScopedWriteLock lock(_rwLock);
|
||||
_meshQueue.push_back(std::move(data));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
int World::findFloor(int x, int z) const {
|
||||
|
|
|
@ -93,7 +93,7 @@ public:
|
|||
* @param[in] pos A World vector that is automatically converted into a mesh tile vector
|
||||
* @note This will not allow to reschedule an extraction for the same area until @c allowReExtraction was called.
|
||||
*/
|
||||
void scheduleMeshExtraction(const glm::ivec2& pos);
|
||||
bool scheduleMeshExtraction(const glm::ivec2& pos);
|
||||
|
||||
void onFrame(long dt);
|
||||
|
||||
|
|
|
@ -2,24 +2,76 @@
|
|||
#include "sauce/ShapeToolInjector.h"
|
||||
#include "core/App.h"
|
||||
#include "core/Process.h"
|
||||
#include "voxel/Spiral.h"
|
||||
#include "video/Shader.h"
|
||||
#include "video/Color.h"
|
||||
#include "video/GLDebug.h"
|
||||
|
||||
// tool for testing the world createXXX functions without starting the application
|
||||
ShapeTool::ShapeTool(io::FilesystemPtr filesystem, core::EventBusPtr eventBus) :
|
||||
ui::UIApp(filesystem, eventBus) {
|
||||
ShapeTool::ShapeTool(io::FilesystemPtr filesystem, core::EventBusPtr eventBus, voxel::WorldPtr world) :
|
||||
ui::UIApp(filesystem, eventBus), _worldRenderer(world), _world(world) {
|
||||
init("engine", "shapetool");
|
||||
}
|
||||
|
||||
ShapeTool::~ShapeTool() {
|
||||
}
|
||||
|
||||
core::AppState ShapeTool::onInit() {
|
||||
GLDebug::enable(GLDebug::Medium);
|
||||
|
||||
if (!_worldShader.init()) {
|
||||
return core::Cleanup;
|
||||
}
|
||||
|
||||
_world->setSeed(1);
|
||||
_worldRenderer.onInit();
|
||||
_camera.init(_width, _height);
|
||||
_camera.setAngles(-M_PI_2, M_PI);
|
||||
_camera.setPosition(glm::vec3(0.0f, 100.0f, 0.0f));
|
||||
|
||||
_clearColor = video::Color::LightBlue;
|
||||
|
||||
// TODO: replace this with a scripting interface for the World::create* functions
|
||||
voxel::Spiral o;
|
||||
const int chunkSize = _world->getChunkSize();
|
||||
glm::ivec2 pos(chunkSize / 2, chunkSize / 2);
|
||||
_world->scheduleMeshExtraction(pos);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
o.next();
|
||||
glm::ivec2 opos(pos.x + o.x() * chunkSize, pos.x + o.y() * chunkSize);
|
||||
_world->scheduleMeshExtraction(opos);
|
||||
}
|
||||
|
||||
return ui::UIApp::onInit();
|
||||
}
|
||||
|
||||
core::AppState ShapeTool::onRunning() {
|
||||
core::AppState state = UIApp::onRunning();
|
||||
|
||||
_world->onFrame(_deltaFrame);
|
||||
|
||||
_camera.updatePosition(_deltaFrame, false, false, false, false);
|
||||
_camera.updateViewMatrix();
|
||||
|
||||
_worldRenderer.onRunning(_now);
|
||||
|
||||
const glm::mat4& view = _camera.getViewMatrix();
|
||||
_worldRenderer.renderWorld(_worldShader, view, _aspect);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
core::AppState ShapeTool::onCleanup() {
|
||||
core::AppState state = UIApp::onCleanup();
|
||||
_world->destroy();
|
||||
return state;
|
||||
}
|
||||
|
||||
void ShapeTool::onMouseMotion(int32_t x, int32_t y, int32_t relX, int32_t relY) {
|
||||
UIApp::onMouseMotion(x, y, relX, relY);
|
||||
_camera.onMotion(x, y, relX, relY);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
return getInjector()->get<ShapeTool>()->startMainLoop(argc, argv);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "ui/UIApp.h"
|
||||
#include "frontend/WorldShader.h"
|
||||
#include "frontend/WorldRenderer.h"
|
||||
#include "video/Camera.h"
|
||||
|
||||
class ShapeTool: public ui::UIApp {
|
||||
protected:
|
||||
video::Camera _camera;
|
||||
frontend::WorldRenderer _worldRenderer;
|
||||
voxel::WorldPtr _world;
|
||||
frontend::WorldShader _worldShader;
|
||||
|
||||
void onMouseMotion(int32_t x, int32_t y, int32_t relX, int32_t relY) override;
|
||||
|
||||
public:
|
||||
ShapeTool(io::FilesystemPtr filesystem, core::EventBusPtr eventBus);
|
||||
ShapeTool(io::FilesystemPtr filesystem, core::EventBusPtr eventBus, voxel::WorldPtr world);
|
||||
~ShapeTool();
|
||||
|
||||
core::AppState onInit() override;
|
||||
core::AppState onRunning() override;
|
||||
core::AppState onCleanup() override;
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
class ShapeToolModule: public core::AbstractModule {
|
||||
void configure() const override {
|
||||
core::AbstractModule::configure();
|
||||
bind<ShapeTool>().in<sauce::SingletonScope>().to<ShapeTool(io::Filesystem &, core::EventBus &)>();
|
||||
bind<ShapeTool>().in<sauce::SingletonScope>().to<ShapeTool(io::Filesystem &, core::EventBus &, voxel::World &)>();
|
||||
bind<voxel::World>().in<sauce::SingletonScope>().to<voxel::World>();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue