Building Worlds
Random Bablings About the Project I'm Working On
The Journey Here
Ever since I bought Leadwerks I have been making the same game. It's games objective has morphed many times since. It started out as a stand clone of a survival mode mod for Left 4 Dead 2. The players would be stuck in a secluded area with no way to escape. Zombies would come in waves and the player would be able to fortify their location. As time went on these locations became bigger and bigger. I started to have levels with multiple city blocks where all the houses were enter-able and complete malls with articulated stores. I even have a screenshot on Steam of an apartment complex where each room was open to the player.
Eventually I got to a point where I has a rather large open world level. At this point I decided it would be better to remove the overarching plot about being rescued and make it a game about world discovery. Instead of building it by hand I decided all buildings and locations would be dynamic. This is where all the real work began.
Starting Small
What I'm working on is now a cross between multiple games. I wanted to have the open world of Dayz, the gameplay mechanics of Left 4 Dead 2 with its claustrophobic closeness of a metropolitan city, and the world generation of 7 Days to Die.
BUILD ALL THE THINGS!!!! o/
This was almost my first mistake. I almost started creating the world generator, and building generator at the same time. While at work with the composition book with graphing paper I carry for game ideas I figured out exactly how EVERYTHING interacts in the world. Here I decided I would start and finish the building generator.
BSP Trees
In order to make a building dynamically one would need to tell the computer how to build it. A template of some sort. One that would adapt to the size of the building. I decided the best way to do this is to define the dimensions of a building and section off each room. To do this I decided to use a bsp tree. I am bad at 2 things when it comes to computers, math and linked lists. Guess what, a bsp tree is almost exactly these 2 things. I ether split a room vertically or horizontally, no diagonals as to preserve my sanity. So far you tell the generator the 2d dimensions of the building. Then you tell it what percent of the floor space you want to claim. After you claim it, you name the floor-space. So far I have this accomplished. I can build the floor and set up the walls. Now what I need to do is make it figure out where doors and windows go, aka portals. Another gotcha that will need to be worked around is since the generator uses percentages you cant have a static width hallway, you would need to tell it something like 1% and it would attempt to use the least amount of space unless the building is HUGE.
These nodes wont split themselves!
Editing In the Editor
Not much to say here other than it's hard. It's hard to change something that creates itself.
What you see isn't exactly what you get.
Results so far:
Look at those beautiful rooms.
This time with shadows.
HUGE GOTCHAS
It took me way too long to figure this out. Even though all the prefabs being used are instanced, each building isn't. Even if the building is identical en every way since it's being created and not loaded it's different. Each additional building after a certain number causes a devastating fps drop. I debug my game with vsync on to let me see what people with less capable cards are seeing. This sudden fps drop can cause you to watch the engine redraw the world allowing you to see behind walls.
What I have left:
Basically EVERYTHING.
Player State
Inventotry Managment
Npc Managment
Prop/Entity Management
World State Saving, Streaming, and Moving
World Generation (streets blocks)
Building Generation (building styles, building prop spawning)
Entity view state determination (things behind you are not drawn, things inside buildings aren't drawn)
Useful Links:
http://lua-users.org/wiki/TableSerialization
PHP-like print_r
This has examples of how to print all the contents of a table regardless of how many items it holds nor how deep it is. I used the PHP-like print_r function. If you store all your settings into a table you can use this to print it to a file and then later directly load it.
http://lua-users.org/wiki/CopyTable
DeepCopy
Somtimes you want to lua to treat tables BY VALUE instead of BY REFRENCE so by using deepcopy you can clone a table and not have the original table change when you change the copied table
edit:
http://snippets.luacode.org/?p=snippets/Deep_copy_of_a_Lua_Table_2
Alternate version of deepcopy. The above version seems to choke on super complex tables with functions in them. HEED ITS LISCENCE (MIT/X11)
- 5
2 Comments
Recommended Comments