• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

-=Code=-

Embedding Python into game engines.

28 posts in this topic

Hi, Has anyone tried embedding (maybe I''m using the wrong word) python into their game? What I mean is a fully functional Python interpreter within the engine eg. you can bring down the console and start writing some Python code and it will work as though on commandline. Anyone think of any uses of such an implementation (beside the one I mention later)? I just saw this being done recently and the guy said something about it speeding up development time, and I''ve been wondering since, how? It was kinda cool. He just typed some stuff in the console and he added weapons and such to a character''s left/right hand.
0

Share this post


Link to post
Share on other sites
I don''t how you could implement this or WHY you would, (If it required gfx) do so... I would spend more time on a scripting lib instead since people could _easially_ modify you''re code.
0

Share this post


Link to post
Share on other sites
I''ve haven''t done it, but I''ve thought about it, and briefly looked into ways to do it easily.

There''s a set of COM interfaces for implementing and running scripts, and there''s a port/implementation/binding for Python. If you provide a COMpliant set of objects to manipulate you''re game, then the user/scriptor has free rain of languages to use - VB Script, JScript, Python, and others... (including C/C++ and VB or even Delphi).
0

Share this post


Link to post
Share on other sites
The Boost project has a C++/Python interoperability library.

Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Andrew Nguyen
I don''t how you could implement this or WHY you would, (If it required gfx) do so... I would spend more time on a scripting lib instead since people could _easially_ modify you''re code.

He''s writing an Engine... meaning the code is supposed to be modifiable. If it''s good enough for Unreal, it''s good enough for ''-=Code=-''.
0

Share this post


Link to post
Share on other sites
I totally realize that. My only thing is WHY he would want to use Python? Mabye a modified version, but just wadding the console isn''t a good idea since Python in my opinion wouldn''t make a good scripter for games. Mabye it COULD, but remember, the only way to do so would be for PYTHON to run the game and that makes execution VERY slow (especiaally for 3d gfx).
0

Share this post


Link to post
Share on other sites
/me has serious doubts regarding Andrew''s knowledge of any parts of his body

Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages.
0

Share this post


Link to post
Share on other sites
Jokes on you! I''m a cadaver with chopped off hands! (j/k)

I know how to use python very well, but, python is very hard to implement. (IMHO) You COULD USE Python to RUN the game, but then it would be extremly slow! I have experience in Python, so trust me, make you''re OWN scripting thing.

But, Python functions are based on c functions so it COULD work, but howw woould you implement the drawing of objects?
0

Share this post


Link to post
Share on other sites
Andrew Nguyen is a doofus. Here''s why:

The Python code, like any other scipting language embedded in a game, would make calls to functions exposed by the game engine. Ergo, the scripting language would define the game mode and maybe additional logic, but the graphics rendering, etc (which you are so hung up on) would have been pre-implemented in whatever language the engine was written in (C/C++/etc).

Before you respond to any technical questions, ask yourself if you understand the question and all its implicit information. Then shut up, because you generally have had nothing to add to these forums.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
0

Share this post


Link to post
Share on other sites
I am NOT saying that Python is going to render graphics. I am asking HOW it would call the gfx. Of course if s/he was to make python call gfx routines, yes he could do it, but then, the interpreter would have to run all of those lines of code.

You see he archetecture on which Python is made dissallows functions from other languages without modifing the code greatly.

You can''t just call a program in Python to show a line without reading the ''Extending Python'' tutorial.
0

Share this post


Link to post
Share on other sites
That is exactly why it''s under advanced help. And either way, you have to then RUN the program from Python then.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Andrew Nguyen
That is exactly why it''s under advanced help.

Go take a look; there''s nothing "advanced" about it. the only reason it''s under "advanced help" is because Alice is designed for non-programmers. For programmers it''s a walk in the park.
quote:
And either way, you have to then RUN the program from Python then.

Wrong again. You call the C functions simply by importing the extension module. For example, say I made a Python module called GSDK to provide access to the graphics engine SDK from Python. To use it in Python, I''d simply do the following:
import GSDK
GSDK.InitGraphics()
GSDK.DrawText("This is NOT hard!")
GSDK.UpdateScreen()
GSDK.Wait(10000)
GSDK.TermGraphics()

Any further under-informed opinions, Mr. I-Am-Python?

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
0

Share this post


Link to post
Share on other sites
I''m using embedded Python in the game I''m working on. My program(C++) loads a python interpreter, feeds it some startup scripts, and then makes calls into the runtime occasionally.

