Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6888371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:00:25+00:00 2026-05-27T06:00:25+00:00

Here’s the deal. My game generates chunks of randomly generated terrain based on the

  • 0

Here’s the deal. My game generates chunks of randomly generated terrain based on the position of the camera (2D isometric). When moving from chunk to chunk, there is always a tiny burst of lag which results in a little jump because the game must wait for the terrain to generate before it moves the camera more. From what I understand of threads, they could be used to have the terrain generate while the main thread moves the camera like normal. I am just not quite sure how to do this. Maybe something like this?

Update(){
if(cam != prevcam)
{
thread.start();
}
}

And then after the other thread is done with the generation it suspends itself somehow and restarts next time the camera position has changed. Note that the camera position refers to the chunk that the camera is centered on. If it was centered on block 40,42 then it would be 1,1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:00:26+00:00Added an answer on May 27, 2026 at 6:00 am

    You could use threads to solve this problem, and it would probably work, but you’re going to introduce a whole set of problems that (a) might still result in lag, and (b) will be much harder to fix.

    Don’t get me wrong, I love threads, but I wouldn’t use them to solve this particular problem, especially in a tight input/logic/render loop in most games.

    The lag happens because the amount of work that needs to be done between frame renders takes long enough that you notice it as a dropped frame rate. What you really want to do is find a way to chop your terrain generation into smaller chunks/tasks that DO fit inside of a single frame render, and then spread terrain generation over as many frame renders as necessary to get it done without dropping the frame rate below what the user will notice.

    To go a little deeper, I can see why you might be tempted to use threads to solve this problem. The thing is, threads are best when you’ve got a job for them to do, and you either don’t care so much about how long it takes for them to finish, or you really need two or more pieces of code to run simultaneously. In the case of simultaneously running code, threads aren’t always an optimal solution either; sometimes spawning a separate process, and leaving multitask scheduling up to the OS (the scheduler being a piece of code that has been highly optimized by tons of professional engineers) is often a better answer.

    By introducing threads into your game loop, the thread’s work still needs to finish within a very small, well-defined time window, which means it needs to work in lock step with the rest of the app, which means there’s no benefit to running in multiple threads because you’re still acting like a single-threaded app.

    The one exception to this would be if you really, truly need to take advantage of multiple cores. Just be warned that adding threads, while totally awesome, is going to add unnecessary complexity in most cases.

    And after saying all of that, to answer your original question, you would use threads to do this by chopping it up into small chunks of work, and letting the thread work on those chunks as quickly as it could, without taking too much CPU time away from more time-sensitive threads, such as your rendering thread.

    I’d like to see more games take advantage of threads. The issue is that most games are essentially simulations where almost everything is tied to a central clock (animation, sound, AI calculations, etc.), and removing that direct connection to the central clock can only be done when the user wouldn’t notice it. Examples of this might include:

    • Pre-calculating random weather (where, only after the weather is calculated, do users see anything), and it doesn’t matter (in terms of game play) when the actual weather appears
    • Path finding, but only if the actors in your game can sometimes take longer to calculate paths than other times.

    Since threads don’t start/stop excecution execution in a known order, or within a certain time, it means sometimes it’ll take 1/10th second, but if the CPU is busy, maybe it’ll take a total of 2 seconds, with how available the CPU is.

    Anyhow – good luck with your game!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is my query: select word_id, count(sentence_id) from sentence_word group by word_id having count(sentence_id)
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is the code from my project where I am using a datepicker. The
Here I am trying to retrieve the response from the server and display it,
Here's Erik Wallentinsen's PullToRefresh ListView on github. But it refreshes the listview from top
Here is the scenario: I have several CIFS partitions which AD-based users can mount
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.