Beyond Python

[ LiB ]

Beyond Python

So what else is there besides games and graphics? Well, a whole heckuva lot, actually. Being the adaptable language that it is, you'll find Python sunning on rocks and slithering in the grass just about everywhere on the planet. The projects in this section may particularly pique your interest.

Beyond

One problem with 3D titles is the massive amounts of knowledge and work required to design, maintain, and update them. Another is the constant re-engineering each independent gaming company must fund and support in order to create the latest and greatest. Beyond is a reusable object framework for game design that was created to address these problems. The idea behind the Beyond project was to identify which parts of the process are works that could be reusable, and then wrap them up as components in order to create robust, easily modifiable 3D games. Python was chosen for this project because of its adaptability to multiple platforms, and its extensibility.

The first version of Beyond, Beyond 1, was the development project and platform for UO2, which was to be an imaginary-planet, massively multiplayer game released by Origin Systems. Based on the Ultima fiction originally created by Richard Garriott, UO2 had player avatars with highly customizable identities capable of interacting with objects and other players in a massive world. Unfortunately, UO2 was dropped and never actually saw the light of day, but this has been a minor setback for one of the principle developers, Jason Asbahr, who now leads an open -source, virtual-world, MMP Python framework, Beyond 2.

Beyond 2 is still very young, with only Version 0.0.1 released, but, of course, it is being built on the backs of several other highly successful platforms, including the Nebula Device by Radon Labs, Beyond 1, and Twisted Python.

Technically, the original Beyond 1 project was based on many languages, but Python had a particularly interesting role. Client-server information is encrypted and passed through constructs called SimObjects using remote method invocations in Python.

The SimObject was a root object, or superclass, for all other objects. SimObjects were organized in an object-oriented hierarchy, and could perform actions by executing methods on themselves or other SimObjects .

Beyond 1 was also data-driven and had a master game database. World builders were able to alter and expand the world by adding behaviors, entities, and data into the database without changing the actual runtime code. Clients (players) would connect to local Python area servers which eventually connected to a main data base server and the main game database.

Sound libraries, network communications, and graphics were all wrapped into Python as extensions using SWIG (short for Simplified Wrapper and Interface Generator; more on SWIG in Chapter 12). Functions in C and C++ are exposed as Python function objects.

Progress on Beyond 2 and Jason Asbahr's other projects can be found at his Website, at http://www.asbahr.com/index.html.

The site includes several papers he has presented on Python and Python games. This set of papers also includes a port of Python onto the PlayStation 2 and Nintendo platforms.

Pippy

Pippy is a port of the Python language to the PalmOS currently under development at Endeavors Technology. Although still young, the latest version runs on Palm OS 3.5 or higher. A handful of the standard Python modules have been removed to reduce the code footprint, though these removals are mostly code features (like dynamic linking libraries) that aren't necessary on a Palm platform. Pippy can be freely distributed as long as the copyright notice is included; the latest versions can be found on its Sourceforge page, at http://pippy. sourceforge .net.

A handful of Python features have been removed for smooth running on the Palm, including the following:

  • Floating point numbers /objects.

  • Complex numbers/objects.

  • Python parser and compiler

  • Documentation strings

  • Dynamic linking

  • Signals

  • Path- related code

  • File I/O ( stdio and stderr are simulated)

  • Most of the Python library modules

  • Most of the Python extension modules

Pippy does include a version of the popular Python interactive interface and a keyword popup menu interface with both a Keywords and Modules menu that contain built-in Python names , reserved keywords, and a listing of the built-in and extension modules.

Development work may still be needed on Pippy to reduce the code footprint, and currently Pippy works on a reduced version of Python 1.5.2. There are a few issues to work out with the Palm's stack (work is underway to bring Stackless Python to Pippy) and Palm's dynamic heap, but the early project results appear promising , the key being an active community willing to take the project to the next level.

Stackless Python

Stackless Python is a development effort led by Christian Tismer, and is a Python variant that doesn't use the C stack. The Python interpreter is written in C, so at some level every Python action is executed via C. Mostly this is good, but sometimes having multiple instances of Python C code running on the stack can cause problems, for example with recursion and with object references that build up on the stack.

Stackless has received quite a bit of community support and has been highlighted at a number of Python conferences. Several companies, including Twin Sun, IronPort, and CCP Games have used Stackless in development. Stackless is a super-tool for Python work using co-routines or micro-threads; the popular MMOG Eve Online is a good example of Stackless use in this case. Stackless has gone through a few variations, and Tismer continues to maintain, update, and further improve the concept, tirelessly making Stackless faster, more portable, and efficient.

You can find more information on Stackless at Christian Tismer's Website, at http://www.tismer.com/.

Twisted

Twisted began its existence as an open-source, massive, multi-player game called Twisted Reality . Since then Twisted has become a way to create network applications, from network transports and protocols to secure client servers. Twisted is no longer just a toy. It is a competitive production server system, designed with a small footprint to run on low-end hardware and still be capable of handling thousands of users.

Twisted supports the following:

  • Win32 events

  • GUI (GTK, Qt, wxPython, Tkinter, and so on)

  • TCP, SSL, UDP, Multicast, and UNIX sockets and subprocesses

  • Scheduling

  • Threading integration

  • RDBMS event loop integration

Twisted also comes with prebuilt implementations , including:

  • A complete Web framework

  • Frameworks providing facilities on top of SSH, FTP, and HTTP

  • An NNTP server framework

  • A user authentication system

  • An instant messenger

Twisted has been the basis for a handful of other open source projects, including CVSToys, Hep, Bannerfish, Beyond 2, and DocmaServer. The users of Twisted include a number of high-profile companies like Masters of Branding, NASA, and Mailman.

Twisted programs usually use the twisted.internet.app.Application function. The applications created with this function are actually Python objects and can be used along with the variety of built-in tools to create and manipulative these applications Twisted comes with, just like any other Python object. The process for creating an application in Twisted normally involves creating an application object and then choosing a reactor (twisted.inter net.reactor ), which is basically a toolkit for running Twisted on different platforms, for the application.

Reactors are the core of the event loop in Twisted, and they provide a basic interface to a number of services, including network communications, threading, and event dispatching. A reactor implements a set of interfaces, usually dependent upon which platform Twisted is playing on. After setting up an application and a rector, you can implement Twisted network protocol parsing and handing with twisted.internet.protocol.Protocol .

Twisted also has Factory classes (twisted.internet.protocol.Factory ) where persistent configuration is kept. The default factory classes can instantiate each protocol.

Programming in Twisted looks remarkably like Python network programming (surprise!). First you must import the reactor and protocol:

 from twisted.internet import reactor, protocol 

Then let's say you wanted the protocol to react to a connection:

 class MyTwistedClass(Protocol): def MyConnection (self):                 # do something         self.transport.loseConnection() 

Now set up Twisted listening on port 5555:

 def main():         factory = protocol.ServerFactory()         factory.protocol = Echo         reactor.listenTCP(5555,factory)         reactor.run() if _name_=='_main_':         main() 

Twisted itself can be found on its Sourceforge page at http://sourceforge.net/projects/twisted.

Twisted also has an active community of users and developers who can be found online at the Twisted Matrix, at http://twistedmatrix.com.

[ LiB ]


Game Programming with Pyton, Lua and Ruby
Game Programming with Pyton, Lua and Ruby
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net