Open soryy708 opened 10 years ago
Looks good. Call it sdl context or something and make a PR
Although, no need to use instance counts. prefer a shared_ptr or something for thread safety and such.
I'll make a PR once I'm able to compile. atm I'm kinda blocked by Issue 1.
Actually, on second thought, I'm not convinced that any change is necessary. It's very C-ish yes, but subsystem it represents is still a C subsystem at the end of the day. Semantically, I don't know what it should mean to init SDL multiple times or what the object holding a count to the handler would represent.
Can you give me a use case for why you'd want anything other than a very simple init at the beginning and quit at the end?
Consider putting an sdl::Handle in a class that uses something that requires SDL to be initialized. Well, in the C way, you'd have to SDL_Init beforehand. However, with sdl::Handle you can just put that in the class and be done with it, not worrying about whether stuff is already initialized or not yet. This would make things easier in big projects, projects with multiple contributors, and bad programmers. Overall, would make your API a lot more powerful without any cost. Why not?
The way it is at the moment, you have to do an
sdl::Init();
in the beginning of your program.atexit(Quit)
makes it so that you don't have to quit when the program terminates.However,
Consider making a handle class to init and deinit using RAII.
So if for some reason SDL's lifetime is bound to some class in someone's game, they can do that elegantly.