Skip to content

Commit 93de90b

Browse files
ozoz
oz
authored and
oz
committed
Replaced memory with new.
Cleaned up gdrv, zdrv, render.
1 parent dc5915b commit 93de90b

25 files changed

+219
-438
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ set(SOURCE_FILES
4242
SpaceCadetPinball/loader.h
4343
SpaceCadetPinball/maths.cpp
4444
SpaceCadetPinball/maths.h
45-
SpaceCadetPinball/memory.cpp
46-
SpaceCadetPinball/memory.h
4745
SpaceCadetPinball/midi.cpp
4846
SpaceCadetPinball/midi.h
4947
SpaceCadetPinball/nudge.cpp

SpaceCadetPinball/GroupData.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "fullscrn.h"
66
#include "gdrv.h"
7-
#include "memory.h"
87
#include "zdrv.h"
98

109

@@ -13,10 +12,15 @@ EntryData::~EntryData()
1312
if (Buffer)
1413
{
1514
if (EntryType == FieldTypes::Bitmap8bit)
16-
gdrv::destroy_bitmap(reinterpret_cast<gdrv_bitmap8*>(Buffer));
15+
{
16+
delete reinterpret_cast<gdrv_bitmap8*>(Buffer);
17+
}
1718
else if (EntryType == FieldTypes::Bitmap16bit)
18-
zdrv::destroy_zmap(reinterpret_cast<zmap_header_type*>(Buffer));
19-
memory::free(Buffer);
19+
{
20+
delete reinterpret_cast<zmap_header_type*>(Buffer);
21+
}
22+
else
23+
delete[] Buffer;
2024
}
2125
}
2226

