Skip to content

Commit

Permalink
Style: remove indentation from namespace blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed Sep 21, 2024
1 parent b309ce6 commit 7ff86da
Show file tree
Hide file tree
Showing 65 changed files with 5,474 additions and 5,472 deletions.
612 changes: 306 additions & 306 deletions app/next/src/gltf_loader.hpp

Large diffs are not rendered by default.

518 changes: 259 additions & 259 deletions app/next/src/main_window.cpp

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions app/next/src/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@

namespace zephyr {

class MainWindow {
public:
~MainWindow();

void Run();

private:
void Setup();
void MainLoop();
void RenderFrame();
void UpdateFramesPerSecondCounter();
void CreateScene();
void CreateBenchmarkScene();

void CreateVulkanEngine();
void CleanupVulkan();

void CreateOpenGLEngine();
void CleanupOpenGL();

std::unique_ptr<RenderEngine> m_render_engine{};
std::shared_ptr<SceneGraph> m_scene_graph{};
std::shared_ptr<SceneNode> m_camera_node{};
std::shared_ptr<SceneNode> m_behemoth_scene{};
std::vector<SceneNode*> m_dynamic_cubes{};

int m_fps_counter{};
std::chrono::steady_clock::time_point m_time_point_last_update{};
u64 m_frame{};
SDL_Window* m_window{};
std::shared_ptr<VulkanInstance> m_vk_instance{};

VkSurfaceKHR m_vk_surface{VK_NULL_HANDLE};
};
class MainWindow {
public:
~MainWindow();

void Run();

private:
void Setup();
void MainLoop();
void RenderFrame();
void UpdateFramesPerSecondCounter();
void CreateScene();
void CreateBenchmarkScene();

void CreateVulkanEngine();
void CleanupVulkan();

void CreateOpenGLEngine();
void CleanupOpenGL();

std::unique_ptr<RenderEngine> m_render_engine{};
std::shared_ptr<SceneGraph> m_scene_graph{};
std::shared_ptr<SceneNode> m_camera_node{};
std::shared_ptr<SceneNode> m_behemoth_scene{};
std::vector<SceneNode*> m_dynamic_cubes{};

int m_fps_counter{};
std::chrono::steady_clock::time_point m_time_point_last_update{};
u64 m_frame{};
SDL_Window* m_window{};
std::shared_ptr<VulkanInstance> m_vk_instance{};

VkSurfaceKHR m_vk_surface{VK_NULL_HANDLE};
};

} // namespace zephyr
186 changes: 93 additions & 93 deletions zephyr/common/include/zephyr/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,122 +9,122 @@

