Technologies of Trosnoth

Reminder: in October 2018, I’m’s artist in residence. You can ask me questions about Trosnoth, support me in my Trosnoth development, join in online alpha testing, and follow this blog for articles about Trosnoth and what I’m working on.

What’s under the bonnet?

In my previous article, I wrote about what makes Trosnoth Trosnoth. But what powers Trosnoth, and why did we choose those building blocks? In this article I’ll try to answer that question.

A python

A python.

1. Python

Trosnoth is a pure Python project. We do use third-party libraries that include binary components. But all of the source code of Trosnoth itself is in Python1. The Python programming language is widely used in scientific computing, education, web services and even embedded computing. And according to the 2018 Stack Overflow survey it’s the 4th most popular programming language2 after JavaScript, Java and shell script. But why choose it for a game?

In years gone by, people used to ask me, ‘Isn’t Python too slow for a game?’ Those were the days when people thought real games should be written in C or C++. But these days many games are written in interpreted languages like Java, C#, or JavaScript. So choosing Python no longer seems quite as weird. Even so, I think it’s worth pointing out that Python was never too slow to run Trosnoth. Thanks to pygame, all the graphics calculations are done by SDL. CPython3 has always been more than capable of keeping up with everything else we need to do, so we never needed to seriously consider speeding things up with PyPy or Cython.

There are three main reasons why Python was an appealing option when we started the Trosnoth project. Firstly, it’s easy to learn. We wanted to make it easy for new programmers to contribute to Trosnoth—or even to learn programming by hacking Trosnoth. Any language that was difficult to learn would make it harder from Trosnoth to be helpful for new programmers.

Secondly, Python allows rapid development. In my experience good developers can do things with Python to the same level of quality in much less time than with many other languages. (Though I do think the difference between languages by this measure has lessened somewhat over the years with the availability of free IDEs containing high quality tools.) This advantage is of great help to an open source project like Trosnoth because developers are usually writing code in their spare time. A developer doesn’t want to spend 50% of their time writing boilerplate code when they only have limited time to spend on Trosnoth.

Thirdly, Python makes it easy to write maintainable code. This is a benefit to any software project, but particularly one where developers are strapped for time. Hunting bugs is much harder when it takes several hours to understand what the code in question was trying to do in the first place.

2. Twisted

Trosnoth runs on a Twisted main loop. That means that it uses a funny thing called cooperative multitasking. I’ve explained this in two different conference talks in the past but many developers are at least somewhat familiar with the concept from JavaScript: you start a task running (say, an AJAX request), then you provide a callback function that should be run when the task completes. In modern JavaScript, you can accomplish this by defining an async function and calling await on the task/promise. This is all cooperative multitasking because it’s the programmer, not the operating system, that decides when one task should pass control to another.

When compared with shared-memory thread-based multitasking, cooperative multitasking eliminates a whole class of synchronisation bugs. Since Trosnoth aims to be welcoming to new programmers this seemed like a good idea. Back in the days of Python 2, you needed a third-party library in order to do cooperative multitasking. Twisted was one of the prominent options, and one of our original contributors had lots of experience using Twisted. So it was an obvious choice to make.

Some vines growing twisted together.

Some twisted things.

These days, Python has built-in primitives for cooperative multitasking: async def, await, async for etc.. It also has asyncio in the standard library. If we’d started the Trosnoth project today, perhaps we would not have chosen to use Twisted. Having said that, Twisted also provides a whole raft of network protocols straight out of the box, which have proven useful at times. For instance, we can run a network-bound interactive Python REPL in a Trosnoth process using Twisted’s manhole module.

3. Pygame

Trosnoth uses pygame for its graphics and audio. When we started working on Trosnoth, pygame and pyglet were the two main contenders for 2D Python audiovisual libraries. Pyglet was relatively young and had only a small community around it. Pygame was mature and had a large community. We chose the safe option and went with pygame. Even though development on pygame stalled from 2009 until late 2016, it continued to serve our needs.

During recent years we’ve toyed with the idea of moving Trosnoth to 2.5D graphics. That is, using a 3D game engine but keeping the gameplay all in a single 2D plane. To this end, we experimented with Panda3D. We even had a working (feature-incomplete) prototype that used the same network protocol and backend code but used Panda3D for the front-end. But sadly, when we updated our codebase to Python 3, the prototype broke. The development version of Panda3D, version 1.10, does support Python 3, but the latest stable release at time of writing does not. Until Panda3D 1.10 is released, any experimenting on this front has stalled.

4. Django (server-only)

The Trosnoth server has a web interface, mostly for displaying statistics from past games. When we first set up the web interface we just used twisted.web. (Yes of course Twisted comes with HTTP support built in!) But twisted.web is very rudimentary and the more information we wanted to display on the interface the more it made sense to move to a more complete web framework.

Django is a widely used and mature web framework so it was an obvious candidate: we wanted to be friendly to new programmers, and Django has lots of documentation and a supportive community. There was just one hassle: some elements of the web interface could interact with a running game. This meant that if we used Django we’d need to establish some communication between the web service and the game server. Or… we could run Django inside a Twisted main loop. This last idea sounds like it would never work. But I read a blog post explaining that actually it works pretty well, if you write code that plays nicely. Doing things this way actually made the transition to Django fairly simple. But talking about it does earn me looks of horrified admiration from certain other Python developers. (These days we actually run the web server in a separate process from the main game server, but there’s still some Twisted-y things going on in the web server.)

And that’s how Trosnoth works

…well that’s what Trosnoth’s built on anyway. There are some other very interesting technical details in how Trosnoth itself works: like where we hide network lag and how bots navigate the map. But those are stories for another day.

Keep an eye out for more articles about Trosnoth here on this blog throughout October.


1 Yes, we also have HTML, CSS and JavaScript in the web interface of the Trosnoth server. But I don’t feel this invalidates my assertion.

2 If you followed the link, I’m sure you saw what I did there.

3 CPython is the reference implementation of the Python language, available from

Posted in midlength | Leave a comment

Why Trosnoth?

Reminder: in October 2018, I’m’s artist in residence. You can ask me questions about Trosnoth, support me in my Trosnoth development, join in online alpha testing, and follow this blog for articles about Trosnoth and what I’m working on.

What’s so special about Trosnoth?

There are so many video games out there—it’s easy to come by reasonably priced, high quality indie games in today’s market. Sure, there weren’t so many indie games back in 2006 when we started the Trosnoth project. But even so, why another game? In this article I’ll talk about why we started the Trosnoth project and a few of the things that make Trosnoth Trosnoth.

Grown in community

The Trosnoth project was dreamed up in a community. It was the spring of 20061 and a group of us had just finished running a fun but exhausting Christian technology camp. We were debriefing the events of camp and someone said, ‘We’ve played the same old video games on camp for years and years.’

Someone else replied, ‘Yes, but it’s really expensive to buy licenses for 60 people to all play a recent game.’

‘And we need a game that parents won’t object to their kids playing,’ interjected another person.

‘And we like our gaming sessions to teach people teamwork and strategy.’

It was at this point that I spoke up. ‘We have this argument every camp, and we still keep playing the same old games. But I’ve been thinking… since we have in this room people with many different skills in technology, couldn’t we make our own game?’

The idea intrigued everyone. A dozen people signed up to help in various ways. And so the Trosnoth project was born. We brainstormed ideas and game rules on a wiki, and finally nutted out the game in enough detail that we could start working on it.

Many of the original contributors are no longer regularly involved, because one can’t be a university student forever2. But the project continues to be integrally tied to community. When we’re considering big changes, past contributors still chip in with their ideas. And our release cycle includes getting user feedback by play-testing, sometimes online and sometimes on the very camp we originally created Trosnoth for.

Humans vs. Machines Trosnoth match, June 2018

