Results 1 to 10 of 20

Thread: Procedural world generation - ground and traps seems to not generating.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    Quote Originally Posted by User137 View Post

    I'm still pretty "new" to perlin noise, but aren't you supposed to combine many random waves. First ones smooth big ones, then smaller and sharper. From line 99+, you are using same frequency for all of them. Do i just misunderstand the code?
    Could be the PerlinNoise2d() already does the multi-wave math for you.
    it is my understanding that PerlinNoise does all that for you which is why it is so slow to begin with.

  2. #2
    @Darkhog
    A few notes about your code:

    You can set size of dynamical multidimensional array using SetLenght(array, XDimension, YDimension).
    http://stackoverflow.com/questions/5...ensional-array

    Also why not storing chink IDs in nuerical way. So you can have soething like this:
    Air = 1, Water = 2 and all ground chunks have ID higher than 2.

    So spike placment code would look something like this:
    Code:
    if ((Chunk[x][y]<3) and (Chunk[x][y-1]<3) and (Chunk[x][y+1]>2) and (Random(101)<TrapChance)) then Chunk[x][y]:=SPIKEID;
    With this you get rid of yourself of that or statment. And becouse you would probably have multiple ground types in the future you saves yourself the need for checking each posib le ground id in the first place.

    I would also split that multicondition if statment of your into several nested if statments. Why? When you are using multiconditional if statment all conditions get checked even if first condition isn't met already. So using nested if statments could speed up your code a bit since it won't be ckecking if other conditions are met, when the first condition has already failed to meet the requirements. Not to mention that such code would be more readable.

  3. #3
    Quote Originally Posted by SilverWarior View Post
    When you are using multiconditional if statment all conditions get checked even if first condition isn't met already.
    This is not true. I can demonstrate that with simple example:
    Code:
    var sl: TStringList;
    begin
      sl:=nil;
      // Version 1: No errors
      if (sl<>nil) and (sl.Add('Test')>0) then exit;
      
      // Version 2: Runtime error
      //if (sl.Add('Test')>0) then exit;
    If-statement ends in the (sl<>nil) condition, because any further conditionals wouldn't change the logical end result. If there was OR, instead of AND, then it would have to proceed to next comparison because (sl<>nil)=false.

    edit: Have you double/triple-checked the drawing code, or done analyzing to the chunks to see if traps are actually generated, just hidden.
    Last edited by User137; 01-06-2013 at 08:09 PM.

  4. #4
    OMG! Found issue. I was using byte for array of TChunk and AIRID was defined by -1. Me and my stupidity... Now it works nicely.

    //edit: When I set chunk x/y when generating world to other number than 0, it generates same exact chunk no matter what I do .

    //edit #2: This is most current version of my world generation class: http://pastebin.com/sPsfNWLD. I've applied optimization fixes suggested by User137 and SilverWarrior, but it is moot point since it generates exact same chunk no matter of what value I put into chunk x/y.
    Last edited by Darkhog; 01-06-2013 at 09:41 PM.

  5. #5
    Ok, I've figured what issue was: It turns out that I had to first generate one chunk before generating subsequent ones. I've also found out that ChunkX and ChunkY does nothing. WTH? Problem with chunks not adding up (seams) probably lies in carving step, however I don't know how to fix it.

    Problem with ChunkX/ChunkY doing nothing... Well I don't even know what causes it (here's perlin noise unit I'm using, which might be relevant - I didn't wrote it nor I do understand it: http://pastebin.com/CSk62Jdf).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •