Dialogs as Functions

July 16th, 2014

This is just an idea I’ve had. I wanted to write it down in some meaningful way so that I can rediscover it later. This is less a C++’ism, and more a JavaScript/Squirrel’ism.

* * *

In any situation where your user interface presents a popup dialog, that process of presenting the dialog should be a function call. Here is pseudocode:

The general idea here is that there should be 2 ways to use the function: 1. Without arguments, to bring up the entry dialog; 2. With arguments, to bypass the entry dialog (for macro/scripting use). The data in extracted from the function arguments, or the shown dialog, and the action is taken place.

Args should be the language equivalent of an object (JavaScript, Squirrel, etc). Alternatively, an array of objects could work too, but named elements would result in nicer code. Like above, it’s assumed a Yes/No/Cancel dialog would store a boolean named State to tell you which (Yes or No) was picked.

The above assumes a synchronous environment, where it’s safe to give a function “ShowDialog_YesNoCancel” full control.

In an asynchronous environment, you’ll want to use something like a Deferred or Future. If there are no arguments, the ShowDialog function will provide the object you bind your State handling function to. Otherwise, bind it to one that will succeed.

Alternatively, there are probably nice ways to handle this using coroutines or generators.

Checking Symbols GCC and Clang

June 20th, 2014

Just a short one.

Reference: http://stackoverflow.com/questions/4548702/whats-the-equivalent-of-cpp-dd-for-clang

Gives you list of all symbols defined by compilers. It’s interesting, that you have to feed it something (anything blank) to get this output though. /dev/null, or pipe in a blank echo (echo “” | gcc -dM -E -), etc.

Works with NaCl (pnacl-clang), Emscripten (emcc), and pretty much every GCC toolchain known to man.

Setting up NaCL and SDL (on a fresh Ubuntu)

June 6th, 2014

Some notes on getting NaCl working. Of course, things didn’t work out-of-the box.

Install nacl_sdk

Grab and follow the instructions here:


i.e. download and do the following:

Install 32bit Headers

‘cmon, everybody runs 64bit Linux these days (in my case Ubuntu 14.04 64bit). You need the 32bit libraries for anything to build though.

Source: http://stackoverflow.com/questions/23661718/native-client-tutorial-cant-find-libstdc

Follow Tutorial

‘make serve’ will now work.


Test2 probably wont run though. I haven’t checked, but I think it may not be a pnacl file (pnacl is necessary to run in a stock Chrome).

EDIT: The problem with Test2 is that newlib is the first Toolchain. If you modify the Makefile by making pnacl the first VALID_TOOLCHAINS (or commenting out the line entirely), and change index.html, the data-tools attribute of the body tag, make pnacl first, it will work correctly.

Now, lets see how far we get compiling SDL NaCL.

Set Environment Variables for SDL

Reference: https://hg.libsdl.org/SDL/file/ae720d61d14d/README-nacl.txt

Do something like the following.

‘readlink -f’ takes a path and converts it in to an absolute path (by following symlinks, ..’s, etc). If you’re on Windows, substitute it for the absolute path to your pepper directory. Mine is /home/mike/Work/Build/nacl_sdk/pepper_35

And of course, edit your pepper version accordingly (35 or whatever).

Build SDL2 in NaCL mode

SDL must be built outside the main SDL directory. I like to call my SDL directory “SDL2″, and do builds in directories like “SDLBuild”. I invoke my build like follows:

Notably, I’m putting the output (make install) inside the SDL subdirectory of the pepper SDK folder.

The Makefile

EDIT: For the makefile to work, I had to make a few changes. Here is the full modified makefile.

The changes are lines 19 and 20. Line 22 is new, as are lines 67 and 68. The last 2 lines are a hack to make “make serve” work the same as it does in the NaCl demos.

Here’s a diff.

For reference, my old notes (before I got it working by changing the makefile):

Okay, this didn’t actually work. I’m not sure exactly how it’s supposed to be configured, but it’s not configured correctly. It should only be used as a reference. Some other notes of things I had to do to get it to work:

naclbuild script

Alternatively, once the environment is set correctly (I think just NACL_SDK_ROOT) it’ll work. In the ‘build-tools’ folder is a script ‘naclbuild’. Run that, and it’ll put some output in the Build folder. Once it finishes, it gives you a string to copy+paste in to your shell. Do it.

Vine Videos: https://vine.co/v/MDnA1x9aPMe, https://vine.co/v/MDn6I6UFWPF

Currently works on Desktop Chrome, and Chrome OS. Will not work on Android (yet).

PPTP Connecting from Ubuntu 14.04

May 17th, 2014

So I was having troubles opening a VPN connection from Ubuntu 14.04. I could VPN just fine on my iPad and Android devices, but I was having no luck on Ubuntu. Looking at my /var/log/syslog, and after much Googling, it seems my problem was ‘secrets’/keyring related.

