Cogs.Core
AssetComponent.cpp
1#include "AssetComponent.h"
2
3#include "Types.h"
4
5using namespace Cogs::Reflection;
6
8{
9 static constexpr EnumeratorDef assetFlagEnums[] = {
10 { "None", AssetFlags::None },
11 { "InstantiateOnDemand", AssetFlags::InstantiateOnDemand },
12 { "RelativePaths", AssetFlags::RelativePaths },
13 { "OverrideMaterial", AssetFlags::OverrideMaterial },
14 { "CloneMaterial", AssetFlags::CloneMaterial },
15 };
16
17 TypeDatabase::createType<AssetFlags>().setEnumerators(assetFlagEnums).setEnumFlags();
18
19 Field fields[] = {
20 { "asset", &AssetComponent::asset },
21 { "flags", &AssetComponent::flags },
22 { "idRanges", &AssetComponent::idRanges },
23 { "tolerance", &AssetComponent::tolerance },
24 { "minDistance", &AssetComponent::minDistance },
25 { "priority", &AssetComponent::priority },
26 { "freezeLod", &AssetComponent::freezeLod },
27 { "forceTolerance", &AssetComponent::forceTolerance },
28 { "material", &AssetComponent::material },
29 };
30
31 TypeDatabase::createType<AssetComponent>().setBase<Component>().setFields(fields);
32}
33
34COGSCORE_DLL_API std::string Cogs::Core::createAssetResourcePathFromIndex(uint32_t resourceIndex, AssetResourceType assetResourceType)
35{
36 char tmp[128];
37
38 int rv;
39 switch (assetResourceType) {
40
41 case AssetResourceType::Asset:
42 // asset files are _not_ put into dirs since the relative position to the path is used to locate other files
43 rv = snprintf(tmp, sizeof(tmp), "%08x.asset", resourceIndex);
44 break;
45
46 case AssetResourceType::Model:
47 // cogsbin files are put into dirs so there isn't more than 4096 entries in each dir, being nice to the file system
48 rv = snprintf(tmp, sizeof(tmp), "%05x/%03x.cogsbin", (resourceIndex >> 12u) & 0xFFFFFu, resourceIndex & 0xFFFu);
49 break;
50
51 default:
52 assert(false && "Illegal enum");
53 return std::string();
54 }
55
56 if (0 < rv && static_cast<size_t>(rv) <= sizeof(tmp)) {
57 return std::string(tmp, rv);
58 }
59 return std::string();
60}
Field definition describing a single data member of a data structure.
Definition: Field.h:68
AssetResourceType
Utility function to format a resource index as a filename.
@ InstantiateOnDemand
Dynamically calculate lod levels and only instantiate what is visible.
@ RelativePaths
Paths in asset file is relative to file's path.
@ OverrideMaterial
Override any model's material with material member of asset component.
@ CloneMaterial
Clone the assetComponent material over any loaded models's material and copy over properties and vari...
Contains reflection support.
Definition: Component.h:11
AssetHandle asset
Asset resource that should be instantiated.
static void registerType()
Register the type in the type system.
bool freezeLod
Temporarily disable adjustment of target lod-level, debug tool to allow moving the camera without aff...
float minDistance
Minimum distance to use when scaling the tolerance.
bool forceTolerance
Disable adjustment of tolerance due to quality system or resource usage.
MaterialInstanceHandle material
Material to use for models if the OverrideMaterial flag is set.
float priority
Used to sort requests, higher number gets processed before lower number.
AssetFlags flags
Flags to control behaviour of asset instantiation.
float tolerance
Tolerance scale factor to use when determining lod levels, see AssetComponent's documentation.