Jump to content


Photo

Python Integration


  • Please log in to reply
30 replies to this topic

#1 red knight

red knight

    Xenocide Project Leader

  • Xenocide Inactive
  • 3,310 posts

Posted 31 January 2005 - 07:33 AM

@Guyver: Just for the record if you didnt notice it too. PyOgre addon (Python Ogre Bindings) are available now, so take that in mind when you start with the Python Integration.

Greetings
Red Knight
Sourceforge Nick: flois - Federico Andres Lois
Visit my blog at: flois.blogspot.com

Posted Image

Pookie cover me, I am going in.

#2 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 31 January 2005 - 01:50 PM

Thanks Red Knight. I know about PyOgre, but like all bindings of engines, it's rather useless, becouse we're writting C++ code, which is fastest possible solution, and we don't need to access Ogre in python scripts, becouse we're gonna use this scripts on higher level than engine level.

Guyver
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#3 red knight

red knight

    Xenocide Project Leader

  • Xenocide Inactive
  • 3,310 posts

Posted 31 January 2005 - 02:59 PM

Thanks Red Knight. I know about PyOgre, but like all bindings of engines, it's rather useless, becouse we're writting C++ code, which is fastest possible solution, and we don't need to access Ogre in python scripts, becouse we're gonna use this scripts on higher level than engine level.

Guyver

<{POST_SNAPBACK}>

I just wanted to let you know only, because that project has been stalled for a long time. It may be useful to tweak stuff without recompiling though, but dont concentrate on that.

Greetings
Red Knight
Sourceforge Nick: flois - Federico Andres Lois
Visit my blog at: flois.blogspot.com

Posted Image

Pookie cover me, I am going in.

#4 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 31 January 2005 - 03:38 PM

I just wanted to let you know only, because that project has been stalled for a long time. It may be useful to tweak stuff without recompiling though, but dont concentrate on that.

Greetings
Red Knight

<{POST_SNAPBACK}>

Ok, I'll keep an eye on it.

Guyver
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#5 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 15 March 2005 - 06:46 AM

Preliminary console dialog has been checked in. :)

Good news, cuz that brings us closer to python scripting.

Now I gotta research more on boost::python and python-embedding.

Guyver
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#6 Beetle

Beetle

    Programming Department

  • Xenocide Inactive
  • 350 posts

Posted 15 March 2005 - 05:42 PM

Problems with compiling :(

first error of missing pyconfig.h file. When i have added folder to "additional include directories" compiling go with some warinigs
scriptsystem.cpp
d:\Programming\Projekty\Xenocide\xenocide\src\common\console\scriptsystem.cpp(115) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
        while calling the constructor 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax>::_Myt &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]
        d:\progs\vs\Vc7\include\xstring(321) : see declaration of 'std::basic_string<_Elem,_Traits,_Ax>::__ctor'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]
        and
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]

and linker error with xenoluncher :(
xenocommon.lib(settings.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) private: void * __thiscall Ogre::MemoryManager::op_new_sc(unsigned int,unsigned int)" (__imp_?op_new_sc@MemoryManager@Ogre@@AAEPAXII@Z) referenced in function 
<< and much more >>

Sorry for so quik post, but today i have very long day :( i will look into it deeper tomorow, posting here only to let you know :)

Greetings,
Beetle
Posted Image

#7 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 16 March 2005 - 10:04 AM

I don't know why you get that unresolved symbol, that warning I know and don't know how to throw it away. I updated project files with proper paths also.

EDIT: get python_bin package from Updater (I forgot python24.dll in common package ;) ).

Guyver

Edited by guyver6, 16 March 2005 - 12:34 PM.

Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#8 Beetle

Beetle

    Programming Department

  • Xenocide Inactive
  • 350 posts

Posted 16 March 2005 - 02:50 PM

Hi

About linker error:
When i copied additional dependencies (lib files) from xenoui to xenoluncher everything compiled ok. Maybe you should check that?

About console, great work! It will be VERY useful (it is very annoying to always look into log if you want to check only one small thing). I can’t wait until I can add some functions to console :)

Greetings,

Beetle
Posted Image

#9 rincewind

rincewind

    Programming Department

  • Xenocide Programming Department
  • 541 posts

Posted 16 March 2005 - 03:37 PM

Hi

About linker error:
When i copied additional dependencies (lib files) from xenoui to xenoluncher everything compiled ok. Maybe you should check that?

About console, great work! It will be VERY useful (it is very annoying to always look into log if you want to check only one small thing). I can’t wait until I can add some functions to console :)

Greetings,

Beetle

<{POST_SNAPBACK}>

The linker error is now a known issue, I'm currently in the process of getting rid of it. It's cased by settings-class depending on Ogre. For now, you have to copy all dll's from system_d dir to xenocidegame (or system if you use release build). Plus the additional dependencies.

Greetings,

Rincewind
Posted Image

I love boost!!! The next best thing since the invention of C++.

#10 Beetle

Beetle

    Programming Department

  • Xenocide Inactive
  • 350 posts

Posted 16 March 2005 - 03:48 PM

Yes i noticed this :) i also noticed that i should add callback to audio_musicvolume setting.

Beetle
Posted Image

#11 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 17 March 2005 - 05:29 AM

Console was a must, I'm now extending it.

You can already find that you can set and get settings using set/get in console in game. So if you add callback for audio volume it's highly possible to be able to control volume from console :)

Also, today exec command should be ready (allowing you to execute console scripts) which will replace our .cfg files. Rincewind is working on Settings enhancements, so it will look really nice. Stay tuned :)

Guyver
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#12 rincewind

rincewind

    Programming Department

  • Xenocide Programming Department
  • 541 posts

Posted 17 March 2005 - 05:38 AM

I would also add not to add too much code with settings right now, as there will be some major changes soon.

rincewind
Posted Image

I love boost!!! The next best thing since the invention of C++.

#13 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 21 March 2005 - 05:14 PM

I have a little update on scripting. First of all check this out:
Posted Image

As you can see it's actually working pretty nice. Thou, it's Lua, not python. I was trying and trying to make python work like I wanted it to work, but unfortunately looks like python is designed more to be stand-alone programming language, than embeddable one. So I've given Lua a try and... well, you can see it on screenshot. Anyway, I think we can use lua for scripting, what do you think?

Guyver

Edited by guyver6, 21 March 2005 - 05:16 PM.

Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#14 red knight

red knight

    Xenocide Project Leader

  • Xenocide Inactive
  • 3,310 posts

Posted 22 March 2005 - 10:04 AM

Lua is a good bet too.

Greetings
Red Knight
Sourceforge Nick: flois - Federico Andres Lois
Visit my blog at: flois.blogspot.com

Posted Image

Pookie cover me, I am going in.

#15 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 22 March 2005 - 03:52 PM

Ok, code commited, package in Updater. Have phun :)

NOTE: I compiled lua and lualib into luabind, two less libraries and better release build optimization :).

Guyver
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#16 kamikazejay

kamikazejay

    Sergeant

  • Forum Members
  • PipPipPip
  • 10 posts

Posted 02 April 2005 - 01:10 PM

Is the idea that the entire overlord AI system is scripted?

Edited by kamikazejay, 02 April 2005 - 01:38 PM.


#17 rincewind

rincewind

    Programming Department

  • Xenocide Programming Department
  • 541 posts

Posted 02 April 2005 - 02:16 PM

Is the idea that the entire overlord AI system is scripted?

<{POST_SNAPBACK}>

The high-level stuff, yes. Probably even Mission-AI.

Rincewind
Posted Image

I love boost!!! The next best thing since the invention of C++.

#18 Beetle

Beetle

    Programming Department

  • Xenocide Inactive
  • 350 posts

Posted 07 April 2005 - 04:25 AM

When i write into console something like:

set audio_music false

Exceptions occur (boost bad lexical cast) . Ok i know that i should write 0 instead of false, but an exception? It closes whole program, i think that it should be only some error on console :)

Greetings,
Beetle
Posted Image

#19 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 07 April 2005 - 06:29 AM

That's true, console and settings need a little more user-friendliness :wink1:

Anyway, I'll look at it when I'm finished with XML.

