Announcement

Collapse
No announcement yet.

How much is too much for Tick()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How much is too much for Tick()

    How much is considered too much code to be put in a Tick Function? I've been told that because of how often it is executed, you don't want to put too much code, or code that takes a lot of processing power (like iterators) inside of tick because it will slow the game down. The following is a copy/paste of my weapon's tick function (It's a vehicle-mounted weapon), does it seem excessive?

    Code:
    Simulated function Tick(Float DeltaTime)
    {
         Local Rotator LNewRot, RNewRot;
         Local Vector RPivVect, RDirVect, LPivVect, LDirVect;
         Super.Tick(DeltaTime);
         If (Vehicle(Owner).bDriving != True)
             Return;
         LPivVect = GetBoneCoords('LPivot').origin ;
         RPivVect = GetBoneCoords('RPivot').origin ;
         
         LDirVect = (CurrentHitLocation - LPivVect) << Rotation;
         RDirVect = (CurrentHitLocation - RPivVect) << Rotation;
    
         LNewRot = Rotator(LDirVect);
         RNewRot = Rotator(RDirVect);
         
         LNewRot.Pitch = -(LNewRot.Pitch);
         LNewRot.Yaw = -(LNewRot.Yaw);
         
         RNewRot.Pitch = -(RNewRot.Pitch);
         RNewRot.Yaw = -(RNewRot.Yaw);
    
         If (LNewRot.Pitch > PitchUpLimit && LNewRot.Pitch < 32768)
             LNewRot.Pitch = PitchUpLimit;
         If (LNewRot.Pitch < PitchDownLimit && LNewRot.Pitch > -32768)
             LNewRot.Pitch = PitchDownLimit;
         If (LNewRot.Yaw > YawEndConstraint && LNewRot.Yaw < 32768)
             LNewRot.Yaw = YawEndConstraint;
         If (LNewRot.Yaw < YawStartConstraint && LNewRot.Pitch > -32768)
             LNewRot.Yaw = YawStartConstraint;
             
         If (RNewRot.Pitch > PitchUpLimit && RNewRot.Pitch < 32768)
             RNewRot.Pitch = PitchUpLimit;
         If (RNewRot.Pitch < PitchDownLimit && RNewRot.Pitch > -32768)
             RNewRot.Pitch = PitchDownLimit;
         If (RNewRot.Yaw > YawEndConstraint && RNewRot.Yaw < 32768)
             RNewRot.Yaw = YawEndConstraint;
         If (RNewRot.Yaw < YawStartConstraint && RNewRot.Pitch > -32768)
             RNewRot.Yaw = YawStartConstraint;
    
         SetBoneRotation('LPivot',LNewRot);
         SetBoneRotation('RPivot',RNewRot);
    }
    This code sets the direction of both barrels of the weapon to point at the same location, so it needs to be in tick or at least in a very fast timer function or the barrels will be jumpy. Thanks

    #2
    Well considering the amount of code used in pawns (movement code is executed as often as the tick) and that this is a vehicle, imho this would seem to be a perfectly acceptable amount (since there would not be too many vehicles anyways), but why go by assumptions, download the unrealscript profiler, start up a map with a few of your vehicles and see how much time the code actually takes in comparison to all of the other script code. http://udn.epicgames.com/Two/ScriptProfiler

    Comment


      #3
      Looks like a pretty helpful program, but I'm not seeing anyything that resembles instructions on how to get it started. It simply errors out the instant that I run the executable (which is only 84k, I downloaded it twice to confirm that the file wasn't corrupt).

      What am I missing?

      Comment


        #4
        whoops, sorry I forgot to mention (I had the same error when I first tried to use it as well), you have to have that dang Microsoft dot net framework installed (since the utility was written by the epic folks using that, but they failed to mention that you had to have it to make the proggie work). MS and its silly proprietary junk... here is the link to the dot net framework download (about 23Mb) http://www.microsoft.com/downloads/d...displaylang=en

        Comment


          #5
          Seems like peanuts compared to some other default vehicle Tick code.

          By the way, you know you're basically doing this:
          Code:
          event Tick()
          {
              DoThingy(A);
              DoThingy(B);
              DoSomething(A);
              DoSomething(B);
              DoStuff(A);
              DoStuff(B);
          }
          You could also do it like this:
          Code:
          event Tick()
          {
              DoEverything(A);
              DoEverything(B);
          }
          
          function DoEverything(Object o)
          {
              DoThingy(o);
              DoSomething(o);
              DoStuff(o);
          }
          That way you only have to change it in one place if something needs updating and you don't run the risk of copy/paste errors.

          Comment


            #6
            But calling functions adds overhead :P

            anyway, what you do in the tick isn't a lot or heavy

            Comment


              #7
              Not by a long shot. HUD code is far worse, lol. HUD code also gets run every FRAME, which is more often than every tick.

              Comment


                #8
                Originally posted by Bonehed316
                Not by a long shot. HUD code is far worse, lol. HUD code also gets run every FRAME, which is more often than every tick.
                now that's interesting, did you make up that yourself?

                Comment


                  #9
                  Uhhh...no.

                  The script profiler will tell you that HUD code accounts for 50-60% of the script execution time. It also, for the most part, gets called every time the canvas renders, which if you are running 85fps, is 85 times per second, which is significantly more than the 30 or so times tick MIGHT get called per second. Therefor HUD code gets called more frequently than tick code. Generally your draw calls are a huge portion of your execution time, which is just about all of what the HUD does (not much point in doing something in the HUD if you dont draw it, right?).

                  Comment


                    #10
                    Well, the rendering pipeline is initiated from tick. Every tick is a single frame.

                    Comment


                      #11
                      But tick gets called at most once every 1/MaxTickRate seconds, which is far less frequent than PostRender. Not calling PostRender every frame would result in horrible shimmer effects. And rendering only on tick would result in much fewer than 85 fps, or a much higher tick rate than necessary.

                      I guess you could find the time delta between any two post render calls to proove it. I just assume that because HUD code takes up a majority of the execution time, that it must be called more often, ie every frame.

                      Comment


                        #12
                        you are completely right, in case of a server.
                        but then again, on the server nothing is rendered.

                        Comment


                          #13
                          Originally posted by Bonehed316
                          But tick gets called at most once every 1/MaxTickRate seconds, which is far less frequent than PostRender. Not calling PostRender every frame would result in horrible shimmer effects. And rendering only on tick would result in much fewer than 85 fps, or a much higher tick rate than necessary.

                          I guess you could find the time delta between any two post render calls to proove it. I just assume that because HUD code takes up a majority of the execution time, that it must be called more often, ie every frame.
                          Rendering twice in a row would be a waste of time. Nothing will have changed, so the exact same thing would be rendered all over again.

                          I'd say if HUD code takes up the majority of execution time, that would be because rendering code is generally slower, not because it executes more often.

                          Comment


                            #14
                            Well, rendering the same thing over and over is better than rendering only once every 1/MaxTickRate seconds. Under the assumption that this was true in the case of standalone games, it makes more sense to render independant of tick. However, if this is not the case then tick must be called more frequently offline than online, which changes the whole dynamic of my understanding of the engine, and really makes more sense in the process.

                            Comment


                              #15
                              only dedicated servers use maxtickrate, this is to for one reduce the server load, otherwise it would (like the client) try to do as much things as fast as possible (resulting in 100% CPU load). This is, not really useful. Clients will try do to as much as possible as fast as possible (unless the framerate it capped). Servers don't have to do any of the rendering stuff or visual effect things.

                              Just because the server ticks at 30Hz doesn't mean the client also ticks at 30Hz. The client ticks as fast as it can. It will only receive updates from the server every 1/30th second. In the time between the updates from the server the client will simulate the changes that it expects.

                              Comment

                              Working...
                              X