Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare engine for MOJO #430

Merged
merged 21 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5a26940
feat(core): add gamepad.hpp
RiscadoA Jun 18, 2023
5b037a4
feat(core): add gamepad event & state getter
RiscadoA Jun 18, 2023
f120290
feat(core): implement gamepads on GLFWWindow
RiscadoA Jun 18, 2023
b8a6984
feat(engine): add gamepads to input
RiscadoA Jun 18, 2023
b09b361
feat(engine): add gamepad to input plugin
RiscadoA Jun 18, 2023
f1017e0
feat(engine): activate bloom on renderer plugin
RiscadoA Jun 18, 2023
dee9e8d
feat(engine): add LocalToWorld automagically
RiscadoA Jun 18, 2023
94b1ad9
docs(engine): remove unnecessary LocalToWorlds
RiscadoA Jun 18, 2023
fa48649
feat(engine): track collisions for new entities
luishfonseca Jun 18, 2023
41a439a
feat(core): store settings defaults
RiscadoA Jun 18, 2023
d22c3d1
feat(core): allow modifying settings in inspector
RiscadoA Jun 18, 2023
abd7130
fix(engine): allow settings inspector collapse
DiogoMendonc-a Jun 18, 2023
b6f96c8
fix(engine): fix transform plugin
RiscadoA Jun 18, 2023
772a566
feat(engine): add second player automatically
RiscadoA Jun 19, 2023
0bdf5a0
feat(core): draw debug lines
luishfonseca Jun 19, 2023
fcff73c
fix(core): unbork debug lines math
luishfonseca Jun 19, 2023
c6ddd5c
fix(engine): remove innerSpotAngle
RiscadoA Jun 19, 2023
d0beb03
feat(engine): allow editing components
RiscadoA Jun 19, 2023
f77a547
docs: add .0F to float literal
RiscadoA Jun 26, 2023
7581753
feat(engine): make bloom toggleable with settings
RiscadoA Sep 7, 2023
e19e0ae
fix(engine): replace beforeTag by before
RiscadoA Sep 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(CUBOS_CORE_SOURCE
"src/cubos/core/io/glfw_window.hpp"
"src/cubos/core/io/glfw_window.cpp"
"src/cubos/core/io/keyboard.cpp"
"src/cubos/core/io/gamepad.cpp"

"src/cubos/core/gl/debug.cpp"
"src/cubos/core/gl/render_device.cpp"
Expand Down Expand Up @@ -115,6 +116,7 @@ set(CUBOS_CORE_INCLUDE
"include/cubos/core/io/window.hpp"
"include/cubos/core/io/keyboard.hpp"
"include/cubos/core/io/cursor.hpp"
"include/cubos/core/io/gamepad.hpp"

"include/cubos/core/geom/box.hpp"
"include/cubos/core/geom/capsule.hpp"
Expand Down
9 changes: 9 additions & 0 deletions core/include/cubos/core/gl/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ namespace cubos::core::gl
/// @param renderDevice Render device to use.
static void init(RenderDevice& renderDevice);

/// @brief Draws a line that will stay visible for a specified amount of time.
/// @param start Starting point of the line.
/// @param end Ending point of the line.
/// @param relative Whether the ending point is relative to the starting point.
/// @param color Color of the drawn line.
/// @param time How long will it be visible for? If 0, for a single frame.
static void drawLine(glm::vec3 start, glm::vec3 end, bool relative = false, glm::vec3 color = glm::vec3(1),
float time = 0.0F);

/// @brief Draws a filled box that will stay visible for a specified amount of time.
/// @param box Box to draw.
/// @param transform Transformation matrix to apply to the box.
Expand Down
3 changes: 1 addition & 2 deletions core/include/cubos/core/gl/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ namespace cubos::core::gl
float intensity;
float range;
float spotAngle;
float innerSpotAngle;

SpotLight(const glm::vec3& position, const glm::quat& rotation, const glm::vec3& color, float intensity,
float range, float spotAngle, float innerSpotAngle);
float range, float spotAngle);
};

/// @brief Describes a directional light.
Expand Down
102 changes: 102 additions & 0 deletions core/include/cubos/core/io/gamepad.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/// @file
/// @brief Struct Gref cubos::core::io::GamepadState and related enums.
/// @ingroup core-io

#pragma once

#include <string>

