Skip to content

Instantly share code, notes, and snippets.

View eliasdaler's full-sized avatar

Elias Daler eliasdaler

View GitHub Profile
@eliasdaler
eliasdaler / tmd_export.py
Last active November 7, 2025 15:09
.blend to .tmd (PS1) export
"""
.blend to TMD export.
Only objects in "Collection" collection are exported, they're automatically joined and triangulated.
Only flat shaded meshes are supported:
Use Color Attribute -> Face Corner (NOT Vertex color).
Run via CLI:
/usr/bin/blender <BLEND_FILE> \
--quiet --python-exit-code 1 \
--background --python tmd_export.py \
@eliasdaler
eliasdaler / tmd.hexpat
Created September 16, 2025 16:43
TMD ImHex parser (unfinished)
import std.io;
import std.core;
import std.sys;
#include <math.hexpat>
struct Vec3Pad {
FixedPoint<s16> x, y, z;
u16 pad [[hidden]];
} [[sealed, format("format_vec3")]];
@eliasdaler
eliasdaler / fmt.lua
Last active February 27, 2023 18:15
string.format is cool, but we can do better
-- depends on https://github.com/kikito/inspect.lua
local inspect = require 'inspect'
local M = {}
local function tostring_impl(v)
if type(v) == "table" then
-- change to inspect(v, {newline=""}) if you want to print everything tables on one line
return inspect(v)
elseif type(v) == "nil" then
@eliasdaler
eliasdaler / 0_bench_test.go
Last active February 17, 2024 08:35
The quest for a good vector library for a gamedev
package main
import (
"testing"
"github.com/go-gl/mathgl/mgl32"
"github.com/kvartborg/vector"
"github.com/ungerik/go3d/vec2"
"gonum.org/v1/gonum/mat"
)
@eliasdaler
eliasdaler / main_test.go
Created December 13, 2021 21:16
Comparison (struct vs kvatbog's vector which uses slices)
package main
import (
"testing"
"github.com/kvartborg/vector"
)
// kvartborg/vector version
type vec = vector.Vector
#include <iostream>
#include <meta.h>
#include <json.h>
using json = nlohmann::json;
struct Entity {
int id;
};
struct Character : Entity {
@eliasdaler
eliasdaler / simple_meta_info_class.cpp
Created September 26, 2017 09:31
Simple meta info class for this article: https://eliasdaler.github.io/meta-stuff
#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>
#include <json.hpp>
using json = nlohmann::json;
template <typename Class>
@eliasdaler
eliasdaler / safe_reference.cpp
Last active June 5, 2021 03:40
Safe reference implementation. C++ part. See https://eliasdaler.github.io/game-object-references for details
#include <sol.hpp>
#include <string>
#include <iostream>
using EntityId = int;
class Entity {
public:
explicit Entity(EntityId id) :
name("John"), id(id)
@eliasdaler
eliasdaler / safe_reference.lua
Last active June 5, 2021 03:40
Safe reference implementation. Lua part. See https://eliasdaler.github.io/game-object-references for details
Handles = {}
local memoizedFuncs = {}
-- metatable which does magic
local mt = {}
mt.__index = function(handle, key)
if not handle.isValid then
print(debug.traceback())
error("Error: handle is not valid!", 2)
end
@eliasdaler
eliasdaler / OBB.cpp
Last active March 21, 2025 07:08
OBB collision check and resolution using SAT (SFML, 2D)
// SAT collision check and resolution
// Public domain
// Usage example:
// if (testCollision(obb1, obb2, mtv)) { // obb1, obb2 - sf::RectangleShape, mtv - sf::Vector2f
// obb1.move(mtv);
// }
static const float NORMAL_TOLERANCE = 0.0001f;
using RectVertexArray = std::array<sf::Vector2f, 4>;