Drewol / unnamed-sdvx-clone

A game based on K-Shoot MANIA and Sound Voltex
MIT License
782 stars 93 forks source link

Rewrite to proper C++ #54

Open BonusPlay opened 6 years ago

BonusPlay commented 6 years ago

Hey, first of all I really enjoy the game, but I've realized the source code is completely unreadable and the project's architecture is a mess. Some things I'd like to improve on:

I've started doing changes on my fork, you can see most of the changes here. I ask for help as this is a very ambitious plan that will take very long if done by 1 man, but if done correctly it should enable more developers to help at the project. Any help is appreciated, don't be scared, if you want to help and you know C++, just contact me.

Drewol commented 6 years ago

Thank you for this, it's something I've put off doing since I "took over" the project since it's mostly just a lot of tedious work without anything really changing about the game itself. I will unfortunately probably not be able to help a lot with this other than explaining some parts of the code because I'll be rather busy with studying and the work I'll still want to squeeze in is stuff like bug-fixes and smaller features.

nashiora commented 6 years ago

I wanted to do this when I saw the code, but I have no real experience in large C++ projects so I was hoping someone else would like to. Glad to see you've started something!

BonusPlay commented 6 years ago

@nashiora there are many small tasks to do, any and all help is needed.

nashiora commented 6 years ago

@BonusPlay do you have a Discord? A lot of conversation happens on there for us.

BonusPlay commented 6 years ago

@nashiora yes, I also use discord a lot.

nashiora commented 6 years ago

@BonusPlay https://discord.gg/c6wQSG

T045T commented 6 years ago

@BonusPlay I saw you just got to a working build a few hours ago - nice! Do you still need help with this transition?

BonusPlay commented 6 years ago

@T045T Hell yeah. Catch this and hack away!

Hinara commented 5 years ago

Just a question, Is there any reason that USC avoid exception ? Cause I would like to use them to improve code lisibility, but as I look in the code, everything seems to be done to avoid using them.

BonusPlay commented 5 years ago

@Hinara C++ exceptions provide unnecessary overhead which is aspecially undesireable in game dev (since it reduces FPS), due to compiler needing to produce stack unwinding code for exception handling. It is much better idea to use std::expected (which isn't out oficially, but there are ready to go implementations). You can find plenty of talks about exceptions (like this).

Hinara commented 5 years ago

Yeah but some parts like map loading not done directly in a critical part, I know about exception overhead but between a program a bit less efficient, and a program which may crash easily with a raw segfault, which one is the easier to debug ? And it makes hard to deal with some part of the stl, take std::stoi, the only alternative that comes to my mind is atoi, but atoi doesn't report any error if it fails. And currently it's even worse because all you need is if it has failed or not, nothing about which type of error :/

BonusPlay commented 5 years ago

Problem is, that C++ isn't slower in functions that USS exceptions. Using exceptions at all slows your program by ~10%. Most modern games are compiled with -fno-exceptions.

I think it's much easier to debug program, where you can assert if something horrible happens. On my refactors branch I have code like:

auto Mesh::Create() -> optional<unique_ptr<Mesh>>

It is quite obvious, that this function may fail. Moreover, it is clear when it fails, because you cannot proceed without checking if it failed or not.

As per STL it will only throw if you screw up badly. I'm pretty sure, that with -fno-exceptions it will call abort, which is even better (short trace allows for easier debugging).

Hinara commented 5 years ago

Optionnel seems to be a good choice for me :) I think I will use it in my refactor Doesn't no-except prevent the slowing done the code everywhere ?

int a = std::stoi("a")

Is that a code which is screwd up ? Have you any solution of a standard function like stoi which return allow you to get an int but doesn't throw or send a specific integer value as an error ? If one with optional exist I will be happy :)

BonusPlay commented 5 years ago

-fno-exceptions is quite weird. It is applied "per binarny", and you can link normal STL (with exceptions) to tour binary (without exceptions). Worst case scenario it will abort out.

As per stuff like std::stoi... C++ Game Dev never really went along with STL. People would just write their own implementation that suited their needs. I can understand that this might be a bit too much for an open source project, so I would recommend to only use exceptions as a last resort (so we can later replace them easily with something actually usable).

Hinara commented 5 years ago

Sorry I delete my previous comment as it has some strange result which might have happened because of another load on my CPU. So after a few tests I find out that under gnu -fno-exceptions doesn't to have that much performance benefits, however noexcept makes my code faster (benefit is not preserve with -fno-exceptions) Test under g++ (4:7.4.0-1ubuntu2.3)

123jimin commented 4 years ago

Note that purposes of stuffs such as Audio_Impl are not about abstraction itself, but it's a technique called PImpl, which is often used to reduce compilation time during developement.

Whether this is worth keeping is debatable, though.

BonusPlay commented 4 years ago

I'm afraid compile time is the least significant problem this project has. On my fork I started moving everything to interfaces and factory pattern as seen here and here. This cleans up a lot of code and makes it very clear where logic is placed at. Also allows to write new implementations of current interfaces and switching to using them by replacing a single LoC. Since this project doesn't have to follow ABI at all I believe that migrating to factory functions and proper interfaces would improve project tremendously.

Hinara commented 4 years ago

Do you mean first compilation time or differential compilation ? Some modules are not that bad like the audio module, but the core have a lot of functionalities, and modifying one file of it makes effectively recompile the whole project.