Switch between Python-Ogre and original Ogre

newbie007

01-09-2008 06:08:57

Python-Ogre is ported from Ogre, and even many many names of the methods seem to be the same as those in Ogre...

Maybe we can create applications in Python-Ogre and finally before production we port the applications back to Ogre.

I wonder, is this pipeline possible? Anybody tried this?

There are at least 2 advantages:

- Performance gain:
There should be some, not much, though.

- Protection from decompilation:
This is the most important...
It's really not so hard to decompile a Python application, even it's been obfuscated before compiling into bytecodes.

Zyzle

01-09-2008 06:42:57

I'm sure its possible but my question would be, why bother? Why not just write the app from the start in C++?

The main problem I can see with this is the difference in the type system between the two languages, I can see a lot of problems trying to convert from the dynamic system back to a static one.

Another potential problem is memory management, in python this is done for you through reference counting, i.e. as soon as an object has no references in the callstack it is flagged for removal (that is right isnt it?) in C++ you'll have to do all memory management yourself.

I'm really not sure why you would want this. Also I'm not an expert but is it really that much more difficult to decompile C++ code than python bytecode?

newbie007

01-09-2008 07:00:16

I'm sure its possible but my question would be, why bother? Why not just write the app from the start in C++?


The problem is that, if start in C++, the debugging would be much much MUCH more painful, and more complicated.

If there's a more mechanical way to port from Python version to C++ version, that would be so nice that the learning curve of using Ogre series libraries may become even less steep... (I think.)

The main problem I can see with this is the difference in the type system between the two languages, I can see a lot of problems trying to convert from the dynamic system back to a static one.

Another potential problem is memory management, in python this is done for you through reference counting, i.e. as soon as an object has no references in the callstack it is flagged for removal (that is right isnt it?) in C++ you'll have to do all memory management yourself.

I'm really not sure why you would want this. Also I'm not an expert but is it really that much more difficult to decompile C++ code than python bytecode?


Yes, if you're saying C++ for native systems, not the .Net one...
If I understand correctly, those compiled binaries can at most be decompiled back to assembly codes.

saluk

01-09-2008 08:13:50

If the purpose of hiding code is to do things like add copy protection, c++ hasn't really helped game makers much in this regard. If it's to stop people from writing cheats in an online game, again, c++ hasn't helped. It makes things a little more difficult, granted, but hackers are quite resourceful. The people you lock out tend to be people who wouldn't know how to make your source code do anything meaningful anyway.

Also it is possible to encrypt your code which is then loaded from an executable. Of course they can still decompile the C code, find the decryption key, and unlock the code, but it does add more steps. In the end though, it wont stop the most resourceful people, and once one of those hackers break it, it might as well be broken for the entire internets.

The only way to truly protect code, written in any language, is to have it be run off a server which you control. Remember the rule of copy protection: if the user can run it, the user can copy it. You can make it hard, but you can never make it impossible.



I don't see how something could ever automatically convert python-ogre projects to c++, but if you are careful, you should be able to set up a system where you can prototype things on the python side (for the nice debugging) and then quickly port that section of code over to the c side. Maybe keep it in python long enough to get all of the basics working, then port that to c and expand from there. That way at the beginning, where you aren't sure what approach or design would work best, you have the quick, no compile, fast writing that comes with python; and then when the architecture is more defined you can get the speed in c.

Other options, for speed especially, are to write the whole thing in python-ogre first, profile it (find the slowest parts), and rewrite the slowest functions into a c extension. I have heard this is the best way, because python is fast enough for most things, so you aren't really speeding things up to use c for the whole thing, just extending development time. Whereas if you know which parts of the code really need C, you can fix the bottlenecks, and the code is easy to continue to maintain. Although personally I've never messed with c extensions, I have found even in python that often optimizing a small part of it will take away any slowdowns I had.

With python-ogre, most of the parts that need c++ code are already written in c++, the rendering, probably the physics, animation, etc. All you are doing is setting up the pieces and hooking them together. Only if you have very advanced ai or are doing a lot of logic processing would I even consider dropping down to the c level in a python-ogre project.



But yeah, you don't gain much from ogre specifically by using python-ogre, as you are using the same function calls. What you benefit from is the dynamic scripting, and python datatypes and libraries, none of which would be convertable directly to c code.

SiWi

01-09-2008 10:44:52

Another potential problem is memory management, in python this is done for you through reference counting, i.e. as soon as an object has no references in the callstack it is flagged for removal (that is right isnt it?) in C++ you'll have to do all memory management yourself.
In general yes, but there are a number of memory allocations in PythonOgre, that you should delete yourself, because of the underlying C++ libraries.
But I'm no expert at this either.
Well, conversion from Python to C++ is not that hard, but you should definetly know C++ as well as the STL.
I don't know about any "automatic" code conversion tools, as should be quite hard to make some, as the code converter would've to decide on the type of an object(including deletion and reinizalisation, when changing the type), and if variable is a value, a pointer or a reference. But these are just some basic things, there are even harder... .
Well you're right C++ code can only be recompiled to Assembler, bytecode is quite a bit easier to decompile.
For a performance wise solution it might be the better to go with IronPython and MOGRE.
The code conversion would come at a neglible amount of time cost, but there might be a reasonable performance improvement.
But then again I don't know how PythonOgre performs compared to Mogre and PythonOgre has a lot more libraries and is near to bug free compared to Mogre.

Conclusion:
PythonOgre is the best way to develop with Ogre( read: to develop games) in alternative languages as it has a broad spectrum of libraries, is very stable and doesn't take too much of a performance hit PLUS Python is just smart. 8)

EDIT: Just found this: http://code.google.com/p/shedskin/

saluk

01-09-2008 20:43:47

Yes there is shedskin, cython, rpython, ctypes, and various other ways to write pieces of your program in c, or compile pieces of your program to c, if it is very carefully written. These solutions are worth looking into when trying to speed up your program. They aren't good for writing an entire program with though, as they are fairly restrictive. You want to "drop down" only when it makes sense to.

They also don't solve the "problem" of hackable source code. Encryption/obfuscation are the only things I can see that can help there.

SiWi

02-09-2008 09:30:05

Well, as I see it this hackable source code thing is not too much of a problem. There is no source code I know that can't be rehacked.
Also there is this tool for Python to makes your source code human unreadable(see PythonOgre).