Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
GlynLeine committed Nov 28, 2024
1 parent a30a102 commit 3f1f2f6
Show file tree
Hide file tree
Showing 9 changed files with 475 additions and 201 deletions.
36 changes: 24 additions & 12 deletions src/application/context/contexthelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ namespace rythe::application

bool ContextHelper::init()
{
glfwSetErrorCallback([](int code, rsl::cstring desc)
{
log::error("GLFW ERROR {}: {}", code, desc);
});
glfwSetErrorCallback([](int code, rsl::cstring desc) { log::error("GLFW ERROR {}: {}", code, desc); });

bool success = glfwInit();
if (success)
Expand Down Expand Up @@ -86,9 +83,8 @@ namespace rythe::application
mw = mode->width;
mh = mode->height;

overlap =
math::max(0, math::min(wx + ww, mx + mw) - math::max(wx, mx)) *
math::max(0, math::min(wy + wh, my + mh) - math::max(wy, my));
overlap = math::max(0, math::min(wx + ww, mx + mw) - math::max(wx, mx)) *
math::max(0, math::min(wy + wh, my + mh) - math::max(wy, my));

if (bestoverlap < overlap)
{
Expand All @@ -100,7 +96,9 @@ namespace rythe::application
return bestmonitor;
}

void ContextHelper::setWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, math::int2 pos, math::int2 size, int refreshRate)
void ContextHelper::setWindowMonitor(
GLFWwindow* window, GLFWmonitor* monitor, math::int2 pos, math::int2 size, int refreshRate
)
{
glfwSetWindowMonitor(window, monitor, pos.x, pos.y, size.x, size.y, refreshRate);
}
Expand All @@ -125,7 +123,8 @@ namespace rythe::application
return glfwCreateWindow(dim.x, dim.y, title, monitor, share);
}

GLFWwindow* ContextHelper::createWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share)
GLFWwindow*
ContextHelper::createWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share)
{
return glfwCreateWindow(width, height, title, monitor, share);
}
Expand All @@ -139,9 +138,12 @@ namespace rythe::application
{
GLFWwindow* focus = newFocus.load(std::memory_order_acquire);
if (!focus)
{
return;
}

while (!newFocus.compare_exchange_weak(focus, nullptr, std::memory_order_release, std::memory_order_relaxed));
while (!newFocus.compare_exchange_weak(focus, nullptr, std::memory_order_release, std::memory_order_relaxed))
;

glfwHideWindow(focus);
glfwShowWindow(focus);
Expand All @@ -156,7 +158,9 @@ namespace rythe::application
void ContextHelper::setWindowShouldClose(GLFWwindow* window, int value)
{
if (window)
{
glfwSetWindowShouldClose(window, value);
}
}

int ContextHelper::windowShouldClose(GLFWwindow* window)
Expand Down Expand Up @@ -194,7 +198,9 @@ namespace rythe::application
void ContextHelper::destroyWindow(GLFWwindow* window)
{
if (initialized())
{
glfwDestroyWindow(window);
}
}

math::int2 ContextHelper::getFramebufferSize(GLFWwindow* window)
Expand All @@ -207,7 +213,9 @@ namespace rythe::application
void ContextHelper::swapBuffers(GLFWwindow* window)
{
if (initialized())
{
glfwSwapBuffers(window);
}
}

void ContextHelper::swapInterval(int interval)
Expand Down Expand Up @@ -305,12 +313,14 @@ namespace rythe::application
return glfwSetWindowMaximizeCallback(window, callback);
}

GLFWframebuffersizefun ContextHelper::setFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun callback)
GLFWframebuffersizefun
ContextHelper::setFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun callback)
{
return glfwSetFramebufferSizeCallback(window, callback);
}

GLFWwindowcontentscalefun ContextHelper::setWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback)
GLFWwindowcontentscalefun
ContextHelper::setWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback)
{
return glfwSetWindowContentScaleCallback(window, callback);
}
Expand All @@ -323,7 +333,9 @@ namespace rythe::application
int ContextHelper::getGamepadSate(int jid, GLFWgamepadstate* state)
{
if (initialized())
{
return glfwGetGamepadState(jid, state);
}
return 0;
}

