group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
AssetRegistry.hpp
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <cstdint>
15#include <glm/vec3.hpp>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
21enum class AssetRole : uint8_t
22{
27};
28
31{
32 std::string name;
33 std::string filename;
35 glm::vec3 renderScale{1.0f};
36 glm::vec3 renderTranslation{0.0f};
37 glm::vec3 renderRotationDegrees{0.0f};
38 int32_t modelIndex = -1;
39 bool hasCollision = false;
40};
41
50{
51public:
53 int add(const std::string& name,
54 const std::string& filename = "",
56 glm::vec3 renderScale = glm::vec3{1.0f},
57 glm::vec3 renderTranslation = glm::vec3{0.0f},
58 glm::vec3 renderRotationDegrees = glm::vec3{0.0f})
59 {
60 const int id = static_cast<int>(entries_.size());
61 entries_.push_back({.name = name,
62 .filename = filename,
63 .role = role,
64 .renderScale = renderScale,
65 .renderTranslation = renderTranslation,
66 .renderRotationDegrees = renderRotationDegrees});
67 nameToId_[name] = id;
68 return id;
69 }
70
72 void setModelIndex(int assetId, int32_t modelIndex)
73 {
74 if (assetId >= 0 && assetId < static_cast<int>(entries_.size()))
75 entries_[static_cast<size_t>(assetId)].modelIndex = modelIndex;
76 }
77
79 void setHasCollision(int assetId, bool v = true)
80 {
81 if (assetId >= 0 && assetId < static_cast<int>(entries_.size()))
82 entries_[static_cast<size_t>(assetId)].hasCollision = v;
83 }
84
86 [[nodiscard]] int32_t modelIndex(const std::string& name) const
87 {
88 const auto it = nameToId_.find(name);
89 if (it == nameToId_.end())
90 return -1;
91 return entries_[static_cast<size_t>(it->second)].modelIndex;
92 }
93
95 [[nodiscard]] int32_t modelIndex(int assetId) const
96 {
97 if (assetId < 0 || assetId >= static_cast<int>(entries_.size()))
98 return -1;
99 return entries_[static_cast<size_t>(assetId)].modelIndex;
100 }
101
103 [[nodiscard]] int id(const std::string& name) const
104 {
105 const auto it = nameToId_.find(name);
106 return (it != nameToId_.end()) ? it->second : -1;
107 }
108
110 [[nodiscard]] const AssetEntry& entry(int assetId) const { return entries_[static_cast<size_t>(assetId)]; }
111
113 [[nodiscard]] int count() const { return static_cast<int>(entries_.size()); }
114
116 [[nodiscard]] const std::vector<AssetEntry>& entries() const { return entries_; }
117
118private:
119 std::vector<AssetEntry> entries_;
120 std::unordered_map<std::string, int> nameToId_;
121};
AssetRole
Describes how a registered asset should be used.
Definition AssetRegistry.hpp:22
@ Entity
Dynamic entity model (player, weapon) — drawn via EntityRenderCmd only.
Definition AssetRegistry.hpp:25
@ Map
Static world geometry — rendered in scene pass, has collision.
Definition AssetRegistry.hpp:23
@ Prop
Static placed object — rendered in scene pass, optionally has collision.
Definition AssetRegistry.hpp:24
@ Effect
Procedural effect (glow sphere, beam) — drawn via EntityRenderCmd only.
Definition AssetRegistry.hpp:26
Central asset registry — maps names to renderer model indices.
Definition AssetRegistry.hpp:50
void setHasCollision(int assetId, bool v=true)
Mark an asset as having collision data.
Definition AssetRegistry.hpp:79
std::vector< AssetEntry > entries_
Definition AssetRegistry.hpp:119
std::unordered_map< std::string, int > nameToId_
Definition AssetRegistry.hpp:120
int32_t modelIndex(const std::string &name) const
Look up the renderer model index by asset name. Returns -1 if not found.
Definition AssetRegistry.hpp:86
const AssetEntry & entry(int assetId) const
Get a read-only reference to an entry.
Definition AssetRegistry.hpp:110
int count() const
Number of registered assets.
Definition AssetRegistry.hpp:113
int add(const std::string &name, const std::string &filename="", AssetRole role=AssetRole::Entity, glm::vec3 renderScale=glm::vec3{1.0f}, glm::vec3 renderTranslation=glm::vec3{0.0f}, glm::vec3 renderRotationDegrees=glm::vec3{0.0f})
Register a new asset. Returns its asset ID (index into entries_).
Definition AssetRegistry.hpp:53
void setModelIndex(int assetId, int32_t modelIndex)
Set the renderer model index for a registered asset.
Definition AssetRegistry.hpp:72
int32_t modelIndex(int assetId) const
Look up the renderer model index by asset ID. Returns -1 if out of range.
Definition AssetRegistry.hpp:95
const std::vector< AssetEntry > & entries() const
All entries (for debug UI / logging).
Definition AssetRegistry.hpp:116
int id(const std::string &name) const
Look up asset ID by name. Returns -1 if not found.
Definition AssetRegistry.hpp:103
One entry in the asset registry.
Definition AssetRegistry.hpp:31
glm::vec3 renderScale
Default per-entity render scale for this asset.
Definition AssetRegistry.hpp:35
AssetRole role
Definition AssetRegistry.hpp:34
glm::vec3 renderRotationDegrees
Default per-entity local Euler rotation in degrees.
Definition AssetRegistry.hpp:37
glm::vec3 renderTranslation
Default per-entity local translation for this asset.
Definition AssetRegistry.hpp:36
std::string name
Human-readable name (e.g. "porsche", "wraith", "map1").
Definition AssetRegistry.hpp:32
bool hasCollision
True if collision was generated for this asset.
Definition AssetRegistry.hpp:39
std::string filename
GLB filename relative to assets/ (empty for procedural).
Definition AssetRegistry.hpp:33
int32_t modelIndex
Renderer model index (-1 = not uploaded to GPU yet).
Definition AssetRegistry.hpp:38