Skip to content

Instantly share code, notes, and snippets.

View eliasdaler's full-sized avatar

Elias Daler eliasdaler

View GitHub Profile
@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
void LevelEditor::update(math::Time dt)
{
camera.update(dt);
{
auto& rs = engine_system.getGame().getSystem<RenderingSystem>();
rs.updateView("levelEditor", camera.getView());
}
currentState->update(dt);
@eliasdaler
eliasdaler / main.cpp
Created January 31, 2018 06:37
Eigen test... kinda awkward to use with SFML
#include <SFML/Graphics.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <Eigen/Sparse>
#include <Eigen/Geometry>
namespace Eigen
{
template <typename T>
using Vector2 = Eigen::Matrix<T, 2, 1>;
#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 April 28, 2024 20:56
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>;