2018-11-03 19:07:53 (edited by kianoosh 2018-11-03 19:10:20)

Hi there. Let's say i want to loop a function in my game which is created using pyglet. You might say that use pyglet.clock.schedule functions but here my problem comes. It looks like pyglet itself increases the sleeptime so when you say pyglet.clock.schedule_interval(func, .001) it's not really calling a function each 1 millisecond. Pyglet itself puts a sleep between each call, At least from what I could guess and thus making loops that should be very fast like bullet update function trigger seriously slower than how fast they should be called. I tried multi threading too but it looks like it even doesn't let me start a thread or possibly use a thread when pyglet makes its window and begins working. Please tell me there's a way to fix this or there's a way to make pyglet.clock.schedule stop lying and call functions about as fast as you tell it to.
Edit: I used pyglet.schedule(func) as well, Still the same result. It doesn't trigger functions in the way I want it to
Thanks for reading.

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2018-11-07 09:47:52 (edited by magurp244 2018-11-07 10:26:44)

The speed at which functions are processed and called is a measure of how much processing power you have, usually calling things every 0.001 milliseconds is unnecessarily, and impractically fast. On top of having to return control to the operating system and process things like keyboard, mouse, rendering, and other functions, how processor intensive your code is can greatly effect how often functions in your code are called. For example if one section of code takes 1.2 milliseconds to run, then whatevers next on the stack will take 1.2 seconds before its called. A large part of code optimization is to free up cycles like this.

Practically speaking updating things every 0.01 milliseconds is more than enough, and if you want to make a bullet move faster, just update its position by a greater amount, for example instead of the bullet moving 1 space every 0.0001 milliseconds, make it move 100 spaces every 0.01 milliseconds.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

Thumbs up

2018-11-07 10:01:04

Just a sidenote: Magurp244 explained it clearly as always smile but I would suggest, from my experience, that using a physics library will make your life much easier if you are developing a complex game. As an example, instead of moving the bullet manually each timestep, you set the bullet's velocity and orientation then the engine will update everything for you.

It's not for everybody but consider it. My main programing language is c#, but I am sure there will be good python physics engines out there.

Thumbs up