Jump to content

  • Log In with Google      Sign In   
  • Create Account


Embedding Python into game engines.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
28 replies to this topic

#1 -=Code=-   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 January 2002 - 06:45 PM

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.

Sponsor:

#2 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 20 January 2002 - 06:53 PM

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.

#3 Shannon Barber   Moderators   -  Reputation: 1361

Like
Likes
Like

Posted 20 January 2002 - 07:13 PM

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).

#4 Arild Fines   Members   -  Reputation: 968

Like
Likes
Like

Posted 20 January 2002 - 07:17 PM

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.

#5 Kylotan   Moderators   -  Reputation: 3333

Like
Likes
Like

Posted 21 January 2002 - 12:06 AM

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=-''.


#6 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 03:35 AM

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).

#7 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 03:36 AM

A small comment:

I KNOW PYTHON BETTER THAN THE BACK OF MY HAND!

#8 Arild Fines   Members   -  Reputation: 968

Like
Likes
Like

Posted 21 January 2002 - 06:59 AM

/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.

#9 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 08:55 AM

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?

#10 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 21 January 2002 - 09:03 AM

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!


#11 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 09:54 AM

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.

#12 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 21 January 2002 - 10:00 AM

You can write a C function and call it from Python. It''s pretty easy; even the Alice website has a section on it in their advanced help.

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


#13 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 11:27 AM

That is exactly why it''s under advanced help. And either way, you have to then RUN the program from Python then.


#14 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 21 January 2002 - 12:19 PM

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!


#15 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 12:40 PM

I understand that C->Python is easy. Now show me Python->C (Don''t go off using swig! ... although...)

#16 Siebharinn   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 January 2002 - 12:55 PM

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

#17 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 12:58 PM

Darn, a post that can go both ways... :p

#18 rds   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 January 2002 - 01:03 PM

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

#19 Andrew Nguyen   Members   -  Reputation: 150

Like
Likes
Like

Posted 21 January 2002 - 01:05 PM

I meant Python->C WITHOUT SWIG

#20 mutex   Members   -  Reputation: 1109

Like
Likes
Like

Posted 21 January 2002 - 01:21 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS