Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animation Loops outside the Gameloop
#1
Wondering if anyone uses loop timers outside the gameloop.

Just an idea, for example:

Code:
Sub BltSomething(ByVal Something As Long)

    Dim x As Long
    x = 0

    Do While x  -1
        If GetTickCount > SomethingTimer + 125 Then
            If x  4 Then
                SomethingTimer = GetTickCount
                Call BltSomething
                x = x + 1
            Else
                x = -1
            End If

    DoEvents

    Loop

End Sub

Then just have a BltSomething packet. Im runnin out the door but thought Id ask instead of testing, plus I like the constructive comments.
Reply
#2
I don't quite exactly get what you're asking, but if you want to render from an external loop, its not going to work well. All your rendering needs to be done in the same loop to ensure you render in the correct order and every frame.

Now if you want to use the timer to modify how stuff is rendered, but not actually render, that is totally fine.
Reply
#3
In plain English:

The subroutine you posted has a timer check in it. That timer check would want to be in GameLoop rather than in it's own separate loop.

A good example of what a mess that makes is the server, where you have 4 or 5 different timers. It really messes up the timing, and it wasn't until I removed those that a lot of the annoying bugs I used to get sorted themselves out.

Now, having a separate timer doing some rendering isn't going to work. If, however, you want to keep calling the rendering subroutine from within the gameloop and have the separate loop only changing a variable, then that's fine.

For example, you keep 'BltSomething' in the gameloop, but in the separate timer you could have 'SomethingVariable = SomethingVariable + 1' or something.

Wow... my post made even less sense than Tyler's.

Sorry Sad
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#4
Yeah I failed to mention Im using an optimized GFX system so you'd only need to render something once, which would also render to a seperate buffer that is blted whenever anyone moves underneath that area. So NOW is this acceptable? I dont want to have things in the gameloop that dont need to be used alot.. Would a few tickcount loop timers create noticable problems or lag? They are, afterall, being exited.
Reply
#5
No, not is not. Your rendering time is still random in context with the rest of the program. You want to render in order - its not about performance, its not about thread safety, its just about logic. You can mix in updates with rendering at times (although its a bit harder to follow and not very well structured) but you can not throw around your rendering times randomly.

If you are rendering to a separate buffer, put the code where you want it in the call to render to that separate buffer. Keep it linear and simple.
Reply
#6
Spodi Wrote:No, not is not. Your rendering time is still random in context with the rest of the program. You want to render in order - its not about performance, its not about thread safety, its just about logic. You can mix in updates with rendering at times (although its a bit harder to follow and not very well structured) but you can not throw around your rendering times randomly.

If you are rendering to a separate buffer, put the code where you want it in the call to render to that separate buffer. Keep it linear and simple.

Why would it have to be "in order"? The movement of players is just as random. If what youre saying is true, I need a better explanation, here's a bit a code I planned to use.

Code:
Sub SpellAnim(ByVal Spell As Long, ByVal x As Long, ByVal y As Long)
    
    Dim SpellTimer As Long
    Dim z As Long
    z = 0

    Do While z  -1
        If GetTickCount > SpellTimer + Spell(i).Interval Then
            If z  12 Then
                SpellTimer = GetTickCount
                Call BltSpell(i, x, y)
                x = x + 1
            Else
                x = -1
            End If

    DoEvents

    Loop

End Sub

OOo I just realized, what if this procedure was executed again during the DoEvents, what would happen with the same sub running at the same time. Also while we're on the topic, I wanted to create some serverside timers for some map events. What if there were say, a dozen of these timers active on the server, would it be noticable?
Reply
#7
Why would you want to do this anyways?

Stop trying to make it so complicated. You do all your blt'ing in the game loop, you don't need to separate it into 100 different functions.

If it's not going to be used a lot you still keep it in there...doing the proper checks.

Why do you think we use a main game loop and not 10 different timers each dealing with a different thing?

Listen to Spodi, it's about logic...
Reply
#8
Well Ive moved onto server loops and need some more advice..
I think that certain events arent important enough to check every loop, such as the respawning of map objects (ex/ trees, ore, etc)
SOoo.. I just through this together in a minute:

Serverloop:
Code:
If GetTickCount > SecondTimer + 1000 Then
            Call CheckTempTree
            SecondTimer = GetTickCount
        End If


Code:
Sub CheckTempTree()
Dim x As Long
'RespawnTreeID records current temp trees, and handles the timer and respawn

    Do while x  -1
        If RespawnTreeID(x) = -1
             x = -1
        Else
             If GetTickCount > RespawnTreeID(x).Timer + 20000 Then
                 RespawnTree(RespawnTreeID(x))
                 RemoveTreeID(x)
             End If
        End If
    Do Events
    Loop

End Sub
This would reduce checking certain unimportant procedures, thereby lightening up on the serverloop. Idk I just pieced this together off the top of my head, you can harrass me now.
Reply
#9
Code:
If GetTickCount > SecondTimer Then
                Call CheckTempTree
                SecondTimer = GetTickCount + 1000
            End If

That's how it should look. Instead of doing the check and adding a lot, it just does the check and then adds once.
Reply
#10
GIAKEN Wrote:
Code:
If GetTickCount > SecondTimer Then
                Call CheckTempTree
                SecondTimer = GetTickCount + 1000
            End If

That's how it should look. Instead of doing the check and adding a lot, it just does the check and then adds once.

Thanks for that, just fixed up my Gameloop and Serverloop ;D

I need some constructive criticism on the way I set up the respawn timer.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)