Skip to content

Instantly share code, notes, and snippets.

View waldnercharles's full-sized avatar

Charles Waldner waldnercharles

  • 23:19 (UTC -06:00)
View GitHub Profile
#pragma once
#include <Spaghetti/Vec2.h>
namespace Spaghetti {
template<typename T>
struct Vec2;
template<typename T>
struct Circle {
@waldnercharles
waldnercharles / MessageBus.cs
Created June 22, 2023 15:17
Just an easy, quick, simple ol' message bus.
public readonly struct Subscription : IDisposable
{
private readonly Action? m_Dispose;
public Subscription(Action dispose)
{
m_Dispose = dispose;
}
public void Dispose()
public sealed class ObjectPool<T> : IDisposable where T : Node2D, IPoolable<T>
{
private readonly Node m_Parent;
private readonly PackedScene m_PackedScene;
private readonly string? m_Group;
private readonly HashSet<T> m_Active = new HashSet<T>();
private readonly Stack<T> m_Inactive = new Stack<T>();
private readonly Action<T> m_OnReleased;
#pragma once
#include <pico_ecs.h>
// -- System API --
template<ecs_system_fn F>
inline ecs_id_t ecs_system;
template<ecs_system_fn F, typename... Cs>
ecs_id_t ecs_register_system(ecs_t *ecs, void *udata)
#define SPRITEBATCH_CHECK_BUFFER_GROW(ctx, count, capacity, data, type) \
do { \
if ((ctx->count) >= ctx->capacity) \
{ \
int new_capacity = (ctx->count) * 2; \
void* new_data = SPRITEBATCH_MALLOC(sizeof(type) * new_capacity, ctx->mem_ctx); \
if (!new_data) return 0; \
SPRITEBATCH_MEMCPY(new_data, ctx->data, sizeof(type) * (ctx->count)); \
SPRITEBATCH_FREE(ctx->data, ctx->mem_ctx); \
ctx->data = (type*)new_data; \
-- Shallow copy a table
local function shallow_copy(t)
local copy = {}
for k, v in pairs(t) do
copy[k] = v
end
return copy
end
-- Escape reserved characters
---@meta
---@class CF_Touch
---@field id number
---@field x number
---@field y number
---@field pressure number
---@class CF_ImeComposition
---@field composition string
---@class Profiler
local profiler = {
internal_fns = {},
call_stack = {},
call_tree = {},
clock = function()
return get_ticks() / get_tick_frequency()
end
}
@waldnercharles
waldnercharles / luajit.cmake
Created October 4, 2024 17:11
luajit cmake integration
include(FetchContent)
FetchContent_Declare(
luajit
GIT_REPOSITORY https://github.com/LuaJIT/LuaJIT
GIT_TAG v2.1
)
FetchContent_MakeAvailable(luajit)
if (luajit_ADDED)
uint64_t b2_colorBox2DYellow = 16772748;
uint64_t b2_colorBox2DGreen = 9226532;
uint64_t b2_colorBox2DBlue = 3190463;
uint64_t b2_colorBox2DRed = 14430514;
uint64_t b2_colorYellowGreen = 10145074;
uint64_t b2_colorYellow = 16776960;
uint64_t b2_colorWhiteSmoke = 16119285;
uint64_t b2_colorWhite = 16777215;
uint64_t b2_colorWheat = 16113331;
uint64_t b2_colorVioletRed = 13639824;