Skip to content

Commit

Permalink
rename terrain -> heightmap in engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Feb 13, 2024
1 parent c8adf8b commit 26cf8c2
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 116 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
138 changes: 67 additions & 71 deletions engine/src/drawables/terrain.rs → engine/src/drawables/heightmap.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion engine/src/drawables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod instanced_mesh;
mod lit_mesh;
mod multispritebatch;
mod spritebatch;
pub mod terrain;
pub mod heightmap;
mod water;

pub use instanced_mesh::*;
Expand Down
34 changes: 17 additions & 17 deletions engine/src/perf_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub struct PerfCounters {
shadows_triangles: AtomicUsize,
shadows_drawcalls: AtomicUsize,

terrain_triangles: AtomicUsize,
terrain_depth_triangles: AtomicUsize,
terrain_shadows_triangles: AtomicUsize,
heightmap_triangles: AtomicUsize,
heightmap_depth_triangles: AtomicUsize,
heightmap_shadows_triangles: AtomicUsize,
}

pub struct PerfCountersStatic {
Expand All @@ -26,9 +26,9 @@ pub struct PerfCountersStatic {
pub shadows_triangles: usize,
pub shadows_drawcalls: usize,

pub terrain_triangles: usize,
pub terrain_depth_triangles: usize,
pub terrain_shadows_triangles: usize,
pub heightmap_triangles: usize,
pub heightmap_depth_triangles: usize,
pub heightmap_shadows_triangles: usize,
}

impl PerfCounters {
Expand All @@ -44,9 +44,9 @@ impl PerfCounters {
depth_drawcalls: *self.depth_drawcalls.get_mut(),
shadows_triangles: *self.shadows_triangles.get_mut(),
shadows_drawcalls: *self.shadows_drawcalls.get_mut(),
terrain_triangles: *self.terrain_triangles.get_mut(),
terrain_depth_triangles: *self.terrain_depth_triangles.get_mut(),
terrain_shadows_triangles: *self.terrain_shadows_triangles.get_mut(),
heightmap_triangles: *self.heightmap_triangles.get_mut(),
heightmap_depth_triangles: *self.heightmap_depth_triangles.get_mut(),
heightmap_shadows_triangles: *self.heightmap_shadows_triangles.get_mut(),
}
}

Expand All @@ -57,9 +57,9 @@ impl PerfCounters {
*self.depth_drawcalls.get_mut() = 0;
*self.shadows_triangles.get_mut() = 0;
*self.shadows_drawcalls.get_mut() = 0;
*self.terrain_triangles.get_mut() = 0;
*self.terrain_depth_triangles.get_mut() = 0;
*self.terrain_shadows_triangles.get_mut() = 0;
*self.heightmap_triangles.get_mut() = 0;
*self.heightmap_depth_triangles.get_mut() = 0;
*self.heightmap_shadows_triangles.get_mut() = 0;
}

pub fn drawcall(&self, triangles: impl TryInto<usize>) {
Expand Down Expand Up @@ -89,22 +89,22 @@ impl PerfCounters {
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
}

pub fn terrain_drawcall(&self, triangles: impl TryInto<usize>) {
self.terrain_triangles.fetch_add(
pub fn heightmap_drawcall(&self, triangles: impl TryInto<usize>) {
self.heightmap_triangles.fetch_add(
triangles.try_into().unwrap_or(0),
std::sync::atomic::Ordering::Relaxed,
);
}

pub fn terrain_depth_drawcall(&self, triangles: impl TryInto<usize>, shadows: bool) {
pub fn heightmap_depth_drawcall(&self, triangles: impl TryInto<usize>, shadows: bool) {
if shadows {
self.terrain_shadows_triangles.fetch_add(
self.heightmap_shadows_triangles.fetch_add(
triangles.try_into().unwrap_or(0),
std::sync::atomic::Ordering::Relaxed,
);
return;
}
self.terrain_depth_triangles.fetch_add(
self.heightmap_depth_triangles.fetch_add(
triangles.try_into().unwrap_or(0),
std::sync::atomic::Ordering::Relaxed,
);
Expand Down
20 changes: 10 additions & 10 deletions engine_demo/src/terrain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use engine::terrain::TerrainRender as EngineTerrainRender;
use engine::heightmap::HeightmapRender;
use engine::{Context, FrameContext, InstancedMeshBuilder, MeshInstance};
use geom::{pack_height, vec2, Camera, Heightmap, HeightmapChunk, LinearColor, Vec3};

Expand All @@ -9,7 +9,7 @@ const CRESO: usize = 16;
const MAP_SIZE: usize = 50;

pub struct Terrain {
terrain: EngineTerrainRender<CSIZE, CRESO>,
heightmap: HeightmapRender<CSIZE, CRESO>,
heights: Heightmap<CRESO, { CSIZE }>,
reload: bool,

Expand Down Expand Up @@ -52,22 +52,22 @@ impl DemoElement for Terrain {
}
}

let mut terrain = EngineTerrainRender::new(gfx, MAP_SIZE as u32, MAP_SIZE as u32);
let mut heightmap = HeightmapRender::new(gfx, MAP_SIZE as u32, MAP_SIZE as u32);

for x in 0..MAP_SIZE {
for y in 0..MAP_SIZE {
terrain.update_chunk(
heightmap.update_chunk(
gfx,
(x as u32, y as u32),
h.get_chunk((x as u16, y as u16)).unwrap(),
);
}
}

terrain.invalidate_height_normals(&ctx.gfx);
heightmap.invalidate_height_normals(&ctx.gfx);

Self {
terrain,
heightmap,
heights: h,
reload: false,
last_hitpos: None,
Expand All @@ -79,7 +79,7 @@ impl DemoElement for Terrain {
fn update(&mut self, ctx: &mut Context, cam: &Camera) {
if self.reload {
self.reload = false;
self.terrain.invalidate_height_normals(&ctx.gfx);
self.heightmap.invalidate_height_normals(&ctx.gfx);
}

self.last_hitpos = None;
Expand All @@ -98,7 +98,7 @@ impl DemoElement for Terrain {
}

fn render(&mut self, fc: &mut FrameContext, cam: &Camera) {
self.terrain.draw_terrain(cam, fc);
self.heightmap.draw_heightmap(cam, fc);

self.hitmesh.instances.clear();
if let Some(pos) = self.last_hitpos {
Expand All @@ -120,8 +120,8 @@ impl DemoElement for Terrain {
}

fn render_gui(&mut self, ui: &mut egui::Ui) {
ui.indent("terrain", |ui| {
if cfg!(debug_assertions) && ui.button("reload terrain").clicked() {
ui.indent("heightmap", |ui| {
if cfg!(debug_assertions) && ui.button("reload heightmap").clicked() {
self.reload = true;
}
});
Expand Down
4 changes: 2 additions & 2 deletions geom/src/heightmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ mod erosion {
// 0..1
const INERTIA: f32 = 0.1; // At zero, water will instantly change direction to flow downhill. At 1, water will never change direction.
const SEDIMENT_CAPACITY_FACTOR: f32 = 1.0; // Multiplier for how much sediment a droplet can carry
const MIN_SEDIMENT_CAPACITY: f32 = 0.003; // Used to prevent carry capacity getting too close to zero on flatter terrain
const MIN_SEDIMENT_CAPACITY: f32 = 0.003; // Used to prevent carry capacity getting too close to zero on flatter heightmap

// 0..1
const ERODE_SPEED: f32 = 0.3;
Expand Down Expand Up @@ -796,7 +796,7 @@ mod erosion {
}
} else {
// Erode a fraction of the droplet's current carry capacity.
// Clamp the erosion to the change in height so that it doesn't dig a hole in the terrain behind the droplet
// Clamp the erosion to the change in height so that it doesn't dig a hole in the heightmap behind the droplet
let amount_to_erode =
f32::min((sediment_capacity - sediment) * ERODE_SPEED, -delta_height);

Expand Down
12 changes: 6 additions & 6 deletions native_app/src/gui/windows/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ pub fn debug(window: egui::Window<'_>, ui: &egui::Context, uiworld: &UiWorld, si
));
ui.add_space(5.0);
ui.label(format!(
"{}k terrain triangles",
counters.terrain_triangles / 1000
"{}k heightmap triangles",
counters.heightmap_triangles / 1000
));
ui.label(format!(
"{}k terrain depth triangles",
counters.terrain_depth_triangles / 1000
"{}k heightmap depth triangles",
counters.heightmap_depth_triangles / 1000
));
ui.label(format!(
"{}k terrain shadow triangles",
counters.terrain_shadows_triangles / 1000
"{}k heightmap shadow triangles",
counters.heightmap_shadows_triangles / 1000
));
drop(counters);

Expand Down
18 changes: 9 additions & 9 deletions native_app/src/rendering/map_rendering/terrain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use engine::terrain::TerrainRender as EngineTerrainRender;
use engine::heightmap::HeightmapRender;
use engine::{Context, FrameContext, GfxContext};
use geom::Camera;
use simulation::map::{Map, MapSubscriber, UpdateType};
Expand All @@ -8,39 +8,39 @@ const CSIZE: u32 = simulation::map::Heightmap::SIZE;
const CRESO: usize = simulation::map::Heightmap::RESOLUTION;

pub struct TerrainRender {
terrain: EngineTerrainRender<CSIZE, CRESO>,
heightmap: HeightmapRender<CSIZE, CRESO>,
terrain_sub: MapSubscriber,
}

impl TerrainRender {
pub fn new(gfx: &mut GfxContext, sim: &Simulation) -> Self {
let (w, h) = sim.map().environment.size();

let terrain = EngineTerrainRender::new(gfx, w as u32, h as u32);
let terrain = HeightmapRender::new(gfx, w as u32, h as u32);

Self {
terrain,
heightmap: terrain,
terrain_sub: sim.map().subscribe(UpdateType::Terrain),
}
}

pub fn draw(&mut self, cam: &Camera, fctx: &mut FrameContext<'_>) {
self.terrain.draw_terrain(cam, fctx);
self.heightmap.draw_heightmap(cam, fctx);
}

pub fn update(&mut self, ctx: &mut Context, map: &Map) {
let ter = &map.environment;

if self.terrain_sub.take_cleared() {
for (chunk_id, chunk) in ter.chunks() {
self.terrain.update_chunk(
self.heightmap.update_chunk(
&mut ctx.gfx,
(chunk_id.0 as u32, chunk_id.1 as u32),
chunk,
);
}

self.terrain.invalidate_height_normals(&ctx.gfx);
self.heightmap.invalidate_height_normals(&ctx.gfx);
return;
}

Expand All @@ -50,7 +50,7 @@ impl TerrainRender {
let chunk =
unwrap_retlog!(ter.get_chunk(chunkid), "trying to update nonexistent chunk");

self.terrain.update_chunk(
self.heightmap.update_chunk(
&mut ctx.gfx,
(chunkid.0 as u32, chunkid.1 as u32),
chunk,
Expand All @@ -60,7 +60,7 @@ impl TerrainRender {
}

if changed {
self.terrain.invalidate_height_normals(&ctx.gfx);
self.heightmap.invalidate_height_normals(&ctx.gfx);
}
}
}

0 comments on commit 26cf8c2

Please sign in to comment.