Skip to content

Commit 3c96562

Browse files
authored
Merge pull request #68 from CapsCollective/feature/gltf-support
Added support for scene-based imports via custom static mesh format
2 parents 5fcd30e + fbd3167 commit 3c96562

File tree

123 files changed

+1563
-4073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+1563
-4073
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@
4646
[submodule "vendor/vulkan/Vulkan-Utility-Libraries"]
4747
path = vendor/vulkan/Vulkan-Utility-Libraries
4848
url = https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
49+
[submodule "vendor/assimp"]
50+
path = vendor/assimp
51+
url = https://github.com/assimp/assimp.git

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ clean:
121121
$(RM) $(call platformpth,$(outputDir))
122122
$(RM) $(call platformpth,$(buildFlagsFile))
123123

124+
clean-deps:
125+
git submodule foreach --recursive git clean -xfd
126+
git submodule foreach --recursive git reset --hard
127+
$(RM) $(call platformpth,$(vendorDir)/include)
128+
$(RM) $(call platformpth,$(vendorDir)/vulkan/include)
129+
$(RM) $(call platformpth,$(vendorDir)/vulkan/lib)
130+
131+
clean-all: clean clean-deps
132+
124133
# Check file formatting program across all source files
125134
format-check:
126135
$(formatScript) "$(engineDir) $(examplesDir) $(testsDir) $(packerDir)" --check

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ You can see examples of this in any of the application targets under `examples`.
158158
├─[engine]
159159
│ ├─[core] <- the engine's core library
160160
│ ├─[render] <- the engine's renderer
161+
| ├─[resources] <- the engine's resource types and loading system
161162
│ ├─[window] <- the engine's windowing and input library
162163
│ ├─[utils] <- the engine's utils library
163164
164165
├─[examples]
165166
│ ├─[game] <- an example app utilising all of the engine's libraries
166-
│ ├─[render] <- an example app demonstrating the renderer
167+
│ ├─[render] <- an example app demonstrating the renderer for 3D
168+
| ├─[tilemap] <- an example app demonstrating the renderer for a tilemap
167169
168170
├─[make] <- additional Make file utilities for the build system
169171
├─[packer] <- an asset packing app for bundling game assets in a pack file on build

engine/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include $(makeDir)/Functions.mk
99
include $(makeDir)/Platform.mk
1010

1111
# Set source build vars
12-
coreSrcDir := .
12+
coreSrcDir := ./
1313
coreBinDir := $(binDir)/engine/core
1414
coreSources := $(call rwildcard,$(coreSrcDir)/,*.cpp)
1515
coreObjects := $(call findobjs,$(coreSrcDir),$(coreBinDir),$(coreSources))

engine/core/entity/Entity.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616

1717
namespace Siege
1818
{
19-
// Static member initialisation
20-
const String Entity::ENTITY_NAME("Entity");
21-
22-
Entity::Entity(const String& name, const Xform& transform, int zIndex) :
19+
Entity::Entity(Token type, const Xform& transform, int zIndex) :
2320
transform(transform),
24-
name(name),
21+
type(type),
2522
index(GenerationalIndex()),
2623
zIndex(zIndex)
2724
{}
@@ -42,9 +39,9 @@ void Entity::QueueFree()
4239
EntitySystem::QueueFree(this);
4340
}
4441

45-
const String& Entity::GetName() const
42+
Token Entity::GetType() const
4643
{
47-
return name;
44+
return type;
4845
}
4946

5047
const GenerationalIndex& Entity::GetIndex() const

engine/core/entity/Entity.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
#define SIEGE_ENGINE_ENTITY_H
1212

1313
#include <utils/String.h>
14+
#include <utils/Token.h>
1415
#include <utils/math/Maths.h>
1516
#include <utils/math/Xform.h>
1617

1718
#include "EntityPtr.h"
1819
#include "IndexAllocator.h"
1920

