Re: Python script and C++



On Tue, 28 Nov 2006 10:12:23 +0100, Marc 'BlackJack' Rintsch <bj_666@xxxxxxx> wrote:
In <1164691472.172783.151290@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, Ravi Teja
wrote:

I am new to python and currently I am working on a traffic simulation
which I plan to define the various agents using scripting. It's kind of like
scripting for non-playable character in games. I am thinking of using python
for this but I am concerned with running time. Is scripting a lot slower
compared to direct implementation in C++? Does compiling the script help in
any way?

Python is perfectly suitable for this use. Python was in use in video
games in this way when computers were a lot slower.

There's a difference between simulations and games. The simulation will
not always be observed by a human being so it runs as fast as possible.
In games the speed of NPCs is usually limited to a level the player can
deal with.

Yeah. Simulation can mean running for a week on the best hardware available,
with the most optimized code you can come up with. And a week may be
acceptable, while two weeks are not.

But I think Python is fine for such a task.

I am not so sure, but ...

The only way to find out if
it may be to slow is writing a prototype and measure.

.... this is a good approach.

Maybe it's a good
idea to design the API for the "NPCs" independent from the language so you
can also write them in C++ or another scripting language.

However, if that API requires thousands of calls per second during
simulation time, it doesn't help speed much, because calling C code from
Python is a pretty heavy thing in itself. The big win is when you spend a
lot of uninterrupted CPU time in C code.

One approach is to write the executive engine in C++ (once again: if needed)
and the compiler/configuration subsystem -- the thing that generates the
simulated world -- in Python. That's a perfect place for a flexible,
high-level language.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
.



Relevant Pages

  • Whats the best Python Book for me
    ... scripting for some games that are coming out. ... What book would you recommend. ... I am thinking Teach Your Self Python in 24 Hours is probably the best place ...
    (comp.lang.python)
  • Re: Prey - demo impressions - kind of lame
    ... indeed like scripted FPS? ... YOu have no idea about the range and depth of games I play. ... But what needs to be added to "scripting is good to ... and has no effect on potential gameplay content. ...
    (comp.sys.ibm.pc.games.action)
  • Re: Batch commands on Windows
    ... OK, actually on second test, the problem is mostly with IDLE, but not ... # this actually does the same thing as Python, ... then delete the batch file, but that seems like an awful hack. ... And that seems like the most basic thing that a scripting ...
    (comp.lang.python)
  • Re: can python do this?
    ... I don't know if any Linux web browsers are particularly scriptable. ... I think this should be easily doable with Python, ... keyboard shortcuts without activating iTunes. ... but that use doesn't need scripting. ...
    (comp.lang.python)
  • Scripting C++ Game AI object using Python Generators
    ... I am interested in using Python as a scripting ... language for a game that is primarily implemented in C++, ... interested in using generators in those scripts... ...
    (comp.lang.python)