Skip to content

Commit

Permalink
w broken
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed May 24, 2024
1 parent d06dcba commit bf68ae9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/hole.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
#include "hole.hpp"
//#include <mg/Functions.h>

namespace floormat {

using bbox = cut_rectangle_result::bbox;

cut_rectangle_result cut_rectangle(bbox input, bbox hole)
{
auto ihalf = Vector2i{input.bbox_size/2};
auto istart = input.position - ihalf;
auto iend = input.position + Vector2i{input.bbox_size} - ihalf;

auto hhalf = Vector2i{hole.bbox_size/2};
auto hstart = hole.position - hhalf;
auto hend = hole.position + Vector2i{hole.bbox_size} - hhalf;

bool iempty = Vector2ui{input.bbox_size}.product() == 0;
bool hempty = Vector2ui{hole.bbox_size}.product() == 0;

bool outside_before_x = hend.x() >= istart.x();
bool outside_after_x = hstart.x() <= iend.x();
bool affects_start_x = hstart.x() <= istart.x();
bool affects_end_x = hend.x() >= iend.x();

//std::atomic_signal_fence(std::memory_order::relaxed); // compiler-only barrier

#if 1
auto foo = uint8_t(outside_before_x << 0 | outside_after_x << 1 | affects_start_x << 2 | affects_end_x << 3 | iempty << 4 | hempty << 5);
volatile auto bar = foo;
(void)bar;
#endif

return {};
}

} // namespace floormat
30 changes: 30 additions & 0 deletions src/hole.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
#pragma once
#include "object.hpp"
#include <array>

namespace floormat {

struct hole_proto final : object_proto
{
bool affects_render : 1 = true;
bool affects_physics : 1 = false;
};

struct hole : object
{
bool affects_render : 1 = true;
bool affects_physics : 1 = false;

hole(object_id id, class chunk& c, const hole_proto& proto);
};

struct cut_rectangle_result
{
struct bbox
{
Vector2i position;
Vector2ub bbox_size;
};

std::array<bbox, 8> ret;
uint8_t size = 0;

operator ArrayView<const bbox>() const;
};

cut_rectangle_result cut_rectangle(cut_rectangle_result::bbox input, cut_rectangle_result::bbox hole);

} // namespace floormat
1 change: 1 addition & 0 deletions test/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ int App::exec()
FM_TEST(test_math),
FM_TEST(test_astar_pool),
FM_TEST(test_coords),
FM_TEST(test_hole),
FM_TEST(test_bptr),
FM_TEST(test_iptr),
FM_TEST(test_entity),
Expand Down
1 change: 1 addition & 0 deletions test/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void test_critter();
void test_dijkstra();
void test_entity();
void test_hash();
void test_hole();
void test_iptr();
void test_json();
void test_json2();
Expand Down
19 changes: 19 additions & 0 deletions test/hole.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "app.hpp"

namespace floormat {

namespace {

// tests go here
void test1()
{
}

} // namespace

void Test::test_hole()
{
test1();
}

} // namespace floormat

0 comments on commit bf68ae9

Please sign in to comment.