namespace zephyr::bit {

template<typename T>
constexpr auto number_of_bits() -> uint {
return 8 * sizeof(T);
}

template<typename T, typename U = T>
constexpr auto get_bit(T value, uint bit) -> U {
return static_cast<U>((value >> bit) & 1);
}

template<typename T, typename U = T>
constexpr auto get_field(T value, uint lowest_bit, uint count) -> U {
return static_cast<U>((value >> lowest_bit) & ~(static_cast<T>(-1) << count));
}

template<typename T>
constexpr auto rotate_right(T value, uint amount) -> T {
auto bits = number_of_bits<T>();
if (amount == 0)
return value;
return (value >> amount) | (value << (bits - amount));
}

namespace detail {
template<typename T>
constexpr auto number_of_bits() -> uint {
return 8 * sizeof(T);
}

template<typename T, typename U = T>
constexpr auto get_bit(T value, uint bit) -> U {
return static_cast<U>((value >> bit) & 1);
}

template<typename T, typename U = T>
constexpr auto get_field(T value, uint lowest_bit, uint count) -> U {
return static_cast<U>((value >> lowest_bit) & ~(static_cast<T>(-1) << count));
constexpr auto build_pattern_mask(const char* pattern) -> T {
auto result = T{};
auto i = 0U;
auto bits = number_of_bits<T>();
while (i < bits && pattern[i] != 0) {
if (pattern[i] == '0' || pattern[i] == '1')
result |= 1ULL << (bits - i - 1);
i++;
}
result >>= bits - i;
return result;
}

template<typename T>
constexpr auto rotate_right(T value, uint amount) -> T {
constexpr auto build_pattern_value(const char* pattern) -> T {
auto result = T{};
auto i = 0U;
auto bits = number_of_bits<T>();
if (amount == 0)
return value;
return (value >> amount) | (value << (bits - amount));
}

namespace detail {
template<typename T>
constexpr auto build_pattern_mask(const char* pattern) -> T {
auto result = T{};
auto i = 0U;
auto bits = number_of_bits<T>();
while (i < bits && pattern[i] != 0) {
if (pattern[i] == '0' || pattern[i] == '1')
result |= 1ULL << (bits - i - 1);
i++;
}
result >>= bits - i;
return result;
while (i < bits && pattern[i] != 0) {
if (pattern[i] == '1')
result |= 1ULL << (bits - i - 1);
i++;
}

template<typename T>
constexpr auto build_pattern_value(const char* pattern) -> T {
auto result = T{};
auto i = 0U;
auto bits = number_of_bits<T>();
while (i < bits && pattern[i] != 0) {
if (pattern[i] == '1')
result |= 1ULL << (bits - i - 1);
i++;
}
result >>= bits - i;
return result;
}
} // namespace zephyr::bit::detail

template<typename T>
constexpr auto match_pattern(T value, const char* pattern) -> bool {
return (value & detail::build_pattern_mask<T>(pattern)) == detail::build_pattern_value<T>(pattern);
result >>= bits - i;
return result;
}
} // namespace zephyr::bit::detail

template<typename T>
constexpr T ones = (T)std::numeric_limits<std::make_unsigned_t<T>>::max();
template<typename T>
constexpr auto match_pattern(T value, const char* pattern) -> bool {
return (value & detail::build_pattern_mask<T>(pattern)) == detail::build_pattern_value<T>(pattern);
}

template<typename T>
constexpr T ones = (T)std::numeric_limits<std::make_unsigned_t<T>>::max();

} // namespace zephyr::bit

namespace zephyr {

template<uint bit, uint length, typename T>
requires std::unsigned_integral<T>
struct Bits {
struct Bit {
constexpr Bit(uint index, T& data) : index{index}, data{&data} {}

constexpr operator unsigned() const {
return (*data >> index) & 1u;
}

constexpr Bit& operator=(unsigned value) {
*data = (*data & ~((T)1 << index)) | (value > 0 ? ((T)1 << index) : 0);
return *this;
}

uint index;
T* data;
};

template<typename U>
constexpr explicit operator U() const {
return (U)((data & mask) >> bit);
}
template<uint bit, uint length, typename T>
requires std::unsigned_integral<T>
struct Bits {
struct Bit {
constexpr Bit(uint index, T& data) : index{index}, data{&data} {}

constexpr operator unsigned() const {
return (data & mask) >> bit;
return (*data >> index) & 1u;
}

template<typename U>
constexpr Bits& operator=(U value) {
data = (data & ~mask) | (((T)value << bit) & mask);
constexpr Bit& operator=(unsigned value) {
*data = (*data & ~((T)1 << index)) | (value > 0 ? ((T)1 << index) : 0);
return *this;
}

constexpr Bit operator[](uint index) {
return {bit + index, data};
}
uint index;
T* data;
};

constexpr bool operator[](uint index) const {
return data & ((T)1 << (bit + index));
}
template<typename U>
constexpr explicit operator U() const {
return (U)((data & mask) >> bit);
}

template<typename U>
constexpr bool operator==(U const& rhs) const {
return (this->operator U()) == rhs;
}
constexpr operator unsigned() const {
return (data & mask) >> bit;
}

private:
static constexpr T mask = bit::ones<T> >> (bit::number_of_bits<T>() - length) << bit;
template<typename U>
constexpr Bits& operator=(U value) {
data = (data & ~mask) | (((T)value << bit) & mask);
return *this;
}

T data;
};
constexpr Bit operator[](uint index) {
return {bit + index, data};
}

constexpr bool operator[](uint index) const {
return data & ((T)1 << (bit + index));
}

template<typename U>
constexpr bool operator==(U const& rhs) const {
return (this->operator U()) == rhs;
}

private:
static constexpr T mask = bit::ones<T> >> (bit::number_of_bits<T>() - length) << bit;

T data;
};

} // namespace zephyr
78 changes: 39 additions & 39 deletions zephyr/common/include/zephyr/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,52 @@

namespace zephyr {

template<typename... Args>
class Event {
public:
using SubID = u64;
using Handler = std::function<void(Args...)>;

struct Subscription {
Subscription(SubID id, Handler handler) : id{id}, handler{handler} {}
SubID id;
Handler handler;
};

Event() = default;
Event(const Event& other) = delete;

Event& operator=(Event const& other) = delete;

void Emit(Args&&... args) const {
for(const Subscription& subscription : m_subscription_list) {
subscription.handler(std::forward<Args>(args)...);
}
template<typename... Args>
class Event {
public:
using SubID = u64;
using Handler = std::function<void(Args...)>;

struct Subscription {
Subscription(SubID id, Handler handler) : id{id}, handler{handler} {}
SubID id;
Handler handler;
};

Event() = default;
Event(const Event& other) = delete;

Event& operator=(Event const& other) = delete;

void Emit(Args&&... args) const {
for(const Subscription& subscription : m_subscription_list) {
subscription.handler(std::forward<Args>(args)...);
}
}

SubID Subscribe(Handler handler) {
return m_subscription_list.emplace_back(NextID(), std::move(handler)).id;
}
SubID Subscribe(Handler handler) {
return m_subscription_list.emplace_back(NextID(), std::move(handler)).id;
}

void Unsubscribe(SubID id) {
const auto match = std::ranges::find_if(m_subscription_list, [id](const Subscription& subscription) { return subscription.id == id; });
if(match != m_subscription_list.end()) {
m_subscription_list.erase(match);
}
void Unsubscribe(SubID id) {
const auto match = std::ranges::find_if(m_subscription_list, [id](const Subscription& subscription) { return subscription.id == id; });
if(match != m_subscription_list.end()) {
m_subscription_list.erase(match);
}
}

private:
SubID NextID() {
if(m_next_id == std::numeric_limits<decltype(m_next_id)>::max()) [[unlikely]] {
ZEPHYR_PANIC("Reached the maximum number of event subscriptions. What?");
}
return m_next_id++;
private:
SubID NextID() {
if(m_next_id == std::numeric_limits<decltype(m_next_id)>::max()) [[unlikely]] {
ZEPHYR_PANIC("Reached the maximum number of event subscriptions. What?");
}
return m_next_id++;
}

SubID m_next_id{0u};
std::vector<Subscription> m_subscription_list{};
};
SubID m_next_id{0u};
std::vector<Subscription> m_subscription_list{};
};

typedef Event<> VoidEvent;
typedef Event<> VoidEvent;

} // namespace zephyr
4 changes: 2 additions & 2 deletions zephyr/common/include/zephyr/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace zephyr {
#endif

using f32 = float;
using f64 = double;
using f32 = float;
using f64 = double;

#ifdef ZEPHYR_SCOPE_FLOAT_TYPES
} // namespace zephyr
Expand Down
Loading

0 comments on commit 7ff86da

Please sign in to comment.