I started using reference counters for my assets in my application :
 - Images
 - Models
 - ....

Such as :

alias ModelType = RefCounted!Model;

struct Model
{
        static ModelType create(Mesh mesh, Shader shader) {
                ModelType model = ModelType();

                model.mesh = mesh;
                model.shader = shader;

                return model;
        }
}

I worked fine and compiled, but now i also want to keep a reference of the created models :
static ModelType[string] loadedModels;

static ModelType load(string modelName) {
        ModelType model = null;
                
        switch(extensions) {
                case "obj":
                        model = loadObjModel(modelName, shader);
                        break;
                case "dae":
                        model = loadColladaModel(modelName);
                        break;
                default: abort(extensions ~ " not supported model file format");
        }
                
loadedModels[modelName] = model; // This creates a reference, so i need to get rid of it
        model.refCountedStore()._store._count--; // Something like that
        model.modelName = modelName;
        
        return model;
}

So i create load a model, and the reference counter is at one ( normal ). Now i store this model in the associative array but i do not want it to count in the reference count. Unfortunatly _store is private. How can i go about making the reference in the associative array be canceled?

Reply via email to