proper room over room support

This commit is contained in:
KP 2024-08-04 15:22:44 -05:00
parent 602b23a900
commit 1f383c2800
13 changed files with 79 additions and 83 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 KiB

View file

@ -1,70 +1,45 @@
[11:46:03 PM] Info: Starting... [03:20:37 PM] Info: Starting...
KP3D version 2 KP3D version 2
=============================== ===============================
Copyright (C) kpworld.xyz 2018-2024 Copyright (C) kpworld.xyz 2018-2024
Contact me! @kp_cftsz Contact me! @kp_cftsz
[11:46:03 PM] Info: Initializing SDL [03:20:37 PM] Info: Initializing SDL
[11:46:03 PM] Info: Initializing OpenGL [03:20:37 PM] Info: Initializing OpenGL
[11:46:03 PM] Info: OpenGL version: 4.6.0 NVIDIA 536.23 [03:20:37 PM] Info: OpenGL version: 4.6.0 NVIDIA 536.23
[11:46:03 PM] Info: Initializing GLEW [03:20:37 PM] Info: Initializing GLEW
[11:46:03 PM] Info: Initializing SDL_mixer [03:20:37 PM] Info: Initializing SDL_mixer
[11:46:03 PM] Info: Reticulating splines... [03:20:37 PM] Info: Reticulating splines...
[11:46:03 PM] Info: Ready! [03:20:37 PM] Info: Ready!
[11:46:03 PM] Info: Loading script: build-cylinder.scm [03:20:37 PM] Info: Loading script: build-cylinder.scm
[11:46:03 PM] Info: Loading script: build-stairs.scm [03:20:37 PM] Info: Loading script: build-stairs.scm
[11:46:03 PM] Info: Loading material resource: block.png [03:20:37 PM] Info: Loading material resource: block.png
[11:46:03 PM] Info: Found normal map texture: materials/block_n.png [03:20:37 PM] Info: Found normal map texture: materials/block_n.png
[11:46:03 PM] Info: Loading material resource: brick2.jpg [03:20:37 PM] Info: Loading material resource: brick2.jpg
[11:46:03 PM] Info: Found normal map texture: materials/brick2_n.jpg [03:20:37 PM] Info: Found normal map texture: materials/brick2_n.jpg
[11:46:03 PM] Info: Loading material resource: bricks.jpg [03:20:37 PM] Info: Loading material resource: bricks.jpg
[11:46:03 PM] Info: Found normal map texture: materials/bricks_n.jpg [03:20:37 PM] Info: Found normal map texture: materials/bricks_n.jpg
[11:46:03 PM] Info: Loading material resource: FLAT5_7.png [03:20:37 PM] Info: Loading material resource: FLAT5_7.png
[11:46:03 PM] Info: Found normal map texture: materials/FLAT5_7_n.png [03:20:37 PM] Info: Found normal map texture: materials/FLAT5_7_n.png
[11:46:03 PM] Info: Loading material resource: floor0.png [03:20:37 PM] Info: Loading material resource: floor0.png
[11:46:03 PM] Info: Found normal map texture: materials/floor0_n.png [03:20:37 PM] Info: Found normal map texture: materials/floor0_n.png
[11:46:03 PM] Info: Loading material resource: floor1.png [03:20:37 PM] Info: Loading material resource: floor1.png
[11:46:03 PM] Info: Found normal map texture: materials/floor1_n.png [03:20:37 PM] Info: Found normal map texture: materials/floor1_n.png
[11:46:03 PM] Info: Loading material resource: GRASS2.png [03:20:37 PM] Info: Loading material resource: GRASS2.png
[11:46:03 PM] Info: Found normal map texture: materials/GRASS2_n.png [03:20:37 PM] Info: Found normal map texture: materials/GRASS2_n.png
[11:46:03 PM] Info: Loading material resource: hardwood.jpg [03:20:37 PM] Info: Loading material resource: hardwood.jpg
[11:46:03 PM] Info: Found normal map texture: materials/hardwood_n.jpg [03:20:37 PM] Info: Found normal map texture: materials/hardwood_n.jpg
[11:46:03 PM] Info: Map init [03:20:37 PM] Info: Map init
[11:46:03 PM] Info: Finalized mesh with 49 batches [03:20:37 PM] Info: Finalized mesh with 49 batches
[11:46:06 PM] Info: Finalized mesh with 54 batches [03:20:41 PM] Info: Finalized mesh with 54 batches
[11:46:07 PM] Info: Finalized mesh with 48 batches [03:20:56 PM] Info: Finalized mesh with 60 batches
[11:46:08 PM] Info: Finalized mesh with 54 batches [03:21:07 PM] Info: Finalized mesh with 67 batches
[11:46:09 PM] Info: Finalized mesh with 48 batches [03:21:13 PM] Info: Finalized mesh with 75 batches
[11:46:09 PM] Info: Finalized mesh with 54 batches [03:21:19 PM] Info: Finalized mesh with 83 batches
[11:46:09 PM] Info: Finalized mesh with 48 batches [03:21:21 PM] Info: Finalized mesh with 84 batches
[11:46:09 PM] Info: Finalized mesh with 54 batches [03:21:36 PM] Info: Finalized mesh with 91 batches
[11:46:09 PM] Info: Finalized mesh with 48 batches [03:21:37 PM] Info: Finalized mesh with 92 batches
[11:46:09 PM] Info: Finalized mesh with 54 batches [03:21:47 PM] Info: Finalized mesh with 99 batches
[11:46:09 PM] Info: Finalized mesh with 48 batches [03:21:49 PM] Info: Finalized mesh with 107 batches
[11:46:09 PM] Info: Finalized mesh with 54 batches [03:21:49 PM] Info: Finalized mesh with 108 batches
[11:46:10 PM] Info: Finalized mesh with 48 batches
[11:46:10 PM] Info: Finalized mesh with 54 batches
[11:46:10 PM] Info: Finalized mesh with 48 batches
[11:46:10 PM] Info: Finalized mesh with 54 batches
[11:46:10 PM] Info: Finalized mesh with 48 batches
[11:46:10 PM] Info: Finalized mesh with 54 batches
[11:46:10 PM] Info: Finalized mesh with 48 batches
[11:46:10 PM] Info: Finalized mesh with 54 batches
[11:46:11 PM] Info: Finalized mesh with 48 batches
[11:46:12 PM] Info: Finalized mesh with 54 batches
[11:46:12 PM] Info: Finalized mesh with 48 batches
[11:46:14 PM] Info: Finalized mesh with 54 batches
[11:46:14 PM] Info: Finalized mesh with 48 batches
[11:46:15 PM] Info: Finalized mesh with 54 batches
[11:46:15 PM] Info: Finalized mesh with 48 batches
[11:46:15 PM] Info: Finalized mesh with 54 batches
[11:46:15 PM] Info: Finalized mesh with 48 batches
[11:46:16 PM] Info: Finalized mesh with 54 batches
[11:46:16 PM] Info: Finalized mesh with 54 batches
[11:46:17 PM] Info: Finalized mesh with 54 batches
[11:46:17 PM] Info: Finalized mesh with 48 batches
[11:46:17 PM] Info: Finalized mesh with 54 batches
[11:46:18 PM] Info: Finalized mesh with 54 batches
[11:46:19 PM] Info: Finalized mesh with 54 batches
[11:46:19 PM] Info: Finalized mesh with 54 batches

View file

@ -668,6 +668,8 @@ void Map::Rebuild(NormalGenType gen_normals)
Sector& potential_parent = *spp; Sector& potential_parent = *spp;
if (sector.id == potential_parent.id) if (sector.id == potential_parent.id)
continue; continue;
if (sector.floor.base_height >= potential_parent.ceiling.base_height) // room-over-room support
continue;
if (SectorContains(potential_parent, sector)) if (SectorContains(potential_parent, sector))
{ {
potential_parent.children.push_back(&sector); potential_parent.children.push_back(&sector);
@ -878,10 +880,15 @@ void Map::RenderSkybox()
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }
void Map::BuildGrid() void Map::BuildGrid(float y)
{ {
m_grid_shader.Load(".kp3d/map_grid_v.glsl", ".kp3d/map_grid_f.glsl"); m_grid_y = y;
m_grid_texture.Load(".kp3d/map_grid.png", false, kp3d::Texture::FILTER_LINEAR); if (m_grid_texture.GetPath().empty())
{
m_grid_shader.Load(".kp3d/map_grid_v.glsl", ".kp3d/map_grid_f.glsl");
m_grid_texture.Load(".kp3d/map_grid.png", false, kp3d::Texture::FILTER_LINEAR);
}
m_grid_mesh.Reset();
m_grid_mesh.AddBatch(&m_grid_texture, { m_grid_mesh.AddBatch(&m_grid_texture, {
Vertex3D(Vec3(-0.5f, 0.0f, 0.5f), Vec2(0.0f, 1.0f)), Vertex3D(Vec3(-0.5f, 0.0f, 0.5f), Vec2(0.0f, 1.0f)),
Vertex3D(Vec3(-0.5f, 0.0f, -0.5f), Vec2(0.0f, 0.0f)), Vertex3D(Vec3(-0.5f, 0.0f, -0.5f), Vec2(0.0f, 0.0f)),
@ -893,14 +900,18 @@ void Map::BuildGrid()
m_grid_mesh.Finalize(); m_grid_mesh.Finalize();
for (const RenderBatch3D& batch: m_grid_mesh.GetBatchesRef()) for (const RenderBatch3D& batch: m_grid_mesh.GetBatchesRef())
for (int i = 0; i < batch.vertex_data.size(); i++) for (int i = 0; i < batch.vertex_data.size(); i++)
grid_box[i] = batch.vertex_data[i].position * 1000.0f; grid_box[i] = {
batch.vertex_data[i].position.x * 1000.0f,
batch.vertex_data[i].position.y + m_grid_y,
batch.vertex_data[i].position.z * 1000.0f
};
} }
void Map::RenderGrid() void Map::RenderGrid()
{ {
Renderer3D::PushShader(m_grid_shader); Renderer3D::PushShader(m_grid_shader);
Vec3 camera_pos = Renderer3D::GetPrimaryCamera()->position; Vec3 camera_pos = Renderer3D::GetPrimaryCamera()->position;
camera_pos.y = 0.01f; camera_pos.y = 0.01f + m_grid_y;
Transform grid_transform(camera_pos, {0.0, 0.0, 0.0}, {1000.0, 0.0, 1000.0}); Transform grid_transform(camera_pos, {0.0, 0.0, 0.0}, {1000.0, 0.0, 1000.0});
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
Renderer3D::DrawMesh(m_grid_mesh, grid_transform); Renderer3D::DrawMesh(m_grid_mesh, grid_transform);

View file

@ -157,7 +157,7 @@ public:
void BuildSkybox(const std::string& texture_path, float scale = 128.0f); void BuildSkybox(const std::string& texture_path, float scale = 128.0f);
void RenderSkybox(); void RenderSkybox();
void BuildGrid(); void BuildGrid(float y = 0.0f);
void RenderGrid(); void RenderGrid();
StaticMesh& GetMeshRef(); StaticMesh& GetMeshRef();
@ -175,6 +175,7 @@ private:
StaticMesh m_mesh; StaticMesh m_mesh;
StaticMesh m_grid_mesh; StaticMesh m_grid_mesh;
Shader m_grid_shader; Shader m_grid_shader;
float m_grid_y = 0.0f;
Texture m_grid_texture; Texture m_grid_texture;
Skybox m_skybox_data; Skybox m_skybox_data;
Transform m_transform; Transform m_transform;

View file

@ -312,8 +312,8 @@ void Editor::UpdateModeBuild()
s->ceiling.material = kp3d::res::material_cache["block.png"].get(); s->ceiling.material = kp3d::res::material_cache["block.png"].get();
s->floor.material = kp3d::res::material_cache["block.png"].get(); s->floor.material = kp3d::res::material_cache["block.png"].get();
s->floor.floor = true; s->floor.floor = true;
s->floor.base_height = 0.0f; s->floor.base_height = m_grid_y;
s->ceiling.base_height = 2.0f; s->ceiling.base_height = m_grid_y + 4.0f;
s->id = sandbox->map.sectors.size() + 1; s->id = sandbox->map.sectors.size() + 1;
s->parent_id = 0; s->parent_id = 0;
s->inverted = false; s->inverted = false;
@ -369,8 +369,8 @@ void Editor::UpdateModeBuild()
s->ceiling.material = kp3d::res::material_cache["block.png"].get(); s->ceiling.material = kp3d::res::material_cache["block.png"].get();
s->floor.material = kp3d::res::material_cache["block.png"].get(); s->floor.material = kp3d::res::material_cache["block.png"].get();
s->floor.floor = true; s->floor.floor = true;
s->floor.base_height = 0.0f; s->floor.base_height = m_grid_y;
s->ceiling.base_height = 4.0f; s->ceiling.base_height = m_grid_y + 4.0f;
s->id = sandbox->map.sectors.size() + 1; s->id = sandbox->map.sectors.size() + 1;
s->parent_id = 0; s->parent_id = 0;
s->inverted = false; s->inverted = false;
@ -1174,19 +1174,27 @@ void Editor::OnScrollWheel(const kp3d::ScrollWheelEvent* e)
{ {
using namespace kp3d; using namespace kp3d;
if (editor_hovered_batch.empty()) if (m_mode == MODE_NORMAL)
return;
auto factor = (2.0f / 128.0f) * e->length;
for (auto* batch: editor_hovered_batch)
{ {
auto info = std::any_cast<BatchSectorInfo>(batch->userdata); if (editor_hovered_batch.empty())
if (info.flat) return;
auto factor = (2.0f / 128.0f) * e->length;
for (auto* batch : editor_hovered_batch)
{ {
info.flat->base_height += factor; auto info = std::any_cast<BatchSectorInfo>(batch->userdata);
RebuildMap(); if (info.flat)
{
info.flat->base_height += factor;
RebuildMap();
}
} }
} }
else if (m_mode == MODE_BUILD)
{
m_grid_y += (2.0f / 128.0f) * e->length;
sandbox->map.BuildGrid(m_grid_y);
}
} }
void Editor::OnKeyPress(const kp3d::KeyPressEvent* e) void Editor::OnKeyPress(const kp3d::KeyPressEvent* e)

View file

@ -80,6 +80,7 @@ private:
kp3d::Texture m_banner; kp3d::Texture m_banner;
kp3d::Texture m_stem; kp3d::Texture m_stem;
kp3d::Vec3 m_stem_pos; kp3d::Vec3 m_stem_pos;
float m_grid_y = 0.0f;
EditMode m_mode; EditMode m_mode;
// TODO: Refactor me! // TODO: Refactor me!