TheCherno / Sparky

Cross-Platform High Performance 2D/3D game engine for people like me who like to write code.
Apache License 2.0
1.1k stars 222 forks source link

Improving Readability and Smart Memory Management #36

Open nyanzebra opened 9 years ago

nyanzebra commented 9 years ago

More of an enhancement than an issue...

Sparky/Sparky-core/src/graphics/layers/layer.h

In this file you have a vector of pointers called renderables.

However, it could be called Renderables renderables by a typedef and using unique_ptr.

//std::vector<Renderable2D*> m_Renderables;
typedef std::vector<std::unique_ptr<Renderable2D>> Renderables;
Renderables m_Renderables;
//or even better!
typedef std::map<std::string, std::unique_ptr<Renderable2D>> RenderableMap;
RenderableMap m_RenderableMap;
//now one can access these by name and remove them by name!

This will make it easier to read, and show a good way to handle memory through the use of smart pointers. As standard pointers are dangerous, it is probably better to change the objects that can be changed to unique_ptr as well.