diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-08 21:09:36 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-09 17:59:13 -0400 |
commit | 5c82f052c26303318e81ddd76475c1d188cc74f4 (patch) | |
tree | 3204ef94f2861224a380aa566728c02b4acd1fd9 /src/systems/pondering.cpp | |
parent | 96e6f3231aed9919d660a06944f1d96dc8241f8e (diff) | |
download | therapy-5c82f052c26303318e81ddd76475c1d188cc74f4.tar.gz therapy-5c82f052c26303318e81ddd76475c1d188cc74f4.tar.bz2 therapy-5c82f052c26303318e81ddd76475c1d188cc74f4.zip |
Simplified positions/sizes with vectors
Positions and sizes are now stored as vectors (of doubles and ints, respectively). This allows for at least minor code simplification in many places, and cleans up the CollisionParams code in PonderingSystem quite a bit.
Diffstat (limited to 'src/systems/pondering.cpp')
-rw-r--r-- | src/systems/pondering.cpp | 294 |
1 files changed, 104 insertions, 190 deletions
diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 7b3ab2d..ec83270 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp | |||
@@ -47,7 +47,7 @@ void PonderingSystem::initializeBody( | |||
47 | 47 | ||
48 | if (type == PonderableComponent::Type::freefalling) | 48 | if (type == PonderableComponent::Type::freefalling) |
49 | { | 49 | { |
50 | ponderable.accelY = NORMAL_GRAVITY; | 50 | ponderable.accel.y() = NORMAL_GRAVITY; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
@@ -56,10 +56,10 @@ void PonderingSystem::initPrototype(id_type prototype) | |||
56 | auto& ponderable = game_.getEntityManager(). | 56 | auto& ponderable = game_.getEntityManager(). |
57 | getComponent<PonderableComponent>(prototype); | 57 | getComponent<PonderableComponent>(prototype); |
58 | 58 | ||
59 | ponderable.velX = 0.0; | 59 | ponderable.vel.x() = 0.0; |
60 | ponderable.velY = 0.0; | 60 | ponderable.vel.y() = 0.0; |
61 | ponderable.accelX = 0.0; | 61 | ponderable.accel.x() = 0.0; |
62 | ponderable.accelY = 0.0; | 62 | ponderable.accel.y() = 0.0; |
63 | ponderable.grounded = false; | 63 | ponderable.grounded = false; |
64 | ponderable.frozen = false; | 64 | ponderable.frozen = false; |
65 | ponderable.collidable = true; | 65 | ponderable.collidable = true; |
@@ -102,19 +102,17 @@ void PonderingSystem::tickBody( | |||
102 | // Accelerate | 102 | // Accelerate |
103 | if (!ponderable.frozen) | 103 | if (!ponderable.frozen) |
104 | { | 104 | { |
105 | ponderable.velX += ponderable.accelX * dt; | 105 | ponderable.vel += ponderable.accel * dt; |
106 | ponderable.velY += ponderable.accelY * dt; | ||
107 | 106 | ||
108 | if ((ponderable.type == PonderableComponent::Type::freefalling) | 107 | if ((ponderable.type == PonderableComponent::Type::freefalling) |
109 | && (ponderable.velY > TERMINAL_VELOCITY)) | 108 | && (ponderable.vel.y() > TERMINAL_VELOCITY)) |
110 | { | 109 | { |
111 | ponderable.velY = TERMINAL_VELOCITY; | 110 | ponderable.vel.y() = TERMINAL_VELOCITY; |
112 | } | 111 | } |
113 | } | 112 | } |
114 | 113 | ||
115 | // Move | 114 | // Move |
116 | double newX = transformable.x; | 115 | vec2d newPos = transformable.pos; |
117 | double newY = transformable.y; | ||
118 | 116 | ||
119 | if (!ponderable.frozen) | 117 | if (!ponderable.frozen) |
120 | { | 118 | { |
@@ -123,19 +121,13 @@ void PonderingSystem::tickBody( | |||
123 | auto& ferryTrans = game_.getEntityManager(). | 121 | auto& ferryTrans = game_.getEntityManager(). |
124 | getComponent<TransformableComponent>(ponderable.ferry); | 122 | getComponent<TransformableComponent>(ponderable.ferry); |
125 | 123 | ||
126 | newX = ferryTrans.x + ponderable.relX; | 124 | newPos = ferryTrans.pos + ponderable.rel; |
127 | newY = ferryTrans.y + ponderable.relY; | ||
128 | } | 125 | } |
129 | 126 | ||
130 | newX += ponderable.velX * dt; | 127 | newPos += ponderable.vel * dt; |
131 | newY += ponderable.velY * dt; | ||
132 | } | 128 | } |
133 | 129 | ||
134 | CollisionResult result = | 130 | CollisionResult result = moveBody(entity, newPos); |
135 | moveBody( | ||
136 | entity, | ||
137 | newX, | ||
138 | newY); | ||
139 | 131 | ||
140 | // Perform cleanup for orientable entites | 132 | // Perform cleanup for orientable entites |
141 | bool groundedChanged = (ponderable.grounded != result.grounded); | 133 | bool groundedChanged = (ponderable.grounded != result.grounded); |
@@ -194,8 +186,7 @@ void PonderingSystem::tickBody( | |||
194 | auto& ferryTrans = game_.getEntityManager(). | 186 | auto& ferryTrans = game_.getEntityManager(). |
195 | getComponent<TransformableComponent>(ponderable.ferry); | 187 | getComponent<TransformableComponent>(ponderable.ferry); |
196 | 188 | ||
197 | ponderable.relX = transformable.x - ferryTrans.x; | 189 | ponderable.rel = transformable.pos - ferryTrans.pos; |
198 | ponderable.relY = transformable.y - ferryTrans.y; | ||
199 | } | 190 | } |
200 | 191 | ||
201 | // Handle ferry passengers | 192 | // Handle ferry passengers |
@@ -212,35 +203,34 @@ void PonderingSystem::tickBody( | |||
212 | // Move to an adjacent map, if necessary | 203 | // Move to an adjacent map, if necessary |
213 | if (result.adjacentlyWarping) | 204 | if (result.adjacentlyWarping) |
214 | { | 205 | { |
215 | double warpX = result.newX; | 206 | vec2d warpPos = result.pos; |
216 | double warpY = result.newY; | ||
217 | 207 | ||
218 | switch (result.adjWarpDir) | 208 | switch (result.adjWarpDir) |
219 | { | 209 | { |
220 | case Direction::left: | 210 | case Direction::left: |
221 | { | 211 | { |
222 | warpX = GAME_WIDTH + WALL_GAP - transformable.w; | 212 | warpPos.x() = GAME_WIDTH + WALL_GAP - transformable.size.w(); |
223 | 213 | ||
224 | break; | 214 | break; |
225 | } | 215 | } |
226 | 216 | ||
227 | case Direction::right: | 217 | case Direction::right: |
228 | { | 218 | { |
229 | warpX = -WALL_GAP; | 219 | warpPos.x() = -WALL_GAP; |
230 | 220 | ||
231 | break; | 221 | break; |
232 | } | 222 | } |
233 | 223 | ||
234 | case Direction::up: | 224 | case Direction::up: |
235 | { | 225 | { |
236 | warpY = MAP_HEIGHT * TILE_HEIGHT - transformable.h; | 226 | warpPos.y() = MAP_HEIGHT * TILE_HEIGHT - transformable.size.h(); |
237 | 227 | ||
238 | break; | 228 | break; |
239 | } | 229 | } |
240 | 230 | ||
241 | case Direction::down: | 231 | case Direction::down: |
242 | { | 232 | { |
243 | warpY = -WALL_GAP; | 233 | warpPos.y() = -WALL_GAP; |
244 | 234 | ||
245 | break; | 235 | break; |
246 | } | 236 | } |
@@ -250,15 +240,13 @@ void PonderingSystem::tickBody( | |||
250 | changeMap( | 240 | changeMap( |
251 | entity, | 241 | entity, |
252 | result.adjWarpMapId, | 242 | result.adjWarpMapId, |
253 | warpX, | 243 | warpPos); |
254 | warpY); | ||
255 | } | 244 | } |
256 | } | 245 | } |
257 | 246 | ||
258 | CollisionResult PonderingSystem::moveBody( | 247 | PonderingSystem::CollisionResult PonderingSystem::moveBody( |
259 | id_type entity, | 248 | id_type entity, |
260 | double x, | 249 | vec2d newPos) |
261 | double y) | ||
262 | { | 250 | { |
263 | auto& ponderable = game_.getEntityManager(). | 251 | auto& ponderable = game_.getEntityManager(). |
264 | getComponent<PonderableComponent>(entity); | 252 | getComponent<PonderableComponent>(entity); |
@@ -266,26 +254,29 @@ CollisionResult PonderingSystem::moveBody( | |||
266 | auto& transformable = game_.getEntityManager(). | 254 | auto& transformable = game_.getEntityManager(). |
267 | getComponent<TransformableComponent>(entity); | 255 | getComponent<TransformableComponent>(entity); |
268 | 256 | ||
269 | const double oldX = transformable.x; | ||
270 | const double oldY = transformable.y; | ||
271 | const double oldRight = oldX + transformable.w; | ||
272 | const double oldBottom = oldY + transformable.h; | ||
273 | |||
274 | CollisionResult result; | 257 | CollisionResult result; |
275 | 258 | ||
276 | if (ponderable.collidable) | 259 | if (ponderable.collidable) |
277 | { | 260 | { |
278 | result = detectCollisions(entity, x, y); | 261 | result = detectCollisions(entity, newPos); |
279 | } else { | 262 | } else { |
280 | result.newX = x; | 263 | result.pos = newPos; |
281 | result.newY = y; | ||
282 | } | 264 | } |
283 | 265 | ||
284 | // Move | 266 | // Move |
285 | if (!ponderable.frozen) | 267 | if (!ponderable.frozen) |
286 | { | 268 | { |
287 | transformable.x = result.newX; | 269 | transformable.pos = result.pos; |
288 | transformable.y = result.newY; | 270 | |
271 | if (result.blockedHoriz) | ||
272 | { | ||
273 | ponderable.vel.x() = 0.0; | ||
274 | } | ||
275 | |||
276 | if (result.blockedVert) | ||
277 | { | ||
278 | ponderable.vel.y() = 0.0; | ||
279 | } | ||
289 | } | 280 | } |
290 | 281 | ||
291 | return result; | 282 | return result; |
@@ -311,21 +302,14 @@ namespace CollisionParams { | |||
311 | return (colliderAxis > entityAxis); | 302 | return (colliderAxis > entityAxis); |
312 | } | 303 | } |
313 | 304 | ||
314 | inline static double OldAxis(const TransformableComponent& transformable) | 305 | inline static double EntityAxis(const vec2d& pos, const vec2i& size) |
315 | { | 306 | { |
316 | return HorizVert::AxisOldLower(transformable); | 307 | return HorizVert::AxisLower(pos); |
317 | } | 308 | } |
318 | 309 | ||
319 | inline static double NewAxis( | 310 | inline static double ObjectAxis(const vec2d& pos, const vec2i& size) |
320 | const CollisionResult& result, | ||
321 | const TransformableComponent&) | ||
322 | { | 311 | { |
323 | return HorizVert::AxisNewLower(result); | 312 | return HorizVert::AxisUpper(pos, size); |
324 | } | ||
325 | |||
326 | inline static double ObjectAxis(const TransformableComponent& transformable) | ||
327 | { | ||
328 | return HorizVert::AxisOldUpper(transformable); | ||
329 | } | 313 | } |
330 | 314 | ||
331 | inline static bool Closer(double left, double right) | 315 | inline static bool Closer(double left, double right) |
@@ -352,21 +336,14 @@ namespace CollisionParams { | |||
352 | return (colliderAxis < entityAxis); | 336 | return (colliderAxis < entityAxis); |
353 | } | 337 | } |
354 | 338 | ||
355 | inline static double OldAxis(const TransformableComponent& transformable) | 339 | inline static double EntityAxis(const vec2d& pos, const vec2i& size) |
356 | { | 340 | { |
357 | return HorizVert::AxisOldUpper(transformable); | 341 | return HorizVert::AxisUpper(pos, size); |
358 | } | 342 | } |
359 | 343 | ||
360 | inline static double NewAxis( | 344 | inline static double ObjectAxis(const vec2d& pos, const vec2i& size) |
361 | const CollisionResult& result, | ||
362 | const TransformableComponent& transformable) | ||
363 | { | 345 | { |
364 | return HorizVert::AxisNewUpper(result, transformable); | 346 | return HorizVert::AxisLower(pos); |
365 | } | ||
366 | |||
367 | inline static double ObjectAxis(const TransformableComponent& transformable) | ||
368 | { | ||
369 | return HorizVert::AxisOldLower(transformable); | ||
370 | } | 347 | } |
371 | 348 | ||
372 | inline static bool Closer(double left, double right) | 349 | inline static bool Closer(double left, double right) |
@@ -375,121 +352,62 @@ namespace CollisionParams { | |||
375 | } | 352 | } |
376 | }; | 353 | }; |
377 | 354 | ||
378 | class Horizontal { | 355 | template <size_t Axis, size_t NonAxis> |
356 | class HorizVert { | ||
379 | public: | 357 | public: |
380 | 358 | ||
381 | inline static double AxisOldLower( | 359 | inline static double AxisLower(const vec2d& pos) |
382 | const TransformableComponent& transformable) | ||
383 | { | 360 | { |
384 | return transformable.x; | 361 | return pos.coords[Axis]; |
385 | } | 362 | } |
386 | 363 | ||
387 | inline static double AxisOldUpper( | 364 | inline static double AxisUpper(const vec2d& pos, const vec2i& size) |
388 | const TransformableComponent& transformable) | ||
389 | { | 365 | { |
390 | return transformable.x + transformable.w; | 366 | return pos.coords[Axis] + size.coords[Axis]; |
391 | } | 367 | } |
392 | 368 | ||
393 | inline static double AxisNewLower(const CollisionResult& result) | 369 | inline static double NonAxisLower(const vec2d& pos) |
394 | { | 370 | { |
395 | return result.newX; | 371 | return pos.coords[NonAxis]; |
396 | } | 372 | } |
397 | 373 | ||
398 | inline static double AxisNewUpper( | 374 | inline static double NonAxisUpper(const vec2d& pos, const vec2i& size) |
399 | const CollisionResult& result, | ||
400 | const TransformableComponent& transformable) | ||
401 | { | 375 | { |
402 | return result.newX + transformable.w; | 376 | return pos.coords[NonAxis] + size.coords[NonAxis]; |
403 | } | 377 | } |
404 | 378 | ||
405 | inline static double NonAxisOldLower( | ||
406 | const TransformableComponent& transformable) | ||
407 | { | ||
408 | return transformable.y; | ||
409 | } | ||
410 | |||
411 | inline static double NonAxisOldUpper( | ||
412 | const TransformableComponent& transformable) | ||
413 | { | ||
414 | return transformable.y + transformable.h; | ||
415 | } | ||
416 | |||
417 | inline static double NonAxisNewLower( | ||
418 | const CollisionResult& result, | ||
419 | const TransformableComponent& transformable) | ||
420 | { | ||
421 | return result.newY; | ||
422 | } | ||
423 | |||
424 | inline static double NonAxisNewUpper( | ||
425 | const CollisionResult& result, | ||
426 | const TransformableComponent& transformable) | ||
427 | { | ||
428 | return result.newY + transformable.h; | ||
429 | } | ||
430 | }; | 379 | }; |
431 | 380 | ||
432 | class Vertical { | 381 | using Horizontal = HorizVert<0, 1>; |
433 | public: | 382 | using Vertical = HorizVert<1, 0>; |
434 | |||
435 | inline static double AxisOldLower( | ||
436 | const TransformableComponent& transformable) | ||
437 | { | ||
438 | return transformable.y; | ||
439 | } | ||
440 | |||
441 | inline static double AxisOldUpper( | ||
442 | const TransformableComponent& transformable) | ||
443 | { | ||
444 | return transformable.y + transformable.h; | ||
445 | } | ||
446 | 383 | ||
447 | inline static double AxisNewLower(const CollisionResult& result) | 384 | template <Direction dir, typename AscDesc> |
448 | { | 385 | class DetectCollisions : public AscDesc { |
449 | return result.newY; | 386 | public: |
450 | } | ||
451 | 387 | ||
452 | inline static double AxisNewUpper( | 388 | static const Direction Dir = dir; |
453 | const CollisionResult& result, | ||
454 | const TransformableComponent& transformable) | ||
455 | { | ||
456 | return result.newY + transformable.h; | ||
457 | } | ||
458 | 389 | ||
459 | inline static double NonAxisOldLower( | 390 | inline static double EntityAxis(const vec2d& pos, const vec2i& size) |
460 | const TransformableComponent& transformable) | ||
461 | { | 391 | { |
462 | return transformable.x; | 392 | return AscDesc::EntityAxis(pos, size); |
463 | } | 393 | } |
464 | 394 | ||
465 | inline static double NonAxisOldUpper( | 395 | inline static double ObjectAxis(const vec2d& pos, const vec2i& size) |
466 | const TransformableComponent& transformable) | ||
467 | { | 396 | { |
468 | return transformable.x + transformable.w; | 397 | return AscDesc::ObjectAxis(pos, size); |
469 | } | 398 | } |
470 | 399 | ||
471 | inline static double NonAxisNewLower( | 400 | inline static double EntityAxis(const TransformableComponent& transformable) |
472 | const CollisionResult& result, | ||
473 | const TransformableComponent& transformable) | ||
474 | { | 401 | { |
475 | return result.newX; | 402 | return AscDesc::EntityAxis(transformable.pos, transformable.size); |
476 | } | 403 | } |
477 | 404 | ||
478 | inline static double NonAxisNewUpper( | 405 | inline static double ObjectAxis(const TransformableComponent& transformable) |
479 | const CollisionResult& result, | ||
480 | const TransformableComponent& transformable) | ||
481 | { | 406 | { |
482 | return result.newX + transformable.w; | 407 | return AscDesc::ObjectAxis(transformable.pos, transformable.size); |
483 | } | 408 | } |
484 | }; | 409 | }; |
485 | 410 | ||
486 | template <Direction dir, typename AscDesc> | ||
487 | class DetectCollisions : public AscDesc { | ||
488 | public: | ||
489 | |||
490 | static const Direction Dir = dir; | ||
491 | }; | ||
492 | |||
493 | class Left : public DetectCollisions<Direction::left, Desc<Horizontal>> { | 411 | class Left : public DetectCollisions<Direction::left, Desc<Horizontal>> { |
494 | public: | 412 | public: |
495 | 413 | ||
@@ -531,23 +449,22 @@ namespace CollisionParams { | |||
531 | }; | 449 | }; |
532 | }; | 450 | }; |
533 | 451 | ||
534 | CollisionResult PonderingSystem::detectCollisions( | 452 | PonderingSystem::CollisionResult PonderingSystem::detectCollisions( |
535 | id_type entity, | 453 | id_type entity, |
536 | double x, | 454 | vec2d newPos) |
537 | double y) | ||
538 | { | 455 | { |
539 | auto& transformable = game_.getEntityManager(). | 456 | auto& transformable = game_.getEntityManager(). |
540 | getComponent<TransformableComponent>(entity); | 457 | getComponent<TransformableComponent>(entity); |
541 | 458 | ||
542 | CollisionResult result; | 459 | CollisionResult result; |
543 | result.newX = x; | 460 | result.pos.x() = newPos.x(); |
544 | result.newY = transformable.y; | 461 | result.pos.y() = transformable.pos.y(); |
545 | 462 | ||
546 | // Find horizontal collisions. | 463 | // Find horizontal collisions. |
547 | if (result.newX < transformable.x) | 464 | if (result.pos.x() < transformable.pos.x()) |
548 | { | 465 | { |
549 | detectCollisionsInDirection<CollisionParams::Left>(entity, result); | 466 | detectCollisionsInDirection<CollisionParams::Left>(entity, result); |
550 | } else if (result.newX > transformable.x) | 467 | } else if (result.pos.x() > transformable.pos.x()) |
551 | { | 468 | { |
552 | detectCollisionsInDirection<CollisionParams::Right>(entity, result); | 469 | detectCollisionsInDirection<CollisionParams::Right>(entity, result); |
553 | } | 470 | } |
@@ -555,13 +472,13 @@ CollisionResult PonderingSystem::detectCollisions( | |||
555 | // Find vertical collisions | 472 | // Find vertical collisions |
556 | if (!result.stopProcessing) | 473 | if (!result.stopProcessing) |
557 | { | 474 | { |
558 | result.newY = y; | 475 | result.pos.y() = newPos.y(); |
559 | result.touchedWall = false; | 476 | result.touchedWall = false; |
560 | 477 | ||
561 | if (result.newY < transformable.y) | 478 | if (result.pos.y() < transformable.pos.y()) |
562 | { | 479 | { |
563 | detectCollisionsInDirection<CollisionParams::Up>(entity, result); | 480 | detectCollisionsInDirection<CollisionParams::Up>(entity, result); |
564 | } else if (result.newY > transformable.y) | 481 | } else if (result.pos.y() > transformable.pos.y()) |
565 | { | 482 | { |
566 | detectCollisionsInDirection<CollisionParams::Down>(entity, result); | 483 | detectCollisionsInDirection<CollisionParams::Down>(entity, result); |
567 | } | 484 | } |
@@ -586,25 +503,25 @@ void PonderingSystem::detectCollisionsInDirection( | |||
586 | getComponent<MappableComponent>(mapEntity); | 503 | getComponent<MappableComponent>(mapEntity); |
587 | 504 | ||
588 | // Get old location. | 505 | // Get old location. |
589 | auto& transformable = game_.getEntityManager(). | 506 | auto& transform = game_.getEntityManager(). |
590 | getComponent<TransformableComponent>(entity); | 507 | getComponent<TransformableComponent>(entity); |
591 | 508 | ||
592 | bool boundaryCollision = false; | 509 | bool boundaryCollision = false; |
593 | 510 | ||
594 | auto boundaries = Param::MapBoundaries(mappable); | 511 | auto boundaries = Param::MapBoundaries(mappable); |
595 | auto it = boundaries.lower_bound(Param::OldAxis(transformable)); | 512 | auto it = boundaries.lower_bound(Param::EntityAxis(transform)); |
596 | 513 | ||
597 | // Find the axis distance of the closest environmental boundary. | 514 | // Find the axis distance of the closest environmental boundary. |
598 | for (; | 515 | for (; |
599 | (it != std::end(boundaries)) && | 516 | (it != std::end(boundaries)) && |
600 | Param::AtLeastInAxisSweep( | 517 | Param::AtLeastInAxisSweep( |
601 | it->first, | 518 | it->first, |
602 | Param::NewAxis(result, transformable)); | 519 | Param::EntityAxis(result.pos, transform.size)); |
603 | it++) | 520 | it++) |
604 | { | 521 | { |
605 | // Check that the boundary is in range for the other axis. | 522 | // Check that the boundary is in range for the other axis. |
606 | if ((Param::NonAxisNewUpper(result, transformable) > it->second.lower) && | 523 | if ((Param::NonAxisUpper(result.pos, transform.size) > it->second.lower) && |
607 | (Param::NonAxisNewLower(result, transformable) < it->second.upper)) | 524 | (Param::NonAxisLower(result.pos) < it->second.upper)) |
608 | { | 525 | { |
609 | // We have a collision! | 526 | // We have a collision! |
610 | boundaryCollision = true; | 527 | boundaryCollision = true; |
@@ -644,16 +561,16 @@ void PonderingSystem::detectCollisionsInDirection( | |||
644 | // Check if the entity would move into the potential collider, | 561 | // Check if the entity would move into the potential collider, |
645 | if (Param::IsPastAxis( | 562 | if (Param::IsPastAxis( |
646 | Param::ObjectAxis(colliderTrans), | 563 | Param::ObjectAxis(colliderTrans), |
647 | Param::NewAxis(result, transformable)) && | 564 | Param::EntityAxis(result.pos, transform.size)) && |
648 | // that it wasn't already colliding, | 565 | // that it wasn't already colliding, |
649 | !Param::IsPastAxis( | 566 | !Param::IsPastAxis( |
650 | Param::ObjectAxis(colliderTrans), | 567 | Param::ObjectAxis(colliderTrans), |
651 | Param::OldAxis(transformable)) && | 568 | Param::EntityAxis(transform)) && |
652 | // that the position on the non-axis is in range, | 569 | // that the position on the non-axis is in range, |
653 | (Param::NonAxisOldUpper(colliderTrans) > | 570 | (Param::NonAxisUpper(colliderTrans.pos, colliderTrans.size) > |
654 | Param::NonAxisNewLower(result, transformable)) && | 571 | Param::NonAxisLower(result.pos)) && |
655 | (Param::NonAxisOldLower(colliderTrans) < | 572 | (Param::NonAxisLower(colliderTrans.pos) < |
656 | Param::NonAxisNewUpper(result, transformable)) && | 573 | Param::NonAxisUpper(result.pos, transform.size)) && |
657 | // and that the collider is not farther away than the environmental | 574 | // and that the collider is not farther away than the environmental |
658 | // boundary. | 575 | // boundary. |
659 | (!boundaryCollision || | 576 | (!boundaryCollision || |
@@ -688,7 +605,7 @@ void PonderingSystem::detectCollisionsInDirection( | |||
688 | // Check if the entity would still move into the potential collider. | 605 | // Check if the entity would still move into the potential collider. |
689 | if (!Param::IsPastAxis( | 606 | if (!Param::IsPastAxis( |
690 | Param::ObjectAxis(colliderTrans), | 607 | Param::ObjectAxis(colliderTrans), |
691 | Param::NewAxis(result, transformable))) | 608 | Param::EntityAxis(result.pos, transform.size))) |
692 | { | 609 | { |
693 | break; | 610 | break; |
694 | } | 611 | } |
@@ -702,8 +619,8 @@ void PonderingSystem::detectCollisionsInDirection( | |||
702 | Param::Dir, | 619 | Param::Dir, |
703 | colliderPonder.colliderType, | 620 | colliderPonder.colliderType, |
704 | Param::ObjectAxis(colliderTrans), | 621 | Param::ObjectAxis(colliderTrans), |
705 | Param::NonAxisOldLower(colliderTrans), | 622 | Param::NonAxisLower(colliderTrans.pos), |
706 | Param::NonAxisOldUpper(colliderTrans), | 623 | Param::NonAxisUpper(colliderTrans.pos, colliderTrans.size), |
707 | result); | 624 | result); |
708 | 625 | ||
709 | if (result.stopProcessing) | 626 | if (result.stopProcessing) |
@@ -724,8 +641,8 @@ void PonderingSystem::detectCollisionsInDirection( | |||
724 | (it->first == boundaryAxis); | 641 | (it->first == boundaryAxis); |
725 | it++) | 642 | it++) |
726 | { | 643 | { |
727 | if ((Param::NonAxisNewUpper(result, transformable) > it->second.lower) && | 644 | if ((Param::NonAxisLower(result.pos) < it->second.upper) && |
728 | (Param::NonAxisNewLower(result, transformable) < it->second.upper)) | 645 | (Param::NonAxisUpper(result.pos, transform.size) > it->second.lower)) |
729 | { | 646 | { |
730 | processCollision( | 647 | processCollision( |
731 | entity, | 648 | entity, |
@@ -756,9 +673,6 @@ void PonderingSystem::processCollision( | |||
756 | double upper, | 673 | double upper, |
757 | CollisionResult& result) | 674 | CollisionResult& result) |
758 | { | 675 | { |
759 | auto& ponderable = game_.getEntityManager(). | ||
760 | getComponent<PonderableComponent>(entity); | ||
761 | |||
762 | auto& transformable = game_.getEntityManager(). | 676 | auto& transformable = game_.getEntityManager(). |
763 | getComponent<TransformableComponent>(entity); | 677 | getComponent<TransformableComponent>(entity); |
764 | 678 | ||
@@ -823,29 +737,29 @@ void PonderingSystem::processCollision( | |||
823 | { | 737 | { |
824 | case Direction::left: | 738 | case Direction::left: |
825 | { | 739 | { |
826 | result.newX = GAME_WIDTH + WALL_GAP - transformable.w; | 740 | result.pos.x() = GAME_WIDTH + WALL_GAP - transformable.size.w(); |
827 | 741 | ||
828 | break; | 742 | break; |
829 | } | 743 | } |
830 | 744 | ||
831 | case Direction::right: | 745 | case Direction::right: |
832 | { | 746 | { |
833 | result.newX = -WALL_GAP; | 747 | result.pos.x() = -WALL_GAP; |
834 | 748 | ||
835 | break; | 749 | break; |
836 | } | 750 | } |
837 | 751 | ||
838 | case Direction::up: | 752 | case Direction::up: |
839 | { | 753 | { |
840 | result.newY = | 754 | result.pos.y() = |
841 | MAP_HEIGHT * TILE_HEIGHT + WALL_GAP - transformable.h; | 755 | MAP_HEIGHT * TILE_HEIGHT + WALL_GAP - transformable.pos.h(); |
842 | 756 | ||
843 | break; | 757 | break; |
844 | } | 758 | } |
845 | 759 | ||
846 | case Direction::down: | 760 | case Direction::down: |
847 | { | 761 | { |
848 | result.newY = -WALL_GAP; | 762 | result.pos.y() = -WALL_GAP; |
849 | 763 | ||
850 | break; | 764 | break; |
851 | } | 765 | } |
@@ -905,33 +819,33 @@ void PonderingSystem::processCollision( | |||
905 | { | 819 | { |
906 | case Direction::left: | 820 | case Direction::left: |
907 | { | 821 | { |
908 | result.newX = axis; | 822 | result.pos.x() = axis; |
909 | ponderable.velX = 0.0; | 823 | result.blockedHoriz = true; |
910 | 824 | ||
911 | break; | 825 | break; |
912 | } | 826 | } |
913 | 827 | ||
914 | case Direction::right: | 828 | case Direction::right: |
915 | { | 829 | { |
916 | result.newX = axis - transformable.w; | 830 | result.pos.x() = axis - transformable.size.w(); |
917 | ponderable.velX = 0.0; | 831 | result.blockedHoriz = true; |
918 | 832 | ||
919 | break; | 833 | break; |
920 | } | 834 | } |
921 | 835 | ||
922 | case Direction::up: | 836 | case Direction::up: |
923 | { | 837 | { |
924 | result.newY = axis; | 838 | result.pos.y() = axis; |
925 | ponderable.velY = 0.0; | 839 | result.blockedVert = true; |
926 | 840 | ||
927 | break; | 841 | break; |
928 | } | 842 | } |
929 | 843 | ||
930 | case Direction::down: | 844 | case Direction::down: |
931 | { | 845 | { |
932 | result.newY = axis - transformable.h; | 846 | result.pos.y() = axis - transformable.size.h(); |
847 | result.blockedVert = true; | ||
933 | result.groundEntity = collider; | 848 | result.groundEntity = collider; |
934 | ponderable.velY = 0.0; | ||
935 | result.grounded = true; | 849 | result.grounded = true; |
936 | 850 | ||
937 | break; | 851 | break; |