-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Model(raylib::Mesh) constructor to throw an exception #305
base: master
Are you sure you want to change the base?
Conversation
I'm not the biggest fan of Exceptions (for gamedev or resource-loading, I'm using I didn't find anything in raylib cheatsheet for coping the Meshes (like for The problem I see with In my own solution I deleted the ctors: constexpr Model(const Model&) = delete;
Model(Model&& other) noexcept { ...}
constexpr Model& operator=(owner<const ::Model&> model) = delete;
constexpr Model& operator=(owner<::Model&&> model) noexcept { ... } I'm not sure if I should make an move-ctor for TextureUnmanaged GetTexture() {
return TextureUnmanaged{m_data.texture};
}
void SetTexture(owner<const ::Texture&> newTexture) = delete;
void SetTexture(owner<::Texture&&> newTexture) noexcept {
m_data.texture = newTexture;
newTexture = NullTexture;
} You can still get an My approach would be, load the Model and Mesh as correct as possible, all at once: raylib::Model model(raylib::Mesh::Cubicmap(imMap, Vector3{ 1.0f, 1.0f, 1.0f })); raylib::Texture texture;
// load texture
raylib::Model model = [&](){
raylib::Mesh mesh;
raylib::Model model;
// load things and do stuff with texture
// move all possible ownership into model
return model;
}(); create/load texture(s) and model(s) via lamdas and move them into an (managed) assetsMap (or something). |
I'm still try to figure out some things, but by deleting and forbid some (implicit) casting, all my "owning" classes, uses Composition over inheritance, I catch errors at compile time. And all the copy-able basic DataTypes, like But that's just my personal approach, I'm still testing things out and been open for feedback. Catch bugs and errors at compile-time. |
Deleting it all together seems like the best option. Good call. Regarding composition instead of inheritance, I was considering something similar in the beginning of the project as well. But in the end, thought that having the raylib-cpp objects inherit from the structs would keep the underlaying structure more similar to raylib, and still be able to interopt with it similarly. In the end it does get tricky when a raylib object wants to take control of the memory management itself, like this Model/Mesh example. I'd love to keep the simplest solution that remains close to raylib, but provides subtle niceties on top. |
#306 could be an ez first step |
@furudbat What about just throwing an exception with a hint about how to avoid the error?