Timer reset ?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Timer reset ?

Post by jph_wacheski »

Supposeing I have a Timer running in the OnUpdate of an AppState,. and I leave the AppState and then return to it,. my testing tells me the timer is not reset. How could I reset that timer?

humm,. thinkin' on this now I suspect I could move the timer to an Model that I destroy and re-create,. guess that will work,. I will post this anyway to get more ideas from you guys,. peace.
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hey jph,

Depending on what you want to do, your solution of having the Timer in a Spawned Model might be the best way to go. A alternative route would be a do-it-yourself Timer. I've attached a example that renders a sprite at 2 seconds and restarts the AppState at 4 seconds. The benefit of this approach is that you can calculate how far the frame has passed the Timer moment. Let's say you want to do something at moment 1/60. If the framerate is a steady 60 fps, it will happen at the second frame of your application. If the framerate is 75, it won't happen until the third .. and if your fps is 1, it will happen at the second .. but way past the 1/60 mark obviously. When you know how much you're off, you can counter this easily. Very useful for syncing sound or doing stuff at a constant ( time-based opposed to frame-based ) rate. This feature could be added to the Timer Component though ..

By the way, the reason I'm not using App.Time is because that value hasn't been reset the first frame of a Application ( bug ). Also keep in mind that Components in the Update State of a AppState are executed after spawned Models.

K
Attachments
Timer.zgeproj
(1.72 KiB) Downloaded 577 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

ah, thanks Kjell, I should have thought of that too,. brain gets dusty at times,. lol.

Perhaps an addition to the timer component to allow for resets would be a usefull feature Ville,. another for the increasingly large wish list. As always what ever you choose to add I will endevor to utilise,. . respect.
iterationGAMES.com
kattle87
Posts: 402
Joined: Wed Sep 26, 2007 9:06 am
Location: Italy

Post by kattle87 »

Kjell wrote: By the way, the reason I'm not using App.Time is because that value hasn't been reset the first frame of a Application ( bug ).
Not sure I have understood this very well... When does this bug occours?
In the fall of 1972 President Nixon announced that the rate of increase of inflation was decreasing. This was the first time a sitting president used the third derivative to advance his case for reelection.
-=Hugo Rossi=-
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Francesco,

App.Time isn't being reset before starting a preview in the Editor causing the first value to be the duration of your last session ( this bug doesn't occur in executables though ).

K
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

App.Time should be reset in preview, I'll see if I can fix that. Also Timers should be reset when switching back to a appstate.
This feature could be added to the Timer Component though ..
Do you mean like a property that can be read to determine how much time the timer is "off" from the actual interval depending on framerate?
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

I can think of situations when not reseting them would be wanted as well,. having a Playing State and a Paused State I would NOT want them reset when coming back from the paused state,. . perhaps some manual reset is a better way,. in my case I just moved them to a model and all is well.
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph,

Pause should not be a AppState but a Global variable. Having a pause button can get quite a bit more complicated then you would expect. This is why most games usually only let you pause during game-play and not for example while a cut-scene is being played.

K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

That is fully dependant on how things are implemented,. I have been useing appStates for pause and quite like that by building pause this way the onRender events are still executed,. makes for some interesting fun pause visuals..,
Personaly I have long been a critic of the no pause in a cut scene BS that most console games exibit,. what to do when the phone rings or someone knocks at the door during a cut ? miss it and not know the story or ignor people in the real world,. . pause should always be availible on the same switch cut or no,. IMHO.
iterationGAMES.com
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Timer reset ?

Post by rrTea »

Hej Ville,
VilleK wrote:Also Timers should be reset when switching back to a appstate.
From my experience, not only Timers but AnimatorSimple components should also get reset when switching states and starting / stopping the Preview. The Animators and Timers that should not get reset are probably best kept in the main OnUpdate anyway - and the animations that do require to remember their position are mostly dealt with manually (they probably do not fit with the "Simple" part of the AnimatorSimple) in my case at least.

To see how confusing this can be otherwise, run the code below in the preview. Nothing will happen, as expected, so press "0" (zero) to start the Animator. The white model will slowly start moving upwards. Now stop the Preview before the white model reaches the wireframe area. Start the Preview again. You'd expect nothing will happen (since the Animator is not self starting) but the white model will still be moving up! Same with switching states (press "1" and "2" to switch between two states).

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" ClearColor="0.5 0 0 0" FileVersion="2">
  <OnLoaded>
    <SetAppState State="AppState1"/>
    <ZExpression Expression="Model1.POsition.Y = 0;"/>
    <SpawnModel Model="Model1" SpawnStyle="1"/>
  </OnLoaded>
  <States>
    <AppState Name="AppState1">
      <OnStart>
        <ZExpression Expression="App.ClearColor = vector3(0.5,0,0);"/>
      </OnStart>
      <OnUpdate>
        <KeyPress Keys="0" RepeatDelay="0.1">
          <OnPressed>
            <StartAnimator Animator="anim_Mover"/>
          </OnPressed>
        </KeyPress>
        <KeyPress Keys="2" RepeatDelay="0.1">
          <OnPressed>
            <SetAppState State="AppState2"/>
          </OnPressed>
        </KeyPress>
        <AnimatorSimple Name="anim_Mover" Duration="10" Target="Model1.POsition.Y" ToValue="2"/>
      </OnUpdate>
    </AppState>
    <AppState Name="AppState2">
      <OnStart>
        <ZExpression Expression="App.ClearColor = vector3(0.5,0.5,0);"/>
      </OnStart>
      <OnUpdate>
        <KeyPress Keys="1" RepeatDelay="0.1">
          <OnPressed>
            <SetAppState State="AppState1"/>
          </OnPressed>
        </KeyPress>
      </OnUpdate>
    </AppState>
  </States>
  <OnRender>
    <UseMaterial Material="Material2"/>
    <RenderNet>
      <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex.Y += 2;]]>
      </RenderVertexExpression>
    </RenderNet>
  </OnRender>
  <Content>
    <Model Name="Model1" Position="0 0.3657 0">
      <OnRender>
        <UseMaterial Material="Material1"/>
        <RenderNet/>
      </OnRender>
    </Model>
    <Material Name="Material1"/>
    <Material Name="Material2" Shading="2"/>
  </Content>
</ZApplication>
I mean, yes the Animator could be put into a Model and spawn / delete it but after a while it'd just be confusing, once there are a few of them to keep track of. Alternatively there could be an option to manually stop / reset / restart such components (I posted about it in some other place, can't remember where).
Last edited by rrTea on Thu Jul 26, 2018 1:49 am, edited 1 time in total.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Timer reset ?

Post by VilleK »

rrTea wrote:I mean, yes the Animator could be put into a Model and spawn / delete it but after a while it'd just be confusing, once there are a few of them to keep track of. Alternatively there could be an option to manually stop / reset / restart such components (but I already talked about it in some other place can't remember where).
Hi,

I haven't yet tried your example (reading forums using a Mac here) but iirc there is a "Reset component" menu item in the popup menu that resets selected component in the project tree? Though I would agree that this should happen automatically after start/stop preview.
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Timer reset ?

Post by rrTea »

Yes, a component can be reset from the Project Tree but once there are more then 5 animators (even if it's a really small project) it's easy to forget one of them (or remember to do it at all... in the heat of creative outbursts :D ) + you'd have to keep all the Animators in an accessible place etc...
rrTea wrote:Alternatively there could be an option to manually stop / reset / restart such components
I meant during runtime, for example something that can be put in OnLeave or something like that (or maybe StartAnimator can work like MusicControl's Start / Stop).
Post Reply