Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AbrahamR, 7th_zorro, dr_panther, 1 invisible), 702 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 1 of 6 1 2 3 4 5 6
python wrapper #270067
06/05/09 20:24
06/05/09 20:24
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
when cleaning up the mess on my harddisk recently i came across my python wrapper which i started for a6 but never really finished. i played around with it a bit again and updated it to a7.

is there anyone interested in something like that? i think there aren't many python users here?

currently it wraps about 75% of the engine api so it still would need some work...

here is an example:
Code:
# python version of e_tutorial.cpp



from a7 import *

lesson = 3



###############################################################################
if lesson == 1:
    e = Engine("earth.mdl -nwnd -nc")
    while e.frame():
        pass
    e.close()



###############################################################################
if lesson == 2:
    e = Engine("-nwnd -nc")
    e.fps_max = 50
    camera = e.camera
    add_folder("C:\Program Files (x86)\GStudio7\samples")
    level_load("small.hmp")
    while e.frame():
        camera.pan += -3 * e.key_force.x
        camera.tilt += 3 * e.key_force.y
        move = Vector()
        move.x = 6 * (e.key_w - e.key_s)
        move.y = 6 * (e.key_a - e.key_d)
        camera.position += move.rotate(camera.orientation)
    e.close()



###############################################################################
if lesson == 3:
    
    def plop():
        ball.playsound(pong, 100)
    
    def kick():
        speed = Vector(150, 0, 0)
        speed = speed.rotate(camera.orientation)
        speed.z = 75
        ball.ph_addvelcentral(speed)
        plop()
    
    e = Engine("-nwnd -nc")
    e.shadow_stencil = 4
    e.sound_vol = 100
    camera = e.camera
    
    add_folder("C:\Program Files (x86)\GStudio7\samples")
    
    pong = Sound("tap.wav")
    
    splash = Panel()
    splash.bmap = Bitmap("digital.pcx")
    splash.scale_x = float(e.screen_size.x) / splash.bmap.width()
    splash.scale_y = float(e.screen_size.y) / splash.bmap.height()
    splash.flags |= VISIBLE
    
    for i in range(3): e.frame()
    level_load("small.hmp")
    
    ticks = 0
    while ticks < 16:
        ticks += e.time_step
        e.frame()
    splash.remove()
    
    Entity("blood_gsmall+6.tga", flags2=SKY|CUBE, layer=0)
    
    ball = Entity("earth.mdl", (0, 0, 100), None)
    ball.ph_settype(PH_RIGID, PH_SPHERE)
    ball.ph_setmass(1, PH_SPHERE)
    ball.ph_setfriction(90)
    ball.ph_setelasticity(75, 100)
    ball.ph_setdamping(30, 5)
    ball.ph_addvelcentral((2, 2, 0))
    ball.flags |= SHADOW|CAST
    ball.event = plop
    ball.emask |= ENABLE_FRICTION
    
    ph_setgravity((0, 0, -500))
    e.on_space = kick
    
    speed = Vector()
    angular_speed = Vector()
    
    while e.frame():
        
        force = Vector()
        
        force.x = -5 * (e.key_force.x + e.mouse_force.x)
        force.y = 5 * (e.key_force.y + e.mouse_force.y)
        move = vec_accelerate(angular_speed, force, 0.8)
        camera.orientation += move
        
        force.x = 6 * (e.key_w - e.key_s)	
        force.y = 6 * (e.key_a - e.key_d)
        force.z = 6 * (e.key_home - e.key_end)
        move = vec_accelerate(speed, force, 0.5)
        camera.position += move.rotate(camera.orientation)
        
    e.close()


with python it's also possible to do a scheduler:
Code:
from a7_scheduler import *



@schedule
def rotate_entity():
    while 1:
        e.my.pan += 5 * e.time_step
        yield(1) # wait 1 frame



@schedule
def move_camera():
    camera = e.camera
    speed = Vector()
    angular_speed = Vector()
    while 1:
        force = Vector()
        
        force.x = -5 * (e.key_force.x + e.mouse_force.x)
        force.y = 5 * (e.key_force.y + e.mouse_force.y)
        move = vec_accelerate(angular_speed, force, 0.8)
        camera.orientation += move
        
        force.x = 6 * (e.key_w - e.key_s)	
        force.y = 6 * (e.key_a - e.key_d)
        force.z = 6 * (e.key_home - e.key_end)
        move = vec_accelerate(speed, force, 0.5)
        camera.position += move.rotate(camera.orientation)
        
        yield(1) # wait 1 frame



@schedule
def main():
    add_folder("C:\Program Files (x86)\GStudio7\samples")
    e.video_mode = 8

    yield(3) # wait 3 frames
    level_load("small.hmp")
    Entity("blood_gsmall+6.tga", flags2=SKY|CUBE, layer=0)

    Entity("earth.mdl", (0, 0, 100), rotate_entity)

    move_camera()



main()
scheduler()

functions that use wait() need to be decorated with @schedule and wait() = yield() in python but otherwise it works just like in lite-c. smile

Re: python wrapper [Re: ventilator] #270090
06/06/09 04:40
06/06/09 04:40
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
I'm far away from being able to program object oriented, but from the few examples that I saw - and see in your post - of python, it seems to be such a nice clean easy readable language, that I hope to learn it one day.

You show an example of how similar one can program with python to Lite-C.

Do you have an easy example that shows the benefit of using python _instead_ of lite-c, as well?
Maybe, using a class that can be extended to get an advanced AI without the effort one has to make in lite-c. (Just my humble non-professional idea.)

Re: python wrapper [Re: Pappenheimer] #270108
06/06/09 10:33
06/06/09 10:33
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
i don't have an advanced ai example but here are some advantages of python:
  • automatic memory management
  • powerful built-in dynamic data structures (lists, dictionaries, sets,...)
  • powerful string handling
  • the huge python standard library with modules for almost everything you could ever need (web access,...)
  • no long compile times (you can even change the program while it is running.)
  • object orientation (which means that you can subclass Entity() and create different entity types for example, you can use Vector() objects like v1 + (2 * (v2 * -v1)) * v2 instead of having to use the cumbersome vec_ commands, skills aren't necessary because you can just assign an unlimited number of arbitrary properties to entities,...)


disadvantages of python:
  • it is slower than C but in most of my tests it has been fast enough (one case that could be a bit problematic is particle callbacks. calling tenthousands of them per frame is a bit slow with python. such problems can be solved by moving the bottleneck to C though (which is quite easy with tools like cython). for example there could be some predefined particle callbacks in C (they always look very similar anyway) and python just controls their parameters.)


there are projects like google's unladen-swallow or pypy which aim to make python faster.

Re: python wrapper [Re: ventilator] #270146
06/06/09 14:48
06/06/09 14:48
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Just an idea. Can one use such a wrapper with the free Lite-C version?

At the moment I'm working on a workshop for kids - not online, but as crash courses and summer courses with the use of the free version of Lite-C and MED, because the kids should be able to continue their project after the workshop.

Maybe, such a wrapper could be of use for teaching students with lite-c? - I'm not familiar with the requirements of all those studies though.

Re: python wrapper [Re: Pappenheimer] #270162
06/06/09 16:56
06/06/09 16:56
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
i don't think it would work with lite-c because the acknex.dll needs to be bound to the python.exe and as far as i know only the gamestudio editions can do that.

<edit>
it could be that it works with the lite-c editions too if you work directly in the lite-c directory. the acknex.dll security mechanism checks if some files are present in the same directory (like sed.exe and some others) and if it finds them it probably doesn't have to be bound to python.exe.
</edit>

originally my plan was to do the wrapper for gamestudio first (in order to learn how all of this wrapping stuff works) and later move it to ogre or irrlicht. an open source solution with gamestudio-like scripting would be nice. but it would be a lot of work which i have procrastinated so far. smile

Re: python wrapper [Re: ventilator] #270164
06/06/09 17:00
06/06/09 17:00
Joined: Apr 2008
Posts: 437
dracula Offline
Senior Member
dracula  Offline
Senior Member

Joined: Apr 2008
Posts: 437
I am interested in Python. I am not sure what a 'wrapper' is, I could guess but if you told me I would be grateful
thanks

Re: python wrapper [Re: dracula] #270167
06/06/09 17:20
06/06/09 17:20
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
the acknex.dll is for C/C++. if you want to use it from other languages you need a translation layer which converts the data types and wraps function calls and so on. this often gets called "wrapper".

Re: python wrapper [Re: ventilator] #270174
06/06/09 17:37
06/06/09 17:37
Joined: Apr 2008
Posts: 437
dracula Offline
Senior Member
dracula  Offline
Senior Member

Joined: Apr 2008
Posts: 437
Would your proposed wrapper work with Commercial A7 ?

Thanks

(BTW. I have a portable folder with Python, Pygame and other stuff inside and the whole thing works perfectly without installation etc)

Re: python wrapper [Re: ventilator] #270183
06/06/09 18:01
06/06/09 18:01
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Originally Posted By: ventilator
an open source solution with gamestudio-like scripting would be nice. but it would be a lot of work which i have procrastinated so far. smile

I don't understand this last sentence.
Do you mean an own engine similar to acknex? Or, do you mean a dll or whatever which calls the acknex engine and its functions, but is independent to the achnex.dll?

Re: python wrapper [Re: Pappenheimer] #270190
06/06/09 18:37
06/06/09 18:37
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
i mean something totally independent of acknex.dll.

my plan was to use the same (or similar) wrapper with ogre or irrlicht. it would require another layer inbetween which offers an interface similar to acknex.dll.

probably it will never happen though since it would be a lot of work. smile several months probably. but if it worked out there would be a free gamestudio alternative (together with the upcoming blender 2.5 as an user friendly editor).

Quote:
Would your proposed wrapper work with Commercial A7 ?

yes, it would work with all gamestudio editions. i am not sure about the lite-c editions though. someone would have to try that.

Page 1 of 6 1 2 3 4 5 6

Moderated by  aztec, Blink, HeelX 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1