58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <Delegate/Delegate.h>
|
|
#include <glm/glm.hpp>
|
|
|
|
class ModelManager
|
|
{
|
|
public:
|
|
struct Voxel
|
|
{
|
|
glm::vec3 loc, color;
|
|
int mass;
|
|
};
|
|
class StaticModel
|
|
{
|
|
std::string name_;
|
|
std::vector<Voxel> voxels_;
|
|
glm::vec3 mass_center_;
|
|
public:
|
|
Delegate<const std::string&> OnDestroy;
|
|
|
|
StaticModel(const std::vector<Voxel>& voxels, std::string name);
|
|
~StaticModel();
|
|
|
|
const std::vector<Voxel>& GetVoxels() const { return voxels_; }
|
|
glm::vec3 GetMassCenter() const { return mass_center_; }
|
|
const std::string& GetName() const { return name_; }
|
|
};
|
|
|
|
struct owner_counter
|
|
{
|
|
std::atomic_ullong counter;
|
|
StaticModel* model;
|
|
|
|
owner_counter() = default;
|
|
owner_counter(const owner_counter& other);
|
|
};
|
|
|
|
private:
|
|
|
|
std::unordered_map<unsigned int, owner_counter> models;
|
|
|
|
static unsigned int FNV1aHash (const char *buf);
|
|
|
|
void OnDestroySometimeModelCaller(const std::string& name);
|
|
|
|
public:
|
|
Delegate<std::string> OnDestroySometimeModel;
|
|
Delegate<StaticModel*> OnLoadSometimeModel;
|
|
|
|
~ModelManager();
|
|
|
|
StaticModel* LoadModel(const std::string& name);
|
|
void FreeModel(const std::string& name);
|
|
}; |