Skip to content

Instantly share code, notes, and snippets.

View unrays's full-sized avatar
🐱
Coding while listening to Bach

Félix-Olivier Dumas unrays

🐱
Coding while listening to Bach
  • Computer Science Student · Cégep de Rimouski
  • Rimouski, Québec
View GitHub Profile
@unrays
unrays / singleton.cpp
Created January 19, 2026 12:51
Modern C++ CRTP singleton implementation
// Copyright (c) December 2025 Félix-Olivier Dumas. All rights reserved.
// Licensed under the terms described in the LICENSE file
template<typename Derived>
struct Singleton {
public:
static Derived& instance() {
static Derived instance(Token{});
return instance;
}
@unrays
unrays / hook.cpp
Created January 19, 2026 12:51
Compile-time event hooks using CRTP in modern C++
// Copyright (c) December 2025 Félix-Olivier Dumas. All rights reserved.
// Licensed under the terms described in the LICENSE file
template<typename Hooked>
struct IEventHookable {
protected:
IEventHookable() {
if constexpr (requires(Hooked h) { h.onCreated(); })
static_cast<Hooked*>(this)->onCreated();
else onCreatedDefault();
@unrays
unrays / unrays_printer.cpp
Last active December 10, 2025 02:44
An elegant and conceptually interesting CRTP-based C++ printer using SFINAE for compile-time static dispatch of variadic arguments.
// Copyright (c) December 2025 Félix-Olivier Dumas. All rights reserved.
// Licensed under the terms described in the LICENSE file
template<typename Variation>
class IPrinter {
public:
template<typename... Args>
auto print(Args&&... args) noexcept ->
std::enable_if_t<std::is_void_v
<decltype(std::declval<Variation>().print(std::declval<Args>()...))>,
@unrays
unrays / main.cpp
Last active December 10, 2025 02:43
Sparse Set and Dense Array Template for ECS in C++ by unrays
// Copyright (c) December 2025 Félix-Olivier Dumas. All rights reserved.
// Licensed under the terms described in the LICENSE file.
template<typename T>
struct Sparse {
private:
static constexpr std::size_t DEFAULT_DENSE_CAPACITY = 2048;
static constexpr std::size_t DEFAULT_SPARSE_CAPACITY = 16384;
inline void error_not_enough_capacity(const std::string& context, size_t required, size_t actual) {
@unrays
unrays / ecs.cpp
Last active December 10, 2025 02:41
High-performance C++ ECS with cache-friendly design
// Copyright (c) November 2025 Félix-Olivier Dumas. All rights reserved.
// Licensed under the terms described in the LICENSE file.
class Registry {
private:
static constexpr std::uint32_t InitialEntityCapacity = 131072;
static constexpr std::uint32_t InitialPoolCapacity = 262143;
std::vector<ComponentMask> _cmask;
std::vector<ComponentMask> _ctype;
@unrays
unrays / Registry.java
Created October 16, 2025 23:52
A Minimal ECS Registry in Java
// Copyright (c) October 2025 Félix-Olivier Dumas. All rights reserved.
// Licensed under the terms described in the LICENSE file
package com.ECS.ecs;
import com.ECS.components.Component;
import java.util.HashMap;
import java.util.Map;