MCPcopy Create free account
hub / github.com/assaultcube/AC / collide

Function collide

source/src/physics.cpp:213–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211// drop & rise are supplied by the physics below to indicate gravity/push for current mini-timestep
212
213bool collide(physent *d, bool spawn, float drop, float rise)
214{
215 cornersurface = 0;
216 const float fx1 = d->o.x-d->radius; // figure out integer cube rectangle this entity covers in map
217 const float fy1 = d->o.y-d->radius;
218 const float fx2 = d->o.x+d->radius;
219 const float fy2 = d->o.y+d->radius;
220 const int x1 = int(fx1);
221 const int y1 = int(fy1);
222 const int x2 = int(fx2);
223 const int y2 = int(fy2);
224 float hi = 127, lo = -128;
225 const float eyeheight = d->eyeheight;
226 const float playerheight = eyeheight + d->aboveeye;
227 float z1 = d->o.z-eyeheight, z2 = z1 + playerheight;
228 if(d->type != ENT_BOUNCE) z1 += 1.26;
229 const int applyclip = d->type == ENT_BOT || d->type == ENT_PLAYER || (d->type == ENT_BOUNCE && ((bounceent *)d)->plclipped) ? TAGANYCLIP : TAGCLIP;
230
231 for(int y = y1; y<=y2; y++) for(int x = x1; x<=x2; x++) // collide with map
232 {
233 if(OUTBORD(x,y)) return true;
234 sqr *s = S(x,y);
235 bool tagclipped = (s->tag & applyclip) != 0;
236 float ceil = s->ceil;
237 float floor = s->floor;
238 switch(s->type)
239 {
240 case SOLID:
241 return true;
242
243 case CORNER:
244 {
245 sqr *ns, *h = NULL;
246 int bx, by, bs;
247 int q = cornertest(x, y, bx, by, bs, ns, h);
248 bool matter = false, match = false;
249 switch(q) // 0XX3
250 { // XXXX
251 case 0: // 1XX2
252 match = x==x2 && y==y2;
253 matter = fx2-bx+fy2-by>=bs;
254 break;
255 case 1:
256 match = x==x2 && y==y1;
257 matter = fx2-bx>=fy1-by;
258 break;
259 case 2:
260 match = x==x1 && y==y1;
261 matter = fx1-bx+fy1-by<=bs;
262 break;
263 case 3:
264 match = x==x1 && y==y2;
265 matter = fx1-bx<=fy2-by;
266 break;
267 default:
268 return true; // mapper's fault: corner with unsufficient solids: renderer can't handle those anyway: treat as solid
269 }
270 cornersurface = (q & 1) ? 5 : 6;

Callers 7

loopiFunction · 0.85
moveplayerFunction · 0.85
entinmapFunction · 0.85
flagdroppedFunction · 0.85
setvantagepointFunction · 0.85
gotovantagepointFunction · 0.85
spectatemodeFunction · 0.85

Calls 4

cornertestFunction · 0.85
plcollideFunction · 0.85
mmcollideFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected