Fix joining sectors

This commit is contained in:
KP 2024-07-27 17:27:31 -05:00
parent a443869284
commit da83fa0e0d
8 changed files with 534 additions and 230 deletions

View file

@ -56,7 +56,9 @@ void main()
vec3 res = light.diffuse * lambert(norm, light.position); 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);
} }

View file

@ -13,5 +13,5 @@ uniform float u_time;
void main() void main()
{ {
vec4 tex = texture(u_texture, v_texcoord) * v_color; 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);
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 186 B

View file

@ -1,124 +1,269 @@
[04:15:30 PM] Info: Starting... [05:25:18 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
[04:15:30 PM] Info: Initializing SDL [05:25:18 PM] Info: Initializing SDL
[04:15:30 PM] Info: Initializing OpenGL [05:25:18 PM] Info: Initializing OpenGL
[04:15:30 PM] Info: OpenGL version: 4.6.0 NVIDIA 517.70 [05:25:18 PM] Info: OpenGL version: 4.6.0 NVIDIA 536.23
[04:15:30 PM] Info: Initializing GLEW [05:25:18 PM] Info: Initializing GLEW
[04:15:30 PM] Info: Initializing SDL_mixer [05:25:18 PM] Info: Initializing SDL_mixer
[04:15:30 PM] Info: Reticulating splines... [05:25:18 PM] Info: Reticulating splines...
[04:15:30 PM] Info: Ready! [05:25:18 PM] Info: Ready!
[04:15:31 PM] Info: SECTOR HIERARCHY [05:25:18 PM] Info: SECTOR HIERARCHY
[04:15:31 PM] Info: Sector 3 (area: 1) [05:25:18 PM] Info: Sector 3 (area: 1)
[04:15:31 PM] Info: Parent: [05:25:18 PM] Info: Parent:
[04:15:31 PM] Info: - 1 [05:25:18 PM] Info: - 1
[04:15:31 PM] Info: Children: [05:25:18 PM] Info: Children:
[04:15:31 PM] Info: - [NO CHILDREN] [05:25:18 PM] Info: - [NO CHILDREN]
[04:15:31 PM] Info: ----- [05:25:18 PM] Info: -----
[04:15:31 PM] Info: Sector 4 (area: 1) [05:25:18 PM] Info: Sector 4 (area: 1)
[04:15:31 PM] Info: Parent: [05:25:18 PM] Info: Parent:
[04:15:31 PM] Info: - 2 [05:25:18 PM] Info: - 2
[04:15:31 PM] Info: Children: [05:25:18 PM] Info: Children:
[04:15:31 PM] Info: - [NO CHILDREN] [05:25:18 PM] Info: - [NO CHILDREN]
[04:15:31 PM] Info: ----- [05:25:18 PM] Info: -----
[04:15:31 PM] Info: Sector 6 (area: 6) [05:25:18 PM] Info: Sector 6 (area: 6)
[04:15:31 PM] Info: Parent: [05:25:18 PM] Info: Parent:
[04:15:31 PM] Info: - 1 [05:25:18 PM] Info: - 1
[04:15:31 PM] Info: Children: [05:25:18 PM] Info: Children:
[04:15:31 PM] Info: - [NO CHILDREN] [05:25:18 PM] Info: - [NO CHILDREN]
[04:15:31 PM] Info: ----- [05:25:18 PM] Info: -----
[04:15:31 PM] Info: Sector 2 (area: 19) [05:25:18 PM] Info: Sector 2 (area: 19)
[04:15:31 PM] Info: Parent: [05:25:18 PM] Info: Parent:
[04:15:31 PM] Info: - 1 [05:25:18 PM] Info: - 1
[04:15:31 PM] Info: Children: [05:25:18 PM] Info: Children:
[04:15:31 PM] Info: - 4 [05:25:18 PM] Info: - 4
[04:15:31 PM] Info: ----- [05:25:18 PM] Info: -----
[04:15:31 PM] Info: Sector 5 (area: 34) [05:25:18 PM] Info: Sector 5 (area: 34)
[04:15:31 PM] Info: Parent: [05:25:18 PM] Info: Parent:
[04:15:31 PM] Info: - [NO PARENT] [05:25:18 PM] Info: - [NO PARENT]
[04:15:31 PM] Info: Children: [05:25:18 PM] Info: Children:
[04:15:31 PM] Info: - [NO CHILDREN] [05:25:18 PM] Info: - [NO CHILDREN]
[04:15:31 PM] Info: ----- [05:25:18 PM] Info: -----
[04:15:31 PM] Info: Sector 1 (area: 105.5) [05:25:18 PM] Info: Sector 1 (area: 105.5)
[04:15:31 PM] Info: Parent: [05:25:18 PM] Info: Parent:
[04:15:31 PM] Info: - [NO PARENT] [05:25:18 PM] Info: - [NO PARENT]
[04:15:31 PM] Info: Children: [05:25:18 PM] Info: Children:
[04:15:31 PM] Info: - 3 [05:25:18 PM] Info: - 3
[04:15:31 PM] Info: - 6 [05:25:18 PM] Info: - 6
[04:15:31 PM] Info: - 2 [05:25:18 PM] Info: - 2
[04:15:31 PM] Info: ----- [05:25:18 PM] Info: -----
[04:16:52 PM] Info: SECTOR HIERARCHY [05:25:30 PM] Info: SECTOR HIERARCHY
[04:16:52 PM] Info: Sector 3 (area: 1) [05:25:30 PM] Info: Sector 3 (area: 1)
[04:16:52 PM] Info: Parent: [05:25:30 PM] Info: Parent:
[04:16:52 PM] Info: - 1 [05:25:30 PM] Info: - 1
[04:16:52 PM] Info: Children: [05:25:30 PM] Info: Children:
[04:16:52 PM] Info: - [NO CHILDREN] [05:25:30 PM] Info: - [NO CHILDREN]
[04:16:52 PM] Info: ----- [05:25:30 PM] Info: -----
[04:16:52 PM] Info: Sector 4 (area: 1) [05:25:30 PM] Info: Sector 4 (area: 1)
[04:16:52 PM] Info: Parent: [05:25:30 PM] Info: Parent:
[04:16:52 PM] Info: - 2 [05:25:30 PM] Info: - 2
[04:16:52 PM] Info: Children: [05:25:30 PM] Info: Children:
[04:16:52 PM] Info: - [NO CHILDREN] [05:25:30 PM] Info: - [NO CHILDREN]
[04:16:52 PM] Info: ----- [05:25:30 PM] Info: -----
[04:16:52 PM] Info: Sector 6 (area: 6) [05:25:30 PM] Info: Sector 6 (area: 6)
[04:16:52 PM] Info: Parent: [05:25:30 PM] Info: Parent:
[04:16:52 PM] Info: - 1 [05:25:30 PM] Info: - 1
[04:16:52 PM] Info: Children: [05:25:30 PM] Info: Children:
[04:16:52 PM] Info: - [NO CHILDREN] [05:25:30 PM] Info: - [NO CHILDREN]
[04:16:52 PM] Info: ----- [05:25:30 PM] Info: -----
[04:16:52 PM] Info: Sector 7 (area: 16) [05:25:30 PM] Info: Sector 7 (area: 15)
[04:16:52 PM] Info: Parent: [05:25:30 PM] Info: Parent:
[04:16:52 PM] Info: - [NO PARENT] [05:25:30 PM] Info: - [NO PARENT]
[04:16:52 PM] Info: Children: [05:25:30 PM] Info: Children:
[04:16:52 PM] Info: - [NO CHILDREN] [05:25:30 PM] Info: - [NO CHILDREN]
[04:16:52 PM] Info: ----- [05:25:30 PM] Info: -----
[04:16:52 PM] Info: Sector 2 (area: 19) [05:25:30 PM] Info: Sector 2 (area: 19)
[04:16:52 PM] Info: Parent: [05:25:30 PM] Info: Parent:
[04:16:52 PM] Info: - 1 [05:25:30 PM] Info: - 1
[04:16:52 PM] Info: Children: [05:25:30 PM] Info: Children:
[04:16:52 PM] Info: - 4 [05:25:30 PM] Info: - 4
[04:16:52 PM] Info: ----- [05:25:30 PM] Info: -----
[04:16:52 PM] Info: Sector 5 (area: 34) [05:25:30 PM] Info: Sector 5 (area: 34)
[04:16:52 PM] Info: Parent: [05:25:30 PM] Info: Parent:
[04:16:52 PM] Info: - [NO PARENT] [05:25:30 PM] Info: - [NO PARENT]
[04:16:52 PM] Info: Children: [05:25:30 PM] Info: Children:
[04:16:52 PM] Info: - [NO CHILDREN] [05:25:30 PM] Info: - [NO CHILDREN]
[04:16:52 PM] Info: ----- [05:25:30 PM] Info: -----
[04:16:52 PM] Info: Sector 1 (area: 105.5) [05:25:30 PM] Info: Sector 1 (area: 105.5)
[04:16:52 PM] Info: Parent: [05:25:30 PM] Info: Parent:
[04:16:52 PM] Info: - [NO PARENT] [05:25:30 PM] Info: - [NO PARENT]
[04:16:52 PM] Info: Children: [05:25:30 PM] Info: Children:
[04:16:52 PM] Info: - 3 [05:25:30 PM] Info: - 3
[04:16:52 PM] Info: - 6 [05:25:30 PM] Info: - 6
[04:16:52 PM] Info: - 2 [05:25:30 PM] Info: - 2
[04:16:52 PM] Info: ----- [05:25:30 PM] Info: -----
[04:16:57 PM] Info: SECTOR HIERARCHY [05:25:35 PM] Info: SECTOR HIERARCHY
[04:16:57 PM] Info: Sector 3 (area: 1) [05:25:35 PM] Info: Sector 3 (area: 1)
[04:16:57 PM] Info: Parent: [05:25:35 PM] Info: Parent:
[04:16:57 PM] Info: - 1 [05:25:35 PM] Info: - 1
[04:16:57 PM] Info: Children: [05:25:35 PM] Info: Children:
[04:16:57 PM] Info: - [NO CHILDREN] [05:25:35 PM] Info: - [NO CHILDREN]
[04:16:57 PM] Info: ----- [05:25:35 PM] Info: -----
[04:16:57 PM] Info: Sector 4 (area: 1) [05:25:35 PM] Info: Sector 4 (area: 1)
[04:16:57 PM] Info: Parent: [05:25:35 PM] Info: Parent:
[04:16:57 PM] Info: - 2 [05:25:35 PM] Info: - 2
[04:16:57 PM] Info: Children: [05:25:35 PM] Info: Children:
[04:16:57 PM] Info: - [NO CHILDREN] [05:25:35 PM] Info: - [NO CHILDREN]
[04:16:57 PM] Info: ----- [05:25:35 PM] Info: -----
[04:16:57 PM] Info: Sector 8 (area: 4) [05:25:35 PM] Info: Sector 8 (area: 3)
[04:16:57 PM] Info: Parent: [05:25:35 PM] Info: Parent:
[04:16:57 PM] Info: - [NO PARENT] [05:25:35 PM] Info: - [NO PARENT]
[04:16:57 PM] Info: Children: [05:25:35 PM] Info: Children:
[04:16:57 PM] Info: - [NO CHILDREN] [05:25:35 PM] Info: - [NO CHILDREN]
[04:16:57 PM] Info: ----- [05:25:35 PM] Info: -----
[04:16:57 PM] Info: Sector 6 (area: 6) [05:25:35 PM] Info: Sector 6 (area: 6)
[04:16:57 PM] Info: Parent: [05:25:35 PM] Info: Parent:
[04:16:57 PM] Info: - 1 [05:25:35 PM] Info: - 1
[04:16:57 PM] Info: Children: [05:25:35 PM] Info: Children:
[04:16:57 PM] Info: - [NO CHILDREN] [05:25:35 PM] Info: - [NO CHILDREN]
[04:16:57 PM] Info: ----- [05:25:35 PM] Info: -----
[04:16:57 PM] Info: Sector 7 [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: -----

View file

@ -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); 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) || 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); 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 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 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 on_segment = start_on_seg && end_on_seg;
bool left_join = start_on_seg && end_cmp; bool right_join = start_on_seg && end_cmp;
bool right_join = end_on_seg && start_cmp; bool left_join = end_on_seg && start_cmp;
if (on_segment && not_child) if (on_segment && not_child)
good = true; good = true;
if (good && !l.portal && !ld.portal) if (good && !l.portal && !ld.portal)
{ {
// Partial join // We're looking for 4 cases:
//if (left_join && !right_join) // 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
// XYf old_end = ld.end; // 2. This linedef overlaps the wall but touches one point on the left
// ld.end.x = l.start.x; // In this case, we'll split the wall into 2
// ld.end.y = l.start.y; // 3. This linedef overlaps the wall but touches one point on the right
// ld.flags = Wall::FLAG_TOUCHED; // In this case, we'll split the wall into 2
// ld.textures[TEX_FRONT] = nullptr; // 4. This linedef touches both points of the other wall
// ld.flags = Wall::FLAG_OPENING; // In this case, we'll just mark the other side as an opening
// ld.portal = &s; enum Case {
// Wall w1 = ld; UNKNOWN,
// w1.flags = Wall::FLAG_TOUCHED; OVERLAP_NO_TOUCH,
// w1.start.x = ld.end.x; OVERLAP_LEFT_TOUCH,
// w1.start.y = ld.end.y; OVERLAP_RIGHT_TOUCH,
// w1.end.x = l.end.x; OVERLAP_BOTH_TOUCH
// w1.end.y = l.end.y; } type = UNKNOWN;
//
// InsertLine(sector.walls, i + 1, w1);
// // InsertLine(sector.walls, i + 2, w2);
//}
//else
if (same_points) 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; XYf old_end = ld.end;
ld.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; ld.end.x = l.end.x;
ld.portal = &s; ld.end.y = l.end.y;
} ld.flags = Wall::FLAG_TOUCHED;
} Wall w1 = ld;
else if (on_segment) w1.start.x = ld.end.x;
{ w1.start.y = ld.end.y;
XYf old_end = ld.end; w1.end.x = l.start.x;
ld.end.x = l.end.x; w1.end.y = l.start.y;
ld.end.y = l.end.y; w1.textures[TEX_FRONT] = nullptr;
ld.flags = Wall::FLAG_TOUCHED; w1.flags = Wall::FLAG_OPENING;
Wall w1 = ld; w1.portal = &s;
w1.start.x = ld.end.x; w1.flags = Wall::FLAG_TOUCHED;
w1.start.y = ld.end.y; InsertLine(sector.walls, i + 1, w1);
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) {
Wall w2 = ld; Wall w2 = ld;
w2.start.x = w1.end.x; w2.start.x = w1.end.x;
w2.start.y = w1.end.y; w2.start.y = w1.end.y;
@ -368,11 +366,54 @@ void Map::JoinSectors(Sector& sector)
w2.flags = Wall::FLAG_TOUCHED; w2.flags = Wall::FLAG_TOUCHED;
InsertLine(sector.walls, i + 2, w2); 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 // Mark the other one as an opening
// This really shouldn't be necessary I think, but whatever
l.textures[TEX_FRONT] = nullptr; l.textures[TEX_FRONT] = nullptr;
l.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; l.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED;
l.portal = &sector; l.portal = &sector;
@ -686,7 +727,7 @@ void Map::RenderSkybox()
void Map::BuildGrid() void Map::BuildGrid()
{ {
m_grid_shader.Load(".kp3d/map_grid_v.glsl", ".kp3d/map_grid_f.glsl"); 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, { 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)),
@ -705,7 +746,7 @@ 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.0f; camera_pos.y = 0.01f;
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

@ -31,6 +31,7 @@ Editor::Editor()
{ {
m_stem.Load("editor/stem.png"); m_stem.Load("editor/stem.png");
m_block.Load("block.png", true); m_block.Load("block.png", true);
m_mode = MODE_BUILD;
} }
Editor::~Editor() Editor::~Editor()
@ -43,46 +44,97 @@ void Editor::Init()
void Editor::Update() void Editor::Update()
{ {
if (sandbox->IsKeyDown(kp3d::KEY_O)) #define KEY_SHORTCUT(key, action) if (sandbox->IsKeyDown(kp3d::KEY_##key)) { action; sandbox->KeyReset(kp3d::KEY_##key); }
{
sandbox->map.join_disabled ^= 1;
sandbox->KeyReset(kp3d::KEY_O);
}
if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_LEFT)) KEY_SHORTCUT(SPACE, m_mode = MODE_NORMAL);
{ KEY_SHORTCUT(V, m_mode = MODE_BUILD);
points.push_back(m_stem_pos); 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; points.push_back(m_stem_pos);
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); 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->MouseButtonReset(kp3d::MOUSE_BUTTON_LEFT);
sandbox->map.Rebuild(kp3d::GEN_NORMALS);
points.clear();
} }
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) if (points.size() > 1)
{ {
for (int i = 0; i < points.size() - 1; i++) for (int i = 0; i < points.size() - 1; i++)
{ RenderLine(points[i], points[i + 1], 0xFF00FFFF);
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);
}
} }
if (points.size() > 0)
RenderLine(points.back(), m_stem_pos, 0xFFFF00FF);
// Render the "stem" // Render the "stem"
auto ray = kp3d::GetRayFromCamera(sandbox->camera); auto ray = kp3d::GetRayFromCamera(sandbox->camera);
@ -155,6 +190,7 @@ void Editor::RenderStem(kp3d::Vec3 position)
void Editor::RenderUI() void Editor::RenderUI()
{ {
// Menu bar
ImGui::BeginMainMenuBar(); ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("File")) if (ImGui::BeginMenu("File"))
{ {
@ -165,5 +201,65 @@ void Editor::RenderUI()
{ {
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("View"))
{
ImGui::Checkbox("Info overlay", &show_info_overlay);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar(); 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);
} }

View file

@ -3,6 +3,13 @@
#include "KP3D_Texture.h" #include "KP3D_Texture.h"
#include "KP3D_Math.h" #include "KP3D_Math.h"
enum EditMode
{
MODE_NORMAL,
MODE_BUILD,
MODE_SECTOR_EDIT
};
class Editor class Editor
{ {
public: public:
@ -13,11 +20,24 @@ public:
void Update(); void Update();
void RenderMap(); void RenderMap();
void RenderStem(kp3d::Vec3 position); void RenderStem(kp3d::Vec3 position);
void RenderModeBuild();
void RenderModeSectorEdit();
void RenderUI(); void RenderUI();
void RenderUIInfo();
private:
void RenderLine(kp3d::Vec3 start, kp3d::Vec3 end, kp3d::uint color);
private: private:
kp3d::Texture m_stem; kp3d::Texture m_stem;
kp3d::Texture m_block; kp3d::Texture m_block;
kp3d::Vec3 m_stem_pos; kp3d::Vec3 m_stem_pos;
EditMode m_mode;
// TODO: Refactor me!
bool show_info_overlay = true;
}; };

View file

@ -105,12 +105,12 @@ void Sandbox::Update()
if (IsKeyDown(kp3d::KEY_S)) camera.Move(camera.forward, -move_speed); 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_A)) camera.Move(camera.right, move_speed);
if (IsKeyDown(kp3d::KEY_D)) 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_SPACE)) camera.position.y += move_speed;
if (IsKeyDown(kp3d::KEY_LSHIFT)) 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_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_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_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_F)) camera.Rotate(kp3d::Camera::AXIS_Y, -qerf_speed);
ResetMouseCursor([&](float x, float y) { camera.UpdateMouseLook({x, y}); }); ResetMouseCursor([&](float x, float y) { camera.UpdateMouseLook({x, y}); });
camera.UpdateMatrix(); camera.UpdateMatrix();
} }