Expand Down
13 changes: 9 additions & 4 deletions src/application/context/contexthelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ namespace rythe::application
static int getError(rsl::cstring* desc);
static GLFWmonitor* getPrimaryMonitor();
static GLFWmonitor* getCurrentMonitor(GLFWwindow* window);
static void setWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, math::int2 pos, math::int2 size, int refreshRate);
static void
setWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, math::int2 pos, math::int2 size, int refreshRate);
static const GLFWvidmode* getPrimaryVideoMode();
static const GLFWvidmode* getVideoMode(GLFWmonitor* monitor);
static void windowHint(int hint, int value);
static GLFWwindow* createWindow(math::int2 dim, const char* title, GLFWmonitor* monitor = nullptr, GLFWwindow* share = nullptr);
static GLFWwindow* createWindow(int width, int height, const char* title, GLFWmonitor* monitor = nullptr, GLFWwindow* share = nullptr);
static GLFWwindow*
createWindow(math::int2 dim, const char* title, GLFWmonitor* monitor = nullptr, GLFWwindow* share = nullptr);
static GLFWwindow* createWindow(
int width, int height, const char* title, GLFWmonitor* monitor = nullptr, GLFWwindow* share = nullptr
);
/**@brief Request the input thread to give focus to this window.
*/
static void showWindow(GLFWwindow* window);
Expand Down Expand Up @@ -89,7 +93,8 @@ namespace rythe::application
static GLFWwindowiconifyfun setWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun callback);
static GLFWwindowmaximizefun setWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback);
static GLFWframebuffersizefun setFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun callback);
static GLFWwindowcontentscalefun setWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback);
static GLFWwindowcontentscalefun
setWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback);
static GLFWjoystickfun setJoystickCallback(GLFWjoystickfun callback);
static int getGamepadSate(int jid, GLFWgamepadstate* state);
static void updateGamepadMappings(const char* name);
Expand Down
2 changes: 2 additions & 0 deletions src/application/events/windowevents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ namespace rythe::application
: windowHandle(windowHandle)
{
for (int i = 0; i < count; i++)
{
paths.push_back(cpaths[i]);
}
}
};

Expand Down
137 changes: 68 additions & 69 deletions src/application/input/inputmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,17 @@ namespace rythe::application
MAX_SIZE = 16 + JOYSTICK0
};

static uint8_t value(modifier_keys m)
{
return static_cast<uint8_t>(m);
}
static uint8_t value(modifier_keys m) { return static_cast<uint8_t>(m); }

friend uint8_t operator-(modifier_keys lhs, modifier_keys rhs)
{
return value(lhs) - value(rhs);
}
friend uint8_t operator-(modifier_keys lhs, modifier_keys rhs) { return value(lhs) - value(rhs); }

friend uint8_t operator+(modifier_keys lhs, modifier_keys rhs)
{
return value(lhs) + value(rhs);
}
friend uint8_t operator+(modifier_keys lhs, modifier_keys rhs) { return value(lhs) + value(rhs); }
friend modifier_keys operator+(modifier_keys lhs, uint8_t rhs)
{
return static_cast<modifier_keys>(value(lhs) + rhs);
}
friend uint8_t operator&(modifier_keys lhs, modifier_keys rhs)
{
return value(lhs) & value(rhs);
}
friend uint8_t operator|(modifier_keys lhs, modifier_keys rhs)
{
return value(lhs) | value(rhs);
}
friend uint8_t operator&(modifier_keys lhs, modifier_keys rhs) { return value(lhs) & value(rhs); }
friend uint8_t operator|(modifier_keys lhs, modifier_keys rhs) { return value(lhs) | value(rhs); }

enum class method
{
Expand Down Expand Up @@ -219,53 +204,54 @@ namespace rythe::application
static constexpr bool is_axis(method m)
{
return m == method::MOUSE || m == method::JOY || m == method::SCROLL || m == method::GAMEPAD_LEFT_TRIGGER ||
m == method::GAMEPAD_RIGHT_TRIGGER || m == method::GAMEPAD_LEFT_AXIS || m == method::GAMEPAD_RIGHT_AXIS ||
m == method::GAMEPAD_LEFT_X || m == method::GAMEPAD_LEFT_Y || m == method::GAMEPAD_RIGHT_X ||
m == method::GAMEPAD_RIGHT_Y || m == method::HSCROLL || m == method::VSCROLL ||
m == method::MOUSE_X || m == method::MOUSE_Y;
m == method::GAMEPAD_RIGHT_TRIGGER || m == method::GAMEPAD_LEFT_AXIS ||
m == method::GAMEPAD_RIGHT_AXIS || m == method::GAMEPAD_LEFT_X || m == method::GAMEPAD_LEFT_Y ||
m == method::GAMEPAD_RIGHT_X || m == method::GAMEPAD_RIGHT_Y || m == method::HSCROLL ||
m == method::VSCROLL || m == method::MOUSE_X || m == method::MOUSE_Y;
}

static constexpr bool is_key(method m)
{
return m == method::KEY || m == method::CHAR || m == method::JOY || m == method::MOUSE || m == method::GAMEPAD_A ||
m == method::GAMEPAD_B || m == method::GAMEPAD_X || m == method::GAMEPAD_Y ||
m == method::GAMEPAD_LEFT_BUMPER || m == method::GAMEPAD_RIGHT_BUMPER || m == method::GAMEPAD_BACK ||
m == method::GAMEPAD_START || m == method::GAMEPAD_GUIDE || m == method::GAMEPAD_DPAD_UP ||
m == method::GAMEPAD_DPAD_RIGHT || m == method::GAMEPAD_DPAD_DOWN || m == method::GAMEPAD_DPAD_LEFT ||
m == method::SPACE || m == method::APOSTROPHE || m == method::COMMA || m == method::MINUS ||
m == method::PERIOD || m == method::SLASH || m == method::NUM0 || m == method::NUM1 ||
m == method::NUM2 || m == method::NUM3 || m == method::NUM4 || m == method::NUM5 || m == method::NUM6 ||
m == method::NUM7 || m == method::NUM8 || m == method::NUM9 || m == method::SEMICOLON ||
m == method::EQUAL || m == method::A || m == method::B || m == method::C || m == method::D ||
m == method::E || m == method::F || m == method::G || m == method::H || m == method::I || m == method::J ||
m == method::K || m == method::L || m == method::M || m == method::N || m == method::O || m == method::P ||
m == method::Q || m == method::R || m == method::S || m == method::T || m == method::U || m == method::V ||
m == method::W || m == method::X || m == method::Y || m == method::Z || m == method::LEFT_BRACKET ||
m == method::BACKSLASH || m == method::RIGHT_BRACKET || m == method::GRAVE_ACCENT || m == method::WORLD_1 ||
return m == method::KEY || m == method::CHAR || m == method::JOY || m == method::MOUSE ||
m == method::GAMEPAD_A || m == method::GAMEPAD_B || m == method::GAMEPAD_X ||
m == method::GAMEPAD_Y || m == method::GAMEPAD_LEFT_BUMPER || m == method::GAMEPAD_RIGHT_BUMPER ||
m == method::GAMEPAD_BACK || m == method::GAMEPAD_START || m == method::GAMEPAD_GUIDE ||
m == method::GAMEPAD_DPAD_UP || m == method::GAMEPAD_DPAD_RIGHT || m == method::GAMEPAD_DPAD_DOWN ||
m == method::GAMEPAD_DPAD_LEFT || m == method::SPACE || m == method::APOSTROPHE ||
m == method::COMMA || m == method::MINUS || m == method::PERIOD || m == method::SLASH ||
m == method::NUM0 || m == method::NUM1 || m == method::NUM2 || m == method::NUM3 ||
m == method::NUM4 || m == method::NUM5 || m == method::NUM6 || m == method::NUM7 ||
m == method::NUM8 || m == method::NUM9 || m == method::SEMICOLON || m == method::EQUAL ||
m == method::A || m == method::B || m == method::C || m == method::D || m == method::E ||
m == method::F || m == method::G || m == method::H || m == method::I || m == method::J ||
m == method::K || m == method::L || m == method::M || m == method::N || m == method::O ||
m == method::P || m == method::Q || m == method::R || m == method::S || m == method::T ||
m == method::U || m == method::V || m == method::W || m == method::X || m == method::Y ||
m == method::Z || m == method::LEFT_BRACKET || m == method::BACKSLASH ||
m == method::RIGHT_BRACKET || m == method::GRAVE_ACCENT || m == method::WORLD_1 ||
m == method::WORLD_2 || m == method::ESCAPE || m == method::ENTER || m == method::TAB ||
m == method::BACKSPACE || m == method::INSERT || m == method::DEL || m == method::RIGHT ||
m == method::LEFT || m == method::DOWN || m == method::UP || m == method::PAGE_UP ||
m == method::PAGE_DOWN || m == method::HOME || m == method::END || m == method::CAPS_LOCK ||
m == method::SCROLL_LOCK || m == method::NUM_LOCK || m == method::PRINT_SCREEN || m == method::PAUSE ||
m == method::F1 || m == method::F2 || m == method::F3 || m == method::F4 || m == method::F5 ||
m == method::F6 || m == method::F7 || m == method::F8 || m == method::F9 || m == method::F10 ||
m == method::F11 || m == method::F12 || m == method::F13 || m == method::F14 || m == method::F15 ||
m == method::F16 || m == method::F17 || m == method::F18 || m == method::F19 || m == method::F20 ||
m == method::F21 || m == method::F22 || m == method::F23 || m == method::F24 || m == method::F25 ||
m == method::KP_0 || m == method::KP_1 || m == method::KP_2 || m == method::KP_3 || m == method::KP_4 ||
m == method::KP_5 || m == method::KP_6 || m == method::KP_7 || m == method::KP_8 || m == method::KP_9 ||
m == method::KP_DECIMAL || m == method::KP_DIVIDE || m == method::KP_MULTIPLY || m == method::KP_SUBTRACT ||
m == method::SCROLL_LOCK || m == method::NUM_LOCK || m == method::PRINT_SCREEN ||
m == method::PAUSE || m == method::F1 || m == method::F2 || m == method::F3 || m == method::F4 ||
m == method::F5 || m == method::F6 || m == method::F7 || m == method::F8 || m == method::F9 ||
m == method::F10 || m == method::F11 || m == method::F12 || m == method::F13 || m == method::F14 ||
m == method::F15 || m == method::F16 || m == method::F17 || m == method::F18 || m == method::F19 ||
m == method::F20 || m == method::F21 || m == method::F22 || m == method::F23 || m == method::F24 ||
m == method::F25 || m == method::KP_0 || m == method::KP_1 || m == method::KP_2 ||
m == method::KP_3 || m == method::KP_4 || m == method::KP_5 || m == method::KP_6 ||
m == method::KP_7 || m == method::KP_8 || m == method::KP_9 || m == method::KP_DECIMAL ||
m == method::KP_DIVIDE || m == method::KP_MULTIPLY || m == method::KP_SUBTRACT ||
m == method::KP_ADD || m == method::KP_ENTER || m == method::KP_EQUAL || m == method::LEFT_SHIFT ||
m == method::LEFT_CONTROL || m == method::LEFT_ALT || m == method::LEFT_SUPER || m == method::RIGHT_SHIFT ||
m == method::RIGHT_CONTROL || m == method::RIGHT_ALT || m == method::RIGHT_SUPER || m == method::MENU ||
m == method::MOUSE_LEFT || m == method::MOUSE_MIDDLE || m == method::MOUSE_RIGHT ||
m == method::GAMEPAD_RIGHT_THUMB || m == method::GAMEPAD_LEFT_THUMB;
m == method::LEFT_CONTROL || m == method::LEFT_ALT || m == method::LEFT_SUPER ||
m == method::RIGHT_SHIFT || m == method::RIGHT_CONTROL || m == method::RIGHT_ALT ||
m == method::RIGHT_SUPER || m == method::MENU || m == method::MOUSE_LEFT ||
m == method::MOUSE_MIDDLE || m == method::MOUSE_RIGHT || m == method::GAMEPAD_RIGHT_THUMB ||
m == method::GAMEPAD_LEFT_THUMB;
}

static constexpr bool has_keys_and_axis(method m)
{
return is_key(m) && is_axis(m);
}
static constexpr bool has_keys_and_axis(method m) { return is_key(m) && is_axis(m); }

static constexpr bool is_family(method m)
{
Expand Down Expand Up @@ -406,30 +392,43 @@ namespace rythe::application
case method::JOY:
{
return std::set<method>{
method::GAMEPAD_A, method::GAMEPAD_B, method::GAMEPAD_X, method::GAMEPAD_Y, method::GAMEPAD_LEFT_BUMPER,
method::GAMEPAD_RIGHT_BUMPER, method::GAMEPAD_BACK, method::GAMEPAD_START, method::GAMEPAD_GUIDE,
method::GAMEPAD_DPAD_UP, method::GAMEPAD_DPAD_RIGHT,
method::GAMEPAD_DPAD_DOWN, method::GAMEPAD_DPAD_LEFT, method::GAMEPAD_LEFT_X, method::GAMEPAD_LEFT_Y,
method::GAMEPAD_RIGHT_X, method::GAMEPAD_RIGHT_Y, method::GAMEPAD_LEFT_TRIGGER, method::GAMEPAD_RIGHT_TRIGGER,
method::GAMEPAD_RIGHT_THUMB, method::GAMEPAD_LEFT_THUMB
method::GAMEPAD_A,
method::GAMEPAD_B,
method::GAMEPAD_X,
method::GAMEPAD_Y,
method::GAMEPAD_LEFT_BUMPER,
method::GAMEPAD_RIGHT_BUMPER,
method::GAMEPAD_BACK,
method::GAMEPAD_START,
method::GAMEPAD_GUIDE,
method::GAMEPAD_DPAD_UP,
method::GAMEPAD_DPAD_RIGHT,
method::GAMEPAD_DPAD_DOWN,
method::GAMEPAD_DPAD_LEFT,
method::GAMEPAD_LEFT_X,
method::GAMEPAD_LEFT_Y,
method::GAMEPAD_RIGHT_X,
method::GAMEPAD_RIGHT_Y,
method::GAMEPAD_LEFT_TRIGGER,
method::GAMEPAD_RIGHT_TRIGGER,
method::GAMEPAD_RIGHT_THUMB,
method::GAMEPAD_LEFT_THUMB

};
}
case method::GAMEPAD_LEFT_AXIS:
{
return std::set<method>{
method::GAMEPAD_LEFT_X, method::GAMEPAD_LEFT_Y
};
return std::set<method>{method::GAMEPAD_LEFT_X, method::GAMEPAD_LEFT_Y};
}
case method::GAMEPAD_RIGHT_AXIS:
{
return std::set<method>{
method::GAMEPAD_RIGHT_X, method::GAMEPAD_RIGHT_Y
};
return std::set<method>{method::GAMEPAD_RIGHT_X, method::GAMEPAD_RIGHT_Y};
}
case method::MOUSE:
{
return std::set<method>{method::MOUSE_Y, method::MOUSE_X, method::MOUSE_LEFT, method::MOUSE_MIDDLE, method::MOUSE_RIGHT};
return std::set<method>{
method::MOUSE_Y, method::MOUSE_X, method::MOUSE_LEFT, method::MOUSE_MIDDLE, method::MOUSE_RIGHT
};
}

case method::SCROLL:
Expand Down
Loading

0 comments on commit 3f1f2f6

Please sign in to comment.