1
0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-21 18:22:40 +01:00

Replaced memory with new.

Cleaned up gdrv, zdrv, render.
This commit is contained in:
oz 2021-10-02 17:45:31 +03:00
parent dc5915b4f8
commit 93de90b680
25 changed files with 220 additions and 439 deletions

View File

@ -42,8 +42,6 @@ set(SOURCE_FILES
SpaceCadetPinball/loader.h
SpaceCadetPinball/maths.cpp
SpaceCadetPinball/maths.h
SpaceCadetPinball/memory.cpp
SpaceCadetPinball/memory.h
SpaceCadetPinball/midi.cpp
SpaceCadetPinball/midi.h
SpaceCadetPinball/nudge.cpp

View File

@ -4,7 +4,6 @@
#include "fullscrn.h"
#include "gdrv.h"
#include "memory.h"
#include "zdrv.h"
@ -13,10 +12,15 @@ EntryData::~EntryData()
if (Buffer)
{
if (EntryType == FieldTypes::Bitmap8bit)
gdrv::destroy_bitmap(reinterpret_cast<gdrv_bitmap8*>(Buffer));
{
delete reinterpret_cast<gdrv_bitmap8*>(Buffer);
}
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)
{
// Get rid of spliced bitmap early on, to simplify render pipeline
auto bmp = memory::allocate<gdrv_bitmap8>();
auto zMap = memory::allocate<zmap_header_type>();
auto bmp = new gdrv_bitmap8(srcBmp->Width, srcBmp->Height, srcBmp->Width);
auto zMap = new zmap_header_type(srcBmp->Width, srcBmp->Height, srcBmp->Width);
SplitSplicedBitmap(*srcBmp, *bmp, *zMap);
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");
gdrv::create_bitmap(&bmp, srcBmp.Width, srcBmp.Height, srcBmp.Width);
std::memset(bmp.IndexedBmpPtr, 0xff, bmp.Stride * bmp.Height);
bmp.XPosition = srcBmp.XPosition;
bmp.YPosition = srcBmp.YPosition;
bmp.Resolution = srcBmp.Resolution;
zdrv::create_zmap(&zMap, srcBmp.Width, srcBmp.Height, srcBmp.Width);
zdrv::fill(&zMap, zMap.Width, zMap.Height, 0, 0, 0xFFFF);
zMap.Resolution = srcBmp.Resolution;

View File

@ -4,7 +4,6 @@
#include "control.h"
#include "loader.h"
#include "memory.h"
#include "timer.h"
#include "TPinballTable.h"
@ -17,11 +16,11 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro
float* floatArr = loader::query_float_attribute(groupIndex, 0, 904);
if (floatArr)
{
int count = 2 * List.size();
TimerTimeArray = memory::allocate<float>(count);
auto count = 2 * List.size();
TimerTimeArray = new float[count];
if (TimerTimeArray)
{
for (int i = 0; i < count; ++floatArr)
for (auto i = 0u; i < count; ++floatArr)
TimerTimeArray[i++] = *floatArr;
}
}
@ -30,8 +29,7 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro
TLightBargraph::~TLightBargraph()
{
if (TimerTimeArray)
memory::free(TimerTimeArray);
delete[] TimerTimeArray;
}
int TLightBargraph::Message(int code, float value)

View File

@ -4,7 +4,6 @@
#include "control.h"
#include "loader.h"
#include "memory.h"
#include "pb.h"
#include "pinball.h"
#include "render.h"
@ -194,18 +193,18 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false)
TPinballTable::~TPinballTable()
{
for (int scoreIndex = 0; scoreIndex < 4; scoreIndex++)
for (auto& PlayerScore : PlayerScores)
{
memory::free(PlayerScores[scoreIndex].ScoreStruct);
delete PlayerScore.ScoreStruct;
}
if (ScorePlayerNumber1)
{
memory::free(ScorePlayerNumber1);
delete ScorePlayerNumber1;
ScorePlayerNumber1 = nullptr;
}
if (ScoreBallcount)
{
memory::free(ScoreBallcount);
delete ScoreBallcount;
ScoreBallcount = nullptr;
}
delete LightGroup;

View File

@ -75,7 +75,7 @@ void TTextBox::Clear()
gdrv_bitmap8* bmp = BgBmp;
if (bmp)
gdrv::copy_bitmap(
&render::vscreen,
render::vscreen,
Width,
Height,
OffsetX,
@ -84,7 +84,7 @@ void TTextBox::Clear()
OffsetX,
OffsetY);
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 != -1)
@ -149,7 +149,7 @@ void TTextBox::Draw()
auto bmp = BgBmp;
if (bmp)
gdrv::copy_bitmap(
&render::vscreen,
render::vscreen,
Width,
Height,
OffsetX,
@ -158,7 +158,7 @@ void TTextBox::Draw()
OffsetX,
OffsetY);
else
gdrv::fill_bitmap(&render::vscreen, Width, Height, OffsetX, OffsetY, 0);
gdrv::fill_bitmap(render::vscreen, Width, Height, OffsetX, OffsetY, 0);
bool display = false;
while (Message1)
@ -191,8 +191,8 @@ void TTextBox::Draw()
{
gdrv::grtext_draw_ttext_in_box(
Message1->Text,
render::vscreen.XPosition + OffsetX,
render::vscreen.YPosition + OffsetY,
render::vscreen->XPosition + OffsetX,
render::vscreen->YPosition + OffsetY,
Width,
Height,
255);
@ -245,10 +245,10 @@ void TTextBox::Draw()
auto height = charBmp->Height;
auto width = charBmp->Width;
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);
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;
offX += charBmp->Width + font->GapWidth;
}