namespace cubos::core::io
{
/// @brief Gamepad buttons.
/// @ingroup core-io
enum class GamepadButton
{
Invalid = -1,

A,
B,
X,
Y,
LBumper,
RBumper,
Back,
Start,
Guide,
LThumb,
RThumb,
Up,
Right,
Down,
Left,

Count
};

/// @brief Gamepad axes.
/// @ingroup core-io
enum class GamepadAxis
{
Invalid = -1,

LX,
LY,
RX,
RY,
LTrigger,
RTrigger,

Count
};

/// @brief Holds the state of a gamepad.
/// @ingroup core-io
struct GamepadState
{
/// @brief Which buttons are pressed, indexed by @ref GamepadButton.
bool buttons[static_cast<int>(GamepadButton::Count)];

/// @brief Values of the axes, indexed by @ref GamepadAxis.
float axes[static_cast<int>(GamepadAxis::Count)];

/// @brief Checks if a button is pressed.
/// @param button Button to check.
/// @return Whether it is pressed or not.
bool pressed(GamepadButton button) const
{
return buttons[static_cast<int>(button)];
}

/// @brief Gets the value of an axis.
/// @param axis Axis to get the value of.
/// @return Value of the axis.
float axis(GamepadAxis axis) const
{
return axes[static_cast<int>(axis)];
}
};

/// @brief Converts a @ref GamepadButton enum to a string.
/// @param button Button to convert.
/// @return String representation.
/// @ingroup core-io
std::string gamepadButtonToString(GamepadButton button);

/// @brief Converts a string to a @ref GamepadButton.
/// @param str String to convert.
/// @return Button.
/// @ingroup core-io
GamepadButton stringToGamepadButton(const std::string& str);

/// @brief Convert a @ref GamepadAxis to a string.
/// @param axis Axis to convert.
/// @return String representation.
/// @ingroup core-io
std::string gamepadAxisToString(GamepadAxis axis);

/// @brief Convert a string to a @ref GamepadAxis.
/// @param str String to convert.
/// @return Axis.
/// @ingroup core-io
GamepadAxis stringToGamepadAxis(const std::string& str);
} // namespace cubos::core::io
17 changes: 16 additions & 1 deletion core/include/cubos/core/io/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <glm/glm.hpp>

#include <cubos/core/io/cursor.hpp>
#include <cubos/core/io/gamepad.hpp>
#include <cubos/core/io/keyboard.hpp>

namespace cubos::core::gl
Expand Down Expand Up @@ -113,10 +114,18 @@ namespace cubos::core::io
char32_t codepoint; ///< Unicode character that was input.
};

/// @brief Event sent when a gamepad is connected or disconnected.
/// @ingroup core-io
struct GamepadConnectionEvent
{
int gamepad; ///< Id of the gamepad.
bool connected; ///< Whether the gamepad was connected.
};

/// @brief Variant that can hold any of the window events.
/// @ingroup core-io
using WindowEvent = std::variant<KeyEvent, ModifiersEvent, MouseButtonEvent, MouseMoveEvent, MouseScrollEvent,
ResizeEvent, TextEvent>;
ResizeEvent, TextEvent, GamepadConnectionEvent>;

/// @brief Handle to a window.
/// @see @ref BaseWindow @copybrief BaseWindow
Expand Down Expand Up @@ -210,6 +219,12 @@ namespace cubos::core::io
/// @return Whether the key and modifiers (or a superset of) are currently pressed.
virtual bool pressed(Key key, Modifiers modifiers = Modifiers::None) const = 0;

/// @brief Gets the state of the specified gamepad.
/// @param gamepad Gamepad to get the state of.
/// @param state State to fill with the gamepad state.
/// @return Whether the gamepad was found.
virtual bool gamepadState(int gamepad, GamepadState& state) const = 0;

protected:
/// @brief Asks the implementation to fill the event queue with new events.
virtual void pollEvents() = 0;
Expand Down
18 changes: 9 additions & 9 deletions core/include/cubos/core/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ namespace cubos::core
///
/// @param key Key.
/// @param value Value.
void setBool(const std::string& key, const bool& value);
void setBool(const std::string& key, bool value);

/// @brief Retrieves the bool setting with the given @p key.
///
/// If no setting exists with such key, returns @p defaultValue.
/// If no setting exists with such key, sets it to @p defaultValue and returns it.
/// If the setting exists but its value is not "true", returns false.
///
/// @param key Key.
/// @param defaultValue Default value.
/// @return Current value.
bool getBool(const std::string& key, const bool& defaultValue) const;
bool getBool(const std::string& key, bool defaultValue);

/// @brief Defines a new string setting.
///
Expand All @@ -49,12 +49,12 @@ namespace cubos::core

/// @brief Retrieves the string setting with the given @p key.
///
/// If no setting exists with such key, returns @p defaultValue.
/// If no setting exists with such key, sets it to @p defaultValue and returns it.
///
/// @param key Key.
/// @param defaultValue Default value.
/// @return Current value.
std::string getString(const std::string& key, const std::string& defaultValue) const;
std::string getString(const std::string& key, const std::string& defaultValue);

/// @brief Defines a new integer setting.
///
Expand All @@ -67,13 +67,13 @@ namespace cubos::core

/// @brief Retrieves the integer setting with the given @p key.
///
/// If no setting exists with such key, returns @p defaultValue.
/// If no setting exists with such key, sets it to @p defaultValue and returns it.
/// If the setting exists but its value is not a valid integer, returns @p defaultValue.
///
/// @param key Key.
/// @param defaultValue Default value.
/// @return Current value.
int getInteger(const std::string& key, int defaultValue) const;
int getInteger(const std::string& key, int defaultValue);

/// @brief Defines a new double setting.
///
Expand All @@ -85,13 +85,13 @@ namespace cubos::core

/// @brief Retrieves the double setting with the given @p key.
///
/// If no setting exists with such key, returns the default value.
/// If no setting exists with such key, sets it to @p defaultValue and returns it.
/// If the setting exists but its value is not a valid double, returns the default value.
///
/// @param key Key.
/// @param defaultValue Default value.
/// @return Current value.
double getDouble(const std::string& key, double defaultValue) const;
double getDouble(const std::string& key, double defaultValue);

/// @brief Merges the settings from @p settingsToMerge.
///
Expand Down
6 changes: 5 additions & 1 deletion core/samples/gl/debug_renderer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ int main()
glm::lookAt(glm::vec3{3 * sinf((float)t), 3, 3 * cosf((float)t)}, glm::vec3{0.0F, 0.0F, 0.0F},
glm::vec3{0.0F, 1.0F, 0.0F});

gl::Debug::drawWireBox(geom::Box{}, glm::mat4{1.0});
// Gizmo
gl::Debug::drawLine(glm::vec3{0.0F}, glm::vec3{1.0F, 0.0F, 0.0F}, true, glm::vec3{1.0F, 0.0F, 0.0F});
gl::Debug::drawLine(glm::vec3{0.0F}, glm::vec3{0.0F, 1.0F, 0.0F}, true, glm::vec3{0.0F, 1.0F, 0.0F});
gl::Debug::drawLine(glm::vec3{0.0F}, glm::vec3{0.0F, 0.0F, 1.0F}, true, glm::vec3{0.0F, 0.0F, 1.0F});

gl::Debug::flush(vp, deltaT);
window->swapBuffers();
while (auto event = window->pollEvent())
Expand Down
12 changes: 12 additions & 0 deletions core/src/cubos/core/gl/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/transform.hpp>

#include <cubos/core/gl/debug.hpp>
Expand Down Expand Up @@ -193,6 +194,17 @@
wireframeRasterState = renderDevice.createRasterState(rsDesc);
}

void Debug::drawLine(glm::vec3 start, glm::vec3 end, bool relative, glm::vec3 color, float time)

Check warning on line 197 in core/src/cubos/core/gl/debug.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/gl/debug.cpp#L197

Added line #L197 was not covered by tests
{
auto vec = relative ? end : end - start;
auto transform = glm::translate(start) * glm::translate(vec / 2.0F) *
glm::orientation(glm::normalize(vec), glm::vec3{0.0F, 1.0F, 0.0F}) *
glm::scale(glm::vec3{0.1F, glm::length(vec), 0.1F});
debugDrawMutex.lock();
requests.push_back(DebugDrawRequest{objCube, fillRasterState, transform, time, color});
debugDrawMutex.unlock();

Check warning on line 205 in core/src/cubos/core/gl/debug.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/gl/debug.cpp#L199-L205

Added lines #L199 - L205 were not covered by tests
}

void Debug::drawBox(geom::Box box, glm::mat4 transform, glm::vec3 color, float time)
{
debugDrawMutex.lock();
Expand Down
3 changes: 1 addition & 2 deletions core/src/cubos/core/gl/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
using namespace cubos::core::gl;

SpotLight::SpotLight(const glm::vec3& position, const glm::quat& rotation, const glm::vec3& color, float intensity,
float range, float spotAngle, float innerSpotAngle)
float range, float spotAngle)

Check warning on line 6 in core/src/cubos/core/gl/light.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/gl/light.cpp#L6

Added line #L6 was not covered by tests
: position(position)
, rotation(rotation)
, color(color)
, intensity(intensity)
, range(range)
, spotAngle(spotAngle)
, innerSpotAngle(innerSpotAngle)
{
}

Expand Down
Loading
Loading