Gamestates for Lag Compensation?

Have you taken a look at my example (gameloop.py in my GitHub for PyAuthServer?) I don’t expect you to guess from the class!

https://github.com/agoose77/PyAuthServer/blob/master/bge_game_system/gameloop.py

A really simple example (which doesn’t check options like USE_FRAMERATE, or update the profile information):

In the custom build of Blender, look in the Render tab (Game render engine), below the exit key.

If you use the code below, place it inside a text block called “main.py” and write this in the Custom gameloop entry field “main.GameLoop”


from bge import types, logic


class GameLoop(types.KX_PythonLogicLoop):
    
    def tick(self, current_time, time_step):
        for scene in logic.getSceneList():
            self.set_current_scene(scene)
            
            self.update_logic_bricks(current_time)
            self.update_animations(current_time)
            self.update_physics(current_time, time_step)
            self.update_scenegraph(current_time)
        
            self.update_render()
        
            self.update_keyboard()
            self.update_mouse()
            self.update_scenes()
            
    
    def main(self):
        current_time = self.get_time()
        
        accumulator = 0.0
        clock_time = 0.0
        
        while not self.check_quit():
            current_time, last_time = self.get_time(), current_time
            delta_time = current_time - last_time
            
            tick_rate = logic.getLogicTicRate()
            time_step = 1.0 / tick_rate
            
            # Prevent large DT values
            if delta_time > 0.25:
                delta_time = 0.25
            
            accumulator += delta_time
            
            # Calculate how many full ticks
            ticks_to_process = int(accumulator / time_step)
            elapsed_time = ticks_to_process * time_step
            
            # Update accumulator
            accumulator -= elapsed_time
            
            # Update clock
            clock_time += elapsed_time
            
            for i in range(ticks_to_process):
                # Update this here in case tick was an empty function (updates events)
                self.update_blender()
                self.tick(clock_time, time_step)
            

Yeah; I was using gameloop.py as an example, but I couldn’t figure how to run it. I never would’ve guessed to just call(?) the class itself: I was doing “<module name>.<test class name>.main”, which did nothing. :stuck_out_tongue:

I knew it was gonna be something silly like that. Thanks~!

It actually imports the module and obtains the class in memory, then runs .main(),
It’s a barebones implementation at the moment, so it’s not quite perfect and some things might not work as expected.

from bge import logic, types

class GameLoop(types.KX_PythonLogicLoop):
    def __init__(self):
        pass
        
    def main(self):
        pass

I’ve attached that to the default scene’s cube, and I get this error:

Python script error - object ‘Cube’, controller ‘Python’:
TypeError: Base PyObjectPlus() takes exactly 1 argument (0 given)

Have I simply cut too much in my first phase of testing? I’ve also tried directly copying GameLoop from gameloop.py, cutting only contextmanager and ReplicableRegisteredSignal (the names weren’t registered, because I removed the SignalListener extension), and the error was still there.

What am I doing incorrectly? Where is PyObjectPlus(), in all of this? I’ll attach a blend for you to check out yourself.

Attachments

loopdeloop.blend (448 KB)

I’m trying to be as clear as I can Alfonso, please read my previous posts!

The gameloop class runs the game engine, and so it doesn’t rely on Logic Bricks (well it does, but only because the engine has certain places where this is the case).

In the custom build of Blender, when using the Game Engine render engine mode, there is an input field called “Custom gameloop”. Writing this entry with “main.GameLoop” will run the gameloop with the engine.

Good luck

This has been a rough learning process, but I’ve finally gotten the barebones functionality up and running. I’ve got a simple spinning object that prints a message to the console that couldn’t do either if the GameLoop script didn’t run. I’ve attached my demo, in case I’ve set myself up for failure in a way I don’t see.

Sorry this took so long to grasp! With the basics down, experiments should be a lot smoother from here on out~

Attachments

loopdeloop2.blend (442 KB)

That print statement made me laugh :wink:

Here’s where I am right now, with my testing. So far, I’m doing very well! My kink right now is that I can’t figure out how to pause background-object animations outside of the game loop. Is it possible to pause an object’s animation(s) without deactivating actuators?

In a pinch, I could simply have objects not set to be affected by the rollback mechanics can simply have an always-actuator that will pause animation on the first frame of rollbacks, and then resumes on the next frame of normal action, but there’s a lot of nasty overhead with that method.

Attachments

loopdeloop2.blend (520 KB)