• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Pixelated_Nate
      Hello all!
      I'm currently designing a 2D, Puzzle/Action RPG, in a similar vein to Legend of Zelda: Link to The Past, in Unity and require a Programmer partner in which to work with me.
      The project, yet to be titled, will feature:
      A semi-open world, represented through pixel art, in which the player traverses to enter dungeons and advance the story. A handful of side-quests that require memorizing details and using puzzle-mechanics. A fast-paced, melee combat system that will include dodging, blocking and utilizing four different attack types that can be switched on the fly. A simple inventory of "Key Items" to be used in order to advance the story. Day & Night system and Weather Effects, with weather effecting combat.  A very simple Dialogue System to convey information via colored text. Saving/Loading via exporting and importing a physical save file. Majority of the project is already planned out, with plans to release commercially and splitting the profits equally among the two of us. 
      I would request that the applicant is able to work semi-independently, following an outline, and that they have experience in both C# programming  *and* putting those scripts to use inside Unity, whilst I will be creating the Art, Music/SFX and doing Level Design (Though if you are also comfortable in assisting me with these, I wouldn't be opposed.).
      Work will be shared in either Github or Unity Collab (Applicants preference), with communication done via Discord. 
      For more information and to apply, please contact me at nathan.jenkins1012@gmail.com
      Thanks for reading! 
    • By Just4lol
      I'm looking for my dream teammate(s) to help me work on my Unity game. I still dont know where Im going with that project but I want to make a good final product that I would be able to sell or publish it for free on Steam.  Here a video of the prototype (The only thing I dint made is the skybox) https://www.youtube.com/watch?v=y2Otmt9jRkc
      My discord : Just4lol#46982
      I want somone at least as competent as me : 
      - I want somone with at least one year of experience in Unity (already worked with scriptable object and know oop).
      - Already worked with shaders or can do editors tools is a plus.
      - Can do 3d models in Blender or can do 2d art for the ui or particles effects.
      - Can make soundtracks or sound effects a bonus.
      Im a french Canadian so mind my english I will do my best to edit any errors I see. 
    • By Damnwing0405
      I am looking for talents to form a team of making a strategy base action game. Talents I am currently looking for are : -
      (I) Unity programmer (mobile)
      (II) Game designer
      (III) 3d Artist
      (IV) SFX Artist
      The attachment is some game concept for the game. All the concept will be turn into 3d or card form. The game will be strategy game where the players can form their own team and control the units in the battle field real time to fight against each others.  If you are interested to know more details please pm me or send an email to damnwing0405@gmail.com

    • By bsudheer
      Leap Leap Leap! is a fast-paced, endless running game where you leap from rooftop to rooftop in a computer simulated world.

      This is a free run game and get excited by this fabulous computer simulated world of skyscrapers and surreal colors in parallax effect. On your way, collect cubes and revival points as many as you can to make a long run.

      Features of Leap Leap Leap:
      -Option of two themes: Black or White.
      -Simple one touch gameplay.
      -Attractive art.
      -Effective use of parallax.
      To Download the game:
      Playstore: https://play.google.com/store/apps/details?id=com.avakaigames.leap
      Appstore: https://itunes.apple.com/us/app/leap-leap-leap/id683764406?mt=8

    • By BillyGD

      Play Flick Football 3D @ https://gamejolt.com/games/flickfootball3d/326078
      Check out our Facebook page @ https://www.facebook.com/FlickFootball3D/
      Flick Football 3D is a turn based football game inspired by the table top classic 'Subbuteo'.
      The game is currently in very early Alpha development. There is still a lot to be done before the first proper release but I have decided to release this playable version to get as much feedback as possible.
      The only game mode currently available in this release is the 'Practice Mode' which gives you control of both teams. Either play against yourself to get used to how the game works or play against friends and family on the same computer!
      Planned Future Features Include:
      -Take control of your own custom team in the single player campaign.
      -Play in online leagues and tournaments against other players in the multiplayer mode.
      -Fully customisable stadiums to make you stand out from the rest of the players.
      -Improve your players stats and skills by playing matches and setting up training sessions.
      Flick Football 3D is available for Windows, Mac and Browser.
      Thank you for viewing my game, all feedback is greatly appreciated. I can be contacted at; BillyGDev@outlook.com
      'Flick Football 3D' is also the development name for the game and I haven't yet decided what the full release will be called, so if you have any ideas please drop me a message!
  • Advertisement
  • Advertisement
Sign in to follow this  

Unity Latency vs Speed: Multithreading or single-threading

