-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssets.h
More file actions
150 lines (128 loc) · 3.69 KB
/
Copy pathAssets.h
File metadata and controls
150 lines (128 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
Copyright (c) 2024-2025 Toksisitee. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, refer to license.md or https://opensource.org/licenses/MIT
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*/
#pragma once
//#include <vector>
#include <memory>
#include <utility>
#include "Palette.h"
class CTexture2D;
typedef struct IDirect3DDevice9* LPDIRECT3DDEVICE9, * PDIRECT3DDEVICE9;
extern inline void SafeDestroyTexture( CTexture2D*& pTexture );
namespace Assets
{
//template <typename T>
//struct Bank {
// uint32_t Entries;
// std::vector<std::pair<uint32_t, T>> Entry;
//};
class CAsset
{
public:
CAsset()
{
m_pPalette = std::make_shared<CPalette>();
}
~CAsset() { SafeDestroyTexture( m_pTexture ); }
virtual Result LoadBin( const std::string& sFilePath ) = 0;
virtual Result LoadImg( const std::string& sFilePath ) = 0;
virtual Result ExportImg( const std::string& sFilePath ) = 0;
virtual Result ExportBin( const std::string& sFilePath ) = 0;
virtual bool CreateTexture( LPDIRECT3DDEVICE9 pD3DDevice ) = 0;
inline virtual void* GetPtr() = 0;
void SetPalette( const std::shared_ptr<CPalette>& pPalette )
{
m_pPalette = pPalette;
}
inline void DestroyTexture()
{
SafeDestroyTexture( m_pTexture );
}
[[nodiscard]] inline CTexture2D* GetTexture()
{
return m_pTexture;
}
[[nodiscard]] inline CPalette* GetPalette()
{
return m_pPalette.get();
}
protected:
std::shared_ptr<CPalette> m_pPalette = nullptr;
CTexture2D* m_pTexture = nullptr;
};
#if 0
class CAsset
{
public:
virtual ~CAsset() {};
virtual bool Load( const char* pszFile ) = 0;
virtual void Create( const char* pszFile ) = 0;
virtual void Export() = 0;
protected:
char* m_pBuffer;
uint32_t m_nBufferLength;
};
template <typename T>
class CAssetBank : public CAsset
{
public:
virtual ~CAssetBank() {};
virtual bool Load( const char* pszFile )
{
m_Bank.Entries = 0;
m_Bank.Entry.clear();
if ( m_pBuffer ) {
delete[] m_pBuffer;
}
std::ifstream ifs( pszFile, std::ios::binary );
if ( ifs.is_open() ) {
ifs.seekg( 0 );
m_nBufferLength = static_cast<uint32_t>(ifs.tellg());
if ( m_nBufferLength > 0 ) {
m_pBuffer = new char[m_nBufferLength];
ifs.read( m_pBuffer, m_nBufferLength );
ifs.close();
if ( m_pBuffer != NULL ) {
char* pBuffer = m_pBuffer;
m_Bank.Entries = *(reinterpret_cast<uint32_t*>(pBuffer));
if ( m_Bank.Entries == 0 ) {
this->Clear();
return false;
}
pBuffer += sizeof( uint32_t );
for ( uint32_t i = 0; i < m_Bank.Entries; i++ ) {
auto offset = *(reinterpret_cast<uint32_t*>(pBuffer));
m_Bank.Entry.push_back( std::make_pair( offset, *(reinterpret_cast<T*>(&m_pBuffer[offset])) ) );
pBuffer += sizeof( uint32_t );
}
return true;
}
}
return false;
}
}
protected:
virtual void Clear()
{
delete[] m_pBuffer;
m_pBuffer = nullptr;
m_Bank.Entry.clear();
m_nBufferLength = 0;
}
private:
struct Bank<T> m_Bank;
char* m_pBuffer;
uint32_t m_nBufferLength;
};
#endif
const char* GetFileTypeSz( FileType eFileType );
extern Result OpenWnd( const std::string& sFilePath, FileType eFileType );
extern Result QuickLoad( void* pAsset, const std::string& sFilePath, FileType eFileType );
extern std::string GenerateAssetName( const char* pszIdentifier, FileType eType );
extern CTexture2D* LoadTexture( const std::string& sFilePath, const Assets::FileType eType, int nSize );
}