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-2023 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 {
30namespace asset {
31class AssetManager;
32
33enum class AssetType {
34 NONE,
39 TEXTURE,
44 SHADER,
49 HJSON,
54 TEXT,
58 MODEL,
63 FONT,
68 CUBEMAP,
75 AUDIO,
81 SCRIPT,
82 BINARY
83};
84
85// This will be hell to maintain
86
92inline AssetType FromString(const std::string& name) {
93 if (name == "none") {
94 return AssetType::NONE;
95 } else if (name == "texture") {
96 return AssetType::TEXTURE;
97 } else if (name == "shader") {
98 return AssetType::SHADER;
99 } else if (name == "hjson") {
100 return AssetType::HJSON;
101 } else if (name == "text") {
102 return AssetType::TEXT;
103 } else if (name == "model") {
104 return AssetType::MODEL;
105 } else if (name == "font") {
106 return AssetType::FONT;
107 } else if (name == "cubemap") {
108 return AssetType::CUBEMAP;
109 } else if (name == "directory") {
111 } else if (name == "audio") {
112 return AssetType::AUDIO;
113 } else if (name == "shader_def") {
115 } else if (name == "binary") {
116 return AssetType::BINARY;
117 }
118 return AssetType::NONE;
119}
120
126inline std::string ToString(AssetType type) {
127 switch (type) {
128 default:
129 case AssetType::NONE:
130 return "none";
132 return "texture";
134 return "shader";
135 case AssetType::HJSON:
136 return "hjson";
137 case AssetType::TEXT:
138 return "text";
139 case AssetType::MODEL:
140 return "model";
141 case AssetType::FONT:
142 return "font";
144 return "cubemap";
146 return "directory";
147 case AssetType::AUDIO:
148 return "audio";
150 return "binary";
152 return "shader_def";
153 }
154}
155
159class Asset {
160 public:
161 // Virtual destructor to make class virtual
162 virtual ~Asset() = default;
163 virtual AssetType GetAssetType() = 0;
164 // For lazy initialization or other
165 virtual void PostLoad(AssetManager&) {}
166 std::string path;
167 int accessed = 0;
168};
169} // namespace asset
170} // namespace cqsp
The base class for assets.
Definition: asset.h:159
virtual void PostLoad(AssetManager &)
Definition: asset.h:165
virtual AssetType GetAssetType()=0
std::string path
Definition: asset.h:166
virtual ~Asset()=default
int accessed
Definition: asset.h:167
Definition: assetmanager.h:145
std::string ToString(AssetType type)
Converts asset type to asset type names for display
Definition: asset.h:126
AssetType
Definition: asset.h:33
@ 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:92
@ 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
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:21