Setting up a PPTP VPN connection is easy.


What I was lacking was one very specific checkbox with many implications, none of which were spelled out. The important one is that “Available to All Users” skips the secrets check, and instead prompts you for a password. That’s better than no VPN at all. :)


My advanced settings look something like this, thanks to other tutorials I stumbled across:


Notably, no PAP, as that’s very insecure. The rest of the options, I haven’t tried otherwise. What’s important to me is I can now connect to my VPN.

Setting up a remote PPTP server

May 17th, 2014

So I’ve been working on netcode recently. LAN/Local testing is only so effective, when the real internet is so laggy. Ideally, if I could be in 2 places at once, I could test the game under a more natural lagged internet.

So that’s what I’ve done. I’ve split in two and sent my other half down south… okay no. I recently set up an inexpensive unmanaged BuyVM VPS server (256 MB RAM, Dual Core) in Las Vegas running a trimmed down version of Ubuntu 14.04 Server. From where I’m at (2 hours south of Toronto), the ping between myself and the Las Vegas server is around 100ms.

Like always, here are my notes.

Setting up BuyVM Server as a PPTP VPN

Setting up, I started by “Reinstalling” a fresh Minimized Ubuntu 14.04 64bit Server. At the time, Ubuntu 14.04 wasn’t yet available as a pre-install. It was something I had to do after creating my account.

From that fresh install, I need to first do an APT update:

Next, install IPTABLES.

Follow these instructions:


At the very end though, we’re setting the IPTables in “/etc/rc.local”. Do this instead:

The change is the first line. We’re not binding to an interface, but setting a source.

Done. Can now VPN using the PPTP protocol, and route all your internet traffic through it.

Reference: http://wiki.buyvm.net/doku.php/ipsec (combined the Ubuntu notes and this)

* * *

To connect: Use the server IP address, login and password set in the secrets file.

Croutons and Chromebooks

May 15th, 2014

More wacky hardware, I picked up a Samsung Chromebook for cheap.


I’ve specifically been waiting for a deal on the Samsung Chromebook, as it’s quite unique: It has a Samsung Exynos SOC, which contains ARM CPU and GPU (MALI-T604). Next to NVidia’s efforts, these are some of the most powerful ARM CPUs out there. The GPU is a tiny bit dated though (same one as the original Google Nexus 10), but does support OpenGL ES 3.0 (with an appropriate driver at least).

Why else do I want a Chromebook? To test Ubuntu for ARM. I regularly test on 64bit Intel CPUs, but would like the option to do some more heavy-duty tests on ARM. I do have an Android build, but I want more. So I bought this very specific Chromebook for this.

Installing Linux (Ubuntu)

How to Enable Developer Mode and install Crouton

Follow those instructions above to enable Developer Mode (ESC+REFRESH+POWER, then CTRL+D). Developer Mode wipes the system, and adds a warning message upon boot (WARNING! DEVELOPER MODE).

If it’s a brand-new Chromebook, you may need to force an auto-update. Click on your portrait picture in the lower right corner, then go Settings->Help and wait a moment for auto-update to begin.

Grab Crouton (Link).

Press CTRL+ALT+T to open Crosh.

From Crosh type shell. This will bring up a proper terminal. You can now run Crouton.

Where ‘trusty’ is the Ubuntu version (14.04) and gnome is the Window Manager to install. The default Ubuntu version is ‘precise’ (12.04), but that’s old. Other WM’s can be installed by using commas (i.e. xfce,kde,gnome,unity). NOTE: I was only able to get xfce working with Ubuntu 14.04.

Using “list” instead of a -r or -t argument will list all choices. Running crouton without arguments will list all options.

In case you ever need to uninstall, go to the /usr/local/chroots folder and doing:


Using Linux on the Chromebook

Crouton is magical. You actually run both ChromeOS and Ubuntu simultaneously. Dual booting is an option (see the Developer Mode article above for ChrUbuntu details), but this is slicker.

To start your alternative Linux, bring up Crosh (CTRL+ALT+T) and type shell. From the shell sudo run your WM start command like so:

Then the cool part: Press CTRL+ALT+SHIFT+FORWARD (and BACK) to toggle between ChromeOS and the currently running Linux Window Manager.

OpenGL Benchmarking

First, to log details of the OpenGL driver, install mesa-utils.

Then run glxinfo. You’ll probably want to grep some of that output. Source.

To benchmark install glmark2 (or glmark2-es2, or both).

Then simply run glmark2. An overlay will popup, and it’ll start testing. Source.


Initial results show that the ARM Mali driver does not ship with Ubuntu, thus it has to fall back on to software rendering. That said, it actually does a really good job on the software rendering, but we’re not taking advantage of the system yet.

ARM has provided a reference on how to create a bootable SD card with the correct drivers:


I’ve spent enough time on the Chromebook today, so I may try this another time.