Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
403884f
refactor: create class to control meshes
Varnill Oct 9, 2025
22485f3
chore: delete unnecesary code
Varnill Oct 9, 2025
c4097f0
refactor: change structure binding to values_view
Varnill Oct 9, 2025
2b6e6c5
chore: add const for vars in a loop
Varnill Oct 9, 2025
6393d8c
refactor: remove an useless function
Varnill Oct 9, 2025
839298c
refactor: rename vk_loader.cpp/.h
Varnill Oct 9, 2025
b442c20
chore: remove useless code
Varnill Oct 9, 2025
a92e7b5
refactor: move LoaderGLTF to ModelImpl
Varnill Oct 9, 2025
544ca74
refactor: simplify if-else in function
Varnill Oct 9, 2025
9953d9c
chore: add const to the variable
Varnill Oct 9, 2025
9cdba6f
fix if-else, because always return false
Varnill Oct 9, 2025
596d658
refactor: apply designated initializer
Varnill Oct 9, 2025
4cdc8b7
fix: delete symbols
Varnill Oct 9, 2025
f4c53dd
chore: delete useless var
Varnill Oct 9, 2025
d8b08d9
refactor: apply designated initializer
Varnill Oct 9, 2025
65ea896
chore: delete useless semicolon
Varnill Oct 9, 2025
5421de1
refactor: move a var in for-init
Varnill Oct 9, 2025
45ef4bb
chore: add const to vars
Varnill Oct 9, 2025
cc1e4ef
refactor: give MeshController by weak_ptr
Varnill Oct 9, 2025
c80cb3b
refactor: removing the code logic from CtrlImpl
Varnill Oct 9, 2025
e6d1800
chore: add description to classes
Varnill Oct 9, 2025
a2722cb
refactor: delete a redundant arg
Varnill Oct 9, 2025
89a68a1
refactor: string_view to filesystem::path
Varnill Oct 9, 2025
4cec30d
refactor: return value return by create_mesh()
Varnill Oct 9, 2025
30f5ed2
fix descriptors
Varnill Oct 9, 2025
32a3bea
fix
Varnill Oct 9, 2025
61fdc12
fix spdlog
Varnill Oct 9, 2025
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
90 changes: 42 additions & 48 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_COMPILE_WARNING_AS_ERROR": "ON",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
"CMAKE_COMPILE_WARNING_AS_ERROR": "OFF"
},
"toolchainFile": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
},

{
"name": "windows-base",
"hidden": true,
"inherits": "base",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_C_FLAGS_INIT": "/W4 /wd4700",
"CMAKE_CXX_FLAGS_INIT": "/W4 /wd4700"
"CMAKE_C_FLAGS_INIT": "/W4",
"CMAKE_CXX_FLAGS_INIT": "/W4"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},

