diff options
-rw-r--r-- | editor/draw.cpp | 4 | ||||
-rw-r--r-- | editor/editor.cpp | 3 | ||||
-rw-r--r-- | src/chunk-collision.cpp | 12 |
3 files changed, 17 insertions, 2 deletions
diff --git a/editor/draw.cpp b/editor/draw.cpp index 9060f865..aa8cc5f0 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -20,6 +20,7 @@ void app::draw_cursor() { constexpr float LINE_WIDTH = 2; auto& shader = M->shader(); + auto& w = M->world(); const auto inactive_color = 0xff00ffff_rgbaf; if (cursor.tile && !cursor.in_imgui) @@ -56,6 +57,9 @@ void app::draw_cursor() auto [_f, _w, anim_mesh] = M->meshes(); const auto offset = Vector3i(Vector2i(sel.offset), 0); const auto pos = cursor.tile->to_signed3()*iTILE_SIZE + offset; + auto [ch, t] = w[*cursor.tile]; + if (!ch.can_place_entity(sel, cursor.tile->local())) + shader.set_tint({1, 0, 1, 0.5f}); anim_mesh.draw(shader, *sel.atlas, sel.r, sel.frame, Vector3(pos), 1); } } diff --git a/editor/editor.cpp b/editor/editor.cpp index 1b0611e1..a1de4b4f 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -110,7 +110,8 @@ void editor::on_click_(world& world, global_coords pos, button b) default: break; case button::place: if (const auto& sel = mode->get_selected()) - mode->place_tile(world, pos, sel, *_app); + if (auto [ch, t] = world[pos]; ch.can_place_entity(sel.proto, pos.local())) + mode->place_tile(world, pos, sel, *_app); break; case button::remove: mode->place_tile(world, pos, {}, *_app); diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index 7cf436a0..9810cee3 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -120,12 +120,22 @@ bool chunk::can_place_entity(const entity_proto& proto, local_coords pos) { (void)ensure_scenery_mesh(); + switch (proto.pass) + { + case pass_mode::blocked: + case pass_mode::see_through: + break; + case pass_mode::pass: + case pass_mode::shoot_through: + return true; + } + const auto center = Vector2(pos)*TILE_SIZE2 + Vector2(proto.offset) + Vector2(proto.bbox_offset), min = center - Vector2(proto.bbox_size/2), max = min + Vector2(proto.bbox_size); bool ret = true; _rtree.Search(min.data(), max.data(), [&](uint64_t data, const auto&) { [[maybe_unused]] auto x = std::bit_cast<collision_data>(data); - if (x.pass == (uint64_t)pass_mode::pass) + if (x.pass == (uint64_t)pass_mode::pass || x.pass == (uint64_t)pass_mode::shoot_through) return true; return ret = false; }); |