gdrv: simplified bitmap, fixed blit, improved SDL present.
Removed some Windows dependencies.
This commit is contained in:
@@ -15,19 +15,19 @@
|
||||
#include "TTextBox.h"
|
||||
#include "winmain.h"
|
||||
|
||||
int main()
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
{
|
||||
// Testing with UI
|
||||
char cmdLine[1]{};
|
||||
WinMain(GetModuleHandleA(nullptr), nullptr, cmdLine, 10);
|
||||
std::string cmdLine;
|
||||
for (int i = 0; i < argc; i++)
|
||||
cmdLine += argv[i];
|
||||
winmain::WinMain(cmdLine.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "Hello World!\n";
|
||||
gdrv::init(nullptr,0,0);
|
||||
auto dib = gdrv::DibCreate(8, 1, 1);
|
||||
gdrv::DibSetUsage(dib, nullptr, 1);
|
||||
gdrv::init(0,0);
|
||||
|
||||
auto d = objlist_class<void>(2, 4);
|
||||
for (size_t i = 0; i < 100; i++)
|
||||
@@ -39,7 +39,7 @@ int main()
|
||||
auto xx = sizeof(datFileHeader);
|
||||
|
||||
lstrcpyA(winmain::DatFileName, "PINBALL.DAT");
|
||||
pb::init(nullptr);
|
||||
pb::init();
|
||||
auto datFile = pb::record_table;
|
||||
|
||||
assert(partman::field_size_nth(datFile, 0, datFieldTypes::String, 0) == 43);
|
||||
|
||||
@@ -440,22 +440,22 @@ void fullscrn::window_size_changed()
|
||||
return;
|
||||
}
|
||||
|
||||
RECT client{};
|
||||
GetClientRect(hWnd, &client);
|
||||
int width, height;
|
||||
SDL_GetWindowSize(winmain::MainWindow, &width, &height);
|
||||
auto res = &resolution_array[resolution];
|
||||
ScaleX = static_cast<float>(client.right) / res->TableWidth;
|
||||
ScaleY = static_cast<float>(client.bottom) / res->TableHeight;
|
||||
ScaleX = static_cast<float>(width) / res->TableWidth;
|
||||
ScaleY = static_cast<float>(height) / res->TableHeight;
|
||||
OffsetX = OffsetY = 0;
|
||||
|
||||
if (options::Options.UniformScaling)
|
||||
{
|
||||
ScaleY = ScaleX = min(ScaleX, ScaleY);
|
||||
OffsetX = floor((client.right - res->TableWidth * ScaleX) / 2);
|
||||
OffsetY = floor((client.bottom - res->TableHeight * ScaleY) / 2);
|
||||
OffsetX = floor((width - res->TableWidth * ScaleX) / 2);
|
||||
OffsetY = floor((height - res->TableHeight * ScaleY) / 2);
|
||||
auto dc = GetDC(hWnd);
|
||||
if (dc)
|
||||
{
|
||||
BitBlt(dc, 0, 0, client.right, client.bottom, dc, 0, 0, BLACKNESS);
|
||||
BitBlt(dc, 0, 0, width, height, dc, 0, 0, BLACKNESS);
|
||||
ReleaseDC(hWnd, dc);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,8 +10,6 @@ enum class BitmapType : char
|
||||
|
||||
struct gdrv_bitmap8
|
||||
{
|
||||
BITMAPINFO* Dib;
|
||||
char* BmpBufPtr2;
|
||||
char* BmpBufPtr1;
|
||||
int Width;
|
||||
int Height;
|
||||
@@ -22,6 +20,20 @@ struct gdrv_bitmap8
|
||||
int YPosition;
|
||||
};
|
||||
|
||||
struct Rgba
|
||||
{
|
||||
uint8_t peRed;
|
||||
uint8_t peGreen;
|
||||
uint8_t peBlue;
|
||||
uint8_t peFlags;
|
||||
};
|
||||
union ColorRgba
|
||||
{
|
||||
uint32_t Color;
|
||||
Rgba rgba;
|
||||
};
|
||||
static_assert(sizeof(ColorRgba) == 4, "Wrong size of RGBA color");
|
||||
|
||||
struct LOGPALETTEx256 : LOGPALETTE
|
||||
{
|
||||
PALETTEENTRY palPalEntry2[256 - 1];
|
||||
@@ -37,27 +49,17 @@ struct LOGPALETTEx256 : LOGPALETTE
|
||||
class gdrv
|
||||
{
|
||||
public:
|
||||
static HPALETTE palette_handle;
|
||||
static int sequence_handle;
|
||||
static HDC sequence_hdc;
|
||||
static int use_wing;
|
||||
|
||||
static int init(SDL_Renderer* renderer, int width, int height);
|
||||
static int init(int width, int height);
|
||||
static int uninit();
|
||||
static void get_focus();
|
||||
static BITMAPINFO* DibCreate(int16_t bpp, int width, int height);
|
||||
static void DibSetUsage(BITMAPINFO* dib, HPALETTE hpal, int someFlag);
|
||||
static int create_bitmap_dib(gdrv_bitmap8* bmp, int width, int height);
|
||||
static int create_bitmap(gdrv_bitmap8* bmp, int width, int height);
|
||||
static int create_raw_bitmap(gdrv_bitmap8* bmp, int width, int height, int flag);
|
||||
static int create_spliced_bitmap(gdrv_bitmap8* bmp, int width, int height, int size);
|
||||
static int destroy_bitmap(gdrv_bitmap8* bmp);
|
||||
static int display_palette(PALETTEENTRY* plt);
|
||||
static int display_palette(ColorRgba* plt);
|
||||
static void start_blit_sequence();
|
||||
static void blit_sequence(gdrv_bitmap8* bmp, int xSrc, int ySrcOff, int xDest, int yDest, int DestWidth,
|
||||
int DestHeight);
|
||||
static void end_blit_sequence();
|
||||
static void blit(gdrv_bitmap8* bmp, int xSrc, int ySrcOff, int xDest, int yDest, int DestWidth, int DestHeight);
|
||||
static void blit(gdrv_bitmap8* bmp, int xSrc, int ySrc, int xDest, int yDest, int width, int height);
|
||||
static void blat(gdrv_bitmap8* bmp, int xDest, int yDest);
|
||||
static void fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, char fillChar);
|
||||
static void copy_bitmap(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff, gdrv_bitmap8* srcBmp,
|
||||
@@ -65,15 +67,13 @@ public:
|
||||
static void copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff,
|
||||
gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff);
|
||||
static void grtext_draw_ttext_in_box(LPCSTR text, int xOff, int yOff, int width, int height, int a6);
|
||||
static void BlitScreen();
|
||||
private:
|
||||
/*COLORONCOLOR or HALFTONE*/
|
||||
static const int stretchMode = COLORONCOLOR;
|
||||
static SDL_Renderer* renderer;
|
||||
static int grtext_blue;
|
||||
static int grtext_green;
|
||||
static int grtext_red;
|
||||
static SDL_Texture* vScreenTex;
|
||||
static char* vScreenPixels;
|
||||
static int vScreenWidth, vScreenHeight;
|
||||
static ColorRgba current_palette[256];
|
||||
|
||||
static int StretchDIBitsScaled(HDC hdc, int xDest, int yDest, int DestWidth, int DestHeight, int xSrc, int ySrc,
|
||||
int SrcWidth, int SrcHeight, gdrv_bitmap8* bmp, UINT iUsage,
|
||||
DWORD rop);
|
||||
static int StretchDIBitsScaled(int xSrc, int ySrc, int xDst, int yDst,
|
||||
int width, int height, gdrv_bitmap8* bmp);
|
||||
};
|
||||
|
||||
@@ -167,7 +167,7 @@ void high_score::show_high_score_dialog(high_score_struct* table)
|
||||
dlg_enter_name = 0;
|
||||
dlg_score = 0;
|
||||
dlg_hst = table;
|
||||
DialogBoxParamA(winmain::hinst, "dlg_highscores", winmain::hwnd_frame, HighScore, 0);
|
||||
DialogBoxParamA(nullptr, "dlg_highscores", nullptr, HighScore, 0);
|
||||
}
|
||||
|
||||
void high_score::show_and_set_high_score_dialog(high_score_struct* table, int score, int pos, LPCSTR defaultName)
|
||||
|
||||
@@ -151,9 +151,13 @@ int loader::get_sound_id(int groupIndex)
|
||||
sprintf_s(fileName2, pb::FullTiltMode ? "SOUND\\%s" : "%s", fileName);
|
||||
pinball::make_path_name(filePath, fileName2);
|
||||
|
||||
HFILE hFile = _lopen(filePath, 0);
|
||||
_lread(hFile, &wavHeader, sizeof wavHeader);
|
||||
_lclose(hFile);
|
||||
FILE* file;
|
||||
if (!fopen_s(&file, filePath, "rb"))
|
||||
{
|
||||
fread(&wavHeader, 1, sizeof wavHeader, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
auto sampleCount = wavHeader.data_size / (wavHeader.channels * (wavHeader.bits_per_sample / 8.0));
|
||||
sound_list[soundIndex].Duration = static_cast<float>(sampleCount / wavHeader.sample_rate);
|
||||
sound_list[soundIndex].WavePtr = Sound::LoadWaveFile(filePath);
|
||||
|
||||
@@ -32,11 +32,11 @@ MCIERROR midi::music_stop()
|
||||
return Mix_HaltMusic();
|
||||
}
|
||||
|
||||
int midi::music_init(HWND hwnd)
|
||||
int midi::music_init()
|
||||
{
|
||||
if (pb::FullTiltMode)
|
||||
{
|
||||
return music_init_ft(hwnd);
|
||||
return music_init_ft();
|
||||
}
|
||||
|
||||
currentMidi = Mix_LoadMUS(pinball::get_rc_string(156, 0));
|
||||
@@ -74,7 +74,7 @@ objlist_class<midi_struct>* midi::TrackList;
|
||||
midi_struct *midi::track1, *midi::track2, *midi::track3, *midi::active_track, *midi::active_track2;
|
||||
int midi::some_flag1;
|
||||
|
||||
int midi::music_init_ft(HWND hwnd)
|
||||
int midi::music_init_ft()
|
||||
{
|
||||
active_track = nullptr;
|
||||
TrackList = new objlist_class<midi_struct>(0, 1);
|
||||
|
||||
@@ -54,7 +54,7 @@ class midi
|
||||
public:
|
||||
static MCIERROR play_pb_theme(int flag);
|
||||
static MCIERROR music_stop();
|
||||
static int music_init(HWND hwnd);
|
||||
static int music_init();
|
||||
static MCIERROR restart_midi_seq(LPARAM param);
|
||||
static void music_shutdown();
|
||||
private:
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
static objlist_class<midi_struct>* TrackList;
|
||||
static midi_struct *track1, *track2, *track3, *active_track, *active_track2;
|
||||
static int some_flag1;
|
||||
static int music_init_ft(HWND hwnd);
|
||||
static int music_init_ft();
|
||||
static void music_shutdown_ft();
|
||||
static midi_struct* load_track(LPCSTR fileName);
|
||||
static int load_file(midi_struct** midi_res, void* filePtrOrPath, int fileSizeP, int flags);
|
||||
|
||||
@@ -80,7 +80,7 @@ void options::init(HMENU menuHandle)
|
||||
Options.RightFlipperKeyDft = SDLK_SLASH;
|
||||
Options.PlungerKeyDft = SDLK_SPACE;
|
||||
Options.LeftTableBumpKeyDft = SDLK_x;
|
||||
Options.RightTableBumpKeyDft = SDLK_GREATER;
|
||||
Options.RightTableBumpKeyDft = SDLK_PERIOD;
|
||||
Options.BottomTableBumpKeyDft = SDLK_UP;
|
||||
/*pinball::get_rc_int(159, &Options.LeftFlipperKeyDft);
|
||||
pinball::get_rc_int(160, &Options.RightFlipperKeyDft);
|
||||
@@ -126,7 +126,7 @@ void options::init(HMENU menuHandle)
|
||||
if (MenuHandle)
|
||||
{
|
||||
DeleteMenu(MenuHandle, Menu1_Select_Table, 0);
|
||||
DrawMenuBar(winmain::hwnd_frame);
|
||||
DrawMenuBar(nullptr);
|
||||
}
|
||||
}
|
||||
memory::free(tmpBuf);
|
||||
@@ -387,7 +387,7 @@ void options::init_resolution()
|
||||
|
||||
void options::keyboard()
|
||||
{
|
||||
DialogBoxParamA(winmain::hinst, "KEYMAPPER", winmain::hwnd_frame, KeyMapDlgProc, 0);
|
||||
DialogBoxParamA(nullptr, "KEYMAPPER", nullptr, KeyMapDlgProc, 0);
|
||||
}
|
||||
|
||||
INT_PTR _stdcall options::KeyMapDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
@@ -11,24 +11,24 @@ short partman::_field_size[] =
|
||||
|
||||
datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool fullTiltMode)
|
||||
{
|
||||
_OFSTRUCT ReOpenBuff{};
|
||||
datFileHeader header{};
|
||||
dat8BitBmpHeader bmpHeader{};
|
||||
dat16BitBmpHeader zMapHeader{};
|
||||
|
||||
const HFILE fileHandle = OpenFile(lpFileName, &ReOpenBuff, 0);
|
||||
if (fileHandle == -1)
|
||||
FILE* fileHandle;
|
||||
fopen_s(&fileHandle, lpFileName, "rb");
|
||||
if (fileHandle == nullptr)
|
||||
return nullptr;
|
||||
_lread(fileHandle, &header, 183u);
|
||||
fread(&header, 1, sizeof datFileHeader, fileHandle);
|
||||
if (lstrcmpA("PARTOUT(4.0)RESOURCE", header.FileSignature))
|
||||
{
|
||||
_lclose(fileHandle);
|
||||
fclose(fileHandle);
|
||||
return nullptr;
|
||||
}
|
||||
auto datFile = memory::allocate<datFileStruct>();
|
||||
if (!datFile)
|
||||
{
|
||||
_lclose(fileHandle);
|
||||
fclose(fileHandle);
|
||||
return nullptr;
|
||||
}
|
||||
if (lstrlenA(header.Description) <= 0)
|
||||
@@ -42,7 +42,7 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
datFile->Description = descriptionBuf;
|
||||
if (!descriptionBuf)
|
||||
{
|
||||
_lclose(fileHandle);
|
||||
fclose(fileHandle);
|
||||
memory::free(datFile);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -54,13 +54,13 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
auto unknownBuf = memory::allocate(header.Unknown);
|
||||
if (!unknownBuf)
|
||||
{
|
||||
_lclose(fileHandle);
|
||||
fclose(fileHandle);
|
||||
if (datFile->Description)
|
||||
memory::free(datFile->Description);
|
||||
memory::free(datFile);
|
||||
return nullptr;
|
||||
}
|
||||
_lread(fileHandle, static_cast<void*>(unknownBuf), header.Unknown);
|
||||
fread(unknownBuf, 1, header.Unknown, fileHandle);
|
||||
memory::free(unknownBuf);
|
||||
}
|
||||
|
||||
@@ -97,10 +97,10 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
|
||||
if (entryType == datFieldTypes::Bitmap8bit)
|
||||
{
|
||||
_hread(fileHandle, &bmpHeader, sizeof(dat8BitBmpHeader));
|
||||
fread(&bmpHeader, 1, sizeof(dat8BitBmpHeader), fileHandle);
|
||||
if (bmpHeader.Resolution != resolution && bmpHeader.Resolution != -1)
|
||||
{
|
||||
_llseek(fileHandle, bmpHeader.Size, 1);
|
||||
fseek(fileHandle, bmpHeader.Size, SEEK_CUR);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
abort = true;
|
||||
break;
|
||||
}
|
||||
_hread(fileHandle, bmp->BmpBufPtr1, bmpHeader.Size);
|
||||
fread(bmp->BmpBufPtr1, 1, bmpHeader.Size, fileHandle);
|
||||
bmp->XPosition = bmpHeader.XPosition;
|
||||
bmp->YPosition = bmpHeader.YPosition;
|
||||
}
|
||||
@@ -137,19 +137,19 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
fieldSize--;
|
||||
if (zMapResolution != resolution && zMapResolution != -1)
|
||||
{
|
||||
_llseek(fileHandle, fieldSize, 1);
|
||||
fseek(fileHandle, fieldSize, SEEK_CUR);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
_hread(fileHandle, &zMapHeader, sizeof(dat16BitBmpHeader));
|
||||
fread(&zMapHeader, 1, sizeof(dat16BitBmpHeader), fileHandle);
|
||||
int length = fieldSize - sizeof(dat16BitBmpHeader);
|
||||
|
||||
auto zmap = memory::allocate<zmap_header_type>(1, length);
|
||||
zmap->Width = zMapHeader.Width;
|
||||
zmap->Height = zMapHeader.Height;
|
||||
zmap->Stride = zMapHeader.Stride;
|
||||
_hread(fileHandle, zmap->ZBuffer, length);
|
||||
fread(zmap->ZBuffer, 1, length, fileHandle);
|
||||
entryData->Buffer = reinterpret_cast<char*>(zmap);
|
||||
}
|
||||
else
|
||||
@@ -161,7 +161,7 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
abort = true;
|
||||
break;
|
||||
}
|
||||
_hread(fileHandle, entryBuffer, fieldSize);
|
||||
fread(entryBuffer, 1, fieldSize, fileHandle);
|
||||
}
|
||||
|
||||
entryData->FieldSize = fieldSize;
|
||||
@@ -170,7 +170,7 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
datFile->NumberOfGroups = groupIndex + 1;
|
||||
}
|
||||
|
||||
_lclose(fileHandle);
|
||||
fclose(fileHandle);
|
||||
if (datFile->NumberOfGroups == header.NumberOfGroups)
|
||||
return datFile;
|
||||
unload_records(datFile);
|
||||
@@ -280,16 +280,16 @@ char* partman::field_labeled(datFileStruct* datFile, LPCSTR lpString, datFieldTy
|
||||
return groupIndex < 0 ? nullptr : field(datFile, groupIndex, fieldType);
|
||||
}
|
||||
|
||||
char partman::_lread_char(HFILE hFile)
|
||||
char partman::_lread_char(FILE* file)
|
||||
{
|
||||
char Buffer = 0;
|
||||
_lread(hFile, &Buffer, 1u);
|
||||
fread(&Buffer, 1, 1, file);
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
int partman::_lread_long(HFILE hFile)
|
||||
int partman::_lread_long(FILE* file)
|
||||
{
|
||||
int Buffer = 0;
|
||||
_lread(hFile, &Buffer, 4u);
|
||||
fread(&Buffer, 1, 4, file);
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,6 @@ public:
|
||||
static char* field_labeled(datFileStruct* datFile, LPCSTR lpString, datFieldTypes fieldType);
|
||||
private:
|
||||
static short _field_size[];
|
||||
static char _lread_char(HFILE hFile);
|
||||
static int _lread_long(HFILE hFile);
|
||||
static char _lread_char(FILE* file);
|
||||
static int _lread_long(FILE* file);
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ high_score_struct pb::highscore_table[5];
|
||||
bool pb::FullTiltMode = false;
|
||||
|
||||
|
||||
int pb::init(SDL_Renderer* render)
|
||||
int pb::init()
|
||||
{
|
||||
float projMat[12], zMin = 0, zScaler = 0;
|
||||
CHAR datFileName[300];
|
||||
@@ -52,7 +52,7 @@ int pb::init(SDL_Renderer* render)
|
||||
if (!record_table)
|
||||
return 1;
|
||||
|
||||
auto plt = (PALETTEENTRY*)partman::field_labeled(record_table, "background", datFieldTypes::Palette);
|
||||
auto plt = (ColorRgba*)partman::field_labeled(record_table, "background", datFieldTypes::Palette);
|
||||
gdrv::display_palette(plt);
|
||||
|
||||
auto backgroundBmp = (gdrv_bitmap8*)partman::field_labeled(record_table, "background", datFieldTypes::Bitmap8bit);
|
||||
@@ -75,7 +75,7 @@ int pb::init(SDL_Renderer* render)
|
||||
zScaler = cameraInfo[2];
|
||||
}
|
||||
|
||||
gdrv::init(render, resInfo->TableWidth, resInfo->TableHeight);
|
||||
gdrv::init(resInfo->TableWidth, resInfo->TableHeight);
|
||||
render::init(nullptr, zMin, zScaler, resInfo->TableWidth, resInfo->TableHeight);
|
||||
gdrv::copy_bitmap(
|
||||
&render::vscreen,
|
||||
@@ -448,7 +448,7 @@ void pb::keydown(int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 'B':
|
||||
case 'b':
|
||||
TBall* ball;
|
||||
if (MainTable->BallList->GetCount() <= 0)
|
||||
{
|
||||
@@ -477,17 +477,17 @@ void pb::keydown(int key)
|
||||
ball->Acceleration.Y = 0.0;
|
||||
ball->Acceleration.X = 0.0;
|
||||
break;
|
||||
case 'H':
|
||||
case 'h':
|
||||
char String1[200];
|
||||
lstrcpyA(String1, pinball::get_rc_string(26, 0));
|
||||
high_score::show_and_set_high_score_dialog(highscore_table, 1000000000, 1, String1);
|
||||
break;
|
||||
case 'M':
|
||||
case 'm':
|
||||
char buffer[20];
|
||||
sprintf_s(buffer, "%zu", memory::use_total);
|
||||
MessageBoxA(winmain::hwnd_frame, buffer, "Mem:", 0x2000u);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Mem:", buffer, winmain::MainWindow);
|
||||
break;
|
||||
case 'R':
|
||||
case 'r':
|
||||
control::cheat_bump_rank();
|
||||
break;
|
||||
case VK_F11:
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
static high_score_struct highscore_table[5];
|
||||
static bool FullTiltMode;
|
||||
|
||||
static int init(SDL_Renderer* render);
|
||||
static int init();
|
||||
static int uninit();
|
||||
static void reset_table();
|
||||
static void firsttime_setup();
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <cstdint>
|
||||
#include <type_traits> /*For control template*/
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
//#include <iostream>
|
||||
#include <iomanip>
|
||||
//#include <cstdlib>
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
#include "SDL.h"
|
||||
#include <SDL_mixer.h>
|
||||
|
||||
//typedef const char* LPCSTR;
|
||||
//typedef int HINSTANCE;
|
||||
//typedef int HWND;
|
||||
|
||||
/*Use (void) to silent unused warnings.*/
|
||||
#define assertm(exp, msg) assert(((void)msg, exp))
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ std::map<uint32_t, LPCSTR> rc_strings
|
||||
{2032, "Use &Maximum Resolution (1024 x 768)"}
|
||||
};
|
||||
|
||||
int LoadStringL(HINSTANCE hInstance, UINT uID, LPSTR lpBuffer, int cchBufferMax)
|
||||
int LoadStringAlt(UINT uID, LPSTR lpBuffer, int cchBufferMax)
|
||||
{
|
||||
auto str = rc_strings.find(uID);
|
||||
if (str == rc_strings.end())
|
||||
@@ -214,7 +214,7 @@ int LoadStringL(HINSTANCE hInstance, UINT uID, LPSTR lpBuffer, int cchBufferMax)
|
||||
return 0;
|
||||
}
|
||||
|
||||
lstrcpyA(lpBuffer, str->second);
|
||||
strncpy_s(lpBuffer, cchBufferMax, str->second, cchBufferMax);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ int pinball::RightShift = -1;
|
||||
char* pinball::get_rc_string(int uID, int a2)
|
||||
{
|
||||
char* result = &getRcBuffer[256 * rc_string_slot];
|
||||
if (!LoadStringL(winmain::hinst, uID, &getRcBuffer[256 * rc_string_slot], 255))
|
||||
if (!LoadStringAlt(uID, &getRcBuffer[256 * rc_string_slot], 255))
|
||||
*result = 0;
|
||||
if (++rc_string_slot >= 6)
|
||||
rc_string_slot = 0;
|
||||
@@ -239,7 +239,7 @@ char* pinball::get_rc_string(int uID, int a2)
|
||||
int pinball::get_rc_int(int uID, int* dst)
|
||||
{
|
||||
char buffer[255];
|
||||
int result = LoadStringL(winmain::hinst, uID, buffer, 255);
|
||||
int result = LoadStringAlt(uID, buffer, 255);
|
||||
if (!result)
|
||||
return result;
|
||||
*dst = atoi(buffer);
|
||||
|
||||
@@ -138,7 +138,7 @@ void render::update()
|
||||
auto dirtyRect = &(*dirtyPtr)->DirtyRect;
|
||||
auto width2 = (*dirtyPtr)->DirtyRect.Width;
|
||||
if (width2 > 0)
|
||||
gdrv::blit_sequence(
|
||||
gdrv::blit(
|
||||
&vscreen,
|
||||
dirtyRect->XPosition,
|
||||
dirtyRect->YPosition,
|
||||
@@ -165,7 +165,7 @@ void render::update()
|
||||
if (maths::overlapping_box(dirtyRect, rectCopy, &overlapRect) && dirtyRect->Width > 0)
|
||||
{
|
||||
if (overlapRect.Width > 0)
|
||||
gdrv::blit_sequence(
|
||||
gdrv::blit(
|
||||
&vscreen,
|
||||
overlapRect.XPosition,
|
||||
overlapRect.YPosition,
|
||||
@@ -177,7 +177,7 @@ void render::update()
|
||||
else
|
||||
{
|
||||
if (dirtyRect->Width > 0)
|
||||
gdrv::blit_sequence(
|
||||
gdrv::blit(
|
||||
&vscreen,
|
||||
dirtyRect->XPosition,
|
||||
dirtyRect->YPosition,
|
||||
@@ -186,7 +186,7 @@ void render::update()
|
||||
dirtyRect->Width,
|
||||
dirtyRect->Height);
|
||||
if (rectCopy->Width > 0)
|
||||
gdrv::blit_sequence(
|
||||
gdrv::blit(
|
||||
&vscreen,
|
||||
rectCopy->XPosition,
|
||||
rectCopy->YPosition,
|
||||
|
||||
@@ -250,7 +250,7 @@ void score::update(scoreStruct* score)
|
||||
{
|
||||
unsigned char curChar = scoreBuf[index];
|
||||
curChar -= '0';
|
||||
gdrv_bitmap8* bmp = score->CharBmp[curChar % 10];
|
||||
gdrv_bitmap8* bmp = score->CharBmp[curChar % 10u];
|
||||
x -= bmp->Width;
|
||||
int height = bmp->Height;
|
||||
int width = bmp->Width;
|
||||
|
||||
@@ -13,10 +13,9 @@
|
||||
|
||||
const double TargetFps = 60, TargetFrameTime = 1000 / TargetFps;
|
||||
|
||||
HINSTANCE winmain::hinst = nullptr;
|
||||
HWND winmain::hwnd_frame = nullptr;
|
||||
HCURSOR winmain::mouse_hsave;
|
||||
SDL_Window* winmain::MainWindow = nullptr;
|
||||
SDL_Renderer* winmain::Renderer = nullptr;
|
||||
|
||||
int winmain::return_value = 0;
|
||||
int winmain::bQuit = 0;
|
||||
@@ -47,13 +46,7 @@ uint32_t timeGetTimeAlt()
|
||||
return static_cast<uint32_t>(millis);
|
||||
}
|
||||
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
{
|
||||
return winmain::WinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
|
||||
}
|
||||
|
||||
int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
int winmain::WinMain(LPCSTR lpCmdLine)
|
||||
{
|
||||
memory::init(memalloc_failure);
|
||||
++memory::critical_allocation;
|
||||
@@ -70,7 +63,6 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
}
|
||||
|
||||
pinball::quickFlag = strstr(lpCmdLine, "-quick") != nullptr;
|
||||
hinst = hInstance;
|
||||
auto regSpaceCadet = pinball::get_rc_string(166, 0);
|
||||
options::get_string(regSpaceCadet, "Pinball Data", DatFileName, pinball::get_rc_string(168, 0), 300);
|
||||
|
||||
@@ -85,20 +77,8 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
strcpy_s(DatFileName, "CADET.DAT");
|
||||
pb::FullTiltMode = true;
|
||||
}
|
||||
|
||||
iFrostUniqueMsg = RegisterWindowMessageA("PinballThemeSwitcherUniqueMsgString");
|
||||
auto windowClass = pinball::get_rc_string(167, 0);
|
||||
auto windowHandle = FindWindowA(windowClass, nullptr);
|
||||
if (windowHandle)
|
||||
{
|
||||
SendMessageA(windowHandle, iFrostUniqueMsg, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (check_expiration_date())
|
||||
return 0;
|
||||
|
||||
auto splash = splash::splash_screen(hInstance, "splash_bitmap", "splash_bitmap");
|
||||
|
||||
auto splash = splash::splash_screen(nullptr, "splash_bitmap", "splash_bitmap");
|
||||
pinball::FindShiftKeys();
|
||||
options::init_resolution();
|
||||
|
||||
@@ -123,6 +103,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
-1,
|
||||
SDL_RENDERER_ACCELERATED
|
||||
);
|
||||
Renderer = renderer;
|
||||
if (!renderer)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not create renderer", SDL_GetError(), window);
|
||||
@@ -141,10 +122,10 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
options::menu_set(Menu1_Sounds, 0);
|
||||
Sound::Activate();
|
||||
|
||||
if (!pinball::quickFlag && !midi::music_init((HWND)window))
|
||||
if (!pinball::quickFlag && !midi::music_init())
|
||||
options::menu_set(Menu1_Music, 0);
|
||||
|
||||
if (pb::init(renderer))
|
||||
if (pb::init())
|
||||
_exit(0);
|
||||
SetCursor(prevCursor);
|
||||
auto changeDisplayFg = options::get_int(nullptr, "Change Display", 1);
|
||||
@@ -160,7 +141,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
--memory::critical_allocation;
|
||||
}
|
||||
|
||||
auto menuHandle = GetMenu(windowHandle);
|
||||
auto menuHandle = GetMenu(nullptr);
|
||||
options::init(menuHandle);
|
||||
pb::reset_table();
|
||||
pb::firsttime_setup();
|
||||
@@ -180,11 +161,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
splash::splash_destroy(splash);
|
||||
}
|
||||
|
||||
pinball::adjust_priority(options::Options.PriorityAdj);
|
||||
const auto startTime = timeGetTimeAlt();
|
||||
MSG wndMessage{};
|
||||
while (timeGetTimeAlt() >= startTime && timeGetTimeAlt() - startTime < 0) // Don't wait for now, was 2000
|
||||
PeekMessageA(&wndMessage, hwnd_frame, 0, 0, 1u);
|
||||
pinball::adjust_priority(options::Options.PriorityAdj);
|
||||
|
||||
if (strstr(lpCmdLine, "-demo"))
|
||||
pb::toggle_demo();
|
||||
@@ -217,7 +194,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
{
|
||||
if (!gfr_display.BmpBufPtr1)
|
||||
{
|
||||
auto plt = static_cast<PALETTEENTRY*>(malloc(1024u));
|
||||
auto plt = static_cast<ColorRgba*>(malloc(1024u));
|
||||
auto pltPtr = &plt[10];
|
||||
for (int i1 = 0, i2 = 0; i1 < 256 - 10; ++i1, i2 += 8)
|
||||
{
|
||||
@@ -228,7 +205,8 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
redGreen = i1;
|
||||
}
|
||||
|
||||
*pltPtr++ = {redGreen, redGreen, blue};
|
||||
auto clr = Rgba{ redGreen, redGreen, blue, 0 };
|
||||
*pltPtr++ = { *reinterpret_cast<uint32_t*>(&clr) };
|
||||
}
|
||||
gdrv::display_palette(plt);
|
||||
free(plt);
|
||||
@@ -291,18 +269,20 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
}
|
||||
--updateCounter;
|
||||
then = now;
|
||||
|
||||
auto frameEnd = static_cast<double>(SDL_GetPerformanceCounter());
|
||||
auto elapsedMs = (frameEnd - frameStart) * sdlTimerResMs;
|
||||
if (elapsedMs >= TargetFrameTime)
|
||||
{
|
||||
// Keep track of remainder, limited to one frame time.
|
||||
frameStart = frameEnd - min(elapsedMs - TargetFrameTime, TargetFrameTime) / sdlTimerResMs;
|
||||
SDL_RenderPresent(renderer);
|
||||
frameCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto frameEnd = static_cast<double>(SDL_GetPerformanceCounter());
|
||||
auto elapsedMs = (frameEnd - frameStart) * sdlTimerResMs;
|
||||
if (elapsedMs >= TargetFrameTime)
|
||||
{
|
||||
// Keep track of remainder, limited to one frame time.
|
||||
frameStart = frameEnd - min(elapsedMs - TargetFrameTime, TargetFrameTime) / sdlTimerResMs;
|
||||
SDL_RenderClear(renderer);
|
||||
gdrv::BlitScreen();
|
||||
SDL_RenderPresent(renderer);
|
||||
frameCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,9 +292,10 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
pb::uninit();
|
||||
Sound::Close();
|
||||
gdrv::uninit();
|
||||
DestroyWindow(hwnd_frame);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
options::path_uninit();
|
||||
UnregisterClassA(windowClass, hinst);
|
||||
|
||||
if (restart)
|
||||
{
|
||||
@@ -385,17 +366,17 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
|
||||
++memory::critical_allocation;
|
||||
|
||||
auto prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
|
||||
gdrv::init(nullptr,0,0);
|
||||
gdrv::init(0,0);
|
||||
|
||||
auto voiceCount = options::get_int(nullptr, "Voices", 8);
|
||||
if (!Sound::Init(voiceCount))
|
||||
options::menu_set(Menu1_Sounds, 0);
|
||||
Sound::Activate();
|
||||
|
||||
if (!pinball::quickFlag && !midi::music_init(hWnd))
|
||||
if (!pinball::quickFlag && !midi::music_init())
|
||||
options::menu_set(Menu1_Music, 0);
|
||||
|
||||
if (pb::init(nullptr))
|
||||
if (pb::init())
|
||||
_exit(0);
|
||||
SetCursor(prevCursor);
|
||||
auto changeDisplayFg = options::get_int(nullptr, "Change Display", 1);
|
||||
@@ -485,10 +466,10 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
|
||||
case VK_ESCAPE:
|
||||
if (options::Options.FullScreen)
|
||||
options::toggle(0x193u);
|
||||
SendMessageA(hwnd_frame, 0x112u, 0xF020u, 0);
|
||||
SendMessageA(nullptr, 0x112u, 0xF020u, 0);
|
||||
break;
|
||||
case VK_F1:
|
||||
help_introduction(hinst, hWnd);
|
||||
help_introduction(nullptr, hWnd);
|
||||
break;
|
||||
case VK_F2:
|
||||
new_game();
|
||||
@@ -574,7 +555,7 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
|
||||
{
|
||||
char cmdLine[0x1F4u];
|
||||
options::get_string(nullptr, "Shell Exe", tmpBuf, "", 500);
|
||||
auto iHwnd = reinterpret_cast<size_t>(hwnd_frame);
|
||||
auto iHwnd = reinterpret_cast<size_t>(nullptr);
|
||||
sprintf_s(
|
||||
cmdLine,
|
||||
"%s %s%zX %s%zX",
|
||||
@@ -587,7 +568,7 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
|
||||
{
|
||||
auto caption = pinball::get_rc_string(170, 0);
|
||||
auto text = pinball::get_rc_string(171, 0);
|
||||
MessageBoxA(hwnd_frame, text, caption, 0x2010u);
|
||||
MessageBoxA(nullptr, text, caption, 0x2010u);
|
||||
}
|
||||
memory::free(tmpBuf);
|
||||
}
|
||||
@@ -610,7 +591,7 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
|
||||
case Menu1_Help_Topics:
|
||||
if (!single_step)
|
||||
pause();
|
||||
help_introduction(hinst, hWnd);
|
||||
help_introduction(nullptr, hWnd);
|
||||
break;
|
||||
case 106: // End game button?
|
||||
pb::end_game();
|
||||
@@ -637,7 +618,7 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
|
||||
case Menu1_About_Pinball:
|
||||
if (!single_step)
|
||||
pause();
|
||||
a_dialog(hinst, hWnd);
|
||||
a_dialog(nullptr, hWnd);
|
||||
break;
|
||||
case Menu1_High_Scores:
|
||||
if (!single_step)
|
||||
@@ -745,7 +726,7 @@ int winmain::event_handler(const SDL_Event* event)
|
||||
SDL_MinimizeWindow(MainWindow);
|
||||
break;
|
||||
case SDLK_F1:
|
||||
help_introduction(hinst, (HWND)MainWindow);
|
||||
help_introduction(nullptr, (HWND)MainWindow);
|
||||
break;
|
||||
case SDLK_F2:
|
||||
new_game();
|
||||
@@ -876,6 +857,10 @@ int winmain::event_handler(const SDL_Event* event)
|
||||
gdrv::get_focus();
|
||||
pb::loose_focus();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
fullscrn::window_size_changed();
|
||||
fullscrn::force_redraw();
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
break;
|
||||
@@ -914,12 +899,6 @@ void winmain::memalloc_failure()
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
int winmain::check_expiration_date()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
HDC winmain::_BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint)
|
||||
{
|
||||
HDC context = BeginPaint(hWnd, lpPaint);
|
||||
@@ -1004,5 +983,6 @@ void winmain::help_introduction(HINSTANCE a1, HWND a2)
|
||||
void winmain::Restart()
|
||||
{
|
||||
restart = true;
|
||||
PostMessageA(hwnd_frame, WM_QUIT, 0, 0);
|
||||
SDL_Event event{SDL_QUIT};
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
@@ -4,19 +4,16 @@
|
||||
class winmain
|
||||
{
|
||||
public:
|
||||
static const DWORD WndStyle = WS_GROUP | WS_SYSMENU | WS_DLGFRAME | WS_BORDER | WS_MAXIMIZE | WS_CLIPCHILDREN |
|
||||
WS_THICKFRAME | WS_MAXIMIZEBOX;
|
||||
static char DatFileName[300];
|
||||
static int single_step;
|
||||
static HINSTANCE hinst;
|
||||
static HWND hwnd_frame;
|
||||
static SDL_Window* MainWindow;
|
||||
static SDL_Renderer* Renderer;
|
||||
|
||||
static int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
|
||||
static int WinMain(LPCSTR lpCmdLine);
|
||||
static LRESULT CALLBACK message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
static int event_handler(const SDL_Event* event);
|
||||
static void memalloc_failure();
|
||||
static int ProcessWindowMessages();
|
||||
static int check_expiration_date();
|
||||
static HDC _GetDC(HWND hWnd);
|
||||
static int a_dialog(HINSTANCE hInstance, HWND hWnd);
|
||||
static void end_pause();
|
||||
@@ -32,7 +29,6 @@ private:
|
||||
static gdrv_bitmap8 gfr_display;
|
||||
static HCURSOR mouse_hsave;
|
||||
static bool restart;
|
||||
static SDL_Window* MainWindow;
|
||||
|
||||
static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
|
||||
};
|
||||
|
||||
@@ -127,9 +127,9 @@ void zdrv::paint_spliced_bmp(int xPos, int yPos, gdrv_bitmap8* dstBmp, zmap_head
|
||||
if (yOffset < 0)
|
||||
return;
|
||||
|
||||
auto bmpDstPtr = &dstBmp->BmpBufPtr2[xOffset + yOffset * dstBmp->Stride];
|
||||
auto bmpDstPtr = &dstBmp->BmpBufPtr1[xOffset + yOffset * dstBmp->Stride];
|
||||
auto zMapDstPtr = &dstZmap->ZPtr2[xOffset + yOffset * dstZmap->Stride];
|
||||
auto bmpSrcPtr = reinterpret_cast<unsigned short*>(srcBmp->BmpBufPtr2);
|
||||
auto bmpSrcPtr = reinterpret_cast<unsigned short*>(srcBmp->BmpBufPtr1);
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user