[C++ -> C] Switching language

  • TheGreatDoge
    7th Jan 2016 Member 0 Permalink

    As you know, TPT is written in C++. I'm more of a C guy for its non-bloated nature. I'm not here to start a war about C/C++ but rather to discuss something.

     

    TPT is using the SDL library. It's a C library, even though it's compatible with C++, like 99% of the C code on Earth. I believe the game would get a major speedup with C, even though it'll be more complex.

     

    I understand that threading in C++ is a piece of cake compared to threading in C, which is a nightmare. But appart from that, by switching the object oriented model for a more... C like approach would probably befinit to the performances.

     

    Of course, I at the time I write this, I'm only compiling the game from the Arch Linux AUR, so I don't know the source code yet.

     

    I know rewriting a game is a nightmare on lots of different levels, but I'd like to have the point of view of some of you on the topic.

     

  • mniip
    7th Jan 2016 Developer 0 Permalink
    It was written in C originally. It has been rewritten in C++ in 2012/2013.

    TheGreatDoge:

    I believe the game would get a major speedup with C

    What makes you think that?

    TheGreatDoge:

    But appart from that, by switching the object oriented model for a more... C like approach would probably befinit to the performances.

    The processing parts of TPT (the simulation) are already very procedural. There's no virtual table lookups, no closures, no RAII, no smart storage.
    Edited 2 times by mniip. Last: 7th Jan 2016
  • jacob1
    7th Jan 2016 Developer 1 Permalink
    Yeah, it wouldn't make sense to switch back to C after we already went to C++. The switch to C++ didn't add very much slowdown (maybe 1-2 fps on an empty screen). The actual particle physics part is still basically C code. It was mostly the interface and similar code that needed to be rewritten into C++, and it is much clearer now (using an event based system instead of each new interface calling sdl_poll). While you could probably still get something like this working in C, I don't see a reason to.

    We don't use many C++ features, so I agree with mniip that we wouldn't see a major speedup by rewriting it back into C. We mostly just use C++ for classes and some other basic features, we don't even use C++11 at all (still use pthreads for threading).
  • Mao_Zedong
    8th Jan 2016 Member 0 Permalink

    @jacob1 (View Post)

    >still use pthreads for threading

    Last I checked, no compilers except GCC even properly support C++11 threads. Did that change?