Skip to content

Commit

Permalink
Renderer|Gloom: Brute force plane heights update
Browse files Browse the repository at this point in the history
To see if this works at all, update all plane heights every frame.
Next up: only update what is changing.
  • Loading branch information
skyjake committed Feb 11, 2020
1 parent af2c3dc commit 3b8bdeb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/render/classicworldrenderer.h
Expand Up @@ -38,6 +38,8 @@ class ClassicWorldRenderer : public IWorldRenderer

void glInit() override;
void glDeinit() override;
void loadMap(const de::String &mapId) override;
void unloadMap() override;
void setCamera() override;

void advanceTime(de::TimeSpan elapsed) override;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/client/include/render/gloomworldrenderer.h
Expand Up @@ -32,7 +32,8 @@ class GloomWorldRenderer : public IWorldRenderer
void glDeinit() override;
void setCamera() override;

void loadMap(const de::String &mapId);
void loadMap(const de::String &mapId) override;
void unloadMap() override;

void advanceTime(de::TimeSpan elapsed) override;
void renderPlayerView(int num) override;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/render/iworldrenderer.h
Expand Up @@ -36,6 +36,8 @@ class IWorldRenderer
virtual void glInit() = 0;
virtual void glDeinit() = 0;

virtual void loadMap(const de::String &mapId) = 0;
virtual void unloadMap() = 0;
virtual void setCamera() = 0;

virtual void advanceTime(de::TimeSpan elapsed) = 0;
Expand Down
8 changes: 8 additions & 0 deletions doomsday/apps/client/src/render/classicworldrenderer.cpp
Expand Up @@ -18,7 +18,15 @@

#include "render/classicworldrenderer.h"

using namespace de;

ClassicWorldRenderer::ClassicWorldRenderer()
{}

void ClassicWorldRenderer::loadMap(const String &/*mapId*/)
{}

void ClassicWorldRenderer::unloadMap()
{}

// other methods elsewhere...
45 changes: 45 additions & 0 deletions doomsday/apps/client/src/render/gloomworldrenderer.cpp
Expand Up @@ -22,10 +22,15 @@
#include "world/p_players.h"
#include "clientapp.h"

#include <doomsday/world/map.h>
#include <doomsday/world/sector.h>
#include <doomsday/world/world.h>
#include <gloom/world.h>
#include <gloom/world/map.h>
#include <gloom/render/icamera.h>
#include <de/ImageBank>
#include <de/FS>
#include <de/data/json.h>

using namespace de;

Expand Down Expand Up @@ -81,6 +86,7 @@ DE_PIMPL(GloomWorldRenderer)

PlayerCamera playerCamera;
std::unique_ptr<gloom::World> glWorld;
List<gloom::ID> sectorLut; // sector number => gloom ID
ImageBank images;

Impl(Public *i) : Base(i)
Expand Down Expand Up @@ -111,12 +117,51 @@ void GloomWorldRenderer::setCamera()
void GloomWorldRenderer::loadMap(const String &mapId)
{
d->glWorld->loadMap(mapId);

// Read the lookup tables.
{
const auto & asset = App::asset("map." + mapId);
const Record lut =
parseJSON(String::fromUtf8(FS::locate<const File>(asset.absolutePath("lookupPath"))));

const auto &sectorIds = lut["sectorIds"].array();
d->sectorLut.resize(sectorIds.size());
auto i = d->sectorLut.begin();
for (const auto *value : sectorIds.elements())
{
*i++ = value->asUInt();
}
}
}

void GloomWorldRenderer::unloadMap()
{
d->sectorLut.clear();
}

void GloomWorldRenderer::advanceTime(TimeSpan elapsed)
{
if (d->glWorld)
{
// Update changed plane heights.
if (world::World::get().hasMap() && !d->sectorLut.isEmpty())
{
const auto &map = world::World::get().map();
const auto &glMap = d->glWorld->map();
for (int sectorIndex = 0; sectorIndex < map.sectorCount(); ++sectorIndex)
{
const auto & sector = map.sector(sectorIndex);
const gloom::ID sectorId = d->sectorLut[sectorIndex];
const gloom::ID floorId = glMap.floorPlaneId(sectorId);
const gloom::ID ceilingId = glMap.ceilingPlaneId(sectorId);

d->glWorld->setPlaneY(floorId, sector.floor().height());
d->glWorld->setPlaneY(ceilingId, sector.ceiling().height());

// TODO: Pass the target height and speed to glWorld and let the shaders update
// the heights on the GPU. Only update the plane heights buffer when a move begins.
}
}
d->glWorld->update(elapsed);
}
}
Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/client/src/world/gloomworld.cpp
Expand Up @@ -58,6 +58,7 @@ String GloomWorld::mapPackageId() const

void GloomWorld::aboutToChangeMap()
{
ClientApp::render().world().unloadMap();
PackageLoader::get().unload(mapPackageId());
d->exportedPath.clear();
}
Expand Down Expand Up @@ -95,6 +96,6 @@ void GloomWorld::mapFinalized()
// We are likely in a busy thread now, so we shouldn't do GL operations.
// Load the map in the main thread instead.
Loop::mainCall([mapId]() {
static_cast<GloomWorldRenderer &>(ClientApp::render().world()).loadMap(mapId.lower());
ClientApp::render().world().loadMap(mapId.lower());
});
}

0 comments on commit 3b8bdeb

Please sign in to comment.