On the other end, my program provides extensions, so that scripts have native hooks into the game itself. A big chunk of the python code that gets called turns around and calls native methods that I''ve provided.

I''m limiting the python scripts to logic-only stuff, I wouldn''t do any graphics with it. And I tried to offload as much as possible into the extension code.

I should note though, that this isn''t easy. There is a *lot* of support code that goes into making this happen. If it wasn''t for the fact that I like python so much, I wouldn''t have even bothered. For the simple game I''m working on it''s gross overkill, but the experience will serve me later when I''m working on something much more scriptable.

If anyone is interested, I''ll get my code cleaned up and maybe post it somewhere. Perhaps even a short tutorial or something on using python as a scripting language.

Take care,
Bill
0

Share this post


Link to post
Share on other sites
Check out Crystal Space http://crystal.sourceforge.net/ and CEL http://cel.sourceforge.net/ There is a Python plugin that is part of the engine. It uses SWIG, however it might give you a clue how to implement it.

Also in the Python docs are how to do C->Python w/o SWIG
0

Share this post


Link to post
Share on other sites
If you''re interested, I''ve written an IRC client that supports Python as a scripting language, and I have to say it''s been very easy.

And yes, I call functions both ways, Python -> C and C -> Python. I do not use SWIG. I haven''t looked into SWIG because there''s just not much to calling C functions from Python:


#define PythonFunction(name) \
PyObject* name(PyObject* self, PyObject* args)
PythonFunction(BaoIrc_MessageBox)
{
char* sMessage;
UINT nType = MB_OK;
char* sCaption = 0;

if (!PyArg_ParseTuple(args, "s|iz:MessageBox", &sMessage, &nType, &sCaption))
return NULL;

if (!sCaption)
sCaption = "BaoIrc";

int res = ::MessageBox(AfxGetMainWnd()->GetSafeHwnd(), sMessage, sCaption, nType);
return Py_BuildValue("i", res);
}


You can download a very buggy version of BaoIrc from http://students.washington.edu/bqn/baoirc

0

Share this post


Link to post
Share on other sites
1) Its very easy to call Python from C/C++ and vice versa. Python has been designed to allow for ease-of-embedding for a long time now.

2) Crystal Space game engine has a Python scripting component, as does the Nebula Device game engine.

3) Disney''s new MMORPG ToonTown uses Python for scripting.

4) Ultima Online II was using Python as its scripting language, though the entire project has since been canned.

5) Blade of Darkness did scripting in Python

6) I''m sure there are more gaming projects, including pro projects, which use Python, but I don''t know them off hand.

7) Nobody is going to write low-level graphics routines in Python, or any other scripting language for that matter. It would be used to do game-logic, AI, that sort of thing. It can easily be made to have access to graphic objects (meshes, etc) at a high-level, move them, rotate them, etc, via calling methods, but all the heavy-lifting would be done underneath the full engine in C/C++ if you''re sane. Python is plenty fast for this type of higher-level scripting.

8) Given #7, if you don''t see how Python could be used to control graphics without having the low level graphics code itself written in Python (this means you Andrew), please stick to the beginners boards only.

9) Andrew Nguyen is an idiot. Is there any way to killfile people on this message board? If not, could it be added? I don''t fault people for ignorance, we are all ignorant on every subject until we take the time to learn it; but to be ignorant and annoying and to think you know what you''re talking about when you don''t just makes you look like a complete tool.


0

Share this post


Link to post
Share on other sites
quote:
Original post by Andrew Nguyen
That''s C->Python, now show me Python->C for GOD''S SAKE!


Why don''t you try reading other people''s posts before posting again? Someone has already posted an example of Python calling C above:

quote:

Wrong again. You call the C functions simply by importing the extension module. For example, say I made a Python module called GSDK to provide access to the graphics engine SDK from Python. To use it in Python, I''d simply do the following:

import GSDK
GSDK.InitGraphics()
GSDK.DrawText("This is NOT hard!"
GSDK.UpdateScreen()
GSDK.Wait(10000)
GSDK.TermGraphics()



Now shut up with your Python->C whining already.
0

Share this post


Link to post
Share on other sites
? Calling Python methods from C is even easier.


PyObject* py; // irc connection object
PyObject* obj; // my existing python object, say an event handler
PyObject* res = PyObject_CallMethod(obj, "OnJoin", "Oss", py, sPrefix, sChans);
Py_XDECREF(res);

0

Share this post


Link to post
Share on other sites