MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DoTerrainDynamicTable

Function DoTerrainDynamicTable

editor/editor_lighting.cpp:1730–1791  ·  view source on GitHub ↗

Puts a 3d grid of points on the terrain and sets a bit indicating if a light source can reach that point. This is used for the dynamic lighting of objects on the terrain

Source from the content-addressed store, hash-verified

1728// Puts a 3d grid of points on the terrain and sets a bit indicating if a light source
1729// can reach that point. This is used for the dynamic lighting of objects on the terrain
1730void DoTerrainDynamicTable() {
1731 int i, t, k, j, maxrays;
1732 int raynum = 0;
1733 int key;
1734
1735 maxrays = AREA_X * AREA_Z * 8 * Terrain_sky.num_satellites;
1736
1737 mprintf(0, "Calculating dynamic light table for %d points...\n", maxrays);
1738 mprintf(0, "Press tilde key to abort!\n");
1739
1740 memset(Terrain_dynamic_table, 0, (TERRAIN_DEPTH * TERRAIN_WIDTH));
1741
1742 for (i = 0; i < AREA_Z; i++) {
1743 // ddio_KeyFrame();
1744 while ((key = ddio_KeyInKey()) != 0) {
1745 if (key == KEY_LAPOSTRO) {
1746 for (; i < AREA_Z; i++) {
1747 for (t = 0; t < AREA_X; t++) {
1748 int tseg = i * TERRAIN_WIDTH + t;
1749 Terrain_dynamic_table[tseg] = 255;
1750 }
1751 }
1752
1753 return;
1754 }
1755 }
1756
1757 for (t = 0; t < AREA_X; t++) {
1758 int tseg = i * TERRAIN_WIDTH + t;
1759 vector gp;
1760
1761 gp.x = (t * TERRAIN_SIZE);
1762 gp.z = (i * TERRAIN_SIZE);
1763
1764 gp.y = Terrain_seg[tseg].y;
1765
1766 for (k = 0; k < 8; k++) {
1767 vector pos;
1768
1769 pos.x = gp.x;
1770 pos.z = gp.z;
1771 pos.y = k * (MAX_TERRAIN_HEIGHT / 8);
1772
1773 for (j = 0; j < Terrain_sky.num_satellites; j++) {
1774 raynum++;
1775 mprintf_at(2, 4, 0, "Ray=%d ", raynum);
1776
1777 if (gp.y > pos.y)
1778 continue;
1779
1780 int answer;
1781 answer = ShootRayForTerrainLight(&pos, &Terrain_sky.satellite_vectors[j], tseg);
1782 if (!answer)
1783 continue;
1784
1785 Terrain_dynamic_table[tseg] |= (1 << k);
1786 j = Terrain_sky.num_satellites;
1787 }

Callers 2

OnDynamicTerrainMethod · 0.85
DoRadiosityForTerrainFunction · 0.85

Calls 2

ddio_KeyInKeyFunction · 0.85
ShootRayForTerrainLightFunction · 0.85

Tested by

no test coverage detected