mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-11-25 04:02:30 +01:00
Replaced memory with new.
Cleaned up gdrv, zdrv, render.
This commit is contained in:
parent
dc5915b4f8
commit
93de90b680
@ -42,8 +42,6 @@ set(SOURCE_FILES
|
|||||||
SpaceCadetPinball/loader.h
|
SpaceCadetPinball/loader.h
|
||||||
SpaceCadetPinball/maths.cpp
|
SpaceCadetPinball/maths.cpp
|
||||||
SpaceCadetPinball/maths.h
|
SpaceCadetPinball/maths.h
|
||||||
SpaceCadetPinball/memory.cpp
|
|
||||||
SpaceCadetPinball/memory.h
|
|
||||||
SpaceCadetPinball/midi.cpp
|
SpaceCadetPinball/midi.cpp
|
||||||
SpaceCadetPinball/midi.h
|
SpaceCadetPinball/midi.h
|
||||||
SpaceCadetPinball/nudge.cpp
|
SpaceCadetPinball/nudge.cpp
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include "fullscrn.h"
|
#include "fullscrn.h"
|
||||||
#include "gdrv.h"
|
#include "gdrv.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "zdrv.h"
|
#include "zdrv.h"
|
||||||
|
|
||||||
|
|
||||||
@ -13,10 +12,15 @@ EntryData::~EntryData()
|
|||||||
if (Buffer)
|
if (Buffer)
|
||||||
{
|
{
|
||||||
if (EntryType == FieldTypes::Bitmap8bit)
|
if (EntryType == FieldTypes::Bitmap8bit)
|
||||||
gdrv::destroy_bitmap(reinterpret_cast<gdrv_bitmap8*>(Buffer));
|
{
|
||||||
|
delete reinterpret_cast<gdrv_bitmap8*>(Buffer);
|
||||||
|
}
|
||||||
else if (EntryType == FieldTypes::Bitmap16bit)
|
else if (EntryType == FieldTypes::Bitmap16bit)
|
||||||
zdrv::destroy_zmap(reinterpret_cast<zmap_header_type*>(Buffer));
|
{
|
||||||
memory::free(Buffer);
|
delete reinterpret_cast<zmap_header_type*>(Buffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
delete[] Buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,8 +44,8 @@ void GroupData::AddEntry(EntryData* entry)
|
|||||||
if (srcBmp->BitmapType == BitmapTypes::Spliced)
|
if (srcBmp->BitmapType == BitmapTypes::Spliced)
|
||||||
{
|
{
|
||||||
// Get rid of spliced bitmap early on, to simplify render pipeline
|
// Get rid of spliced bitmap early on, to simplify render pipeline
|
||||||
auto bmp = memory::allocate<gdrv_bitmap8>();
|
auto bmp = new gdrv_bitmap8(srcBmp->Width, srcBmp->Height, srcBmp->Width);
|
||||||
auto zMap = memory::allocate<zmap_header_type>();
|
auto zMap = new zmap_header_type(srcBmp->Width, srcBmp->Height, srcBmp->Width);
|
||||||
SplitSplicedBitmap(*srcBmp, *bmp, *zMap);
|
SplitSplicedBitmap(*srcBmp, *bmp, *zMap);
|
||||||
|
|
||||||
NeedsSort = true;
|
NeedsSort = true;
|
||||||
@ -97,13 +101,11 @@ void GroupData::SplitSplicedBitmap(const gdrv_bitmap8& srcBmp, gdrv_bitmap8& bmp
|
|||||||
{
|
{
|
||||||
assertm(srcBmp.BitmapType == BitmapTypes::Spliced, "GroupData: wrong bitmap type");
|
assertm(srcBmp.BitmapType == BitmapTypes::Spliced, "GroupData: wrong bitmap type");
|
||||||
|
|
||||||
gdrv::create_bitmap(&bmp, srcBmp.Width, srcBmp.Height, srcBmp.Width);
|
|
||||||
std::memset(bmp.IndexedBmpPtr, 0xff, bmp.Stride * bmp.Height);
|
std::memset(bmp.IndexedBmpPtr, 0xff, bmp.Stride * bmp.Height);
|
||||||
bmp.XPosition = srcBmp.XPosition;
|
bmp.XPosition = srcBmp.XPosition;
|
||||||
bmp.YPosition = srcBmp.YPosition;
|
bmp.YPosition = srcBmp.YPosition;
|
||||||
bmp.Resolution = srcBmp.Resolution;
|
bmp.Resolution = srcBmp.Resolution;
|
||||||
|
|
||||||
zdrv::create_zmap(&zMap, srcBmp.Width, srcBmp.Height, srcBmp.Width);
|
|
||||||
zdrv::fill(&zMap, zMap.Width, zMap.Height, 0, 0, 0xFFFF);
|
zdrv::fill(&zMap, zMap.Width, zMap.Height, 0, 0, 0xFFFF);
|
||||||
zMap.Resolution = srcBmp.Resolution;
|
zMap.Resolution = srcBmp.Resolution;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include "control.h"
|
#include "control.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "TPinballTable.h"
|
#include "TPinballTable.h"
|
||||||
|
|
||||||
@ -17,11 +16,11 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro
|
|||||||
float* floatArr = loader::query_float_attribute(groupIndex, 0, 904);
|
float* floatArr = loader::query_float_attribute(groupIndex, 0, 904);
|
||||||
if (floatArr)
|
if (floatArr)
|
||||||
{
|
{
|
||||||
int count = 2 * List.size();
|
auto count = 2 * List.size();
|
||||||
TimerTimeArray = memory::allocate<float>(count);
|
TimerTimeArray = new float[count];
|
||||||
if (TimerTimeArray)
|
if (TimerTimeArray)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count; ++floatArr)
|
for (auto i = 0u; i < count; ++floatArr)
|
||||||
TimerTimeArray[i++] = *floatArr;
|
TimerTimeArray[i++] = *floatArr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,8 +29,7 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro
|
|||||||
|
|
||||||
TLightBargraph::~TLightBargraph()
|
TLightBargraph::~TLightBargraph()
|
||||||
{
|
{
|
||||||
if (TimerTimeArray)
|
delete[] TimerTimeArray;
|
||||||
memory::free(TimerTimeArray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TLightBargraph::Message(int code, float value)
|
int TLightBargraph::Message(int code, float value)
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include "control.h"
|
#include "control.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
#include "pinball.h"
|
#include "pinball.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
@ -194,18 +193,18 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false)
|
|||||||
|
|
||||||
TPinballTable::~TPinballTable()
|
TPinballTable::~TPinballTable()
|
||||||
{
|
{
|
||||||
for (int scoreIndex = 0; scoreIndex < 4; scoreIndex++)
|
for (auto& PlayerScore : PlayerScores)
|
||||||
{
|
{
|
||||||
memory::free(PlayerScores[scoreIndex].ScoreStruct);
|
delete PlayerScore.ScoreStruct;
|
||||||
}
|
}
|
||||||
if (ScorePlayerNumber1)
|
if (ScorePlayerNumber1)
|
||||||
{
|
{
|
||||||
memory::free(ScorePlayerNumber1);
|
delete ScorePlayerNumber1;
|
||||||
ScorePlayerNumber1 = nullptr;
|
ScorePlayerNumber1 = nullptr;
|
||||||
}
|
}
|
||||||
if (ScoreBallcount)
|
if (ScoreBallcount)
|
||||||
{
|
{
|
||||||
memory::free(ScoreBallcount);
|
delete ScoreBallcount;
|
||||||
ScoreBallcount = nullptr;
|
ScoreBallcount = nullptr;
|
||||||
}
|
}
|
||||||
delete LightGroup;
|
delete LightGroup;
|
||||||
|
@ -75,7 +75,7 @@ void TTextBox::Clear()
|
|||||||
gdrv_bitmap8* bmp = BgBmp;
|
gdrv_bitmap8* bmp = BgBmp;
|
||||||
if (bmp)
|
if (bmp)
|
||||||
gdrv::copy_bitmap(
|
gdrv::copy_bitmap(
|
||||||
&render::vscreen,
|
render::vscreen,
|
||||||
Width,
|
Width,
|
||||||
Height,
|
Height,
|
||||||
OffsetX,
|
OffsetX,
|
||||||
@ -84,7 +84,7 @@ void TTextBox::Clear()
|
|||||||
OffsetX,
|
OffsetX,
|
||||||
OffsetY);
|
OffsetY);
|
||||||
else
|
else
|
||||||
gdrv::fill_bitmap(&render::vscreen, Width, Height, OffsetX, OffsetY, 0);
|
gdrv::fill_bitmap(render::vscreen, Width, Height, OffsetX, OffsetY, 0);
|
||||||
if (Timer)
|
if (Timer)
|
||||||
{
|
{
|
||||||
if (Timer != -1)
|
if (Timer != -1)
|
||||||
@ -149,7 +149,7 @@ void TTextBox::Draw()
|
|||||||
auto bmp = BgBmp;
|
auto bmp = BgBmp;
|
||||||
if (bmp)
|
if (bmp)
|
||||||
gdrv::copy_bitmap(
|
gdrv::copy_bitmap(
|
||||||
&render::vscreen,
|
render::vscreen,
|
||||||
Width,
|
Width,
|
||||||
Height,
|
Height,
|
||||||
OffsetX,
|
OffsetX,
|
||||||
@ -158,7 +158,7 @@ void TTextBox::Draw()
|
|||||||
OffsetX,
|
OffsetX,
|
||||||
OffsetY);
|
OffsetY);
|
||||||
else
|
else
|
||||||
gdrv::fill_bitmap(&render::vscreen, Width, Height, OffsetX, OffsetY, 0);
|
gdrv::fill_bitmap(render::vscreen, Width, Height, OffsetX, OffsetY, 0);
|
||||||
|
|
||||||
bool display = false;
|
bool display = false;
|
||||||
while (Message1)
|
while (Message1)
|
||||||
@ -191,8 +191,8 @@ void TTextBox::Draw()
|
|||||||
{
|
{
|
||||||
gdrv::grtext_draw_ttext_in_box(
|
gdrv::grtext_draw_ttext_in_box(
|
||||||
Message1->Text,
|
Message1->Text,
|
||||||
render::vscreen.XPosition + OffsetX,
|
render::vscreen->XPosition + OffsetX,
|
||||||
render::vscreen.YPosition + OffsetY,
|
render::vscreen->YPosition + OffsetY,
|
||||||
Width,
|
Width,
|
||||||
Height,
|
Height,
|
||||||
255);
|
255);
|
||||||
@ -245,10 +245,10 @@ void TTextBox::Draw()
|
|||||||
auto height = charBmp->Height;
|
auto height = charBmp->Height;
|
||||||
auto width = charBmp->Width;
|
auto width = charBmp->Width;
|
||||||
if (render::background_bitmap)
|
if (render::background_bitmap)
|
||||||
gdrv::copy_bitmap_w_transparency(&render::vscreen, width, height, offX, y, charBmp, 0,
|
gdrv::copy_bitmap_w_transparency(render::vscreen, width, height, offX, y, charBmp, 0,
|
||||||
0);
|
0);
|
||||||
else
|
else
|
||||||
gdrv::copy_bitmap(&render::vscreen, width, height, offX, y, charBmp, 0, 0);
|
gdrv::copy_bitmap(render::vscreen, width, height, offX, y, charBmp, 0, 0);
|
||||||
font = Font;
|
font = Font;
|
||||||
offX += charBmp->Width + font->GapWidth;
|
offX += charBmp->Width + font->GapWidth;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "TTextBoxMessage.h"
|
#include "TTextBoxMessage.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
|
|
||||||
TTextBoxMessage::TTextBoxMessage(char* text, float time)
|
TTextBoxMessage::TTextBoxMessage(char* text, float time)
|
||||||
@ -11,7 +10,7 @@ TTextBoxMessage::TTextBoxMessage(char* text, float time)
|
|||||||
if (text)
|
if (text)
|
||||||
{
|
{
|
||||||
const auto textLen = strlen(text) + 1;
|
const auto textLen = strlen(text) + 1;
|
||||||
Text = memory::allocate(textLen);
|
Text = new char[textLen];
|
||||||
if (Text)
|
if (Text)
|
||||||
strncpy(Text, text, textLen);
|
strncpy(Text, text, textLen);
|
||||||
}
|
}
|
||||||
@ -21,8 +20,7 @@ TTextBoxMessage::TTextBoxMessage(char* text, float time)
|
|||||||
|
|
||||||
TTextBoxMessage::~TTextBoxMessage()
|
TTextBoxMessage::~TTextBoxMessage()
|
||||||
{
|
{
|
||||||
if (Text)
|
delete[] Text;
|
||||||
memory::free(Text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float TTextBoxMessage::TimeLeft() const
|
float TTextBoxMessage::TimeLeft() const
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include "gdrv.h"
|
#include "gdrv.h"
|
||||||
|
|
||||||
#include "GroupData.h"
|
#include "GroupData.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "partman.h"
|
#include "partman.h"
|
||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
#include "score.h"
|
#include "score.h"
|
||||||
@ -10,77 +9,74 @@
|
|||||||
|
|
||||||
ColorRgba gdrv::current_palette[256]{};
|
ColorRgba gdrv::current_palette[256]{};
|
||||||
|
|
||||||
int gdrv::create_bitmap(gdrv_bitmap8* bmp, int width, int height, int stride, bool indexed)
|
gdrv_bitmap8::gdrv_bitmap8(int width, int height, bool indexed)
|
||||||
{
|
{
|
||||||
assertm(width >= 0 && height >= 0, "Negative bitmap8 dimensions");
|
assertm(width >= 0 && height >= 0, "Negative bitmap8 dimensions");
|
||||||
|
|
||||||
bmp->Width = width;
|
Width = width;
|
||||||
bmp->Height = height;
|
Height = height;
|
||||||
bmp->Stride = width;
|
Stride = width;
|
||||||
bmp->BitmapType = BitmapTypes::DibBitmap;
|
IndexedStride = width;
|
||||||
bmp->Texture = nullptr;
|
BitmapType = BitmapTypes::DibBitmap;
|
||||||
|
Texture = nullptr;
|
||||||
if (stride >= 0)
|
IndexedBmpPtr = nullptr;
|
||||||
bmp->IndexedStride = stride;
|
XPosition = 0;
|
||||||
else
|
YPosition = 0;
|
||||||
{
|
Resolution = 0;
|
||||||
bmp->IndexedStride = width;
|
|
||||||
if (width % 4)
|
|
||||||
bmp->IndexedStride = width - width % 4 + 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indexed)
|
if (indexed)
|
||||||
bmp->IndexedBmpPtr = memory::allocate(bmp->Height * bmp->IndexedStride);
|
IndexedBmpPtr = new char[Height * IndexedStride];
|
||||||
bmp->BmpBufPtr1 = memory::allocate<ColorRgba>(bmp->Height * bmp->Stride);
|
BmpBufPtr1 = new ColorRgba[Height * Stride];
|
||||||
if (bmp->BmpBufPtr1)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gdrv::create_bitmap(gdrv_bitmap8& bmp, const dat8BitBmpHeader& header)
|
gdrv_bitmap8::gdrv_bitmap8(const dat8BitBmpHeader& header)
|
||||||
{
|
{
|
||||||
assertm(header.Width >= 0 && header.Height >= 0, "Negative bitmap8 dimensions");
|
assertm(header.Width >= 0 && header.Height >= 0, "Negative bitmap8 dimensions");
|
||||||
|
|
||||||
if (header.IsFlagSet(bmp8Flags::Spliced))
|
if (header.IsFlagSet(bmp8Flags::Spliced))
|
||||||
bmp.BitmapType = BitmapTypes::Spliced;
|
BitmapType = BitmapTypes::Spliced;
|
||||||
else if (header.IsFlagSet(bmp8Flags::DibBitmap))
|
else if (header.IsFlagSet(bmp8Flags::DibBitmap))
|
||||||
bmp.BitmapType = BitmapTypes::DibBitmap;
|
BitmapType = BitmapTypes::DibBitmap;
|
||||||
else
|
else
|
||||||
bmp.BitmapType = BitmapTypes::RawBitmap;
|
BitmapType = BitmapTypes::RawBitmap;
|
||||||
|
|
||||||
bmp.Width = header.Width;
|
Width = header.Width;
|
||||||
bmp.Stride = header.Width;
|
Stride = header.Width;
|
||||||
bmp.IndexedStride = header.Width;
|
IndexedStride = header.Width;
|
||||||
bmp.Height = header.Height;
|
Height = header.Height;
|
||||||
bmp.XPosition = header.XPosition;
|
XPosition = header.XPosition;
|
||||||
bmp.YPosition = header.YPosition;
|
YPosition = header.YPosition;
|
||||||
bmp.Resolution = header.Resolution;
|
Resolution = header.Resolution;
|
||||||
bmp.Texture = nullptr;
|
Texture = nullptr;
|
||||||
|
|
||||||
int sizeInBytes;
|
int sizeInBytes;
|
||||||
if (bmp.BitmapType == BitmapTypes::Spliced)
|
if (BitmapType == BitmapTypes::Spliced)
|
||||||
{
|
{
|
||||||
sizeInBytes = header.Size;
|
sizeInBytes = header.Size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (bmp.BitmapType == BitmapTypes::RawBitmap)
|
if (BitmapType == BitmapTypes::RawBitmap)
|
||||||
assertm(bmp.Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag");
|
assertm(Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag");
|
||||||
if (bmp.Width % 4)
|
if (Width % 4)
|
||||||
bmp.IndexedStride = bmp.Width - bmp.Width % 4 + 4;
|
IndexedStride = Width - Width % 4 + 4;
|
||||||
sizeInBytes = bmp.Height * bmp.IndexedStride;
|
sizeInBytes = Height * IndexedStride;
|
||||||
assertm(sizeInBytes == header.Size, "Wrong bitmap8 size");
|
assertm(sizeInBytes == header.Size, "Wrong bitmap8 size");
|
||||||
}
|
}
|
||||||
|
|
||||||
bmp.IndexedBmpPtr = memory::allocate(sizeInBytes);
|
IndexedBmpPtr = new char[sizeInBytes];
|
||||||
bmp.BmpBufPtr1 = memory::allocate<ColorRgba>(bmp.Stride * bmp.Height);
|
BmpBufPtr1 = new ColorRgba[Stride * Height];
|
||||||
if (bmp.BmpBufPtr1)
|
}
|
||||||
|
|
||||||
|
gdrv_bitmap8::~gdrv_bitmap8()
|
||||||
|
{
|
||||||
|
if (BitmapType != BitmapTypes::None)
|
||||||
{
|
{
|
||||||
return 0;
|
delete[] BmpBufPtr1;
|
||||||
|
delete[] IndexedBmpPtr;
|
||||||
|
if (Texture)
|
||||||
|
SDL_DestroyTexture(Texture);
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gdrv::display_palette(ColorRgba* plt)
|
int gdrv::display_palette(ColorRgba* plt)
|
||||||
@ -139,24 +135,6 @@ int gdrv::display_palette(ColorRgba* plt)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int gdrv::destroy_bitmap(gdrv_bitmap8* bmp)
|
|
||||||
{
|
|
||||||
if (!bmp)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (bmp->BitmapType != BitmapTypes::None)
|
|
||||||
{
|
|
||||||
memory::free(bmp->BmpBufPtr1);
|
|
||||||
if (bmp->IndexedBmpPtr)
|
|
||||||
memory::free(bmp->IndexedBmpPtr);
|
|
||||||
if (bmp->Texture)
|
|
||||||
SDL_DestroyTexture(bmp->Texture);
|
|
||||||
}
|
|
||||||
memset(bmp, 0, sizeof(gdrv_bitmap8));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gdrv::fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar)
|
void gdrv::fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar)
|
||||||
{
|
{
|
||||||
auto color = current_palette[fillChar];
|
auto color = current_palette[fillChar];
|
||||||
|
@ -39,6 +39,9 @@ static_assert(sizeof(ColorRgba) == 4, "Wrong size of RGBA color");
|
|||||||
|
|
||||||
struct gdrv_bitmap8
|
struct gdrv_bitmap8
|
||||||
{
|
{
|
||||||
|
gdrv_bitmap8(int width, int height, bool indexed);
|
||||||
|
gdrv_bitmap8(const struct dat8BitBmpHeader& header);
|
||||||
|
~gdrv_bitmap8();
|
||||||
ColorRgba* BmpBufPtr1;
|
ColorRgba* BmpBufPtr1;
|
||||||
char* IndexedBmpPtr;
|
char* IndexedBmpPtr;
|
||||||
int Width;
|
int Width;
|
||||||
@ -49,7 +52,6 @@ struct gdrv_bitmap8
|
|||||||
int XPosition;
|
int XPosition;
|
||||||
int YPosition;
|
int YPosition;
|
||||||
unsigned Resolution;
|
unsigned Resolution;
|
||||||
//ColorRgba* RgbaBuffer;
|
|
||||||
SDL_Texture* Texture;
|
SDL_Texture* Texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,9 +59,6 @@ struct gdrv_bitmap8
|
|||||||
class gdrv
|
class gdrv
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int create_bitmap(gdrv_bitmap8* bmp, int width, int height, int stride = -1, bool indexed = true);
|
|
||||||
static int create_bitmap(gdrv_bitmap8& bmp, const struct dat8BitBmpHeader& header);
|
|
||||||
static int destroy_bitmap(gdrv_bitmap8* bmp);
|
|
||||||
static int display_palette(ColorRgba* plt);
|
static int display_palette(ColorRgba* plt);
|
||||||
static void fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar);
|
static void fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar);
|
||||||
static void copy_bitmap(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff, gdrv_bitmap8* srcBmp,
|
static void copy_bitmap(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff, gdrv_bitmap8* srcBmp,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "GroupData.h"
|
#include "GroupData.h"
|
||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
#include "pinball.h"
|
#include "pinball.h"
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "memory.h"
|
|
||||||
|
|
||||||
size_t memory::use_total;
|
|
||||||
int memory::critical_allocation;
|
|
||||||
void (*memory::critical_callback)();
|
|
||||||
std::map<void*, size_t> memory::alloc_map{};
|
|
||||||
|
|
||||||
void memory::init(void (*callback)())
|
|
||||||
{
|
|
||||||
critical_callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* memory::allocate(size_t size)
|
|
||||||
{
|
|
||||||
auto buf = static_cast<char*>(malloc(size));
|
|
||||||
if (!buf)
|
|
||||||
{
|
|
||||||
if (critical_allocation && critical_callback)
|
|
||||||
critical_callback();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
use_total += size;
|
|
||||||
alloc_map[buf] = size;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory::free(void* buf)
|
|
||||||
{
|
|
||||||
auto alloc = alloc_map.find(buf);
|
|
||||||
if (alloc == alloc_map.end())
|
|
||||||
{
|
|
||||||
assertm(false, "Unknown memory type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
use_total -= alloc->second;
|
|
||||||
std::free(alloc->first);
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
class memory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void init(void (*callback)(void));
|
|
||||||
static char* allocate(size_t size);
|
|
||||||
static void free(void* buf);
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static T* allocate(size_t count = 1, size_t add = 0)
|
|
||||||
{
|
|
||||||
size_t size = sizeof(T) * count + add;
|
|
||||||
auto buf = static_cast<T*>(malloc(size));
|
|
||||||
if (!buf)
|
|
||||||
{
|
|
||||||
if (critical_allocation && critical_callback)
|
|
||||||
critical_callback();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
use_total += size;
|
|
||||||
alloc_map[buf] = size;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static T* realloc(T* buf, size_t size)
|
|
||||||
{
|
|
||||||
if (!buf)
|
|
||||||
return reinterpret_cast<T*>(allocate(size));
|
|
||||||
|
|
||||||
auto alloc = alloc_map.find(buf);
|
|
||||||
if (alloc == alloc_map.end())
|
|
||||||
{
|
|
||||||
assertm(false, "Unknown memory type");
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto newBuf = static_cast<T*>(std::realloc(alloc->first, size));
|
|
||||||
if (!newBuf)
|
|
||||||
{
|
|
||||||
if (critical_allocation && critical_callback)
|
|
||||||
critical_callback();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
use_total += size - alloc->second;
|
|
||||||
alloc_map.erase(alloc);
|
|
||||||
alloc_map[newBuf] = size;
|
|
||||||
return newBuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t use_total;
|
|
||||||
static int critical_allocation;
|
|
||||||
private:
|
|
||||||
static void (*critical_callback)();
|
|
||||||
static std::map<void*, size_t> alloc_map;
|
|
||||||
};
|
|
@ -2,7 +2,6 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
#include "fullscrn.h"
|
#include "fullscrn.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "midi.h"
|
#include "midi.h"
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
#include "winmain.h"
|
#include "winmain.h"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
|
||||||
|
|
||||||
enum class Menu1:int
|
enum class Menu1:int
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "gdrv.h"
|
#include "gdrv.h"
|
||||||
#include "GroupData.h"
|
#include "GroupData.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "zdrv.h"
|
#include "zdrv.h"
|
||||||
|
|
||||||
short partman::_field_size[] =
|
short partman::_field_size[] =
|
||||||
@ -40,7 +39,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
|
|||||||
|
|
||||||
if (header.Unknown)
|
if (header.Unknown)
|
||||||
{
|
{
|
||||||
auto unknownBuf = memory::allocate(header.Unknown);
|
auto unknownBuf = new char[header.Unknown];
|
||||||
if (!unknownBuf)
|
if (!unknownBuf)
|
||||||
{
|
{
|
||||||
fclose(fileHandle);
|
fclose(fileHandle);
|
||||||
@ -48,7 +47,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
fread(unknownBuf, 1, header.Unknown, fileHandle);
|
fread(unknownBuf, 1, header.Unknown, fileHandle);
|
||||||
memory::free(unknownBuf);
|
delete[] unknownBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
datFile->Groups.reserve(header.NumberOfGroups);
|
datFile->Groups.reserve(header.NumberOfGroups);
|
||||||
@ -75,13 +74,8 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
|
|||||||
assertm(bmpHeader.Size + sizeof(dat8BitBmpHeader) == fieldSize, "partman: Wrong bitmap field size");
|
assertm(bmpHeader.Size + sizeof(dat8BitBmpHeader) == fieldSize, "partman: Wrong bitmap field size");
|
||||||
assertm(bmpHeader.Resolution <= 2, "partman: bitmap resolution out of bounds");
|
assertm(bmpHeader.Resolution <= 2, "partman: bitmap resolution out of bounds");
|
||||||
|
|
||||||
auto bmp = memory::allocate<gdrv_bitmap8>();
|
auto bmp = new gdrv_bitmap8(bmpHeader);
|
||||||
entryData->Buffer = reinterpret_cast<char*>(bmp);
|
entryData->Buffer = reinterpret_cast<char*>(bmp);
|
||||||
if (!bmp || gdrv::create_bitmap(*bmp, bmpHeader))
|
|
||||||
{
|
|
||||||
abort = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fread(bmp->IndexedBmpPtr, 1, bmpHeader.Size, fileHandle);
|
fread(bmp->IndexedBmpPtr, 1, bmpHeader.Size, fileHandle);
|
||||||
}
|
}
|
||||||
else if (entryType == FieldTypes::Bitmap16bit)
|
else if (entryType == FieldTypes::Bitmap16bit)
|
||||||
@ -98,8 +92,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
|
|||||||
fread(&zMapHeader, 1, sizeof(dat16BitBmpHeader), fileHandle);
|
fread(&zMapHeader, 1, sizeof(dat16BitBmpHeader), fileHandle);
|
||||||
auto length = fieldSize - sizeof(dat16BitBmpHeader);
|
auto length = fieldSize - sizeof(dat16BitBmpHeader);
|
||||||
|
|
||||||
auto zMap = memory::allocate<zmap_header_type>();
|
auto zMap = new zmap_header_type(zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride);
|
||||||
zdrv::create_zmap(zMap, zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride);
|
|
||||||
zMap->Resolution = zMapResolution;
|
zMap->Resolution = zMapResolution;
|
||||||
if (zMapHeader.Stride * zMapHeader.Height * 2u == length)
|
if (zMapHeader.Stride * zMapHeader.Height * 2u == length)
|
||||||
{
|
{
|
||||||
@ -114,7 +107,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char* entryBuffer = memory::allocate(fieldSize);
|
auto entryBuffer = new char[fieldSize];
|
||||||
entryData->Buffer = entryBuffer;
|
entryData->Buffer = entryBuffer;
|
||||||
if (!entryBuffer)
|
if (!entryBuffer)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "control.h"
|
#include "control.h"
|
||||||
#include "fullscrn.h"
|
#include "fullscrn.h"
|
||||||
#include "high_score.h"
|
#include "high_score.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "pinball.h"
|
#include "pinball.h"
|
||||||
#include "proj.h"
|
#include "proj.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
@ -40,7 +39,6 @@ int pb::init()
|
|||||||
{
|
{
|
||||||
float projMat[12], zMin = 0, zScaler = 0;
|
float projMat[12], zMin = 0, zScaler = 0;
|
||||||
|
|
||||||
++memory::critical_allocation;
|
|
||||||
auto dataFilePath = pinball::make_path_name(winmain::DatFileName);
|
auto dataFilePath = pinball::make_path_name(winmain::DatFileName);
|
||||||
record_table = partman::load_records(dataFilePath.c_str(), FullTiltMode);
|
record_table = partman::load_records(dataFilePath.c_str(), FullTiltMode);
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ int pb::init()
|
|||||||
|
|
||||||
render::init(nullptr, zMin, zScaler, resInfo->TableWidth, resInfo->TableHeight);
|
render::init(nullptr, zMin, zScaler, resInfo->TableWidth, resInfo->TableHeight);
|
||||||
gdrv::copy_bitmap(
|
gdrv::copy_bitmap(
|
||||||
&render::vscreen,
|
render::vscreen,
|
||||||
backgroundBmp->Width,
|
backgroundBmp->Width,
|
||||||
backgroundBmp->Height,
|
backgroundBmp->Height,
|
||||||
backgroundBmp->XPosition,
|
backgroundBmp->XPosition,
|
||||||
@ -101,7 +99,6 @@ int pb::init()
|
|||||||
|
|
||||||
high_score::read(highscore_table);
|
high_score::read(highscore_table);
|
||||||
ball_speed_limit = MainTable->BallList.at(0)->Offset * 200.0f;
|
ball_speed_limit = MainTable->BallList.at(0)->Offset * 200.0f;
|
||||||
--memory::critical_allocation;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,11 +468,6 @@ void pb::keydown(int key)
|
|||||||
strncpy(String1, pinball::get_rc_string(26, 0), sizeof String1 - 1);
|
strncpy(String1, pinball::get_rc_string(26, 0), sizeof String1 - 1);
|
||||||
high_score::show_and_set_high_score_dialog(highscore_table, 1000000000, 1, String1);
|
high_score::show_and_set_high_score_dialog(highscore_table, 1000000000, 1, String1);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
|
||||||
char buffer[20];
|
|
||||||
snprintf(buffer, sizeof buffer, "%zu", memory::use_total);
|
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Mem:", buffer, winmain::MainWindow);
|
|
||||||
break;
|
|
||||||
case 'r':
|
case 'r':
|
||||||
control::cheat_bump_rank();
|
control::cheat_bump_rank();
|
||||||
break;
|
break;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#define SDL_MAIN_HANDLED
|
#define SDL_MAIN_HANDLED
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "pinball.h"
|
#include "pinball.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "winmain.h"
|
#include "winmain.h"
|
||||||
|
|
||||||
// Todo: load translations from file
|
// Todo: load translations from file
|
||||||
|
@ -2,49 +2,43 @@
|
|||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
#include "GroupData.h"
|
#include "GroupData.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
#include "TPinballTable.h"
|
#include "TPinballTable.h"
|
||||||
#include "winmain.h"
|
#include "winmain.h"
|
||||||
|
|
||||||
int render::many_dirty, render::many_sprites, render::many_balls;
|
std::vector<render_sprite_type_struct*> render::dirty_list, render::sprite_list, render::ball_list;
|
||||||
render_sprite_type_struct **render::dirty_list, **render::sprite_list, **render::ball_list;
|
|
||||||
zmap_header_type* render::background_zmap;
|
zmap_header_type* render::background_zmap;
|
||||||
int render::zmap_offset, render::zmap_offsetY, render::offset_x, render::offset_y;
|
int render::zmap_offset, render::zmap_offsetY, render::offset_x, render::offset_y;
|
||||||
float render::zscaler, render::zmin, render::zmax;
|
float render::zscaler, render::zmin, render::zmax;
|
||||||
rectangle_type render::vscreen_rect;
|
rectangle_type render::vscreen_rect;
|
||||||
gdrv_bitmap8 render::vscreen, *render::background_bitmap, render::ball_bitmap[20];
|
gdrv_bitmap8 *render::vscreen, *render::background_bitmap, *render::ball_bitmap[20];
|
||||||
zmap_header_type render::zscreen;
|
zmap_header_type* render::zscreen;
|
||||||
SDL_Texture* render::vScreenTex = nullptr;
|
SDL_Texture* render::vScreenTex = nullptr;
|
||||||
SDL_Rect render::DestinationRect{};
|
SDL_Rect render::DestinationRect{};
|
||||||
|
|
||||||
void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height)
|
void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height)
|
||||||
{
|
{
|
||||||
++memory::critical_allocation;
|
|
||||||
zscaler = zScaler;
|
zscaler = zScaler;
|
||||||
zmin = zMin;
|
zmin = zMin;
|
||||||
zmax = 4294967300.0f / zScaler + zMin;
|
zmax = 4294967300.0f / zScaler + zMin;
|
||||||
sprite_list = memory::allocate<render_sprite_type_struct*>(1000);
|
vscreen = new gdrv_bitmap8(width, height, false);
|
||||||
dirty_list = memory::allocate<render_sprite_type_struct*>(1000);
|
zscreen = new zmap_header_type(width, height, width);
|
||||||
ball_list = memory::allocate<render_sprite_type_struct*>(20);
|
zdrv::fill(zscreen, zscreen->Width, zscreen->Height, 0, 0, 0xFFFF);
|
||||||
gdrv::create_bitmap(&vscreen, width, height, width, false);
|
|
||||||
zdrv::create_zmap(&zscreen, width, height);
|
|
||||||
zdrv::fill(&zscreen, zscreen.Width, zscreen.Height, 0, 0, 0xFFFF);
|
|
||||||
vscreen_rect.YPosition = 0;
|
vscreen_rect.YPosition = 0;
|
||||||
vscreen_rect.XPosition = 0;
|
vscreen_rect.XPosition = 0;
|
||||||
vscreen_rect.Width = width;
|
vscreen_rect.Width = width;
|
||||||
vscreen_rect.Height = height;
|
vscreen_rect.Height = height;
|
||||||
vscreen.YPosition = 0;
|
vscreen->YPosition = 0;
|
||||||
vscreen.XPosition = 0;
|
vscreen->XPosition = 0;
|
||||||
for (auto& ballBmp : ball_bitmap)
|
for (auto& ballBmp : ball_bitmap)
|
||||||
gdrv::create_bitmap(&ballBmp, 64, 64, 64, false);
|
ballBmp = new gdrv_bitmap8(64, 64, false);
|
||||||
|
|
||||||
background_bitmap = bmp;
|
background_bitmap = bmp;
|
||||||
if (bmp)
|
if (bmp)
|
||||||
gdrv::copy_bitmap(&vscreen, width, height, 0, 0, bmp, 0, 0);
|
gdrv::copy_bitmap(vscreen, width, height, 0, 0, bmp, 0, 0);
|
||||||
else
|
else
|
||||||
gdrv::fill_bitmap(&vscreen, vscreen.Width, vscreen.Height, 0, 0, 0);
|
gdrv::fill_bitmap(vscreen, vscreen->Width, vscreen->Height, 0, 0, 0);
|
||||||
|
|
||||||
{
|
{
|
||||||
UsingSdlHint hint{SDL_HINT_RENDER_SCALE_QUALITY, options::Options.LinearFiltering ? "linear" : "nearest"};
|
UsingSdlHint hint{SDL_HINT_RENDER_SCALE_QUALITY, options::Options.LinearFiltering ? "linear" : "nearest"};
|
||||||
@ -57,25 +51,21 @@ void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int h
|
|||||||
);
|
);
|
||||||
SDL_SetTextureBlendMode(vScreenTex, SDL_BLENDMODE_NONE);
|
SDL_SetTextureBlendMode(vScreenTex, SDL_BLENDMODE_NONE);
|
||||||
}
|
}
|
||||||
--memory::critical_allocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void render::uninit()
|
void render::uninit()
|
||||||
{
|
{
|
||||||
gdrv::destroy_bitmap(&vscreen);
|
delete vscreen;
|
||||||
zdrv::destroy_zmap(&zscreen);
|
delete zscreen;
|
||||||
for (auto i = many_sprites - 1; i >= 0; --i)
|
for (auto sprite : sprite_list)
|
||||||
remove_sprite(sprite_list[i]);
|
remove_sprite(sprite, false);
|
||||||
for (auto j = many_balls - 1; j >= 0; --j)
|
for (auto ball : ball_list)
|
||||||
remove_ball(ball_list[j]);
|
remove_ball(ball, false);
|
||||||
for (auto& ballBmp : ball_bitmap)
|
for (auto& ballBmp : ball_bitmap)
|
||||||
gdrv::destroy_bitmap(&ballBmp);
|
delete ballBmp;
|
||||||
memory::free(ball_list);
|
ball_list.clear();
|
||||||
memory::free(dirty_list);
|
dirty_list.clear();
|
||||||
memory::free(sprite_list);
|
sprite_list.clear();
|
||||||
many_sprites = 0;
|
|
||||||
many_dirty = 0;
|
|
||||||
many_balls = 0;
|
|
||||||
SDL_DestroyTexture(vScreenTex);
|
SDL_DestroyTexture(vScreenTex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +74,9 @@ void render::update()
|
|||||||
unpaint_balls();
|
unpaint_balls();
|
||||||
|
|
||||||
// Clip dirty sprites with vScreen, clear clipping (dirty) rectangles
|
// Clip dirty sprites with vScreen, clear clipping (dirty) rectangles
|
||||||
for (int index = 0; index < many_dirty; ++index)
|
for (auto curSprite : dirty_list)
|
||||||
{
|
{
|
||||||
bool clearSprite = false;
|
bool clearSprite = false;
|
||||||
auto curSprite = dirty_list[index];
|
|
||||||
switch (curSprite->VisualType)
|
switch (curSprite->VisualType)
|
||||||
{
|
{
|
||||||
case VisualTypes::Sprite:
|
case VisualTypes::Sprite:
|
||||||
@ -114,18 +103,17 @@ void render::update()
|
|||||||
auto width = curSprite->DirtyRect.Width;
|
auto width = curSprite->DirtyRect.Width;
|
||||||
auto xPos = curSprite->DirtyRect.XPosition;
|
auto xPos = curSprite->DirtyRect.XPosition;
|
||||||
auto height = curSprite->DirtyRect.Height;
|
auto height = curSprite->DirtyRect.Height;
|
||||||
zdrv::fill(&zscreen, width, height, xPos, yPos, 0xFFFF);
|
zdrv::fill(zscreen, width, height, xPos, yPos, 0xFFFF);
|
||||||
if (background_bitmap)
|
if (background_bitmap)
|
||||||
gdrv::copy_bitmap(&vscreen, width, height, xPos, yPos, background_bitmap, xPos, yPos);
|
gdrv::copy_bitmap(vscreen, width, height, xPos, yPos, background_bitmap, xPos, yPos);
|
||||||
else
|
else
|
||||||
gdrv::fill_bitmap(&vscreen, width, height, xPos, yPos, 0);
|
gdrv::fill_bitmap(vscreen, width, height, xPos, yPos, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Paint dirty rectangles of dirty sprites
|
// Paint dirty rectangles of dirty sprites
|
||||||
for (int index = 0; index < many_dirty; ++index)
|
for (auto sprite : dirty_list)
|
||||||
{
|
{
|
||||||
auto sprite = dirty_list[index];
|
|
||||||
if (sprite->DirtyRect.Width > 0 && (sprite->VisualType == VisualTypes::None || sprite->VisualType ==
|
if (sprite->DirtyRect.Width > 0 && (sprite->VisualType == VisualTypes::None || sprite->VisualType ==
|
||||||
VisualTypes::Sprite))
|
VisualTypes::Sprite))
|
||||||
repaint(sprite);
|
repaint(sprite);
|
||||||
@ -134,27 +122,26 @@ void render::update()
|
|||||||
paint_balls();
|
paint_balls();
|
||||||
|
|
||||||
// In the original, this used to blit dirty sprites and balls
|
// In the original, this used to blit dirty sprites and balls
|
||||||
for (int index = 0; index < many_dirty; ++index)
|
for (auto sprite : dirty_list)
|
||||||
{
|
{
|
||||||
auto sprite = dirty_list[index];
|
|
||||||
sprite->DirtyRectPrev = sprite->DirtyRect;
|
sprite->DirtyRectPrev = sprite->DirtyRect;
|
||||||
if (sprite->UnknownFlag != 0)
|
if (sprite->UnknownFlag != 0)
|
||||||
remove_sprite(sprite);
|
remove_sprite(sprite, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
many_dirty = 0;
|
dirty_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void render::sprite_modified(render_sprite_type_struct* sprite)
|
void render::sprite_modified(render_sprite_type_struct* sprite)
|
||||||
{
|
{
|
||||||
if (sprite->VisualType != VisualTypes::Ball && many_dirty < 999)
|
if (sprite->VisualType != VisualTypes::Ball && dirty_list.size() < 999)
|
||||||
dirty_list[many_dirty++] = sprite;
|
dirty_list.push_back(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp, zmap_header_type* zMap,
|
render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp, zmap_header_type* zMap,
|
||||||
int xPosition, int yPosition, rectangle_type* rect)
|
int xPosition, int yPosition, rectangle_type* rect)
|
||||||
{
|
{
|
||||||
auto sprite = memory::allocate<render_sprite_type_struct>();
|
auto sprite = new render_sprite_type_struct();
|
||||||
if (!sprite)
|
if (!sprite)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
sprite->BmpRect.YPosition = yPosition;
|
sprite->BmpRect.YPosition = yPosition;
|
||||||
@ -163,7 +150,6 @@ render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bi
|
|||||||
sprite->VisualType = visualType;
|
sprite->VisualType = visualType;
|
||||||
sprite->UnknownFlag = 0;
|
sprite->UnknownFlag = 0;
|
||||||
sprite->SpriteArray = nullptr;
|
sprite->SpriteArray = nullptr;
|
||||||
sprite->SpriteCount = 0;
|
|
||||||
sprite->DirtyRect = rectangle_type{};
|
sprite->DirtyRect = rectangle_type{};
|
||||||
if (rect)
|
if (rect)
|
||||||
{
|
{
|
||||||
@ -198,57 +184,41 @@ render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bi
|
|||||||
sprite->DirtyRectPrev = sprite->BmpRect;
|
sprite->DirtyRectPrev = sprite->BmpRect;
|
||||||
if (visualType == VisualTypes::Ball)
|
if (visualType == VisualTypes::Ball)
|
||||||
{
|
{
|
||||||
ball_list[many_balls++] = sprite;
|
ball_list.push_back(sprite);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprite_list[many_sprites++] = sprite;
|
sprite_list.push_back(sprite);
|
||||||
sprite_modified(sprite);
|
sprite_modified(sprite);
|
||||||
}
|
}
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void render::remove_sprite(render_sprite_type_struct* sprite)
|
void render::remove_sprite(render_sprite_type_struct* sprite, bool removeFromList)
|
||||||
{
|
{
|
||||||
int index = 0;
|
if (removeFromList)
|
||||||
if (many_sprites > 0)
|
|
||||||
{
|
{
|
||||||
while (sprite_list[index] != sprite)
|
auto it = std::find(sprite_list.begin(), sprite_list.end(), sprite);
|
||||||
{
|
if (it != sprite_list.end())
|
||||||
if (++index >= many_sprites)
|
sprite_list.erase(it);
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (index < many_sprites)
|
|
||||||
{
|
|
||||||
sprite_list[index] = sprite_list[index + 1];
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
many_sprites--;
|
|
||||||
if (sprite->SpriteArray)
|
|
||||||
memory::free(sprite->SpriteArray);
|
|
||||||
memory::free(sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete sprite->SpriteArray;
|
||||||
|
delete sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render::remove_ball(struct render_sprite_type_struct* ball)
|
void render::remove_ball(render_sprite_type_struct* ball, bool removeFromList)
|
||||||
{
|
{
|
||||||
int index = 0;
|
if (removeFromList)
|
||||||
if (many_balls > 0)
|
|
||||||
{
|
{
|
||||||
while (ball_list[index] != ball)
|
auto it = std::find(ball_list.begin(), ball_list.end(), ball);
|
||||||
{
|
if (it != ball_list.end())
|
||||||
if (++index >= many_balls)
|
ball_list.erase(it);
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (index < many_balls)
|
|
||||||
{
|
|
||||||
ball_list[index] = ball_list[index + 1];
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
many_balls--;
|
|
||||||
memory::free(ball);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete ball->SpriteArray;
|
||||||
|
delete ball;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render::sprite_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, zmap_header_type* zMap, int xPos,
|
void render::sprite_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, zmap_header_type* zMap, int xPos,
|
||||||
@ -322,19 +292,18 @@ void render::repaint(struct render_sprite_type_struct* sprite)
|
|||||||
rectangle_type clipRect{};
|
rectangle_type clipRect{};
|
||||||
if (!sprite->SpriteArray)
|
if (!sprite->SpriteArray)
|
||||||
return;
|
return;
|
||||||
for (int index = 0; index < sprite->SpriteCount; index++)
|
for (auto refSprite : *sprite->SpriteArray)
|
||||||
{
|
{
|
||||||
auto refSprite = sprite->SpriteArray[index];
|
|
||||||
if (!refSprite->UnknownFlag && refSprite->Bmp)
|
if (!refSprite->UnknownFlag && refSprite->Bmp)
|
||||||
{
|
{
|
||||||
if (maths::rectangle_clip(&refSprite->BmpRect, &sprite->DirtyRect, &clipRect))
|
if (maths::rectangle_clip(&refSprite->BmpRect, &sprite->DirtyRect, &clipRect))
|
||||||
zdrv::paint(
|
zdrv::paint(
|
||||||
clipRect.Width,
|
clipRect.Width,
|
||||||
clipRect.Height,
|
clipRect.Height,
|
||||||
&vscreen,
|
vscreen,
|
||||||
clipRect.XPosition,
|
clipRect.XPosition,
|
||||||
clipRect.YPosition,
|
clipRect.YPosition,
|
||||||
&zscreen,
|
zscreen,
|
||||||
clipRect.XPosition,
|
clipRect.XPosition,
|
||||||
clipRect.YPosition,
|
clipRect.YPosition,
|
||||||
refSprite->Bmp,
|
refSprite->Bmp,
|
||||||
@ -351,9 +320,9 @@ void render::repaint(struct render_sprite_type_struct* sprite)
|
|||||||
void render::paint_balls()
|
void render::paint_balls()
|
||||||
{
|
{
|
||||||
// Sort ball sprites by depth
|
// Sort ball sprites by depth
|
||||||
for (auto i = 0; i < many_balls; i++)
|
for (auto i = 0u; i < ball_list.size(); i++)
|
||||||
{
|
{
|
||||||
for (auto j = i; j < many_balls / 2; ++j)
|
for (auto j = i; j < ball_list.size() / 2; ++j)
|
||||||
{
|
{
|
||||||
auto ballA = ball_list[j];
|
auto ballA = ball_list[j];
|
||||||
auto ballB = ball_list[i];
|
auto ballB = ball_list[i];
|
||||||
@ -366,7 +335,7 @@ void render::paint_balls()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For balls that clip vScreen: save original vScreen contents and paint ball bitmap.
|
// For balls that clip vScreen: save original vScreen contents and paint ball bitmap.
|
||||||
for (auto index = 0; index < many_balls; ++index)
|
for (auto index = 0u; index < ball_list.size(); ++index)
|
||||||
{
|
{
|
||||||
auto ball = ball_list[index];
|
auto ball = ball_list[index];
|
||||||
auto dirty = &ball->DirtyRect;
|
auto dirty = &ball->DirtyRect;
|
||||||
@ -374,14 +343,14 @@ void render::paint_balls()
|
|||||||
{
|
{
|
||||||
int xPos = dirty->XPosition;
|
int xPos = dirty->XPosition;
|
||||||
int yPos = dirty->YPosition;
|
int yPos = dirty->YPosition;
|
||||||
gdrv::copy_bitmap(&ball_bitmap[index], dirty->Width, dirty->Height, 0, 0, &vscreen, xPos, yPos);
|
gdrv::copy_bitmap(ball_bitmap[index], dirty->Width, dirty->Height, 0, 0, vscreen, xPos, yPos);
|
||||||
zdrv::paint_flat(
|
zdrv::paint_flat(
|
||||||
dirty->Width,
|
dirty->Width,
|
||||||
dirty->Height,
|
dirty->Height,
|
||||||
&vscreen,
|
vscreen,
|
||||||
xPos,
|
xPos,
|
||||||
yPos,
|
yPos,
|
||||||
&zscreen,
|
zscreen,
|
||||||
xPos,
|
xPos,
|
||||||
yPos,
|
yPos,
|
||||||
ball->Bmp,
|
ball->Bmp,
|
||||||
@ -399,17 +368,17 @@ void render::paint_balls()
|
|||||||
void render::unpaint_balls()
|
void render::unpaint_balls()
|
||||||
{
|
{
|
||||||
// Restore portions of vScreen saved during previous paint_balls call.
|
// Restore portions of vScreen saved during previous paint_balls call.
|
||||||
for (int index = many_balls - 1; index >= 0; index--)
|
for (int index = static_cast<int>(ball_list.size()) - 1; index >= 0; index--)
|
||||||
{
|
{
|
||||||
auto curBall = ball_list[index];
|
auto curBall = ball_list[index];
|
||||||
if (curBall->DirtyRect.Width > 0)
|
if (curBall->DirtyRect.Width > 0)
|
||||||
gdrv::copy_bitmap(
|
gdrv::copy_bitmap(
|
||||||
&vscreen,
|
vscreen,
|
||||||
curBall->DirtyRect.Width,
|
curBall->DirtyRect.Width,
|
||||||
curBall->DirtyRect.Height,
|
curBall->DirtyRect.Height,
|
||||||
curBall->DirtyRect.XPosition,
|
curBall->DirtyRect.XPosition,
|
||||||
curBall->DirtyRect.YPosition,
|
curBall->DirtyRect.YPosition,
|
||||||
&ball_bitmap[index],
|
ball_bitmap[index],
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
@ -425,51 +394,42 @@ void render::shift(int offsetX, int offsetY)
|
|||||||
|
|
||||||
void render::build_occlude_list()
|
void render::build_occlude_list()
|
||||||
{
|
{
|
||||||
++memory::critical_allocation;
|
std::vector<render_sprite_type_struct*>* spriteArr = nullptr;
|
||||||
render_sprite_type_struct** spriteArr = nullptr;
|
for (auto mainSprite : sprite_list)
|
||||||
for (int index = 0; index < many_sprites; ++index)
|
|
||||||
{
|
{
|
||||||
auto mainSprite = sprite_list[index];
|
|
||||||
if (mainSprite->SpriteArray)
|
if (mainSprite->SpriteArray)
|
||||||
{
|
{
|
||||||
memory::free(mainSprite->SpriteArray);
|
delete mainSprite->SpriteArray;
|
||||||
mainSprite->SpriteArray = nullptr;
|
mainSprite->SpriteArray = nullptr;
|
||||||
mainSprite->SpriteCount = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mainSprite->UnknownFlag && mainSprite->BoundingRect.Width != -1)
|
if (!mainSprite->UnknownFlag && mainSprite->BoundingRect.Width != -1)
|
||||||
{
|
{
|
||||||
if (!spriteArr)
|
if (!spriteArr)
|
||||||
spriteArr = memory::allocate<render_sprite_type_struct*>(1000);
|
spriteArr = new std::vector<render_sprite_type_struct*>();
|
||||||
|
|
||||||
int occludeCount = 0;
|
for (auto refSprite : sprite_list)
|
||||||
for (int i = 0; i < many_sprites; ++i)
|
|
||||||
{
|
{
|
||||||
auto refSprite = sprite_list[i];
|
|
||||||
if (!refSprite->UnknownFlag
|
if (!refSprite->UnknownFlag
|
||||||
&& refSprite->BoundingRect.Width != -1
|
&& refSprite->BoundingRect.Width != -1
|
||||||
&& maths::rectangle_clip(&mainSprite->BoundingRect, &refSprite->BoundingRect, nullptr)
|
&& maths::rectangle_clip(&mainSprite->BoundingRect, &refSprite->BoundingRect, nullptr)
|
||||||
&& spriteArr)
|
&& spriteArr)
|
||||||
{
|
{
|
||||||
spriteArr[occludeCount++] = refSprite;
|
spriteArr->push_back(refSprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mainSprite->UnknownFlag && mainSprite->Bmp && occludeCount < 2)
|
if (!mainSprite->UnknownFlag && mainSprite->Bmp && spriteArr->size() < 2)
|
||||||
occludeCount = 0;
|
spriteArr->clear();
|
||||||
if (occludeCount)
|
if (!spriteArr->empty())
|
||||||
{
|
{
|
||||||
mainSprite->SpriteArray = memory::realloc(spriteArr, sizeof(void*) * occludeCount);
|
mainSprite->SpriteArray = spriteArr;
|
||||||
mainSprite->SpriteCount = occludeCount;
|
|
||||||
spriteArr = nullptr;
|
spriteArr = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spriteArr)
|
delete spriteArr;
|
||||||
memory::free(spriteArr);
|
|
||||||
|
|
||||||
--memory::critical_allocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void render::SpriteViewer(bool* show)
|
void render::SpriteViewer(bool* show)
|
||||||
@ -575,23 +535,23 @@ void render::BlitVScreen()
|
|||||||
reinterpret_cast<void**>(&lockedPixels),
|
reinterpret_cast<void**>(&lockedPixels),
|
||||||
&pitch
|
&pitch
|
||||||
);
|
);
|
||||||
assertm(static_cast<unsigned>(pitch) == vscreen.Width * sizeof(ColorRgba), "Padding on vScreen texture");
|
assertm(static_cast<unsigned>(pitch) == vscreen->Width * sizeof(ColorRgba), "Padding on vScreen texture");
|
||||||
|
|
||||||
if (offset_x == 0 && offset_y == 0)
|
if (offset_x == 0 && offset_y == 0)
|
||||||
{
|
{
|
||||||
// No offset - direct copy
|
// No offset - direct copy
|
||||||
std::memcpy(lockedPixels, vscreen.BmpBufPtr1, vscreen.Width * vscreen.Height * sizeof(ColorRgba));
|
std::memcpy(lockedPixels, vscreen->BmpBufPtr1, vscreen->Width * vscreen->Height * sizeof(ColorRgba));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Copy offset table and fixed side bar
|
// Copy offset table and fixed side bar
|
||||||
auto tableWidth = pb::MainTable->Width;
|
auto tableWidth = pb::MainTable->Width;
|
||||||
auto scoreWidth = vscreen.Width - pb::MainTable->Width;
|
auto scoreWidth = vscreen->Width - pb::MainTable->Width;
|
||||||
auto tableStride = tableWidth * sizeof(ColorRgba);
|
auto tableStride = tableWidth * sizeof(ColorRgba);
|
||||||
auto scoreStride = scoreWidth * sizeof(ColorRgba);
|
auto scoreStride = scoreWidth * sizeof(ColorRgba);
|
||||||
auto srcScorePtr = &vscreen.BmpBufPtr1[tableWidth];
|
auto srcScorePtr = &vscreen->BmpBufPtr1[tableWidth];
|
||||||
|
|
||||||
auto xSrc = 0, ySrc = 0, xDst = offset_x, yDst = offset_y, height = vscreen.Height;
|
auto xSrc = 0, ySrc = 0, xDst = offset_x, yDst = offset_y, height = vscreen->Height;
|
||||||
|
|
||||||
// Negative dst == positive src offset
|
// Negative dst == positive src offset
|
||||||
if (xDst < 0)
|
if (xDst < 0)
|
||||||
@ -618,8 +578,8 @@ void render::BlitVScreen()
|
|||||||
if (ySrc)
|
if (ySrc)
|
||||||
height -= ySrc;
|
height -= ySrc;
|
||||||
|
|
||||||
auto srcBmpPtr = &vscreen.BmpBufPtr1[vscreen.Width * ySrc + xSrc];
|
auto srcBmpPtr = &vscreen->BmpBufPtr1[vscreen->Width * ySrc + xSrc];
|
||||||
auto dstPtr = &lockedPixels[vscreen.Width * yDst + xDst];
|
auto dstPtr = &lockedPixels[vscreen->Width * yDst + xDst];
|
||||||
for (int y = height; y > 0; --y)
|
for (int y = height; y > 0; --y)
|
||||||
{
|
{
|
||||||
std::memcpy(dstPtr, srcBmpPtr, tableStride);
|
std::memcpy(dstPtr, srcBmpPtr, tableStride);
|
||||||
@ -627,8 +587,8 @@ void render::BlitVScreen()
|
|||||||
std::memcpy(dstPtr, srcScorePtr, scoreStride);
|
std::memcpy(dstPtr, srcScorePtr, scoreStride);
|
||||||
dstPtr += scoreWidth;
|
dstPtr += scoreWidth;
|
||||||
|
|
||||||
srcBmpPtr += vscreen.Stride;
|
srcBmpPtr += vscreen->Stride;
|
||||||
srcScorePtr += vscreen.Stride;
|
srcScorePtr += vscreen->Stride;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ struct render_sprite_type_struct
|
|||||||
int ZMapOffestY;
|
int ZMapOffestY;
|
||||||
int ZMapOffestX;
|
int ZMapOffestX;
|
||||||
rectangle_type DirtyRect;
|
rectangle_type DirtyRect;
|
||||||
render_sprite_type_struct** SpriteArray;
|
std::vector<render_sprite_type_struct*>* SpriteArray;
|
||||||
int SpriteCount;
|
|
||||||
rectangle_type BoundingRect;
|
rectangle_type BoundingRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ struct render_sprite_type_struct
|
|||||||
class render
|
class render
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static gdrv_bitmap8 vscreen, *background_bitmap;
|
static gdrv_bitmap8 *vscreen, *background_bitmap;
|
||||||
static SDL_Rect DestinationRect;
|
static SDL_Rect DestinationRect;
|
||||||
|
|
||||||
static void init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height);
|
static void init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height);
|
||||||
@ -41,26 +40,25 @@ public:
|
|||||||
static render_sprite_type_struct* create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp,
|
static render_sprite_type_struct* create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp,
|
||||||
zmap_header_type* zMap,
|
zmap_header_type* zMap,
|
||||||
int xPosition, int yPosition, rectangle_type* rect);
|
int xPosition, int yPosition, rectangle_type* rect);
|
||||||
static void remove_sprite(render_sprite_type_struct* sprite);
|
static void remove_sprite(render_sprite_type_struct* sprite, bool removeFromList);
|
||||||
static void remove_ball(struct render_sprite_type_struct* ball);
|
static void remove_ball(render_sprite_type_struct* ball, bool removeFromList);
|
||||||
static void sprite_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, zmap_header_type* zMap, int xPos,
|
static void sprite_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, zmap_header_type* zMap, int xPos,
|
||||||
int yPos);
|
int yPos);
|
||||||
static void sprite_set_bitmap(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp);
|
static void sprite_set_bitmap(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp);
|
||||||
static void set_background_zmap(struct zmap_header_type* zMap, int offsetX, int offsetY);
|
static void set_background_zmap(struct zmap_header_type* zMap, int offsetX, int offsetY);
|
||||||
static void ball_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, float depth, int xPos, int yPos);
|
static void ball_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, float depth, int xPos, int yPos);
|
||||||
static void shift(int offsetX, int offsetY);
|
static void shift(int offsetX, int offsetY);
|
||||||
static void build_occlude_list();
|
static void build_occlude_list();
|
||||||
static void SpriteViewer(bool* show);
|
static void SpriteViewer(bool* show);
|
||||||
static void PresentVScreen();
|
static void PresentVScreen();
|
||||||
private:
|
private:
|
||||||
static int many_dirty, many_sprites, many_balls;
|
static std::vector<render_sprite_type_struct*> dirty_list, sprite_list, ball_list;
|
||||||
static render_sprite_type_struct **dirty_list, **sprite_list, **ball_list;
|
|
||||||
static zmap_header_type* background_zmap;
|
static zmap_header_type* background_zmap;
|
||||||
static int zmap_offset, zmap_offsetY, offset_x, offset_y;
|
static int zmap_offset, zmap_offsetY, offset_x, offset_y;
|
||||||
static float zscaler, zmin, zmax;
|
static float zscaler, zmin, zmax;
|
||||||
static rectangle_type vscreen_rect;
|
static rectangle_type vscreen_rect;
|
||||||
static gdrv_bitmap8 ball_bitmap[20];
|
static gdrv_bitmap8 *ball_bitmap[20];
|
||||||
static zmap_header_type zscreen;
|
static zmap_header_type* zscreen;
|
||||||
static SDL_Texture* vScreenTex;
|
static SDL_Texture* vScreenTex;
|
||||||
|
|
||||||
static void repaint(struct render_sprite_type_struct* sprite);
|
static void repaint(struct render_sprite_type_struct* sprite);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "EmbeddedData.h"
|
#include "EmbeddedData.h"
|
||||||
#include "fullscrn.h"
|
#include "fullscrn.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "GroupData.h"
|
#include "GroupData.h"
|
||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
@ -19,7 +18,7 @@ int score::init()
|
|||||||
|
|
||||||
scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
|
scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
|
||||||
{
|
{
|
||||||
auto score = memory::allocate<scoreStruct>();
|
auto score = new scoreStruct();
|
||||||
if (!score)
|
if (!score)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
score->Score = -9999;
|
score->Score = -9999;
|
||||||
@ -31,7 +30,7 @@ scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
|
|||||||
FieldTypes::ShortArray));
|
FieldTypes::ShortArray));
|
||||||
if (!dimensions)
|
if (!dimensions)
|
||||||
{
|
{
|
||||||
memory::free(score);
|
delete score;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
int groupIndex = *dimensions++;
|
int groupIndex = *dimensions++;
|
||||||
@ -50,10 +49,7 @@ scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
|
|||||||
|
|
||||||
scoreStruct* score::dup(scoreStruct* score, int scoreIndex)
|
scoreStruct* score::dup(scoreStruct* score, int scoreIndex)
|
||||||
{
|
{
|
||||||
auto result = memory::allocate<scoreStruct>();
|
return new scoreStruct(*score);
|
||||||
if (result)
|
|
||||||
memcpy(result, score, sizeof(scoreStruct));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void score::load_msg_font(LPCSTR lpName)
|
void score::load_msg_font(LPCSTR lpName)
|
||||||
@ -73,7 +69,7 @@ void score::load_msg_font_3DPB(LPCSTR lpName)
|
|||||||
auto rcData = reinterpret_cast<int16_t*>(ImFontAtlas::DecompressCompressedBase85Data(
|
auto rcData = reinterpret_cast<int16_t*>(ImFontAtlas::DecompressCompressedBase85Data(
|
||||||
EmbeddedData::PB_MSGFT_bin_compressed_data_base85));
|
EmbeddedData::PB_MSGFT_bin_compressed_data_base85));
|
||||||
|
|
||||||
auto fontp = memory::allocate<score_msg_font_type>();
|
auto fontp = new score_msg_font_type();
|
||||||
msg_fontp = fontp;
|
msg_fontp = fontp;
|
||||||
if (!fontp)
|
if (!fontp)
|
||||||
{
|
{
|
||||||
@ -91,10 +87,10 @@ void score::load_msg_font_3DPB(LPCSTR lpName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto height = rcData[2];
|
auto height = rcData[2];
|
||||||
auto tmpCharBur = memory::allocate(maxWidth * height + 4);
|
auto tmpCharBur = new char[maxWidth * height + 4];
|
||||||
if (!tmpCharBur)
|
if (!tmpCharBur)
|
||||||
{
|
{
|
||||||
memory::free(msg_fontp);
|
delete msg_fontp;
|
||||||
msg_fontp = nullptr;
|
msg_fontp = nullptr;
|
||||||
IM_FREE(rcData);
|
IM_FREE(rcData);
|
||||||
return;
|
return;
|
||||||
@ -111,19 +107,8 @@ void score::load_msg_font_3DPB(LPCSTR lpName)
|
|||||||
if (!width)
|
if (!width)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto bmp = memory::allocate<gdrv_bitmap8>();
|
auto bmp = new gdrv_bitmap8(width, height, true);
|
||||||
msg_fontp->Chars[charInd] = bmp;
|
msg_fontp->Chars[charInd] = bmp;
|
||||||
if (!bmp)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gdrv::create_bitmap(bmp, width, height, width))
|
|
||||||
{
|
|
||||||
memory::free(bmp);
|
|
||||||
msg_fontp->Chars[charInd] = nullptr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto sizeInBytes = height * width + 1;
|
auto sizeInBytes = height * width + 1;
|
||||||
memcpy(tmpCharBur + 3, ptrToData, sizeInBytes);
|
memcpy(tmpCharBur + 3, ptrToData, sizeInBytes);
|
||||||
@ -139,7 +124,7 @@ void score::load_msg_font_3DPB(LPCSTR lpName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memory::free(tmpCharBur);
|
delete[] tmpCharBur;
|
||||||
IM_FREE(rcData);
|
IM_FREE(rcData);
|
||||||
if (charInd != 128)
|
if (charInd != 128)
|
||||||
unload_msg_font();
|
unload_msg_font();
|
||||||
@ -152,7 +137,7 @@ void score::load_msg_font_FT(LPCSTR lpName)
|
|||||||
int groupIndex = pb::record_table->record_labeled(lpName);
|
int groupIndex = pb::record_table->record_labeled(lpName);
|
||||||
if (groupIndex < 0)
|
if (groupIndex < 0)
|
||||||
return;
|
return;
|
||||||
msg_fontp = reinterpret_cast<score_msg_font_type*>(memory::allocate(sizeof(score_msg_font_type)));
|
msg_fontp = new score_msg_font_type();
|
||||||
if (!msg_fontp)
|
if (!msg_fontp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -179,15 +164,11 @@ void score::unload_msg_font()
|
|||||||
{
|
{
|
||||||
/*3DBP creates bitmaps, FT just references them from partman*/
|
/*3DBP creates bitmaps, FT just references them from partman*/
|
||||||
if (!pb::FullTiltMode)
|
if (!pb::FullTiltMode)
|
||||||
for (int i = 0; i < 128; i++)
|
for (auto& Char : msg_fontp->Chars)
|
||||||
{
|
{
|
||||||
if (msg_fontp->Chars[i])
|
delete Char;
|
||||||
{
|
|
||||||
gdrv::destroy_bitmap(msg_fontp->Chars[i]);
|
|
||||||
memory::free(msg_fontp->Chars[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
memory::free(msg_fontp);
|
delete msg_fontp;
|
||||||
msg_fontp = nullptr;
|
msg_fontp = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,7 +179,7 @@ void score::erase(scoreStruct* score, int blitFlag)
|
|||||||
{
|
{
|
||||||
if (score->BackgroundBmp)
|
if (score->BackgroundBmp)
|
||||||
gdrv::copy_bitmap(
|
gdrv::copy_bitmap(
|
||||||
&render::vscreen,
|
render::vscreen,
|
||||||
score->Width,
|
score->Width,
|
||||||
score->Height,
|
score->Height,
|
||||||
score->OffsetX,
|
score->OffsetX,
|
||||||
@ -207,7 +188,7 @@ void score::erase(scoreStruct* score, int blitFlag)
|
|||||||
score->OffsetX,
|
score->OffsetX,
|
||||||
score->OffsetY);
|
score->OffsetY);
|
||||||
else
|
else
|
||||||
gdrv::fill_bitmap(&render::vscreen, score->Width, score->Height, score->OffsetX, score->OffsetY, 0);
|
gdrv::fill_bitmap(render::vscreen, score->Width, score->Height, score->OffsetX, score->OffsetY, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,9 +223,9 @@ void score::update(scoreStruct* score)
|
|||||||
int height = bmp->Height;
|
int height = bmp->Height;
|
||||||
int width = bmp->Width;
|
int width = bmp->Width;
|
||||||
if (render::background_bitmap)
|
if (render::background_bitmap)
|
||||||
gdrv::copy_bitmap_w_transparency(&render::vscreen, width, height, x, y, bmp, 0, 0);
|
gdrv::copy_bitmap_w_transparency(render::vscreen, width, height, x, y, bmp, 0, 0);
|
||||||
else
|
else
|
||||||
gdrv::copy_bitmap(&render::vscreen, width, height, x, y, bmp, 0, 0);
|
gdrv::copy_bitmap(render::vscreen, width, height, x, y, bmp, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
#include "memory.h"
|
|
||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
|
|
||||||
int timer::SetCount;
|
int timer::SetCount;
|
||||||
@ -13,7 +12,7 @@ timer_struct* timer::TimerBuffer;
|
|||||||
|
|
||||||
int timer::init(int count)
|
int timer::init(int count)
|
||||||
{
|
{
|
||||||
auto buf = memory::allocate<timer_struct>(count);
|
auto buf = new timer_struct[count];
|
||||||
TimerBuffer = buf;
|
TimerBuffer = buf;
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return 1;
|
return 1;
|
||||||
@ -32,8 +31,7 @@ int timer::init(int count)
|
|||||||
|
|
||||||
void timer::uninit()
|
void timer::uninit()
|
||||||
{
|
{
|
||||||
if (TimerBuffer)
|
delete[] TimerBuffer;
|
||||||
memory::free(TimerBuffer);
|
|
||||||
TimerBuffer = nullptr;
|
TimerBuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include "winmain.h"
|
#include "winmain.h"
|
||||||
|
|
||||||
#include "fullscrn.h"
|
#include "fullscrn.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "midi.h"
|
#include "midi.h"
|
||||||
#include "pinball.h"
|
#include "pinball.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
@ -28,7 +27,7 @@ int winmain::no_time_loss;
|
|||||||
|
|
||||||
bool winmain::restart = false;
|
bool winmain::restart = false;
|
||||||
|
|
||||||
gdrv_bitmap8 winmain::gfr_display{};
|
gdrv_bitmap8* winmain::gfr_display = nullptr;
|
||||||
std::string winmain::DatFileName;
|
std::string winmain::DatFileName;
|
||||||
bool winmain::ShowAboutDialog = false;
|
bool winmain::ShowAboutDialog = false;
|
||||||
bool winmain::ShowImGuiDemo = false;
|
bool winmain::ShowImGuiDemo = false;
|
||||||
@ -46,7 +45,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
restart = false;
|
restart = false;
|
||||||
bQuit = false;
|
bQuit = false;
|
||||||
|
|
||||||
memory::init(memalloc_failure);
|
std::set_new_handler(memalloc_failure);
|
||||||
|
|
||||||
// SDL init
|
// SDL init
|
||||||
SDL_SetMainReady();
|
SDL_SetMainReady();
|
||||||
@ -117,8 +116,6 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
|
|
||||||
// PB init from message handler
|
// PB init from message handler
|
||||||
{
|
{
|
||||||
++memory::critical_allocation;
|
|
||||||
|
|
||||||
options::init();
|
options::init();
|
||||||
auto voiceCount = options::get_int("Voices", 8);
|
auto voiceCount = options::get_int("Voices", 8);
|
||||||
if (Sound::Init(voiceCount))
|
if (Sound::Init(voiceCount))
|
||||||
@ -136,8 +133,6 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fullscrn::init();
|
fullscrn::init();
|
||||||
|
|
||||||
--memory::critical_allocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pb::reset_table();
|
pb::reset_table();
|
||||||
@ -182,7 +177,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
|
|
||||||
if (DispGRhistory)
|
if (DispGRhistory)
|
||||||
{
|
{
|
||||||
if (!gfr_display.BmpBufPtr1)
|
if (!gfr_display)
|
||||||
{
|
{
|
||||||
auto plt = static_cast<ColorRgba*>(malloc(1024u));
|
auto plt = static_cast<ColorRgba*>(malloc(1024u));
|
||||||
auto pltPtr = &plt[10];
|
auto pltPtr = &plt[10];
|
||||||
@ -199,14 +194,14 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
}
|
}
|
||||||
gdrv::display_palette(plt);
|
gdrv::display_palette(plt);
|
||||||
free(plt);
|
free(plt);
|
||||||
gdrv::create_bitmap(&gfr_display, 400, 15, 400, false);
|
gfr_display = new gdrv_bitmap8(400, 15, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dtHistoryCounter)
|
if (!dtHistoryCounter)
|
||||||
{
|
{
|
||||||
dtHistoryCounter = 300;
|
dtHistoryCounter = 300;
|
||||||
gdrv::copy_bitmap(&render::vscreen, 300, 10, 0, 30, &gfr_display, 0, 0);
|
gdrv::copy_bitmap(render::vscreen, 300, 10, 0, 30, gfr_display, 0, 0);
|
||||||
gdrv::fill_bitmap(&gfr_display, 300, 10, 0, 0, 0);
|
gdrv::fill_bitmap(gfr_display, 300, 10, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +222,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
auto deltaT = static_cast<int>(frameDuration);
|
auto deltaT = static_cast<int>(frameDuration);
|
||||||
frameDuration -= deltaT;
|
frameDuration -= deltaT;
|
||||||
pb::frame(deltaT);
|
pb::frame(deltaT);
|
||||||
if (gfr_display.BmpBufPtr1)
|
if (gfr_display)
|
||||||
{
|
{
|
||||||
auto deltaTPal = deltaT + 10;
|
auto deltaTPal = deltaT + 10;
|
||||||
auto fillChar = static_cast<uint8_t>(deltaTPal);
|
auto fillChar = static_cast<uint8_t>(deltaTPal);
|
||||||
@ -235,7 +230,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
{
|
{
|
||||||
fillChar = 1;
|
fillChar = 1;
|
||||||
}
|
}
|
||||||
gdrv::fill_bitmap(&gfr_display, 1, 10, 300 - dtHistoryCounter, 0, fillChar);
|
gdrv::fill_bitmap(gfr_display, 1, 10, 300 - dtHistoryCounter, 0, fillChar);
|
||||||
--dtHistoryCounter;
|
--dtHistoryCounter;
|
||||||
}
|
}
|
||||||
updateCounter++;
|
updateCounter++;
|
||||||
@ -289,7 +284,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gdrv::destroy_bitmap(&gfr_display);
|
delete gfr_display;
|
||||||
options::uninit();
|
options::uninit();
|
||||||
midi::music_shutdown();
|
midi::music_shutdown();
|
||||||
pb::uninit();
|
pb::uninit();
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
|
|
||||||
static int WinMain(LPCSTR lpCmdLine);
|
static int WinMain(LPCSTR lpCmdLine);
|
||||||
static int event_handler(const SDL_Event* event);
|
static int event_handler(const SDL_Event* event);
|
||||||
static void memalloc_failure();
|
[[ noreturn ]] static void memalloc_failure();
|
||||||
static int ProcessWindowMessages();
|
static int ProcessWindowMessages();
|
||||||
static void a_dialog();
|
static void a_dialog();
|
||||||
static void end_pause();
|
static void end_pause();
|
||||||
@ -64,7 +64,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static int return_value, bQuit, DispFrameRate, DispGRhistory, activated;
|
static int return_value, bQuit, DispFrameRate, DispGRhistory, activated;
|
||||||
static int has_focus, mouse_down, last_mouse_x, last_mouse_y, no_time_loss;
|
static int has_focus, mouse_down, last_mouse_x, last_mouse_y, no_time_loss;
|
||||||
static gdrv_bitmap8 gfr_display;
|
static gdrv_bitmap8* gfr_display;
|
||||||
static std::string FpsDetails;
|
static std::string FpsDetails;
|
||||||
static bool restart;
|
static bool restart;
|
||||||
static bool ShowAboutDialog;
|
static bool ShowAboutDialog;
|
||||||
|
@ -1,21 +1,26 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "zdrv.h"
|
#include "zdrv.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "winmain.h"
|
#include "winmain.h"
|
||||||
|
|
||||||
|
|
||||||
int zdrv::create_zmap(zmap_header_type* zmap, int width, int height, int stride)
|
zmap_header_type::zmap_header_type(int width, int height, int stride)
|
||||||
{
|
{
|
||||||
zmap->Width = width;
|
Resolution = 0;
|
||||||
zmap->Height = height;
|
Width = width;
|
||||||
zmap->Stride = stride >= 0 ? stride : pad(width);
|
Height = height;
|
||||||
zmap->Texture = nullptr;
|
Stride = stride >= 0 ? stride : pad(width);
|
||||||
|
Texture = nullptr;
|
||||||
zmap->ZPtr1 = memory::allocate<unsigned short>(zmap->Stride * zmap->Height);
|
ZPtr1 = new unsigned short[Stride * Height];
|
||||||
return zmap->ZPtr1 ? 0 : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int zdrv::pad(int width)
|
zmap_header_type::~zmap_header_type()
|
||||||
|
{
|
||||||
|
delete[] ZPtr1;
|
||||||
|
if (Texture)
|
||||||
|
SDL_DestroyTexture(Texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
int zmap_header_type::pad(int width)
|
||||||
{
|
{
|
||||||
int result = width;
|
int result = width;
|
||||||
if (width & 3)
|
if (width & 3)
|
||||||
@ -23,17 +28,6 @@ int zdrv::pad(int width)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zdrv::destroy_zmap(zmap_header_type* zmap)
|
|
||||||
{
|
|
||||||
if (!zmap)
|
|
||||||
return -1;
|
|
||||||
if (zmap->ZPtr1)
|
|
||||||
memory::free(zmap->ZPtr1);
|
|
||||||
if (zmap->Texture)
|
|
||||||
SDL_DestroyTexture(zmap->Texture);
|
|
||||||
memset(zmap, 0, sizeof(zmap_header_type));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zdrv::fill(zmap_header_type* zmap, int width, int height, int xOff, int yOff, uint16_t fillWord)
|
void zdrv::fill(zmap_header_type* zmap, int width, int height, int xOff, int yOff, uint16_t fillWord)
|
||||||
{
|
{
|
||||||
|
@ -3,20 +3,21 @@
|
|||||||
|
|
||||||
struct zmap_header_type
|
struct zmap_header_type
|
||||||
{
|
{
|
||||||
|
zmap_header_type(int width, int height, int stride);
|
||||||
|
~zmap_header_type();
|
||||||
int Width;
|
int Width;
|
||||||
int Height;
|
int Height;
|
||||||
int Stride;
|
int Stride;
|
||||||
unsigned Resolution;
|
unsigned Resolution;
|
||||||
uint16_t* ZPtr1;
|
uint16_t* ZPtr1;
|
||||||
SDL_Texture* Texture;
|
SDL_Texture* Texture;
|
||||||
|
private:
|
||||||
|
static int pad(int width);
|
||||||
};
|
};
|
||||||
|
|
||||||
class zdrv
|
class zdrv
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int pad(int width);
|
|
||||||
static int create_zmap(zmap_header_type* zmap, int width, int height, int stride = -1);
|
|
||||||
static int destroy_zmap(zmap_header_type* zmap);
|
|
||||||
static void fill(zmap_header_type* zmap, int width, int height, int xOff, int yOff, uint16_t fillWord);
|
static void fill(zmap_header_type* zmap, int width, int height, int xOff, int yOff, uint16_t fillWord);
|
||||||
static void paint(int width, int height, gdrv_bitmap8* dstBmp, int dstBmpXOff, int dstBmpYOff,
|
static void paint(int width, int height, gdrv_bitmap8* dstBmp, int dstBmpXOff, int dstBmpYOff,
|
||||||
zmap_header_type* dstZMap, int dstZMapXOff, int dstZMapYOff, gdrv_bitmap8* srcBmp, int srcBmpXOff,
|
zmap_header_type* dstZMap, int dstZMapXOff, int dstZMapYOff, gdrv_bitmap8* srcBmp, int srcBmpXOff,
|
||||||
|
Loading…
Reference in New Issue
Block a user