Development Progress Report, weeks 39 and 40

Two weeks since the last update, and things have been going a bit slowly. Headachey and nauseous today, which is certainly not helping.

There have been a number of code-improvements that simplify authoring, especially when casting characters into scenes, and similar meta-programming tasks. That’s all to the good.

The writing has been a bit slower, and I think it is because I got hung up on a particular scene. Continue reading Development Progress Report, weeks 39 and 40

Development Progress Report, weeks 37 and 38

Missed a week, due to life and commitments, so this is a double week, with a blob of promised telemetry source-code.


The Story-Compiler is a nineteen-pass tangle. Basically, any time I need it to do more, and whatever-it-is doesn’t cleanly fit into any of the existing passes, I just add another pass.

This leads to some interesting precedence-of-operations issues. This pass should happen before these other passes, but… oh, it relies on this other pass to go earlier.

That may need a tidy up. Also, now that I’m expanding and replicating parts of the source on its way through the story-compiler, I’m pretty sure the way I’ve been tracking the start/end positions of scenes in the intermediate data-structures is starting to drift.

Not enough to break anything just yet, but I’m sure it will, as the compiler uses a lot of per-scene data. In short, I need either a better way of tracking which line of the intermediate story-data belongs to which scene, or a better way of inserting/deleting lines of the intermediate story-data.

The engine itself has no such troubles, being that it breaks everything out of the final compiled story into separated scenes and performances. I suppose I could actually tear the intermediate data into parts, and reassemble later, but that would make some tasks harder, rather than easier.

I think, for now, better tagging of intermediate lines is probably the way to go. Probably.


I’m slowly replacing some of my original syntactical constructs with newer things. Actually, in the compiled story file, things are still pretty much the same, but I’m using the compiler phase to allow for a more sensible syntax for what were previously some historically awkward constructs.

The idea is to make everything a whole lot simpler. Here’s an example:

Scene 115
 Summary: Alice and Bob give either Christine or Danielle (whoever it worked out to in scene 100) a lift to the next town.
 Arc:The Mysterious Hitchhiker
 // Set up aliases for cast we copied from scene 100
 role:4:name=Craybourne [alice]
 role:5:name=Drayper [bob]
passenger,hitcher:{Name:[driver]} put the car in gear, flipped on the indicators, and checked {herhis:[driver]} mirrors. {?role:[driver]:Drayper|He nervously glanced this way and that before finally pulling awkwardly out onto the road|There was only a moment's pause before she pulled the car smoothly onto the highway, and accelerated}.

Trust me, that’s a whole lot nicer.


Work’s coming along well on the next stage of the story. It requires some parallel tech that I’m throwing together on-the-fly, as I need it. It’s slow, but steady, and there’s another big plot-twist, besides.

The nature of that twist is something I want to revisit before it is set in stone. Does it need a trigger warning? Does it go farther than I’m comfortable with for the overall tone of the story?


This actually gives me two options.

I could either make some adjustments to the scene so that it is a good deal less whatever-it-is (trying not to be spoilery is hard!). Or, I could do that and present it as an optional form of the story. Maybe stick some trigger-warnings on the options screen, and eliminate/vary characters or a couple narrative elements based on what you choose not to see.

The second one sounds more complicated, so I’ll probably end up at least writing the code for it eventually, even if I don’t take advantage of it myself.

For now, I might archive the problematic bit of narrative, and tweak it. I’ve got a softer version that should still fit the bill narratively.

Game Telemetry

At the IGDAM get-together last week (one of the life bits that ironically got in the way of getting the devblog done), I promised to post my telemetry code. Telemetry in your alphas/alpha-demos is important, I think. That’s around the time you want more data about how people actually are playing your game, but as an Indie, you can’t exactly afford any kind of structured playtest – but as long as you have a cheapie web-host that you can drop a script on, you can get game-telemetry, and thus feedback that will help inform your design and polish decisions.

The code here isn’t particularly arcane, and should build under both Visual Studio on Windows and G++ on Linux. Basically, if you know C++, then there’s nothing terribly difficult in this.


#include <deque>
#include <string>
#include <clocale>
#include <locale>
#include <codecvt>
#include "SDL.h"
#ifdef _WIN32
#include "windows.h"
typedef uint32_t Uint32;

class TelemetryEvent
 typedef enum { none = 0, startup = 1, shutdown, like, dislike, loadstart, loadend, savestart, saveend, characterpick, footnote, loaderror, runtimerror, titlescreen,choice } code_t;
 TelemetryEvent(code_t n) { eventcode = n; timestamp = SDL_GetTicks(); }
 TelemetryEvent(code_t n, const std::wstring &str) { eventcode = n; timestamp = SDL_GetTicks(); data = str; }
 ~TelemetryEvent() = default;
 code_t eventcode = none;
 Uint32 timestamp = 0;
 std::wstring data;

 std::string to_string()
 std::string result;

 result += std::to_string(eventcode);
 result += ",";
 result += std::to_string(timestamp);
 result += ",";
 std::string tmp(data.begin(), data.end());
 result += tmp;
 return result;

class AppTelemetry
 bool WS_init = false;
 std::deque<TelemetryEvent> events;
 void Transmit();
 bool enabled = true;
 void SendEvent(const TelemetryEvent& te);
 void Poll();
 void Flush() { if (!enabled) return; while (events.size()) Poll(); }
 void Enable(bool b) { enabled = b; }

extern AppTelemetry TelemetryObject;



#include "Telemetry.h"

#include <iostream>
#include <thread>
#include "EngineIO.h"
#ifdef _WIN32
#include "Winsock.h"
#pragma comment(lib,"ws2_32.lib")
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>

typedef uint32_t Uint32;
typedef int SOCKET;
typedef sockaddr_in SOCKADDR_IN;
typedef sockaddr SOCKADDR;
static const SOCKET INVALID_SOCKET=-1;

void closesocket(SOCKET s)


AppTelemetry TelemetryObject;

#define TELEMETRY_HEADER "GET / HTTP.1.1\nHost: " TELEMETRY_HOST "\nX-Xtelemetry: "

#ifdef _WIN32
 if (WSAStartup(MAKEWORD(2, 2), &WsaDat) != 0)
 { // failed

 WS_init = true;


#ifdef _WIN32
 WS_init = false;

void AppTelemetry::SendEvent(const TelemetryEvent& te)
 if (!enabled)

void AppTelemetry::Transmit()
 if (!enabled)
 if (events.size() == 0)
 return; // No work to do
 // Get the first event from the queue
 TelemetryEvent te(events.front());
 events.pop_front(); // And remove it from the queue

 if (Socket == INVALID_SOCKET)
 return; // Nuts. Can't create the socket
 struct hostent *host;
 if ((host = gethostbyname(TELEMETRY_HOST)) == NULL)
 return; // Can't look up the name.
 SockAddr.sin_port = htons(TELEMETRY_PORT);
 SockAddr.sin_family = AF_INET;
 SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);

 // Attempt to connect to server
#ifdef _WIN32
 // The Windows version of this function returns SOCKET_ERROR on failure.
 if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) == SOCKET_ERROR)
 Output(DEBUGGING, "Winsock connect error "+std::to_string(WSAGetLastError()));
 return; // Connection failed
 // Linux returns 0 on success
 if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0)
 return; // Connection failed

 // TODO: Send the data here.
 send(Socket, TELEMETRY_HEADER, (int)strlen(TELEMETRY_HEADER), 0);
 auto msg = te.to_string();
 send(Socket, msg.c_str(), (int)msg.length(),0);
 send(Socket, "\n\n", 2,0);

 // Shutdown our socket
 shutdown(Socket, 1);

 // Close our socket entirely
