From 74367e5fb0cc4abef7b5539784a13f9efd69e1bf Mon Sep 17 00:00:00 2001 From: MrLetsplay2003 Date: Wed, 13 Sep 2023 20:42:01 +0200 Subject: [PATCH] Format code --- src/kekengine/cpp/common/defaults.cpp | 40 ++++----- src/kekengine/cpp/common/engine.cpp | 43 +++++----- src/kekengine/cpp/input/input.cpp | 10 +-- src/kekengine/cpp/object/gameobject.cpp | 2 +- src/kekengine/cpp/object/light.cpp | 30 ++++--- .../cpp/player/defaultplayercontroller.cpp | 10 +-- .../cpp/player/noclipplayercontroller.cpp | 2 - src/kekengine/cpp/player/player.cpp | 4 +- src/kekengine/cpp/player/playercontroller.cpp | 1 - src/kekengine/cpp/render/camera.cpp | 6 +- src/kekengine/cpp/render/fonts.cpp | 30 +++---- src/kekengine/cpp/render/mesh.cpp | 2 +- src/kekengine/cpp/render/shader.cpp | 12 +-- src/kekengine/cpp/render/texture.cpp | 8 +- src/kekengine/cpp/ui/ui.cpp | 10 +-- src/kekengine/cpp/ui/uielements.cpp | 38 +++++---- src/kekengine/cpp/util/errordialog.cpp | 3 +- src/kekengine/cpp/util/objparser.cpp | 30 +++---- src/kekengine/cpp/util/utils.cpp | 84 +++++++++---------- src/kekengine/include/camera.h | 3 +- src/kekengine/include/color.h | 39 +++++---- .../include/defaultplayercontroller.h | 7 +- src/kekengine/include/fonts.h | 17 ++-- src/kekengine/include/gameobject.h | 9 +- src/kekengine/include/internal.h | 6 +- src/kekengine/include/internal/input.h | 8 +- src/kekengine/include/internal/physics.h | 29 ++++--- src/kekengine/include/internal/ui.h | 2 + src/kekengine/include/light.h | 15 ++-- src/kekengine/include/mesh.h | 11 +-- .../include/noclipplayercontroller.h | 5 +- src/kekengine/include/object.h | 24 +++--- src/kekengine/include/objparser.h | 2 +- src/kekengine/include/player.h | 5 +- src/kekengine/include/playercontroller.h | 3 +- src/kekengine/include/scene.h | 3 +- src/kekengine/include/shader.h | 9 +- src/kekengine/include/texture.h | 7 +- src/kekengine/include/types.h | 7 +- src/kekengine/include/ui.h | 39 +++++---- src/kekengine/include/uielements.h | 14 ++-- src/kekengine/include/utils.h | 25 ++++-- src/kekgame/cpp/kekgame.cpp | 71 ++++++++-------- 43 files changed, 365 insertions(+), 360 deletions(-) diff --git a/src/kekengine/cpp/common/defaults.cpp b/src/kekengine/cpp/common/defaults.cpp index 7637d2c..42697d9 100644 --- a/src/kekengine/cpp/common/defaults.cpp +++ b/src/kekengine/cpp/common/defaults.cpp @@ -1,11 +1,11 @@ +#include "defaultplayercontroller.h" #include "input.h" +#include "internal.h" +#include "internal/physics.h" +#include "internal/ui.h" +#include "noclipplayercontroller.h" #include "ui.h" #include "uielements.h" -#include "defaultplayercontroller.h" -#include "noclipplayercontroller.h" -#include "internal.h" -#include "internal/ui.h" -#include "internal/physics.h" namespace kek::Defaults { @@ -88,7 +88,7 @@ static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int ac double x, y; glfwGetCursorPos(kekData.window, &x, &y); doUIMouseHover(x, y); - }else { + } else { Input::setCursorMode(GLFWCursorMode::CAPTURE); for(auto e : UI::getElements()) { @@ -102,7 +102,7 @@ static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int ac kekData.player->controller = kekData.player->noclip ? (PlayerController *) noclipController : (PlayerController *) defaultController; if(kekData.player->noclip) { kekData.physics->world->removeRigidBody(kekData.player->physics->body); - }else { + } else { kekData.physics->world->addRigidBody(kekData.player->physics->body); } } @@ -118,8 +118,7 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d } switch(Input::getCursorMode()) { - case GLFWCursorMode::CAPTURE: - { + case GLFWCursorMode::CAPTURE: { float xoff = lastX - x; float yoff = lastY - y; @@ -131,8 +130,7 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d break; } case GLFWCursorMode::FREE: - case GLFWCursorMode::HIDDEN: - { + case GLFWCursorMode::HIDDEN: { doUIMouseHover(x, y); break; } @@ -142,21 +140,18 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d lastY = y; } -static void defaultMouseButtonCallback(GLFWwindow* window, int button, int action, int mods, void *data) { +static void defaultMouseButtonCallback(GLFWwindow *window, int button, int action, int mods, void *data) { switch(Input::getCursorMode()) { - case GLFWCursorMode::CAPTURE: - { + case GLFWCursorMode::CAPTURE: { // TODO break; } case GLFWCursorMode::FREE: - case GLFWCursorMode::HIDDEN: - { + case GLFWCursorMode::HIDDEN: { switch(action) { case GLFW_PRESS: break; - case GLFW_RELEASE: - { + case GLFW_RELEASE: { double x, y; glfwGetCursorPos(window, &x, &y); doUIMouseClick(x, y, (GLFWMouseButton) button); @@ -188,7 +183,7 @@ void init() { Input::addMouseButtonListener(MouseButtonCallback(defaultMouseButtonCallback, nullptr)); options = new ButtonElement(uiPx(0), uiPx(100), uiPx(100), uiPx(50)); - //UI::addElement(options); + // UI::addElement(options); kekData.player = new Player(); btVector3 positions[2]; @@ -204,23 +199,22 @@ void init() { btTransform from; from.setIdentity(); - from.setOrigin(btVector3(0,0,0)); + from.setOrigin(btVector3(0, 0, 0)); btTransform to; to.setIdentity(); - to.setOrigin(btVector3(1,1,1)); + to.setOrigin(btVector3(1, 1, 1)); btCollisionWorld::ClosestConvexResultCallback cb = btCollisionWorld::ClosestConvexResultCallback(from.getOrigin(), to.getOrigin()); kekData.physics->world->convexSweepTest((btConvexShape *) shape, from, to, cb); kekData.player->physics = new PlayerPhysicsObjectData(); kekData.player->physics->body = body; - kekData.player->moveTo(glm::vec3(5,10,0)); + kekData.player->moveTo(glm::vec3(5, 10, 0)); kekData.player->controller = defaultController; } void destroy() { - } } diff --git a/src/kekengine/cpp/common/engine.cpp b/src/kekengine/cpp/common/engine.cpp index 89befe7..555e3f5 100644 --- a/src/kekengine/cpp/common/engine.cpp +++ b/src/kekengine/cpp/common/engine.cpp @@ -1,33 +1,33 @@ #include "engine.h" -#include +#include #include +#include #include #include #include -#include #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION #include #include -#include "errordialog.h" -#include "objparser.h" -#include "resource.h" #include "camera.h" #include "constants.h" -#include "gameobject.h" -#include "scene.h" #include "defaults.h" +#include "errordialog.h" +#include "gameobject.h" +#include "objparser.h" +#include "physics.h" +#include "resource.h" +#include "scene.h" #include "ui.h" #include "uielements.h" -#include "physics.h" #include "internal.h" -#include "internal/ui.h" #include "internal/input.h" +#include "internal/ui.h" kek::KekData kek::kekData; @@ -42,19 +42,19 @@ static void framebufferSizeCallback(GLFWwindow *window, int w, int h) { } static void glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char *message, const void *userParam) { - //if(id == 0x20071) return; + // if(id == 0x20071) return; if(severity == GL_DEBUG_SEVERITY_NOTIFICATION) return; - std::cout << "OpenGL Debug (" << id << "): " << message << std::endl; + std::cout << "OpenGL Debug (" << id << "): " << message << std::endl; } int init() { // Init GLFW - if (glfwInit() != GL_TRUE) { + if(glfwInit() != GL_TRUE) { const char *errorMsg; int code = glfwGetError(&errorMsg); if(code != GLFW_NO_ERROR) { ErrorDialog::showError("Failed to initialize GLFW: " + std::string(errorMsg) + std::string(" (") + std::to_string(code) + std::string(")")); - }else { + } else { ErrorDialog::showError("Failed to initialize GLFW: Unknown error"); } @@ -79,7 +79,7 @@ int init() { int code = glfwGetError(&errorMsg); if(code != GLFW_NO_ERROR) { ErrorDialog::showError("Failed to create window: " + std::string(errorMsg) + " (" + std::to_string(code) + ")"); - }else { + } else { ErrorDialog::showError("Failed to create window: Unknown error"); } @@ -93,7 +93,7 @@ int init() { // Init GLEW glewExperimental = GL_TRUE; - if (glewInit() != GLEW_OK) { + if(glewInit() != GLEW_OK) { ErrorDialog::showError("Failed to initialize GLEW"); glfwTerminate(); return KEK_ERROR; @@ -105,7 +105,7 @@ int init() { int flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags); - if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) { + if(flags & GL_CONTEXT_FLAG_DEBUG_BIT) { glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(glDebugOutput, nullptr); @@ -122,7 +122,7 @@ int init() { glCullFace(GL_BACK); glClearColor(0.1f, 0.3f, 0.1f, 0.0f); - //glfwSwapInterval(0); + // glfwSwapInterval(0); stbi_set_flip_vertically_on_load(true); @@ -228,23 +228,20 @@ int start() { ShaderLight shLight; memcpy(shLight.color, glm::value_ptr(light->color), sizeof(shLight.color)); switch(light->getType()) { - case LightType::POINT: - { + case LightType::POINT: { PointLight *l = (PointLight *) light; memcpy(&shLight.position, glm::value_ptr(l->getPosition()), sizeof(shLight.position)); memcpy(&shLight.attenuation, glm::value_ptr(glm::vec3(l->constant, l->linear, l->quadratic)), sizeof(shLight.attenuation)); numPointLights++; break; } - case LightType::DIRECTIONAL: - { + case LightType::DIRECTIONAL: { DirectionalLight *l = (DirectionalLight *) light; memcpy(&shLight.direction, glm::value_ptr(l->direction), sizeof(shLight.direction)); numDirectionalLights++; break; } - case LightType::SPOT: - { + case LightType::SPOT: { SpotLight *l = (SpotLight *) light; memcpy(&shLight.position, glm::value_ptr(l->getPosition()), sizeof(shLight.position)); memcpy(&shLight.direction, glm::value_ptr(l->direction), sizeof(shLight.direction)); diff --git a/src/kekengine/cpp/input/input.cpp b/src/kekengine/cpp/input/input.cpp index 92d3b43..f28c7a6 100644 --- a/src/kekengine/cpp/input/input.cpp +++ b/src/kekengine/cpp/input/input.cpp @@ -1,7 +1,7 @@ #include "input.h" -#include #include +#include #include "internal.h" #include "internal/input.h" @@ -55,7 +55,7 @@ void onKeyCharCallback(GLFWwindow *window, unsigned int codepoint) { } } -void onMouseButtonCallback(GLFWwindow* window, int button, int action, int mods) { +void onMouseButtonCallback(GLFWwindow *window, int button, int action, int mods) { for(auto cb : kekData.input->mouseButtonCallbacks) { cb.second(window, button, action, mods); } @@ -157,8 +157,7 @@ KeyboardCapture captureKeyboardInput(KeyCharCallback charCallback, KeyCallback k id, charCallback, keyCallback, - uncaptureCallback - }; + uncaptureCallback}; return id; } @@ -169,8 +168,7 @@ bool uncaptureKeyboardInput(KeyboardCapture capture) { KEK_INVALID_ID, KeyCharCallback(), KeyCallback(), - Callable() - }; + Callable()}; return true; } diff --git a/src/kekengine/cpp/object/gameobject.cpp b/src/kekengine/cpp/object/gameobject.cpp index 58b8bf0..21e0f06 100644 --- a/src/kekengine/cpp/object/gameobject.cpp +++ b/src/kekengine/cpp/object/gameobject.cpp @@ -34,7 +34,7 @@ void GameObject::draw(Shader *shader) { void GameObject::addPhysics(btCollisionShape *shape, float mass, int collisionFlags) { this->physics = new PhysicsObjectData(); - btVector3 inertia = btVector3(0,0,0); + btVector3 inertia = btVector3(0, 0, 0); shape->calculateLocalInertia(mass, inertia); btRigidBody *body = new btRigidBody(mass, new btDefaultMotionState(), shape, inertia); body->setFriction(1); diff --git a/src/kekengine/cpp/object/light.cpp b/src/kekengine/cpp/object/light.cpp index d0514ee..df4165e 100644 --- a/src/kekengine/cpp/object/light.cpp +++ b/src/kekengine/cpp/object/light.cpp @@ -1,7 +1,7 @@ #include -#include "light.h" #include "constants.h" +#include "light.h" namespace kek { @@ -10,40 +10,40 @@ Light::Light(glm::vec3 color) { } Light::~Light() { - } -PointLight::PointLight(glm::vec3 color, float constant, float linear, float quadratic): Light(color) { +PointLight::PointLight(glm::vec3 color, float constant, float linear, float quadratic) + : Light(color) { this->constant = constant; this->linear = linear; this->quadratic = quadratic; } PointLight::~PointLight() { - } LightType PointLight::getType() { return LightType::POINT; } -DirectionalLight::DirectionalLight(glm::vec3 color, glm::vec3 direction): Light(color) { +DirectionalLight::DirectionalLight(glm::vec3 color, glm::vec3 direction) + : Light(color) { this->direction = direction; } DirectionalLight::~DirectionalLight() { - } LightType DirectionalLight::getType() { return LightType::DIRECTIONAL; } -void DirectionalLight::lookAt(glm::vec3 direction){ +void DirectionalLight::lookAt(glm::vec3 direction) { this->direction = direction; } -SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float linear, float quadratic, float innerCutoff, float outerCutoff): Light(color) { +SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float linear, float quadratic, float innerCutoff, float outerCutoff) + : Light(color) { this->direction = direction; this->constant = constant; this->linear = linear; @@ -53,7 +53,6 @@ SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float } SpotLight::~SpotLight() { - } LightType SpotLight::getType() { @@ -65,14 +64,19 @@ void SpotLight::lookAt(glm::vec3 direction) { } LightList::LightList() { - } void LightList::add(Light *light) { switch(light->getType()) { - case LightType::POINT: point.push_back((PointLight *) light); break; - case LightType::DIRECTIONAL: directional.push_back((DirectionalLight *) light); break; - case LightType::SPOT: spot.push_back((SpotLight *) light); break; + case LightType::POINT: + point.push_back((PointLight *) light); + break; + case LightType::DIRECTIONAL: + directional.push_back((DirectionalLight *) light); + break; + case LightType::SPOT: + spot.push_back((SpotLight *) light); + break; } } diff --git a/src/kekengine/cpp/player/defaultplayercontroller.cpp b/src/kekengine/cpp/player/defaultplayercontroller.cpp index e40ff32..f4ccead 100644 --- a/src/kekengine/cpp/player/defaultplayercontroller.cpp +++ b/src/kekengine/cpp/player/defaultplayercontroller.cpp @@ -3,8 +3,8 @@ #include "internal.h" #include "internal/physics.h" -#include #include +#include namespace kek { @@ -31,7 +31,7 @@ static bool castPlayer(glm::vec3 pos, glm::vec3 delta, const btCollisionObject * } static bool checkPlayerGrounded(float groundDistance, float maxWalkAngle, const btCollisionObject **outGround, glm::vec3 *outNormal) { - glm::vec3 groundDir = glm::vec3(0,-groundDistance,0); + glm::vec3 groundDir = glm::vec3(0, -groundDistance, 0); glm::vec3 point; glm::vec3 normal; @@ -49,11 +49,9 @@ static bool checkPlayerGrounded(float groundDistance, float maxWalkAngle, const } DefaultPlayerController::DefaultPlayerController() { - } DefaultPlayerController::~DefaultPlayerController() { - } glm::vec3 DefaultPlayerController::move(glm::vec3 movement) { @@ -61,7 +59,7 @@ glm::vec3 DefaultPlayerController::move(glm::vec3 movement) { glm::vec3 totalMovement = glm::vec3(0); int count = 0; - while (count < 3) { + while(count < 3) { float frac; glm::vec3 normal; bool collision = castPlayer(pos + totalMovement, movement, nullptr, &frac, nullptr, &normal); @@ -96,7 +94,7 @@ void DefaultPlayerController::update() { if(!onGround) { velocity += gravity * kekData.lastFrameTime; - }else{ + } else { velocity = glm::vec3(0); } diff --git a/src/kekengine/cpp/player/noclipplayercontroller.cpp b/src/kekengine/cpp/player/noclipplayercontroller.cpp index 28db572..1c5d86b 100644 --- a/src/kekengine/cpp/player/noclipplayercontroller.cpp +++ b/src/kekengine/cpp/player/noclipplayercontroller.cpp @@ -5,11 +5,9 @@ namespace kek { NoclipPlayerController::NoclipPlayerController() { - } NoclipPlayerController::~NoclipPlayerController() { - } glm::vec3 NoclipPlayerController::move(glm::vec3 movement) { diff --git a/src/kekengine/cpp/player/player.cpp b/src/kekengine/cpp/player/player.cpp index 503fe71..bf6c8da 100644 --- a/src/kekengine/cpp/player/player.cpp +++ b/src/kekengine/cpp/player/player.cpp @@ -5,8 +5,8 @@ namespace kek { -Player::Player(): RotateableObject() { - +Player::Player() + : RotateableObject() { } void Player::rotateTo(glm::quat rotation) { diff --git a/src/kekengine/cpp/player/playercontroller.cpp b/src/kekengine/cpp/player/playercontroller.cpp index 2a644c5..9a12a9e 100644 --- a/src/kekengine/cpp/player/playercontroller.cpp +++ b/src/kekengine/cpp/player/playercontroller.cpp @@ -3,7 +3,6 @@ namespace kek { PlayerController::~PlayerController() { - } } diff --git a/src/kekengine/cpp/render/camera.cpp b/src/kekengine/cpp/render/camera.cpp index 4b739c9..be5bd75 100644 --- a/src/kekengine/cpp/render/camera.cpp +++ b/src/kekengine/cpp/render/camera.cpp @@ -5,8 +5,8 @@ #include #include #include -#include #include +#include #include "object.h" #include "utils.h" @@ -64,7 +64,7 @@ glm::mat4 Camera::transformationMatrix() { float x = sin(rollRad); float y = cos(rollRad); glm::vec3 up = glm::vec3(x, y, 0.0f); - //glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); + // glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); glm::vec3 right = glm::normalize(glm::cross(direction, up)); glm::vec3 cameraUp = glm::normalize(glm::cross(right, direction)); @@ -103,7 +103,7 @@ glm::vec3 Camera::eulerAngles() { float yawDegrees; if(direction.x == 0 && direction.z == 0) { yawDegrees = 0; - }else { + } else { glm::vec2 xz = glm::normalize(glm::vec2(direction.x, direction.z)); // Normalized XZ coordinates yawDegrees = glm::degrees(atan2(-xz.y, xz.x)) + 90.0f; // -z because OpenGL if(yawDegrees > 180.0f) { diff --git a/src/kekengine/cpp/render/fonts.cpp b/src/kekengine/cpp/render/fonts.cpp index cde0e1c..2e8cd5c 100644 --- a/src/kekengine/cpp/render/fonts.cpp +++ b/src/kekengine/cpp/render/fonts.cpp @@ -1,15 +1,15 @@ #include "fonts.h" -#include #include #include -#include #include +#include +#include -#include "shader.h" -#include "engine.h" #include "constants.h" +#include "engine.h" #include "internal.h" +#include "shader.h" #include "unicode.h" namespace kek { @@ -37,7 +37,8 @@ void TextObject::destroy() { blocks.clear(); } -TextObject::TextObject(TextObject &&other): blocks(other.blocks) { +TextObject::TextObject(TextObject &&other) + : blocks(other.blocks) { other.blocks.clear(); } @@ -74,13 +75,12 @@ struct RenderChar { RenderChar(float xPos, float yPos, float w, float h, float texL, float texR, float texU, float texD) { float coords[] = { - xPos, yPos, texL, texU, - xPos, yPos + h, texL, texD, - xPos + w, yPos, texR, texU, - xPos + w, yPos, texR, texU, - xPos, yPos + h, texL, texD, - xPos + w, yPos + h, texR, texD - }; + xPos, yPos, texL, texU, + xPos, yPos + h, texL, texD, + xPos + w, yPos, texR, texU, + xPos + w, yPos, texR, texU, + xPos, yPos + h, texL, texD, + xPos + w, yPos + h, texR, texD}; for(int i = 0; i < 24; i++) data[i] = coords[i]; } }; @@ -142,7 +142,7 @@ void TextObject::loadChars() { auto charsForBlock = chars.find(charBlock); if(charsForBlock != chars.end()) { charsForBlock->second.push_back(rCh); - }else { + } else { std::vector chs; chs.push_back(rCh); chars[charBlock] = chs; @@ -175,7 +175,7 @@ void TextObject::loadChars() { oldBlock->length = textLength; glNamedBufferSubData(oldBlock->vbo, 0, textLength * sizeof(RenderChar), &it->second[0]); - }else { + } else { // Allocate Buffer TextBlock block; allocateBuffer(&block, textLength); @@ -192,7 +192,7 @@ void TextObject::loadChars() { while(it2 != blocks.end()) { if(chars.find(it2->first) == chars.end()) { it2 = blocks.erase(it2); - }else { + } else { it2++; } } diff --git a/src/kekengine/cpp/render/mesh.cpp b/src/kekengine/cpp/render/mesh.cpp index 2535aab..f1641b8 100644 --- a/src/kekengine/cpp/render/mesh.cpp +++ b/src/kekengine/cpp/render/mesh.cpp @@ -28,7 +28,7 @@ Mesh::Mesh(std::vector vertices, std::vector indices, Material glCreateBuffers(1, &vbo); glCreateBuffers(1, &ebo); - //glBindVertexArray(vao); + // glBindVertexArray(vao); glNamedBufferData(vbo, vertices.size() * sizeof(Vertex), &vertices[0], GL_STATIC_DRAW); glNamedBufferData(ebo, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW); diff --git a/src/kekengine/cpp/render/shader.cpp b/src/kekengine/cpp/render/shader.cpp index 89c9e54..e609254 100644 --- a/src/kekengine/cpp/render/shader.cpp +++ b/src/kekengine/cpp/render/shader.cpp @@ -1,7 +1,7 @@ #include "shader.h" -#include "types.h" -#include "resource.h" #include "constants.h" +#include "resource.h" +#include "types.h" #include @@ -27,7 +27,7 @@ static GLuint compileShader(GLenum type, std::string path) { } stream << includeBuf; delete includeBuf; - }else { + } else { stream << line << '\n'; } } @@ -47,7 +47,8 @@ static GLuint compileShader(GLenum type, std::string path) { if(!success) { char log[512]; glGetShaderInfoLog(shaderID, 512, nullptr, log); - std::cout << "Failed to compile shader \"" << path << "\":\n" << log << std::endl; + std::cout << "Failed to compile shader \"" << path << "\":\n" + << log << std::endl; throw std::exception(); } @@ -76,7 +77,8 @@ static GLuint compileProgram(unsigned int n, GLenum *types, std::string *paths) if(!success) { char log[512]; glGetProgramInfoLog(id, 512, nullptr, log); - std::cout << "Failed to link program:\n" << log << std::endl; + std::cout << "Failed to link program:\n" + << log << std::endl; throw std::exception(); } diff --git a/src/kekengine/cpp/render/texture.cpp b/src/kekengine/cpp/render/texture.cpp index 999ea96..5aa4b70 100644 --- a/src/kekengine/cpp/render/texture.cpp +++ b/src/kekengine/cpp/render/texture.cpp @@ -3,8 +3,8 @@ #include #include -#include "resource.h" #include "internal.h" +#include "resource.h" namespace kek { @@ -18,7 +18,7 @@ static GLuint allocTexture(unsigned char *data, int width, int height, float bor glTextureParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTextureStorage2D(id, 1, GL_RGB8, width, height); glTextureSubImage2D(id, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); - //glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); + // glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); glGenerateTextureMipmap(id); return id; } @@ -36,7 +36,7 @@ Texture::Texture(std::string texturePath) { unsigned char *data = stbi_load_from_memory((stbi_uc *) buf->buffer, buf->length, &width, &height, &nrChannels, 0); delete buf; - float borderColor[] = { 1.0f, 0.0f, 1.0f, 1.0f }; + float borderColor[] = {1.0f, 0.0f, 1.0f, 1.0f}; id = allocTexture(data, width, height, borderColor); stbi_image_free(data); @@ -74,7 +74,7 @@ std::shared_ptr Texture::generateColor(glm::vec3 color) { data[0] = (unsigned char) (color.x * 255); data[1] = (unsigned char) (color.y * 255); data[2] = (unsigned char) (color.z * 255); - float borderColor[4] = { color.x, color.y, color.z, 1.0f }; + float borderColor[4] = {color.x, color.y, color.z, 1.0f}; GLuint tex = allocTexture(data, 1, 1, borderColor); free(data); return std::make_shared(tex); diff --git a/src/kekengine/cpp/ui/ui.cpp b/src/kekengine/cpp/ui/ui.cpp index cb8bd2a..c78a1a5 100644 --- a/src/kekengine/cpp/ui/ui.cpp +++ b/src/kekengine/cpp/ui/ui.cpp @@ -7,12 +7,12 @@ namespace kek { -UIElement::UIElement(UIValue x, UIValue y): x(x), y(y) { - +UIElement::UIElement(UIValue x, UIValue y) + : x(x), + y(y) { } UIElement::~UIElement() { - } // Returns the element's position relative to its parent in pixels @@ -170,7 +170,7 @@ void UIElement::clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button) if(clickedChild != nullptr) { UIPoint childPos = clickedChild->getPosition(); clickedChild->clickAll(UIPoint(pos.x - childPos.x, pos.y - childPos.y), screenPos, button); - }else { + } else { click(pos, screenPos, button); } } @@ -196,7 +196,7 @@ bool UIElement::focusEnterAll(UIPoint pos, UIPoint screenPos) { } if(focusable) { - //UI::focusElement(this); FIXME + // UI::focusElement(this); FIXME return true; } diff --git a/src/kekengine/cpp/ui/uielements.cpp b/src/kekengine/cpp/ui/uielements.cpp index 3f090ea..1275fb5 100644 --- a/src/kekengine/cpp/ui/uielements.cpp +++ b/src/kekengine/cpp/ui/uielements.cpp @@ -7,7 +7,8 @@ namespace kek { -TextElement::TextElement(UIValue x, UIValue y, Font *font): UIElement(x, y) { +TextElement::TextElement(UIValue x, UIValue y, Font *font) + : UIElement(x, y) { this->text = new TextObject(font, "Text"); this->sizePixels = KEK_DEFAULT_FONT_SIZE_PIXELS; this->color = Colors::WHITE; @@ -15,7 +16,8 @@ TextElement::TextElement(UIValue x, UIValue y, Font *font): UIElement(x, y) { this->textBounds = TextBounds::SMALLEST; } -TextElement::TextElement(UIValue x, UIValue y): TextElement(x, y, kekData.ui->defaultFont) {} +TextElement::TextElement(UIValue x, UIValue y) + : TextElement(x, y, kekData.ui->defaultFont) {} TextElement::~TextElement() { delete text; @@ -32,7 +34,7 @@ UIBounds TextElement::getBounds() { switch(textBounds) { case TextBounds::SMALLEST: default: - h = metrics.height; + h = metrics.height; offsetY = metrics.offsetY; break; case TextBounds::LINE: @@ -49,7 +51,6 @@ UIBounds TextElement::getBounds() { default: return offsetUIBounds(w, h, origin); } - } void TextElement::setText(std::string text) { @@ -84,12 +85,12 @@ void TextElement::draw(UIPoint screenPos, glm::mat4 projection) { } } -UIWindow::UIWindow(UIValue x, UIValue y): UIElement(x, y) { +UIWindow::UIWindow(UIValue x, UIValue y) + : UIElement(x, y) { addChild(new TextElement(x, y)); } UIWindow::~UIWindow() { - } UIElementType UIWindow::getType() { @@ -97,19 +98,25 @@ UIElementType UIWindow::getType() { } void UIWindow::draw(UIPoint screenPos, glm::mat4 projection) { - } static float rectangleVerts[] = { - 0.0f, 1.0f, - 1.0f, 1.0f, - 1.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 0.0f, - 0.0f, 1.0f, + 0.0f, + 1.0f, + 1.0f, + 1.0f, + 1.0f, + 0.0f, + 1.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, }; -RectangleElement::RectangleElement(UIValue x, UIValue y, UIValue w, UIValue h): UIElement(x, y) { +RectangleElement::RectangleElement(UIValue x, UIValue y, UIValue w, UIValue h) + : UIElement(x, y) { this->w = w; this->h = h; color = Colors::BLACK; @@ -153,7 +160,8 @@ void RectangleElement::draw(UIPoint screenPos, glm::mat4 projection) { glDrawArrays(GL_TRIANGLES, 0, 6); } -ButtonElement::ButtonElement(UIValue x, UIValue y, UIValue w, UIValue h): RectangleElement(x, y, w, h) { +ButtonElement::ButtonElement(UIValue x, UIValue y, UIValue w, UIValue h) + : RectangleElement(x, y, w, h) { clickable = true; color = Colors::CYAN; diff --git a/src/kekengine/cpp/util/errordialog.cpp b/src/kekengine/cpp/util/errordialog.cpp index f8f497c..42826cb 100644 --- a/src/kekengine/cpp/util/errordialog.cpp +++ b/src/kekengine/cpp/util/errordialog.cpp @@ -44,7 +44,8 @@ static void show(GtkMessageType type, GtkButtonsType buttons, const char *title, gtk_dialog_run(GTK_DIALOG(d)); gtk_widget_destroy(w); gtk_widget_destroy(d); - while(g_main_context_iteration(nullptr, false)); + while(g_main_context_iteration(nullptr, false)) + ; } void showInfo(std::string message) { diff --git a/src/kekengine/cpp/util/objparser.cpp b/src/kekengine/cpp/util/objparser.cpp index b024a16..d983939 100644 --- a/src/kekengine/cpp/util/objparser.cpp +++ b/src/kekengine/cpp/util/objparser.cpp @@ -1,12 +1,12 @@ #include "objparser.h" -#include -#include -#include #include +#include +#include +#include -#include "types.h" #include "resource.h" +#include "types.h" namespace kek::ObjParser { @@ -51,15 +51,15 @@ Mesh *parseMesh(MemoryBuffer *buf, std::string folderPath) { float x, y, z; str >> x >> y >> z; vertexPositions.push_back(glm::vec3(x, y, z)); - }else if(cmd == "vn") { + } else if(cmd == "vn") { float x, y, z; str >> x >> y >> z; vertexNormals.push_back(glm::normalize(glm::vec3(x, y, z))); - }else if(cmd == "vt") { + } else if(cmd == "vt") { float u, v = 1.0f; str >> u >> v; vertexTexCoords.push_back(glm::vec2(u, v)); - }else if(cmd == "f") { + } else if(cmd == "f") { uint32_t v1, v1T, v1N; readFaceVertex(str, &v1, &v1T, &v1N); uint32_t v2, v2T, v2N; @@ -73,14 +73,14 @@ Mesh *parseMesh(MemoryBuffer *buf, std::string folderPath) { indices.push_back(indices.size()); vertices.push_back(Vertex(vertexPositions[v3 - 1], vertexNormals[v3N - 1], vertexTexCoords[v3T - 1])); indices.push_back(indices.size()); - }else if(cmd == "mtllib") { + } else if(cmd == "mtllib") { std::string name; str >> name; std::string mtllibPath = folderPath + name; std::map mats = loadMaterials(mtllibPath); materials.insert(mats.begin(), mats.end()); - }else if(cmd == "usemtl") { + } else if(cmd == "usemtl") { std::string mtlName; str >> mtlName; auto it = materials.find(mtlName); @@ -90,7 +90,7 @@ Mesh *parseMesh(MemoryBuffer *buf, std::string folderPath) { } material = it->second; - }else { + } else { std::cout << "Ignoring unknown/unsupported OBJ command: " << cmd << std::endl; } } @@ -146,23 +146,23 @@ std::map parseMaterials(MemoryBuffer *buf, std::string if(name.length() > 0) mats.emplace(name, makeMaterial(ambient, diffuse, specular, shininess)); str >> name; - }else if(cmd == "Ka") { + } else if(cmd == "Ka") { float r, g, b; str >> r >> g >> b; ambient = Texture::generateColor(glm::vec3(r, g, b)); - }else if(cmd == "Kd") { + } else if(cmd == "Kd") { float r, g, b; str >> r >> g >> b; diffuse = Texture::generateColor(glm::vec3(r, g, b)); - }else if(cmd == "Ks") { + } else if(cmd == "Ks") { float r, g, b; str >> r >> g >> b; specular = Texture::generateColor(glm::vec3(r, g, b)); - }else if(cmd == "Ns") { + } else if(cmd == "Ns") { float s; str >> s; shininess = s; - }else { + } else { std::cout << "Ignoring unknown/unsupported MTL command: " << cmd << std::endl; } } diff --git a/src/kekengine/cpp/util/utils.cpp b/src/kekengine/cpp/util/utils.cpp index d43e439..f76103c 100644 --- a/src/kekengine/cpp/util/utils.cpp +++ b/src/kekengine/cpp/util/utils.cpp @@ -48,53 +48,53 @@ glm::vec3 faceNormal(CubeFace face) { } float cubeTriangles[] = { - // Front - -0.5f, -0.5f, 0.5f, // 0 - 0.5f, -0.5f, 0.5f, // 1 - 0.5f, 0.5f, 0.5f, // 2 - 0.5f, 0.5f, 0.5f, // 2 - -0.5f, 0.5f, 0.5f, // 3 - -0.5f, -0.5f, 0.5f, // 0 + // Front + -0.5f, -0.5f, 0.5f, // 0 + 0.5f, -0.5f, 0.5f, // 1 + 0.5f, 0.5f, 0.5f, // 2 + 0.5f, 0.5f, 0.5f, // 2 + -0.5f, 0.5f, 0.5f, // 3 + -0.5f, -0.5f, 0.5f, // 0 - // Back - 0.5f, -0.5f, -0.5f, // 5 - -0.5f, -0.5f, -0.5f, // 4 - -0.5f, 0.5f, -0.5f, // 7 - -0.5f, 0.5f, -0.5f, // 7 - 0.5f, 0.5f, -0.5f, // 6 - 0.5f, -0.5f, -0.5f, // 5 + // Back + 0.5f, -0.5f, -0.5f, // 5 + -0.5f, -0.5f, -0.5f, // 4 + -0.5f, 0.5f, -0.5f, // 7 + -0.5f, 0.5f, -0.5f, // 7 + 0.5f, 0.5f, -0.5f, // 6 + 0.5f, -0.5f, -0.5f, // 5 - // Up - -0.5f, 0.5f, 0.5f, // 3 - 0.5f, 0.5f, 0.5f, // 2 - 0.5f, 0.5f, -0.5f, // 6 - 0.5f, 0.5f, -0.5f, // 6 - -0.5f, 0.5f, -0.5f, // 7 - -0.5f, 0.5f, 0.5f, // 3 + // Up + -0.5f, 0.5f, 0.5f, // 3 + 0.5f, 0.5f, 0.5f, // 2 + 0.5f, 0.5f, -0.5f, // 6 + 0.5f, 0.5f, -0.5f, // 6 + -0.5f, 0.5f, -0.5f, // 7 + -0.5f, 0.5f, 0.5f, // 3 - // Down - 0.5f, -0.5f, -0.5f, // 5 - 0.5f, -0.5f, 0.5f, // 1 - -0.5f, -0.5f, 0.5f, // 0 - -0.5f, -0.5f, 0.5f, // 0 - -0.5f, -0.5f, -0.5f, // 4 - 0.5f, -0.5f, -0.5f, // 5 + // Down + 0.5f, -0.5f, -0.5f, // 5 + 0.5f, -0.5f, 0.5f, // 1 + -0.5f, -0.5f, 0.5f, // 0 + -0.5f, -0.5f, 0.5f, // 0 + -0.5f, -0.5f, -0.5f, // 4 + 0.5f, -0.5f, -0.5f, // 5 - // Left - -0.5f, -0.5f, -0.5f, // 4 - -0.5f, -0.5f, 0.5f, // 0 - -0.5f, 0.5f, 0.5f, // 3 - -0.5f, 0.5f, 0.5f, // 3 - -0.5f, 0.5f, -0.5f, // 7 - -0.5f, -0.5f, -0.5f, // 4 + // Left + -0.5f, -0.5f, -0.5f, // 4 + -0.5f, -0.5f, 0.5f, // 0 + -0.5f, 0.5f, 0.5f, // 3 + -0.5f, 0.5f, 0.5f, // 3 + -0.5f, 0.5f, -0.5f, // 7 + -0.5f, -0.5f, -0.5f, // 4 - // Right - 0.5f, -0.5f, 0.5f, // 1 - 0.5f, -0.5f, -0.5f, // 5 - 0.5f, 0.5f, -0.5f, // 6 - 0.5f, 0.5f, -0.5f, // 6 - 0.5f, 0.5f, 0.5f, // 2 - 0.5f, -0.5f, 0.5f, // 1 + // Right + 0.5f, -0.5f, 0.5f, // 1 + 0.5f, -0.5f, -0.5f, // 5 + 0.5f, 0.5f, -0.5f, // 6 + 0.5f, 0.5f, -0.5f, // 6 + 0.5f, 0.5f, 0.5f, // 2 + 0.5f, -0.5f, 0.5f, // 1 }; float textureCoordinates[] = { diff --git a/src/kekengine/include/camera.h b/src/kekengine/include/camera.h index d4b2467..5fe0591 100644 --- a/src/kekengine/include/camera.h +++ b/src/kekengine/include/camera.h @@ -8,7 +8,7 @@ namespace kek { class Camera: public DefaultObject { -public: + public: glm::vec3 direction; float roll; @@ -38,7 +38,6 @@ public: glm::vec3 eulerAngles(); void applyEuler(glm::vec3 euler); - }; } \ No newline at end of file diff --git a/src/kekengine/include/color.h b/src/kekengine/include/color.h index a0ee9ac..258222c 100644 --- a/src/kekengine/include/color.h +++ b/src/kekengine/include/color.h @@ -5,11 +5,17 @@ namespace kek { struct Color { float r, g, b, a; - constexpr Color(float r, float g, float b, float a): r(r), g(g), b(b), a(a) {} + constexpr Color(float r, float g, float b, float a) + : r(r), + g(g), + b(b), + a(a) {} - constexpr Color(float r, float g, float b): Color(r, g, b, 1.0) {} + constexpr Color(float r, float g, float b) + : Color(r, g, b, 1.0) {} - constexpr Color(): Color(0,0,0,1) {} + constexpr Color() + : Color(0, 0, 0, 1) {} float *valuePointer() { return &r; @@ -22,24 +28,23 @@ struct Color { constexpr Color brighter(float factor = 0.7) const { return Color(r / factor, g / factor, b / factor, a); } - }; class Colors { -public: - static constexpr Color RED = Color(1.0, 0.0, 0.0); - static constexpr Color ORANGE = Color(1.0, 0.5, 0.0); - static constexpr Color YELLOW = Color(1.0, 1.0, 0.0); - static constexpr Color GREEN = Color(0.0, 1.0, 0.0); - static constexpr Color CYAN = Color(0.0, 1.0, 1.0); - static constexpr Color BLUE = Color(0.0, 0.0, 1.0); - static constexpr Color PURPLE = Color(0.5, 0.0, 0.5); - static constexpr Color MAGENTA = Color(1.0, 0.0, 1.0); - static constexpr Color GRAY = Color(0.5, 0.5, 0.5); - static constexpr Color WHITE = Color(1.0, 1.0, 1.0); - static constexpr Color BLACK = Color(0.0, 0.0, 0.0); - static constexpr Color TRANSPARENT = Color(0.0, 0.0, 0.0, 0.0); + public: + static constexpr Color RED = Color(1.0, 0.0, 0.0); + static constexpr Color ORANGE = Color(1.0, 0.5, 0.0); + static constexpr Color YELLOW = Color(1.0, 1.0, 0.0); + static constexpr Color GREEN = Color(0.0, 1.0, 0.0); + static constexpr Color CYAN = Color(0.0, 1.0, 1.0); + static constexpr Color BLUE = Color(0.0, 0.0, 1.0); + static constexpr Color PURPLE = Color(0.5, 0.0, 0.5); + static constexpr Color MAGENTA = Color(1.0, 0.0, 1.0); + static constexpr Color GRAY = Color(0.5, 0.5, 0.5); + static constexpr Color WHITE = Color(1.0, 1.0, 1.0); + static constexpr Color BLACK = Color(0.0, 0.0, 0.0); + static constexpr Color TRANSPARENT = Color(0.0, 0.0, 0.0, 0.0); Colors() = delete; }; diff --git a/src/kekengine/include/defaultplayercontroller.h b/src/kekengine/include/defaultplayercontroller.h index 2898946..b5356aa 100644 --- a/src/kekengine/include/defaultplayercontroller.h +++ b/src/kekengine/include/defaultplayercontroller.h @@ -1,14 +1,14 @@ #pragma once -#include "playercontroller.h" #include "input.h" +#include "playercontroller.h" namespace kek { class DefaultPlayerController: public PlayerController { -public: - glm::vec3 gravity = glm::vec3(0,-9.81,0); + public: + glm::vec3 gravity = glm::vec3(0, -9.81, 0); float minSlideAngle = 5; float maxWalkAngle = 60; float jumpVelocity = 3; @@ -28,7 +28,6 @@ public: virtual glm::vec3 move(glm::vec3 movement); virtual void update(); - }; } diff --git a/src/kekengine/include/fonts.h b/src/kekengine/include/fonts.h index a13aad3..0fd4b96 100644 --- a/src/kekengine/include/fonts.h +++ b/src/kekengine/include/fonts.h @@ -4,8 +4,8 @@ #include FT_FREETYPE_H #include -#include #include +#include #include "color.h" #include "resource.h" @@ -64,7 +64,7 @@ struct TextBlock { class TextObject { -private: + private: Font *font; std::string text; @@ -73,7 +73,7 @@ private: int width; int height; -public: + public: std::map blocks; TextObject(Font *font, std::string text); @@ -96,18 +96,17 @@ public: TextMetrics getMetrics(int sizePixels); -private: + private: void destroy(); void allocateBuffer(TextBlock *block, int numChars); void loadChars(); - }; class Font { -private: + private: int lineHeight; int ascender; int descender; @@ -117,8 +116,7 @@ private: std::map characterBlocks; -public: - + public: Font(std::string path); ~Font(); @@ -151,9 +149,8 @@ public: // Draws text centered around (x,y) void drawTextCentered(TextObject *textObject, glm::mat4 projection, int x, int y, int sizePixels, Color color); -private: + private: CharacterBlock generateCharacterBlock(unsigned int block); - }; } diff --git a/src/kekengine/include/gameobject.h b/src/kekengine/include/gameobject.h index 5f092d5..67e7a2c 100644 --- a/src/kekengine/include/gameobject.h +++ b/src/kekengine/include/gameobject.h @@ -1,7 +1,7 @@ #pragma once -#include "object.h" #include "mesh.h" +#include "object.h" #include "physics.h" #include @@ -10,10 +10,10 @@ namespace kek { class GameObject: public RotateableObject { -protected: + protected: std::vector meshes; -public: + public: PhysicsObjectData *physics; GameObject(); @@ -31,7 +31,7 @@ public: virtual void rotateTo(glm::quat rotation); - virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0,1,0))); }; + virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0, 1, 0))); }; virtual glm::quat getRotation(); @@ -40,7 +40,6 @@ public: virtual void moveTo(glm::vec3 position); virtual glm::vec3 getPosition(); - }; } diff --git a/src/kekengine/include/internal.h b/src/kekengine/include/internal.h index 7c5ba31..b1e911a 100644 --- a/src/kekengine/include/internal.h +++ b/src/kekengine/include/internal.h @@ -4,13 +4,13 @@ #include #include -#include "input.h" #include "camera.h" +#include "fonts.h" +#include "input.h" +#include "player.h" #include "scene.h" #include "texture.h" -#include "fonts.h" #include "ui.h" -#include "player.h" namespace kek { diff --git a/src/kekengine/include/internal/input.h b/src/kekengine/include/internal/input.h index b6f9160..a3b9c3d 100644 --- a/src/kekengine/include/internal/input.h +++ b/src/kekengine/include/internal/input.h @@ -1,5 +1,9 @@ #pragma once +#include + +#include "../input.h" + namespace kek { struct ActiveKeyboardCapture { @@ -26,8 +30,8 @@ namespace Input { void onCursorPosCallback(GLFWwindow *window, double x, double y); void onKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); void onKeyCharCallback(GLFWwindow *window, unsigned int codepoint); -void onMouseButtonCallback(GLFWwindow* window, int button, int action, int mods); +void onMouseButtonCallback(GLFWwindow *window, int button, int action, int mods); } -} \ No newline at end of file +} diff --git a/src/kekengine/include/internal/physics.h b/src/kekengine/include/internal/physics.h index 8cd72a7..7a76b6e 100644 --- a/src/kekengine/include/internal/physics.h +++ b/src/kekengine/include/internal/physics.h @@ -1,7 +1,10 @@ #pragma once -#include #include +#include +#include + +#include "../physics.h" namespace kek { @@ -17,29 +20,29 @@ struct PlayerPhysicsObjectData: public PhysicsObjectData { btGhostObject *jumpCollider; }; -struct ClosestNotSelfConvexResultCallback : public btCollisionWorld::ConvexResultCallback { - ClosestNotSelfConvexResultCallback(const btVector3& convexFromWorld, const btVector3& convexToWorld, btCollisionObject *self) : - m_self(self), - m_convexFromWorld(convexFromWorld), - m_convexToWorld(convexToWorld), - m_hitCollisionObject(0){} +struct ClosestNotSelfConvexResultCallback: public btCollisionWorld::ConvexResultCallback { + ClosestNotSelfConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, btCollisionObject *self) + : m_self(self), + m_convexFromWorld(convexFromWorld), + m_convexToWorld(convexToWorld), + m_hitCollisionObject(0) {} btCollisionObject *m_self; - btVector3 m_convexFromWorld; //used to calculate hitPointWorld from hitFraction + btVector3 m_convexFromWorld; // used to calculate hitPointWorld from hitFraction btVector3 m_convexToWorld; btVector3 m_hitNormalWorld; btVector3 m_hitPointWorld; - const btCollisionObject* m_hitCollisionObject; + const btCollisionObject *m_hitCollisionObject; - virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& convexResult, bool normalInWorldSpace) { + virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { if(convexResult.m_hitCollisionObject == m_self) return 1.0f; m_closestHitFraction = convexResult.m_hitFraction; m_hitCollisionObject = convexResult.m_hitCollisionObject; - if (normalInWorldSpace) { + if(normalInWorldSpace) { m_hitNormalWorld = convexResult.m_hitNormalLocal; - }else{ - ///need to transform normal into worldspace + } else { + /// need to transform normal into worldspace m_hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis() * convexResult.m_hitNormalLocal; } m_hitPointWorld = convexResult.m_hitPointLocal; diff --git a/src/kekengine/include/internal/ui.h b/src/kekengine/include/internal/ui.h index c1bc33a..e53d6db 100644 --- a/src/kekengine/include/internal/ui.h +++ b/src/kekengine/include/internal/ui.h @@ -1,5 +1,7 @@ #pragma once +#include "../ui.h" + namespace kek { struct UIData { diff --git a/src/kekengine/include/light.h b/src/kekengine/include/light.h index 3072cc9..8022e39 100644 --- a/src/kekengine/include/light.h +++ b/src/kekengine/include/light.h @@ -15,7 +15,7 @@ enum class LightType { class Light { -public: + public: glm::vec3 color; Light(glm::vec3 color); @@ -23,12 +23,11 @@ public: virtual ~Light(); virtual LightType getType() = 0; - }; class PointLight: public Light, public DefaultObject { -public: + public: float constant, linear, quadratic; PointLight(glm::vec3 color, float constant, float linear, float quadratic); @@ -36,12 +35,11 @@ public: ~PointLight(); LightType getType(); - }; class DirectionalLight: public Light { -public: + public: glm::vec3 direction; DirectionalLight(glm::vec3 color, glm::vec3 direction); @@ -51,12 +49,11 @@ public: LightType getType(); void lookAt(glm::vec3 direction); - }; class SpotLight: public Light, public DefaultObject { -public: + public: glm::vec3 direction; float constant, linear, quadratic; float innerCutoff, outerCutoff; @@ -68,12 +65,11 @@ public: LightType getType(); void lookAt(glm::vec3 direction); - }; class LightList { -public: + public: std::vector point; std::vector directional; std::vector spot; @@ -81,7 +77,6 @@ public: LightList(); void add(Light *light); - }; } diff --git a/src/kekengine/include/mesh.h b/src/kekengine/include/mesh.h index 2f89ad3..7e1e7e4 100644 --- a/src/kekengine/include/mesh.h +++ b/src/kekengine/include/mesh.h @@ -1,10 +1,10 @@ #pragma once -#include -#include #include +#include #include #include +#include #include "shader.h" #include "texture.h" @@ -17,24 +17,22 @@ struct Vertex { glm::vec2 texCoords; Vertex(glm::vec3 pos, glm::vec3 normal, glm::vec2 texCoords); - }; struct Material { -public: + public: std::shared_ptr ambient; std::shared_ptr diffuse; std::shared_ptr specular; float shininess; Material(std::shared_ptr ambient, std::shared_ptr diffuse, std::shared_ptr specular, float shininess); - }; class Mesh { -public: + public: std::vector vertices; std::vector indices; Material *material; @@ -46,7 +44,6 @@ public: ~Mesh(); void draw(Shader *shader); - }; } diff --git a/src/kekengine/include/noclipplayercontroller.h b/src/kekengine/include/noclipplayercontroller.h index 397c163..50228aa 100644 --- a/src/kekengine/include/noclipplayercontroller.h +++ b/src/kekengine/include/noclipplayercontroller.h @@ -1,13 +1,13 @@ #pragma once -#include "playercontroller.h" #include "input.h" +#include "playercontroller.h" namespace kek { class NoclipPlayerController: public PlayerController { -public: + public: float noclipSpeed = 6; KeyBinding keyForward = KEK_INVALID_ID; @@ -24,7 +24,6 @@ public: virtual glm::vec3 move(glm::vec3 movement); virtual void update(); - }; } diff --git a/src/kekengine/include/object.h b/src/kekengine/include/object.h index 222f1bd..c3772f2 100644 --- a/src/kekengine/include/object.h +++ b/src/kekengine/include/object.h @@ -7,8 +7,8 @@ namespace kek { class Object { -public: - virtual ~Object() {}; + public: + virtual ~Object(){}; virtual void translate(glm::vec3 delta) = 0; @@ -21,31 +21,29 @@ public: virtual void moveTo(glm::vec3 position) = 0; virtual glm::vec3 getPosition() = 0; - }; class DefaultObject: public Object { -protected: + protected: glm::vec3 position; -public: + public: DefaultObject(); - virtual ~DefaultObject() {}; + virtual ~DefaultObject(){}; virtual void translate(glm::vec3 delta); virtual void moveTo(glm::vec3 position); virtual glm::vec3 getPosition(); - }; class RotateableObject: public Object { -public: - virtual ~RotateableObject() {}; + public: + virtual ~RotateableObject(){}; virtual void rotate(float angle, glm::vec3 axis) = 0; @@ -56,18 +54,17 @@ public: virtual void lookAtPos(glm::vec3 position); virtual glm::quat getRotation() = 0; - }; class DefaultRotateableObject: public RotateableObject, public DefaultObject { -protected: + protected: glm::quat rotation; -public: + public: DefaultRotateableObject(); - virtual ~DefaultRotateableObject() {}; + virtual ~DefaultRotateableObject(){}; virtual void rotate(float angle, glm::vec3 axis); @@ -82,7 +79,6 @@ public: virtual void moveTo(glm::vec3 position) { DefaultObject::moveTo(position); }; virtual glm::vec3 getPosition() { return DefaultObject::getPosition(); }; - }; } diff --git a/src/kekengine/include/objparser.h b/src/kekengine/include/objparser.h index 9e57042..48c069c 100644 --- a/src/kekengine/include/objparser.h +++ b/src/kekengine/include/objparser.h @@ -2,8 +2,8 @@ #include -#include "types.h" #include "mesh.h" +#include "types.h" namespace kek::ObjParser { diff --git a/src/kekengine/include/player.h b/src/kekengine/include/player.h index 51ed08f..2efa846 100644 --- a/src/kekengine/include/player.h +++ b/src/kekengine/include/player.h @@ -7,7 +7,7 @@ namespace kek { class Player: public RotateableObject { -public: + public: PlayerPhysicsObjectData *physics; PlayerController *controller; bool noclip = false; @@ -19,7 +19,7 @@ public: virtual void rotateTo(glm::quat rotation); - virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0,1,0))); }; + virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0, 1, 0))); }; virtual glm::quat getRotation(); @@ -32,7 +32,6 @@ public: virtual glm::vec3 getEyePosition() { return getPosition() + glm::vec3(0, KEK_PLAYER_EYE_OFFSET, 0); } virtual glm::vec3 getFootPosition() { return getPosition() - glm::vec3(0, KEK_PLAYER_HEIGHT / 2, 0); }; - }; } diff --git a/src/kekengine/include/playercontroller.h b/src/kekengine/include/playercontroller.h index b6a819a..ec0f8c1 100644 --- a/src/kekengine/include/playercontroller.h +++ b/src/kekengine/include/playercontroller.h @@ -6,12 +6,11 @@ namespace kek { class PlayerController { -public: + public: virtual ~PlayerController() = 0; virtual glm::vec3 move(glm::vec3 movement) = 0; virtual void update() = 0; - }; } diff --git a/src/kekengine/include/scene.h b/src/kekengine/include/scene.h index 9c641b7..5e31446 100644 --- a/src/kekengine/include/scene.h +++ b/src/kekengine/include/scene.h @@ -9,7 +9,7 @@ namespace kek { class Scene { -public: + public: std::vector objects; LightList *lights; @@ -25,7 +25,6 @@ public: // Draws the scene void draw(Shader *shader); - }; } diff --git a/src/kekengine/include/shader.h b/src/kekengine/include/shader.h index cee8995..39ca47a 100644 --- a/src/kekengine/include/shader.h +++ b/src/kekengine/include/shader.h @@ -1,13 +1,14 @@ #pragma once -#include #include +#include #include "constants.h" namespace kek { #pragma pack(push, 1) + struct ShaderLight { float color[3]; float pad; @@ -18,9 +19,10 @@ struct ShaderLight { float attenuation[3]; // constant, linear, quadratic float pad4; float cutoff[2]; // inner, outer - //float lightSpaceMatrix[16]; // mat4 + // float lightSpaceMatrix[16]; // mat4 float padding[2]; }; + #pragma pack(pop) // Lighting data for shader @@ -33,7 +35,7 @@ struct LightingData { class Shader { -public: + public: unsigned int id; LightingData *lighting; @@ -46,7 +48,6 @@ public: void initLighting(); void use(); - }; } diff --git a/src/kekengine/include/texture.h b/src/kekengine/include/texture.h index 4b0b40b..06014c6 100644 --- a/src/kekengine/include/texture.h +++ b/src/kekengine/include/texture.h @@ -4,15 +4,15 @@ #include #include -#include -#include #include +#include +#include namespace kek { class Texture { -public: + public: GLuint id; std::string path; @@ -27,7 +27,6 @@ public: static std::shared_ptr load(std::string texturePath); static std::shared_ptr generateColor(glm::vec3 color); - }; } diff --git a/src/kekengine/include/types.h b/src/kekengine/include/types.h index fc1f620..86fe244 100644 --- a/src/kekengine/include/types.h +++ b/src/kekengine/include/types.h @@ -1,15 +1,15 @@ #pragma once -#include -#include #include +#include #include +#include namespace kek { class MemoryBuffer: public std::streambuf { -public: + public: char *buffer; size_t length; @@ -22,7 +22,6 @@ public: ~MemoryBuffer() { free(buffer); } - }; } diff --git a/src/kekengine/include/ui.h b/src/kekengine/include/ui.h index 103813e..ef211e5 100644 --- a/src/kekengine/include/ui.h +++ b/src/kekengine/include/ui.h @@ -16,13 +16,20 @@ namespace kek { struct UIPoint { int x, y; - UIPoint(int x, int y): x(x), y(y) {} + + UIPoint(int x, int y) + : x(x), + y(y) {} }; struct UIBounds { int x, y, w, h; - UIBounds(int x, int y, int w, int h): x(x), y(y), w(w), h(h) {} + UIBounds(int x, int y, int w, int h) + : x(x), + y(y), + w(w), + h(h) {} inline bool contains(UIPoint pos) { return pos.x > x && pos.y > y && pos.x < x + w && pos.y < y + h; @@ -115,16 +122,15 @@ struct UIValue { constexpr friend UIValue operator-(const UIValue &lhs, const UIValue &rhs) { return UIValue(lhs) -= rhs; } - }; class UIElement { -protected: + protected: UIElement *parent = nullptr; std::vector children; -public: + public: UIValue x, y; Origin origin = Origin::TOP_LEFT; bool clickable = false; @@ -152,13 +158,13 @@ public: void addChild(UIElement *child); void removeChild(UIElement *child); -protected: + protected: int uiToScreen(UIValue val); static int offsetX(int w, Origin origin); static int offsetY(int h, Origin origin); static UIBounds offsetUIBounds(int w, int h, Origin origin); -public: + public: // Returns the bounds of the element relative to its origin virtual UIBounds getBounds() = 0; @@ -167,22 +173,21 @@ public: void hoverAll(UIPoint pos, UIPoint screenPos); void hoverExitAll(); - virtual void hoverEnter(UIPoint pos, UIPoint screenPos) {}; - virtual void hover(UIPoint pos, UIPoint screenPos) {}; - virtual void hoverExit() {}; + virtual void hoverEnter(UIPoint pos, UIPoint screenPos){}; + virtual void hover(UIPoint pos, UIPoint screenPos){}; + virtual void hoverExit(){}; void clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button); - virtual void click(UIPoint pos, UIPoint screenPos, GLFWMouseButton button) {}; + virtual void click(UIPoint pos, UIPoint screenPos, GLFWMouseButton button){}; bool focusEnterAll(UIPoint pos, UIPoint screenPos); - virtual void focusEnter(UIPoint pos, UIPoint screenPos) {}; - virtual void focusExit() {}; + virtual void focusEnter(UIPoint pos, UIPoint screenPos){}; + virtual void focusExit(){}; UIElement *dragEnterAll(UIPoint pos, UIPoint screenPos); - virtual void dragEnter(UIPoint pos, UIPoint screenPos) {}; - virtual void drag(UIPoint pos, UIPoint screenPos) {}; - virtual void dragExit(UIPoint pos, UIPoint screenPos) {}; - + virtual void dragEnter(UIPoint pos, UIPoint screenPos){}; + virtual void drag(UIPoint pos, UIPoint screenPos){}; + virtual void dragExit(UIPoint pos, UIPoint screenPos){}; }; namespace UI { diff --git a/src/kekengine/include/uielements.h b/src/kekengine/include/uielements.h index cdefe0b..f0a68e3 100644 --- a/src/kekengine/include/uielements.h +++ b/src/kekengine/include/uielements.h @@ -13,7 +13,6 @@ class UIWindow: public UIElement { virtual UIElementType getType(); virtual void draw(UIPoint screenPos, glm::mat4 projection); - }; enum class TextMode { @@ -30,10 +29,10 @@ enum class TextBounds { class TextElement: public UIElement { -protected: + protected: TextObject *text; -public: + public: int sizePixels; Color color; TextMode textMode; @@ -54,18 +53,17 @@ public: std::string getText(); virtual void draw(UIPoint screenPos, glm::mat4 projection); - }; class RectangleElement: public UIElement { -protected: + protected: UIValue w, h; unsigned int vao; unsigned int vbo; -public: + public: Color color; RectangleElement(UIValue x, UIValue y, UIValue w, UIValue h); @@ -77,12 +75,11 @@ public: virtual UIBounds getBounds(); virtual void draw(UIPoint screenPos, glm::mat4 projection); - }; class ButtonElement: public RectangleElement { -public: + public: TextElement *text; Color color; Color hoverColor; @@ -97,7 +94,6 @@ public: virtual void click(UIPoint pos, UIPoint screenPos, GLFWMouseButton button); virtual void draw(UIPoint screenPos, glm::mat4 projection); - }; } diff --git a/src/kekengine/include/utils.h b/src/kekengine/include/utils.h index 8217201..48da7d1 100644 --- a/src/kekengine/include/utils.h +++ b/src/kekengine/include/utils.h @@ -8,19 +8,25 @@ namespace kek { -template -using GenericFunction = void(*)(Args... args); +template +using GenericFunction = void (*)(Args... args); -template +template struct GenericCallable { GenericFunction function; void *data; - GenericCallable(): function(nullptr), data(nullptr) {} + GenericCallable() + : function(nullptr), + data(nullptr) {} - GenericCallable(GenericFunction function): function(function), data(nullptr) {}; + GenericCallable(GenericFunction function) + : function(function), + data(nullptr){}; - GenericCallable(GenericFunction function, void *data): function(function), data(data) {} + GenericCallable(GenericFunction function, void *data) + : function(function), + data(data) {} void operator()(Args... args) { if(function == nullptr) return; @@ -39,7 +45,12 @@ float clampCyclic(int value, int min, int max); float clamp(int value, int min, int max); enum class CubeFace { - FRONT, BACK, UP, DOWN, LEFT, RIGHT + FRONT, + BACK, + UP, + DOWN, + LEFT, + RIGHT }; glm::vec3 faceNormal(CubeFace face); diff --git a/src/kekgame/cpp/kekgame.cpp b/src/kekgame/cpp/kekgame.cpp index be596f9..56cdd29 100644 --- a/src/kekgame/cpp/kekgame.cpp +++ b/src/kekgame/cpp/kekgame.cpp @@ -16,37 +16,40 @@ using namespace kek; static ButtonElement *button; static KeyboardCapture capture = KEK_INVALID_ID; -void periodicCallback(GLFWwindow *window, void *data){ - +void periodicCallback(GLFWwindow *window, void *data) { } -void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data){ - +void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data) { } -void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods, void *data){ - +void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods, void *data) { } void onButtonClick(void *data) { button->color = Colors::RED; button->hoverColor = Colors::ORANGE; - capture = Input::captureKeyboardInput(KeyCharCallback([](GLFWwindow *window, unsigned int codepoint, void *data) { - std::u32string str = Unicode::convertStdToU32(button->text->getText()); - if(codepoint == KEK_INPUT_DELETE) { - str = str.substr(0, str.length() - 1); - }else { - str.push_back(codepoint); - } - button->text->setText(Unicode::convertU32ToStd(str)); - }, nullptr), KeyCallback([](GLFWwindow *window, int key, int scancode, int action, int mods, void *data) { - if(key == GLFW_KEY_ENTER && action == GLFW_PRESS) { - Input::uncaptureKeyboardInput(capture); - } - }, nullptr), Callable([](void *data) { - button->color = Colors::WHITE; - button->hoverColor = Colors::GRAY; - }, nullptr)); + capture = Input::captureKeyboardInput( + KeyCharCallback([](GLFWwindow *window, unsigned int codepoint, void *data) { + std::u32string str = Unicode::convertStdToU32(button->text->getText()); + if(codepoint == KEK_INPUT_DELETE) { + str = str.substr(0, str.length() - 1); + } else { + str.push_back(codepoint); + } + button->text->setText(Unicode::convertU32ToStd(str)); + }, + nullptr), + KeyCallback([](GLFWwindow *window, int key, int scancode, int action, int mods, void *data) { + if(key == GLFW_KEY_ENTER && action == GLFW_PRESS) { + Input::uncaptureKeyboardInput(capture); + } + }, + nullptr), + Callable([](void *data) { + button->color = Colors::WHITE; + button->hoverColor = Colors::GRAY; + }, + nullptr)); } int main(int argc, char **argv) { @@ -58,7 +61,7 @@ int main(int argc, char **argv) { { std::shared_ptr tex = Texture::load("image/white.png"); floor->addMesh(genCubeMesh(100, 1, 100, tex, tex, tex)); - btCollisionShape *shape = new btBoxShape(btVector3(50,0.5,50)); + btCollisionShape *shape = new btBoxShape(btVector3(50, 0.5, 50)); floor->addPhysics(shape, 0, btCollisionObject::CF_STATIC_OBJECT); scene->addObject(floor); } @@ -67,10 +70,10 @@ int main(int argc, char **argv) { { std::shared_ptr tex = Texture::load("image/white.png"); wall->addMesh(genCubeMesh(1, 10, 50, tex, tex, tex)); - btCollisionShape *shape = new btBoxShape(btVector3(0.5,5,25)); + btCollisionShape *shape = new btBoxShape(btVector3(0.5, 5, 25)); wall->addPhysics(shape, 0, btCollisionObject::CF_STATIC_OBJECT); - wall->moveTo(glm::vec3(0,2.5,0)); - wall->rotate(M_PI / 4, glm::vec3(0,0,1)); + wall->moveTo(glm::vec3(0, 2.5, 0)); + wall->rotate(M_PI / 4, glm::vec3(0, 0, 1)); scene->addObject(wall); } @@ -84,7 +87,7 @@ int main(int argc, char **argv) { Mesh *mesh2 = ObjParser::loadMesh("object/cube_colored/Cube.obj"); GameObject *test3 = new GameObject(); - btCollisionShape *shape2 = new btBoxShape(btVector3(1,1,1)); + btCollisionShape *shape2 = new btBoxShape(btVector3(1, 1, 1)); test3->addPhysics(shape2, 0, btCollisionObject::CF_STATIC_OBJECT); test3->addMesh(mesh2); test3->moveTo(glm::vec3(2, 1, 2)); @@ -92,7 +95,7 @@ int main(int argc, char **argv) { for(int i = 0; i < 10; i++) { GameObject *test2 = new GameObject(); - btCollisionShape *shape = new btBoxShape(btVector3(1,1,1)); + btCollisionShape *shape = new btBoxShape(btVector3(1, 1, 1)); test2->addPhysics(shape, 10); test2->addMesh(ObjParser::loadMesh("object/cube_colored/Cube.obj")); test2->moveTo(glm::vec3(1.0f, 5.0f, 3 * i)); @@ -100,15 +103,15 @@ int main(int argc, char **argv) { } PointLight *light = new PointLight(glm::vec3(1), 1, 0, 0.1); - light->moveTo(glm::vec3(0,1,0)); + light->moveTo(glm::vec3(0, 1, 0)); scene->lights->add(light); - //DirectionalLight *l = new DirectionalLight(glm::vec3(1), glm::vec3(1, -1, 1)); - //scene->lights->add(l); + // DirectionalLight *l = new DirectionalLight(glm::vec3(1), glm::vec3(1, -1, 1)); + // scene->lights->add(l); - //SpotLight *spot = new SpotLight(glm::vec3(1), glm::vec3(0, 0, -1), 1, 0, 1, glm::radians(8.0f), glm::radians(15.0f)); - //spot->moveTo(glm::vec3(0, 0, 5)); - //scene->lights->add(spot); + // SpotLight *spot = new SpotLight(glm::vec3(1), glm::vec3(0, 0, -1), 1, 0, 1, glm::radians(8.0f), glm::radians(15.0f)); + // spot->moveTo(glm::vec3(0, 0, 5)); + // scene->lights->add(spot); Engine::setActiveScene(scene);