Page 1 of 3

Privateer GG talking heads

Posted: Wed Dec 12, 2012 11:21 am
by Herr_Koos
Hi all,

Been lurking for a while; I mostly post on the Privateer GG forums since it's the only Vega Strike based game I currently play. This community seems much more active though, so here I am! :D

I decided to start messing around with the talking heads implementation. First step was to try and replace the static images with an animation as done for various other things like base backgrounds (walking people, flying spaceships, etc). This turned out to be easier than expected. I also have a fairly easy and repeatable way of turning videos into screen captures and then into animated PNG sequences. It will take time, but can be done, no problem.

The next challenge is getting the logic right so that a particular animation only plays when the correct character is speaking. At the moment, the animation just keeps playing and is oblivious to the timing/duration of the conversation. It also doesn't switch from the fixer or bartender to the player character and back.

What I really need is some insight into how talking heads were supposed to be implemented in the first place. Does the logic perhaps already exist to switch between heads based on who is speaking? I can see some references to talking heads in the code, as taken here from bar_lib.py:

if bartenderhead:
import campaign_lib
if campaign_lib.doTalkingHeads():
script+="import Base\nimport campaign_lib\ncampaign_lib.AddConversationStoppingSprite('Bartender','bases/heads/"+bartenderhead+".spr',(.582,-.2716),(3.104,2.4832),'Return_To_Bar').__call__(Base.GetCurRoom(),None)\n"
Base.Python (room0, 'talk', 0.5875, -0.373333, 0.285, 0.626667,'Talk to the Bartender',script+"import bartender\nbartender.Speak (bartender.GetBartenderText("+repr(bartext)+"))\n",0)


Quite frankly though, I have no solid idea where to start looking or what to look for. Any insight would be greatly appreciated. In the meantime, I will keep working on creating the assets themselves.

Re: Privateer GG talking heads

Posted: Wed Dec 12, 2012 12:48 pm
by klauss
Herr_Koos wrote: I decided to start messing around with the talking heads implementation. First step was to try and replace the static images with an animation as done for various other things like base backgrounds (walking people, flying spaceships, etc). This turned out to be easier than expected. I also have a fairly easy and repeatable way of turning videos into screen captures and then into animated PNG sequences. It will take time, but can be done, no problem.
You know, we do have support for video files. You do need a build with such support enabled though (not sure it's commonplace in SVN), and it hasn't been tested on the talking heads, but it'd be a matter of testing it anyway.
Herr_Koos wrote:The next challenge is getting the logic right so that a particular animation only plays when the correct character is speaking. At the moment, the animation just keeps playing and is oblivious to the timing/duration of the conversation. It also doesn't switch from the fixer or bartender to the player character and back.
An easy way to fix that is with a timed trigger - ie, you can switch the animation with a static file as soon as some amount of time elapses. Of course it'd be easier with videos.
Herr_Koos wrote:What I really need is some insight into how talking heads were supposed to be implemented in the first place. Does the logic perhaps already exist to switch between heads based on who is speaking? I can see some references to talking heads in the code, as taken here from bar_lib.py
Actually, I'd have to read bar_lib to figure it out. I've never dived much into that code.

But suffice it to say, that the engine itself has very few "base interface primitives". It's probably all done in python, based on timings.

Re: Privateer GG talking heads

Posted: Wed Dec 12, 2012 2:34 pm
by Herr_Koos
klauss wrote: You know, we do have support for video files. You do need a build with such support enabled though (not sure it's commonplace in SVN), and it hasn't been tested on the talking heads, but it'd be a matter of testing it anyway.
I'm not really keen to play with SVN right now; I'd prefer to work on what I have. Creating the animations from the videos is quite straightforward, and switching to the video's later will be easy enough.
Herr_Koos wrote:The next challenge is getting the logic right so that a particular animation only plays when the correct character is speaking. At the moment, the animation just keeps playing and is oblivious to the timing/duration of the conversation. It also doesn't switch from the fixer or bartender to the player character and back.
klauss wrote: An easy way to fix that is with a timed trigger - ie, you can switch the animation with a static file as soon as some amount of time elapses. Of course it'd be easier with videos.
Can you give me an example of the syntax, or point me to a reference? I'm willing to give it a shot. I also take it that you would add this line to the environment .py file, thus for bar_lib.py, add a line that plays mining_spr (the animation) for x seconds, then switch to the static PNG.
What I would prefer to do is, for example, play the animation until the currently playing sound file has completed. If there is some flag set after this (I could even add one), one could use this as the trigger for the static animation.
Herr_Koos wrote:What I really need is some insight into how talking heads were supposed to be implemented in the first place. Does the logic perhaps already exist to switch between heads based on who is speaking? I can see some references to talking heads in the code, as taken here from bar_lib.py
klauss wrote:Actually, I'd have to read bar_lib to figure it out. I've never dived much into that code.
But suffice it to say, that the engine itself has very few "base interface primitives". It's probably all done in python, based on timings.
Cool, Let me know if you find anything insightful.

Re: Privateer GG talking heads

Posted: Wed Dec 12, 2012 3:15 pm
by Herr_Koos
A good start would be to find where the current sprite files for the heads are referenced in the code. It may seem like an obvious thing but I'm struggling to find it.

Re: Privateer GG talking heads

Posted: Fri Dec 14, 2012 6:31 pm
by Herr_Koos
OK, think I have the soundfile reference figured out. Question: Can I add and reference variables in .py files without recompiling anything? Thus far, any attempt to set flags or create new variables in a base environment .py file results in that environment no longer being selectable from the main concourse.

Re: Privateer GG talking heads

Posted: Fri Dec 14, 2012 10:56 pm
by loki1950
You should be able to make changes to the Python without re-compiling as Python is an interpreted language not a complied one.BTW some of the sound file controls are done with associated XML files.

Enjoy the Choice :)

Re: Privateer GG talking heads

Posted: Sat Dec 15, 2012 4:25 pm
by Herr_Koos
Thanks Loki, will keep digging. Where are these XML files located and referenced?

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 3:17 am
by klauss
Herr_Koos wrote:
klauss wrote: An easy way to fix that is with a timed trigger - ie, you can switch the animation with a static file as soon as some amount of time elapses. Of course it'd be easier with videos.
Can you give me an example of the syntax, or point me to a reference?
Sorry for the delay, I've been held up by RL. You have an example usage in GUI.py, in the class GUIVideoStream - Base.RunScript can be used to add a python callback with a timeout. The class there uses 0.0 as a timeout to make it run immediately, but you can set any timeout you want.

The pythoncallback function just creates a parameterized script, so it can plug the proper identifiers. You might not need to, and a plain string with the script might be enough.

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 11:59 am
by Herr_Koos
klauss wrote: Sorry for the delay, I've been held up by RL. You have an example usage in GUI.py, in the class GUIVideoStream - Base.RunScript can be used to add a python callback with a timeout. The class there uses 0.0 as a timeout to make it run immediately, but you can set any timeout you want.

The pythoncallback function just creates a parameterized script, so it can plug the proper identifiers. You might not need to, and a plain string with the script might be enough.
No worries. I'm on leave as of last Friday, so I finally have some time to play around. :D Still trying to figure out how the scripts tie together. I've been using the mining base bartender as my guinea pig, and inside bar_lib.py I've found where the spr file is referenced and also where the sound files for the speech are referenced. I'll try the timed trigger first and see how that goes.

Will any of Python's default functions or libraries be available? If, for example, I want to add "import time" so that I can use "time.sleep", will that work or will it break something?

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 6:27 pm
by klauss
Herr_Koos wrote:Will any of Python's default functions or libraries be available? If, for example, I want to add "import time" so that I can use "time.sleep", will that work or will it break something?
There are many built-in modules available in VS (check modules/builtin). There are many missing too. You shouldn't assume they're there in any case, check the builtin folder first.

Though linux systems will have them all available (since we use the distro's python), windows will only find whatever's on modules/builtin.

In any case, you don't want to time.sleep. That would freeze the engine until the timeout happens. Bad thing.

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 9:32 pm
by Herr_Koos
That helps a lot, thanks. I just used time.sleep as an example, don't worry. :-)

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 9:39 pm
by Herr_Koos
klauss wrote: You have an example usage in GUI.py, in the class GUIVideoStream - Base.RunScript can be used to add a python callback with a timeout. The class there uses 0.0 as a timeout to make it run immediately, but you can set any timeout you want.
GUIVideoStream does not exist in my GUI.py file... I'm working with 1.03 stable remember, so maybe it was added after that. Can you maybe post the example for me?

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 9:45 pm
by klauss
I could, but why not just check VS SVN?

All you need is see how Base.RunScript works, which should work just fine in 1.03.

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 10:32 pm
by Herr_Koos
Awesome, did not know I could view the code online... Will have to bookmark that link!

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 10:43 pm
by Herr_Koos
OK, so looking at this line:

Base.RunScript(self.room.getIndex(),self.index+"PLAY",pythoncallback(self.id, "play"),0.0)

Base.RunScript expects four inputs, but I'm only interested in the timeout (0.0), right? What can I pass in the other parameter fields?

Re: Privateer GG talking heads

Posted: Sun Dec 16, 2012 10:57 pm
by klauss
Herr_Koos wrote:OK, so looking at this line:

Base.RunScript(self.room.getIndex(),self.index+"PLAY",pythoncallback(self.id, "play"),0.0)

Base.RunScript expects four inputs, but I'm only interested in the timeout (0.0), right? What can I pass in the other parameter fields?
RunScript takes:
  • Room number
  • Script identifier
  • Python script to run
  • Time delay
The first two are standard for Base interface elements. A script is an element too, one that is invisible and just triggers the script when the timeout occurs.

The python script you pass is run on an empty context, so it gets a bit tricky to do useful stuff in there. You don't have access to variables, not even globals. You can only import modules and invoke their functions.

I was working a way back on XGUI.py, which was an XML-backed UI description parser that would be able to run "pythonscript"-like scripts, essentially adding useful context to that callback. I don't think you need that much context though, because all you need is to change the sprite of an image element, and you can do that by importing Base and invoking it with proper arguments.

Re: Privateer GG talking heads

Posted: Tue Dec 18, 2012 11:53 am
by Herr_Koos
Any way to see what the contents if a script file currently are? I installed Python, opened bar_lib.py, added a "print" line to display the contents of the script file used in the module, launched the game and then ran the module. It returns an error: ImportError: No module named Base, which obviously comes from "import Base" in the first line of the file.

Re: Privateer GG talking heads

Posted: Tue Dec 18, 2012 12:48 pm
by klauss
Herr_Koos wrote:Any way to see what the contents if a script file currently are? I installed Python, opened bar_lib.py, added a "print" line to display the contents of the script file used in the module, launched the game and then ran the module. It returns an error: ImportError: No module named Base, which obviously comes from "import Base" in the first line of the file.
How did you "run" the module?

Re: Privateer GG talking heads

Posted: Tue Dec 18, 2012 12:50 pm
by Herr_Koos
Opened it in a Python interpreter.

Re: Privateer GG talking heads

Posted: Tue Dec 18, 2012 5:31 pm
by klauss
Ya... that doesn't work.

Base, VS and a few other modules, are interfaces to engine internals. They don't exist outside of the engine's embedded python interpreter.

Re: Privateer GG talking heads

Posted: Tue Dec 18, 2012 9:49 pm
by Herr_Koos
But surely you have ways to view the current value of a variable or otherwise do error checking?

Re: Privateer GG talking heads

Posted: Tue Dec 18, 2012 10:39 pm
by klauss
Print, and debug.info/warn/error/fatal/debug (in debug.py)

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 7:15 am
by Herr_Koos
I've tried print with no success thus far. Where does the output of a print command actually display when you use it? Will it be output to a file? Does it create a command line pop-up or open the Python shell window?

EDIT: There is also the question of whether to use the print statement or the print function...

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 7:52 am
by klauss
In linux, it all goes to the console. In windows, plain print goes to stdout.txt, while "print >>sys.stderr" goes to stderr.txt.

AFAIK, all the debug functions go to stderr.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 8:15 am
by Herr_Koos
How often is stdout.txt recreated or refreshed? Can I just say "print variable" at any point in the code to have it print the variable to that file?

EDIT: OK, yes, it works. That will help a lot, thanks.