NewayPix / hazard-memory

An experimental SDL2 Game Engine written in C++
MIT License
0 stars 0 forks source link

Improve collision system #21

Open ryukinix opened 3 years ago

ryukinix commented 3 years ago

Currently we have the following Colliders:

All them implement at least the collide method which is used to calculate if two Colliders objects are in the collision state. However that implementation it is obscure, without clear documentation what does and poorly tested.

It is kind weird to use because I need a Collider object wraping the primitive geometric object to use it... which create a weird overhead of primitive geometric copies and worse: I use the internal representation of the collider to render it on screen. I think collision and rendering should be totally decoupled.

The collide operation is not commutative too. If I have two different instances from diferentes classes of Colliders maybe will not work as expected. Suppose I have a ColliderRect called cr and a ColliderCircle called cc. That calls they are not the same:

wesleycsj commented 3 years ago

Yes, i agree too. I think we should make any kind of system some module apart(Since they're are part of systems which normally doesn't fit inherintance for work, only for internal representation). And for this case, make these types part of a Collision/Physics header to be only imported in the game loop main file as something like "#include "Physics.hpp" " // just an example.

rafaelcn commented 3 years ago

I agree.

wesleycsj commented 3 years ago

I think we should remove Colliders/Physics files from the project until we define what gonna do in the project.

ryukinix commented 3 years ago

The step to remove colliders should be the same to add the new ones, otherwise, it will break at least two examples: lerax-square-platform and lerax-breakout. That would be bad.

wesleycsj commented 3 years ago

Then i think, it will be freezed by now until a Collision class be provided with minimal functions.

ryukinix commented 3 years ago

No problem. If you want destroy code, you should provide something better to replace it, otherwise doesn't makes sense to me.

wesleycsj commented 3 years ago

In this case, i would not say destroyed, but instead, rewritten. And be sure it is better to provide the initial structure to do the collision detection and resolution instead of a file with some separated functions to just calculate intersections(which could be made in the gameloop because it is too short).