fix caching and 32bit->8bit bugs · ModusCreateOrg/creative-engine@61e0b8a · GitHub
Skip to content

Commit 61e0b8a

Browse files
committed
fix caching and 32bit->8bit bugs
1 parent 8cccf65 commit 61e0b8a

9 files changed

Lines changed: 107 additions & 97 deletions

File tree

‎src/BBitmap.cpp‎

Lines changed: 13 additions & 5 deletions

‎src/BBitmap.h‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,27 @@ class BFont;
6262
*
6363
*/
6464
class BBitmap : public BBase {
65-
friend class BResourceManager;
66-
friend class Display;
67-
65+
/**
66+
* public factory methods
67+
*/
6868
public:
69-
BBitmap(TUint aWidth, TUint aHeight, TUint aDepth,
70-
TUint16 aMemoryFlag = MEMF_SLOW);
69+
static BBitmap *CreateBBitmap(TUint aWidth, TUint aHeight, TUint aDepth, TUint16 aMemoryFlag = MEMF_SLOW);
70+
71+
static BBitmap *CreateBBitmap(TAny *aRom, TUint16 aMemoryFlag = MEMF_SLOW);
72+
73+
private:
74+
/*
75+
* Constructors are PRIVATE - use the factory methods!
76+
*/
77+
BBitmap(TUint aWidth, TUint aHeight, TUint aDepth, TUint16 aMemoryFlag = MEMF_SLOW);
7178

7279
BBitmap(TAny *aRom, TUint16 aMemoryFlag = MEMF_SLOW);
7380

81+
public:
7482
virtual ~BBitmap();
7583

7684
TUint mPitch;
85+
7786
public:
7887
TUint Width() { return mWidth; }
7988

@@ -156,6 +165,7 @@ class BBitmap : public BBase {
156165
TRGB &GetColor(TUint8 index) { return mPalette[index]; }
157166

158167
static void CheckScreenDepth();
168+
159169
public:
160170
TRGB &ReadColor(TInt aX, TInt aY) {
161171
TUint8 pixel = mPixels[aY * mPitch + aX];
@@ -206,7 +216,6 @@ class BBitmap : public BBase {
206216
DrawRect(aViewPort, aRect.x1, aRect.y1, aRect.x2, aRect.y2, aColor);
207217
}
208218

209-
210219
void FillRect(BViewPort *aViewPort, TInt aX1, TInt aY1, TInt aX2, TInt aY2, TUint8 aColor);
211220
void FillRect(BViewPort *aViewPort, TRect &aRect, TUint8 aColor) {
212221
FillRect(aViewPort, aRect.x1, aRect.y1, aRect.x2, aRect.y2, aColor);
@@ -217,7 +226,6 @@ class BBitmap : public BBase {
217226
FillRect(aViewPort, aRect.x1, aRect.y1, aRect.x2, aRect.y2, aColor);
218227
}
219228

220-
221229
void DrawCircle(BViewPort *aViewPort, TInt aX, TInt aY, TUint r, TUint8 aColor);
222230

223231
void FillCircle(BViewPort *aViewPort, TInt aX, TInt aY, TUint r, TUint8 aColor);

‎src/BEvents.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class BEventMessageList : public BList {
7070

7171
// The Event Emitter
7272
class BEventEmitter : public BBase {
73-
public:
74-
BEventEmitter() {}
75-
~BEventEmitter() {}
73+
//public:
74+
// BEventEmitter() {}
75+
// ~BEventEmitter() {}
7676

7777
public:
7878
TBool Listen(TUint16 type, BProcess *aProcess);

‎src/BMapPlayfield.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ static BObjectProgram *object_programs[MAX_TILEMAPS];
88
static void init_cache() {
99
if (!initialized) {
1010
initialized = ETrue;
11-
for (TInt i = 0; i < MAX_TILEMAPS; i++) {
12-
object_programs[i] = ENull;
11+
for (auto & object_program : object_programs) {
12+
object_program = ENull;
1313
}
1414
}
1515
}
@@ -47,7 +47,6 @@ BMapPlayfield::BMapPlayfield(BViewPort *aViewPort, TUint16 aResourceId, TInt16 a
4747
mMapHeight = mTileMap->mHeight;
4848
mMapData = &mTileMap->mMapData[0];
4949
mTileset = mTileMap->mTiles;
50-
mObjectProgram = mTileMap->mObjectProgram;
5150
mObjectCount = mTileMap->mObjectCount;
5251
printf("BMapPlayfield: %d Objects\n", mObjectCount);
5352
}

‎src/BResourceManager.cpp‎

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ BResourceManager gResourceManager((TAny *)Resources_start);
1212

1313
#include <stdio.h>
1414

15-
1615
#ifdef __linux__
1716

1817
// LINUX TARGET
1918
asm(
20-
" .section .rodata\n"
21-
" .global binary_Resources_bin_start\n"
22-
" .global binary_Resources_bin_end\n"
23-
" .balign 16\n"
24-
"binary_Resources_bin_start:\n"
25-
" .incbin \"Resources.bin\"\n"
26-
"binary_Resources_bin_end:\n"
27-
" .byte 0\n"
28-
" .align 4\n"
29-
);
19+
" .section .rodata\n"
20+
" .global binary_Resources_bin_start\n"
21+
" .global binary_Resources_bin_end\n"
22+
" .balign 16\n"
23+
"binary_Resources_bin_start:\n"
24+
" .incbin \"Resources.bin\"\n"
25+
"binary_Resources_bin_end:\n"
26+
" .byte 0\n"
27+
" .align 4\n");
3028
//extern TUint8 binary_Resources_bin_end[];\n"
3129
extern __attribute((aligned(16))) TUint8 binary_Resources_bin_start[];
3230
//extern TUint8 binary_Resources_bin_start[];
@@ -35,60 +33,59 @@ extern __attribute((aligned(16))) TUint8 binary_Resources_bin_start[];
3533

3634
// MAC TARGET
3735
asm(
38-
" .section .rodata,.rodata\n"
39-
" .global _binary_Resources_bin_start\n"
40-
" .global _binary_Resources_bin_end\n"
41-
" .align 4\n"
42-
"_binary_Resources_bin_start:\n"
43-
" .incbin \"Resources.bin\"\n"
44-
"_binary_Resources_bin_end:\n"
45-
" .byte 0\n"
46-
" .align 4\n"
47-
);
36+
" .section .rodata,.rodata\n"
37+
" .global _binary_Resources_bin_start\n"
38+
" .global _binary_Resources_bin_end\n"
39+
" .align 4\n"
40+
"_binary_Resources_bin_start:\n"
41+
" .incbin \"Resources.bin\"\n"
42+
"_binary_Resources_bin_end:\n"
43+
" .byte 0\n"
44+
" .align 4\n");
4845
extern "C" {
4946
extern TUint8 binary_Resources_bin_start[];
5047
extern TUint8 binary_Resources_bin_end[];
5148
//extern TUint8 binary_Resources_bin_start[];
5249
}
5350

54-
#endif // MAC TARGET
51+
#endif // MAC TARGET
5552

5653
BResourceManager gResourceManager(binary_Resources_bin_start);
5754

58-
#endif // LINUX OR MAC TARGET
55+
#endif // LINUX OR MAC TARGET
5956

6057
struct BitmapSlot {
6158
BitmapSlot(TInt16 aResourceId, TInt16 aImageType, BBitmap *aBitmap, TBool aCached = EFalse) {
6259
mResourceId = aResourceId;
63-
mImageType = aImageType;
64-
mBitmap = aBitmap;
65-
mCached = aCached;
60+
mImageType = aImageType;
61+
mBitmap = aBitmap;
62+
mCached = aCached;
6663
}
6764

68-
TInt16 mResourceId;
69-
TInt16 mImageType;
65+
TInt16 mResourceId;
66+
TInt16 mImageType;
7067
BBitmap *mBitmap;
71-
TBool mCached;
68+
TBool mCached;
7269
};
7370

7471
struct RawSlot {
7572
RawSlot(TInt16 aResourceId, BRaw *aRaw, TBool aCached = EFalse) {
7673
mResourceId = aResourceId;
77-
mCached = aCached;
78-
mRaw = aRaw;
74+
mCached = aCached;
75+
mRaw = aRaw;
7976
}
8077

8178
TInt16 mResourceId;
82-
BRaw *mRaw;
83-
TBool mCached;
79+
BRaw *mRaw;
80+
TBool mCached;
8481
};
8582

8683
BResourceManager::BResourceManager(TAny *aROM) {
87-
TUint32 *ptr = (TUint32 *) aROM;
88-
this->mPtr = aROM;
89-
this->mNumResources = *ptr++;
84+
TUint32 *ptr = (TUint32 *)aROM;
85+
this->mPtr = aROM;
86+
this->mNumResources = *ptr++;
9087
this->mResourceTable = ptr;
91-
this->mROM = (TUint8 *) &ptr[this->mNumResources];
88+
this->mROM = (TUint8 *)&ptr[this->mNumResources];
9289
for (TInt i = 0; i < MAX_BITMAP_SLOTS; i++) {
9390
mBitmapSlots[i] = ENull;
9491
}
@@ -98,7 +95,7 @@ BResourceManager::BResourceManager(TAny *aROM) {
9895
for (TInt i = 0; i < MAX_RAW_SLOTS; i++) {
9996
mRawSlots[i] = ENull;
10097
}
101-
// Dump();
98+
// Dump();
10299
}
103100

104101
BResourceManager::~BResourceManager() {
@@ -110,21 +107,20 @@ BResourceManager::~BResourceManager() {
110107
TPalette *BResourceManager::LoadPalette(TInt16 aPaletteId) {
111108
TUint8 *rom = &this->mROM[this->mResourceTable[aPaletteId]];
112109
TPalette *p = new TPalette[256];
113-
for (TInt c=0; c<256; c++) {
110+
for (TInt c = 0; c < 256; c++) {
114111
p[c].r = *rom++;
115112
p[c].g = *rom++;
116113
p[c].b = *rom++;
117114
}
118115
return p;
119116
}
120117

121-
122118
void BResourceManager::FreePalette(TPalette *aPalette) {
123-
delete [] aPalette;
119+
delete[] aPalette;
124120
}
125121

126122
BBitmap *BResourceManager::LoadBitmap(TInt16 aResourceId) {
127-
return new BBitmap(&this->mROM[this->mResourceTable[aResourceId]]);
123+
return BBitmap::CreateBBitmap(&this->mROM[this->mResourceTable[aResourceId]]);
128124
}
129125

130126
BTileMap *BResourceManager::LoadTileMap(TInt16 aResourceId, TInt16 aTilesetId) {
@@ -142,7 +138,7 @@ TBool BResourceManager::LoadBitmap(TInt16 aResourceId, TInt16 aSlotId, TInt16 aI
142138
mBitmapSlots[aSlotId] = new BitmapSlot(aResourceId, aImageType, bm);
143139
}
144140
else {
145-
auto *bm = new BBitmap(&this->mROM[this->mResourceTable[aResourceId]]);
141+
auto *bm = BBitmap::CreateBBitmap(&this->mROM[this->mResourceTable[aResourceId]]);
146142
mBitmapSlots[aSlotId] = new BitmapSlot(aResourceId, aImageType, bm);
147143
}
148144
return ETrue;
@@ -152,7 +148,7 @@ TBool BResourceManager::PreloadBitmap(TInt16 aResourceId) {
152148
if (mPreloadedBitmaps[aResourceId]) {
153149
delete mPreloadedBitmaps[aResourceId];
154150
}
155-
auto *bm = new BBitmap(&this->mROM[this->mResourceTable[aResourceId]]);
151+
auto *bm = BBitmap::CreateBBitmap(&this->mROM[this->mResourceTable[aResourceId]]);
156152
mPreloadedBitmaps[aResourceId] = bm;
157153
return ETrue;
158154
}
@@ -225,7 +221,7 @@ TInt BResourceManager::BitmapWidth(TInt aSlotId) {
225221
64, 128, 64, 256,
226222
128, 256, 256
227223
};
228-
BitmapSlot *slot = mBitmapSlots[aSlotId];
224+
BitmapSlot *slot = mBitmapSlots[aSlotId];
229225
if (!slot) {
230226
return 0;
231227
}
@@ -242,7 +238,7 @@ TInt BResourceManager::BitmapHeight(TInt aSlotId) {
242238
128, 64, 256, 64,
243239
128, 256, 256
244240
};
245-
BitmapSlot *slot = mBitmapSlots[aSlotId];
241+
BitmapSlot *slot = mBitmapSlots[aSlotId];
246242
if (!slot) {
247243
return 0;
248244
}
@@ -302,21 +298,20 @@ BRaw *BResourceManager::GetRaw(TInt16 aSlotId) {
302298
return slot->mRaw;
303299
}
304300

305-
306301
void BResourceManager::Dump() {
307-
//#ifndef PRODUCTION
308-
//#if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__)
302+
//#ifndef PRODUCTION
303+
//#if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__)
309304
printf("BResourceManager Dump\n");
310305
printf("mNumResources: %d\n", mNumResources);
311306
printf("OFFSETS:\n");
312307
for (TInt i = 0; i < mNumResources; i++) {
313308
printf("%8d: ", mResourceTable[i]);
314-
TUint8 *ptr = &mROM[mResourceTable[i]];
315-
for (TInt j = 0; j < 16; j++) {
309+
TUint8 *ptr = &mROM[mResourceTable[i]];
310+
for (TInt j = 0; j < 16; j++) {
316311
printf("%02x ", *ptr++);
317312
}
318313
printf("\n");
319314
}
320-
//#endif
321-
//#endif
315+
//#endif
316+
//#endif
322317
}

‎src/BResourceManager.h‎

Lines changed: 11 additions & 8 deletions

0 commit comments

Comments
 (0)