Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
asset.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <string>
20
29namespace cqsp::asset {
30class AssetManager;
31
32enum class AssetType {
33 NONE,
38 TEXTURE,
43 SHADER,
48 HJSON,
53 TEXT,
57 MODEL,
62 FONT,
67 CUBEMAP,
74 AUDIO,
80 SCRIPT,
81 BINARY
82};
83
84// This will be hell to maintain
85
91inline AssetType FromString(const std::string& name) {
92 if (name == "none") {
93 return AssetType::NONE;
94 } else if (name == "texture") {
95 return AssetType::TEXTURE;
96 } else if (name == "shader") {
97 return AssetType::SHADER;
98 } else if (name == "hjson") {
99 return AssetType::HJSON;
100 } else if (name == "text") {
101 return AssetType::TEXT;
102 } else if (name == "model") {
103 return AssetType::MODEL;
104 } else if (name == "font") {
105 return AssetType::FONT;
106 } else if (name == "cubemap") {
107 return AssetType::CUBEMAP;
108 } else if (name == "directory") {
110 } else if (name == "audio") {
111 return AssetType::AUDIO;
112 } else if (name == "shader_def") {
114 } else if (name == "binary") {
115 return AssetType::BINARY;
116 }
117 return AssetType::NONE;
118}
119
125inline std::string ToString(AssetType type) {
126 switch (type) {
127 default:
128 case AssetType::NONE:
129 return "none";
131 return "texture";
133 return "shader";
134 case AssetType::HJSON:
135 return "hjson";
136 case AssetType::TEXT:
137 return "text";
138 case AssetType::MODEL:
139 return "model";
140 case AssetType::FONT:
141 return "font";
143 return "cubemap";
145 return "directory";
146 case AssetType::AUDIO:
147 return "audio";
149 return "binary";
151 return "shader_def";
152 }
153}
154
156inline bool AssetIsVisual(AssetType type) {
157 return (type == AssetType::SHADER) || (type == AssetType::MODEL) || (type == AssetType::CUBEMAP) ||
158 (type == AssetType::SHADER_DEFINITION) || (type == AssetType::TEXTURE) || (type == AssetType::FONT) ||
159 (type == AssetType::AUDIO);
160}
161
165class Asset {
166 public:
167 // Virtual destructor to make class virtual
168 virtual ~Asset() = default;
169 virtual AssetType GetAssetType() = 0;
170 // For lazy initialization or other
171 virtual void PostLoad(AssetManager&) {}
172 std::string path;
173 int accessed = 0;
174};
175} // namespace cqsp::asset
The base class for assets.
Definition: asset.h:165
virtual void PostLoad(AssetManager &)
Definition: asset.h:171
virtual AssetType GetAssetType()=0
std::string path
Definition: asset.h:172
virtual ~Asset()=default
int accessed
Definition: asset.h:173
Definition: assetmanager.h:46
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: asset.h:29
std::string ToString(AssetType type)
Converts asset type to asset type names for display
Definition: asset.h:125
AssetType
Definition: asset.h:32
@ SHADER_DEFINITION
shader_def as the type parameter in resource.hjson
@ TEXT
text as the type parameter in resource.hjson
@ HJSON
hjson as the type parameter in resource.hjson
@ AUDIO
audio as the type parameter in resource.hjson
AssetType FromString(const std::string &name)
Converts asset type names to asset types
Definition: asset.h:91
@ FONT
Font prototype.
Definition: assetprototype.h:28
@ NONE
Definition: assetprototype.h:25
@ SHADER
shader prototype
Definition: assetprototype.h:27
@ TEXTURE
texture prototype
Definition: assetprototype.h:26
@ CUBEMAP
cubemap prototype
Definition: assetprototype.h:29
@ MODEL
Model prototype.
Definition: assetprototype.h:30
bool AssetIsVisual(AssetType type)
Checks whether the asset is needed for windowed mode or not.
Definition: asset.h:156