Guyver
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#20 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 08 June 2005 - 01:15 PM

Could somebody describe the multi-line stuff in Console?

For me, it seems that the Console isn't reporting all errors (for example if I type an incorrect lua command or similar, there is no error message), or the Console regonises it as a multi-line command, which I find rather confusing.

- Garo

#21 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 03 January 2006 - 08:41 AM

Time to push this topic back up.

Note-to-self (others might find this valuable also): http://wiki.python.o...st.python/HowTo

- Garo =)

#22 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 04 January 2006 - 06:32 AM

Darn, I was looking for this topic a while ago and couldn't find it :).
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#23 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 06 January 2006 - 03:37 PM

Oyeah! Got python integrated into dagonsquirrels console. One picture tells you more than a thousand words:

Posted Image

We are hoping with guyver6 that the dagonsquirrel branch can be merged back to HEAD this weekend =)

- Garo

#24 red knight

red knight

    Xenocide Project Leader

  • Xenocide Inactive
  • 3,310 posts

Posted 06 January 2006 - 05:54 PM

Excelent work Guyver (as always ;) ).. will meet you soon on the irc channel. I will be auditing a little the new source :D (You have time to clean it and put the dust under the carpet :P ) -- JK .

Greetings
Red Knight
Sourceforge Nick: flois - Federico Andres Lois
Visit my blog at: flois.blogspot.com

Posted Image

Pookie cover me, I am going in.

#25 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 07 January 2006 - 01:08 PM

Excelent work Guyver (as always ;) ).. will meet you soon on the irc channel. I will be auditing a little the new source :D (You have time to clean it and put the dust under the carpet :P ) --  JK .

Greetings
Red Knight

<{POST_SNAPBACK}>

Of course half of the fame goes to Garo, since he's the one who made lots of work on Console. Atm I'm programming CEGUIPython script module, so we don't miss Lua anyhow.

PS. I'm logging onto IRC too.
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#26 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 10 January 2006 - 04:50 AM

Now hear this! Now hear this!

Python Integrated Development Environment is now available at http://projectxenoci...ramming/spe.exe. This is self-extracting archive (just point it to the dir you want SPE installed). This IDE contains all we would ever need to develop Python code (together with remote debugger which I'll integrate into Xenocide in the near future).

Run spe.cmd to execute IDE

Btw, please test if this package works for you, I tried to make it standalone, but I don't have a machine without python installed, so I can't test it too much.

EDIT: if the link doesn't work - wait a while, I'm uploading, it's >20MB ;)

Edited by guyver6, 10 January 2006 - 04:51 AM.

Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#27 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 16 January 2006 - 03:52 PM

This is mainly for me so I can explain this tomorrow at work

mthread.py
#import generators
import generalmessage

def foo():
    yield 1
    yield 2


class ThreadManager:
    
    def __init__(self):
        self.counter = 0 #unique id for every thread
        self.threads = {}
    
    def schedule(self, elapsedTime):
        toBeRemoved = []
        print "cheduler running"
        for uid, (thread, threadGenerator) in self.threads.iteritems():
            try:
                threadGenerator.next()
        
            except StopIteration:
                toBeRemoved.append(uid)

        for uid in toBeRemoved:
            del self.threads[uid]
        
            
            
    def addThread(self, thread):
        self.threads[self.counter] = (thread, thread())
        self.counter += 1
        
        
        
class ThreadBase:
    
    def __call__(self):
        return self.run()

    def callbackFirst(self, newState):
        print "Callback first called"
        self.state = 1

    def callbackSecond(self, newState):
        print "Callback second called"
        self.state = 2

        
    def askYesOrNo(self, text):
        self.state = 0

        dialog = generalmessage.GeneralMessage(text)
        dialog.addFirstCallback(self.callbackFirst)
        dialog.addSecondCallback(self.callbackSecond)
        
        while self.state == 0:
            yield None
        del dialog
        yield self.state

        
        
      
class TestThread(ThreadBase):
    
    def run(self):
        self.counter = 0
        while self.counter < 2:
            result = "No"
            for step in self.askYesOrNo("Are you sure"):
                if step != None:
                    result = step
                else:
                    yield step
            print "Got results: " + str(result)
            
            yield()
    
      
