Bullet Physics Integration on Source SDK

Introduction
That was mostly a spare time experiment for me to have some idea about Source SDK's capabilities. The repository can be found on https://github.com/dyanikoglu/source-sdk-bullet-physics
The Story
While browsing through game developement related repositories in Github, I've found someone was able to inject a different physics engine into Source SDK https://github.com/DrChat/Gmod-vphysics. After playing around with the project, I've decided to take over the project, and make further improvements. That was nice opportunity for me to discover Source SDK.
As first step, I had to remove whole Bullet SDK source code from upstream repository, and add Bullet SDK Github repository https://github.com/bulletphysics/bullet3 as a git submodule into my fork. With that way, Bullet SDK related commits will be completely separated from the actual work on Source SDK, and at the same time, I will be able to merge recent changes from upstream Bullet SDK repository easily. Talking about recent changes of Bullet SDK, the upstream repository was using an ancient version of Bullet, so I had to update the version, and fix lots of API change related compile errors in injection code.
As second step, I've tried to get more clean & well defined workflow for building the binaries for Bullet SDK & Source. To achieve a faster build workflow, I've utilized CMake to automate majority of Bullet's building process.
After setting up the new workflow, I've started investigating the existing physics injection source code by debugging, and tried to find bottlenecks on various scenarios. Since the injection is highly experimental, it had lots of under the hood issues as expected.
The biggest problem with existing injection code was the utilization of old multithreaded modules of Bullet. Those modules were deprecated like 4-5 years ago, and was replaced with more powerful and modern techniques later. I've had to rewrite physics environment initialization part of the injection source with those new multithreaded modules: https://github.com/dyanikoglu/source-sdk-bullet-physics/commit/154fff24f15e30ec130f3262a3f191793671d839 & https://github.com/dyanikoglu/source-sdk-bullet-physics/commit/d62c5870792c3e66c4750c63e9b3a4c8b6ed307d
After getting new multithreaded modules working, I've did some stress tests, and discovered some bottlenecks on the injection source code. I've did various commits to increase performance during scenes with lots of physics objects:
Complexity optimization for LedgeToConvex function. Previously was O(n^2), now it's O(nlgn) in worst case thanks to pre-sorting of triangles: https://github.com/dyanikoglu/source-sdk-bullet-physics/commit/1e63ba860b5dd7dcf7f7410e2d88270ffcb07aee
More modern approach for handling CCD (Continuous Collision Detection): https://github.com/dyanikoglu/source-sdk-bullet-physics/commit/7dfa36ac8af5b1ce895d8c90d02ca1acfb36b467
Micro-optimization by reordering collision pair checks with their frequencies: https://github.com/dyanikoglu/source-sdk-bullet-physics/commit/40412f0505b607d9b49f2d063d922503afd25c27
... and other optimizations mostly related with finding optimal configuration parameters of Bullet SDK for Source.
Results
As the final result, I was able to have somewhat stable gameplay with lots of physics bodies flying around, and was able to maintain 200+ FPS most of the time (I was probably jamming during the recording, please ignore the music if it's not your style 🙂):
... and of course, the injection didn't work in some cases, and caused some funny ragdoll physics 🙂 :
At the end, it was an interesting experiment for me to see an ancient game engine running a modern physics SDK, but of course with serious amount of issues.

keo nha cai mình thấy mọi người nói hoài nên cũng ghé thử cho biết, kiểu vào xem giao diện có dễ dùng không thôi. Vừa mở lên là thấy trang nhìn khá sáng sủa, khoảng trắng vừa đủ nên không bị bí hay rối mắt. Mình lướt xuống một chút thì thấy họ chia nội dung theo từng khối rõ ràng, đoạn nào ra đoạn đó nên đọc nhanh vẫn bắt được ý. Cái mình thích là mấy chỗ trình bày dạng bảng cột nhìn gọn, không phải căng mắt dò từng dòng. Thanh menu đặt ngay chỗ dễ thấy nên bấm qua lại cũng nhanh, không cần tìm nhiều. Nói chung cảm giác dùng vài phút là quen…
Bài viết dễ đọc, ví dụ minh họa thực tế nên mình hiểu nhanh hơn, cảm ơn bạn đã chia sẻ. Mình thì hay xem thống kê XSMB mỗi ngày, cần tra lại cho tiện nên tự gom thông tin vào một trang riêng để khỏi phải tìm nhiều nơi. Bạn nào cũng quan tâm dữ liệu cập nhật theo ngày thì ghé xem thử https://graph.org/Soi-Cầu-XSMB-08-02-2
Mình mua vé số chủ yếu cho vui thôi, kiểu có cái để hóng kết quả mỗi ngày chứ không đặt nặng chuyện đổi đời. Trước đây nghe bạn bè bàn về “cầu kèo” này nọ, mình tò mò thử theo dõi, lúc đầu thấy rối rắm nhưng xem dần thì cũng nhận ra vài chỗ hay bị lặp. Có khi mình đọc mấy bài nhận định như https://soicauxsmb.io/phan-tich-xsmb.html rồi tự note lại vài ý, sau đó đem so với kết quả để kiểm tra xem có phải mình đang tự tưởng tượng ra quy luật không. Trúng được chút thì vui thật, nhưng nhiều lần sai bét nên mình luôn tự nhắc đừng tin quá. Nói chung coi dự…