Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
path = third_party/sdl
url = https://github.com/gkit-org/SDL.git
branch = release-3.4.x

[submodule "third_party/sdl_image"]
path = third_party/sdl_image
url = https://github.com/gkit-org/SDL_image.git
Expand Down
2 changes: 0 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ set (CORE "gkit_core")
## Core Sources file ##
file(GLOB_RECURSE CORE_SRC
"./application/*.cpp"
"./graphic/*.cpp"
# "./input/*.cpp"
"./scene/*.cpp"
"./resource/*cpp"
"./utils/*.cpp"
Expand Down
3 changes: 2 additions & 1 deletion src/core/application.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "../include/application.hpp"
#include "scene/unit.hpp"
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_log.h>

gkit::Application::Application() noexcept : root(), windows() {
gkit::Application::Application() noexcept : root(), singleton_units(gkit::scene::Unit::create<scene::Unit>()) {
SDL_InitFlags flags = SDL_INIT_AUDIO |
SDL_INIT_EVENTS |
SDL_INIT_GAMEPAD |
Expand Down
33 changes: 0 additions & 33 deletions src/core/graphic/window.cpp

This file was deleted.

7 changes: 3 additions & 4 deletions src/core/include/application.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include "graphic/window.hpp"
#include "scene/unit.hpp"
#include "utils/Singleton.hpp"
#include <atomic>
#include <memory>
#include <vector>

namespace gkit {

class Application {
class Application : public utils::Singleton<Application> {
public:
explicit Application() noexcept;
virtual ~Application() noexcept;
Expand All @@ -21,8 +21,7 @@ namespace gkit {

private:
std::unique_ptr<scene::Unit> root;
std::vector<std::unique_ptr<gkit::graphic::Window>> windows;

std::unique_ptr<scene::Unit> singleton_units;
std::atomic<bool> running = false;
}; // class Application

Expand Down
3 changes: 0 additions & 3 deletions src/core/include/gkit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// Basic
#include <application.hpp>

// Graphic
#include <graphic/window.hpp>

// Scene
#include <scene/unit.hpp>
#include <scene/object.hpp>
Expand Down
28 changes: 0 additions & 28 deletions src/core/include/graphic/window.hpp

This file was deleted.

8 changes: 4 additions & 4 deletions src/core/include/resource/resource_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace gkit::resource {
auto load(std::filesystem::path path) -> std::optional<std::shared_ptr<T>> {
auto cached_res = get_cache(path);
if (cached_res.has_value()) {
return std::static_pointer_cast<T>(cached_res);
auto target_res = std::dynamic_pointer_cast<T>(cached_res);
return target_res == nullptr ? std::nullopt : target_res;
}

auto loaded_res = std::make_shared(T());
Expand All @@ -32,9 +33,8 @@ namespace gkit::resource {
}
};
private:
std::shared_mutex cache_rw_mutex = std::shared_mutex();
std::unordered_map<std::filesystem::path, std::shared_ptr<gkit::resource::Resource>> resource_cache
= std::unordered_map<std::filesystem::path, std::shared_ptr<gkit::resource::Resource>>();
std::shared_mutex cache_rw_mutex {};
std::unordered_map<std::filesystem::path, std::shared_ptr<gkit::resource::Resource>> resource_cache {};

auto push_to_cache(std::shared_ptr<gkit::resource::Resource> res) -> void;
auto get_cache(std::filesystem::path path) -> std::optional<std::shared_ptr<gkit::resource::Resource>>;
Expand Down
10 changes: 8 additions & 2 deletions src/core/include/scene/unit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <memory>

Expand Down Expand Up @@ -170,10 +171,15 @@ namespace gkit::scene {

private: // children management
std::atomic<bool> modified = false;
mutable std::shared_mutex index_cache_rw_mutex;

std::unordered_map<const char*, Unit*> name_map_cache;
mutable std::shared_mutex name_map_cache_rw_mutex;

std::vector<uint32_t> active_index_cache;
mutable std::shared_mutex children_rw_mutex;
mutable std::shared_mutex index_cache_rw_mutex;

std::vector<std::unique_ptr<Unit>> children;
mutable std::shared_mutex children_rw_mutex;

// when (active_index_cache.size() / children.size() <= overload_factor)
// children vector will realloc(call method @ref remap_children_and_cache())
Expand Down
28 changes: 6 additions & 22 deletions src/core/scene/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@ gkit::scene::Unit::Unit() noexcept :
children(std::vector<std::unique_ptr<Unit>>()),
active_index_cache(),
children_rw_mutex() { }
// gkit::scene::Unit::Unit(const Unit&) noexcept {}
// gkit::scene::Unit::Unit(Unit&& other) noexcept :
// name(other.name),
// parent(nullptr),
// modified(true),
// active_index_cache(),
// process_enabled(other.process_enabled.load()),
// ready_to_drop(other.ready_to_drop.load())
// {
// for (auto&& child_ptr : other.children) {
// if (child_ptr == nullptr) continue;
// this->children.push_back(std::move(child_ptr));
// }
// this->update_index_cache();
// }
// gkit::scene::Unit::Unit(std::string&& name) noexcept : gkit::scene::Unit(name) { }


gkit::scene::Unit::Unit(std::string name) noexcept : gkit::scene::Unit() {
this->name = name;
}
Expand Down Expand Up @@ -217,11 +203,11 @@ auto gkit::scene::Unit::iterator::operator--(int) -> iterator {
auto gkit::scene::Unit::iterator::operator==(const iterator& other) const -> bool { return m_owner == other.m_owner && m_pos == other.m_pos; }
auto gkit::scene::Unit::iterator::operator!=(const iterator& other) const -> bool { return !(*this == other); }

auto gkit::scene::Unit::begin() -> iterator{
auto gkit::scene::Unit::begin() -> iterator {
return iterator(this, 0);
}

auto gkit::scene::Unit::end() -> iterator{
auto gkit::scene::Unit::end() -> iterator {
return iterator(this, active_index_cache.size());
}

Expand Down Expand Up @@ -261,13 +247,11 @@ auto gkit::scene::Unit::const_iterator::operator==(const const_iterator& other)
auto gkit::scene::Unit::const_iterator::operator!=(const const_iterator& other) const -> bool { return !(*this == other); }

auto gkit::scene::Unit::begin() const -> const_iterator {
const_cast<Unit*>(this);
return const_iterator(this, 0);
return const_iterator(const_cast<Unit*>(this), 0);
}

auto gkit::scene::Unit::end() const -> const_iterator {
const_cast<Unit*>(this);
return const_iterator(this, active_index_cache.size());
return const_iterator(const_cast<Unit*>(this), active_index_cache.size());
}

auto gkit::scene::Unit::cbegin() const -> const_iterator { return begin(); }
Expand Down
15 changes: 0 additions & 15 deletions test/core/graphic/window_test.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/core/scene/test_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class RootUnit : public Unit {


int main() {
gkit::Application app;
auto& app = gkit::Application::instance();
auto root = Unit::create<RootUnit>("root");
app.set_root(std::move(root));
app.run();
Expand Down
1 change: 1 addition & 0 deletions third_party/sdl
Submodule sdl added at c546c5
1 change: 1 addition & 0 deletions third_party/sdl_image
Submodule sdl_image added at 074262
Loading