Jump to content
  • entries
    15
  • comments
    50
  • views
    25,782

Building Worlds


Einlander

3,154 views

 Share

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.

 

blogentry-7960-0-04477000-1410053918_thumb.png

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.

 

 

5tpJJmt.png

What you see isn't exactly what you get.

 

Results so far:

 

 

 

gPNl4C4.jpg

Look at those beautiful rooms.

kK3IPHC.jpg

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)

  • Upvote 5
 Share

2 Comments


Recommended Comments

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.

I'm interested if you find some ways to keep high frame rate.

 

Your rooms will need doors , windows, you will need corridors, stairs, how will you manage that ?

Same for decoration like table, chairs and other decorative assets how will you manage to have the rooms with stuuf in the right place ? table at center, shelves on walls etc ... ?

How many dynamic lights per building or room ? How will they be placed on rooms ?

 

Keep the good work as project seems promising.

Link to comment

The building you see in the images is just a simple convenience store. It has the front store part, A storage/Stock room and the small room is the office. Other buildings will have different looks as long as you build the bsp tree properly. Corridors and hallways are currently just rooms where you simply don't build walls. As for windows and doors, I have yet to get that working. I have to build in a system where it recognizes outer walls and inner walls.

 

If you look closely at the images you will notice that each room has a gap on all sides. This is to allow an outside wall to be created so you can have bricks on the outside and drywall on the inside. doorways would simply be holes in the walls and a door jamb+ door prefab would link the 2 to hide the gaps.

 

So as to not play guessing games with entities, I will have to create yet another subsystem that will place the windows and doors on certain tiles (The buildings are made of tiles), store them in a list and apply them to the internal and external walls. The furniture and other things will follow similar rules, ie: rooms name is "Office", a desk goes in an office, on the desk will be a lamp, etc. I have a system that I created with the walls that will snap the to their cardinal direction (north, south, east, west) without rotation, that can be applied to furniture.

 

The lights are a bit simpler. If I turn off shadows on the directional lights, I go from 20-30 fps up to a solid 60 fps, but turning off shadows isn't ideal. So I have come up with 2 Ideas, when you leave the bounding box of a building, all props inside and maybe the walls will be hidden, All buildings behind the player beyond a certain distance will also be hidden. And to take it further, as the link in this thread shows http://www.leadwerks.com/werkspace/topic/9478-ps4-infamous-game-technical-details/page__hl__infamous , In my game it is not 1 solid world, it is divided into zones. All adjacent zones will be loaded and only displayed when the player is looking in their general direction. When the player moves to a different zone, all zones (x,z) positions get shifted to the old position and the player is warped to the inverse side/side opposite.

 

All this would keep the engine from drawing ridiculous amounts of buildings, and keeps the shadow shading low. Hopefully it will keep the fps at a bearable level. Also I manually enabled my release mode game to run with ATI crossfire (debug runs windowed, and release runs fullscreen 1080p).

 

I had a lot of downtime at work to figure all this and write it down.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...