View File

@ -1,6 +1,5 @@
#include "pch.h"
#include "TTextBoxMessage.h"
#include "memory.h"
#include "pb.h"
TTextBoxMessage::TTextBoxMessage(char* text, float time)
@ -11,7 +10,7 @@ TTextBoxMessage::TTextBoxMessage(char* text, float time)
if (text)
{
const auto textLen = strlen(text) + 1;
Text = memory::allocate(textLen);
Text = new char[textLen];
if (Text)
strncpy(Text, text, textLen);
}
@ -21,8 +20,7 @@ TTextBoxMessage::TTextBoxMessage(char* text, float time)
TTextBoxMessage::~TTextBoxMessage()
{
if (Text)
memory::free(Text);
delete[] Text;
}
float TTextBoxMessage::TimeLeft() const

View File

@ -2,7 +2,6 @@
#include "gdrv.h"
#include "GroupData.h"
#include "memory.h"
#include "partman.h"
#include "pb.h"
#include "score.h"
@ -10,77 +9,74 @@
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");
bmp->Width = width;
bmp->Height = height;
bmp->Stride = width;
bmp->BitmapType = BitmapTypes::DibBitmap;
bmp->Texture = nullptr;
if (stride >= 0)
bmp->IndexedStride = stride;
else
{
bmp->IndexedStride = width;
if (width % 4)
bmp->IndexedStride = width - width % 4 + 4;
}
Width = width;
Height = height;
Stride = width;
IndexedStride = width;
BitmapType = BitmapTypes::DibBitmap;
Texture = nullptr;
IndexedBmpPtr = nullptr;
XPosition = 0;
YPosition = 0;
Resolution = 0;
if (indexed)
bmp->IndexedBmpPtr = memory::allocate(bmp->Height * bmp->IndexedStride);
bmp->BmpBufPtr1 = memory::allocate<ColorRgba>(bmp->Height * bmp->Stride);
if (bmp->BmpBufPtr1)
{
return 0;
}
return -1;
IndexedBmpPtr = new char[Height * IndexedStride];
BmpBufPtr1 = new ColorRgba[Height * Stride];
}
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");
if (header.IsFlagSet(bmp8Flags::Spliced))
bmp.BitmapType = BitmapTypes::Spliced;
BitmapType = BitmapTypes::Spliced;
else if (header.IsFlagSet(bmp8Flags::DibBitmap))
bmp.BitmapType = BitmapTypes::DibBitmap;
BitmapType = BitmapTypes::DibBitmap;
else
bmp.BitmapType = BitmapTypes::RawBitmap;
BitmapType = BitmapTypes::RawBitmap;
bmp.Width = header.Width;
bmp.Stride = header.Width;
bmp.IndexedStride = header.Width;
bmp.Height = header.Height;
bmp.XPosition = header.XPosition;
bmp.YPosition = header.YPosition;
bmp.Resolution = header.Resolution;
bmp.Texture = nullptr;
Width = header.Width;
Stride = header.Width;
IndexedStride = header.Width;
Height = header.Height;
XPosition = header.XPosition;
YPosition = header.YPosition;
Resolution = header.Resolution;
Texture = nullptr;
int sizeInBytes;
if (bmp.BitmapType == BitmapTypes::Spliced)
if (BitmapType == BitmapTypes::Spliced)
{
sizeInBytes = header.Size;
}
else
{
if (bmp.BitmapType == BitmapTypes::RawBitmap)
assertm(bmp.Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag");
if (bmp.Width % 4)
bmp.IndexedStride = bmp.Width - bmp.Width % 4 + 4;
sizeInBytes = bmp.Height * bmp.IndexedStride;
if (BitmapType == BitmapTypes::RawBitmap)
assertm(Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag");
if (Width % 4)
IndexedStride = Width - Width % 4 + 4;
sizeInBytes = Height * IndexedStride;
assertm(sizeInBytes == header.Size, "Wrong bitmap8 size");
}
bmp.IndexedBmpPtr = memory::allocate(sizeInBytes);
bmp.BmpBufPtr1 = memory::allocate<ColorRgba>(bmp.Stride * bmp.Height);
if (bmp.BmpBufPtr1)
IndexedBmpPtr = new char[sizeInBytes];
BmpBufPtr1 = new ColorRgba[Stride * Height];
}
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)
@ -139,24 +135,6 @@ int gdrv::display_palette(ColorRgba* plt)
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)
{
auto color = current_palette[fillChar];

View File

@ -39,6 +39,9 @@ static_assert(sizeof(ColorRgba) == 4, "Wrong size of RGBA color");
struct gdrv_bitmap8
{
gdrv_bitmap8(int width, int height, bool indexed);
gdrv_bitmap8(const struct dat8BitBmpHeader& header);
~gdrv_bitmap8();
ColorRgba* BmpBufPtr1;
char* IndexedBmpPtr;
int Width;
@ -49,7 +52,6 @@ struct gdrv_bitmap8
int XPosition;
int YPosition;
unsigned Resolution;
//ColorRgba* RgbaBuffer;
SDL_Texture* Texture;
};
@ -57,9 +59,6 @@ struct gdrv_bitmap8
class gdrv
{
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 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,

View File

@ -1,6 +1,5 @@
#include "pch.h"
#include "loader.h"
#include "memory.h"
#include "GroupData.h"
#include "pb.h"
#include "pinball.h"

View File

@ -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);
}

