Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Resource.cpp
Go to the documentation of this file.
1
2
3#include "Headers/Resource.h"
5
6namespace Divide {
7
8//---------------------------- Resource ------------------------------------------//
9Resource::Resource( const std::string_view resourceName, const std::string_view typeName )
10 : GUIDWrapper()
11 , _typeName( typeName )
12 , _resourceName(resourceName)
13 , _resourceState(ResourceState::RES_CREATED)
14{
15}
16
18{
19 return _resourceState.load(std::memory_order_relaxed);
20}
21
22void Resource::setState(const ResourceState currentState)
23{
24 _resourceState.store(currentState, std::memory_order_relaxed);
25}
26
28{
29 if ( res != nullptr )
30 {
32 }
33}
34
36{
37 if ( res != nullptr )
38 {
39 const ResourceState state = res->getState();
40 return state == ResourceState::RES_CREATED || state == ResourceState::RES_LOADED;
41 }
42
43 return true;
44}
45
46//---------------------------- Cached Resource ------------------------------------//
47CachedResource::CachedResource( const ResourceDescriptorBase& descriptor, const std::string_view typeName )
48 : Resource( descriptor.resourceName(), typeName)
49 , _assetLocation( descriptor.assetLocation() )
50 , _assetName( descriptor.assetName() )
51 , _descriptorHash( descriptor.getHash() )
52{
53}
54
55bool CachedResource::load( [[maybe_unused]] PlatformContext& context )
56{
57 return true;
58}
59
61{
62 return true;
63}
64
66{
67 return true;
68}
69
71{
72 Resource::setState(currentState);
73}
74
75ResourceDescriptorBase::ResourceDescriptorBase( const std::string_view resourceName )
76 : Hashable()
77 , _resourceName( resourceName.data(), resourceName.size() )
78{
79
80}
81
83{
84 _hash = 1337;
85
87 _resourceName,
88 _assetLocation,
89 _assetName,
90 _flag,
91 _ID,
92 _mask.i,
93 _enumValue,
94 _data.x,
95 _data.y,
96 _data.z );
97
98 return _hash;
99}
100
101} // namespace Divide
#define WAIT_FOR_CONDITION(...)
virtual bool postLoad()
Definition: Resource.cpp:60
virtual bool unload()
Definition: Resource.cpp:65
virtual bool load(PlatformContext &context)
Loading and unloading interface.
Definition: Resource.cpp:55
CachedResource(const ResourceDescriptorBase &descriptor, std::string_view typeName)
Definition: Resource.cpp:47
void setState(ResourceState currentState) final
Definition: Resource.cpp:70
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
std::atomic< ResourceState > _resourceState
Definition: Resource.h:81
ResourceState getState() const noexcept
Definition: Resource.cpp:17
virtual void setState(ResourceState currentState)
Definition: Resource.cpp:22
Resource(std::string_view resourceName, std::string_view typeName)
Definition: Resource.cpp:9
void Hash_combine(size_t &seed, const T &v, const Rest &... rest) noexcept
a la Boost
Definition: MathHelper.inl:799
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool SafeToDelete(Resource *res)
Definition: Resource.cpp:35
ResourceState
Definition: Resource.h:57
@ RES_LOADED
The resource is available for usage.
@ RES_CREATED
The pointer has been created and instantiated, but no data has been loaded.
void WaitForReady(Resource *res)
Definition: Resource.cpp:27
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
SceneGraphNode * _flag[2]
Definition: WarScene.h:96
size_t _hash
Definition: Hashable.h:49
size_t getHash() const override
Definition: Resource.cpp:82
ResourceDescriptorBase(const std::string_view resourceName)
Definition: Resource.cpp:75