This topic is 4962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently working on the core design of my game engine, deciding how the components will fit together. My current concerns are keeping input latency low, and making sure video v-sync doesn't stall the gamestate updates. After reading through these forums and other articles over the past week, I've been toying with two ideas: IDEA 1 (from this thread) Use a single thread, and attempt to run the game state (including input) at a fixed rate, while allowing the renderer to run at full speed. Essentially the game loop runs as fast as possible, and within each iteration the time is checked to determine if the game state should be updated, which could be set to around 20 times a second. PROBLEM As nice and simple as this method is, I see two big problems. First, input latency. Polling for player input only 20 times a second isn't going to feel very smooth to the player, it will react rather choppy. And Second, the speed of the loop could stall if v-sync is on, and the renderer ends up waiting for large spaces of time. This could throw the game state off, and player input will be even more erratic. (And yes, I do want to be able to use v-sync.) IDEA 2 (triggered by this thread) I use multiple threads. The main thread controls the game state, and does a lot of sleeping, running only around 20 times a second. The renderer has its own thread, which runs as fast as possible, over and over. V-sync works just fine, since it will only stall that one thread, the main thread continues on as normal (and in fact benefits from the v-sync stalls by making better use of the CPU). Input as well has is own thread, and it too sleeps most of the time, waking up multiple times a second to poll for player input. PROBLEM The main problem here is the potential fight for CPU time. With the rendering thread running full speed, the other two threads will have to fight to get their updates done without causing game state or input stutters. One solution I read a lot involves messing with thread priorities, making the renderer a lower priority than the other two, so that they get a chance to run when they wake up. But this feels more like playing with fire to me, changing thread priorities and hoping it all works out. Unlike the single-thread method, where everything was linear and we knew for sure it worked as expected, I don't have as much faith in the thread priorities, and the various platforms the game may be ported to. And still, we have the issue of how often we need to poll for input, to balance between using too much CPU, and preventing input stutters from the delays. I believe DX has the option to use an event system for input, where the input thread is able to sleep until the player provides input, then it automatically wakes up to handle it. But I don't know if this is available for all forms of input (keyboard/mouse/joystick), and more importantly, I don't know that this is available on other platforms (heck, I don't know anything about game input under Linux right now). So, I feel stuck, there are pros and cons to both ideas, speed or latency issues either way. Anyone have some input on this, your own experiences or alternatives? Anything would be appreciated, I'm ready to move on from here. :)

Share this post

Link to post
Share on other sites
The rule is quite simple in the end: Thread overhead is not worth it, only thread what you must. Basically what you have right now sounds like a sound idea, if you want a thread to take up less of the timeslice you can have it check how long it's busy with GetTickCount and call Sleep(0) when it's exceeded it's slice according to you.

You could also have threads call longer Sleeps.

Share this post

Link to post
Share on other sites
Honestly, from my experiences, you only really want to mess with a few threads:

1.) A thread for rendering. This should only do rendering. You might want to just make it your main thread for simplicity's sake.

2.) A thread that handles AI, input, physics, and all other CPU-dependent stuff. Don't do a seperate thread for input; it's unnecessary and will probably cause you to get input lag.

3.) A thread for music and sound. Duh.

4.) A thread for networking. You MIGHT be able to put this one into the main thread, or the CPU-dependent thread, but it depends on your overall design.

5.) A thread for streaming in data. Duh.

Share this post

Link to post
Share on other sites
Buth when it comes to multithreading, is there an alternative to modifying thread priorities? Or maybe theres something I don't know about how threads cooperate? Making them sleep as much as possible is the best thing I can think of, but it still seems that they'll be competing a lot.

Etnu, the threads you have listed there sound good, though I know from your other posts that you're able to keep input in the main thread because you run it 100 times a second. This seems a little extreme to me, surely that creates some heavy CPU competition with the renderer thread? And given that, in a multiplayer game, the host is only broadcasting updates 10-20 times a second to the clients, it seemed redundant for all of the main loop to run faster than that. What are your thoughts there?

Share this post

Link to post
Share on other sites
1.) A good renderer should do as little as possible on the CPU. Your video card is powerful. Use it. Stop wasting time trying to make sure every little polygon that isn't visible isn't drawn. That's pointless. Use the graphics card's features. Occlusion queries. Lay down Z. The odds are that you're just wasting clocks with your culling algorithms if you're only pushing 5-10 million polys / sec.

2.) Priorities don't need to be modified much. Sleep(0) is usually good enough. Multi-tasking OSes like windows work remarkably well with seperate threads. Just check your processes tab...


And given that, in a multiplayer game, the host is only broadcasting updates 10-20 times a second to the clients, it seemed redundant for all of the main loop to run faster than that.


const float InputResolution = 0.01f;

float InputUpdateTimer = 0.0f;
UpdateTimer += DeltaTime();
if(UpdateTimer >= InputResolution)
UpdateTimer = 0.0f;

Share this post

Link to post
Share on other sites
Keep in mind here that the input engine is idle 90% of the time. Processing an action when you press the "up" key is not likely to eat many CPU resources.

Share this post

Link to post
Share on other sites
threads do not compete. They run during a given time slice (the quantum) and then return the control to the kernel which wake up another thread (and so on... only sleeping threads and threads which are in a "wait" state are not concerned).

If one of your thread do not have anything to do, then Sleep(0). It's easy and simple - it will only return the control to the OS which can then wake another thread.

Playing with thread proirity must be done only if you have a good understanding of what is done behind the scene. It will modify the way the OS allocates time quantums - and therefore may change the way your program is executed. This means that if your threads are communicating then you'll have to take care to the synchronisation of the threads.

Rising the priority of a thread will of course give it more time to execute - as a consequence, other threads will have less time. This is done by using the SetThreadPriority() function in Windows (see the msdn for further informations about this function and its parameters).


Share this post

Link to post
Share on other sites
It depends a lot on the OS, but the generally:

1. In a pre-emptive system (like Windows), threads of the same priority take turns. They switch after a small period of time or when the current thread relinquishes control.
2. In a cooperative system (like on a certain console), threads of the same priority take turns, however they switch only when the current thread relinquishes control.
3. Threads of a lower priority only run when no higher priority thread is ready to run.

Share this post

Link to post
Share on other sites
Original post by Emmanuel Deloget
... Rising the priority of a thread will of course give it more time to execute ...

That is not accurate.

Example: two threads have the same priority. Since they take turns, each gets about 50% of the time. If you raise the priority of one, it will get 100% and the other will get 0%.

Another example: two threads have different priorities. The higher priority thread relinquishes time occasionally, so the lower priority thread get about 30% of the time. If you raise the priority of the lower thread, but it is still lower than the higher thread, nothing will change.

Of course, this is simplified and depends on the OS.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement