From e8e009e42d71d2c50b9ebde5e0c9a130e286d73b Mon Sep 17 00:00:00 2001 From: Balhau Date: Thu, 2 Jan 2025 17:57:04 +0000 Subject: [PATCH] More on premake refactoring --- app/cnumbers.cpp | 13 ++-- app/gl1.cpp | 126 +++++++++++++++++------------------ app/tinker.cpp | 113 ++++++++++++++++++------------- premake5.lua | 1 + src/engine/math/matrix3d.cpp | 44 ++++++++++-- src/engine/math/matrix3d.hpp | 12 ++-- src/engine/math/point3d.hpp | 14 ++-- src/platform/base.hpp | 1 + src/platform/types.hpp | 2 + 9 files changed, 187 insertions(+), 139 deletions(-) diff --git a/app/cnumbers.cpp b/app/cnumbers.cpp index 81ae648..cd6671c 100644 --- a/app/cnumbers.cpp +++ b/app/cnumbers.cpp @@ -1,12 +1,11 @@ +#include "../src/bmath/complex.hpp" #include -#include "../bmath/complex.hpp" using BMath::Complex; -int main(void) -{ +int main(void) { std::cout << "Complex numbers " << std::endl; - Complex c1(1,1); - Complex c2(2,2); - std::cout << c1 << c2 << c2-c1 << c2+c1 < #include -#include -#include +#include #include +#include #include +#include -#include "../opengl/Shader.h" -#include "../opengl/Renderer.h" -#include "../opengl/VertexBuffer.h" -#include "../opengl/IndexBuffer.h" -#include "../opengl/VertexArray.h" -#include "../opengl/utils.h" +#include "../src/opengl/IndexBuffer.h" +#include "../src/opengl/Renderer.h" +#include "../src/opengl/Shader.h" +#include "../src/opengl/VertexArray.h" +#include "../src/opengl/VertexBuffer.h" +#include "../src/opengl/utils.h" const std::string SHADERS_PATH = "src/opengl/res/shaders/Basic.shader"; -static void error_callback(int error, const char *description) -{ - fputs(description, stderr); +static void error_callback(int error, const char *description) { + fputs(description, stderr); } -static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) -{ - if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) - glfwSetWindowShouldClose(window, GL_TRUE); +static void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) { + if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) + glfwSetWindowShouldClose(window, GL_TRUE); } -int main(void) -{ - GLFWwindow *window; - glfwSetErrorCallback(error_callback); - if (!glfwInit()) - exit(EXIT_FAILURE); - window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); - if (!window) - { - glfwTerminate(); - exit(EXIT_FAILURE); - } - - glfwMakeContextCurrent(window); - glfwSetKeyCallback(window, key_callback); - - int major, minor, revision; - glfwGetVersion(&major, &minor, &revision); - - printf("Running against GLFW %i.%i.%i\n", major, minor, revision); - LOG(glfwGetVersionString()); - - while (!glfwWindowShouldClose(window)) - { - float ratio; - int width, height; - glfwGetFramebufferSize(window, &width, &height); - ratio = width / (float)height; - glViewport(0, 0, width, height); - glClear(GL_COLOR_BUFFER_BIT); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glRotatef((float)glfwGetTime() * 50.f, 0.f, 0.f, 1.f); - glBegin(GL_TRIANGLES); - glColor3f(1.f, 0.f, 0.f); - glVertex3f(-0.6f, -0.4f, 0.f); - glColor3f(0.f, 1.f, 0.f); - glVertex3f(0.6f, -0.4f, 0.f); - glColor3f(0.f, 0.f, 1.f); - glVertex3f(0.f, 0.6f, 0.f); - glEnd(); - glfwSwapBuffers(window); - glfwPollEvents(); - } - glfwDestroyWindow(window); +int main(void) { + GLFWwindow *window; + glfwSetErrorCallback(error_callback); + if (!glfwInit()) + exit(EXIT_FAILURE); + window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); + if (!window) { glfwTerminate(); - exit(EXIT_SUCCESS); + exit(EXIT_FAILURE); + } + + glfwMakeContextCurrent(window); + glfwSetKeyCallback(window, key_callback); + + int major, minor, revision; + glfwGetVersion(&major, &minor, &revision); + + printf("Running against GLFW %i.%i.%i\n", major, minor, revision); + LOG(glfwGetVersionString()); + + while (!glfwWindowShouldClose(window)) { + float ratio; + int width, height; + glfwGetFramebufferSize(window, &width, &height); + ratio = width / (float)height; + glViewport(0, 0, width, height); + glClear(GL_COLOR_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glRotatef((float)glfwGetTime() * 50.f, 0.f, 0.f, 1.f); + glBegin(GL_TRIANGLES); + glColor3f(1.f, 0.f, 0.f); + glVertex3f(-0.6f, -0.4f, 0.f); + glColor3f(0.f, 1.f, 0.f); + glVertex3f(0.6f, -0.4f, 0.f); + glColor3f(0.f, 0.f, 1.f); + glVertex3f(0.f, 0.6f, 0.f); + glEnd(); + glfwSwapBuffers(window); + glfwPollEvents(); + } + glfwDestroyWindow(window); + glfwTerminate(); + exit(EXIT_SUCCESS); } diff --git a/app/tinker.cpp b/app/tinker.cpp index cb64d9b..854d3af 100644 --- a/app/tinker.cpp +++ b/app/tinker.cpp @@ -1,51 +1,39 @@ +#include "../src/platform/dsl/pt.h" #include using namespace std; -#define CALLBACK(init,end) \ -{ \ - .init_cena = init, \ - .end_cena = end \ -} +#define CALLBACK(init, end) \ + { .init_cena = init, .end_cena = end } #define ATTRIBUTE_NO_RETURN __attribute__((__noreturn__)) -#define CALLBACK_ARRAY_SIZE(array) sizeof(array)/sizeof(Callback) +#define CALLBACK_ARRAY_SIZE(array) sizeof(array) / sizeof(Callback) typedef struct Callback { void (*init_cena)(void); void (*end_cena)(void); } Callback; -void end_cena_cool(){ - std::cout << "End cool stuff" << std::endl; -} +void end_cena_cool() { std::cout << "End cool stuff" << std::endl; } -void end_cena_not_cool(){ - std::cout << "End not cool stuff" << std::endl; -} +void end_cena_not_cool() { std::cout << "End not cool stuff" << std::endl; } -void init_cena_cool(){ - std::cout<< "Init cool stuff" << std::endl; -} +void init_cena_cool() { std::cout << "Init cool stuff" << std::endl; } -void init_cena_not_cool(){ - std::cout << "Init not cool stuff" << std::endl; -} +void init_cena_not_cool() { std::cout << "Init not cool stuff" << std::endl; } -void void_func(){ - std::cout << "Void function 1" << std::endl; -} +void void_func() { std::cout << "Void function 1" << std::endl; } void void_func2() ATTRIBUTE_NO_RETURN; -void void_func2(){ - exit(0); -} +void void_func2() { exit(0); } #define COLOR_ARRAY 3 -typedef union Color{ +enum Colors { RED, GREEN, BLUE }; + +typedef union Color { struct { int r; int g; @@ -54,38 +42,67 @@ typedef union Color{ int color_array[COLOR_ARRAY]; } Color; -int main(int argc, char** argv){ - Callback calls[]={ - CALLBACK(init_cena_cool, end_cena_cool), - CALLBACK(init_cena_not_cool,end_cena_not_cool), - CALLBACK(init_cena_cool, end_cena_not_cool), - CALLBACK(init_cena_not_cool, end_cena_cool) - }; +void printColor(const Color &color) { + std::cout << "[" << color.r << "," << color.g << "," << color.b << "]" + << std::endl; +} +Color red = {{ + .r = 1, + .g = 0, + .b = 0, +}}; +Color green = {{ + .r = 0, + .g = 1, + .b = 0, +}}; +Color blue = {{ + .r = 0, + .g = 0, + .b = 1, +}}; - Callback empty_calls[]={}; +Color colors[] = {[RED] = red, [GREEN] = green, [BLUE] = blue}; + +int main(int argc, char **argv) { + Callback callbacks[] = {CALLBACK(init_cena_cool, end_cena_cool), + CALLBACK(init_cena_not_cool, end_cena_not_cool), + CALLBACK(init_cena_cool, end_cena_not_cool), + CALLBACK(init_cena_not_cool, end_cena_cool)}; + + Callback empty_callbacks[] = {}; std::cout << "Hello cenas" << std::endl; - std::cout << "Size of Callback entry bytes:" << sizeof(calls[0]) << std::endl; - std::cout << "Size of Callback array bytes: " << sizeof(calls) << std::endl; - std::cout << "Number of Callback entries: " << sizeof(calls)/sizeof(Callback) << std::endl; - std::cout << "Empty calls size: "<< CALLBACK_ARRAY_SIZE(empty_calls) << std::endl; + std::cout << "Size of Callback entry bytes:" << sizeof(callbacks[0]) + << std::endl; + std::cout << "Size of Callback array bytes: " << sizeof(callbacks) + << std::endl; + std::cout << "Number of Callback entries: " + << sizeof(callbacks) / sizeof(Callback) << std::endl; + std::cout << "Empty callbacks size: " << CALLBACK_ARRAY_SIZE(empty_callbacks) + << std::endl; - int array_size = CALLBACK_ARRAY_SIZE(calls); - int i=0; - for(i=0;ix + v.x, this->y + v.y, this->z + v.z); - }; - inline vector3d operator-(const point3d &b) { - return vector3d(b.x - this->x, b.y - this->y, b.z - this->z); - } }; +inline point3d operator+(const point3d &a, const vector3d &b) { + return point3d(a.x + b.x, a.y + b.y, a.z + b.z); +}; + +inline vector3d operator-(const point3d &a, const point3d &b) { + return vector3d(b.x - a.x, b.y - a.y, b.z - a.z); +} + }; // namespace engine::math diff --git a/src/platform/base.hpp b/src/platform/base.hpp index 52b0bc8..37ad5f4 100644 --- a/src/platform/base.hpp +++ b/src/platform/base.hpp @@ -2,4 +2,5 @@ #include "platform.hpp" #include "types.hpp" +#include #include diff --git a/src/platform/types.hpp b/src/platform/types.hpp index 05c6f29..0b52f91 100644 --- a/src/platform/types.hpp +++ b/src/platform/types.hpp @@ -11,6 +11,8 @@ typedef long int64; typedef char int8; typedef short int16; +#define f_pointer(fp_name, ret_type, ...) ret_type (*fp_name)(__VA_ARGS__) + typedef union { struct { int32 value : 31;