SpaceManiac / Spacecraft

Spacecraft is the SpaceManiac Minecraft Server, a C# server for Minecraft (http://minecraft.net) licensed under CC-BY-SA
3 stars 1 forks source link

New Lighting Idea! Should speed up physics #6

Closed AtkinsSJ closed 14 years ago

AtkinsSJ commented 14 years ago

(Implemented)

I have an idea that should massively speed up physics: Separating lighting from regular physics.

Now, to figure out if something is lit, you only need to know the height of the highest opaque block - anything below is in shadow, and anything above is lit. So the map would contain a 2d array of integers, for the height (I think this is Y) coordinate of the highest opaque block in the relevant column.

When a block is placed, a quick check is done: Is it an opaque block? If so: Is it higher than the highest opaque block? If so: Go through the tiles between the two heights, setting them to shaded and reacting as necessary. eg, destroying flowers, setting grass to dirt. Then, set highest to the new value.

When an opaque block is removed, another check: Is it he highest opaque block? If so: Go down through each square, setting it to lit, until you reach an opaque block, reacting as necessary - setting dirt to grass, destroying mushrooms. Then, set highest to the new value.

This way, you no longer need to check through 65000 dirt and grass tiles each physics tick - they only get checked when something changes. :D

What do you guys think?

SpaceManiac commented 14 years ago

It looks mostly pretty good; the only thing I can spot is the loss of randomness in the dirt-to-grass conversion. It's definetly worth a look into.

AtkinsSJ commented 14 years ago

For randomness, you could always add the grass/dirt locations, with random times, to a list of delayed changes. But I'm not that bothered about having random things really. :P

SpaceManiac commented 14 years ago

Implemented, and working excellently.