 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hello,
I started developing a simple real-time game with POV yesterday. I wrote
a program in C++ to pass arrow key presses to an .inc file, in the form
of a #declared vector. Everything was going great, I almost finished up
the maze game I was working on. No errors at at all. But today I started
receiving errors possibly related to my text file not being fully
written before POV can read the vector :(
I don't know why errors would suddenly start cropping up today. Maybe I
just got lucky yesterday...
Is there another way to pass custom key presses to a POV scene
on-the-fly? Possibly as a .dll GUI extension? Or maybe a way to ensure
that POV doesn't read the #include before it's finished being written?
I'm not even sure if that's the problem :/
Sam
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hi Sam,
A very cool idea!
I know of no way aside from hacking the POVRay source to support something like
this directly. But, for what you are trying to do, perhaps the quick thing would
be writing to another file and then replace the one being read with a system
'mv' command or similar. It should be the case that only complete files would be
available to POVRay for read that way.
Regards, Bill
stbenge <not### [at] hotmail com> wrote:
> Hello,
>
> I started developing a simple real-time game with POV yesterday. I wrote
> a program in C++ to pass arrow key presses to an .inc file, in the form
> of a #declared vector. Everything was going great, I almost finished up
> the maze game I was working on. No errors at at all. But today I started
> receiving errors possibly related to my text file not being fully
> written before POV can read the vector :(
>
> I don't know why errors would suddenly start cropping up today. Maybe I
> just got lucky yesterday...
>
> Is there another way to pass custom key presses to a POV scene
> on-the-fly? Possibly as a .dll GUI extension? Or maybe a way to ensure
> that POV doesn't read the #include before it's finished being written?
> I'm not even sure if that's the problem :/
>
> Sam
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
William Pokorny wrote:
> Hi Sam,
> A very cool idea!
Yeah, I hope it works out! As processors become faster, more complex
raytraced games could be made, maybe with a patched Version of POV...
> I know of no way aside from hacking the POVRay source to support something like
> this directly. But, for what you are trying to do, perhaps the quick thing would
> be writing to another file and then replace the one being read with a system
> 'mv' command or similar. It should be the case that only complete files would be
> available to POVRay for read that way.
> Regards, Bill
I will investigate this. Not sure how to go about it, since my
programming skills are few. But I'll google "'mv' 'system command'
windows" or some such.
Thanks for answering!
Sam
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: stbenge
Subject: Re: Passing custom key presses to a POV scene?
Date: 15 Oct 2009 02:51:31
Message: <4ad6c673@news.povray.org>
|
|
 |
|  |
|  |
|
 |
stbenge wrote:
> I will investigate this. Not sure how to go about it, since my
> programming skills are few. But I'll google "'mv' 'system command'
> windows" or some such.
Gah, I'm getting nowhere! I just found out that I hate daniweb. I
thought the stdio function "rename()" was going to work, but it won't
save over a file if it already exists. remove()ing the old one and
rename()ing the next one won't work, of course.
I wish there was a replace() command for copying over a file. I couldn't
make heads or tails of this "mv" system command.... that is, I can't
seem to find anything useful by googling. Not yet, anyway.
There's always a tomorrow. Well, until the sun goes supernova :P
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Can't you decide inside your programm to only launch POV-Ray when the writing is
over ?...
Or are you using a separate daemon to continously render images ?...
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: stbenge
Subject: Re: Passing custom key presses to a POV scene?
Date: 15 Oct 2009 14:59:12
Message: <4ad77100@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Gyscos wrote:
> Can't you decide inside your programm to only launch POV-Ray when the writing is
> over ?...
I would like to do this, keeping the same instance of POV open while I
render on-demand from an external program, but have no idea how to do it.
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Christian Froeschlin
Subject: Re: Passing custom key presses to a POV scene?
Date: 15 Oct 2009 16:31:59
Message: <4ad786bf$1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
stbenge wrote:
> I started developing a simple real-time game with POV yesterday.
Umm ... what's your definition of real-time here? ;)
> receiving errors possibly related to my text file not being fully
> written before POV can read the vector :(
How do you start the render and wait for it to finish?
Maybe you could try calling fflush() after writing the data.
> Is there another way to pass custom key presses to a POV scene
Sure, you can pass a define via command line:
pvengine +whatever ... maze.pov Declare=Arrow=2
Then the scene would have a variable "Arrow" defined with value 2.
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: stbenge
Subject: Re: Passing custom key presses to a POV scene?
Date: 15 Oct 2009 19:14:24
Message: <4ad7acd0@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Christian Froeschlin wrote:
> stbenge wrote:
>
>> I started developing a simple real-time game with POV yesterday.
>
> Umm ... what's your definition of real-time here? ;)
Anywhere between 70-12 FPS for a 100x100 to 200x200 render on a quad
core. This doesn't involve using the +rtr command line option. Instead,
I'm having to use +kff1215752192, which should be enough time for
solving the maze.
>> receiving errors possibly related to my text file not being fully
>> written before POV can read the vector :(
>
> How do you start the render and wait for it to finish?
I don't :/ My program simply writes to an .inc file every time an arrow
key is pressed. I might be able to optimize this by writing only once if
a key is still being pressed.
> Maybe you could try calling fflush() after writing the data.
I will look into that. Currently, I do this:
myfile.open(file_temp);
myfile << "#declare dir=";
myfile << vEcToR << ";\n";
myfile.close();
ifstream ifs(file_temp,ios::in|ios::binary);
ofstream ofs(file,ios::out | ios::binary);
ofs << ifs.rdbuf();
I haven't had a problem with this new setup yet, but I feel like I'm
just getting lucky again.
>> Is there another way to pass custom key presses to a POV scene
>
> Sure, you can pass a define via command line:
>
> pvengine +whatever ... maze.pov Declare=Arrow=2
>
> Then the scene would have a variable "Arrow" defined with value 2.
How do I do this? With a system() command? If so, how do I find out
where 'pvengine' is?
Sam
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: clipka
Subject: Re: Passing custom key presses to a POV scene?
Date: 15 Oct 2009 23:38:59
Message: <4ad7ead3@news.povray.org>
|
|
 |
|  |
|  |
|
 |
stbenge schrieb:
>
> I don't :/ My program simply writes to an .inc file every time an arrow
> key is pressed. I might be able to optimize this by writing only once if
> a key is still being pressed.
You might do it as follows:
- In your program, update the .inc file only after verifying that a
certain "acknowledge marker" ("ACK") file does exist; after having
written the .inc file, have the program delete the ACK file.
- In your scene file, use the file_exists() function to check whether
the ACK file does exist; if not, include the .inc file, then use
#fopen/#write to generate/overwrite a temporary .inc file to contain the
very same data, and after that use the same mechanism to create the ACK
file. If however the ACK file does exist already, simply include the
temporary .inc file instead.
I think that should do the trick without conflicts.
Make sure to init the system properly (e.g. by making sure the ACK file
is not present, and the main .inc file exists and has some content that
makes sense), and to provide for a way to recover in case the system
should become "stuck" for some unexpected reason (e.g. time out if the
POV-Ray script fails to create the ACK file in due time; you can also
put the current frame number into the temporary .inc file and cross
check, to create a timeout mechanism on the POV-Ray side in case the
program fails to clear the ACK file at regular intervals)
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Nicolas Alvarez
Subject: Re: Passing custom key presses to a POV scene?
Date: 16 Oct 2009 15:56:24
Message: <4ad8cfe7@news.povray.org>
|
|
 |
|  |
|  |
|
 |
stbenge wrote:
> Gah, I'm getting nowhere! I just found out that I hate daniweb. I
> thought the stdio function "rename()" was going to work, but it won't
> save over a file if it already exists.
The documentation I have says:
"If newpath already exists it will be atomically replaced (subject to a few
conditions; see ERRORS below), so that there is no point at which another
process attempting to access newpath will find it missing."
Those "few conditions" were all about moving directories, thus irrelevant in
this case.
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Christian Froeschlin
Subject: Re: Passing custom key presses to a POV scene?
Date: 17 Oct 2009 07:19:31
Message: <4ad9a843$1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
stbenge wrote:
> I'm having to use +kff1215752192, which should be enough time for
> solving the maze.
ah, I think you didn't mention before that you were running
povray in a continuous animation loop. Now I see how you are
trying to do it. I was assuming you executed povray once for
each new frame, in which case you could have used command
line parameter (but probably end up with a lot less fps).
In your case you indeed need a form of synchronization mechanism
and clipkas suggestion should work for that. If the time you need
to write to the inc file is significantly less than the time you
need to render one frame, you can simplify it to writing a marker
file "parse_finished" at the end of the scene, having the C++
program wait for the appearance of that file, write the inc
and remove the marker file.
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: stbenge
Subject: Re: Passing custom key presses to a POV scene?
Date: 17 Oct 2009 16:29:24
Message: <4ada2924@news.povray.org>
|
|
 |
|  |
|  |
|
 |
clipka wrote:
> You might do it as follows:
I'll give this a go soon. Thank you for replying!
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Christian Froeschlin wrote:
> stbenge wrote:
>
>> I'm having to use +kff1215752192, which should be enough time for
>> solving the maze.
>
> ah, I think you didn't mention before that you were running
> povray in a continuous animation loop. Now I see how you are
> trying to do it. I was assuming you executed povray once for
> each new frame, in which case you could have used command
> line parameter (but probably end up with a lot less fps).
I wish I knew how to execute POV-Ray from the command line. I know how
to use the command line, but I cannot seem to get my program to find
POV. Simply typing system("start pvengine etc..."); won't work. I get a
message telling me that 'pvengine' was not found :( 'pvengine.exe' also
does not work. I spent hours looking up a way to find the path of an
.exe by name alone, but got nowhere at all.
> In your case you indeed need a form of synchronization mechanism
> and clipkas suggestion should work for that. If the time you need
> to write to the inc file is significantly less than the time you
> need to render one frame, you can simplify it to writing a marker
> file "parse_finished" at the end of the scene, having the C++
> program wait for the appearance of that file, write the inc
> and remove the marker file.
Another good suggestion! I'll have to implement it soon. Thanks!
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Christian Froeschlin
Subject: Re: Passing custom key presses to a POV scene?
Date: 18 Oct 2009 08:36:44
Message: <4adb0bdc$1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
stbenge wrote:
> I wish I knew how to execute POV-Ray from the command line. I know how
> to use the command line, but I cannot seem to get my program to find
> POV. Simply typing system("start pvengine etc..."); won't work. I get a
> message telling me that 'pvengine' was not found :( 'pvengine.exe' also
> does not work. I spent hours looking up a way to find the path of an
> .exe by name alone, but got nowhere at all.
I am a bit confused by that but I hope you're the confused one ;)
I assume you are using Windows because otherwise you'd know how
to run povray from the command line. But under Windows, pvengine.exe
is just the name of the normal povray main GUI you start every day
(note: for 3.7 beta it can be something like pvengine-sse2.exe).
You should know where it is because you installed it there :-P
but if you don't know check the link on your desktop or start
menu you use to start povray (right-click > Properties ...
will show you the full target path and name).
It will typically look something like:
"C:\Program Files\POV-Ray for Windows v3.6\bin\pvengine.exe"
In order to start it from the command line, you need to either
A) Switch to the correct drive and directory before executing, e.g.,
1.> C:
2.> cd "\Program Files\POV-Ray for Windows v3.6\bin"
3.> pvengine
(use of double quotes is required for names which contain spaces).
B) Or, provide the full path to the executable every time
1.> "C:\Program Files\POV-Ray for Windows v3.6\bin\pvengine"
C) Or, add the bin directory to the environment search path:
1.> set PATH="%PATH%;C:\Program Files\POV-Ray for Windows v3.6\bin"
2.> pvengine
1. will only affect the current cmd shell. You can set this globally
and permanently in the Windows GUI via
Start Menu > Settings > Control Panel > System >
Advanced > Environment Variables > Path
You only add the directory there, without %PATH%.
If you have administrator privileges, you can modify the
System Path but be careful not to delete something else or
corrupt it. This will work for all users. If you add it to
the User space it will only work for the current user (add
a new variable Path there it if doesn't yet exist).
Now practise all three methods using cmd.exe before attempting
to spawn povray from your C++ application ;) And don't forget to
play with adding command line parameters!
When you're sick of typing the same stuff over and over again,
it will be time for Lesson Two, Batch File Programming ;)
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Christian Froeschlin
Subject: Re: Passing custom key presses to a POV scene?
Date: 18 Oct 2009 08:43:45
Message: <4adb0d81$1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Christian Froeschlin wrote:
> Now practise all three methods using cmd.exe before attempting
> to spawn povray from your C++ application ;)
I belatedly realized you have the problem only from your C++
application. But the steps there should be identical. The easiest
method is probably (C), a simple system("pvengine.exe") should
work after the PATH variable has been set globally, and it
does not require you to hardcode the path into your app.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Christian Froeschlin wrote:
> Christian Froeschlin wrote:
>
>> Now practise all three methods using cmd.exe before attempting
>> to spawn povray from your C++ application ;)
>
> I belatedly realized you have the problem only from your C++
> application. But the steps there should be identical. The easiest
> method is probably (C), a simple system("pvengine.exe") should
> work after the PATH variable has been set globally, and it
> does not require you to hardcode the path into your app.
But I would want something like this to work for everybody who downloads
my program. I wouldn't want them to have to set up environment variables
just for my program. With POV's default behavior of installing to
personal user directories these days, the whole issue just becomes more
tangled. I might be missing something though...
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Nicolas Alvarez
Subject: Re: Passing custom key presses to a POV scene?
Date: 18 Oct 2009 20:08:02
Message: <4adbade1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
stbenge wrote:
> Christian Froeschlin wrote:
>> Christian Froeschlin wrote:
>>
>>> Now practise all three methods using cmd.exe before attempting
>>> to spawn povray from your C++ application ;)
>>
>> I belatedly realized you have the problem only from your C++
>> application. But the steps there should be identical. The easiest
>> method is probably (C), a simple system("pvengine.exe") should
>> work after the PATH variable has been set globally, and it
>> does not require you to hardcode the path into your app.
>
> But I would want something like this to work for everybody who downloads
> my program. I wouldn't want them to have to set up environment variables
> just for my program. With POV's default behavior of installing to
> personal user directories these days, the whole issue just becomes more
> tangled. I might be missing something though...
It's possible POV-Ray installer stores its installation location in the
registry. You'd have to look there.
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: stbenge
Subject: Re: Passing custom key presses to a POV scene?
Date: 18 Oct 2009 20:44:56
Message: <4adbb688@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Nicolas Alvarez wrote:
> It's possible POV-Ray installer stores its installation location in the
> registry. You'd have to look there.
Every clue is good! I'll take a look and see what my options are.
Writing .inc files every time a new key is pressed seems like the hard
way to go about it :/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Sam, Your idea has been rattling around in my head (plenty of space), and I
started to wonder if we might be able to do some interactive modeling with
POVRay in addition to game playing? Would be limited I expect, but such a
technique might be useful.
Bill
stbenge <not### [at] hotmail com> wrote:
> Nicolas Alvarez wrote:
> > It's possible POV-Ray installer stores its installation location in the
> > registry. You'd have to look there.
>
> Every clue is good! I'll take a look and see what my options are.
> Writing .inc files every time a new key is pressed seems like the hard
> way to go about it :/
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: stbenge
Subject: Re: Passing custom key presses to a POV scene?
Date: 18 Oct 2009 21:47:00
Message: <4adbc514@news.povray.org>
|
|
 |
|  |
|  |
|
 |
William Pokorny wrote:
> Sam, Your idea has been rattling around in my head (plenty of space), and I
> started to wonder if we might be able to do some interactive modeling with
> POVRay in addition to game playing? Would be limited I expect, but such a
> technique might be useful.
It's possible, all right. It sounds like a coding nightmare, but it may
have its uses. Like if you wanted to see how an object would effect
lighting conditions or texturing. Also, a scene viewer could be made,
where you can interactively zoom, move through, and pan across the image.
Sam
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
stbenge schrieb:
> But I would want something like this to work for everybody who downloads
> my program. I wouldn't want them to have to set up environment variables
> just for my program. With POV's default behavior of installing to
> personal user directories these days, the whole issue just becomes more
> tangled. I might be missing something though...
Try registry keys
HKCU\Software\POV-Ray\CurrentVersion\Home
HKCU\Software\POV-Ray\v3.6\Windows\Home
HKCU\Software\POV-Ray\v3.7\Windows\Home
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |