It's all in your head, Part 9

The only place you'll ever hear the truth
User avatar
Chris
Introversion Staff
Introversion Staff
Posts: 1172
Joined: Sat Nov 25, 2000 7:28 pm
Location: Cambridge, UK
Contact:

It's all in your head, Part 9

Postby Chris » Fri Feb 08, 2008 4:43 pm

I’ve started working on some of the simulation aspects of Subversion. It’s a huge and daunting area, and a big part of the problem with taking on such mammoth tasks is often not knowing where to start. The building generator in the previous blog post generates relatively simple external facades based on the traditional tapered Manhattan skyscraper, then fills in some minimal structural detail on each floor – the floor itself, the steel supporting columns that run up the centre of the building, and an elevator shaft.

Why an elevator shaft? It’s the simplest type of “room” to generate right now, being composed entirely of a vertical shaft nearly always located at the centre of the skyscraper, and always in the same place on every floor (of course). It’s a much simpler subset of the general problem of generating building interiors, and lets me lay a lot of the framework that will eventually be used for the difficult stuff.

It also gave me a starting point for simulation : Elevators! While at first they may seem pretty trivial, a working elevator system is actually a fairly complex state machine made up of several components and independent parts. Even a simple model contains:
- Elevator car with door and buttons for each floor
- A separate door on each floor of the building
- A “call” button next to each door
- A motor on the top floor raising/lowering the car by cable, with a counter-balance
- Sensors inside the shaft to determine the car location
- A computer system that controls everything
- Not to mention independent safety brakes on the car to stop it falling.

A perfect system to get started with. I’ve thrown together a quick prototype system to try to get my head around what data will be stored where and when. In this screenshot you can see the elevator shaft and all its components and connections (in red), and on the right of the picture is the current state of the Elevator Control Computer. There are four components for each floor : the Button (to call the elevator), a Low Sensor and a High Sensor (at the bottom and top of the door, to detect the elevators presence), and the Door itself. They all report back to the computer on their status, and the computer issues commands to the motor and the doors to control the system. In this shot the car is on the 1st floor (notice the two sensors on Floor 1 lit up, and the Door sensor reporting it as open.) As the Elevator rises up the shaft you can see the sensors lighting up and the logic of the computer driving the motor to move the car. It’s actually kinda fun, like playing with an extended Lego set.

Image

In past games we would have just created a bunch of C++ objects that represented each component, and written code to control how they behave. It’s served us well in past games, but it’s not going to be good enough for Subversion. Firstly we’re looking at many times more objects in Subversion than previous games, and secondly we’re really hoping to foster a strong Subversion community and open up the system to user made content. So with all that in mind, let’s talk about Script Languages.

Writing our game object logic and behaviours in script gives us tons of advantages and blasts opens the scope of Subversion. Firstly it makes it very quick and easy for us to write new game objects, by basing new objects on existing objects and building up a hierarchy of scripted behaviour code. Secondly it makes Subversion wonderfully extensible. In the past our games have supported mods to varying degrees of success, but we’ve never gone “all the way”. Ultimately mod makers will put up with ropey systems and manual editing of files, but regular game players will not. For any mod system to be truly successful, the integration of user made content has to be seamless for the regular user – he clicks what he wants in game, and it just works. This is our aim in Subversion.

Johnny and myself have worked on a couple of script systems in the past, and we’ve never been truly satisfied. It’s not uncommon for a script system to require extensive and often horrendous glue code built using supporting libraries, in order to get C++ talking with your scripts and vice versa. We’re looking for a language that is elegant and pleasing to look at (which rules out most), is easily embeddable in C++, and has decent documentation and support available. We also want a language that is as “readable” as possible and easy to learn – we’ve no interest in writing our scripts in what is essentially C++ (i’m looking at you, Un**al Sc**pt).

Python is a strong contender. Python has been around for a while, is extremely well supported and documented, and is essentially a fully functioning modern programming language. You could write an entire modern game in python, by writing your core engine in C++ and calling it from within Python. Numerous games make extensive use of Python, including Eve Online and Civ IV. In my experience over the last few days, Python is not particularly easy to embed, and essentially requires additional libraries such as Boost before it becomes genuinely useful to the C++ programmer as an embedded language. Johnny also believes Python to be quite slow, even by scripting standards. It does however have excellent built-in support for Objects, Classes, and all those modern programming features we computer scientists love so much.

Here’s an example Python script, so you can see what the syntax looks like. I’ve never been wild about Python’s style, to be honest.
http://www.amk.ca/python/simple/letters.html

Lua is the next contender. Lua is also used by some fairly impressive commercial games, including SimCity 4, World of Warcraft, FarCry, Psychonauts and a ton more. Lua is relatively new compared to Python, and this does cause it some problems. The API is still changing and being rewritten yearly, meaning a lot of the documentation and examples on the internet are already out of date and refuse to work. In my experiments Lua has proved to be much simpler to embed in C++, however it is much more down to the wire – Lua requires the C++ programmer to directly manipulate a shared stack to communicate with your scripts, which is analogous to programming while sitting on a pile of volatile explosives while spiders crawl over your body. Fundamentally Lua is designed to be embedded and controlled by C++, whereas Python wants to embed and control C++ in itself. Lua also falls over itself when you start thinking about classes and Object Oriented programming – it can do it, but only through some tricks and hacks. When combined with a couple of extra libraries – Boost and LuaBind, Lua starts to become much more interesting, and takes on much of the power of Python.

