Skip to content

Instantly share code, notes, and snippets.

#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <stdexcept>
#include <GL/glew.h>
#include <GL/glut.h>
inline static void glCheck(int line) {
GLenum err = glGetError();
@numberZero
numberZero / minetest.sh
Created November 10, 2018 22:25
Minetest wrapper
#!/bin/bash
# Find out where we are
bindir="$(dirname "$0")/bin"
baseconf="$bindir/../minetest.conf"
binary="${MINETEST:-$bindir/minetest}"
conf="$(mktemp)"
extraconf="$(mktemp)"
diff --git a/src/client/tile.cpp b/src/client/tile.cpp
index fe26832d4..ee20a687b 100644
--- a/src/client/tile.cpp
+++ b/src/client/tile.cpp
@@ -770,9 +770,9 @@ void TextureSource::rebuildImagesAndTextures()
}
}
-inline static void applyShadeFactor(video::SColor &color, float factor)
+inline static void applyShadeFactor(video::SColor &color, u32 factor)
@numberZero
numberZero / inactive-mapblock-handling.md
Created August 17, 2018 21:34
Mesecons inactive mapblock handling

Inactive mapblock handling

As Minetest world is virtually infinite, only part of it can be loaded in memory at any given time. Actually, there are 3 possible states for a mapblock:

  • Unloaded
  • Loaded (cached)
  • Active

Minetest activates blocks around players, and also so-called “force-loaded” (“anchored”) blocks. All internal computations (like liquid flow) happen in active blocks only. But active blocks are expensive, so the activation range is very limited. Blocks farther than that may be loaded (to support larger view range), but they are not activated until you come close enough.

For most mods, that just means they will work near players only. But in Mesecons it may easily happen that a device is very large and spans many blocks, only some of which are active. Such situations need special treatment.

@numberZero
numberZero / opengl_fragment.glsl
Created August 10, 2018 12:52
Trivial shaders for Minetest
uniform sampler2D baseTexture;
void main(void)
{
vec2 uv = gl_TexCoord[0].st;
vec4 base = texture2D(baseTexture, uv);
gl_FragColor = vec4(base.rgb * gl_Color.rgb, base.a);
}
@numberZero
numberZero / array_wrapper.hxx
Last active February 16, 2018 17:12
Length-independent array wrapper. To be used inside ternary operator etc.
template <typename T>
struct ArrayWrapper
{
T *const data;
const std::size_t size;
T *begin()
{
return data;
}
@numberZero
numberZero / enum_class.hxx
Created November 23, 2017 22:52
Safe enum-indexed array
#pragma once
#include <cstdint>
#include <array>
#include <initializer_list>
template <typename Enum>
class enum_traits;
#define _CONCAT(x, y) x##y