Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not strictly a symptom of bad design. Although you certainly could abstract the types out of the type checking. For the sake of performance and runtime customization, you should almost definitely NOT use RTTI or other direct type checking systems. Implementing your own (much simplified) type checking dynamic allows objects to define collision behavior at an object level rather than a class level and to redefine collision behavior at runtime.</p> <pre><code>//PSEUDO CODE enum CollisionTypes = {HARD_THING, SOFT_THING, EXPLODING_THING}; class FragileThing is a GameObject { public function getCollisionType() { return SOFT_THING; } public function collideWith(GameObject obj) { if (obj.getCollisionType() == SOFT_THING) print "whew..."; else print "OUCH!"; } } class CollisionDispatcher is a PhysXCollisionListener { public function getCollisionFromPhysX(Collision col) { col.left.collideWith(col.right); col.right.collideWith(col.left); } } </code></pre> <p>Another system that I have seen used (in books) is to use an engine wide messaging framework to dispatch collisions with type information embedded into the message. Unrelated types can simply ignore the messages. I have not tried this though. I would also recommend examining your LevelObject class to determine if there isn't some kind of common functionality you can add to it that would sidestep this problem. For instance, if there are very few fundamental types of objects (Red and Green perhaps, or Ethereal, Soft, Hard, Explosive) then you can, instead of conditional statements, encode those types into function calls: <code>function collideWithSomethingHard(LevelObject obj)</code> thus allowing objects to define only the collision behavior they care about. Hope this helps a little.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload