Wednesday, July 29, 2009

refactoring is done

For now, that is. I think I've worked out all of the new bugs I introduced and everything seems to be working fine. I feel so compelled to work on things more related to the engine than creating more 'x-com' content, but this is probably a good thing. If you open/close a door that's adjacent to another door, it automatically opens/closes all adjacent doors. Yay for double-wide doors. Units now have a dimension variable, which will later be used for 2*2 sized units... and possibly larger ones.

the LOS algorithm is still only looking at a single dimension and I need to work on this, but I also need how to abstract objects into a sort of 3d shape. Things have a height, but nothing else really. I really need to figure out how I want to do this. Goal: windows that you can see out of.

Also, I'm going to start working on light sources, which will be switchable and vary in different ways. The simplest type of light source would be a diffused light which wouldn't cast shadows, but would diminish as its distance from the source increased. This would only need to be updated if it was switched on/off. Another type of light would be very similar to the LOS that agents use to see, except it would add light to the lighting matrix array. Each time some object in the world were to move, it would have to check with all of these light sources:
am I within your range?: no = done
yes = am I within your field of view: no = done
yes = subtract your light from my current position and the position I'll be moving to,
I move
add light aimed at my old and my new position.

This could still take time if there were a lot of these lights within range, even with only needing to redraw a small portion of their beams, but I think it would open up an interesting level ambiance that isn't normally seen in roguelikes. Also, many light-sources will likely be a combintaion of diffused light that doesn't cast shadows, with another LOS light that does, but the raytracing one will have a shorter range than than the diffused/soft light. The sun would be directional also, but would come from an entire horizontal direction, not a single point. (so, each ray would move directly across the y axis, for example.)

3 comments:

Jotaf said...

As someone who spent waay too much time with his lighting system, I'd recommend you don't go overboard with heights and all. I had to cut down a lot to be able to consider it finished. I only have one kind of light, casting shadows, and no height info whatsoever; and still it was a pain in the ass to code (shadows are cached, which doesn't help). Although sunlight from a direction would probably look cool, at sunset or something.

Windows are easy to implement: tiles that are see-through but not passable. (Unless you allow the player to jump or something.)

I'm not sure if the extra strategic options you gain with implementing height really offset the high cost in terms of complexity.

There's another way to implement height in a cheap but effective way, that we discussed over at RGRD weeks ago. Split the world in two layers: one low and one high. Have a shadow map for each of them, completely independent. Walls block sight in both, bushes and walls with windows block sight in the low layer. Standing operatives are visible in both, but when crouching they're seen only in the low layer.

It's a decent approximation and has the advantage that it can be easily presented to the player with an ASCII display; while a more realistic 3D world would probably be hard to grasp.

abagoforanges said...

Well, adding complex structures to objects will definitely be one of the last things I do, if I do it at all.
Your idea about windows allowing light to pass, but not movement is a good idea.

Height would, if anything, only really allow for, say, ducking behind a brick wall. I highly doubt I'd ever get to a point where I'm defining various parts of the ground to be a few centimeters higher than others and writing code to take advantage of these differences.

Now that it's easy for me to adjust color and such of my tiles, this will allow me to show more things visually. My display engine is capable of 256^3 colors. I think I'll try to do an experimental light tonight.

Jotaf said...

Ah ok, sorry I thought you were really going over the top with height but it's not the case! With all those colors I'm sure the lighting will look completely awesome :)