Teamwork trumps skill

The fact that Trosnoth was grown in community has heavily influenced the game’s design. For instance, we encourage teamwork on camp, so we developed a game that would reward teamwork. When we made design decisions for Trosnoth we kept this in mind, and the result was a game in which communication and teamwork are essential. That’s not to say that skill means nothing in Trosnoth. It helps to be good at aiming, dodging bullets, and quickly getting around the map. But if you’re playing against a team which coordinates its attacks and communicates well, your individual skill will mean very little.

This need for teamwork is mostly enforced by one game mechanic: Trosnoth is a territory control game, but you cannot capture a region of the map unless your team has more living players in the region than the defending team3. In practice this means that an unskilled player can defend a region against one attacker by staying away from them and staying alive. I’ve seen this used to effectively remove the skilled attacker from the game for as long as that attacker spends unsuccessfully trying to kill the pesky defender. But if a team works together, all it takes is a second attacker and the region is captured.

(As a developer I often test features by playing Trosnoth on my own against bots. This has taught me the really bad habit of not communicating with my team. I’ve lost a number of matches with humans as a result.)

High pay-off risks

Because of our emphasis on teamwork, Trosnoth has a game mechanic where a team cannot control two completely separate areas of the game map. This means that if the opposing team somehow manages to split your team’s territory in half, your team only maintains ownership of the larger half. The smaller half becomes neutral.

As a result of this design decision, there is a huge pay-off in trying to split your enemy’s territory. Your enemy stands to lose up to half of the area they control. The trade-off is this: in order to split your enemy’s territory you always need to leave your team’s front line, which usually exposes your own territory to being split. There are times in any Trosnoth match where there’s only a very small chance of this actually paying off. But now and again there’s a better opportunity, and you have a fraction of a second to make a choice: is it worth the risk?

Situations like this often make Trosnoth matches very intense. When someone on your team takes a risk, things can turn around very quickly, for better or for worse.

Scrupulously fair

I often compare Trosnoth to a team sport. Like a sport, a Trosnoth match requires two teams of equal size, and teams have to work together in order to achieve their goal. But even in a physical sport, there are usually uncontrollable factors: the wind is blowing in a certain direction, and the sun is shining in one goalie’s eyes. We designed Trosnoth to avoid this kind of thing as much as possible. If a team wins, they can’t blame it on unfair conditions. To this end, Trosnoth generates maps which are perfectly symmetrical, and avoids randomness wherever possible.

You could think of Trosnoth as a team sport with a referee who is undeniably free of any bias.

Easy to edit

Trosnoth is open source. As a philosophy, this encourages innovation. People can pull apart the game and experiment with any modifications they can imagine.

We’ve used the game to teach Python programming on camps. We’ll set a challenge like adding an item to the game, or writing an algorithm for a computer-controlled player, then we’ll use the process to teach programming concepts.

Because of this, we strive to keep the Trosnoth source code readable and understandable. We’ve sometimes failed at this, but it’s still always our aim.

Where does that leave us?

Of course there’s much more to Trosnoth than just these five factors. But I think these five things paint a good picture of what Trosnoth’s about. It’s fast-paced and risk-filled, but also fair and team-driven. And it’s all built in community.

Watch out for more Trosnoth-related blog articles throughout this month.


1 Spring runs from September to November of course.

2 I have met people, as I’m sure you have, who try to disprove the idea that one can’t be a university student forever. None of them have yet succeeded in arriving at the ‘forever’ part.

3 There’s an upper limit to the number of players you need, but it very rarely comes into play.

Posted in long | Tagged , , , , , , , , , , | Leave a comment

Pygame Artist in Residence

What’s all this?

This month, I’m’s inaugural artist in residence! The artist residency was created to celebrate the Python arts community. It’s a small grant to support me in my art practice.

In residence where?

On the internet. It’s a virtual artist residency, so throughout the month of October I’ll be residing on the internet.

What art practice?

