Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Program hang ups at world creation

Author
Message
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 17th Aug 2011 19:07
I've started work on the world generation code for my project and have run into a bit of an issue. I'm using several "expensive" functions (such as 2d Perlin Noise) across a massive map set (4200 by 1600 right now). After the program compiles it begins the world generation process, which inserts/removes data from a 2d array. The problem is that while going through all the calculations it needs to the program will freeze up, especially if I try moving the window around. At times it will look like the program died (Not Responding, error boxes appearing, etc), but if I wait long enough it finishes all the calculations and I'm able to play the game without a problem.

I suspect this happens since the program is trying to complete everything in a single step or loop of the program, instead of breaking it apart over several loops. Is there anything I can do to stop this from happening?
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Aug 2011 19:11
Use a much much faster machine, or create a dll which can do the perlin noise generation in another thread.

My signature is NOT a moderator plaything! Stop changing it!
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 17th Aug 2011 19:29
Can't you fake the perlin noise somehow? Ghosted textures or something?

Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 17th Aug 2011 19:41
Quote: "Use a much much faster machine, or create a dll which can do the perlin noise generation in another thread."


If I want other people to be able to play the game this needs to work on much, much slower machines As for creating a dll it's not something I have experience with but I'll look into it if there are no other options.


Quote: "Can't you fake the perlin noise somehow? Ghosted textures or something?"


The main reason I'm using Perlin Noise is that the game needs to be able to create a random world based off of a seed. Never used a ghosted texture method so I don't know if it'd work for what I'm trying to do.


One idea I had was to create "checkpoints" in the generation code. That would allow me to complete a single section of the process (such as determining the height map) then exit the loop. On entering the loop again it would skip the height map step since the program would know that checkpoint had already been reached. There might still be the issue of individual sections (such as 2d Perlin Noise) still causing a big hang-up.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 17th Aug 2011 20:09 Edited at: 17th Aug 2011 20:10
Oh yeah, of course. I thought you were just creating a dirty look. Most people just load in a pre-made height map.

Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 1st Sep 2011 23:34
Hate to bump, but I'm still working on these issues

I've timed the world generation code and found that for a world that's 4200 by 1600 blocks, it takes 26 seconds for it to complete at this stage. 24 of those seconds are made up of the cave generation algorithm (2d Perlin noise).

How do other games manage to keep the program from locking up during processor intensive processes?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 1st Sep 2011 23:39
You save it as data, then instead of generating it you just load the map.

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 2nd Sep 2011 03:05
Other games might use multi threading but we don't have that in DBPro. Have you thought of updating the screen after every few iterations of your algorithm? I would think DBPro is "responsive" (i.e. reading windows messages) during a SYNC command. So try to pepper your algorithm with meaningful syncs. Maybe even a progress bar?


A 3D marble platformer using Newton physics.
Alien002
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 2nd Sep 2011 05:25
The easyest way to stop the game from frezzing is to gen the map in chunks. After each chunk has been gen doing a sync. You may have to break the 2d perlin noise in to pices. ie gen noise data , interploting , gen final data and doing a sync after each has be dune.

I'm working on a game like your but i have not got that for with 2d perlin noise. I do have loading functions / screen working . That handles map gen , loading images , sounds and music. see atachment for a screen shot of it. The list of text is for debuging to see what is loading. The pick in the bottom right is spining.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 2nd Sep 2011 18:22 Edited at: 2nd Sep 2011 18:32
I have to agree with Alien002 here. Except, I am thinking of it slightly differently. In my map generation program I make the Heightmap up front randomly on the fly and then make the terrain from it all at the beginning. But now I am ready to start work on walking around and it generates the rest of the maps on the fly. So as Alien was saying, I'll do it in chunks.

In mine I'll be rewriting my code a little where the loop is at. For EACH 1 loop, I have it sync out to it and continue with the rest of the program. Then it comes back to the loop. Once all the loops are done, then it sets a variable saying IF a = MAX then bypass and then it goes out and creates the matrix with image. Something to this effect. If you do it right, it can be fast and not noticeable. Its a tricky process. My program however is already a lot more advanced then I was planning so its taking some planning on my part.

A kind of rough example is in a perline noise you have something like for t = 1 to 20. Well EACH of those is where I sync out the world. Meaning, 1 then sync, then 2 then sync and so on. The perline noise is being created during each sync and if your routine is kept efficient and small it will never be noticeable.

"Son, I crap bigger then you !"
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 3rd Sep 2011 22:42
@Pincho

I'm generating the world up front right now, instead of chunk by chunk. The data is getting stored in an array and then later loaded by chunk while the player moves around the map.


@tiresius/Alien/JackDawson

SYNC is exactly what I was looking for! The only place I've used it is at the end of my main game loop and I never quite understood how else it could be used. Using it too often almost tripled the time it took to generate the world, but I think I've found a happy middle ground.



Seeing as some of you are working on a game similar to mine, might I pick your brains on another matter? What method are you using to display the terrain? Right now I'm using textured object plains, but even though I'm simply retexturing/moving them there's a noticeable hangup every time the chunks update.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 4th Sep 2011 00:09 Edited at: 4th Sep 2011 00:09
I use the simple matrix command. I generate the heightmap first then save it out to the drive. Then import it in for the Matrix to be made with it. Its simple and fast. AND the map stays in tact when they come back to it.

Here are two threads that I have started based on the generator.

http://forum.thegamecreators.com/?m=forum_view&t=188775&b=1

And the newest thread I have because I'm trying to solve a shadow color issue when it comes to fog.

http://forum.thegamecreators.com/?m=forum_view&t=188950&b=1

You can get my latest full source code on the bottom link I have here.

"Son, I crap bigger then you !"
Alien002
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 4th Sep 2011 05:40
Alaror

For my game i'm useing smooth scrolling thats limited to only displaying the terrain around the player.

i'm looking into useing sprites so i can do the brightness of the terrain.
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 4th Sep 2011 23:47
@JackDawson

This is the first time I've taken a serious look at using the MATRIX commands, and I'm quite intrigued to say the least. My concern is that in the UPDATE MATRIX description found in the help files it says that it's a speed intensive command, so it should be used as little as possible. I'm going to play around with it and see what difference it makes.


@Alien002

My camera scrolls along with the player and updates the visible map using a chunk system. I have 9 x 9 chunks loaded at any time, and when the player crosses from one into another three of the chunks get deleted while three of them are created. It's only at the point of deletion/creation that I have a hang up.

That said I agree that only loading/deleting objects in the player's view will help speed things up. Instead of deleting/creating an entire chunk at once the game would just load/delete individual objects near the edge of the screen. If nothing comes of using MATRIX commands for my game this is probably the way I'll go!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 4th Sep 2011 23:52
If you look at my code example from one of my links above, you will see that I call the UPDATE MATRIX only once. And in the future when I add the code to allow me to use more then one heightmap, it will only get called when I am in need of another heightmap each time once. So as it may be intensive if your repeatedly using it, its not that big of a deal if your using a small enough heightmap. I am only using 256x256 for my purposes which is lightning fast. I would not go any smaller since you would need to call that command more often. But the bigger Heightmaps will take longer to UPDATE Matrix, so it was not a choice for me. So I am using good ole 256x256 to have more control over this.

"Son, I crap bigger then you !"
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 5th Sep 2011 23:59 Edited at: 6th Sep 2011 00:25
Alright, I implemented the chunk loading system using MATRIX commands and I'm blown away. The code necessary for terrain updates is at least half the size, and there's no hang up whatsoever (my matrix is only 48 x 48 since it's the most the player would ever see at once).

I did run into an issue though. For some reason I have thin lines between some vertical line of tiles. Is it a problem with the textures I'm using or an incorrect setting for the matrix?
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 6th Sep 2011 03:31
I've attached a screenshot of what the lines look like. There are a few recommendations in other topics on what to do but they haven't made a difference for me. Maybe the code is wrong, or there's a command I'm not using?



Another possibility is that my texture is messed up. Here's the terrain image I'm using: http://i.imgur.com/FTtAP.png
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 04:07
Yes your terrain is wrong. You said your using 48x48. But your picture size you have is 160x128. Well the 128 is what divides up those three separate types of tiles. So 128 Divided by 3 = 42.66666667. In other words, its not aligning up with your terrain.

"Life is like a box of chocolates.. eat it before it melts."
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 6th Sep 2011 04:20
Sorry I should have been more clear. The matrix is broken into 48 x 48 tiles, each tile being 32 pixels wide, which comes to 1536 x 1536 pixels. The terrain image I linked is five tiles wide and 4 tiles high (the blank space at the top is there for any places I don't need terrain), and each block should be 32 x 32 pixels. Is having a blank set of tiles a problem?
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 04:51 Edited at: 6th Sep 2011 04:51
Ahh, I could not see the blank space. Ok. I see it now that I'm actually looking for it.

On another note, its hard to know what your code is doing without something to see, Codewise.

"Life is like a box of chocolates.. eat it before it melts."
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 6th Sep 2011 23:10 Edited at: 6th Sep 2011 23:12
Here's the code I use to create the matrix:



...and where the command is called to update the matrix tiles:



There's also the POSITION and UPDATE commands called after everything else but I don't think those are relevant to the problem I'm having.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 23:54
Quote: "
There's also the POSITION and UPDATE commands called after everything else but I don't think those are relevant to the problem I'm having.
"


I'm confused. I thought that POSITION of your texture is the problem. You have lines. So it very well could be the problem.

And I'm not seeing any problems with that code there. So obviously the issue is somewhere else.

"Life is like a box of chocolates.. eat it before it melts."
Alien002
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 7th Sep 2011 00:01 Edited at: 7th Sep 2011 00:04
The problem could be the Image sizes or if you are getting them from a tile pack it could be the get image x , y , X + size_X , Y + Size_Y.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 7th Sep 2011 00:19
Yea I mentioned that too. But Alaror stated that they come out at 32x32. Which after I checked the file, it was correct. I agree with you totally Alien002. I am thinking that the size inside the code is off somewhere that we have not seen yet.

"Life is like a box of chocolates.. eat it before it melts."
Alien002
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 7th Sep 2011 01:17 Edited at: 7th Sep 2011 02:52
edit: deleted

I forgot that you was useing matrix and posted a message that was about the size of the tiles in the screen shot.

edit 2

Here is my source code for what i have dune so far with the game. I'm think of starting an open souce project. If i do i will post my red stone , water , sand , play collision , etc source code.
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 8th Sep 2011 08:31 Edited at: 8th Sep 2011 18:19
Not sure how I hadn't found it earlier, but this topic had the answer I was looking for: http://forum.thegamecreators.com/?m=forum_view&t=167832&b=1. Evidently mipmapping was the the main culprit, so I had to turn it off when loading the image (using "LOAD IMAGE "imagenumber.png", imagename, 1) and changing the "Filter" part of the SET MATRIX command to 0. I also had to change the SET MATRIX TRIM command to "SET MATRIX TRIM 1, 1.0 / 160.0, 1.0 / 128.0". 160 is the total width of the tile texture image I'm using and 128 is the total height. An unfortunate side effect of this is that too much of the texture gets trimmed out, which means the workable area is actually smaller than 32 x 32.

Thank you to everyone who provided suggestions. I'm able to move forward with my game

Login to post a reply

Server time is: 2026-07-10 06:07:54
Your offset time is: 2026-07-10 06:07:54