Project: Unknown Worlds – Dev Report #2

October 27th, 2010 1 comment
Okay so in the last couple of days i actually had to rewrite the whole voxel system over and over again to get a nice result.
So compared to the first one, everything have changed.
But the benefits are great! So what did i do?


1) The noise generator was too slow so i had to find a way to make it faster. I saw a topic on the Unity3D Forum that was talking about minecraft, and when i told them i was working on something simliar, some other people showed their projects as well. So it turned into a big discussion about technics and how to achieve certain things. We figured out to create a fast noise generator for the terrain, we would have to use a second thread. I’ve never done multithreading before but it’s awesome! So now the terrain simplex noise gets calculated in a second thread which results into no FPS drop, epic!


2) “Infinity!”, yes, now the world COULD be infinity, without any FPS drop when generating new chunks. Why only “could” you ask? Well that leads to my first of ToDo point.


ToDo

So right now i have two major things on my ToDo list.

The first thing is the “could” in being infinit. The world can generate as long as it wants to, there won’t be “out of memory” exception for a very very long time (i’ve never calculated the end but it can be as like notch’ minecraft, 8 times bigger than the size of the world).

The only limits that i have now is floating instability and problems with zbuffer. I’ve read that in Unity (maybe that’s some general game/graphics issue) you can go to a distance of 40k until problems with floatings points and zbuffer will start.

To solve this, someone suggested a solution i really love, cause it reminds me of futurama. In futurama there is this episode where they explain how the spaceships travels through space. The result is that not the spaceship is moving through space, but it’s moving the space around the spaceship.

So yes, that will be the solution! The player won’t move at all from it’s position except in height. But when you walk forwards, you actually will move the world backwards so it will always stay around the zero point! Epic.

You just need to consider that in multiplayer and give it a different approach as well. You will have to check if players are in the same offset from the world to display the right objects, players, etc on their client.

The second major thing i am working on is shading. In minecraft you can see how blocks get a different shade depending on how far away they are from a light source. So i tried to implementing that too, it looks awesome, it just takes too long to calculate so far.

When i generate new blocks, they get a standard light value of 0.2 right now, which indicates my shadow blocks (totally darkness looks bad).

You have to consider that the sun always comes from the top, no whatever where it stands, so this makes things a lot easier.

What i do is, first i go through every row starting at the top. I scan down and if i find an empty block, i set it’s light value to 1. I keep going down until i reach a solid block, then i move on to the next one, cause everything below that block doesn’t need sunlight (the sun can’t reach it).

This calculation takes a second for my 16x16x1 chunks world (where each chunk is 16x16x128 voxels big).

The part that takes very long is the illumination. Here i go through every sunblock, and call a recursive method to apply sun which looks like this:

  • Check if that block is empty and it’s light value is smaller than the one i am applying to. If not, go on with the next one.
  • Get latest light value (in this case 1 because it’s a sunlight block)
  • Apply light value to this block
  • Reduce next light value by 20% and check for neighbors
  • If the light value is over 0.2 (darkness), keep going
  • If my neighbor (left, right, top, bottom, back, front) is a empty block, call the same function for this block with the new reduced light value

This will spread the light over and over again until we reach darkness. The result looks like this:

So for the current version, if i spread the light 8 times, it takes about 36 seconds to fill every chunk. This takes way too long and i have to find a way to make it much faster.

Also right now one method goes through every chunk to apply light. I want to implement that to the chunk creation itself so that every chunk only generates light for itself but i dunno if this will cause any problems, we will see.

Okay so that’s for now. I will post again if i have something new.


Greetings,
Captain_Kiyaku

Minecraft & Project: Unknown Worlds – Dev Report #1

October 10th, 2010 3 comments

Hey everybody!

It’s been quite a long time since i’ve updated my blog. So here we go!

Well, i know i will ruin your productivity if i mention this but… have you ever heard about minecraft?

If you haven’t, you HAVE to check it out! You can find it at www.minecraft.net.

So what is minecraft? Well basically you start in an “infinite”, randomly generated world, without anything in your pockets. The goal for the first day is to build a shelter before it turns night. Why? Well, you are not alone! There are “things” that want to harm you and will only come at night or at dark places.

The cool thing about this game is the world itself. It is made out of blocks and you can destroy every block you want. You will need it to create tools, weapons or other type of blocks to build your own awesome structures!

Not enough? Well, then play it with friends in multiplayer!

The current version is still alpha and has a lot of bugs but nevertheless it is so much fun already. And i suggest everyone to buy a copy, it’s 50% off during the alpha phase, so it’s around 10€.

There is also a free version but it doesn’t have the so called “Survival Mode”, you can just build anything you want with an infinite amount of blocks.

If you need some ingame footage first, check out this awesome trailer i’ve found: Awesome Minecraft Fanmade Trailer!


Okay anyway, as game designer i wondered “how the firetruck can i do something like this?”.

Now i didn’t have a lot of time, besides playing LOTS of minecraft, i also have to work on many projects. But when i just got sick a few days ago, i couldn’t resist but opening my NEW AWESOME EPIC UNITY 3 PROFESSIONAL VERSION! (sorry, got a little excited here), and recreate something like minecraft (note how i make it sound easy to include EVERY minecraft feature into “a few weeks of lame work”, yeah i am awesome 8D).

So yeah, my first system sucked. My second system got better the worlds were still too tiny. But then the user “Beezir” from the Unity board showed me his voxel system and it was epic, the worlds seem to be “infinite” so i adopted his code (with his permission of course) and changed it to my needs. And viola, my world is huge infinite now!

(This is a shot from my second system, not the newest one:)


If you are a nerd and want to know how it works in details, keep reading. If not, jump to the “Non technical version”.


Technical Version:

Voxels:

So you want to know how it works in detail? Okay sure, let me try to explain it as good as possible!

If you have such a giant world, you will see a lot of cubes (lets call them voxels) at the same time. Normally it wouldn’t be possible to render so many voxels without using some kind of tricks, cause the drawcalls and polygon count would explode your graphics card.

So the first thing to do it, create each voxels manually. That means, a cube has 6 faces, top, bottom, left, right, front, back. We will create each face per script depending on if we would be able to see it or not.

Lets say you have 2×2 voxels, then the faces between those voxels are not necessary to draw, cause we won’t be able to see them anyway. It sounds like it would be slow to check if there are voxels around us and then create faces, instead of just spawning a pre-made cube. But this will actually decrease the drawcalls and polygons by A LOT, you wouldn’t be able to get this kind of result with cubes.

That’s the basic method to display millions of voxels at the same time without destroying the framerate.


Chunks:

So let’s say we had a grid of 512x512x128 voxels. The levelgenerator would have to loop through each block and check if there are blocks around us, that means it has to check it 6 times per block. How many loops would that be? Well that’s easy to find out, 512x512x128x6 = 20.447.232 loops per frame if the terrain changed. Ouch! That can’t work.

Accessing so many voxels would kill the frame rate, depending on how far you can see. That’s why we will group some voxels into a chunk and let that chunk do the job for it’s own voxels. In my code, a chunk contains 16x16x16 voxels, so that’s 4096 voxels in one group. Now the levelgenerate doesn’t have to go through every voxel and check if it needs to get recreated, now every chunk will do the job for it’s own voxels! That means the levelgenerator now only has a size of 32x32x8 (because 512 / 16 = 32, and for the height its only 128 / 16 = 8) and tell that chunk at this position to regenerate it’s voxels. So that makes 8.192 loops per frame if something changed for the levelgenerator, that’s easy for him, perfect!

The chunk itself needs to loop 16x16x16x6 times now so that’s 24.576 times, still pretty easy. Additional what my system does, if a voxel on the border needs to change, it will tell it’s neighbor chunk to update as well so it will hide holes.

With this technic we decreased the number of loops by a lot!


Noise:

/START GERMAN INSIDER JOKE

“Gewitter? In Noise?” – Indeed!

/END GERMAN INSIDER JOKE

This part is just the current level creator. The code from Beezir used a SimplexNoise generator to generate hills and caves and splits it into 4 different layers that could be used for grass, sand, gravel, stone.

To be honest, i don’t know much about Noise algorithm so i can’t say much about it here, i just wanted to mention that it’s a good “placeholder” level generator for the beginning. Later on we will need a better system that can create better looking landscapes.


Accessing Chunks:

To know where a CHANGED voxel is, we use a simple Dictionary. It looks lie this: Dictionary<IntCoords, int[, ,]>();

IntCoords is just a 3 space vector. It stores the chunks position, while the int[,,] stores the voxels position inside that chunk.

Since there can’t be another chunk with the same coordinates, using it’s position as key is quite cool and fast to access.

Okay i think that’s it for the technical version so far. More infos will follow with new dev reports.


Non Technical Version:

So you just want a short summary of how the system works, in a language you can understand?

Well the world is made out of blocks. Displaying so many blocks at the same time would be too much for the computer. That’s why i do severals things:

  1. Check if we can actually see the cube, if not, don’t show it
  2. Group 16 x 16 x 16 blocks into a big group and hide all groups that we can’t see
  3. Generate the world by using a complicated rocket science algorithm
  4. Only save blocks we changed or added to a big table

Yep i guess you can summarize it like that :)


Future Plans:

I don’t really want to do a minecraft clone, but if i ever going to finish that project, it will include more RPG elements.

You should be able to get EXP from building, crafting, killing, and then level up to get stronger, have bigger inventories, etc.

I was thinking about NPCs who would give you quests or a trader or whatever.

Though i love the crafting system from minecraft, i might using my own system. But i haven’t got any cool idea for it yet.

I also want the graphics to be better, like on the screenshot i’ve posted.

Well that was a long update. I might go through it at a later date to fix some typos and grammar mistakes, but probably not :P


Hope you enjoyed it anyway, and i will try to post a new webplayer version soon!

Greetings,

Captain_Kiyaku

Street Breakers – iPhone Release!

May 11th, 2010 1 comment

Another game i worked on for Oscar Torres. The game is currently (referring to the posts date) getting reviewed by Apple and should be in the App-Store in a few days.

Description from iTunes:

DESCRIPTION
In this concrete jungle we call New York City, there are flashing lights, fast cars, and fascinating people. The youth of the city is full of energy and ready to show off their break dancing skills. All the boroughs are competing against each other in the regional semi final. You will be one of the elect few that will be battling in Manhattan, Bronx, Queens, Brooklyn and Staten Island. In this game, you will choose where you want to battle and who out of the 10 characters you want to be. Earn points by performing dance moves to Hip Hop and House tracks. Be quick and creative with your moves to gain points.
Battle your way to be the Ultimate Street Breaker!

FEATURES

  • Auto Save feature to save current game
  • 10 Levels of Game Play with addicting combo systems to perform dance moves and earn points
  • 10 Characters to choose from (you are not locked to a particular character you can switch after a level has been completed).
  • 5 Locations Representing the Boroughs of New York City
  • 3 Levels of difficulty
  • Plenty of House and Hip-Hop Tracks to keep you grooving


  • Get it on iTunes!

    Greetings,
    Captain_Kiyaku

    Updater – Round 2!

    April 29th, 2010 No comments

    A long time ago, when i worked on my MMOG (Muffin Mafia Online Game), i showed an updater made by Thomas Bang in Delphi.
    Currently i am learning a lot of C# so i somehow wanted to write a Windows “Application” in C#.
    A friend of mine dig out his old 2D MMO made in Torque Game Builder and he always wanted an updater too.

    So this is my chance!

    I opened Visual Studio C# and started working. After a couple of hour sitting with him in the library and working on our stuff, i got a (already nice) updater done!

    So it basically checks a file on my server that contains all files path+name, size and last modified time.

    The updater will compare it to the local files in this order:
    Does the file exist? -if yes-> Are both files the same size? -if yes-> Is the local file newer than the server one? -if yes-> Don’t Download, it’s up to date!

    If anything returns false, it will download the file from the server.

    It works pretty good, it also create paths if they don’t exit.
    The middle part of the updater is a website. It’s located on my server as well so you can always display the newest news.

    That’s it so far!

    Greetings,
    Captain_Kiyaku

    RedNeckToss – iPhone Release!

    April 6th, 2010 No comments

    A game i worked on for Oscar Torres in early 2010.

    Description from iTunes:

    You are the farmer for today!
    The day to day responsibilities of being a hard working farmer has you in need of some R&R (Rest and Relaxation) and so you venture off into your own competitive world of Tossing! You are brothers “Earl” and “Fred” two overworked farmers looking to have some fun and blow off some steam.

    Tossing is the game and you must toss the washer into the box to earn points.
    BUT! Do not miss or you’ll have to give up your turn to the opponent “Fred”!

    You will have some obstacles with your flock of chickens running around doing their own thing and constantly getting in your way so be sure to calculate your toss!

    It seems easy enough at first, then you are consumed with an attitude to annihilate your opponent as the levels get progressively harder and harder.

    Features:
    -10 levels
    -Easy enough to understand and get started right away
    -Addicting game play
    -Playful folk music to get you in touch with your inner farmer
    -Vivid colors and scenery
    -Use the dynamic gauge to see how powerful your toss will be, but don’t overshoot or you will miss your mark.

    Get it on the iTunes Store!

    Greetings,
    Captain_Kiyaku