Here’s an example Lua script, so you can compare. I find it to be more “readable” than Python, but that’s just a subjective opinion I think.
http://lua-users.org/wiki/SciteCleanDocWhitespace

Ultimately there isn’t much between the languages, and it comes down to requirements and gut feeling as much as anything. Right now I’m going to keep working on prototypes using both languages until one of them does something so stupid that it makes my mind up for me.
User avatar
shinygerbil
level5
level5
Posts: 4667
Joined: Wed Dec 22, 2004 10:14 pm
Location: Out, finding my own food. Also, doing the shinyBonsai Manoeuvre(tm)
Contact:

Postby shinygerbil » Fri Feb 08, 2008 4:49 pm

*craps self with excitement*

That is really awesome. Every post just gets deeper and deeper.
Here is my signature. Make of it what you will.
Image
User avatar
NeoThermic
Introversion Staff
Introversion Staff
Posts: 6256
Joined: Sat Mar 02, 2002 10:55 am
Location: ::1
Contact:

Re: It's all in your head, Part 9

Postby NeoThermic » Fri Feb 08, 2008 4:50 pm

Chris wrote:In my experiments Lua has proved to be much simpler to embed in C++, however it is much more down to the wire – Lua requires the C++ programmer to directly manipulate a shared stack to communicate with your scripts, which is analogous to programming while sitting on a pile of volatile explosives while spiders crawl over your body.


[...]

Chris wrote:Right now I’m going to keep working on prototypes using both languages until one of them does something so stupid that it makes my mind up for me.


Are spiders and explosives being a requisite of Lua not enough? ;)

NeoThermic
User avatar
Feud
level5
level5
Posts: 5149
Joined: Sun Oct 08, 2006 8:40 pm
Location: Blackacre, VA

Postby Feud » Fri Feb 08, 2008 5:19 pm

My word, it's a 3d version of SimTower!
mcnicholls
level1
level1
Posts: 17
Joined: Wed Apr 26, 2006 2:04 pm

Postby mcnicholls » Fri Feb 08, 2008 5:38 pm

Game objects in scripts definitely sounds like the way to go for a game like this and the ability to sub-class and add game object code would make it very dynamic and extendible :-)

Only really used it for a bit of Ruby on Rails, but have you considered Ruby?

I found it quite nice to use and it feels more OO than Python does. I am not sure how easy it is to embed though. I have looked at embedding Python in the past and found quite a lot of documentation on it, but didn't turn up as much documentation for Ruby.

Anyway really excited by the progress ;-)
User avatar
djspiewak
level0
Posts: 5
Joined: Mon Nov 20, 2006 9:47 pm
Contact:

Other Language Option

Postby djspiewak » Fri Feb 08, 2008 5:40 pm

Ruby has almost trivial interop with C/C++. Basically the language API is written entirely in C, which means you can make calls and operations to Ruby stuff in C almost as naturally as you would other C functions (if that can be considered natural). The inverse process is actually even easier, allowing virtually zero-conf calls from Ruby to C (you have to run a special script to generate the proper makefile). You *require* the relevant .{so,dll} by name directly in Ruby and then call the functions directly as Ruby methods.

To be honest, the script-embed-in-C++ scene is pretty limited. Most of the innovation in that department has been focused on more "enterprise" languages like Java.
In the beginning, there was Uplink. Uplink rocked. Then there was Darwinia. Darwinia rocked. Then there was Defcon. Defcon... Hey, I think there's a trend here!
User avatar
briceman2
level2
level2
Posts: 123
Joined: Wed Dec 12, 2007 4:30 am

Postby briceman2 » Fri Feb 08, 2008 5:58 pm

FYI, you might already know, but embedded Python has some nasty memory management issues (which are due to be ironed out in a future release I think, or maybe have been just recently -- does anyone know?).

I watched the delevopment of the open source Game of Life viewer, Golly. It has a Python script engine tacked on. There are serious memory issues in that Python won't return memory to the global pool until the interpretr instance exits. Since Golly's performance is memory bound this can become a limiting problem in certain cases.

I think the basic issue is philisophical -- Python objects are immutable, and garbage collection is automatic. Lua forces you to think closer to the machine, more like C. It is also much more lightweight than Python, and often faster, certainly less memory intensive (see Great Computer Language Shootout, etc.).

Take this with a big grain of salt, but I think Python is top heavy for your application. Lua was the first language that came to mind when I started reading your post.
Pentadact
level1
level1
Posts: 13
Joined: Thu Sep 01, 2005 3:21 pm

Postby Pentadact » Fri Feb 08, 2008 6:14 pm

Garry talks a bit about how he found LUA to use in making Garry's Mod, here on his blog:

http://www.garry.tv/?p=346

He didn't like it, but he doesn't seem to know of an alternative.
User avatar
desktopsimmer
level3
level3
Posts: 370
Joined: Sun Sep 24, 2006 11:51 am
Location: Basement level 1.

Postby desktopsimmer » Fri Feb 08, 2008 6:45 pm

Probably very interesting stuff about the programming aspects of subversion, If I could program and at least understand it :) Something I'll start to pickup when I have time.

The only issue with elevators is that most are staged in really high skyscraper, as the the weight for the counter weight and the cable would causes problems for the motor. So if you want to 'simulate' a building in 'New Subversion' city, you'll have to look into the routes that a person would/could use to get from ground to floor 92 via 3-4 elevators, plus all the delays.
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm

Postby martin » Fri Feb 08, 2008 6:58 pm

Ok, so I seem to be picking on the area no one else is talking about but surely you could make that lift in a much simpler way, without simulating sensors and control computers etc? I'm beginning to think this is some kind of totally awesome version of uplink what with all this anonymous corporatism, the entire world being simulated, virtual computers contolling everything... either that or a totally cool wargame ;)

anyway, I'm also excited about this scripting stuff, personally I prefer lua because it's more similar to languages I already know, but meh - I can learn a new syntax for when I'm modding subversion ;)
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
The GoldFish
level5
level5
Posts: 3961
Joined: Fri Mar 01, 2002 9:01 pm
Location: Bowl / South UK
Contact:

Postby The GoldFish » Fri Feb 08, 2008 7:04 pm

Man, who didn't play Simtower? There's some elevator simulator if ever you needed some!

Also, I'm glad to hear you're looking at scripting languages, although I'm unsure as to at what stage they transform from being a production aid into a stumbling block. Maybe you could talk to the bitblot guys - they used a lot of Lua in Aquaria.

I get the impression that a lot of the code familiar guys here are going to promote python, but uh, I suggest you decide for yourself, and it would be interesting to see why the bb guys chose Lua over it.
User avatar
dudecon
level0
Posts: 6
Joined: Thu Jun 14, 2007 9:38 pm
Contact:

Postby dudecon » Fri Feb 08, 2008 7:42 pm

Some may even go so far as to infer suggested gameplay from said media...If you feel any of the above happening to you, please listen very carefully. You are mistaken.

Okay, so ignoring for a moment the above, I'm going to take a stab at where this is headed.
From the very name "subversion" it is clear that this is not trying to be a city simulator. From the shots we've had earlier of interior spaces, and the continuing work on them, we know that Subversion is headed toward a large scope, but with very fine granularity. Now we're seeing visual representations of completely extraneous control circutry, unless the user will interact with the basic infrastructure controls. The scripting extension means that objects can be programed in some way.
We also know that Introversion is about comprimising computer systems (both in Darwinia and Uplink), as well as all-out large-scale warfare. Why do the buildings have generated structural members, unless we can interact with them?

I'm getting the feeling that Subversion is trying to be a game about the covert intrusion (and possible comprimise) of urban infrastructure and landscape. It will be about how an attacker can enter and conquer a city, perhaps without being seen. It will be about how the fine details can be leveraged to accomplish far-reaching goals. Observing and hacking into elevator controls is only the begining. Air conditioning? Traffic lights? Setting up snipers to control whole square miles of city? Setting demolition charges and bringing down whole skyscrapers? The detail level at this point is immense, and only appears to be increasing, which makes no sense unless the user interacts with the enviroment at all of these levels.

But really, the only thing we know for sure is that I am mistaken.
Artman40
level1
level1
Posts: 67
Joined: Thu Jan 12, 2006 10:47 am

Postby Artman40 » Fri Feb 08, 2008 7:45 pm

And so, "Subversion Collection" is created. Seriously, this engine seems very good for multiple different game genres.
User avatar
Montyphy
level5
level5
Posts: 6745
Joined: Tue Apr 19, 2005 2:28 pm
Location: London, England

Postby Montyphy » Fri Feb 08, 2008 8:39 pm

martin wrote:Ok, so I seem to be picking on the area no one else is talking about but surely you could make that lift in a much simpler way, without simulating sensors and control computers etc?


Sure, there are simpler ways but I'm guessing Chris is hoping that by using such realism it may make it easier to add new interfaces for objects and users to interact with the system.
Uplink help: Check out the Guide or FAQ.
Latest Uplink patch is v1.55.
Mickiscoole
level0
Posts: 1
Joined: Fri Feb 08, 2008 10:42 pm

Postby Mickiscoole » Fri Feb 08, 2008 10:46 pm

The GoldFish wrote:Man, who didn't play Simtower? There's some elevator simulator if ever you needed some!

I remember reading somewhere that SimTower started as a lift simulator

Return to “Introversion Blog”

Who is online

Users browsing this forum: No registered users and 1 guest