Game development. I regularly spend time developing Trosnoth (using pygame and Python). Throughout the month of October I’ll be continuing to work on Trosnoth, but I’ll be updating you as I go.

How can I follow along?

This blog is the main place where I’ll post my updates. You can expect:

  • four blog articles about Trosnoth as previously announced
  • a few special updates on what I’m working on
  • you can ask me questions about Trosnoth and I’ll devote some time this month to answering them
  • maybe some online alpha testing of the next Trosnoth release — fill out this form if you’d like to join in
  • some kind of concluding ‘artist’s exhibition’ at the end of the month — exactly what form this takes is yet to be decided
Posted in midlength | Tagged , , , , , | 2 Comments

Coming soon: 4 Trosnoth articles

What’s this? An update on a dormant blog? I started this blog in 2010, but haven’t written anything recently. I wrote three articles in 2015, one in 2016, and none in 2017. Well that trend has just turned around!

Throughout the month of October 2018, I plan to publish four articles about Trosnoth on this blog. I haven’t made up my mind exactly what I’ll write, but I expect there will be something about what makes Trosnoth unique, something about the underlying technologies and why we chose them, and something about some of the more interesting technical challenges we’ve had to solve. Stay tuned…

If you’ve followed this blog for a long time you’ll have seen me write about Trosnoth many times before. But for any newcomers: Trosnoth is an open source game. It’s a fast-paced territory control shooter. Intrigued? Look out for my upcoming articles to find out more.

(Or you could just browse the source code or download an installer. It’s open source after all!)

Posted in short | Tagged , | 1 Comment

Jesus and the Rich Young Man (One Size Fits All)

Jesus treated people as individuals. He responded differently to different people. But what would have happened if Jesus had tried to use a one-size-fits-all approach to ministry? Here’s how I imagine Mark 10:17-22 (the Rich Young Man) might have turned out. [ NOTE: if you don’t know the original story please read it first ]

As Jesus was starting out on his way to Jerusalem, a rich young man came running up to him, knelt down, and asked, “Good Teacher, what must I do to inherit eternal life?”

“Why do you call me good?” Jesus asked. “Only God is truly good. But to answer your question, you know the commandments. ‘You must not murder. You must not commit adultery. You must not steal. You must not testify falsely. You must not cheat anyone. Honour your father and mother.'”

“Teacher,” the man replied, “I’ve obeyed all these commandments since I was young.”

Jesus looked at the man, and rose to the challenge. “Really. You’ve kept all of them?”

“Yes Teacher. My parents taught me to follow the laws of Moses.”

“Ok, well how about this? Have you ever been angry with anyone?” asked Jesus.

“No Teacher,” he replied. “To be perfectly honest, my life has been fairly easy. I’ve never had any reason to be angry.”

“What about lust then?” asked Jesus. “You must have looked lustfully at a woman at least once?”

“Well,” said the man, “I’ve felt temptations from time to time, but my parents always taught me that temptation was not the same as sin.”

Jesus frowned. “Ok, I’ll give you that one. But all have sinned and fall short of God’s glorious standard, so I know you’re a sinner.” Jesus paused for a moment, then he smiled at the man. “I bet you’re pretty pleased with yourself for keeping all those commandments?”

“Well I do try to honour God.”

“There, see? Pride! The scriptures say, ‘God opposes the proud but gives grace to the humble.’ So you’re a sinner then! See?”

“Um, I guess so.”

“Good. Well the good news is that I’m going to save you from your sin, so all you have to do is accept, believe and confess. Here, read this prayer.”

“So… if I say this prayer I’ll inherit eternal life?”


“And that’s all there is to it? No hidden clauses or small print? Can I keep my possessions? Do I have to change anything else?”

“What have possessions got to do with eternal life? No it’s all on the inside. You just need to believe in me.”

At this the man’s face lit up, and he went away happy, for he had many possessions.

Posted in midlength | Tagged , , , , | Comments Off on Jesus and the Rich Young Man (One Size Fits All)