A revamp that no one will notice

I decided a few days ago that my "collision library" was poorly written and very limiting. I went on an ardous campaign to rewrite the library so that it performs EXACTLY the same but will allow for easier expansions in the future. My collision system uses a set of bounding volumes (circles, rects, oriented rects) and a huge set of intersection methods that handle them. The system being used was directly from my SGP project where I wrote the collision system into the Animation Engine. This was slowly working against me since the interface for the Bounding Volumes was extremely dirty and used my misinformed version of "double dispatch." The interface was so bad because I was trying to find a way to have the proper intersect method get called between two Bounding Volumes when you don't know what type they are (if a & b are just of base type BV). To solve this, I created an interface where each BV type knew about the other BV types. This worked but created a messy dependency problem and also made it a huge pain in the ass to add a new collision shape (basically keeping me from adding one). This problem also occured with my game objects. Certain objects stored their data differently and would need to perform different kind of collisions. This time to solve this problem, I wanted to avoid the shitty interface issue so I created a "Dispatch Table" that stores a map of function pointers. Each object has to have a unique ID and a unique bit flag that when OR'd with another objects bit flag creates a unique value. Using this data, you can register several functions with the table and make a quick call which will resolved which intersection method to call. This system worked so well that I wanted to do that "look at my shiny new hammer" on my collision library. While this is normally a bad idea, I knew my collision library needed it. So know, even though more tests are needed, I have moved the library out of the Animation engine and removed all the dependices between the Bounding Volumes. Hurray...now no one will notice

No comments: