Results 1 to 10 of 34

Thread: Thyandyr's voxel engine

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    In reference to freeing all the TChunks in TDictionary<string, TChunk>, how do I do it?

    I don't see a way to just do

    Code:
    for I = 0 to count-1 do 
      TDict.Items[0].Free
    as it is not sorted or indexable in that way

    Do I need to extract all the keys and then iterate with that list? That hardly seems like a smart way to do it.

    OK this works

    Code:
    for Chunk in TDict.Values do Chunk.Free
    Last edited by Thyandyr; 01-11-2017 at 09:32 PM.

  2. #2
    SO I'm adding lot of single values into one VBO. Things work OK until somewhere slightly above

    Vertices:467544
    Indices :100188
    Total :567732

    some (full) chunks just seem to be missing from where it should be on screen.

    So I draw 23 chunks size 11x11x11 and it all shows great, but 24 chunks and some start to disappear. If I draw 30 chunks it looks like swiss cheese!
    Last edited by Thyandyr; 01-11-2017 at 10:36 PM.

  3. #3
    Quote Originally Posted by Thyandyr View Post
    In reference to freeing all the TChunks in TDictionary<string, TChunk>, how do I do it?

    I don't see a way to just do

    Code:
    for I = 0 to count-1 do 
      TDict.Items[0].Free
    as it is not sorted or indexable in that way

    Do I need to extract all the keys and then iterate with that list? That hardly seems like a smart way to do it.

    OK this works

    Code:
    for Chunk in TDict.Values do Chunk.Free

    Uhhh... why aren't you just using a TObjectDictionary with "doOwnsValues" set in the ownerships parameter in the constructor? That's what they're there for. That way, it works exactly like a TObjectList that has OwnsObjects set to true, and you don't need to do anything at all in your destructor as all the dictionary values will be freed automatically.

    As far as your VBO problem, what kind of GPU are you using?
    Last edited by Akira13; 02-11-2017 at 01:16 AM.

  4. #4
    I have several dictionaries that juggle values between them, so I want to manage the lifetime of the contents myself. But when closing the program I rather empty all the dictionaries. I had a code looping the keys and then getting the values and then freeing the values. that resulted in mem leaks. But I found I can just iterate the values directly and free them. I just haven't used dictionary before. Anyway it is solved.

    For graphics card I have Nvidia GFX 860M or something like that. Laptop. I didn't see any notes about maximum size in the OpenGL documentation. Will continue on this issue tonight.

  5. #5
    I'm not sure exactly how TDictionary works but in general when you are removing items from Lists it is always better to go from last item to first instead of always removing first item in a loop. Why?
    Because when you remove first item from the list all other items needs to be shifted in order to fill the hole that you caused by removing that one item. This results in lots of unneeded data moving in the list internal array.

  6. #6
    Quote Originally Posted by SilverWarior View Post
    I'm not sure exactly how TDictionary works but in general when you are removing items from Lists it is always better to go from last item to first instead of always removing first item in a loop. Why?
    Because when you remove first item from the list all other items needs to be shifted in order to fill the hole that you caused by removing that one item. This results in lots of unneeded data moving in the list internal array.
    I agree and would have done it 'from count-1 downto 0' but that is not possible with TDictionary. Anyway freeing the Chunks is only for the program shutdown so performance is not that important anyway.

    Also I think if I do

    for Chunk in TDict.Values do Chunk.Free

    it still leaves the keys in, so the size of TDict size is not updated. Might be the size is not updated even if I removed the key as well, since there is some method to it called TrimExcess

    Didn't work much today.

    Fixed one bug, but made no progress on the case of too large VBO size causing full chunks disappear.

    Line of 11x11 size chunks along X axis. If I decrease the count by few they all fill a nice solid line as supposed to. Too many like here, and something gets corrupted. Note the closest artifact, the whole chunk is not missing, only half of it (It is hollow since none of the cubes that should not be visible are not drawn)

    Image2.jpg
    Last edited by Thyandyr; 03-11-2017 at 12:05 PM.

  7. #7
    Why keeping all this in single vbo?
    btw occlusion culling will be possible with this approach?

  8. #8
    Quote Originally Posted by laggyluk View Post
    Why keeping all this in single vbo?
    btw occlusion culling will be possible with this approach?
    I'm learning by doing and just wanted to see what happens and how much can push to one VBO. I will only remember things that I learn if I have first hand experience of the 'why' of things. Seeing something work or fail is essential to me.

    Sure occlusion calculations will be possible, currently I only draw voxel surfaces that have solid-gas interface (assuming atmosphere... should be called transparent-opaque interface I guess. Actually you draw glass and water too, so should be called change-of-light-refraction interface heh heh), plus chunk edges. Occlusion on larger scale will be necessary once I manage to draw more stuff on screen. I have camera and chunk locations (and voxels' too). I don't know how it's normally done but I thought do to the large scale occlusion per-chunk and not per voxel.
    Last edited by Thyandyr; 03-11-2017 at 12:21 PM.

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
  •