|
python wrapper
#270067
06/05/09 20:24
06/05/09 20:24
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
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: # 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: 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.
|
|
|
Re: python wrapper
[Re: Pappenheimer]
#270108
06/06/09 10:33
06/06/09 10:33
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
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: Pappenheimer]
#270162
06/06/09 16:56
06/06/09 16:56
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
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.
|
|
|
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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
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. 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
OP
Senior Expert
|
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. 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). 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.
|
|
|
|