From da83fa0e0d724698eb113a98b603797dd526fe63 Mon Sep 17 00:00:00 2001 From: KP Date: Sat, 27 Jul 2024 17:27:31 -0500 Subject: [PATCH] Fix joining sectors --- Data/resources/shaders/.kp3d/map_grid_f.glsl | 6 +- .../resources/shaders/.kp3d/r3d_legacy_f.glsl | 2 +- Data/resources/textures/.kp3d/map_grid.png | Bin 242 -> 186 bytes Data/sandbox-log.txt | 381 ++++++++++++------ KP3Dii/src/KP3D_Map.cpp | 143 ++++--- Sandbox/src/Editor.cpp | 200 ++++++--- Sandbox/src/Editor.h | 20 + Sandbox/src/Sandbox.cpp | 12 +- 8 files changed, 534 insertions(+), 230 deletions(-) diff --git a/Data/resources/shaders/.kp3d/map_grid_f.glsl b/Data/resources/shaders/.kp3d/map_grid_f.glsl index 4aa04fa..49de1f0 100644 --- a/Data/resources/shaders/.kp3d/map_grid_f.glsl +++ b/Data/resources/shaders/.kp3d/map_grid_f.glsl @@ -56,7 +56,9 @@ void main() vec3 res = light.diffuse * lambert(norm, light.position); - float a = dist(v_position.xz, vec2(0.0, 0.0)) * 2.0f; + float a = dist(v_position.xz, vec2(0.0, 0.0)) * 25.0f; - v_output = vec4(tex.rgb, tex.a - a); + tex.rgb *= 1.0 - a; + + v_output = vec4(tex.rgb, tex.a); } diff --git a/Data/resources/shaders/.kp3d/r3d_legacy_f.glsl b/Data/resources/shaders/.kp3d/r3d_legacy_f.glsl index f7a0776..6bdffc7 100644 --- a/Data/resources/shaders/.kp3d/r3d_legacy_f.glsl +++ b/Data/resources/shaders/.kp3d/r3d_legacy_f.glsl @@ -13,5 +13,5 @@ uniform float u_time; void main() { vec4 tex = texture(u_texture, v_texcoord) * v_color; - v_output = vec4(1.0, 0.0, 0.0, 0.5 + (sin(u_time * 0.3f) + 1.0) * 0.25); + v_output = tex;//vec4(1.0, 0.0, 0.0, 0.5 + (sin(u_time * 0.3f) + 1.0) * 0.25); } diff --git a/Data/resources/textures/.kp3d/map_grid.png b/Data/resources/textures/.kp3d/map_grid.png index 0cd8bee8fbd5bf4146e986cb30759e9c374431b8..5fb44dcf8d2c7ef65a026437c835071c119ba407 100644 GIT binary patch delta 140 zcmeywxQlUuBnLAC1H;_yjc+C@Dpaxs_=LDVd-e<{WcVxhG>~E{3Gxg6&+v4+ffta+ zS>O>_%)r36AA}h#Sc6r7g8H5=jv*25Z_gMCG8k|$7=Fm#^r+!1L zY+>2=z8U=0Klu&f7uYXgi123IFpViem-RptSHo5jhHOoSYe5WamQq2&duCbP0l+XkKYcNV# diff --git a/Data/sandbox-log.txt b/Data/sandbox-log.txt index cfc554a..6f5a254 100644 --- a/Data/sandbox-log.txt +++ b/Data/sandbox-log.txt @@ -1,124 +1,269 @@ -[04:15:30 PM] Info: Starting... +[05:25:18 PM] Info: Starting... KP3D version 2 =============================== Copyright (C) kpworld.xyz 2018-2024 Contact me! @kp_cftsz -[04:15:30 PM] Info: Initializing SDL -[04:15:30 PM] Info: Initializing OpenGL -[04:15:30 PM] Info: OpenGL version: 4.6.0 NVIDIA 517.70 -[04:15:30 PM] Info: Initializing GLEW -[04:15:30 PM] Info: Initializing SDL_mixer -[04:15:30 PM] Info: Reticulating splines... -[04:15:30 PM] Info: Ready! -[04:15:31 PM] Info: SECTOR HIERARCHY -[04:15:31 PM] Info: Sector 3 (area: 1) -[04:15:31 PM] Info: Parent: -[04:15:31 PM] Info: - 1 -[04:15:31 PM] Info: Children: -[04:15:31 PM] Info: - [NO CHILDREN] -[04:15:31 PM] Info: ----- -[04:15:31 PM] Info: Sector 4 (area: 1) -[04:15:31 PM] Info: Parent: -[04:15:31 PM] Info: - 2 -[04:15:31 PM] Info: Children: -[04:15:31 PM] Info: - [NO CHILDREN] -[04:15:31 PM] Info: ----- -[04:15:31 PM] Info: Sector 6 (area: 6) -[04:15:31 PM] Info: Parent: -[04:15:31 PM] Info: - 1 -[04:15:31 PM] Info: Children: -[04:15:31 PM] Info: - [NO CHILDREN] -[04:15:31 PM] Info: ----- -[04:15:31 PM] Info: Sector 2 (area: 19) -[04:15:31 PM] Info: Parent: -[04:15:31 PM] Info: - 1 -[04:15:31 PM] Info: Children: -[04:15:31 PM] Info: - 4 -[04:15:31 PM] Info: ----- -[04:15:31 PM] Info: Sector 5 (area: 34) -[04:15:31 PM] Info: Parent: -[04:15:31 PM] Info: - [NO PARENT] -[04:15:31 PM] Info: Children: -[04:15:31 PM] Info: - [NO CHILDREN] -[04:15:31 PM] Info: ----- -[04:15:31 PM] Info: Sector 1 (area: 105.5) -[04:15:31 PM] Info: Parent: -[04:15:31 PM] Info: - [NO PARENT] -[04:15:31 PM] Info: Children: -[04:15:31 PM] Info: - 3 -[04:15:31 PM] Info: - 6 -[04:15:31 PM] Info: - 2 -[04:15:31 PM] Info: ----- -[04:16:52 PM] Info: SECTOR HIERARCHY -[04:16:52 PM] Info: Sector 3 (area: 1) -[04:16:52 PM] Info: Parent: -[04:16:52 PM] Info: - 1 -[04:16:52 PM] Info: Children: -[04:16:52 PM] Info: - [NO CHILDREN] -[04:16:52 PM] Info: ----- -[04:16:52 PM] Info: Sector 4 (area: 1) -[04:16:52 PM] Info: Parent: -[04:16:52 PM] Info: - 2 -[04:16:52 PM] Info: Children: -[04:16:52 PM] Info: - [NO CHILDREN] -[04:16:52 PM] Info: ----- -[04:16:52 PM] Info: Sector 6 (area: 6) -[04:16:52 PM] Info: Parent: -[04:16:52 PM] Info: - 1 -[04:16:52 PM] Info: Children: -[04:16:52 PM] Info: - [NO CHILDREN] -[04:16:52 PM] Info: ----- -[04:16:52 PM] Info: Sector 7 (area: 16) -[04:16:52 PM] Info: Parent: -[04:16:52 PM] Info: - [NO PARENT] -[04:16:52 PM] Info: Children: -[04:16:52 PM] Info: - [NO CHILDREN] -[04:16:52 PM] Info: ----- -[04:16:52 PM] Info: Sector 2 (area: 19) -[04:16:52 PM] Info: Parent: -[04:16:52 PM] Info: - 1 -[04:16:52 PM] Info: Children: -[04:16:52 PM] Info: - 4 -[04:16:52 PM] Info: ----- -[04:16:52 PM] Info: Sector 5 (area: 34) -[04:16:52 PM] Info: Parent: -[04:16:52 PM] Info: - [NO PARENT] -[04:16:52 PM] Info: Children: -[04:16:52 PM] Info: - [NO CHILDREN] -[04:16:52 PM] Info: ----- -[04:16:52 PM] Info: Sector 1 (area: 105.5) -[04:16:52 PM] Info: Parent: -[04:16:52 PM] Info: - [NO PARENT] -[04:16:52 PM] Info: Children: -[04:16:52 PM] Info: - 3 -[04:16:52 PM] Info: - 6 -[04:16:52 PM] Info: - 2 -[04:16:52 PM] Info: ----- -[04:16:57 PM] Info: SECTOR HIERARCHY -[04:16:57 PM] Info: Sector 3 (area: 1) -[04:16:57 PM] Info: Parent: -[04:16:57 PM] Info: - 1 -[04:16:57 PM] Info: Children: -[04:16:57 PM] Info: - [NO CHILDREN] -[04:16:57 PM] Info: ----- -[04:16:57 PM] Info: Sector 4 (area: 1) -[04:16:57 PM] Info: Parent: -[04:16:57 PM] Info: - 2 -[04:16:57 PM] Info: Children: -[04:16:57 PM] Info: - [NO CHILDREN] -[04:16:57 PM] Info: ----- -[04:16:57 PM] Info: Sector 8 (area: 4) -[04:16:57 PM] Info: Parent: -[04:16:57 PM] Info: - [NO PARENT] -[04:16:57 PM] Info: Children: -[04:16:57 PM] Info: - [NO CHILDREN] -[04:16:57 PM] Info: ----- -[04:16:57 PM] Info: Sector 6 (area: 6) -[04:16:57 PM] Info: Parent: -[04:16:57 PM] Info: - 1 -[04:16:57 PM] Info: Children: -[04:16:57 PM] Info: - [NO CHILDREN] -[04:16:57 PM] Info: ----- -[04:16:57 PM] Info: Sector 7 \ No newline at end of file +[05:25:18 PM] Info: Initializing SDL +[05:25:18 PM] Info: Initializing OpenGL +[05:25:18 PM] Info: OpenGL version: 4.6.0 NVIDIA 536.23 +[05:25:18 PM] Info: Initializing GLEW +[05:25:18 PM] Info: Initializing SDL_mixer +[05:25:18 PM] Info: Reticulating splines... +[05:25:18 PM] Info: Ready! +[05:25:18 PM] Info: SECTOR HIERARCHY +[05:25:18 PM] Info: Sector 3 (area: 1) +[05:25:18 PM] Info: Parent: +[05:25:18 PM] Info: - 1 +[05:25:18 PM] Info: Children: +[05:25:18 PM] Info: - [NO CHILDREN] +[05:25:18 PM] Info: ----- +[05:25:18 PM] Info: Sector 4 (area: 1) +[05:25:18 PM] Info: Parent: +[05:25:18 PM] Info: - 2 +[05:25:18 PM] Info: Children: +[05:25:18 PM] Info: - [NO CHILDREN] +[05:25:18 PM] Info: ----- +[05:25:18 PM] Info: Sector 6 (area: 6) +[05:25:18 PM] Info: Parent: +[05:25:18 PM] Info: - 1 +[05:25:18 PM] Info: Children: +[05:25:18 PM] Info: - [NO CHILDREN] +[05:25:18 PM] Info: ----- +[05:25:18 PM] Info: Sector 2 (area: 19) +[05:25:18 PM] Info: Parent: +[05:25:18 PM] Info: - 1 +[05:25:18 PM] Info: Children: +[05:25:18 PM] Info: - 4 +[05:25:18 PM] Info: ----- +[05:25:18 PM] Info: Sector 5 (area: 34) +[05:25:18 PM] Info: Parent: +[05:25:18 PM] Info: - [NO PARENT] +[05:25:18 PM] Info: Children: +[05:25:18 PM] Info: - [NO CHILDREN] +[05:25:18 PM] Info: ----- +[05:25:18 PM] Info: Sector 1 (area: 105.5) +[05:25:18 PM] Info: Parent: +[05:25:18 PM] Info: - [NO PARENT] +[05:25:18 PM] Info: Children: +[05:25:18 PM] Info: - 3 +[05:25:18 PM] Info: - 6 +[05:25:18 PM] Info: - 2 +[05:25:18 PM] Info: ----- +[05:25:30 PM] Info: SECTOR HIERARCHY +[05:25:30 PM] Info: Sector 3 (area: 1) +[05:25:30 PM] Info: Parent: +[05:25:30 PM] Info: - 1 +[05:25:30 PM] Info: Children: +[05:25:30 PM] Info: - [NO CHILDREN] +[05:25:30 PM] Info: ----- +[05:25:30 PM] Info: Sector 4 (area: 1) +[05:25:30 PM] Info: Parent: +[05:25:30 PM] Info: - 2 +[05:25:30 PM] Info: Children: +[05:25:30 PM] Info: - [NO CHILDREN] +[05:25:30 PM] Info: ----- +[05:25:30 PM] Info: Sector 6 (area: 6) +[05:25:30 PM] Info: Parent: +[05:25:30 PM] Info: - 1 +[05:25:30 PM] Info: Children: +[05:25:30 PM] Info: - [NO CHILDREN] +[05:25:30 PM] Info: ----- +[05:25:30 PM] Info: Sector 7 (area: 15) +[05:25:30 PM] Info: Parent: +[05:25:30 PM] Info: - [NO PARENT] +[05:25:30 PM] Info: Children: +[05:25:30 PM] Info: - [NO CHILDREN] +[05:25:30 PM] Info: ----- +[05:25:30 PM] Info: Sector 2 (area: 19) +[05:25:30 PM] Info: Parent: +[05:25:30 PM] Info: - 1 +[05:25:30 PM] Info: Children: +[05:25:30 PM] Info: - 4 +[05:25:30 PM] Info: ----- +[05:25:30 PM] Info: Sector 5 (area: 34) +[05:25:30 PM] Info: Parent: +[05:25:30 PM] Info: - [NO PARENT] +[05:25:30 PM] Info: Children: +[05:25:30 PM] Info: - [NO CHILDREN] +[05:25:30 PM] Info: ----- +[05:25:30 PM] Info: Sector 1 (area: 105.5) +[05:25:30 PM] Info: Parent: +[05:25:30 PM] Info: - [NO PARENT] +[05:25:30 PM] Info: Children: +[05:25:30 PM] Info: - 3 +[05:25:30 PM] Info: - 6 +[05:25:30 PM] Info: - 2 +[05:25:30 PM] Info: ----- +[05:25:35 PM] Info: SECTOR HIERARCHY +[05:25:35 PM] Info: Sector 3 (area: 1) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - 1 +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - [NO CHILDREN] +[05:25:35 PM] Info: ----- +[05:25:35 PM] Info: Sector 4 (area: 1) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - 2 +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - [NO CHILDREN] +[05:25:35 PM] Info: ----- +[05:25:35 PM] Info: Sector 8 (area: 3) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - [NO PARENT] +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - [NO CHILDREN] +[05:25:35 PM] Info: ----- +[05:25:35 PM] Info: Sector 6 (area: 6) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - 1 +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - [NO CHILDREN] +[05:25:35 PM] Info: ----- +[05:25:35 PM] Info: Sector 7 (area: 15) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - [NO PARENT] +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - [NO CHILDREN] +[05:25:35 PM] Info: ----- +[05:25:35 PM] Info: Sector 2 (area: 19) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - 1 +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - 4 +[05:25:35 PM] Info: ----- +[05:25:35 PM] Info: Sector 5 (area: 34) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - [NO PARENT] +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - [NO CHILDREN] +[05:25:35 PM] Info: ----- +[05:25:35 PM] Info: Sector 1 (area: 105.5) +[05:25:35 PM] Info: Parent: +[05:25:35 PM] Info: - [NO PARENT] +[05:25:35 PM] Info: Children: +[05:25:35 PM] Info: - 3 +[05:25:35 PM] Info: - 6 +[05:25:35 PM] Info: - 2 +[05:25:35 PM] Info: ----- +[05:25:47 PM] Info: SECTOR HIERARCHY +[05:25:47 PM] Info: Sector 3 (area: 1) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - 1 +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - [NO CHILDREN] +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 4 (area: 1) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - 2 +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - [NO CHILDREN] +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 8 (area: 3) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - [NO PARENT] +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - [NO CHILDREN] +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 6 (area: 6) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - 1 +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - [NO CHILDREN] +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 9 (area: 8) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - [NO PARENT] +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - [NO CHILDREN] +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 7 (area: 15) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - [NO PARENT] +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - [NO CHILDREN] +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 2 (area: 19) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - 1 +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - 4 +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 5 (area: 34) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - [NO PARENT] +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - [NO CHILDREN] +[05:25:47 PM] Info: ----- +[05:25:47 PM] Info: Sector 1 (area: 105.5) +[05:25:47 PM] Info: Parent: +[05:25:47 PM] Info: - [NO PARENT] +[05:25:47 PM] Info: Children: +[05:25:47 PM] Info: - 3 +[05:25:47 PM] Info: - 6 +[05:25:47 PM] Info: - 2 +[05:25:47 PM] Info: ----- +[05:25:56 PM] Info: SECTOR HIERARCHY +[05:25:56 PM] Info: Sector 3 (area: 1) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - 1 +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 4 (area: 1) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - 2 +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 8 (area: 3) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - [NO PARENT] +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 10 (area: 4) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - [NO PARENT] +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 6 (area: 6) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - 1 +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 9 (area: 8) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - [NO PARENT] +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 7 (area: 15) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - [NO PARENT] +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 2 (area: 19) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - 1 +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - 4 +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 5 (area: 34) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - [NO PARENT] +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - [NO CHILDREN] +[05:25:56 PM] Info: ----- +[05:25:56 PM] Info: Sector 1 (area: 105.5) +[05:25:56 PM] Info: Parent: +[05:25:56 PM] Info: - [NO PARENT] +[05:25:56 PM] Info: Children: +[05:25:56 PM] Info: - 3 +[05:25:56 PM] Info: - 6 +[05:25:56 PM] Info: - 2 +[05:25:56 PM] Info: ----- diff --git a/KP3Dii/src/KP3D_Map.cpp b/KP3Dii/src/KP3D_Map.cpp index 439a3d7..ffeb9b0 100644 --- a/KP3Dii/src/KP3D_Map.cpp +++ b/KP3Dii/src/KP3D_Map.cpp @@ -301,65 +301,63 @@ void Map::JoinSectors(Sector& sector) PosCmp({l.start.x, 0.0f, l.start.y}, {pos_b.x, 0.0f, pos_b.z}, e); bool end_cmp = PosCmp({l.end.x, 0.0f, l.end.y}, {pos_b.x, 0.0f, pos_b.z}, e) || PosCmp({l.end.x, 0.0f, l.end.y}, {pos_a.x, 0.0f, pos_a.z}, e); - bool same_points = start_cmp || end_cmp; + bool same_points = start_cmp && end_cmp; bool start_on_seg = PointInLine(l.start, {pos_a.x, pos_a.z}, {pos_b.x, pos_b.z}); bool end_on_seg = PointInLine(l.end, {pos_a.x, pos_a.z}, {pos_b.x, pos_b.z}); bool on_segment = start_on_seg && end_on_seg; - bool left_join = start_on_seg && end_cmp; - bool right_join = end_on_seg && start_cmp; + bool right_join = start_on_seg && end_cmp; + bool left_join = end_on_seg && start_cmp; if (on_segment && not_child) good = true; + if (good && !l.portal && !ld.portal) { - // Partial join - //if (left_join && !right_join) - //{ - // XYf old_end = ld.end; - // ld.end.x = l.start.x; - // ld.end.y = l.start.y; - // ld.flags = Wall::FLAG_TOUCHED; - // ld.textures[TEX_FRONT] = nullptr; - // ld.flags = Wall::FLAG_OPENING; - // ld.portal = &s; - // Wall w1 = ld; - // w1.flags = Wall::FLAG_TOUCHED; - // w1.start.x = ld.end.x; - // w1.start.y = ld.end.y; - // w1.end.x = l.end.x; - // w1.end.y = l.end.y; - // - // InsertLine(sector.walls, i + 1, w1); - // // InsertLine(sector.walls, i + 2, w2); - //} - //else + // We're looking for 4 cases: + // 1. This linedef overlaps the wall but doesn't touch any particular points + // In this case, we'll split the wall into 3 separate walls; left, middle, right + // 2. This linedef overlaps the wall but touches one point on the left + // In this case, we'll split the wall into 2 + // 3. This linedef overlaps the wall but touches one point on the right + // In this case, we'll split the wall into 2 + // 4. This linedef touches both points of the other wall + // In this case, we'll just mark the other side as an opening + enum Case { + UNKNOWN, + OVERLAP_NO_TOUCH, + OVERLAP_LEFT_TOUCH, + OVERLAP_RIGHT_TOUCH, + OVERLAP_BOTH_TOUCH + } type = UNKNOWN; + if (same_points) + type = OVERLAP_BOTH_TOUCH; + else if (on_segment && !start_cmp && !end_cmp) + type = OVERLAP_NO_TOUCH; + else if (left_join) + type = OVERLAP_LEFT_TOUCH; + else if (right_join) + type = OVERLAP_RIGHT_TOUCH; + + switch (type) { - if (!sector.inverted) + case OVERLAP_NO_TOUCH: { - ld.textures[TEX_FRONT] = nullptr; - ld.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; - ld.portal = &s; - } - } - else if (on_segment) - { - XYf old_end = ld.end; - ld.end.x = l.end.x; - ld.end.y = l.end.y; - ld.flags = Wall::FLAG_TOUCHED; - Wall w1 = ld; - w1.start.x = ld.end.x; - w1.start.y = ld.end.y; - w1.end.x = l.start.x; - w1.end.y = l.start.y; - w1.textures[TEX_FRONT] = nullptr; - w1.flags = Wall::FLAG_OPENING; - w1.portal = &s; - w1.flags = Wall::FLAG_TOUCHED; - InsertLine(sector.walls, i + 1, w1); - if (right_join && !left_join) { + XYf old_end = ld.end; + ld.end.x = l.end.x; + ld.end.y = l.end.y; + ld.flags = Wall::FLAG_TOUCHED; + Wall w1 = ld; + w1.start.x = ld.end.x; + w1.start.y = ld.end.y; + w1.end.x = l.start.x; + w1.end.y = l.start.y; + w1.textures[TEX_FRONT] = nullptr; + w1.flags = Wall::FLAG_OPENING; + w1.portal = &s; + w1.flags = Wall::FLAG_TOUCHED; + InsertLine(sector.walls, i + 1, w1); Wall w2 = ld; w2.start.x = w1.end.x; w2.start.y = w1.end.y; @@ -368,11 +366,54 @@ void Map::JoinSectors(Sector& sector) w2.flags = Wall::FLAG_TOUCHED; InsertLine(sector.walls, i + 2, w2); } - + break; + case OVERLAP_LEFT_TOUCH: + { + Wall w1 = ld; + ld.end.x = l.end.x; + ld.end.y = l.end.y; + ld.flags = Wall::FLAG_TOUCHED; + w1.start.x = ld.end.x; + w1.start.y = ld.end.y; + w1.end.x = l.start.x; + w1.end.y = l.start.y; + w1.textures[TEX_FRONT] = nullptr; + w1.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; + w1.portal = &s; + InsertLine(sector.walls, i + 1, w1); + } + break; + case OVERLAP_RIGHT_TOUCH: + { + Wall w1 = ld; + XYf old_end = ld.end; + ld.end.x = l.start.x; + ld.end.y = l.start.y; + ld.textures[TEX_FRONT] = nullptr; + ld.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; + ld.portal = &s; + w1.start.x = ld.end.x; + w1.start.y = ld.end.y; + w1.end.x = old_end.x; + w1.end.y = old_end.y; + w1.flags = Wall::FLAG_TOUCHED; + InsertLine(sector.walls, i + 1, w1); + } + break; + case OVERLAP_BOTH_TOUCH: + { + if (!sector.inverted) // not sure if we want to discount inverted sectors for just this case or all of + // them; revisit me! + { + ld.textures[TEX_FRONT] = nullptr; + ld.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; + ld.portal = &s; + } + } + break; } // Mark the other one as an opening - // This really shouldn't be necessary I think, but whatever l.textures[TEX_FRONT] = nullptr; l.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; l.portal = §or; @@ -686,7 +727,7 @@ void Map::RenderSkybox() void Map::BuildGrid() { m_grid_shader.Load(".kp3d/map_grid_v.glsl", ".kp3d/map_grid_f.glsl"); - m_grid_texture.Load(".kp3d/map_grid.png", true, kp3d::Texture::FILTER_LINEAR); + m_grid_texture.Load(".kp3d/map_grid.png", false, kp3d::Texture::FILTER_LINEAR); 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, 0.0f)), @@ -705,7 +746,7 @@ void Map::RenderGrid() { Renderer3D::PushShader(m_grid_shader); Vec3 camera_pos = Renderer3D::GetPrimaryCamera()->position; - camera_pos.y = 0.0f; + camera_pos.y = 0.01f; Transform grid_transform(camera_pos, {0.0, 0.0, 0.0}, {1000.0, 0.0, 1000.0}); glDisable(GL_CULL_FACE); Renderer3D::DrawMesh(m_grid_mesh, grid_transform); diff --git a/Sandbox/src/Editor.cpp b/Sandbox/src/Editor.cpp index 8a567af..1217356 100644 --- a/Sandbox/src/Editor.cpp +++ b/Sandbox/src/Editor.cpp @@ -31,6 +31,7 @@ Editor::Editor() { m_stem.Load("editor/stem.png"); m_block.Load("block.png", true); + m_mode = MODE_BUILD; } Editor::~Editor() @@ -43,46 +44,97 @@ void Editor::Init() void Editor::Update() { - if (sandbox->IsKeyDown(kp3d::KEY_O)) - { - sandbox->map.join_disabled ^= 1; - sandbox->KeyReset(kp3d::KEY_O); - } + #define KEY_SHORTCUT(key, action) if (sandbox->IsKeyDown(kp3d::KEY_##key)) { action; sandbox->KeyReset(kp3d::KEY_##key); } - if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_LEFT)) - { - points.push_back(m_stem_pos); + KEY_SHORTCUT(SPACE, m_mode = MODE_NORMAL); + KEY_SHORTCUT(V, m_mode = MODE_BUILD); + KEY_SHORTCUT(C, m_mode = MODE_SECTOR_EDIT); - if (points.size() >= 3 && kp3d::PosCmp(points.back(), points.front(), 1.0f / 128.0f))// points.back() == points.front()) + if (m_mode == MODE_BUILD) + { + if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_LEFT)) { - kp3d::Sector s; - s.ceiling.texture = &m_block; - s.floor.texture = &m_block; - s.floor.floor = true; - s.floor.base_height = 0.0f; - s.ceiling.base_height = 2.0f; - s.id = sandbox->map.sectors.size() + 1; - s.parent_id = 0; - s.inverted = false; - for (int i = 0; i < points.size() - 1; i++) - { - kp3d::Wall wall; - wall.start = {points[i].x, -points[i].z}; - wall.end = {points[i+1].x, -points[i+1].z}; - wall.uid = i; - for (int j = 0; j < 3; j++) - wall.textures[j] = &m_block; + points.push_back(m_stem_pos); - s.walls.push_back(wall); + if (points.size() >= 3 && kp3d::PosCmp(points.back(), points.front(), 1.0f / 128.0f))// points.back() == points.front()) + { + kp3d::Sector s; + s.ceiling.texture = &m_block; + s.floor.texture = &m_block; + s.floor.floor = true; + s.floor.base_height = 0.0f; + s.ceiling.base_height = 2.0f; + s.id = sandbox->map.sectors.size() + 1; + s.parent_id = 0; + s.inverted = false; + for (int i = 0; i < points.size() - 1; i++) + { + kp3d::Wall wall; + wall.start = { points[i].x, -points[i].z }; + wall.end = { points[i + 1].x, -points[i + 1].z }; + wall.uid = i; + for (int j = 0; j < 3; j++) + wall.textures[j] = &m_block; + + s.walls.push_back(wall); + } + + sandbox->map.original_sectors.push_back(s); + sandbox->map.Rebuild(kp3d::GEN_NORMALS); + + points.clear(); } - sandbox->map.original_sectors.push_back(s); - sandbox->map.Rebuild(kp3d::GEN_NORMALS); - - points.clear(); + sandbox->MouseButtonReset(kp3d::MOUSE_BUTTON_LEFT); } + static kp3d::Vec3 start_pos; + static bool has_start_pos = false; + if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_RIGHT)) + { + if (!has_start_pos) + { + start_pos = m_stem_pos; + has_start_pos = true; + } + points.clear(); + points.emplace_back(m_stem_pos.x, start_pos.y, m_stem_pos.z); + points.emplace_back(start_pos.x, start_pos.y, m_stem_pos.z); + points.emplace_back(start_pos.x, start_pos.y, start_pos.z); + points.emplace_back(m_stem_pos.x, start_pos.y, start_pos.z); + points.emplace_back(m_stem_pos.x, start_pos.y, m_stem_pos.z); + std::reverse(points.begin(), points.end()); + } + else + { + if (has_start_pos) + { + kp3d::Sector s; + s.ceiling.texture = &m_block; + s.floor.texture = &m_block; + s.floor.floor = true; + s.floor.base_height = 0.0f; + s.ceiling.base_height = 2.0f; + s.id = sandbox->map.sectors.size() + 1; + s.parent_id = 0; + s.inverted = false; + for (int i = 0; i < points.size() - 1; i++) + { + kp3d::Wall wall; + wall.start = { points[i].x, -points[i].z }; + wall.end = { points[i + 1].x, -points[i + 1].z }; + wall.uid = i; + for (int j = 0; j < 3; j++) + wall.textures[j] = &m_block; - sandbox->MouseButtonReset(kp3d::MOUSE_BUTTON_LEFT); + s.walls.push_back(wall); + } + + sandbox->map.original_sectors.push_back(s); + sandbox->map.Rebuild(kp3d::GEN_NORMALS); + points.clear(); + has_start_pos = false; + } + } } } @@ -95,27 +147,10 @@ void Editor::RenderMap() if (points.size() > 1) { for (int i = 0; i < points.size() - 1; i++) - { - kp3d::Vec3 p0 = points[i]; - kp3d::Vec3 p1 = points[i + 1]; - - float target_thickness = 1.0f / 128.0f; - float thickness = target_thickness; - kp3d::Vec3 player_distance = ((p0 + p1) * 0.5f) - sandbox->camera.position; - float d = sqrtf( - player_distance.x * player_distance.x + player_distance.y * player_distance.y + player_distance.z * player_distance.z - ); - if (d < 0.01f) - d = 0.01f; - thickness *= d; - if (thickness > target_thickness) - thickness = target_thickness; - p0.y += 0.01f; - p1.y += 0.01f; - - kp3d::Renderer3D::DrawLine(p0, p1, thickness * d, 0xFF0000FF); - } + RenderLine(points[i], points[i + 1], 0xFF00FFFF); } + if (points.size() > 0) + RenderLine(points.back(), m_stem_pos, 0xFFFF00FF); // Render the "stem" auto ray = kp3d::GetRayFromCamera(sandbox->camera); @@ -155,6 +190,7 @@ void Editor::RenderStem(kp3d::Vec3 position) void Editor::RenderUI() { + // Menu bar ImGui::BeginMainMenuBar(); if (ImGui::BeginMenu("File")) { @@ -165,5 +201,65 @@ void Editor::RenderUI() { ImGui::EndMenu(); } + if (ImGui::BeginMenu("View")) + { + ImGui::Checkbox("Info overlay", &show_info_overlay); + ImGui::EndMenu(); + } ImGui::EndMainMenuBar(); + + // Overlay + RenderUIInfo(); +} + +void Editor::RenderUIInfo() +{ + if (!show_info_overlay) + return; + + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | + ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMove; + ImGui::SetNextWindowBgAlpha(0.35f); + if (ImGui::Begin("Editor Info", &show_info_overlay, window_flags)) + { + std::string mode_str = "Unknown"; + switch (m_mode) + { + case MODE_NORMAL: mode_str = "Normal"; break; + case MODE_BUILD: mode_str = "Build"; break; + case MODE_SECTOR_EDIT: mode_str = "Sector Edit"; break; + } + ImGui::Text("Mode: %s\n", mode_str.c_str()); + ImGui::Separator(); + ImGui::Text("Caret Position: (%.1f, %.1f, %.1f)", m_stem_pos.x, m_stem_pos.y, m_stem_pos.z); + if (ImGui::BeginPopupContextWindow()) + { + if (ImGui::MenuItem("Hide", NULL, show_info_overlay == false)) + show_info_overlay = false; + ImGui::EndPopup(); + } + ImGui::End(); + } +} + +// + +void Editor::RenderLine(kp3d::Vec3 p0, kp3d::Vec3 p1, kp3d::uint color) +{ + float target_thickness = 1.0f / 128.0f; + float thickness = target_thickness; + kp3d::Vec3 player_distance = ((p0 + p1) * 0.5f) - sandbox->camera.position; + float d = sqrtf( + player_distance.x * player_distance.x + player_distance.y * player_distance.y + player_distance.z * player_distance.z + ); + if (d < 0.01f) + d = 0.01f; + thickness *= d; + if (thickness > target_thickness) + thickness = target_thickness; + p0.y += 0.01f; + p1.y += 0.01f; + + kp3d::Renderer3D::DrawLine(p0, p1, thickness * d, color); } diff --git a/Sandbox/src/Editor.h b/Sandbox/src/Editor.h index 8074814..339522d 100644 --- a/Sandbox/src/Editor.h +++ b/Sandbox/src/Editor.h @@ -3,6 +3,13 @@ #include "KP3D_Texture.h" #include "KP3D_Math.h" +enum EditMode +{ + MODE_NORMAL, + MODE_BUILD, + MODE_SECTOR_EDIT +}; + class Editor { public: @@ -13,11 +20,24 @@ public: void Update(); void RenderMap(); void RenderStem(kp3d::Vec3 position); + + void RenderModeBuild(); + void RenderModeSectorEdit(); + void RenderUI(); + void RenderUIInfo(); + +private: + void RenderLine(kp3d::Vec3 start, kp3d::Vec3 end, kp3d::uint color); private: kp3d::Texture m_stem; kp3d::Texture m_block; kp3d::Vec3 m_stem_pos; + EditMode m_mode; + + // TODO: Refactor me! + bool show_info_overlay = true; + }; diff --git a/Sandbox/src/Sandbox.cpp b/Sandbox/src/Sandbox.cpp index c929aa3..89697f3 100644 --- a/Sandbox/src/Sandbox.cpp +++ b/Sandbox/src/Sandbox.cpp @@ -105,12 +105,12 @@ void Sandbox::Update() if (IsKeyDown(kp3d::KEY_S)) camera.Move(camera.forward, -move_speed); if (IsKeyDown(kp3d::KEY_A)) camera.Move(camera.right, move_speed); if (IsKeyDown(kp3d::KEY_D)) camera.Move(camera.right, -move_speed); - if (IsKeyDown(kp3d::KEY_SPACE)) camera.position.y += move_speed; - if (IsKeyDown(kp3d::KEY_LSHIFT)) camera.position.y -= move_speed; - if (IsKeyDown(kp3d::KEY_Q)) camera.Rotate(kp3d::Camera::AXIS_X, qerf_speed); - if (IsKeyDown(kp3d::KEY_E)) camera.Rotate(kp3d::Camera::AXIS_X, -qerf_speed); - if (IsKeyDown(kp3d::KEY_R)) camera.Rotate(kp3d::Camera::AXIS_Y, qerf_speed); - if (IsKeyDown(kp3d::KEY_F)) camera.Rotate(kp3d::Camera::AXIS_Y, -qerf_speed); + //if (IsKeyDown(kp3d::KEY_SPACE)) camera.position.y += move_speed; + //if (IsKeyDown(kp3d::KEY_LSHIFT)) camera.position.y -= move_speed; + //if (IsKeyDown(kp3d::KEY_Q)) camera.Rotate(kp3d::Camera::AXIS_X, qerf_speed); + //if (IsKeyDown(kp3d::KEY_E)) camera.Rotate(kp3d::Camera::AXIS_X, -qerf_speed); + //if (IsKeyDown(kp3d::KEY_R)) camera.Rotate(kp3d::Camera::AXIS_Y, qerf_speed); + //if (IsKeyDown(kp3d::KEY_F)) camera.Rotate(kp3d::Camera::AXIS_Y, -qerf_speed); ResetMouseCursor([&](float x, float y) { camera.UpdateMouseLook({x, y}); }); camera.UpdateMatrix(); }