0

I'm currently programming a game at the moment, and what I'm currently trying to do is replace multiple "objects" in the game by using a loop.

When I say "objects" I'm not referring to an object in OOP, but a simple entity in my game that is drawn on the buffer (example: a rock or a tree).

Now this method of replacing objects works just fine if it's only a few objects, but if I'm trying to replace up to 25+ objects it looks a bit weird.

What I mean by that is you can see each object being replaced one at a time, rather than all at once. (I understand that this is because the task is executed in a loop)

This pretty much sums up what I'm doing, programmatically:

for(int i = 0; i < tilesToReplace; i++) //Looping through the total amount of tiles that will be replaced
//Spawning an object in the desired tile
spawnObject(objectPatch.objectId, //irrelevant, (new object ID)
        objectPatch.coords[0][i], //irrelevant, X Coordinate of the current index
        objectPatch.coords[1][i]); //irrelevant, Y Coordinate of the current index

I've already thought about doing something such as pausing the entity rendering until all of the objects I want to replace are initialized, but I'm wondering if there's a simpler way of doing this, such as a way of handling a loop that I'm not aware of. (I'm not really aiming for changes I can make with my object/rendering handling, etc.)

user1606034
  • 113
  • 1
  • 5
  • 1
    Unless you multithread it, that's the most you can do. – FThompson Sep 21 '12 at 01:04
  • 1
    Even if you multi thread, only 1 thread should be doing all of the drawing. Without any code, it's hard to tell. Double buffering could be an option if we're delaing with stuff being "painted". – John3136 Sep 21 '12 at 01:13

2 Answers2

0

I tried this example with N = 10; replacing 100 labels still appeared simultaneous. The problem lay elsewhere in your program, and you're going to have to profile the code to see where. As a general principle, try to keep your activity on the event dispatch thread as short as possible; an sscce, for example, may be a useful exercise.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

If you are developing in C++, there is a way where you can setup screen buffering. You process changes on the next screen buffer (the one not displayed). Then you switch the screen to display that buffer after processing is complete.

Are you using C or C++. This an example of why gaming works better on C.