473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Scripting C++ Game AI object using Python Generators

As the subject suggests, I am interested in using Python as a scripting
language for a game that is primarily implemented in C++, and I am also
interested in using generators in those scripts...

Initially I was justing looking at using Python for some event
scripting. So basically an event would trigger an object to run the
appropriate Python script, which would be run in it's entirety and
return control to the C++ code.

After looking at the Python docs and a few articles I've found, I'm
really excited by the idea of using Python generators as micro-threads
for game AI. I've been playing around writing play Python applications
with classes that use generators as update methods, and it's cool as
hell. I've also managed to write a C++ program with an embedded Python
interpreter than runs a script, and I've used the Boost Python library
to expose some C++ functions to Python.

Where I would like to go from there is to be able to associate a Python
script with a C++ object, so that on every frame update I could run the
Python script (which would have functionality implemented as a
generator) until it yields, then move on to updating the next object,
and on the next frame, have the generator continue from where it left off.

I haven't really attempted this yet, because I'm not quite sure where to
start. I'm not sure how to have a Python script persistently attached to
a C++ object so that execution can be returned to C++ from a yield and
continue where it left off on the following update cycle. I am beginning
to suspect, based on the docs and articles I've read, that to get this
sort of functionality I should be looking at exporting all my C++
objects to Python, and then using Python as the glue to write the main
loop of the application, calling out to the C++ objects as required. Is
this assumption correct, or can I get the functionality I want while
still keeping this a C++ application? Should I be looking at writing the
AI modules as Python objects and attaching these to my C++ objects at
runtime?

Initially I was just looking for something to use for simple scripting,
and we were planning to do a custom scripting language, but I know just
enough about language design and implementation to be very weary of
having to maintain our own language when there are proven embeddable
languages out there than are more powerful (and if I wanted to stick
with simple I'd use Lua, which was just a breeze to embed). But the more
I look at Python, the more ambitious I'm getting about how much we could
potentially do by using Python at least as a scripting language and
possible as glue... however, I'm not necessarily sure we need all this
functionality (generators included), but that doesn't mean I don't want
it, and I do like the idea of having more power and flexibility than is
strictly necessary, so that we will have the power to do things we
didn't necessarily plan for or expect. We are using Gamebryo as our
rendering library, so that is a major constraint. That is very much a
C++ library, so this is very much a C++ application. I am also a bit
concerned about scaring other developers on my team... We need a
scripting language, and everyone can deal with that as long as we
pretend that the scripting language is a separate thing for designers,
but I'm afraid if I start suggesting the programmers write our main
application in Python and export the C++ code, I'm in danger of becoming
a heretic ;) I'm not even sure if that's practical, given our C++
middleware and performance concerns, but that's why I'm posting here, to
get some assistance from the experts.

Thanks in advance for any advice
Nick
Jul 18 '05 #1
4 3757
Nick,

I am not able to understand your request fully (problem on my side, I'm not
into Game Programming) ...

but many of your keywords I heard last time in a talk by Chris Tismer,
speaking about http://www.stackless.com/ stacklass Python at Europython in
Charleroi.

Maybe you should look there and maybe send your request directly to him? I
saw him demonstrating a large game application with microthreads and
generators and whatsoever (I just remember the words :)) )

Harald
Jul 18 '05 #2
Yeah, Stackless sounds interesting, and it was used in Eve-Online. At
this point I'm under the impression that a lot of the specific
advantages of stackless have to do with distributed applications, where
you can have lots and lots of remotely instantiated Python objects
running as separate microthreads, managed by software on your servers,
with minimal task-switching overhead. My projects is not online
multiplayer, so I'm not sure if Stackless would have advantages for my
project above and beyond the generators already in Python, but maybe
someone else can shed some light on that?

It may be worthwhile for me to get in touch with them regarding my
project though. Thanks for the suggestion.

Nick

Harald Massa wrote:
Nick,

I am not able to understand your request fully (problem on my side, I'm not
into Game Programming) ...

but many of your keywords I heard last time in a talk by Chris Tismer,
speaking about http://www.stackless.com/ stacklass Python at Europython in
Charleroi.

Maybe you should look there and maybe send your request directly to him? I
saw him demonstrating a large game application with microthreads and
generators and whatsoever (I just remember the words :)) )

Harald

Jul 18 '05 #3
|Thus Spake The_Incubator On the now historical date of Sun, 04 Jan 2004
03:32:11 -0800|
Where I would like to go from there is to be able to associate a Python
script with a C++ object, so that on every frame update I could run the
Python script (which would have functionality implemented as a generator)
until it yields, then move on to updating the next object, and on the next
frame, have the generator continue from where it left off.

I have not dabbled with boost, but I like pyrex, and it allows you to
write c++ classes that can run python code.
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

You should at least dig in and skim over the c/python api. You'll learn a
lot about what pyrex does. I suggest "The Python Bible"
http://www.amazon.com/exec/obidos/tg...32758?v=glance
Of all the documents I've scanned so far, it was the one that I understood
best. YMMV. It has a kind of cookbook method: "Here's how you do this,
Here's how you deal with that kind of data, etc"

Sam Walters

--
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
Do you really want to go there?"""

Jul 18 '05 #4
Harald!

I saw a message you wrote here last spring but being unable to reply to that
one I do that here instead.

You were interested in a component that creates thumbnails from webpages.
Check out http://www.uniworkstech.com/com.htm , this one does just that. Any
page, any thumb size and emulates any screen resolution (even weird ones
like 1024x10000).

Good luck!

/Linus
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: O'Neal Computer Programmer | last post by:
I was reading here: http://groups.google.com/groups?q=elemental+group:comp.lang.python.*&hl=en&lr=&ie=UTF-8&group=comp.lang.python.*&selm=mailman.1044572235.32593.python-list%40python.org&rnum=3...
3
by: Carlos Ribeiro | last post by:
As a side track of my latest investigations, I began to rely heavily on generators for some stuff where I would previsouly use a more conventional approach. Whenever I need to process a list, I'm...
22
by: Ajay | last post by:
hi! is there an authoritative source on the performance of scripting languages such as python vs. something like java, c, c++. its for a report, so it would be awesome if i could quote some...
5
by: Robert Oschler | last post by:
Preamble: - I know this is the Python forum - I know about (and have used) Jython I already posted this question in comp.lang.java. But after a week I have still not received a single reply....
2
by: Terry Reedy | last post by:
According to PCGamer, Jan05, p52: "*Civilization IV* has been designed to fully support the mod community. The game is written using flexible XML data files and the Python scripting language...
33
by: Quest Master | last post by:
I am interested in developing an application where the user has an ample amount of power to customize the application to their needs, and I feel this would best be accomplished if a scripting...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
3
by: heavydada | last post by:
I'm writing a small game in python and I need to be able to run some scripts inside the game. In the game I have these creatures each with some attributes like name and weight and an action. Right...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.