Brainfold On Python, game development and everything

22Feb/08Off

Day four: entity types

Got more stuff done today. I started on entity types with a type database, added a simple texture manager and again structured and consolidated lots of code. Entities are all the visual and/or physical objects in the world: at the moment the terrain, units and shells. Entity types define properties for entities, and entities can be created from entity types. Two different tanks would be two different entity types, two tanks of the same type would be different entities but the same entity type.

Before I can get this done though, I think I need to formalize entity components a bit. At the moment I'm just adding arbitrary attributes to entities, but I'll need to keep track of them somehow. Physics- and gameplay-related attributes could be collected to their own components. With the flow I've been in for a good part of the week though, I don't expect this to be a serious problem. :) Tomorrow will again be a bit busier in the real life department and on Saturday I'm probably going snowboarding with a few friends, but I'm still expecting at least some progress.

As a small statistics, the project has exceeded 1000 lines of code (including comments and empty lines).

19Feb/08Off

Plan for the day

Ok, I'm all ready to start development for today. Today I'm going to focus on gameplay and playing around with physics assisted by Chipmunk. But first I'm going to write a bit about my plans for the game.

There are two major gameplay features and one programming technique I want to emphasize. Let's get the dull technical one out of the way first. I wrote about component-based entities back in December but never got far enough with my "main project" to get anything actually implemented. I'm going to remedy that with this game and experiment with component-based entities. It'll be a very useful experience for future projects and hopefully some readers. :) But more on that later as I start implementing that stuff.

And now the interesting stuff. The feature I most liked about my old artillery game was its modular weapon system I wrote about in my memoirs. I want to create something similar, but of course better this time. :) Maybe I could even let the players customize their weapons, we'll see... The other feature is not really a feature, but a kind of a fixation of mine. In addition to sci-fi, I've always liked "pseudorealism". Not simulation-level realism, but I've always liked stories and games that are not pure fantasy. In the artillery game, this was manifested as separate kinetic and explosive damage, drag for the artillery shells and other features more complex than usual for the genre. I have also always dreamt of writing a pseudorealistic shmup (shoot'em'up), so maybe that will be my next project...

And now, back to work!

15Dec/07Off

MVC, my friend

As I was finishing high level design of scene management, I realized it was starting to resemble the Model-view-controller pattern. The (hopefully) more or less final design is sort of a hybrid of the alternatives I already presented:

  • Entities contain arbitrary data in attributes. These compose the Model.
  • Entities can contain any amount of features; these are the controllers.
  • Subsystems (for lack of a better name) link entity attributes to lower-level systems - such as the renderer, audio mixer and physics simulation - and thus represent views into the scene.

Features are normal tasks in the engine, based on cooperative multitasking. They can read from and write to attributes and create, trigger and listen to signals (an implementation of the observer pattern), which is how they communicate with each other. Subsystems also listen to signals to get notified of attribute changes. Attributes can be shared between features; for example transform is a common attribute probably used by almost all features and subsystems. Sharing of attributes is based purely on their names, there's no actual cooperation between features and subsystems except for signals and of course documentation.

