Cube  Diff

Differences From Artifact [8bad2cc9f5]:

To Artifact [7b61604ca1]:


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80


81
82
83
84
85
86
87
88
89
90

91
92
93
94
95

96
97
98
99
100
101
102
				sy += dy;
				if (SOLID(S(fast_f2nat(sx),
				        fast_f2nat(
				            sy)))) // 90% of time spend in this
				                   // function is on this line
				{
					rdist[i] = (float)(fabs(sx - vx) +
					                   fabs(sy - vy));
					break;
				};
			};
		} 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!

inline float
ca(float x, float y)
{
	return x > y ? y / x : 2 - x / y;
};

inline float
ma(float x, float y)
{
	return x == 0 ? (y > 0 ? 2 : -2) : y / x;
};


int
isoccluded(float vx, float vy, float cx, float cy,
    float csize) // v = viewer, c = cube to test
{
	if (!ocull)
		return 0;







|






<
<
>
>









<
>




<
>







65
66
67
68
69
70
71
72
73
74
75
76
77
78


79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94

95
96
97
98
99
100
101
102
				sy += dy;
				if (SOLID(S(fast_f2nat(sx),
				        fast_f2nat(
				            sy)))) // 90% of time spend in this
				                   // function is on this line
				{
					rdist[i] = (float)(fabs(sx - vx) +
					    fabs(sy - vy));
					break;
				};
			};
		} 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!

inline float
ca(float x, float y)
{
	return x > y ? y / x : 2 - x / y;

}
inline float
ma(float x, float y)
{
	return x == 0 ? (y > 0 ? 2 : -2) : y / x;

}

int
isoccluded(float vx, float vy, float cx, float cy,
    float csize) // v = viewer, c = cube to test
{
	if (!ocull)
		return 0;
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

			}; // E
		} else {
			h = ca(cx + csize - vx, cy - vy);
			l = ca(cx - vx, cy + csize - vy);
		}; // 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
	};

	return 1; // cube is entirely occluded
};








|












<
>
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
			}; // E
		} else {
			h = ca(cx + csize - vx, cy - vy);
			l = ca(cx - vx, cy + csize - vy);
		}; // 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
	};

	return 1; // cube is entirely occluded

}