Jump to content

theDream

Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by theDream

  1. 22 hours ago, Josh said:

    In Leadwerks, the physics are updated one step in the World::Update method if 16 milliseconds have passed since the last physics step. This works independently from the framerate. Physics objects are smoothly interpolated between the previous two steps in order to provide smooth motion, even if the framerate varies from 60 hz. There is no easy way to modify the physics step time.

    This is how I believe the Time class and the World class work roughly and obviously in Lua and not C++ like it actually is:

    local Time = {}
    
    --[[ 
    
        All other Time functions
    
    --]]
    
    function Time:Update()
    
        self.current = self.Millisecs()
    
        if self.pause then
     
            self.previous = self.current 
    
        end 
    
        self.delta = self.current - self.previous
    
        self.previous = self.current
    
    end
    
    function Time:Step(frameRate)
    
        local frameRate = frameRate or 60
    
        local delta = 1000/frameRate
    
        Time:Delay(delta)
        Time:Update()
    
    end
    
    --------------------------
    
    local World = {}
    
    --Other World Functions
    
    function World:Update()
    
        self.physicsDelta = self.physicsDelta + Time.delta
    
        if self.physicsTime >= 1000/60 then
    
            Physics:Update(self.physicsDelta)
            self.physicsDelta =0
    
        end
    
    end

    I was wondering if Time:Step could act like this:

    function Time:Step(frameRate)
    
         self.delta = 1000/frameRate
    
         --In case you switch back to using Time:Update()
         self.previous = self:Millisecs()
    
    end

    I know this would mean modifying the Time Class. Is this possible?

  2. Thank you for a response, I appreciate it.
    I understand I have to call World::Update after Time::Step or Time::Update for the physics to be calculated.

    The issue I am having is that Time::Step which is what I need to use to manually 'step' through time with a fixed Delta uses Time::Delay which stops all processing trying to make it match the given framerate.
    So if I use Time::Update I get about 300+ FPS.
    If I change this to Time::Step and nothing else, because of the call to Time::Delay inside of Time::Step it maxes at 60ish FPS.
    So If I call Time::Step twice a frame because of the delay it drops to 30ish FPS do to the 2 calls to Time::Delay.

    Without this delay, logically I should be able to calculate Physics using the fixed delta given from Time::Step to calculate physics multiply times a frame.

    Here is a basic example:
     

    while window:Closed() == false do
       
      	local frameRate = 60
    	local n = 10
    
        for i = 1, n do
            
            Time:Step(frameRate) --Due to the delay in this function call the FPS will drop to frameRate/n
            world:Update() 
            
        end
        
        world:Render()
        
        context:Sync(false)
        
    end

     

  3. I am working on a server meant for an FPS game. I own the pro version or Leadwerks but do not know C++ at all, so I just use LUA. I am trying to implement a rewind function for delayed or dropped packets. I want to set the objects back to their states 'n' ticks ago and run the physics calculations with the new input back to current tick within 1 rendered frame. I know I need to use Time:Step() which steps through time at 1/60th of a second the same rate as the physics engine. Unfortunately based on tests and the documentation this also calls Time:Delay() to try and maintain 60hz. This makes the max FPS roughly 60 even without context being synced. I figured I would be able to call this multiply times per frame if I could modify the Time:Step() function to get rid of the the Delay. Is this something I could possible modify?

  4. Thanks for the reply. I am having some issues calculating left, right, top, bottom. What I have researched says that  (bottom = -top).

    But in your B calculation and the ones I have seen, top and bottom are added together. To me (top + bottom) should equal 0. But that is obviously not the case since there would be no need to calculate B since it would always be 0.

    And thank you again for the help, I appreciate it.

×
×
  • Create New...