   Where does python fit in?
  [oops - posted this in newtork programming- soz]Hello,I am developing my own architecture for my MMOG. Its a little different to winterdynes! :)I am interested in your opinions regarding development, since I am on the verge of plunging into a first complete build.At present I have a client prog, written in MSVC7 using winsocks to communicate.This is logging into a server, which will validate client moves, etc, and store game info in a MySQL database. The server is also C++.Recently, I've got into python a bit. Its cool!So my first question is - Where do game co's use python? I heard that since its runtime compiled, its good as a scripting language to control AI, objects, etc.Is a python server a bad idea? its slower than C++ being RTcompiled, I think, but really set up for MySQL etc.How does my C++ app talk to python?Many thanksSimon   
Quote:Original post by sipicklesSo my first question is - Where do game co's use python? I heard that since its runtime compiled, its good as a scripting language to control AI, objects, etc.You should really take a look at Civilization IV. Pretty much all the game logic is written in Python, and they supply the Python scripts *with* the game, so you can modify them if you want.Quote:How does my C++ app talk to python?Civ IV uses boost::python.;  ah, I already have boost installed to help me with stoopid c++ strings!   ;  Battlefield 2 uses it as well. I started writing a server entirely in python, but it was too slow for the "inner-loop" stuff, such as constructing packets and object serialization (I wasn't using pickle, as pickles would consume too much bandwidth). I've settled with C#. I am probably going to use python for scripting.   ;  so how do you integrate C++ and python, if c++ is gonna do part of the work, and python the scripting?;  BOOST:Python will allow you to connect python scripts and C++ methods. I suggest you start at www.boost.org/libs/python/doc.That's where I started:)CheersCHris   ;  here's their first sample:char const* greet(){   return "hello, world";}can be exposed to Python by writing a Boost.Python wrapper:#include <boost/python.hpp>using namespace boost::python;BOOST_PYTHON_MODULE(hello){    def("greet", greet);}That's it. We're done. We can now build this as a shared library. The resulting DLL is now visible to Python. Here's a sample Python session:>>> import hello>>> print hello.greet()hello, worldCheersChris   ;Quote:Original post by sipicklesso how do you integrate C++ and python, if c++ is gonna do part of the work, and python the scripting?Well there are two approaches. The first is to embed python within your C++ application.The second, and IMO, the best option is to write your program in python, then write optimized modules in C++ for those sections of code that need it the most. This will reduce the amount of C++ code you write, and it is much easier to implement.For my project I considered this option, but it wouldn't have made much of a difference in speed. My major bottleneck was not code, but rather the slowness of python's class implementation, which keeps all variables as entries in a dictionary.   ;Quote:Original post by sipicklesSo my first question is - Where do game co's use python? I heard that since its runtime compiled, its good as a scripting language to control AI, objects, etc.The usual way is to have the Engine(C++) as the body and your scripting language(python) as the brain.Write your C++(Engine) code with all the important functions that your Engine is going to need and write your python(scripting) code with all the important game logic decisions.  The perfect design would allow you to rewrite the python code and create a new game(without touching the C++) or drop in new C++ code without modifying the python.The second way, is to simply write in a C++ / python hybrid language, where you pass off the tasks between C++ and python, depending on how much better each one handles that task.  The disadvantage of this process, is that you lose the reusibility of the first way, but at the same time, you can write code much faster this way and it's possible to get a much faster game.As for a total python server.  This would depend on what your bottleneck is going to be.  If your server is memory or CPU bound, C++ might be better choice.  If your server is bandwidth bound using python would be fine.  Weither to write one would soley be based on your resources and the game design.   ;  BOOST::python seems, like SWIG, to enable you to use C++ functions in Python scripts.I was thinking more of having a C++ program, accessing Python functions in external files..... is this possible?Thanks   