Saturday, May 23, 2009

Lucky 13 and I Heart DBs

"CREATE INDEX IF NOT EXISTS ..."

I did a lot of optimization on sqlite iteslf using various pragmas, securing it only for single-threaded access and using only pre-prepared statements with bound parameters.  Next, I changed the queries to build the hierarchy using unique keys instead of path strings.  Finally, I created an index for the owner keys that build the hierarchy and the loading time went from 15-20 minutes down to 6-10 seconds.  YEAH!!!!!

I have learned a lot about databases while doing this fix.  Namely, if you're looking for something frequently it should be an integer key and should be indexed.  Also, databases are great but their flexibility and power has to be well managed.


High Noon
Fixed a small problem with dcReference.  Noticed that the swarm spawning density, which implements dcGenericResource directly, didn't implement toString correctly so it wasn't being saved (0 densities everywhere) and compiling caused an infinite loop.  Fixed, and editor works great now.  Going to start on the next list items.   Let's take a look at our beta document.   Says BSOD bug & map tool.  Well, rewriting the map engine is a prereq for the BSOD bug fixes (*crosses fingers*)

1. New Map Renderer, carefully programmed to fix BSOD
2. Get people with BSOD problem to play, if not fixed add testing code for that
3. Vista file-permissions bug, fix installer crappyness, freezing at log-in bug (hopefully fixed by map also)


Thinking on Paper
The map needs to support several distinct features:
  1. Terrain composed of square tiles with different textures in 4 rotated versions
  2. Walls
  3. The ability to black-out sections of the map based on what the user can see (to hide the contents of rooms beyond a wall)
  4. Pits
  5. Second terrain layer for overlays like water, lava, acid and whatnot.
  6. Special effects attached to map
  7. Map triggers.  This is already implemented somewhat, but we need triggers for scripts.
  8. The ability for the server to change elements of the map (?)  Could be useful for switches and such.  This seems like it would be a set of "region flags" that are sent when a new region is entered to describe the state of that region.
  9. Lighting settings so that dungeons are dark, inside it's bright.  Probably a float-variable where -1.0 is always night, 0.0 follows day/night cycle and +1.0 is always day.
Let's see...
region_flag = flag_index > 8 ? 1 : ((flags >> flag_index)&1);
if (region_flag) {
flag_parameters = getParams(region_flag);
switch (flag_parameters.type) {
case SPECIALFX:   specialfx_manager_.createSpecialFX(flag_parameters.specialfx); break;
case SCENERY: scenery_manager_.createScenery(flag_parameters.scenery); break;
case WALL_DOWN: map_manager_.wallDown(flag_parameters.wall_down); break;
case WALL_UP: map_manager_.wallUp(flag_parameters.wall_up); break;
}
}

Yeah that could work!  Up to 8 different triggered effects per 16x16 region, but any number of allowable effect types.

Walls first.  I don't like how a lot of games use a straight LOS algorithm that produces crazy shadows on the map everywhere (ala Diablo).  It's too dark and makes you feel like the game's artificially restricting you.  However, I can't just have monsters waiting in a room while you're standing there on the other side of a partially-open wall looking at them.

I think the solution here is to show all areas of the map that are connected by non-occluding tiles to the one you're occupying, but compute an LOS between actors and only display those that are directly visible to one another.  I can even do a quick/cool "fade in" of the mesh for characters that just came out of a shadow.  This does mean, however, that all solid walls shouldn't be occluding.  This would make characters pop in and out of existence randomly and that doesn't seem reasonable.

So the map needs a new layer for occlusion is the upshot of this.  Layers for now include:
  1. Texture / rotation
  2. Terrain Height (lower than some threshold will color terrain black to indicate a pit)
  3. Fluid Texture (flat plane at -1/4*tile_size depth)
  4. Wall flag, wall height
  5. Occluder (boolean)
  6. Scenery (objects), Animated Meshes (swaying grass?)
  7. Navigability (walk/swim/impassable/prevent teleport/no spells/reduced speed)
And per-region:
  1. Monster swarm spawner
  2. NPCs
  3. Triggers (map teleport, regen HP, scripted event)
  4. Flagged Actions (controllable wall up/down, scenery action ex. open door, special effect)

Ok, let's get started!  This is going to be fun :D

5 comments:

Joe M. said...

The ability to trans through building walls (at least on town buildings) would be nice, as long as you're looking at map code.

Karl said...

Buildings are actually on a completely different map. I can perhaps make the entire inside of a building area teleport you to the other map, though. Either that or just make smaller buildings part of the main map.

Joe M. said...

That last might be best. After all, how many buildings are we going to have for which we want transable wall? Probably only the ones in town (and maybe a hut here and there in the wilderness).

Karl said...

Yes, I suppose that makes sense. It's a shame though because we can't use the building models if I do that. The building has to be made in the map editor and aligned to the ground squares. Also, I have to come up with something for the roof.

Joe M. said...

Yeah, but we don't have to do it for *all* buildings (though it might feel weird to have some in-map and others extra-map).