thread = ThreadManager()
a = TestThread()
thread.addThread(a)

#PythonThreads.instance().addThreadManager(thread.schedule)

generalmessage.py
import cegui

class GeneralMessage:
counter = 0

def __init__(self, text):
Point = cegui.Vector2
self.name = "generalmessage" + str(self.__class__.counter)
self.dialog = cegui.WindowManager.getSingleton().loadWindowLayout(
"layouts/messagebox_general.layout", self.name + "/")
self.__class__.counter += 1
self.window = cegui.WindowManager.getSingleton().createWindow(
"DefaultWindow", self.name + "/testing")

self.window.metricsMode = cegui.Relative
self.window.position = Point(.0, .0)
self.window.size = cegui.Size(1.0, 1.0)
self.window.addChildWindow(self.dialog)
self.getChild("MessageBox/Text").text = text
self.getChild("MessageBox/First").text = "Yes"
self.getChild("MessageBox/No").text = "Yes"

# Just for testing
#self.getChild("MessageBox/First").subscribeEvent("Clicked", self.callback)

self.getChild("MessageBox/First").subscribeEvent("Clicked", self.exit)
self.getChild("MessageBox/Second").subscribeEvent("Clicked", self.exit)

self.dialog.subscribeEvent(cegui.Framewindow.EventCloseClicked, self.exit)
cegui.System.getSingleton().guiSheet.addChildWindow(self.window)

def getChild(self, name):
return self.dialog.getChild(self.name + "/" + name)

def addFirstCallback(self, callback):
self.getChild("MessageBox/First").subscribeEvent("Clicked", callback)

def addSecondCallback(self, callback):
self.getChild("MessageBox/Second").subscribeEvent("Clicked", callback)


def exit(self, args):
cegui.System.getSingleton().guiSheet.removeChildWindow(self.window)
self.window.removeChildWindow(self.dialog)
cegui.WindowManager.getSingleton().destroyWindow(self.window)
cegui.WindowManager.getSingleton().destroyWindow(self.dialog)

def __del__(self):
self.exit(None)
print "GeneralMessage dialog " + self.name + " destroyed"

[/code]

- Garo

#28 UnFleshed One

UnFleshed One

    Programming Department

  • Xenocide Inactive
  • 304 posts

Posted 04 February 2006 - 07:39 PM

Why does it always throw when switching between some of the states?
   EventCallback(PyObject *subscriber)
    : mSubscriber(subscriber), mType(0)
    {
        if (!PyCallable_Check(mSubscriber))
            throw CEGUI::Exception("Event subscriber must be callable.");

Edit:
I mean it is not very good to include exceptions into normal flow of execution. (And it bothers me when debugging :))

Edited by UnFleshed One, 04 February 2006 - 07:41 PM.

Darkness is under the candle.

#29 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 05 February 2006 - 03:47 AM

Why does it always throw when switching between some of the states?

   EventCallback(PyObject *subscriber)
    : mSubscriber(subscriber), mType(0)
    {
        if (!PyCallable_Check(mSubscriber))
            throw CEGUI::Exception("Event subscriber must be callable.");

Edit:
I mean it is not very good to include exceptions into normal flow of execution. (And it bothers me when debugging :))

<{POST_SNAPBACK}>

In what context it throws? Because as I see it's totaly valid piece of code that doesn't allow for non-callable objects to pass by to callback handler.

Second, throwing exception is the best to tell that C++ code is broken. Printing an error to logs/console (without stopping executions) is the best way to handle scripting errors.
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#30 UnFleshed One

UnFleshed One

    Programming Department

  • Xenocide Inactive
  • 304 posts

Posted 05 February 2006 - 01:14 PM

Yep, but this code throws everytime I'm going from Main to Planetview or from Planetview to Options or back. (Might be that it throws on every screen switch).

I mean, it throws, but if I click continue it works fine.
Darkness is under the candle.

#31 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 05 February 2006 - 02:16 PM

That's strange then, cuz I don't experience anything like that...
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.