Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Resource.cpp
1/*
2Copyright (C) 2021,2025 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#include <atomic>
17#include "aeongames/Resource.hpp"
18#include "aeongames/ResourceCache.hpp"
19#include "aeongames/AeonEngine.hpp"
20#include "aeongames/CRC.hpp"
21
22namespace AeonGames
23{
25 {
26 static std::atomic<std::size_t> consecutive{};
27 return consecutive++;
28 }
29
30 void Resource::LoadFromId ( uint32_t aId )
31 {
32 std::vector<uint8_t> buffer ( GetResourceSize ( aId ), 0 );
33 LoadResource ( aId, buffer.data(), buffer.size() );
34 LoadFromMemory ( buffer.data(), buffer.size() );
35 }
36
37 void Resource::LoadFromFile ( const std::string& aFilename )
38 {
39 LoadFromId ( crc32i ( aFilename.c_str(), aFilename.size() ) );
40 }
41
43 {
44 return mConsecutiveId;
45 }
46}
DLL void LoadFromFile(const std::string &aFilename)
Load the resource from a file on disk.
Definition Resource.cpp:37
DLL void LoadFromId(uint32_t aId)
Load the resource identified by a numeric id.
Definition Resource.cpp:30
virtual void LoadFromMemory(const void *aBuffer, size_t aBufferSize)=0
Load the resource from a raw memory buffer.
DLL size_t GetConsecutiveId() const
Get the Consecutive Id for the resource object.
Definition Resource.cpp:42
<- This is here just for the literals
Definition AABB.hpp:31
DLL size_t GetResourceSize(uint32_t crc)
uint32_t crc32i(const char *message, size_t size, uint32_t previous_crc)
Compute the CRC32 of a given message, continuing from a previous CRC value.
Definition CRC.cpp:27
DLL size_t GetNextConsecutiveId()
Returns the next available consecutive resource identifier.
Definition Resource.cpp:24
DLL void LoadResource(uint32_t crc, void *buffer, size_t buffer_size)