Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
creative-engine/src/BResourceManager.cpp at develop · ModusCreateOrg/creative-engine · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ModusCreateOrg
creative-engine
Repository navigation
Code
Issues
1
(1)
Pull requests
1
(1)
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
creative-engine
/
src
/
BResourceManager.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
322 lines (282 loc) · 8.31 KB
develop
Breadcrumbs
creative-engine
/
src
/
BResourceManager.cpp
Copy path
Top
File metadata and controls
Code
Blame
322 lines (282 loc) · 8.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#
include
"
BResourceManager.h
"
#
include
"
BBitmap.h
"
#
include
"
BTileMap.h
"
#
include
"
BSpriteSheet.h
"
//
TODO: should application incbin the resources binary?
#
ifdef
__XTENSA__
//
ODROID GO TARGET
extern
const
TUint8 Resources_start[]
asm
(
"
_binary_Resources_bin_start
"
);
BResourceManager
gResourceManager
((TAny *)Resources_start);
//
extern const TUint8 reesources_bin_start[] asm("_binary_resources_bin_start");
#
else
//
LINUX OR MAC TARGET
#
include
<
stdio.h
>
#
ifdef
__linux__
//
LINUX TARGET
asm
(
"
.section .rodata
\n
"
"
.global binary_Resources_bin_start
\n
"
"
.global binary_Resources_bin_end
\n
"
"
.balign 16
\n
"
"
binary_Resources_bin_start:
\n
"
"
.incbin
\"
Resources.bin
\"\n
"
"
binary_Resources_bin_end:
\n
"
"
.byte 0
\n
"
"
.align 4
\n
"
);
//
extern TUint8 binary_Resources_bin_end[];\n"
extern
__attribute
((aligned(
16
))) TUint8 binary_Resources_bin_start[];
//
extern TUint8 binary_Resources_bin_start[];
//
extern TUint8 binary_Resources_bin_end[];
#
else
//
MAC TARGET
asm
(
"
.section .rodata,.rodata
\n
"
"
.global _binary_Resources_bin_start
\n
"
"
.global _binary_Resources_bin_end
\n
"
"
.align 4
\n
"
"
_binary_Resources_bin_start:
\n
"
"
.incbin
\"
Resources.bin
\"\n
"
"
_binary_Resources_bin_end:
\n
"
"
.byte 0
\n
"
"
.align 4
\n
"
);
extern
"
C
"
{
extern
TUint8 binary_Resources_bin_start[];
extern
TUint8 binary_Resources_bin_end[];
//
extern TUint8 binary_Resources_bin_start[];
}
#
endif
//
MAC TARGET
BResourceManager
gResourceManager
(binary_Resources_bin_start);
#
endif
//
LINUX OR MAC TARGET
struct
BitmapSlot
{
BitmapSlot
(TInt16 aResourceId, TInt16 aImageType, BBitmap *aBitmap, TBool aCached = EFalse) {
mResourceId
= aResourceId;
mImageType
= aImageType;
mBitmap
= aBitmap;
mCached
= aCached;
}
TInt16
mResourceId
;
TInt16
mImageType
;
BBitmap *
mBitmap
;
TBool
mCached
;
};
struct
RawSlot
{
RawSlot
(TInt16 aResourceId, BRaw *aRaw, TBool aCached = EFalse) {
mResourceId
= aResourceId;
mCached
= aCached;
mRaw
= aRaw;
}
TInt16
mResourceId
;
BRaw *
mRaw
;
TBool
mCached
;
};
BResourceManager::BResourceManager
(TAny *aROM) {
TUint32 *ptr = (TUint32 *)aROM;
this
->
mPtr
= aROM;
this
->
mNumResources
= *ptr++;
this
->
mResourceTable
= ptr;
this
->
mROM
= (TUint8 *)&ptr[
this
->
mNumResources
];
for
(TInt i =
0
; i <
MAX_BITMAP_SLOTS
; i++) {
mBitmapSlots
[i] = ENull;
}
for
(TInt i =
0
; i <
MAX_PRELOADED_BITMAPS
; i++) {
mPreloadedBitmaps
[i] = ENull;
}
for
(TInt i =
0
; i <
MAX_RAW_SLOTS
; i++) {
mRawSlots
[i] = ENull;
}
}
BResourceManager::~BResourceManager
() {
ClearBitmapCache
();
ReleaseBitmapSlots
();
ReleaseRawSlots
();
}
TPalette *
BResourceManager::LoadPalette
(TInt16 aPaletteId) {
TUint8 *rom = &
this
->
mROM
[
this
->
mResourceTable
[aPaletteId]];
TPalette *p =
new
TPalette[
256
];
for
(TInt c =
0
; c <
256
; c++) {
p[c].
r
= *rom++;
p[c].
g
= *rom++;
p[c].
b
= *rom++;
}
return
p;
}
void
BResourceManager::FreePalette
(TPalette *aPalette) {
delete[]
aPalette;
}
BBitmap *
BResourceManager::LoadBitmap
(TInt16 aResourceId) {
return
BBitmap::CreateBBitmap
(&
this
->
mROM
[
this
->
mResourceTable
[aResourceId]]);
}
BTileMap *
BResourceManager::LoadTileMap
(TInt16 aResourceId, TInt16 aTilesetId) {
return
new
BTileMap
(&
this
->
mROM
[
this
->
mResourceTable
[aResourceId]], aTilesetId);
}
//
Load a bitmap from FLASH/ROM/RODATA into a slot
TBool
BResourceManager::LoadBitmap
(TInt16 aResourceId, TInt16 aSlotId, TInt16 aImageType) {
BitmapSlot *slot =
mBitmapSlots
[aSlotId];
if
(slot) {
return
slot->
mResourceId
== aResourceId;
}
if
(
mPreloadedBitmaps
[aResourceId]) {
auto
*bm =
mPreloadedBitmaps
[aResourceId];
mBitmapSlots
[aSlotId] =
new
BitmapSlot
(aResourceId, aImageType, bm);
}
else
{
auto
*bm =
BBitmap::CreateBBitmap
(&
this
->
mROM
[
this
->
mResourceTable
[aResourceId]]);
mBitmapSlots
[aSlotId] =
new
BitmapSlot
(aResourceId, aImageType, bm);
}
return
ETrue;
}
BSpriteSheet *
BResourceManager::LoadSpriteSheet
(TInt16 aResourceId) {
TUint32 offset =
this
->
mResourceTable
[aResourceId];
return
new
BSpriteSheet
(&
this
->
mROM
[offset]);
}
TBool
BResourceManager::PreloadBitmap
(TInt16 aResourceId) {
if
(
mPreloadedBitmaps
[aResourceId]) {
delete
mPreloadedBitmaps
[aResourceId];
}
auto
*bm =
BBitmap::CreateBBitmap
(&
this
->
mROM
[
this
->
mResourceTable
[aResourceId]]);
mPreloadedBitmaps
[aResourceId] = bm;
return
ETrue;
}
TBool
BResourceManager::SetBitmap
(BBitmap *aBitmap, TInt16 aSlotId, TInt16 aImageType) {
BitmapSlot *slot =
mBitmapSlots
[aSlotId];
if
(slot) {
return
slot->
mBitmap
== aBitmap;
}
mBitmapSlots
[aSlotId] =
new
BitmapSlot
(-
1
, aImageType, aBitmap);
return
ETrue;
}
TBool
BResourceManager::ReleaseBitmapSlot
(TInt16 aSlotId) {
BitmapSlot *slot =
mBitmapSlots
[aSlotId];
if
(!slot || slot->
mCached
) {
#
ifndef
PRODUCTION
#
if
(defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__)
printf
(
"
WARNING: ReleaseBitmapSlot failed for %d
\n
"
, aSlotId);
#
endif
#
endif
return
EFalse;
}
if
(
mPreloadedBitmaps
[aSlotId] == ENull) {
//
don't delete preloaded bitmaps
delete
slot->
mBitmap
;
}
delete
slot;
mBitmapSlots
[aSlotId] = ENull;
return
ETrue;
}
void
BResourceManager::ReleaseBitmapSlots
() {
for
(TInt16 bm =
0
; bm <
MAX_BITMAP_SLOTS
; bm++) {
if
(
mBitmapSlots
[bm]) {
ReleaseBitmapSlot
(bm);
}
}
}
TBool
BResourceManager::CacheBitmapSlot
(TInt16 aSlotId, TBool aCacheIt) {
BitmapSlot *slot =
mBitmapSlots
[aSlotId];
if
(!slot) {
return
EFalse;
}
slot->
mCached
= aCacheIt;
return
ETrue;
}
void
BResourceManager::ClearBitmapCache
(TBool aCacheIt) {
for
(TInt16 bm =
0
; bm <
MAX_BITMAP_SLOTS
; bm++) {
CacheBitmapSlot
(bm, aCacheIt);
}
}
BBitmap *
BResourceManager::GetBitmap
(TInt16 aSlotId) {
BitmapSlot *slot =
mBitmapSlots
[aSlotId];
if
(!slot) {
return
ENull;
}
return
slot->
mBitmap
;
}
TInt
BResourceManager::BitmapWidth
(TInt aSlotId) {
static
const
TUint16 widthTable[] = {
0
,
8
,
16
,
32
,
64
,
128
,
256
,
8
,
16
,
8
,
32
,
8
,
64
,
8
,
128
,
8
,
256
,
16
,
32
,
16
,
64
,
16
,
128
,
16
,
256
,
32
,
64
,
32
,
128
,
32
,
256
,
64
,
128
,
64
,
256
,
128
,
256
,
256
};
BitmapSlot *slot =
mBitmapSlots
[aSlotId];
if
(!slot) {
return
0
;
}
return
(slot->
mImageType
==
IMAGE_ENTIRE
) ? slot->
mBitmap
->
Width
() :
TInt
(widthTable[slot->
mImageType
]);
}
TInt
BResourceManager::BitmapHeight
(TInt aSlotId) {
static
const
TUint16 heightTable[] = {
0
,
8
,
16
,
32
,
64
,
128
,
256
,
16
,
8
,
32
,
8
,
64
,
8
,
128
,
8
,
256
,
8
,
32
,
16
,
64
,
16
,
128
,
16
,
256
,
16
,
64
,
32
,
128
,
32
,
256
,
32
,
128
,
64
,
256
,
64
,
128
,
256
,
256
};
BitmapSlot *slot =
mBitmapSlots
[aSlotId];
if
(!slot) {
return
0
;
}
return
(slot->
mImageType
==
IMAGE_ENTIRE
) ? slot->
mBitmap
->
Height
() :
TInt
(heightTable[slot->
mImageType
]);
}
//
BRaw management
TBool
BResourceManager::LoadRaw
(TInt16 aResourceId, TInt16 aSlotId) {
RawSlot *slot =
mRawSlots
[aSlotId];
if
(slot) {
return
slot->
mResourceId
== aResourceId;
}
auto
*raw =
new
BRaw
(&
this
->
mROM
[
this
->
mResourceTable
[aResourceId]]);
mRawSlots
[aSlotId] =
new
RawSlot
(aResourceId, raw);
return
ETrue;
}
TBool
BResourceManager::ReleaseRawSlot
(TInt16 aSlotId) {
RawSlot *slot =
mRawSlots
[aSlotId];
if
(!slot || slot->
mCached
) {
return
EFalse;
}
delete
slot->
mRaw
;
delete
slot;
mRawSlots
[aSlotId] = ENull;
return
ETrue;
}
void
BResourceManager::ReleaseRawSlots
() {
for
(TInt16 r =
0
; r <
MAX_RAW_SLOTS
; r++) {
ReleaseRawSlot
(r);
}
}
TBool
BResourceManager::CacheRawSlot
(TInt16 aSlotId, TBool aCacheIt) {
RawSlot *slot =
mRawSlots
[aSlotId];
if
(!slot) {
return
EFalse;
}
slot->
mCached
= aCacheIt;
return
ETrue;
}
void
BResourceManager::ClearRawCache
(TBool aCacheIt) {
for
(TInt16 r =
0
; r <
MAX_RAW_SLOTS
; r++) {
CacheRawSlot
(r, aCacheIt);
}
}
BRaw *
BResourceManager::GetRaw
(TInt16 aSlotId) {
RawSlot *slot =
mRawSlots
[aSlotId];
if
(!slot) {
return
ENull;
}
return
slot->
mRaw
;
}
void
BResourceManager::Dump
() {
//
#ifndef PRODUCTION
//
#if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__)
printf
(
"
BResourceManager Dump
\n
"
);
printf
(
"
mNumResources: %d
\n
"
,
mNumResources
);
printf
(
"
OFFSETS:
\n
"
);
for
(TInt i =
0
; i <
mNumResources
; i++) {
printf
(
"
%8d:
"
,
mResourceTable
[i]);
TUint8 *ptr = &
mROM
[
mResourceTable
[i]];
for
(TInt j =
0
; j <
16
; j++) {
printf
(
"
%02x
"
, *ptr++);
}
printf
(
"
\n
"
);
}
//
#endif
//
#endif
}
You can’t perform that action at this time.