21+
REGISTER_TOKEN(Entity);
22+
2023
namespace Siege
2124
{
2225
/**
@@ -26,36 +29,30 @@ class Entity
2629
{
2730
public:
2831

29-
// Public constants
30-
31-
static const String ENTITY_NAME;
32-
3332
// 'Structors
3433

3534
/**
3635
* Zero-param constructor for Entity, initialises both
37-
* position and rotation to zero, and name to "Entity"
36+
* position and rotation to zero, and type to Entity
3837
*/
39-
Entity() : Entity(ENTITY_NAME) {};
38+
Entity() : Entity(TOKEN_Entity) {};
4039

4140
/**
4241
* Single-param constructor for Entity that simply defines
4342
* a custom name for the Entity
44-
* @param name - a const reference to the name of the
45-
* entity as a string
43+
* @param type - a token for the entity to use as its type
4644
*/
47-
Entity(const String& name) : Entity(name, {Vec3::Zero(), 0.f}) {};
45+
Entity(Token type) : Entity(type, {Vec3::Zero(), 0.f}) {};
4846

4947
/**
5048
* Delegate constructor for Entity, initialises
5149
* generational index to zero
52-
* @param name - a const reference to the name of the
53-
* entity as a string
50+
* @param type - a token for the entity to use as its type
5451
* @param transform - the initial transition of the entity
5552
* @param zIndex - the initial z-index of the entity,
5653
* defaults to zero
5754
*/
58-
Entity(const String& name, const Xform& transform, int zIndex = 0);
55+
Entity(Token type, const Xform& transform, int zIndex = 0);
5956

6057
/**
6158
* Default virtual destructor for Entity
@@ -121,11 +118,10 @@ class Entity
121118
// Public getters
122119

123120
/**
124-
* Getter method for the entity's vanity name
125-
* @return a constant reference to the entity's name
126-
* as a string
121+
* Getter method for the entity's type
122+
* @return a token for the entity's type
127123
*/
128-
const String& GetName() const;
124+
Token GetType() const;
129125

130126
/**
131127
* Getter method for the entity's generational index
@@ -234,9 +230,9 @@ class Entity
234230
// Private fields
235231

236232
/**
237-
* The name of the entity type
233+
* The type of the entity type
238234
*/
239-
const String& name;
235+
Token type;
240236

241237
/**
242238
* The generational index of the entity

engine/core/entity/EntitySystem.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ void EntitySystem::QueueFree(Entity* entity)
7272
EntitySystem* system = FindInGlobalRegister(entity);
7373
if (system)
7474
{
75-
CC_LOG_INFO("Freeing {} at ({})", entity->GetName(), entity->GetIndex().ToString());
75+
CC_LOG_INFO("Freeing {} at ({})", entity->GetType(), entity->GetIndex().ToString());
7676
system->AddToFreeQueue(entity);
7777
}
7878
else
7979
{
8080
CC_LOG_WARNING("Could not find storage for {} at {}",
81-
entity->GetName(),
81+
entity->GetType(),
8282
entity->GetIndex().ToString());
8383
}
8484
}
@@ -90,7 +90,7 @@ void EntitySystem::Resort(Entity* entity, int oldZIdx)
9090
else
9191
{
9292
CC_LOG_WARNING("Could not find storage for {} at {}",
93-
entity->GetName(),
93+
entity->GetType(),
9494
entity->GetIndex().ToString());
9595
}
9696
}
@@ -141,7 +141,7 @@ void EntitySystem::RegisterEntities()
141141
// If the entity's given index already exists then override the existing entry
142142
if (entity->GetIndex().index < entities.size()) entities[entity->GetIndex().index] = entity;
143143
else entities.push_back(entity);
144-
CC_LOG_INFO("Registered {} at ({})", entity->GetName(), entity->GetIndex().ToString());
144+
CC_LOG_INFO("Registered {} at ({})", entity->GetType(), entity->GetIndex().ToString());
145145

146146
packedEntities.push_back(entity);
147147
AddToGlobalRegister(entity, this);

engine/core/scene/SceneFile.cpp

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@
1212
#include <resources/PackFile.h>
1313
#include <resources/ResourceSystem.h>
1414
#include <resources/SceneData.h>
15-
#include <utils/FileSystem.h>
1615
#include <utils/Logging.h>
1716

1817
#include <algorithm>
1918

2019
#include "SceneSystem.h"
21-
#include "resources/GenericFileData.h"
20+
21+
REGISTER_TOKEN(TYPE);
22+
REGISTER_TOKEN(ROTATION);
23+
REGISTER_TOKEN(Z_INDEX);
24+
REGISTER_TOKEN(POSITION);
2225

2326
namespace Siege
2427
{
25-
void SceneFile::RegisterSerialisable(const String& name,
28+
void SceneFile::RegisterSerialisable(Token type,
2629
const Serialiser& serialise,
2730
const Deserialiser& deserialise)
2831
{
29-
GetSerialisables().emplace(name, std::make_pair(serialise, deserialise));
32+
GetSerialisables().emplace(type, std::make_pair(serialise, deserialise));
3033
}
3134

3235
bool SceneFile::Serialise(const std::vector<Entity*>& entities)
@@ -65,14 +68,14 @@ bool SceneFile::SerialiseToString(Entity* entity, String& fileData)
6568
auto& serialisables = GetSerialisables();
6669

6770
// Only serialise entities that register a serialisable interface
68-
auto it = serialisables.find(entity->GetName());
71+
auto it = serialisables.find(entity->GetType());
6972
if (it == serialisables.end()) return false;
7073

7174
// Serialise the general entity information
72-
fileData += (entity->GetName() + LINE_SEP);
73-
fileData += DefineField("POSITION", ToString(entity->GetPosition()));
74-
fileData += DefineField("ROTATION", String::FromFloat(entity->GetRotation().y));
75-
fileData += DefineField("Z-INDEX", String::FromInt(entity->GetZIndex()));
75+
fileData += DefineField(TOKEN_TYPE, entity->GetType().GetId());
76+
fileData += DefineField(TOKEN_POSITION, ToString(entity->GetPosition()));
77+
fileData += DefineField(TOKEN_ROTATION, String::FromFloat(entity->GetRotation().y));
78+
fileData += DefineField(TOKEN_Z_INDEX, String::FromInt(entity->GetZIndex()));
7679

7780
// Apply its serialiser if it
7881
Serialiser serialiser = it->second.first;
@@ -141,34 +144,25 @@ bool SceneFile::Deserialise(std::vector<Entity*>& entities)
141144

142145
Entity* SceneFile::DeserialiseFromString(const String& fileData)
143146
{
144-
if (fileData.IsEmpty())
145-
{
146-
CC_LOG_WARNING("Found empty entity during deserialisation");
147-
return nullptr;
148-
}
149-
150-
// Split the file into arguments and strip the labels from each item
151-
std::vector<String> args = fileData.Split(LINE_SEP);
152-
for (String& arg : args) arg = arg.SubString((int) arg.Find(NAME_SEP) + 1);
147+
std::map<Token, String> attributes = Siege::FileSystem::ParseAttributeFileData(fileData);
153148

154-
// Get the standard entity fields
155-
EntityData data;
156-
if (!(args.size() >= 4 && args[ENTITY_ROT].GetFloat(data.rotation) &&
157-
args[ENTITY_Z_IDX].GetInt(data.zIndex) && FromString(data.position, args[ENTITY_POS])))
149+
if (attributes.empty())
158150
{
159-
CC_LOG_WARNING("Failed to deserialise fields for entity \"{}\"", args[ENTITY_NAME]);
151+
CC_LOG_WARNING("Found empty entity during deserialisation!");
152+
return nullptr;
160153
}
161154

162155
// Check if the entity has a relevant serialisable interface registered
163156
auto& serialisables = GetSerialisables();
164-
auto it = serialisables.find(args[ENTITY_NAME]);
157+
Token typeToken(attributes[TOKEN_TYPE]);
158+
auto it = serialisables.find(typeToken);
165159
if (it != serialisables.end())
166160
{
167161
// Apply its deserialiser
168162
Deserialiser deserialiser = it->second.second;
169-
if (deserialiser) return deserialiser(data, args);
163+
if (deserialiser) return deserialiser(attributes);
170164
}
171-
else CC_LOG_WARNING("\"{}\" has no deserialisation protocols defined", args[ENTITY_NAME]);
165+
else CC_LOG_WARNING("\"{}\" has no deserialisation protocols defined", attributes[TOKEN_TYPE]);
172166
return nullptr;
173167
}
174168

@@ -190,6 +184,29 @@ void SceneFile::InitialiseEntityPathMappings()
190184
}
191185
}
192186

187+
EntityData SceneFile::GetBaseEntityData(const std::map<Token, String>& attributes)
188+
{
189+
EntityData data;
190+
auto it = attributes.find(TOKEN_ROTATION);
191+
if (it == attributes.end() || !it->second.GetFloat(data.rotation))
192+
{
193+
CC_LOG_WARNING("Failed to deserialise ROTATION field for entity attributes");
194+
}
195+
196+
it = attributes.find(TOKEN_Z_INDEX);
197+
if (it == attributes.end() || !it->second.GetInt(data.zIndex))
198+
{
199+
CC_LOG_WARNING("Failed to deserialise Z_INDEX field for entity attributes");
200+
}
201+
202+
it = attributes.find(TOKEN_POSITION);
203+
if (it == attributes.end() || !FromString(data.position, it->second))
204+
{
205+
CC_LOG_WARNING("Failed to deserialise POSITION field for entity attributes");
206+
}
207+
return data;
208+
}
209+
193210
String SceneFile::GetOrCreateEntityFilepath(Entity* entity)
194211
{
195212
// Try to find the entity path amongst the deserialised
@@ -212,7 +229,8 @@ String SceneFile::GetOrCreateEntityFilepath(Entity* entity)
212229

213230
// Failed attempts to find a file index are serialised as 0
214231
String index = result ? String::FromInt(newFileIndex) : "0";
215-
return MakeScenePath(sceneName) + '/' + entity->GetName() + '.' + index + ENTITY_FILE_EXT;
232+
return MakeScenePath(sceneName) + '/' + entity->GetType().GetId() + '.' + index +
233+
ENTITY_FILE_EXT;
216234
}
217235

218236
String SceneFile::MakeScenePath(const String& sceneName)

0 commit comments

Comments
 (0)