74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <windows.h>
|
|
|
|
#include "settlement/core/world.hpp"
|
|
#include "voxel_scene.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <span>
|
|
#include <vector>
|
|
|
|
namespace settlement::viewer {
|
|
|
|
enum class BuildingView { Full, NoRoofs, FloorsOnly };
|
|
|
|
struct BlueprintPart {
|
|
GridPosition cell;
|
|
RecipeId recipe;
|
|
BedBase base = BedBase::Wood;
|
|
};
|
|
|
|
struct SceneView {
|
|
int width;
|
|
int height;
|
|
float origin_x;
|
|
float origin_y;
|
|
float scale;
|
|
float tile_half_width;
|
|
float tile_half_height;
|
|
std::optional<GridPosition> cursor;
|
|
bool valid_cursor;
|
|
std::optional<GridPosition> move_source;
|
|
std::optional<AgentId> selected;
|
|
std::span<const BlueprintPart> blueprint;
|
|
std::optional<BlueprintPart> preview;
|
|
std::span<const RoomPlan> room_blueprints;
|
|
std::optional<RoomPlan> room_preview;
|
|
BuildingView building_view = BuildingView::Full;
|
|
std::optional<std::size_t> moving_room;
|
|
};
|
|
|
|
// Immutable CPU geometry can outlive the latest frame and any GPU backend.
|
|
class PreparedGeometry;
|
|
|
|
class D3DScene {
|
|
public:
|
|
D3DScene();
|
|
~D3DScene();
|
|
D3DScene(const D3DScene&) = delete;
|
|
D3DScene& operator=(const D3DScene&) = delete;
|
|
bool initialize(HWND target, bool software = false);
|
|
[[nodiscard]] bool ready() const noexcept;
|
|
bool render(const World& world, const SceneView& view, std::vector<std::uint32_t>* capture = nullptr);
|
|
[[nodiscard]] static std::shared_ptr<const PreparedGeometry> prepare(const World& world, const SceneView& view);
|
|
bool render(std::shared_ptr<const PreparedGeometry> geometry, const SceneView& view,
|
|
std::vector<std::uint32_t>* capture = nullptr);
|
|
[[nodiscard]] static std::expected<std::shared_ptr<const PreparedGeometry>, VoxelSceneError>
|
|
prepare_voxels(std::shared_ptr<const VoxelScene> scene);
|
|
bool render(std::shared_ptr<const PreparedGeometry> geometry, const VoxelCamera& view,
|
|
std::vector<std::uint32_t>* capture = nullptr);
|
|
[[nodiscard]] std::uint64_t uploads() const noexcept { return uploads_; }
|
|
[[nodiscard]] std::uint64_t frames() const noexcept { return frames_; }
|
|
void reset() noexcept;
|
|
|
|
private:
|
|
std::uint64_t uploads_ = 0, frames_ = 0;
|
|
struct Backend;
|
|
std::shared_ptr<Backend> backend_;
|
|
};
|
|
|
|
} // namespace settlement::viewer
|