Cube  Diff

Differences From Artifact [7b61604ca1]:

To Artifact [fabee6f557]:


53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69


70

71
72
73
74
75
76



77
78
79
80
81
82
83
84
85
53
54
55
56
57
58
59

60
61
62
63
64
65




66
67

68
69
70
71



72
73
74
75

76
77
78
79
80
81
82







-
+





-
-
-
-
+
+
-
+



-
-
-
+
+
+

-







				dy = -(ray - 4);
			} else if (ray >= 5 && ray < 7) {
				dx = ray - 6;
				dy = -1;
			} else {
				dx = 1;
				dy = ray > 4 ? ray - 8 : ray;
			};
			}
			float sx = vx;
			float sy = vy;
			for (;;) {
				sx += dx;
				sy += dy;
				if (SOLID(S(fast_f2nat(sx),
				        fast_f2nat(
				            sy)))) // 90% of time spend in this
				                   // function is on this line
				// 90% of time spend in this function is on this
				// line
				{
				if (SOLID(S(fast_f2nat(sx), fast_f2nat(sy)))) {
					rdist[i] = (float)(fabs(sx - vx) +
					    fabs(sy - vy));
					break;
				};
			};
		} else {
				}
			}
		} else
			rdist[i] = 2;
		};
	}
}

// test occlusion for a cube... one of the most computationally expensive
// functions in the engine as its done for every cube and entity, but its effect
// is more than worth it!

148
149
150
151
152
153
154
155
156


157
158
159
160
161
162
163
164
165
166
167
168
169
170

171

172
173
174
175
176
177
178
179
180
181
182
183

184
185
186
187

188

189
190
191
192
193
194
195
196
197
198
199



200

201
202
203
145
146
147
148
149
150
151


152
153

154
155
156
157
158
159
160
161
162
163
164
165

166

167
168
169
170
171
172
173
174
175
176
177
178

179
180
181
182

183

184
185
186
187
188
189
190
191
192



193
194
195

196
197
198
199







-
-
+
+
-












-
+
-
+











-
+



-
+
-
+








-
-
-
+
+
+
-
+



					    4;
					l = ma(-(cx + csize - vx), -(cy - vy)) +
					    4;
				} // D
			} else {
				h = ca(cy + csize - vy, -(cx + csize - vx)) + 2;
				l = ca(cy - vy, -(cx - vx)) + 2;
			}; // F
		} else // BG
			} // F
		} else { // BG
		{
			if (cy <= vy) {
				if (cy + csize < vy) {
					h = ma(-(cy + csize - vy), cx - vx) + 6;
					l = ma(-(cy + csize - vy),
					        cx + csize - vx) +
					    6;
				} // B
				else
					return 0;
			} else {
				h = ma(cy - vy, -(cx + csize - vx)) + 2;
				l = ma(cy - vy, -(cx - vx)) + 2;
			}; // G
			} // G
		};
		}
	} else // CEH
	{
		if (cy <= vy) // CE
		{
			if (cy + csize < vy) {
				h = ca(-(cy - vy), cx - vx) + 6;
				l = ca(-(cy + csize - vy), cx + csize - vx) + 6;
			} // C
			else {
				h = ma(cx - vx, cy - vy);
				l = ma(cx - vx, cy + csize - vy);
			}; // E
			} // E
		} else {
			h = ca(cx + csize - vx, cy - vy);
			l = ca(cx - vx, cy + csize - vy);
		}; // H
		} // H
	};
	}
	int si = fast_f2nat(h * (NUMRAYS / 8)) +
	    NUMRAYS; // get indexes into occlusion map from angles
	int ei = fast_f2nat(l * (NUMRAYS / 8)) + NUMRAYS + 1;
	if (ei <= si)
		ei += NUMRAYS;

	for (int i = si; i <= ei; i++) {
		if (dist < rdist[i & (NUMRAYS - 1)])
			return 0; // if any value in this segment of the
			          // occlusion map is further away then cube is
			          // not occluded
			// if any value in this segment of the occlusion map is
			// further away then cube is not occluded
			return 0;
	};
	}

	return 1; // cube is entirely occluded
}