I think a rough example is in order again:

  1. A ship gets hit, triggering the hit signal.
  2. The damage controller feature is listening to this signal and gets notified.
  3. Damage controller decreases ship health accordingly and notices it's below zero: it adds a destruction sequence feature to the ship entity and stops listening to hit events.
  4. Destruction sequence adds an audio source attribute to the ship entity (if it doesn't already exist), spawns particle effects for a while and finally marks the ship entity for removal.
  5. The audio subsystem notices the new audio source and adds it to the low level audio mixer.

What do you think? Input is still welcome, I haven't actually started implementing this yet. :) And I still have at least a couple of open questions:

  1. How should signals be triggered externally, for example by features in other entities? Should they just trigger the signals directly, or should there be an "external API" consisting of callable attributes?
  2. Should features occupy named slots like attributes, or should they just reside in a generic list? I'm currently leaning towards the latter approach and reserving names just for attributes, since feature don't have to directly know about each other.

I still have to design the rendering pipeline; I already have a general idea of what I want, but details are kind of blurry. But that's the topic of another post.

11Dec/07Off

Between designs

Yesterday and this morning I've read a lot of material on various topics related to scene management, rendering and a host of other subjects. TomF's Tech Blog was especially useful with rendering. I think I now have a relatively good idea about what I need in scene management and what features it should have. However, at the moment I'm torn between two designs, which are roughly equal to the first and third alternatives in my last post. I wrote small and rough examples on both to illustrate, and input would be really welcome at this point. The example is a space ship with an AI, a rigid body for physics, an audio source for positional sound, a particle effect for the engine and a turret, which in turn contain its own AI.

1. Data container entities with single-instance subsystems handling all the logic

ship = Entity()
ship.visual = ship_mesh
ship.rigid_body = ship_body
ship.logic = ShipAI()
ship.audio_source = AudioSource()

effect = Entity()
effect.visual = ParticleEffect()
effect.parent = ship
effect.transform = engine_transform

turret = Entity()
turret.visual = turret_mesh
turret.logic = TurretAI()
turret.parent = ship
turret.transform = turret_slot_transform

2. Feature (aka component) container entities, with all the logic and data contained in the features

ship = Entity()
ship.add_feature(ShipAI())
ship.add_feature(ship_mesh)
ship.add_feature(ship_body)
ship.add_feature(AudioSource())

effect = Entity()
effect.add_feature(Link(ship))
effect.add_feature(ParticleEffect())
effect.transform = engine_transform

turret = Entity()
turret.add_feature(turret_mesh)
turret.add_feature(TurretAI())
turret.add_feature(Link(ship))
turret.transform = turret_slot_transform

Which do you like more? In my opinion, the first option has the advantage of being perhaps more intuitive and clearer to use: you just assign features to attributes, whose name tells what they are for. On the other hand, the second interface depends less on magic and is perhaps easier to extend with new feature types, as there are no predetermined names for feature "slots" (in the first option, the names are defined by the subsystems that handle the logic of entities). Of course you could also use subsystems in the second option and "intelligent components" in the first option, but these two interfaces seem to fit those two underlying designs best, at least in my opinion.

If you have any questions or general comments about either of the designs, feel free to post them, all input is welcome. :)

10Dec/07Off

Research phase

I've been doing some research and brainstorming for both the engine (still without a new name) and Red Nebula. I'm trying to design a new scene management package for the engine, including a new renderer. What's certain at this point is that it's going to be based on entities with components. Entities are more or less dumb containers for components, which describe the behaviour of the entity. Data lives in either the entity, its components, or both, depending on the exact design. Evolve Your Hierarchy is a good article on what it's about and why you should do it.

This thread on Gamedev.net has been really helpful for getting them brain juices flowing, and as I wrote there, I've got a couple of alternatives I want to think about further:

  1. Very similar to the misguided attempt of creating a unified scene graph for Spineless, but on a higher level, based on game entities, not low-level scene graph nodes. Entities contain just data, while subsystems (or workers as I called them) contain all the logic of how to deal with the data. There are no components per se.
  2. Components define only behaviour, while entities contain components and their (possibly shared) data.
  3. Entities are solely containers for components, while components contain both behaviour and data.

At the moment I'm mostly leaning towards the first alternative, though the other two have their advantages too, and all of them seem quite elegant to me. I'll have to think more about this first, and input is of course always welcome.

Brainstorming for Red Nebula has piqued my interest in reading sci-fi again, so I started reading Iain M. Banks' Use of Weapons. I really like his stories and writing style; they're definitely "high sci-fi" in the sense that technology is really advanced - space battles generally last only fractions of a second - and there are actions sequences and such, but they're not corny adventure stories or anything. I think the genre is called "hard sci-fi". The other sci-fi writer I really like is Philip K. Dick, though his style is completely different and not that much centered on technology.

I've also done some coding, but not much. Mostly just stubs for the new scene package and small fixes here and there. I should get resource management out of the way at some point, before starting to really work on scene management.