Search Unity

After playing minecraft...

Discussion in 'General Discussion' started by jc_lvngstn, Oct 8, 2010.

Thread Status:
Not open for further replies.
  1. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Well, I've spent the last few days (in spare time) rewriting my threading stuff. I had to, because the lighting passes pretty much required me to go from doing lighting per chunk to the entire world at the start of the game. I've just now gotten it working.

    I think I did come up with a generic approach to submitting this to be processed, given a list of things to process (chunks, blocks, etc), the method that actually performs the process, and the number of threads to do the work.

    So, you can say...Process this list of chunks, using the method GenerateTerrainForChunk for each chunk in the list, and split up the work among 20 threads. So far...it appears to be working very well. Now I can move forward.

    So, now I can move forward...time to get the infinite terrain stuff DONE with and move on to more fun stuff.
     
  2. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Here's an updated photo:


    The new changes are looking good. Still a few glitches...but nothing serious. Complex landscapes like this one use a lot of memory. I wouldn't recommend even trying to play it if you didn't have 2+ gigs of ram.

    But, I'm using about 16 shades of light, as opposed to minecraft's 8 or 10...I forget which. So transitions between light and dark areas are a little smoother.

    Sorry I haven't posted the source lately, it's nothing more than I need to get the code in a good place.
     
  3. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,968
    @jc_lvngstn

    your terrains look awesome!!!!
    Maybe you should consider adding slopes? That way it would be not just be a copy of minecraft, it'll be better than minecraft! after all, minecraft is a copy of something else too!
    You're already using cloud pics instead of boxy clouds like in minecraft, so you could go all the way and add slopes, lol

    Your terrains look way more interesting than those in minecraft, even though in minecraft you've got the dirt with grass on top tiles, rather than the full grass tiles. And minecraft got the water flow thing, that allows rivers. You should add rivers as well!

    Minecraft haven't improved as much as it should, I mean... the guy sold like a bizillion of copies, and online is still kind of early beta. You can totally become better than minecraft if you try!
    Add some monsters and sell your game for slightly less than 10 euros, lol
     
  4. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I've been thinking about having slopes instead of blocks, I'm just trying to get the basics of world generation and lighting in before I throw something else in to make it even more crazy :D
    And yeah...having solid grass cubes annoys me also.
    Now...rivers. That's a tricky one. In screenshots like this, I could get a lot of rivers just by raising the water level...but it wouldn't be the same. I might check it out, see how it looks though.
     
  5. xomg

    xomg

    Joined:
    Sep 27, 2010
    Posts:
    330
    That would indeed be crazy, but the "simplest" way would be to run a post-processing pass over the visible cubes after generating and swap them for a more suitably shaped block depending on the surrounding blocks. You'd probably only need a few different blocks and could rotate them to get the desired result. This is Serious Business, but considering you've got over the major hurdle of generating this world in the first place it would be an amazing coup de grâce.

    If you want to be a real bad-ass, generate a mesh from the entire surface of the block terrain and then "relax" and smooth it to produce a monstrous terrain mesh, then split it into chunks. SHOULD BE SIMPLE, RIGHT?
     
  6. maximon

    maximon

    Joined:
    Apr 20, 2008
    Posts:
    14
    terrain is looking very good, love it.

    Btw why has noone mentioned using instances of cubes to optimize this? Are you using instances and if not why not?
     
  7. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Ok, some idle thoughts on rivers:
    I could do like notch and just add some blocks in random locations that spawn water. I could then have a thread dedicated to nothing else but pouring water and letting it flow across the map from various places.

    From what I can tell, in minecraft water has a strength in a block (or amount, whatever). If water can flow straight down, that counts as a full strength block. If it has to flow sideways, however, it diminishes until it either runs out or can fall downward again.. On the surface (pun intended haha), it doesn't sound too terribly complicated.

    So, this would produce minecraftish water.

    It would be awesome if it could produce water that actually filled up areas...like if a waterfall fell into a pit, eventually the pit would fill up and overflow into another area. But this would really only work if the world wasn't infinite. It's just too much dynamic stuff to keep track of as the player explores the world.

    And if the player were to go back and remove the source of water...what, the wold world is somehow going to be updated as the river "dries up"? ugh.

    Seems like it would be very challenging, you would also have to take into account the flow rate of water coming in, vs water coming out. A small opening for water coming in would not have a high flow rate...a huge valley going out would have a much slower flow rate and depth.
    Yeah...it would be awesome to have massive rivers, etc. It just seems like a very big challenge.
     
  8. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    By instances of cubes, do you mean actual cube gameobjects created for each "block"?
    In a 512x512x128 world, there are over 33 million blocks. Unity would probably have a nuclear meltdown if you tried to create 33 million instances of anything.
    Or, did you mean something else?
     
  9. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,968
    ... yeah!! listen to this guy! this is a great idea! relaxing the mesh should be simple enough! ...the relaxed mesh would simply need each vertex position to be an average position of its surrounding vertices.
     
  10. maximon

    maximon

    Joined:
    Apr 20, 2008
    Posts:
    14
    I meant instances, I thought the idea of instance was that you could use it if you want to have lots of the same object on the screen, for example to build up a big forrest or have lots of stones on the terrain. So even if you have 10 000 000 only one drawcall would be done to render them, or perhaps instances in unity dont work like that?
     
  11. xomg

    xomg

    Joined:
    Sep 27, 2010
    Posts:
    330
    You could take a look at how Dwarf Fortress handles water on the wiki pages that discuss it, including how it deals with pressure. It cuts a lot of corners and simplifies things, so that water flowing across diagonals doesn't transfer pressure correctly, etc, but it's a lot of fun to play with either way.

    It sounds suspiciously like Minecraft again, with each tile/cube being able to contain up to 7 levels of water. If there are open tiles around it, the water "flows" into the open tiles and the level in the source tile is reduced. Water sources are infinite, but water won't flow above its source height unless pumping is involved. Many times have I accidentally flooded my fortress while trying to build a cistern or indoor drinking area...

    Again, this is how DF handles fluids and it works "perfectly". You can even pump liquids like magma into a container and then hook up a switch to release the pressure, creating magma cannons or water fountains and such. Great fun.
     
  12. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Honestly, I don't know that much about instancing.
    Would the idea be to identify all possible block configurations...like a dirt block with 4 sides visible...create an instance of that, and anywhere that same block configuration is going to be draw, use the instance instead?
    So if a block can have any combination of sides visible, from none to all 9, that would be mmm...81?
    Then, there's the issue of having different types of blocks, along with some blocks like the dirt ones having grass at the top if they are topsoil.
    Again, I don't know much about instancing, can you give more info on how it would work in my situation?
     
  13. maximon

    maximon

    Joined:
    Apr 20, 2008
    Posts:
    14
    Idea would be to create instance of an object that will look the same and you are not going to change it, new instance can have different position then original. if unitys instancing works the way it should work meaning, if you make 10 000 instances of an object and it does not affect performance or FPS that much then you have a winning situation here, I think you should at least investigate it and see if its possible, it would make it possible to have really long drawing distance if it worked allowing for much more details :)

    btw the noise that you are using, was that simplex or just pure perlin noise. How do you acomplish such overhangs and nice looking terrain?
     
  14. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Wow, that sounds amazing. I'll definitely check out the wiki...to me the biggest question is how to "flow" water into areas off of the map. Thanks!
     
  15. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Last time I looked I believe I was using Perlin, but I can double-check tonight.

    The overhangs are done by having two levels of terrain, one high and one pretty low.
    The high level is created, and BIG caves are created within that. Caves so big they are basically valleys in the world.
    Then, the lower level is created afterwards, with no caves.
     
  16. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,968
    I once made this silly tile isometric game with flowing water. every water tile checked if the tile below had any water and if it was full. If the tile below wasn't full, the water tile from the top passed some water to the tile below, until the tile below is full. Then it checked if there's water on the sides, if there's less water to the sides, it passes water to the tiles until the tiles were even. Now, I don't know anything about optimizing, my game wasn't optimized at all. World was destructible, if you broke a tile, it allowed water to pass through. I used oldschool looking graphics, it was pretty amazing..
    in fact, here's a screenshot for you:
     
  17. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I knew it! Minecraft/Dward Fortress are CLONES of (dozerx's unknown game) :D
    Seriously, though...that's cool. This is my first er second attempt at making a real game. I like your graphics, also. oldschool has become cool, imo.
     
  18. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Looks lovely :D

    I really want to go on with my minecraft too but i have too much work to do at the moment and i've also started my own little "Let's Play Minecraft" serie on youtube.

    When i'm on the bus/skytrain, i always write down all the ideas i have for my game and i've collected so many cool ideas already that i want to realize them, but terrain comes first :/

    So i think what i am doing wrong is only using one thread. You said you use 20 threads @jc?
    How will that run on slower machines, is that still okay? I guess i will try to use more threads too. I once saw in your code that you splitted them among three threads before, and i liked that approach so i will check this out too.

    BTW love your new terrain screens, so unrealistic and epic, really great for a fantasy game and fun to explore. Keep posting and fill the forums cache with awesomeness!
     
  19. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Thanks, Kiyaku.
    What I did was create a class to help me process lists of objects, whether they are chunks, or blocks, or whatever, and you can specify how many threads to do it with. All you do is specify the list of objects, how many threads to use, and what method each thread calls to process a single object.

    Honestly, I'm not sure how many threads will be good for slower machines or single core machines. It will probably be something that users can tweak, it would be very easy to just use a config file with something like

    NumberOfThreadsForTerrainProcessing= 20
    NumberOfThreadsForCreatureAI = 5;

    But, with some testing on various machines, it should be able to figure these out on its own.
    Heh...in fact...you could create a test scene that did nothing but generate terrain for 10 chunks using say...1 thread, and measure how long it takes. It then generates it using 5 threads, measures, 10 threads, etc...until it sees no performance improvement. It could then say "For your machine, the best number of threads to use for world generation is X"

    Crap. So many ideas. So little personal time.
     
  20. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    @xomg...I read up on Dwarf Fortress a little. From what I can tell, the world map has boundaries. Is this true, or is it infinite like Minecraft?
    If it does have boundaries...that makes rivers and such a little more straightforward.
     
  21. Lab013

    Lab013

    Joined:
    Oct 22, 2008
    Posts:
    405
    If all of those threads will be dedicated to the game logic, you want less. More threads than the number of cores means there will be less time for each thread, and since process switching takes a bit of time, it can slow down your game.
     
  22. xomg

    xomg

    Joined:
    Sep 27, 2010
    Posts:
    330
    The world maps it generates aren't infinite, but you can specify the size of them. Each single character in those ASCII maps represents a (huge) playing area that can be entered and explored, and each area is basically a massive 3d array of "cubes" like your game or Minecraft, with about 100 layers in depth and maybe 10 screens or so wide. You can walk between them seamlessly in "adventure" mode, but in the main game mode you're limited to a fixed area with a boundary, from which enemies and traders appear. In this mode, water "flows" off the edge of the map and vanishes, if you were to dig a channel for it that ended there or tried to drain a lake off the edge of the playable area or something. This seems like the easiest way to handle it if your game world has edges.

    You can find videos of the water like this one on Youtube, if you can't figure the game out (and I wouldn't blame you for that). It's not a very video-friendly game, but in this one you can see the water flow and the depth of water is represented by a blue number from 1-7. At 1:20 the player (or actually, a dwarf) opens a floodgate and you can see the water flow through a gap between a river and a large room, and you should be able to make out the water levels fluctuate and transfer in the 420p version of the video. Remember that this is a top-down view, not a cross-section, and the player is not using any graphical tiles so I appreciate how ugly it'll look to most people. The view appears to teleport around because the player is changing bookmarked views on different layers with hotkeys.

    There's a version of DF with a pre-configured graphical tileset here if you did want to mess around with it. Note that I'm not trying to push people into playing the game, just saying that if you want inspiration on how to approach things like this then DF did it years ago and is a lot more open about how things work internally than Minecraft. The concepts and algorithms apply directly to what you and Minecraft are attempting, and are usually detailed somewhere on the wiki or forum.
     
  23. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Quick update: I finally got tired of using Debug.Log() to do debugging on my project. So I did what I should have done all along...use unit tests to test out my code.
    I spent a lot of time on it this weekend, and it's got a much better design (dejavu?). When you create a world, you can specify its chunk dimensions, the block dimensions of each chunk, how many shades of light are used (I think minecraft uses 10), what method to use for terrain generation...it's much better.

    This will make it easy for people to go into config options, and change their world size, amount of lighting, which terrain methods to use (complex landscapes vs simple), all kinds of stuff...on the fly. This will help people with more or less powerful system.

    Also...I was basically doing a pass on the terrain for each shade of light in the system. It worked well..but just wasn't as fast as I would like. It took about 7 seconds for a 512x512x128 'world'.

    Kiyaku, I decided to do a recursive approach instead...and wow. 1.6 seconds, for 16 shades of light! What a difference. I wanted to thank you for the idea to do that.

    So, anyway, after my refactoring...I'm back to the point where I generate a fully lit terrain. I need to put the digging and world movement back in, and I'll be in a good place.
    Also, as far as moving the world around the player...I've decided (for now hah) to simply move the player, and add chunks that are moving into view, and destroy those that are moving out. At whatever range it looks like floating point errors will creep in (like 100k units from the origin), I'll just do a world shift back to the origin for the player, all chunks, etc. It should be so quick nobody will care.
     
    Last edited: Nov 15, 2010
  24. maximon

    maximon

    Joined:
    Apr 20, 2008
    Posts:
    14
    seems like good ideas, keep it up, looking forward a demo soon! :)
     
  25. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Sounds good JC, glad it helped!

    I had no time to continue yet (which makes me kinda sad :/) but the next thing i wanted to do is adding more threads, like you did. I only use one that's why it's so slow for me.

    Don't forget to show new screens if you have anything new :)
     
  26. psyclone

    psyclone

    Joined:
    Nov 17, 2009
    Posts:
    245
    Would love to see the updated code.... I had a bit of a play with the last lot you posted and its fairly easy to follow. Be very interested in seeing the updates youve made.
     
  27. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I'm not through cleaning it up and adding tests, but here it is so far:

    Here's the package:
    http://www.filefactory.com/file/b44b6cd/n/MC2.unitypackage

    And, if you're curious, the nUnit test project:
    http://www.filefactory.com/file/b44b6ch/n/MineClone2Test.zip

    it's using nUnit 2.5.7.

    Target a dark block and press T, and it is -supposed- to replace that block with a sunlit space. Unfortunately, something is wrong with the mesh recreation. If anyone wants to check out the ChunkGameObject and see if something obvious is there, I'd appreciate it.
    This doesn't use the complex landscapes, just a simple one with caves. After I get the core stuff working again, I'll add the complex stuff back. The code is still there, it's just commented out.

    (Edit) Ok...I figured out the mesh generation issue. In World.RegenerateChunks(), comment out this code:


    foreach (Chunk chunk in chunksNeedingRegeneration)
    {
    AddFinishedChunk(chunk);
    }

    The mesh generator already submits finished chunks, so no need to do it again.
    There's still a bug with picking blocks, but removing blocks that aren't fully lit works most of the time.
     
    Last edited: Nov 16, 2010
  28. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
  29. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
  30. psyclone

    psyclone

    Joined:
    Nov 17, 2009
    Posts:
    245
    Very nicely done... I did however manage to find a piece of sky block at the bottom of one of the caves that allowed me to fall out the bottom ;)

    But very nice -- runs at a conformtable 650 fps on my laptop ....

    Yes there is potential in there for something interesting
     
  31. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I've resolved the issue with digging, it works smoothly now. I'm putting a few terrains in for fun, once that's in I'll post some more.
     
  32. madmaxmon

    madmaxmon

    Joined:
    Oct 7, 2010
    Posts:
    19
    Seen this version?

    Source is available via the wiki tab. No idea if it is of any use, but thought I would mention it.

    (p.s. It's another minecraft clone)

    http://manicdigger.sourceforge.net/news/

    Cheers,
    Max
     
  33. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
  34. montgomery

    montgomery

    Joined:
    May 10, 2009
    Posts:
    12
    looks nice.

    interesting corner structure i found :)

     
  35. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Oh, yes...that was a column of blocks I set in the corner, to get a good idea of how deep the ground was beneath my landscape and how high the sky extended above it.
     
  36. psyclone

    psyclone

    Joined:
    Nov 17, 2009
    Posts:
    245
    Web Player seems to work well... was interesting being able to build caves in the water and finding top soil at the bottom of the water.

    Looking really good
     
  37. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    The Great Flood of Jello River just happened yesterday, the grass underneath is still alive ;)

    On a side note...anyone with shader skills who could check out the shader I'm using and suggest changes for it to handle transparency?
     
  38. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Neat! I had to reload the page to get it to run, but otherwise it runs smoothly on my old laptop, and doesn't heat up my laptop like the cpu-bound Minecraft does.
     
  39. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I posted an update to the web version, it's got trees...and also a dumb bug when you dig, but nothing major.

    But, there are issues with random number generation. Tree's aren't placed like they should be, I need to read up on Random.NextDouble(), because it seems real flakey.

    Also...my textures are just bad. I'm still proud of them, I did them myself...but I may end up asking an artist who has submitted minecraft textures if I can use theirs.
    Also...I realize I could get rid of creating the mesh collider for the terrains, and just test for collision based off of the block values. But, this would require creating my own custom character controller, and I'm not ready to dive into that yet. It would save on memory, though.

    Anyway, next up...is probably fixing the digging bug (it currently doesn't light some blocks), and putting back in the stuff for infinite world generation.
     
  40. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Nice caves. Can we bind a key to a toggle-able point light for exploring? :)
     
  41. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Well, you can use the T key to light a cube of air.
    I'd like to have regular, point lighting...but I can't seem to get the shader to work.
     
  42. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Are the trees appearing in bands or other patterns that are not very random-looking? This can often be a problem with simple RNGs when they are used to generate coordinates (see here for further information about this). There is a C# implementation of a better and equally efficient algorithm called xorshift here.
     
  43. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Yes, that was the problem. I did some more research and found a much better algorithm...thanks Andeeee! That was starting to get annoying.
     
  44. ITAmember

    ITAmember

    Joined:
    Feb 13, 2010
    Posts:
    88
    The webplayer is a bit slow at the start, but the generated terrain is worth the wait. :)

    Have you thought about uploaded this project to GitHub or something similar? These kind of games have unlimited potential, an open source community project would progress at a breathtaking rate.
     
  45. Choochoo

    Choochoo

    Joined:
    Nov 24, 2010
    Posts:
    23
    I just found Unity a week ago, and found this thread today, its pretty amazing, I think a nice template for Unity on world generation would be incredible. I have been reading the code and understanding it more, hopefully I can add something in the near future to it. Dynamic games I have always found super fun (civilization series).

    So far what you guys have is amazing the lowest my fps ever got was mid 700's! very nice. Definetly bookmarking this post.
     
  46. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Actually...that's a great idea. I think the best thing for a project like this would be community involvement. I'll look into this.
     
  47. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    What happens is you implement something slightly like marching cubes, but basically where you take a given block, you look at what blocks are around it, and adjust its vertices to produce a smoother surface? ie each block is an irregular quadrilateral? Then slopes become smooth instead of jaggedy?
     
  48. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Yes, and it would probably look nicer also. When I first showed minecraft to my 7 yr old daughter, she loved it, but she only plays on peaceful...she doesn't like the baddies. When I asked here if there was anything else she didn't like about it...she said the blocky ground.

    So, I may look at marching cubes at some point. My biggest concern with it would be memory usage. Mesh data seems to be the biggest memory hog, so much that I'm hesitant to make the terrain any more complex.

    I need to go back and look at the manic digger source. He uses XNA, and I also noticed his memory usage for a map is SMALL...if I remember correctly, about 150 megs as opposed to 500+ for mine. I could drop the collision mesh for the terrain and save some memory, but I'd have to implement a custom character controller/collision and having smooth slopes would make that a little trickier.
     
  49. Choochoo

    Choochoo

    Joined:
    Nov 24, 2010
    Posts:
    23
  50. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
Thread Status:
Not open for further replies.