View File

@ -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;
};

View File

@ -2,7 +2,6 @@
#include "options.h"
#include "fullscrn.h"
#include "memory.h"
#include "midi.h"
#include "Sound.h"
#include "winmain.h"

View File

@ -1,5 +1,4 @@
#pragma once
#include <map>
enum class Menu1:int
{

View File

@ -3,7 +3,6 @@
#include "gdrv.h"
#include "GroupData.h"
#include "memory.h"
#include "zdrv.h"
short partman::_field_size[] =
@ -40,7 +39,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
if (header.Unknown)
{
auto unknownBuf = memory::allocate(header.Unknown);
auto unknownBuf = new char[header.Unknown];
if (!unknownBuf)
{
fclose(fileHandle);
@ -48,7 +47,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
return nullptr;
}
fread(unknownBuf, 1, header.Unknown, fileHandle);
memory::free(unknownBuf);
delete[] unknownBuf;
}
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.Resolution <= 2, "partman: bitmap resolution out of bounds");
auto bmp = memory::allocate<gdrv_bitmap8>();
entryData->Buffer = reinterpret_cast<char*>(bmp);
if (!bmp || gdrv::create_bitmap(*bmp, bmpHeader))
{
abort = true;
break;
}
auto bmp = new gdrv_bitmap8(bmpHeader);
entryData->Buffer = reinterpret_cast<char*>(bmp);
fread(bmp->IndexedBmpPtr, 1, bmpHeader.Size, fileHandle);
}
else if (entryType == FieldTypes::Bitmap16bit)
@ -98,8 +92,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
fread(&zMapHeader, 1, sizeof(dat16BitBmpHeader), fileHandle);
auto length = fieldSize - sizeof(dat16BitBmpHeader);
auto zMap = memory::allocate<zmap_header_type>();
zdrv::create_zmap(zMap, zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride);
auto zMap = new zmap_header_type(zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride);
zMap->Resolution = zMapResolution;
if (zMapHeader.Stride * zMapHeader.Height * 2u == length)
{
@ -114,7 +107,7 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
}
else
{
char* entryBuffer = memory::allocate(fieldSize);
auto entryBuffer = new char[fieldSize];
entryData->Buffer = entryBuffer;
if (!entryBuffer)
{

View File

@ -5,7 +5,6 @@
#include "control.h"
#include "fullscrn.h"
#include "high_score.h"
#include "memory.h"
#include "pinball.h"
#include "proj.h"
#include "render.h"
@ -40,7 +39,6 @@ int pb::init()
{
float projMat[12], zMin = 0, zScaler = 0;
++memory::critical_allocation;
auto dataFilePath = pinball::make_path_name(winmain::DatFileName);
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);
gdrv::copy_bitmap(
&render::vscreen,
render::vscreen,
backgroundBmp->Width,
backgroundBmp->Height,
backgroundBmp->XPosition,
@ -101,7 +99,6 @@ int pb::init()
high_score::read(highscore_table);
ball_speed_limit = MainTable->BallList.at(0)->Offset * 200.0f;
--memory::critical_allocation;
return 0;
}
@ -471,11 +468,6 @@ void pb::keydown(int key)
strncpy(String1, pinball::get_rc_string(26, 0), sizeof String1 - 1);
high_score::show_and_set_high_score_dialog(highscore_table, 1000000000, 1, String1);
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':
control::cheat_bump_rank();
break;

View File

@ -28,6 +28,7 @@
#include <cstring>
#include <string>
#include <thread>
#include <map>
#define SDL_MAIN_HANDLED
#include "SDL.h"

View File

@ -1,6 +1,5 @@
#include "pch.h"
#include "pinball.h"
#include "memory.h"
#include "winmain.h"
// Todo: load translations from file

View File

@ -2,49 +2,43 @@
#include "render.h"
#include "GroupData.h"
#include "memory.h"
#include "options.h"
#include "pb.h"
#include "TPinballTable.h"
#include "winmain.h"
int render::many_dirty, render::many_sprites, render::many_balls;
render_sprite_type_struct **render::dirty_list, **render::sprite_list, **render::ball_list;
std::vector<render_sprite_type_struct*> render::dirty_list, render::sprite_list, render::ball_list;
zmap_header_type* render::background_zmap;
int render::zmap_offset, render::zmap_offsetY, render::offset_x, render::offset_y;
float render::zscaler, render::zmin, render::zmax;
rectangle_type render::vscreen_rect;
gdrv_bitmap8 render::vscreen, *render::background_bitmap, render::ball_bitmap[20];
zmap_header_type render::zscreen;
gdrv_bitmap8 *render::vscreen, *render::background_bitmap, *render::ball_bitmap[20];
zmap_header_type* render::zscreen;
SDL_Texture* render::vScreenTex = nullptr;
SDL_Rect render::DestinationRect{};
void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height)
{
++memory::critical_allocation;
zscaler = zScaler;
zmin = zMin;
zmax = 4294967300.0f / zScaler + zMin;
sprite_list = memory::allocate<render_sprite_type_struct*>(1000);
dirty_list = memory::allocate<render_sprite_type_struct*>(1000);
ball_list = memory::allocate<render_sprite_type_struct*>(20);
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 = new gdrv_bitmap8(width, height, false);
zscreen = new zmap_header_type(width, height, width);
zdrv::fill(zscreen, zscreen->Width, zscreen->Height, 0, 0, 0xFFFF);
vscreen_rect.YPosition = 0;
vscreen_rect.XPosition = 0;
vscreen_rect.Width = width;
vscreen_rect.Height = height;
vscreen.YPosition = 0;
vscreen.XPosition = 0;
vscreen->YPosition = 0;
vscreen->XPosition = 0;
for (auto& ballBmp : ball_bitmap)
gdrv::create_bitmap(&ballBmp, 64, 64, 64, false);
ballBmp = new gdrv_bitmap8(64, 64, false);
background_bitmap = 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
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"};
@ -57,25 +51,21 @@ void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int h
);
SDL_SetTextureBlendMode(vScreenTex, SDL_BLENDMODE_NONE);
}
--memory::critical_allocation;
}
void render::uninit()
{
gdrv::destroy_bitmap(&vscreen);
zdrv::destroy_zmap(&zscreen);
for (auto i = many_sprites - 1; i >= 0; --i)
remove_sprite(sprite_list[i]);
for (auto j = many_balls - 1; j >= 0; --j)
remove_ball(ball_list[j]);
delete vscreen;
delete zscreen;
for (auto sprite : sprite_list)
remove_sprite(sprite, false);
for (auto ball : ball_list)
remove_ball(ball, false);
for (auto& ballBmp : ball_bitmap)
gdrv::destroy_bitmap(&ballBmp);
memory::free(ball_list);
memory::free(dirty_list);
memory::free(sprite_list);
many_sprites = 0;
many_dirty = 0;
many_balls = 0;
delete ballBmp;
ball_list.clear();
dirty_list.clear();
sprite_list.clear();
SDL_DestroyTexture(vScreenTex);
}
@ -84,10 +74,9 @@ void render::update()
unpaint_balls();
// 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;
auto curSprite = dirty_list[index];
switch (curSprite->VisualType)
{
case VisualTypes::Sprite:
@ -114,18 +103,17 @@ void render::update()
auto width = curSprite->DirtyRect.Width;
auto xPos = curSprite->DirtyRect.XPosition;
auto height = curSprite->DirtyRect.Height;
zdrv::fill(&zscreen, width, height, xPos, yPos, 0xFFFF);
zdrv::fill(zscreen, width, height, xPos, yPos, 0xFFFF);
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
gdrv::fill_bitmap(&vscreen, width, height, xPos, yPos, 0);
gdrv::fill_bitmap(vscreen, width, height, xPos, yPos, 0);
}
}
// 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 ==
VisualTypes::Sprite))
repaint(sprite);
@ -134,27 +122,26 @@ void render::update()
paint_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;
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)
{
if (sprite->VisualType != VisualTypes::Ball && many_dirty < 999)
dirty_list[many_dirty++] = sprite;
if (sprite->VisualType != VisualTypes::Ball && dirty_list.size() < 999)
dirty_list.push_back(sprite);
}
render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp, zmap_header_type* zMap,
int xPosition, int yPosition, rectangle_type* rect)
{
auto sprite = memory::allocate<render_sprite_type_struct>();
auto sprite = new render_sprite_type_struct();
if (!sprite)
return nullptr;
sprite->BmpRect.YPosition = yPosition;
@ -163,7 +150,6 @@ render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bi
sprite->VisualType = visualType;
sprite->UnknownFlag = 0;
sprite->SpriteArray = nullptr;
sprite->SpriteCount = 0;
sprite->DirtyRect = rectangle_type{};
if (rect)
{
@ -198,57 +184,41 @@ render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bi
sprite->DirtyRectPrev = sprite->BmpRect;
if (visualType == VisualTypes::Ball)
{
ball_list[many_balls++] = sprite;
ball_list.push_back(sprite);
}
else
{
sprite_list[many_sprites++] = sprite;
sprite_list.push_back(sprite);
sprite_modified(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 (many_sprites > 0)
if (removeFromList)
{
while (sprite_list[index] != sprite)
{
if (++index >= many_sprites)
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);
auto it = std::find(sprite_list.begin(), sprite_list.end(), sprite);
if (it != sprite_list.end())
sprite_list.erase(it);
}
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 (many_balls > 0)
if (removeFromList)
{
while (ball_list[index] != ball)
{
if (++index >= many_balls)
return;
}
while (index < many_balls)
{
ball_list[index] = ball_list[index + 1];
++index;
}
many_balls--;
memory::free(ball);
auto it = std::find(ball_list.begin(), ball_list.end(), ball);
if (it != ball_list.end())
ball_list.erase(it);
}
delete ball->SpriteArray;
delete ball;
}
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{};
if (!sprite->SpriteArray)
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 (maths::rectangle_clip(&refSprite->BmpRect, &sprite->DirtyRect, &clipRect))
zdrv::paint(
clipRect.Width,
clipRect.Height,
&vscreen,
vscreen,
clipRect.XPosition,
clipRect.YPosition,
&zscreen,
zscreen,
clipRect.XPosition,
clipRect.YPosition,
refSprite->Bmp,
@ -351,9 +320,9 @@ void render::repaint(struct render_sprite_type_struct* sprite)
void render::paint_balls()
{
// 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 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 (auto index = 0; index < many_balls; ++index)
for (auto index = 0u; index < ball_list.size(); ++index)
{
auto ball = ball_list[index];
auto dirty = &ball->DirtyRect;
@ -374,14 +343,14 @@ void render::paint_balls()
{
int xPos = dirty->XPosition;
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(
dirty->Width,
dirty->Height,
&vscreen,
vscreen,
xPos,
yPos,
&zscreen,
zscreen,
xPos,
yPos,
ball->Bmp,
@ -399,17 +368,17 @@ void render::paint_balls()
void render::unpaint_balls()
{
// 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];
if (curBall->DirtyRect.Width > 0)
gdrv::copy_bitmap(
&vscreen,
vscreen,
curBall->DirtyRect.Width,
curBall->DirtyRect.Height,
curBall->DirtyRect.XPosition,
curBall->DirtyRect.YPosition,
&ball_bitmap[index],
ball_bitmap[index],
0,
0);
@ -425,51 +394,42 @@ void render::shift(int offsetX, int offsetY)
void render::build_occlude_list()
{
++memory::critical_allocation;
render_sprite_type_struct** spriteArr = nullptr;
for (int index = 0; index < many_sprites; ++index)
std::vector<render_sprite_type_struct*>* spriteArr = nullptr;
for (auto mainSprite : sprite_list)
{
auto mainSprite = sprite_list[index];
if (mainSprite->SpriteArray)
{
memory::free(mainSprite->SpriteArray);
delete mainSprite->SpriteArray;
mainSprite->SpriteArray = nullptr;
mainSprite->SpriteCount = 0;
}
if (!mainSprite->UnknownFlag && mainSprite->BoundingRect.Width != -1)
{
if (!spriteArr)
spriteArr = memory::allocate<render_sprite_type_struct*>(1000);
spriteArr = new std::vector<render_sprite_type_struct*>();
int occludeCount = 0;
for (int i = 0; i < many_sprites; ++i)
for (auto refSprite : sprite_list)
{
auto refSprite = sprite_list[i];
if (!refSprite->UnknownFlag
&& refSprite->BoundingRect.Width != -1
&& maths::rectangle_clip(&mainSprite->BoundingRect, &refSprite->BoundingRect, nullptr)
&& spriteArr)
{
spriteArr[occludeCount++] = refSprite;
spriteArr->push_back(refSprite);
}
}
if (!mainSprite->UnknownFlag && mainSprite->Bmp && occludeCount < 2)
occludeCount = 0;
if (occludeCount)
if (!mainSprite->UnknownFlag && mainSprite->Bmp && spriteArr->size() < 2)
spriteArr->clear();
if (!spriteArr->empty())
{
mainSprite->SpriteArray = memory::realloc(spriteArr, sizeof(void*) * occludeCount);
mainSprite->SpriteCount = occludeCount;
mainSprite->SpriteArray = spriteArr;
spriteArr = nullptr;
}
}
}
if (spriteArr)
memory::free(spriteArr);
--memory::critical_allocation;
delete spriteArr;
}
void render::SpriteViewer(bool* show)
@ -575,23 +535,23 @@ void render::BlitVScreen()
reinterpret_cast<void**>(&lockedPixels),
&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)
{
// 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
{
// Copy offset table and fixed side bar
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 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
if (xDst < 0)
@ -618,8 +578,8 @@ void render::BlitVScreen()
if (ySrc)
height -= ySrc;
auto srcBmpPtr = &vscreen.BmpBufPtr1[vscreen.Width * ySrc + xSrc];
auto dstPtr = &lockedPixels[vscreen.Width * yDst + xDst];
auto srcBmpPtr = &vscreen->BmpBufPtr1[vscreen->Width * ySrc + xSrc];
auto dstPtr = &lockedPixels[vscreen->Width * yDst + xDst];
for (int y = height; y > 0; --y)
{
std::memcpy(dstPtr, srcBmpPtr, tableStride);
@ -627,8 +587,8 @@ void render::BlitVScreen()
std::memcpy(dstPtr, srcScorePtr, scoreStride);
dstPtr += scoreWidth;
srcBmpPtr += vscreen.Stride;
srcScorePtr += vscreen.Stride;
srcBmpPtr += vscreen->Stride;
srcScorePtr += vscreen->Stride;
}
}

View File

@ -22,8 +22,7 @@ struct render_sprite_type_struct
int ZMapOffestY;
int ZMapOffestX;
rectangle_type DirtyRect;
render_sprite_type_struct** SpriteArray;
int SpriteCount;
std::vector<render_sprite_type_struct*>* SpriteArray;
rectangle_type BoundingRect;
};
@ -31,7 +30,7 @@ struct render_sprite_type_struct
class render
{
public:
static gdrv_bitmap8 vscreen, *background_bitmap;
static gdrv_bitmap8 *vscreen, *background_bitmap;
static SDL_Rect DestinationRect;
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,
zmap_header_type* zMap,
int xPosition, int yPosition, rectangle_type* rect);
static void remove_sprite(render_sprite_type_struct* sprite);
static void remove_ball(struct render_sprite_type_struct* ball);
static void remove_sprite(render_sprite_type_struct* sprite, bool removeFromList);
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,
int yPos);
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 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 build_occlude_list();
static void SpriteViewer(bool* show);
static void PresentVScreen();
private:
static int many_dirty, many_sprites, many_balls;
static render_sprite_type_struct **dirty_list, **sprite_list, **ball_list;
static std::vector<render_sprite_type_struct*> dirty_list, sprite_list, ball_list;
static zmap_header_type* background_zmap;
static int zmap_offset, zmap_offsetY, offset_x, offset_y;
static float zscaler, zmin, zmax;
static rectangle_type vscreen_rect;
static gdrv_bitmap8 ball_bitmap[20];
static zmap_header_type zscreen;
static gdrv_bitmap8 *ball_bitmap[20];
static zmap_header_type* zscreen;
static SDL_Texture* vScreenTex;
static void repaint(struct render_sprite_type_struct* sprite);

View File

@ -4,7 +4,6 @@
#include "EmbeddedData.h"
#include "fullscrn.h"
#include "loader.h"
#include "memory.h"
#include "GroupData.h"
#include "pb.h"
#include "render.h"
@ -19,7 +18,7 @@ int score::init()
scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
{
auto score = memory::allocate<scoreStruct>();
auto score = new scoreStruct();
if (!score)
return nullptr;
score->Score = -9999;
@ -31,7 +30,7 @@ scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
FieldTypes::ShortArray));
if (!dimensions)
{
memory::free(score);
delete score;
return nullptr;
}
int groupIndex = *dimensions++;
@ -50,10 +49,7 @@ scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
scoreStruct* score::dup(scoreStruct* score, int scoreIndex)
{
auto result = memory::allocate<scoreStruct>();
if (result)
memcpy(result, score, sizeof(scoreStruct));
return result;
return new scoreStruct(*score);
}
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(
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;
if (!fontp)
{
@ -91,10 +87,10 @@ void score::load_msg_font_3DPB(LPCSTR lpName)
}
auto height = rcData[2];
auto tmpCharBur = memory::allocate(maxWidth * height + 4);
auto tmpCharBur = new char[maxWidth * height + 4];
if (!tmpCharBur)
{
memory::free(msg_fontp);
delete msg_fontp;
msg_fontp = nullptr;
IM_FREE(rcData);
return;
@ -111,19 +107,8 @@ void score::load_msg_font_3DPB(LPCSTR lpName)
if (!width)
continue;
auto bmp = memory::allocate<gdrv_bitmap8>();
auto bmp = new gdrv_bitmap8(width, height, true);
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;
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);
if (charInd != 128)
unload_msg_font();
@ -152,7 +137,7 @@ void score::load_msg_font_FT(LPCSTR lpName)
int groupIndex = pb::record_table->record_labeled(lpName);
if (groupIndex < 0)
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)
return;
@ -179,15 +164,11 @@ void score::unload_msg_font()
{
/*3DBP creates bitmaps, FT just references them from partman*/
if (!pb::FullTiltMode)
for (int i = 0; i < 128; i++)
for (auto& Char : msg_fontp->Chars)
{
if (msg_fontp->Chars[i])
{
gdrv::destroy_bitmap(msg_fontp->Chars[i]);
memory::free(msg_fontp->Chars[i]);
}
delete Char;
}
memory::free(msg_fontp);
delete msg_fontp;
msg_fontp = nullptr;
}
}
@ -198,7 +179,7 @@ void score::erase(scoreStruct* score, int blitFlag)
{
if (score->BackgroundBmp)
gdrv::copy_bitmap(
&render::vscreen,
render::vscreen,
score->Width,
score->Height,
score->OffsetX,
@ -207,7 +188,7 @@ void score::erase(scoreStruct* score, int blitFlag)
score->OffsetX,
score->OffsetY);
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 width = bmp->Width;
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
gdrv::copy_bitmap(&render::vscreen, width, height, x, y, bmp, 0, 0);
gdrv::copy_bitmap(render::vscreen, width, height, x, y, bmp, 0, 0);
}
}
}

View File

@ -1,7 +1,6 @@
#include "pch.h"
#include "timer.h"
#include "memory.h"
#include "pb.h"
int timer::SetCount;
@ -13,7 +12,7 @@ timer_struct* timer::TimerBuffer;
int timer::init(int count)
{
auto buf = memory::allocate<timer_struct>(count);
auto buf = new timer_struct[count];
TimerBuffer = buf;
if (!buf)
return 1;
@ -32,8 +31,7 @@ int timer::init(int count)
void timer::uninit()
{
if (TimerBuffer)
memory::free(TimerBuffer);
delete[] TimerBuffer;
TimerBuffer = nullptr;
}

View File

@ -2,7 +2,6 @@
#include "winmain.h"
#include "fullscrn.h"
#include "memory.h"
#include "midi.h"
#include "pinball.h"
#include "options.h"
@ -28,7 +27,7 @@ int winmain::no_time_loss;
bool winmain::restart = false;
gdrv_bitmap8 winmain::gfr_display{};
gdrv_bitmap8* winmain::gfr_display = nullptr;
std::string winmain::DatFileName;
bool winmain::ShowAboutDialog = false;
bool winmain::ShowImGuiDemo = false;
@ -46,7 +45,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
restart = false;
bQuit = false;
memory::init(memalloc_failure);
std::set_new_handler(memalloc_failure);
// SDL init
SDL_SetMainReady();
@ -117,8 +116,6 @@ int winmain::WinMain(LPCSTR lpCmdLine)
// PB init from message handler
{
++memory::critical_allocation;
options::init();
auto voiceCount = options::get_int("Voices", 8);
if (Sound::Init(voiceCount))
@ -136,8 +133,6 @@ int winmain::WinMain(LPCSTR lpCmdLine)
}
fullscrn::init();
--memory::critical_allocation;
}
pb::reset_table();
@ -182,7 +177,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
if (DispGRhistory)
{
if (!gfr_display.BmpBufPtr1)
if (!gfr_display)
{
auto plt = static_cast<ColorRgba*>(malloc(1024u));
auto pltPtr = &plt[10];
@ -199,14 +194,14 @@ int winmain::WinMain(LPCSTR lpCmdLine)
}
gdrv::display_palette(plt);
free(plt);
gdrv::create_bitmap(&gfr_display, 400, 15, 400, false);
gfr_display = new gdrv_bitmap8(400, 15, false);
}
if (!dtHistoryCounter)
{
dtHistoryCounter = 300;
gdrv::copy_bitmap(&render::vscreen, 300, 10, 0, 30, &gfr_display, 0, 0);
gdrv::fill_bitmap(&gfr_display, 300, 10, 0, 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);
}
}
@ -227,7 +222,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
auto deltaT = static_cast<int>(frameDuration);
frameDuration -= deltaT;
pb::frame(deltaT);
if (gfr_display.BmpBufPtr1)
if (gfr_display)
{
auto deltaTPal = deltaT + 10;
auto fillChar = static_cast<uint8_t>(deltaTPal);
@ -235,7 +230,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
{
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;
}
updateCounter++;
@ -289,7 +284,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
}
}
gdrv::destroy_bitmap(&gfr_display);
delete gfr_display;
options::uninit();
midi::music_shutdown();
pb::uninit();

View File

@ -52,7 +52,7 @@ public:
static int WinMain(LPCSTR lpCmdLine);
static int event_handler(const SDL_Event* event);
static void memalloc_failure();
[[ noreturn ]] static void memalloc_failure();
static int ProcessWindowMessages();
static void a_dialog();
static void end_pause();
@ -64,7 +64,7 @@ public:
private:
static int return_value, bQuit, DispFrameRate, DispGRhistory, activated;
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 bool restart;
static bool ShowAboutDialog;

View File

@ -1,21 +1,26 @@
#include "pch.h"
#include "zdrv.h"
#include "memory.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;
zmap->Height = height;
zmap->Stride = stride >= 0 ? stride : pad(width);
zmap->Texture = nullptr;
zmap->ZPtr1 = memory::allocate<unsigned short>(zmap->Stride * zmap->Height);
return zmap->ZPtr1 ? 0 : -1;
Resolution = 0;
Width = width;
Height = height;
Stride = stride >= 0 ? stride : pad(width);
Texture = nullptr;
ZPtr1 = new unsigned short[Stride * Height];
}
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;
if (width & 3)
@ -23,17 +28,6 @@ int zdrv::pad(int width)
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)
{

View File

@ -3,20 +3,21 @@
struct zmap_header_type
{
zmap_header_type(int width, int height, int stride);
~zmap_header_type();
int Width;
int Height;
int Stride;
unsigned Resolution;
uint16_t* ZPtr1;
SDL_Texture* Texture;
private:
static int pad(int width);
};
class zdrv
{
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 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,