{
"name": "wx64-debug",
"displayName": "x64 Debug",
Expand All @@ -49,15 +50,35 @@
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "wx86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "wx86-release",
"displayName": "x86 Release",
"inherits": "wx86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-base",
"hidden": true,
"inherits": "base",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_C_FLAGS_INIT": "-Wall -Wextra -pedantic -Wconversion -Wdouble-promotion -Wshadow -Wno-missing-field-initializers",
"CMAKE_CXX_FLAGS_INIT": "-Wall -Wextra -pedantic -Wconversion -Wdouble-promotion -Wshadow -Wno-missing-field-initializers"
"CMAKE_C_FLAGS_INIT": "-Wall -Wextra -pedantic -Wconversion -Wdouble-promotion -Wshadow -Wno-missing-field-initializers -Wno-nullability-extension",
"CMAKE_CXX_FLAGS_INIT": "-Wall -Wextra -pedantic -Wconversion -Wdouble-promotion -Wshadow -Wno-missing-field-initializers -Wno-nullability-extension"
},
"condition": {
"type": "equals",
Expand All @@ -84,53 +105,26 @@
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "wx64-debug",
"configurePreset": "wx64-debug"
},
{
"name": "wx64-release",
"configurePreset": "wx64-release"
},
{
"name": "lx64-debug",
"configurePreset": "lx64-debug"
},
{
"name": "lx64-release",
"configurePreset": "lx64-release"
}
],
"testPresets": [
{
"name": "base",
"output": {
"outputOnFailure": true
"name": "lx86-debug",
"displayName": "x86 Debug",
"inherits": "linux-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"hidden": true
},
{
"name": "wx64-debug",
"inherits": "base",
"configurePreset": "wx64-debug"
},
{
"name": "wx64-release",
"inherits": "base",
"configurePreset": "wx64-release"
},
{
"name": "lx64-debug",
"inherits": "base",
"configurePreset": "lx64-debug"
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "lx64-release",
"inherits": "base",
"configurePreset": "lx64-release"
"name": "lx86-release",
"displayName": "x86 Release",
"inherits": "lx86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}
2 changes: 1 addition & 1 deletion cmake/compileShaders.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(BUILD_SHADERS_SCRIPT "${CMAKE_SOURCE_DIR}/scripts/build_shaders.py")

set(SHADERS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/shaders")
set(SHADERS_DEST_DIR "${CMAKE_BINARY_DIR}/shaders")
set(SHADERS_DEST_DIR "${CMAKE_BINARY_DIR}/demo/shaders")

add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Running build_shaders.py script..."
Expand Down
104 changes: 94 additions & 10 deletions demo/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,100 @@
#include <iostream>
#include <memory>
#include <stdexcept>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform.hpp>
#include <iostream>
#include <ranges>

#include "IController.h"

int main([[maybe_unused]] int argc, [[maybe_unused]] char* args[]) {
try {
const auto controller = createInstance();
controller->init();
} catch (const std::runtime_error& e) {
std::cerr << "Unhandled exception: " << e.what() << '\n';
void createCubes(const std::weak_ptr<const MeshController>& mesh_controller) {
for (int i = 0; i < 5; i++) {
if (const auto sp = mesh_controller.lock()) {
sp->create_mesh("/basicmesh.glb");
} else {
throw std::runtime_error("Cubes could not be created");
}
}
}

double getCurrentGlobalTime() {
// Get the current time point
const auto now = std::chrono::system_clock::now();

// Cast to a time duration since the epoch
const auto durationSinceEpoch = now.time_since_epoch();

// Convert to seconds in double precision
const std::chrono::duration<double> seconds = durationSinceEpoch;

// Return the double value
return seconds.count();
}

void updateCube(const std::shared_ptr<const MeshController>& mesh_controller, Mesh::rid_t rid, int8_t i) {
const double sinValue = std::sin(getCurrentGlobalTime() + static_cast<double>(i)) * 5.;

const glm::mat4 scale = glm::scale(glm::vec3{0.2f});
const glm::mat4 translation = glm::translate(glm::vec3{static_cast<float>(i) - 2.5f, sinValue, 0});
mesh_controller->set_transform(rid, scale * translation);
}

void updateCubes(const std::weak_ptr<const MeshController>& mesh_controller) {
if (const auto sp = mesh_controller.lock()) {
auto meshes = sp->get_meshes();
for (int8_t i {}; const auto key : meshes) {
updateCube(sp, key, i);
++i;
}
} else {
throw std::runtime_error("Cubes could not be updated");
}
}

int main([[maybe_unused]] int argc, [[maybe_unused]] char* args[])
{
try
{
const auto controller = createInstance();
const auto mesh_controller = controller->getMeshController();
createCubes(mesh_controller);

SDL_Event e;
bool bQuit = false;
bool stop_rendering = false;

// main loop
while (!bQuit) {
// Handle events on queue
while (SDL_PollEvent(&e) != 0) {
// close the window when user alt-f4s or clicks the X button
if (e.type == SDL_QUIT) bQuit = true;

if (e.type == SDL_WINDOWEVENT) {
if (e.window.event == SDL_WINDOWEVENT_MINIMIZED) {
stop_rendering = true;
}
if (e.window.event == SDL_WINDOWEVENT_RESTORED) {
stop_rendering = false;
}
}

controller->process_event(e);
}

// do not draw if we are minimized
if (stop_rendering) {
// throttle the speed to avoid the endless spinning
std::this_thread::sleep_for(std::chrono::milliseconds(100));
continue;
}

controller->run();
controller->update();
updateCubes(mesh_controller);
}
} catch (std::runtime_error const& e)
{
std::cerr << "Unhandled exception: " << e.what() << '\n';
}

return 0;
return 0;
}
53 changes: 13 additions & 40 deletions include/IController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string_view>

#include "SDL2/SDL.h"
#include "core/MeshController.h"

/*! \brief
* Interface for interacting with the chip that allows changing keyboard
Expand All @@ -23,57 +24,29 @@ class IController {
* \brief Virtual destructor for the interface.
*/
virtual ~IController() = default;

/*!
* \brief Initializes the controller.
*
* This method initializes the necessary components for the controller.
*/
virtual void init() const = 0;

/*!
* \brief Updates the controller status.
*
* This method updates the internal state or status of the controller.
* \brief Renders a new frame
*/
virtual void update() const = 0;

virtual void run() = 0;
/*!
* \brief Processes incoming events.
*
* \param e Event to be processed.
*
* This method processes the incoming SDL event and performs necessary
* actions.
* \brief Applies updates
*/
virtual void processEvent(SDL_Event &e) const = 0;

virtual void update() = 0;
/*!
* \brief Sends data to change the brightness of the backlight.
*
* \param lvl Level of brightness [0; 100].
*
* This method sends data to the chip to change the brightness level of the
* backlight. The lvl parameter specifies the brightness level from 0 (off)
* to 100 (maximum brightness).
* \brief Gets a controller to interact with meshes
* \return Pointer to the MeshController
*/
// virtual void setBrightness(uint16_t lvl) const = 0;

[[nodiscard]] virtual std::weak_ptr<const MeshController>
getMeshController() = 0;
/*!
* \brief Sends data to change the color of the backlight.
*
* \param color Struct with RGB values (each [0; 255]).
*
* This method sends data to the chip to change the color of the backlight.
* The color parameter is a struct containing RGB values, each ranging from
* 0 to 255.
* \brief Handles user actions (SDL events)
* @param e SDL event
*/
// virtual void setColor(Color color) const = 0;

virtual void process_event(const SDL_Event& e) = 0;
/*!
* \brief Shared pointer type for IController.
*/
using Ptr = std::shared_ptr<const IController>;
using Ptr = std::shared_ptr<IController>;
};

IController::Ptr createInstance();
2 changes: 1 addition & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ target_sources(${PROJECT_NAME}
PRIVATE
Controller.cpp
ControllerImpl.cpp
Mesh.cpp
MeshController.cpp
Model.cpp
ModelImpl.cpp
View.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/core/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

#include "core/ControllerImpl.h"

IController::Ptr createController(IModel::Ptr ptr) {
return std::make_shared<ControllerImpl>(std::move(ptr));
IController::Ptr createController(IModel::Ptr model, IView::Ptr view) {
return std::make_shared<ControllerImpl>(std::move(model), std::move(view));
}
Loading
Loading