@@ -40,8 +44,8 @@ void GroupData::AddEntry(EntryData* entry)
4044
if (srcBmp->BitmapType == BitmapTypes::Spliced)
4145
{
4246
// Get rid of spliced bitmap early on, to simplify render pipeline
43-
auto bmp = memory::allocate<gdrv_bitmap8>();
44-
auto zMap = memory::allocate<zmap_header_type>();
47+
auto bmp = new gdrv_bitmap8(srcBmp->Width, srcBmp->Height, srcBmp->Width);
48+
auto zMap = new zmap_header_type(srcBmp->Width, srcBmp->Height, srcBmp->Width);
4549
SplitSplicedBitmap(*srcBmp, *bmp, *zMap);
4650

4751
NeedsSort = true;
@@ -97,13 +101,11 @@ void GroupData::SplitSplicedBitmap(const gdrv_bitmap8& srcBmp, gdrv_bitmap8& bmp
97101
{
98102
assertm(srcBmp.BitmapType == BitmapTypes::Spliced, "GroupData: wrong bitmap type");
99103

100-
gdrv::create_bitmap(&bmp, srcBmp.Width, srcBmp.Height, srcBmp.Width);
101104
std::memset(bmp.IndexedBmpPtr, 0xff, bmp.Stride * bmp.Height);
102105
bmp.XPosition = srcBmp.XPosition;
103106
bmp.YPosition = srcBmp.YPosition;
104107
bmp.Resolution = srcBmp.Resolution;
105-
106-
zdrv::create_zmap(&zMap, srcBmp.Width, srcBmp.Height, srcBmp.Width);
108+
107109
zdrv::fill(&zMap, zMap.Width, zMap.Height, 0, 0, 0xFFFF);
108110
zMap.Resolution = srcBmp.Resolution;
109111

SpaceCadetPinball/TLightBargraph.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "control.h"
66
#include "loader.h"
7-
#include "memory.h"
87
#include "timer.h"
98
#include "TPinballTable.h"
109

@@ -17,11 +16,11 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro
1716
float* floatArr = loader::query_float_attribute(groupIndex, 0, 904);
1817
if (floatArr)
1918
{
20-
int count = 2 * List.size();
21-
TimerTimeArray = memory::allocate<float>(count);
19+
auto count = 2 * List.size();
20+
TimerTimeArray = new float[count];
2221
if (TimerTimeArray)
2322
{
24-
for (int i = 0; i < count; ++floatArr)
23+
for (auto i = 0u; i < count; ++floatArr)
2524
TimerTimeArray[i++] = *floatArr;
2625
}
2726
}
@@ -30,8 +29,7 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro
3029

3130
TLightBargraph::~TLightBargraph()
3231
{
33-
if (TimerTimeArray)
34-
memory::free(TimerTimeArray);
32+
delete[] TimerTimeArray;
3533
}
3634

3735
int TLightBargraph::Message(int code, float value)

SpaceCadetPinball/TPinballTable.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "control.h"
66
#include "loader.h"
7-
#include "memory.h"
87
#include "pb.h"
98
#include "pinball.h"
109
#include "render.h"
@@ -194,18 +193,18 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false)
194193

195194
TPinballTable::~TPinballTable()
196195
{
197-
for (int scoreIndex = 0; scoreIndex < 4; scoreIndex++)
196+
for (auto& PlayerScore : PlayerScores)
198197
{
199-
memory::free(PlayerScores[scoreIndex].ScoreStruct);
198+
delete PlayerScore.ScoreStruct;
200199
}
201200
if (ScorePlayerNumber1)
202201
{
203-
memory::free(ScorePlayerNumber1);
202+
delete ScorePlayerNumber1;
204203
ScorePlayerNumber1 = nullptr;
205204
}
206205
if (ScoreBallcount)
207206
{
208-
memory::free(ScoreBallcount);
207+
delete ScoreBallcount;
209208
ScoreBallcount = nullptr;
210209
}
211210
delete LightGroup;

SpaceCadetPinball/TTextBox.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void TTextBox::Clear()
7575
gdrv_bitmap8* bmp = BgBmp;
7676
if (bmp)
7777
gdrv::copy_bitmap(
78-
&render::vscreen,
78+
render::vscreen,
7979
Width,
8080
Height,
8181
OffsetX,
@@ -84,7 +84,7 @@ void TTextBox::Clear()
8484
OffsetX,
8585
OffsetY);
8686
else
87-
gdrv::fill_bitmap(&render::vscreen, Width, Height, OffsetX, OffsetY, 0);
87+
gdrv::fill_bitmap(render::vscreen, Width, Height, OffsetX, OffsetY, 0);
8888
if (Timer)
8989
{
9090
if (Timer != -1)
@@ -149,7 +149,7 @@ void TTextBox::Draw()
149149
auto bmp = BgBmp;
150150
if (bmp)
151151
gdrv::copy_bitmap(
152-
&render::vscreen,
152+
render::vscreen,
153153
Width,
154154
Height,
155155
OffsetX,
@@ -158,7 +158,7 @@ void TTextBox::Draw()
158158
OffsetX,
159159
OffsetY);
160160
else
161-
gdrv::fill_bitmap(&render::vscreen, Width, Height, OffsetX, OffsetY, 0);
161+
gdrv::fill_bitmap(render::vscreen, Width, Height, OffsetX, OffsetY, 0);
162162

163163
bool display = false;
164164
while (Message1)
@@ -191,8 +191,8 @@ void TTextBox::Draw()
191191
{
192192
gdrv::grtext_draw_ttext_in_box(
193193
Message1->Text,
194-
render::vscreen.XPosition + OffsetX,
195-
render::vscreen.YPosition + OffsetY,
194+
render::vscreen->XPosition + OffsetX,
195+
render::vscreen->YPosition + OffsetY,
196196
Width,
197197
Height,
198198
255);
@@ -245,10 +245,10 @@ void TTextBox::Draw()
245245
auto height = charBmp->Height;
246246
auto width = charBmp->Width;
247247
if (render::background_bitmap)
248-
gdrv::copy_bitmap_w_transparency(&render::vscreen, width, height, offX, y, charBmp, 0,
248+
gdrv::copy_bitmap_w_transparency(render::vscreen, width, height, offX, y, charBmp, 0,
249249
0);
250250
else
251-
gdrv::copy_bitmap(&render::vscreen, width, height, offX, y, charBmp, 0, 0);
251+
gdrv::copy_bitmap(render::vscreen, width, height, offX, y, charBmp, 0, 0);
252252
font = Font;
253253
offX += charBmp->Width + font->GapWidth;
254254
}

SpaceCadetPinball/TTextBoxMessage.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "pch.h"
22
#include "TTextBoxMessage.h"
3-
#include "memory.h"
43
#include "pb.h"
54

65
TTextBoxMessage::TTextBoxMessage(char* text, float time)
@@ -11,7 +10,7 @@ TTextBoxMessage::TTextBoxMessage(char* text, float time)
1110
if (text)
1211
{
1312
const auto textLen = strlen(text) + 1;
14-
Text = memory::allocate(textLen);
13+
Text = new char[textLen];
1514
if (Text)
1615
strncpy(Text, text, textLen);
1716
}
@@ -21,8 +20,7 @@ TTextBoxMessage::TTextBoxMessage(char* text, float time)
2120

2221
TTextBoxMessage::~TTextBoxMessage()
2322
{
24-
if (Text)
25-
memory::free(Text);
23+
delete[] Text;
2624
}
2725

2826
float TTextBoxMessage::TimeLeft() const

SpaceCadetPinball/gdrv.cpp

+42-64
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,81 @@
22
#include "gdrv.h"
33

44
#include "GroupData.h"
5-
#include "memory.h"
65
#include "partman.h"
76
#include "pb.h"
87
#include "score.h"
98
#include "winmain.h"
109

1110
ColorRgba gdrv::current_palette[256]{};
1211

13-
int gdrv::create_bitmap(gdrv_bitmap8* bmp, int width, int height, int stride, bool indexed)
12+
gdrv_bitmap8::gdrv_bitmap8(int width, int height, bool indexed)
1413
{
1514
assertm(width >= 0 && height >= 0, "Negative bitmap8 dimensions");
1615

17-
bmp->Width = width;
18-
bmp->Height = height;
19-
bmp->Stride = width;
20-
bmp->BitmapType = BitmapTypes::DibBitmap;
21-
bmp->Texture = nullptr;
22-
23-
if (stride >= 0)
24-
bmp->IndexedStride = stride;
25-
else
26-
{
27-
bmp->IndexedStride = width;
28-
if (width % 4)
29-
bmp->IndexedStride = width - width % 4 + 4;
30-
}
16+
Width = width;
17+
Height = height;
18+
Stride = width;
19+
IndexedStride = width;
20+
BitmapType = BitmapTypes::DibBitmap;
21+
Texture = nullptr;
22+
IndexedBmpPtr = nullptr;
23+
XPosition = 0;
24+
YPosition = 0;
25+
Resolution = 0;
3126

3227
if (indexed)
33-
bmp->IndexedBmpPtr = memory::allocate(bmp->Height * bmp->IndexedStride);
34-
bmp->BmpBufPtr1 = memory::allocate<ColorRgba>(bmp->Height * bmp->Stride);
35-
if (bmp->BmpBufPtr1)
36-
{
37-
return 0;
38-
}
39-
return -1;
28+
IndexedBmpPtr = new char[Height * IndexedStride];
29+
BmpBufPtr1 = new ColorRgba[Height * Stride];
4030
}
4131

42-
int gdrv::create_bitmap(gdrv_bitmap8& bmp, const dat8BitBmpHeader& header)
32+
gdrv_bitmap8::gdrv_bitmap8(const dat8BitBmpHeader& header)
4333
{
4434
assertm(header.Width >= 0 && header.Height >= 0, "Negative bitmap8 dimensions");
4535

4636
if (header.IsFlagSet(bmp8Flags::Spliced))
47-
bmp.BitmapType = BitmapTypes::Spliced;
37+
BitmapType = BitmapTypes::Spliced;
4838
else if (header.IsFlagSet(bmp8Flags::DibBitmap))
49-
bmp.BitmapType = BitmapTypes::DibBitmap;
39+
BitmapType = BitmapTypes::DibBitmap;
5040
else
51-
bmp.BitmapType = BitmapTypes::RawBitmap;
41+
BitmapType = BitmapTypes::RawBitmap;
5242

53-
bmp.Width = header.Width;
54-
bmp.Stride = header.Width;
55-
bmp.IndexedStride = header.Width;
56-
bmp.Height = header.Height;
57-
bmp.XPosition = header.XPosition;
58-
bmp.YPosition = header.YPosition;
59-
bmp.Resolution = header.Resolution;
60-
bmp.Texture = nullptr;
43+
Width = header.Width;
44+
Stride = header.Width;
45+
IndexedStride = header.Width;
46+
Height = header.Height;
47+
XPosition = header.XPosition;
48+
YPosition = header.YPosition;
49+
Resolution = header.Resolution;
50+
Texture = nullptr;
6151

6252
int sizeInBytes;
63-
if (bmp.BitmapType == BitmapTypes::Spliced)
53+
if (BitmapType == BitmapTypes::Spliced)
6454
{
6555
sizeInBytes = header.Size;
6656
}
6757
else
6858
{
69-
if (bmp.BitmapType == BitmapTypes::RawBitmap)
70-
assertm(bmp.Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag");
71-
if (bmp.Width % 4)
72-
bmp.IndexedStride = bmp.Width - bmp.Width % 4 + 4;
73-
sizeInBytes = bmp.Height * bmp.IndexedStride;
59+
if (BitmapType == BitmapTypes::RawBitmap)
60+
assertm(Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag");
61+
if (Width % 4)
62+
IndexedStride = Width - Width % 4 + 4;
63+
sizeInBytes = Height * IndexedStride;
7464
assertm(sizeInBytes == header.Size, "Wrong bitmap8 size");
7565
}
7666

77-
bmp.IndexedBmpPtr = memory::allocate(sizeInBytes);
78-
bmp.BmpBufPtr1 = memory::allocate<ColorRgba>(bmp.Stride * bmp.Height);
79-
if (bmp.BmpBufPtr1)
67+
IndexedBmpPtr = new char[sizeInBytes];
68+
BmpBufPtr1 = new ColorRgba[Stride * Height];
69+
}
70+
71+
gdrv_bitmap8::~gdrv_bitmap8()
72+
{
73+
if (BitmapType != BitmapTypes::None)
8074
{
81-
return 0;
75+
delete[] BmpBufPtr1;
76+
delete[] IndexedBmpPtr;
77+
if (Texture)
78+
SDL_DestroyTexture(Texture);
8279
}
83-
return -1;
8480
}
8581

8682
int gdrv::display_palette(ColorRgba* plt)
@@ -139,24 +135,6 @@ int gdrv::display_palette(ColorRgba* plt)
139135
return 0;
140136
}
141137

142-
143-
int gdrv::destroy_bitmap(gdrv_bitmap8* bmp)
144-
{
145-
if (!bmp)
146-
return -1;
147-
148-
if (bmp->BitmapType != BitmapTypes::None)
149-
{
150-
memory::free(bmp->BmpBufPtr1);
151-
if (bmp->IndexedBmpPtr)
152-
memory::free(bmp->IndexedBmpPtr);
153-
if (bmp->Texture)
154-
SDL_DestroyTexture(bmp->Texture);
155-
}
156-
memset(bmp, 0, sizeof(gdrv_bitmap8));
157-
return 0;
158-
}
159-
160138
void gdrv::fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar)
161139
{
162140
auto color = current_palette[fillChar];

SpaceCadetPinball/gdrv.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ static_assert(sizeof(ColorRgba) == 4, "Wrong size of RGBA color");
3939

4040
struct gdrv_bitmap8
4141
{
42+
gdrv_bitmap8(int width, int height, bool indexed);
43+
gdrv_bitmap8(const struct dat8BitBmpHeader& header);
44+
~gdrv_bitmap8();
4245
ColorRgba* BmpBufPtr1;
4346
char* IndexedBmpPtr;
4447
int Width;
@@ -49,17 +52,13 @@ struct gdrv_bitmap8
4952
int XPosition;
5053
int YPosition;
5154
unsigned Resolution;
52-
//ColorRgba* RgbaBuffer;
5355
SDL_Texture* Texture;
5456
};
5557

5658

5759
class gdrv
5860
{
5961
public:
60-
static int create_bitmap(gdrv_bitmap8* bmp, int width, int height, int stride = -1, bool indexed = true);
61-
static int create_bitmap(gdrv_bitmap8& bmp, const struct dat8BitBmpHeader& header);
62-
static int destroy_bitmap(gdrv_bitmap8* bmp);
6362
static int display_palette(ColorRgba* plt);
6463
static void fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar);
6564
static void copy_bitmap(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff, gdrv_bitmap8* srcBmp,

SpaceCadetPinball/loader.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "pch.h"
22
#include "loader.h"
3-
#include "memory.h"
43
#include "GroupData.h"
54
#include "pb.h"
65
#include "pinball.h"

0 commit comments

Comments
 (0)