Category: Thoughts

  • I created a game for my son (part 1)

    I have a few AFK days, so I created a mobile game for my son. It is only a prototype now, but it is already playable.

    When I can, I always start what I call a power-of-2 project. In these projects, I do take 16 hours to:

    1. Think at: what to do?
    2. I want to learn something new that will help me do that.
    3. Create something with what I have learned.

    If I like it, I will allocate another 16 hours, then another 32, up to 64, and so on, as a power of 2.

    What to do?

    Like I wrote, I wanted to do a game. But what game? I have multiple games on my iPhone. I tested from one step away what he liked. He is four years old. I saw him choosing fast-action and simple games, like “Basic Hiking,” “Time to React!”, “Geometry,” and similar.

    I thought about creating a game with a simple physics world and a set of squares you can tap and throw away. Once you clean up the screen, you move to the next level. It is simple and quick.

    The name? Tap and Catch!

    Learn something new

    Sixteen hours is too short to create a new game engine, so I used a preexisting one. I already know something about Swift, Obj-C, C, etc., so I searched for a game engine that is:

    1. Small
    2. It has a physics engine
    3. Is programmable in Lua

    Multiple cross-platform engines allow you to use Lua, but I decided on LÖVE (AKA Love2D) ❤️ because it has everything I need.

    I installed the tools I needed.

    1. LÖVE, of course
    2. Lua for VSCode https://marketplace.visualstudio.com/items?itemName=sumneko.lua
    3. Local Lua Debugger also for VSCode https://marketplace.visualstudio.com/items?itemName=tomblind.local-lua-debugger-vscode

    I needed to create a couple of files for running and debugging.

    .vscode/launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "lua-local",
                "request": "launch",
                "name": "Release",
                "program": {
                    "command": "love"
                },
                "args": [
                    ".",
                ],
            },
        ]
    }

    .vscode/settings.json

    {
        "Lua.workspace.library": [
            "${3rd}/love2d/library",
                "lib"
            ],
            "Lua.runtime.version": "LuaJIT",
            "Lua.workspace.checkThirdParty": false,
    }

    The prototype

    In the prototype, I just created a Box2D world with the following:

    love.physics.setMeter(30)
    World = love.physics.newWorld(0, 9.81 * 30, true)

    The “30” number means “one meter in the Box2D world is 30 pixels in the monitor”. See official documentation on why 30 is a good one.

    “9.81” is the earth’s gravity.

    I created a single rectangle attached to the background at the center of the screen with a weld joint in the middle. When the rectangle is clicked, the weld is removed, and a new one is created where the user has clicked.

    Create a weld joint where you click.

    It is working on macOS. It’s time to move to iOS.

    Load the project on iOS

    LÖVE does not work well on the iOS simulator, and I didn’t investigate why because I was short on time.

    It’s bad memory access on glDrawElements

    You can technically enable developer mode on your device, set yourself as a trusted developer, and load the app. But I paid Apple for a developer account, and I had an old one from 2007. Deploying is simple:

    1. Get the iOS source
    2. Compress all your Lua files zip -9 -r TAC.love *.lua
    3. Add the .love file to the “Copy Bundle Resources” build phase of the love-ios target
    4. Run it

    But the red rectangle wasn’t centered anymore on the screen.

    The aspect ratio

    LÖVE default window is 800×600 pixels. See https://iosref.com/res. But modern phones have a 9:19.5 aspect ratio.

    I added this aspect ratio for desktop and mobile to ensure enough room to work on. In the meantime, also set “high DPI” true for retina displays.

    function love.conf(t)
        local aspectRatioW = 19.5
        local aspectRatioH = 9
        local width = 932
    
        t.window.width = width
        t.window.height = math.floor((width * aspectRatioH) / aspectRatioW)
        t.window.highdpi = true
    end

    Relative positioning is then calculated from the center of the screen.

    local w, h = love.graphics.getDimensions()
    -- Center is w / 2, h / 2

    The following image shows a 24×12 grid with four blue rectangles of the last four iPhone models.

    Multiple aspect ratio.

    I then choose a height/12 as the base dimension. Everything on the screen will be a multiple of this base, positioning, dimensions, everything. I will not have problems with larger devices and others.

    I manually created six rectangles to see if it was working. I changed the weld joint to a mouse joint so you can grab and throw them.

    Nine squares are aligned in the center.

    Add a simple menu

    I was at ~8 hours and decided to polish things before moving on. I added a simple menu. I drew two lines to ensure that everything was aligned in the center. I had a first misstep.

    Ops!

    Quick recalculation:

    Now is centered.

    iOS default fonts are boring, so I decided to use FFF Forward.

    New font.

    FFF Forward is a variable-width font. So, the “S” and the “p” are not aligned. I used love.graphics.print with Font:getWidth to fill the background. It should fill all the background, but a font has:

    1. A baseline
    2. A descent
    3. An height
    4. A line height

    It’s fascinating, but there is not enough time to create a pixel-perfect background. So I decided it was good this way.

    The editor

    I needed an editor now to create the levels, as I couldn’t do it manually. Time was running short, so I made a quick JS one. Nothing is interesting here, so a video is enough. The editor saves the results as a JSON.

    Create, move, rotate, delete rectangles.

    I created a Javascript to Lua tables library to transform the JSON file into a levels.lua file. You can find it here: https://github.com/zaerl/js-to-lua.

    From:

    {
      "name": "Level 1",
      "rects": [
        {
          "x": 24,
          "y": 12,
          "r": 0
        }
      ]
    }

    To:

    {
      name = "Level 1",
      rects = { {
        x = 24,
        y = 12,
        r = 0
        } }
    }

    Time has finished

    The 16 hours have passed. I created a small working prototype with four levels, and my son is playing it. I think it is promising, so I will extend it, polish the product, and publish it on the App Store for free.

    See you at Part 2!

    First four levels!
  • Natura Macchina, UUIDdo (IT)

    È online il secondo capito del mio libro. È intitolato UUIDdo.

  • Natura Macchina, il mio libro (IT)

    Natura Macchina è un libro che ho scritto durante un anno di grande dolore e solitudine. Un momento della vita dove la sofferenza è quello che ti trascina fino alla fine della giornata. Quando non vedi mai l’accadere delle cose ma solo la loro fine, cosa che vorresti accadesse per tutto.

    È suddiviso in circa quattro parti e ventiquattro capitoli.

  • Brief collection of Twitter posts

    I’m not using X anymore. I find it boring. Here is a list of my last tweets:

    You know that the Perl regexp you wrote 20 years ago is quite complex if it breaks the VSCode syntax highlighter.

    Yes, it’s true.

    We are continuously compressing, changing the aspect ratios, recording screens, and recording other people’s screens. And using AI to remove all the artifacts over and over. Maybe there will be a time when finding the 1:1 real source of an image/video will be impossible.

    Yes, it’s true as well. We are losing sources of information.

    On the first days at my new company, during a meeting, they asked me: you are a super-hero. What are your superpowers? I answered: know all Git CLI flags.

    This happened at Automattic, where I work now.

    Light takes 1.3 seconds to travel from moon to earth. This lag will generate some weird video calls once they open that luxury hotel in the Sea of Tranquillity.

    Isn’t it strange?

    Imagine a world where `echo` becomes a function in a new version of PHP.

    It’s impossible, or a +20 years waiting.

    The back sheet theorem: If you write a program that helps people replace a workflow focused on Excel sheets, then this program will eventually have an Excel export sooner or later

    I call it the Excel win-win-win.

    What is the biggest challenge in modern IT? “10ⁿ ML”? A new TimSort? A standard for comments in JSON files? No. Reinventing the SMTP protocol. A lot tried, but everybody failed. And chats don’t count.

    You can try it, and you won’t be able to do it.

  • Rethinking at the old times

    I was digging in my old X tweets when I found this:

    Yeah, it was.

    It was also the time of the bbPress crash with WordPress 3.0. Back in the day, I created one of the most simple plugins ever made: /zaerl/zaerl-wordpress-3-integration

    I don’t remember exactly when I created it, the repository is just something I made to save historical code.

    WordPress 3.0 was out, and bbPress was crashing. A strange $GLOBALS['user_email'] was used that created just some head scratch. So you know what? Just set it to null.

    The bbPress community was great like bbPress per se is excellent. The forums are no longer fancy nowadays, and everybody knows this and why.

    But I need to thank the entire community because I am what I am because of them. Go WP!

  • Counting in base 16

    Since I was a child, I counted things in base 16. But remember that I was an average intelligent person and never made someone shout:

    Oh, frabjous day! This kid just told me that he has 0x64 Lego bricks!

    Someone

    I always kept in mind 16 dots arranged in a square of 4x4. These dots were connected by a line every time I counted something, or someone said something.

    This is the scheme (row-column matrix):

    [0,1]-[1,1]-[1,0]-[0,0]
    [3,2]-[2,2]-[2,3]-[3,3]
    [0,2]-[1,2]-[1,3]-[0,3]
    [3,1]-[2,1]-[2,0]-[3,0]

    Usually, I ended my phrases when the square was filled up. With hindsight, I was a bizarre kid.

  • Exciting projects

    The most exciting project is the one that involves a technology that you know little or nothing about.

  • Staying up all night

    I need to stay awake all night long. At 14:00, I will take electroencephalography (EEG), and I need to sleep with multiple electrodes placed on my scalp.

    When I am in a phase of sleep deprivation, I have visual hallucinations. Alfred Bester says in his book The Computer Connection that when you have an epilepsy seizure, you touch the real world with your mind.

    Maybe he’s right.

  • Life again

    Some time ago, I decided to write a science fiction book, mesmerized by too much cyberpunk literature engulfed during long nights of solitude. I finished it as well; it was in the year 2005 if I remember well.

    It tells about a great new Kantō earthquake that forced Tokyo to rebuild from the ground up. I had also guessed the exact year in my prediction, although the results I described were much more severe.

    Rereading it now makes me smile. Paragraphs are too long, there are too many disjointed sentences, and very complex LaTeX macros all over the book. It is a mixture of all the science fiction I read in my youth.

    I copied the other without realizing it. I shaped my experiences as a reader trying to emulate something that I will never get to write.

    Life is strange.

  • Interfaces

    The first time I used a mouse, I got a bizarre feeling. The machine had a very high mouse pointer acceleration, and I could not click icons. It happened a lot of years ago, but I still remember it very well.

    It also was the first time I encountered an infinite loop. The language was Pascal, and the loop was caused by me, assisted by a rogue while loop.

    Let’s jump ahead to the year ~2011. I watched The Mother of All Demos and discovered who invented the mouse.

    After seeing Douglas Engelbart talking about augmenting human intellect, I felt a little dumber as a man but especially as a programmer. RIP.