void AppTelemetry::Poll()
 if (events.size())

#endif (Sorry about the way indenting got eaten up here, but you can figure it out)


import os
import codecs
import time

class FileLock:
 def __init__(self, filename):
 self.filename = filename
 self.fd = None = os.getpid()

 def acquire(self):
 self.fd =, os.O_CREAT|os.O_EXCL|os.O_RDWR)
 # Only needed to let readers know who's locked the file
 os.write(self.fd, "%d" %
 return 1 # return ints so this can be used in older Pythons
 except OSError:
 self.fd = None
 return 0

 def release(self):
 if not self.fd:
 return 0
 return 1
 except OSError:
 return 0

 def __del__(self):

def storetelemetry(ip,tel):
 f ='/home/whatever/data/dtelemetry.txt', 'a','utf-8-sig')

print "Content-Type: text/plain\n\n"
while not lock.acquire():

I call it like this:

 TelemetryObject.SendEvent({ TelemetryEvent::characterpick,selected_character }); // send chosen character name.

Call TelemetryObject.Poll() in your mainloop somewhere, and TelemetryObject.Flush() before you exit, to make sure any telemetry messages have been sent.

The resulting file on your web-host (dtelemetry.txt) should be simple enough to parse and extract useful data from. It has a millisecond timestamp for each event, an event-code and whatever optional extra data gets sent along.

Caveat: The whole thing is single-threaded, so the act of generating an event can stall your game. You want to tweak it to run in a thread? Go for it. Just watch out, because I’m pretty sure that under Windows, your Winsock code needs to be initialised in the same thread that calls on it. The Linux code should be gold.


Development Progress Report, week 34

Generally felt unmotivated and without a lot of creative juice. I still got a lot done, through effort rather than inspiration, though somewhat less of it was narrative, and more of it was code.

Almost all of the code work this week happened in the story-compiler.

You see, I had this epiphany – which I should have had quite a lot sooner.

Continue reading Development Progress Report, week 34

Development Progress Report, week 32


A bit of a mixed week. A number of things (eg: double-casting, see below) have allowed me to cut the word-count without reducing the length of the narrative. So, I’ve shaved off a few thousand words here and there. Ongoing reworking and editing have pushed it back up, so it’s still hovering around the quarter-million word mark.

One final scene is refusing to write itself, but I expect it will work out once the narrative refit is done, and then I can move forward into chapter two.

There’s more interesting stuff than that going on, though.

Continue reading Development Progress Report, week 32

Development Progress Report, week 31

This update is running a couple of days late, I know. I’ll try to blame the public holiday at the beginning of the week for that.

Alright, where are we at? Once again, a good week for development, though more on the narrative side than has happened in recent weeks.

Continue reading Development Progress Report, week 31

Development Progress Report, week 29

My, what a productive week it has been! Many bugs fixed, and many new bugs created (and also fixed).

If we were just working off bugs-fixed, this would have been a banner week, indeed, since I was briefly creating them as fast as I resolved them. However, there was a whole lot more going on.

Continue reading Development Progress Report, week 29

Development Progress Report, week 23-24

I missed last week’s development blog post due to the pressure of other things, so I’ve got two weeks to cover.

On the narrative side, I’m nearing a long-awaited story milestone. The prologues are complete for each of the eleven protagonists, and all but two of them are written through to the end of the rather dense and complicated first day of the story proper. Once those last two characters are written through, that will represent a major milestone.

That brings us to (today), 88 scenes and 232,814 words. That’s more than Dune (the book), or Neverwinter Nights (the game) [This isn’t a competition!], but we’re not really into the full swing of things yet. That will be in the second Act, which is where the bulk of the narrative technology should start to shine (I hope!).

Continue reading Development Progress Report, week 23-24