- BillboardInstance: per-instance uv sub-rect, feet anchor, turn, dithered alpha, flash; BillboardBatch::sharedTexture; Texture createEmpty/update/cellUV/cellAnchor/nearest - SpriteAtlas: fixed-cell runtime atlas with gutters - hd2d::ui: Octopath-style panels, fonts (Cinzel, EB Garamond), dialogue box with typewriter + portraits + choices, menus, nameplates, toasts, ImGui theme - DayCycle (dawn/day/dusk/night keyframes, sun + moon arcs), Weather overcast/mist/ lightning, night-aware presets, stars and moon in the sky - Hidden-window offscreen captures (Window visible=false, Renderer output FBO, OffscreenTarget); --screenshot never opens a window - Camera::worldToScreen; CMake usable via add_subdirectory (HD2D_BUILD_DEMO, HD2D_ENGINE_ASSET_DIR)
70 lines
2.6 KiB
C++
70 lines
2.6 KiB
C++
#pragma once
|
|
#include "hd2d/Camera.h"
|
|
#include "hd2d/Scene.h"
|
|
#include "hd2d/SpriteAtlas.h"
|
|
#include "hd2d/Weather.h"
|
|
|
|
#include <array>
|
|
#include <random>
|
|
#include <string>
|
|
#include <vector>
|
|
// Meadow diorama: terraced grass, a cliff ridge with steps, a pond crossed by
|
|
// a stone bridge with burning braziers, 3D trees/bushes/rocks, weather and a
|
|
// WASD-controlled pixel-art player sprite.
|
|
class DemoScene {
|
|
public:
|
|
bool load(const std::string& assetDir);
|
|
// `move`: x = screen right, y = screen up (camera-relative), length <= 1.
|
|
void update(float dt, float time, glm::vec2 move, const hd2d::Camera& camera);
|
|
void placePlayer(glm::vec2 xz);
|
|
|
|
hd2d::Scene scene;
|
|
glm::vec3 playerPos{0.0f};
|
|
hd2d::Weather weather; // call weather.update() each frame before rendering
|
|
|
|
// Billboard feature test (`--sprite-test`; set before load()): a row of
|
|
// atlas / sprite-sheet sprites behind the player exercising sub-rect
|
|
// frames, flip, turn, alpha dither and flash. Labels are world-space
|
|
// points (sprite tops) for the caller to draw.
|
|
bool spriteTest = false;
|
|
struct Label {
|
|
glm::vec3 pos;
|
|
const char* text;
|
|
};
|
|
std::vector<Label> labels;
|
|
|
|
private:
|
|
struct Obstacle {
|
|
glm::vec2 pos;
|
|
float radius;
|
|
};
|
|
bool buildSpriteTest(const std::string& assetDir);
|
|
void updateSpriteTest(float time, const hd2d::Camera& camera);
|
|
void buildTerrain();
|
|
void scatterProps();
|
|
bool walkable(glm::vec2 from, glm::vec2 to) const;
|
|
bool occupied(glm::vec2 p, float r) const;
|
|
float groundHeight(glm::vec2 p) const; // terrain or bridge deck
|
|
|
|
hd2d::Terrain terrain_;
|
|
hd2d::Water water_;
|
|
hd2d::ParticleSystem particles_;
|
|
hd2d::BillboardBatch tallGrass_, tufts_, flowers_, player_; // pixel-art sprites
|
|
hd2d::ModelLibrary models_; // 3D scenery
|
|
std::array<hd2d::ModelBatch, 2> oaks_, pines_, bushes_, rocks_; // two model variants each
|
|
hd2d::ModelBatch bridge_;
|
|
hd2d::GroundOcclusion groundAO_;
|
|
std::vector<Obstacle> obstacles_;
|
|
std::vector<unsigned char> tallGrassMask_;
|
|
std::mt19937 rng_{42};
|
|
float playerSpeed_ = 4.2f;
|
|
float walkPhase_ = 0.0f;
|
|
hd2d::SpriteAtlas atlas_; // sprite test: runtime-packed cells
|
|
hd2d::BillboardBatch atlasSprites_; // uses atlas_.texture() via sharedTexture
|
|
hd2d::BillboardBatch sheetSprites_; // own texture: a 2x1 sheet read with Texture::cellUV
|
|
int atlasSlots_[3] = {-1, -1, -1}; // hero, flowers, tuft
|
|
int sheetFeetRows_[2] = {0, 0}; // per sheet cell, from the cell top
|
|
float stepTimer_ = 0.0f;
|
|
float facing_ = 0.0f;
|
|
};
|