timer v1, ready.

winmain uninit.
message_handler tweaks.
This commit is contained in:
oz 2020-12-04 18:35:47 +03:00
parent fe66d33768
commit 090beefd07
23 changed files with 327 additions and 121 deletions

Binary file not shown.

View File

@ -1,9 +1,9 @@
#include "pch.h" #include "pch.h"
#include "Sound.h" #include "Sound.h"
int Sound::Init(HINSTANCE hInstance, int voices, void(__stdcall* someFuncPtr)(int, int, int)) int Sound::Init(HINSTANCE hInstance, int voices, void (__stdcall* someFuncPtr)(int, int, int))
{ {
return 1; return 1;
} }
void Sound::Enable(int a1, int a2, int a3) void Sound::Enable(int a1, int a2, int a3)
@ -29,3 +29,13 @@ void Sound::Deactivate()
void Sound::Close() void Sound::Close()
{ {
} }
int Sound::SubFactor(int a1, int a2)
{
return a1 - a2;
}
int Sound::AddFactor(int a1, int a2)
{
return a1 + a2;
}

View File

@ -9,4 +9,6 @@ public:
static void Activate(); static void Activate();
static void Deactivate(); static void Deactivate();
static void Close(); static void Close();
static int SubFactor(int a1, int a2);
static int AddFactor(int a1, int a2);
}; };

View File

@ -64,36 +64,36 @@ MENU_1 MENU
BEGIN BEGIN
POPUP "&Game" POPUP "&Game"
BEGIN BEGIN
MENUITEM "&New Game\tF2", 101 MENUITEM "&New Game\tF2", Menu1_New_Game
MENUITEM "&Launch Ball", 401 MENUITEM "&Launch Ball", Menu1_Launch_Ball
MENUITEM "&Pause/Resume Game\tF3", 402 MENUITEM "&Pause/Resume Game\tF3", Menu1_Pause_Resume_Game
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "&High Scores...", 103 MENUITEM "&High Scores...", Menu1_High_Scores
MENUITEM "&Demo", 404 MENUITEM "&Demo", Menu1_Demo
MENUITEM "E&xit", 105 MENUITEM "E&xit", Menu1_Exit
END END
POPUP "&Options" POPUP "&Options"
BEGIN BEGIN
MENUITEM "&Full Screen\tF4", 403 MENUITEM "&Full Screen\tF4", Menu1_Full_Screen
MENUITEM "Select &Table", 405 MENUITEM "Select &Table", Menu1_Select_Table
POPUP "Select &Players" POPUP "Select &Players"
BEGIN BEGIN
MENUITEM "&1 Player", 408 MENUITEM "&1 Player", Menu1_1Player
MENUITEM "&2 Players", 409 MENUITEM "&2 Players", Menu1_2Players
MENUITEM "&3 Players", 410 MENUITEM "&3 Players", Menu1_3Players
MENUITEM "&4 Players", 411 MENUITEM "&4 Players", Menu1_4Players
END END
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "&Sounds", 201 MENUITEM "&Sounds", Menu1_Sounds
MENUITEM "&Music", 202 MENUITEM "&Music", Menu1_Music
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "P&layer Controls...\tF8", 406 MENUITEM "P&layer Controls...\tF8", Menu1_Player_Controls
END END
POPUP "&Help" POPUP "&Help"
BEGIN BEGIN
MENUITEM "&Help Topics\tF1", 301 MENUITEM "&Help Topics\tF1", Menu1_Help_Topics
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "&About Pinball", 102 MENUITEM "&About Pinball", Menu1_About_Pinball
END END
END END

View File

@ -72,6 +72,7 @@
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>

View File

@ -219,7 +219,7 @@ TPinballTable::~TPinballTable()
{ {
//if (i) //if (i)
//(*(void(__thiscall**)(TLightGroup*, int))(*(_DWORD*)i + 16))(i, 1); //(*(void(__thiscall**)(TLightGroup*, int))(*(_DWORD*)i + 16))(i, 1);
if (!ListP1->Count()) //if (!ListP1->Count())
break; break;
} }
delete ListP2; delete ListP2;

View File

@ -1,2 +1,8 @@
#include "pch.h" #include "pch.h"
#include "TRamp.h" #include "TRamp.h"
void TRamp::port_draw()
{
TCollisionComponent::port_draw();
}

View File

@ -8,4 +8,6 @@ public:
TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false) TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false)
{ {
} }
void port_draw() override;
}; };

View File

@ -50,8 +50,9 @@ int TTextBox::Message(int code, float value)
return 0; return 0;
} }
void TTextBox::TimerExpired(int a2, TTextBox* tb) void TTextBox::TimerExpired(int timerId, void* caller)
{ {
auto tb = static_cast<TTextBox*>(caller);
TTextBoxMessage* message = tb->Message1; TTextBoxMessage* message = tb->Message1;
tb->Timer = 0; tb->Timer = 0;
if (message) if (message)
@ -117,7 +118,7 @@ void TTextBox::Display(char* text, float time)
if (time == -1.0) if (time == -1.0)
Timer = -1; Timer = -1;
else else
Timer = timer::set(time, (int)this, (int)TimerExpired); Timer = timer::set(time, this, TimerExpired);
} }
} }
else else
@ -205,11 +206,11 @@ void TTextBox::Draw()
int timer; int timer;
if (timeLeft >= 0.25f) if (timeLeft >= 0.25f)
{ {
timer = timer::set(timeLeft, (int)this2, (int)TimerExpired); timer = timer::set(timeLeft, this2, TimerExpired);
} }
else else
{ {
timer = timer::set(0.25, (int)this2, (int)TimerExpired); timer = timer::set(0.25, this2, TimerExpired);
} }
this2->Timer = timer; this2->Timer = timer;
goto LABEL_18; goto LABEL_18;

View File

@ -24,5 +24,5 @@ public:
void Display(char* text, float time); void Display(char* text, float time);
void Draw(); void Draw();
static void TimerExpired(int a2, TTextBox* tb); static void TimerExpired(int timerId, void* tb);
}; };

View File

@ -3,20 +3,25 @@
MCIERROR midi::play_pb_theme(int flag) MCIERROR midi::play_pb_theme(int flag)
{ {
return MCIERROR(); return MCIERROR();
} }
MCIERROR midi::music_stop() MCIERROR midi::music_stop()
{ {
return MCIERROR(); return MCIERROR();
} }
int midi::music_init(HWND hwnd) int midi::music_init(HWND hwnd)
{ {
return 1; return 1;
} }
MCIERROR midi::restart_midi_seq(int param) MCIERROR midi::restart_midi_seq(int param)
{ {
return MCIERROR(); return MCIERROR();
}
MCIERROR midi::music_shutdown()
{
return MCIERROR();
} }

View File

@ -6,4 +6,5 @@ public:
static MCIERROR music_stop(); static MCIERROR music_stop();
static int music_init(HWND hwnd); static int music_init(HWND hwnd);
static MCIERROR restart_midi_seq(int param); static MCIERROR restart_midi_seq(int param);
static MCIERROR music_shutdown();
}; };

View File

@ -5,6 +5,7 @@
#include "memory.h" #include "memory.h"
#include "midi.h" #include "midi.h"
#include "pinball.h" #include "pinball.h"
#include "resource.h"
#include "Sound.h" #include "Sound.h"
#include "winmain.h" #include "winmain.h"
@ -68,7 +69,7 @@ void options::init(HMENU menuHandle)
{ {
if (MenuHandle) if (MenuHandle)
{ {
DeleteMenu(MenuHandle, 0x195u, 0); DeleteMenu(MenuHandle, Menu1_Select_Table, 0);
DrawMenuBar(winmain::hwnd_frame); DrawMenuBar(winmain::hwnd_frame);
} }
} }
@ -76,6 +77,20 @@ void options::init(HMENU menuHandle)
} }
} }
void options::uninit()
{
set_int(nullptr, "Sounds", Options.Sounds);
set_int(nullptr, "Music", Options.Music);
set_int(nullptr, "FullScreen", Options.FullScreen);
set_int(nullptr, "Players", Options.Players);
set_int(nullptr, "Left Flippper key", Options.LeftFlipperKey);
set_int(nullptr, "Right Flipper key", Options.RightFlipperKey);
set_int(nullptr, "Plunger key", Options.PlungerKey);
set_int(nullptr, "Left Table Bump key", Options.LeftTableBumpKey);
set_int(nullptr, "Right Table Bump key", Options.RightTableBumpKey);
set_int(nullptr, "Bottom Table Bump key", Options.BottomTableBumpKey);
}
void options::path_init(LPCSTR regPath) void options::path_init(LPCSTR regPath)
{ {
char* buf = memory::allocate(lstrlenA(regPath) + 1); char* buf = memory::allocate(lstrlenA(regPath) + 1);
@ -207,13 +222,13 @@ void options::toggle(UINT uIDCheckItem)
int newValue; int newValue;
switch (uIDCheckItem) switch (uIDCheckItem)
{ {
case 0xC9u: case Menu1_Sounds:
newValue = Options.Sounds == 0; newValue = Options.Sounds == 0;
Options.Sounds = Options.Sounds == 0; Options.Sounds = Options.Sounds == 0;
Sound::Enable(0, 7, newValue); Sound::Enable(0, 7, newValue);
menu_check(uIDCheckItem, newValue); menu_check(uIDCheckItem, newValue);
return; return;
case 0xCAu: case Menu1_Music:
newValue = Options.Music == 0; newValue = Options.Music == 0;
Options.Music = Options.Music == 0; Options.Music = Options.Music == 0;
if (!newValue) if (!newValue)
@ -222,7 +237,7 @@ void options::toggle(UINT uIDCheckItem)
midi::play_pb_theme(0); midi::play_pb_theme(0);
menu_check(uIDCheckItem, newValue); menu_check(uIDCheckItem, newValue);
return; return;
case 0x193u: case Menu1_Full_Screen:
newValue = Options.FullScreen == 0; newValue = Options.FullScreen == 0;
Options.FullScreen = Options.FullScreen == 0; Options.FullScreen = Options.FullScreen == 0;
fullscrn::set_screen_mode(newValue); fullscrn::set_screen_mode(newValue);
@ -232,7 +247,7 @@ void options::toggle(UINT uIDCheckItem)
if (uIDCheckItem > 407 && uIDCheckItem <= 411) if (uIDCheckItem > 407 && uIDCheckItem <= 411)
{ {
Options.Players = uIDCheckItem - 407; Options.Players = uIDCheckItem - 407;
menu_check(0x198u, uIDCheckItem == 408); menu_check(0x198u, Options.Players == 1);
menu_check(0x199u, Options.Players == 2); menu_check(0x199u, Options.Players == 2);
menu_check(0x19Au, Options.Players == 3); menu_check(0x19Au, Options.Players == 3);
menu_check(0x19Bu, Options.Players == 4); menu_check(0x19Bu, Options.Players == 4);

View File

@ -27,6 +27,7 @@ class options
{ {
public: public:
static void init(HMENU menuHandle); static void init(HMENU menuHandle);
static void uninit();
static void path_init(LPCSTR regPath); static void path_init(LPCSTR regPath);
static void path_uninit(); static void path_uninit();
static int get_int(LPCSTR optPath, LPCSTR lpValueName, int defaultValue); static int get_int(LPCSTR optPath, LPCSTR lpValueName, int defaultValue);

View File

@ -58,7 +58,8 @@ int pb::init()
} }
render::init(nullptr, zMin, zScaler, tableSize[0], tableSize[1]); render::init(nullptr, zMin, zScaler, tableSize[0], tableSize[1]);
gdrv::fill_bitmap(&render::vscreen, render::vscreen.Width, render::vscreen.Height, 0, 0, (char)0xff); // temp gdrv::fill_bitmap(&render::vscreen, render::vscreen.Width, render::vscreen.Height, 0, 0,
static_cast<char>(0xff)); // temp
gdrv::copy_bitmap( gdrv::copy_bitmap(
&render::vscreen, &render::vscreen,
backgroundBmp->Width, backgroundBmp->Width,
@ -91,6 +92,21 @@ int pb::init()
return 0; return 0;
} }
int pb::uninit()
{
score::unload_msg_font();
loader::unload();
partman::unload_records(record_table);
//high_score_write(highscore_table, (int)&pb_state);
if (MainTable)
delete MainTable;
MainTable = nullptr;
gdrv::get_focus();
timer::uninit();
render::uninit();
return 0;
}
void pb::reset_table() void pb::reset_table()
{ {
if (MainTable) if (MainTable)
@ -166,7 +182,7 @@ int pb::frame(int time)
v2 = 0.0; v2 = 0.0;
nudge_count = v2; nudge_count = v2;
}*/ }*/
//timer::check(); timer::check();
render::update(); render::update();
//score::update(MainTable->Score1); //score::update(MainTable->Score1);
/*if (!MainTable->UnknownP83) /*if (!MainTable->UnknownP83)

View File

@ -12,6 +12,7 @@ public:
static TPinballTable* MainTable; static TPinballTable* MainTable;
static int init(); static int init();
static int uninit();
static void reset_table(); static void reset_table();
static void firsttime_setup(); static void firsttime_setup();
static void paint(); static void paint();

View File

@ -25,7 +25,7 @@ char* pinball::get_rc_string(int uID, int a2)
int pinball::get_rc_int(int uID, int* dst) int pinball::get_rc_int(int uID, int* dst)
{ {
char buffer[50]; char buffer[255];
int result = LoadStringA(winmain::hinst, uID, buffer, 255); int result = LoadStringA(winmain::hinst, uID, buffer, 255);
if (!result) if (!result)
return result; return result;
@ -38,7 +38,7 @@ void pinball::FindShiftKeys()
{ {
signed int i; // esi signed int i; // esi
int rightShift; // eax int rightShift; // eax
CHAR stringBuf[10]; // [esp+Ch] [ebp-18h] CHAR stringBuf[20]; // [esp+Ch] [ebp-18h]
RightShift = -1; RightShift = -1;
LeftShift = -1; LeftShift = -1;

View File

@ -104,10 +104,14 @@
#define IDS_STRING200 99 #define IDS_STRING200 99
#define IDS_STRING201 100 #define IDS_STRING201 100
#define IDS_STRING202 101 #define IDS_STRING202 101
#define Menu1_New_Game 101
#define IDS_STRING203 102 #define IDS_STRING203 102
#define Menu1_About_Pinball 102
#define IDS_STRING204 103 #define IDS_STRING204 103
#define Menu1_High_Scores 103
#define IDS_STRING205 104 #define IDS_STRING205 104
#define IDS_STRING206 105 #define IDS_STRING206 105
#define Menu1_Exit 105
#define IDS_STRING207 106 #define IDS_STRING207 106
#define IDS_STRING208 107 #define IDS_STRING208 107
#define IDS_STRING209 108 #define IDS_STRING209 108
@ -191,13 +195,27 @@
#define IDS_STRING287 187 #define IDS_STRING287 187
#define IDS_STRING288 188 #define IDS_STRING288 188
#define IDS_STRING289 189 #define IDS_STRING289 189
#define Menu1_Sounds 201
#define Menu1_Music 202
#define Menu1_Help_Topics 301
#define Menu1_Launch_Ball 401
#define Menu1_Pause_Resume_Game 402
#define Menu1_Full_Screen 403
#define Menu1_Demo 404
#define Menu1_Select_Table 405
#define Menu1_Player_Controls 406
#define Menu1_1Player 408
#define Menu1_2Players 409
#define Menu1_3Players 410
#define Menu1_4Players 411
#define ID_GAME_D 40003
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 201 #define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_COMMAND_VALUE 40002 #define _APS_NEXT_COMMAND_VALUE 40004
#define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif

View File

@ -54,3 +54,7 @@ HRSRC score::load_msg_font(LPCSTR lpName)
{ {
return nullptr; return nullptr;
} }
void score::unload_msg_font()
{
}

View File

@ -24,7 +24,6 @@ struct scoreStruct
struct score_msg_font_type struct score_msg_font_type
{ {
}; };
class score class score
@ -35,4 +34,5 @@ public:
static scoreStruct* create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp); static scoreStruct* create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp);
static scoreStruct* dup(scoreStruct* score, int scoreIndex); static scoreStruct* dup(scoreStruct* score, int scoreIndex);
static HRSRC load_msg_font(LPCSTR lpName); static HRSRC load_msg_font(LPCSTR lpName);
static void unload_msg_font();
}; };

View File

@ -2,47 +2,152 @@
#include "timer.h" #include "timer.h"
#include "memory.h" #include "memory.h"
#include "pb.h"
timer_struct timer::timer_struct; timer_struct timer::timerStruct{};
int timer::setCount; int timer::set_count;
int timer::init(int count) int timer::init(int count)
{ {
char* buf; // eax auto buf = (timer_sub_struct*)memory::allocate(sizeof(timer_sub_struct) * count);
int index; // edx timerStruct.TimerMem = buf;
int* v4; // ecx
buf = memory::allocate(20 * count);
timer_struct.buffer1 = buf;
if (!buf) if (!buf)
return 1; return 1;
timer_struct.target = 0; timerStruct.Count = 0;
index = count - 1; timerStruct.MaxCount = count;
timer_struct.count = count; set_count = 1;
setCount = 1;
if (count - 1 > 0) for (int index = 0; index < count - 1; index++)
buf[index].NextTimer = &buf[index + 1];
buf[count - 1].NextTimer = nullptr;
timerStruct.NextTimer = nullptr;
timerStruct.LastTimer = buf;
return 0;
}
void timer::uninit()
{
if (timerStruct.TimerMem)
memory::free(timerStruct.TimerMem);
timerStruct.TimerMem = nullptr;
}
int timer::kill(int timerId)
{
timer_sub_struct* next = timerStruct.NextTimer;
int index = 0;
timer_sub_struct* current = nullptr;
if (timerStruct.Count <= 0)
return 0;
while (timerId != next->TimerId)
{ {
v4 = (int*)(buf + 12); ++index;
do current = next;
{ next = next->NextTimer;
*v4 = (int)(v4 + 2); if (index >= timerStruct.Count)
v4 += 5; return 0;
--index;
}
while (index);
} }
*(int*)&buf[20 * count - 8] = 0; if (current)
timer_struct.target2 = 0; current->NextTimer = next->NextTimer;
timer_struct.buffer2 = buf; else
return 0; timerStruct.NextTimer = next->NextTimer;
--timerStruct.Count;
next->NextTimer = timerStruct.LastTimer;
timerStruct.LastTimer = next;
return timerId;
} }
int timer::kill(int timer) int timer::set(float time, void* caller, void (* callback)(int, void*))
{ {
return 0; if (timerStruct.Count >= timerStruct.MaxCount)
return 0;
/*timerStruct.LastTimer->NextTimer = nullptr;
timerStruct.LastTimer = timerStruct.LastTimer->NextTimer;*/
auto lastNext = timerStruct.LastTimer->NextTimer;
timerStruct.LastTimer->NextTimer = nullptr;
timerStruct.LastTimer = lastNext;
auto prev = timerStruct.NextTimer;
auto current = timerStruct.NextTimer;
auto targetTime = pb::time_ticks + static_cast<int>(time * 1000.0f);
for (int index = 0; index < timerStruct.Count && targetTime >= current->TargetTime; ++index)
{
prev = current;
current = current->NextTimer;
}
auto last = timerStruct.LastTimer;
if (current != prev)
{
timerStruct.LastTimer->NextTimer = prev->NextTimer;
prev->NextTimer = last;
}
else
{
timerStruct.LastTimer->NextTimer = timerStruct.NextTimer;
timerStruct.NextTimer = last;
}
last->Caller = caller;
last->Callback = callback;
last->TimerId = set_count;
last->TargetTime = targetTime;
timerStruct.Count++;
set_count++;
if (set_count <= 0)
set_count = 1;
return last->TimerId;
} }
int timer::set(float time, int caller, int callback) int timer::check()
{ {
return 0; timer_sub_struct curCopy{};
timer_sub_struct* current = timerStruct.NextTimer;
int index = 0;
if (timerStruct.NextTimer)
{
while (pb::time_ticks >= current->TargetTime)
{
--timerStruct.Count;
memcpy(&curCopy, current, sizeof curCopy);
timer_sub_struct** nextPtr = &current->NextTimer;
current = current->NextTimer;
timerStruct.NextTimer = current;
*nextPtr = timerStruct.LastTimer;
timerStruct.LastTimer = current;
if (curCopy.Callback != nullptr)
{
curCopy.Callback(curCopy.TimerId, curCopy.Caller);
current = timerStruct.NextTimer;
}
++index;
if (index > 1)
break;
if (!current)
return index;
}
while (current && pb::time_ticks >= current->TargetTime + 100)
{
--timerStruct.Count;
memcpy(&curCopy, current, sizeof curCopy);
timer_sub_struct** nextPtr = &current->NextTimer;
current = current->NextTimer;
timerStruct.NextTimer = current;
*nextPtr = timerStruct.LastTimer;
timerStruct.LastTimer = current;
if (curCopy.Callback != nullptr)
{
curCopy.Callback(curCopy.TimerId, curCopy.Caller);
current = timerStruct.NextTimer;
}
++index;
}
}
return index;
} }

View File

@ -1,12 +1,21 @@
#pragma once #pragma once
struct __declspec(align(4)) timer_sub_struct
{
int TargetTime;
void* Caller;
void (* Callback)(int, void*);
timer_sub_struct* NextTimer;
int TimerId;
};
struct __declspec(align(4)) timer_struct struct __declspec(align(4)) timer_struct
{ {
int target2; timer_sub_struct* NextTimer;
int count; int MaxCount;
int target; int Count;
char* buffer2; timer_sub_struct* LastTimer;
char* buffer1; timer_sub_struct* TimerMem;
}; };
@ -14,10 +23,12 @@ class timer
{ {
public: public:
static int init(int count); static int init(int count);
static int kill(int timer); static void uninit();
static int set(float time, int caller, int callback); static int kill(int timerId);
static int set(float time, void* caller, void (* callback)(int, void*));
static int check();
private: private:
static timer_struct timer_struct; static timer_struct timerStruct;
static int setCount; static int set_count;
}; };

View File

@ -8,6 +8,7 @@
#include "options.h" #include "options.h"
#include "pb.h" #include "pb.h"
#include "Sound.h" #include "Sound.h"
#include "resource.h"
HINSTANCE winmain::hinst = nullptr; HINSTANCE winmain::hinst = nullptr;
HWND winmain::hwnd_frame = nullptr; HWND winmain::hwnd_frame = nullptr;
@ -68,6 +69,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if (tmpBuf2) if (tmpBuf2)
{ {
char Buffer[40]; char Buffer[40];
bool setOption = false;
for (int i = 0; i < 32700; ++i) for (int i = 0; i < 32700; ++i)
{ {
sprintf_s(Buffer, "Table%d", i); sprintf_s(Buffer, "Table%d", i);
@ -76,12 +78,15 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
break; break;
options::get_string(tmpBuf, "Table Name", tmpBuf2, pinball::WindowName, 500); options::get_string(tmpBuf, "Table Name", tmpBuf2, pinball::WindowName, 500);
if (!lstrcmpA(tmpBuf2, pinball::get_rc_string(169, 0))) if (!lstrcmpA(tmpBuf2, pinball::get_rc_string(169, 0)))
goto LABEL_15; {
setOption = false;
break;
}
if (!*tmpBuf2) if (!*tmpBuf2)
break; break;
} }
options::set_string(nullptr, Buffer, regSpaceCadet); if (setOption)
LABEL_15: options::set_string(nullptr, Buffer, regSpaceCadet);
memory::free(tmpBuf2); memory::free(tmpBuf2);
} }
memory::free(tmpBuf); memory::free(tmpBuf);
@ -111,7 +116,8 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
options::get_string(regSpaceCadet, "Pinball Data", DatFileName, pinball::get_rc_string(168, 0), 300); options::get_string(regSpaceCadet, "Pinball Data", DatFileName, pinball::get_rc_string(168, 0), 300);
iFrostUniqueMsg = RegisterWindowMessageA("PinballThemeSwitcherUniqueMsgString"); iFrostUniqueMsg = RegisterWindowMessageA("PinballThemeSwitcherUniqueMsgString");
auto windowHandle = FindWindowA(pinball::get_rc_string(167, 0), nullptr); auto windowClass = pinball::get_rc_string(167, 0);
auto windowHandle = FindWindowA(windowClass, nullptr);
if (windowHandle) if (windowHandle)
{ {
SendMessageA(windowHandle, iFrostUniqueMsg, 0, 0); SendMessageA(windowHandle, iFrostUniqueMsg, 0, 0);
@ -125,8 +131,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
picce.dwSize = 8; picce.dwSize = 8;
picce.dwICC = 5885; picce.dwICC = 5885;
InitCommonControlsEx(&picce); InitCommonControlsEx(&picce);
auto windowClass = pinball::get_rc_string(167, 0);
WNDCLASSA WndClass{}; WNDCLASSA WndClass{};
WndClass.style = 4104; WndClass.style = 4104;
WndClass.lpfnWndProc = message_handler; WndClass.lpfnWndProc = message_handler;
@ -178,7 +183,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
pinball::adjust_priority(options::Options.PriorityAdj); pinball::adjust_priority(options::Options.PriorityAdj);
const auto startTime = timeGetTime(); const auto startTime = timeGetTime();
MSG wndMessage{}; MSG wndMessage{};
while (timeGetTime() >= startTime && timeGetTime() - startTime < 0)// Don't wait for now, was 2000 while (timeGetTime() >= startTime && timeGetTime() - startTime < 0) // Don't wait for now, was 2000
PeekMessageA(&wndMessage, hwnd_frame, 0, 0, 1u); PeekMessageA(&wndMessage, hwnd_frame, 0, 0, 1u);
if (strstr(lpCmdLine, "-demo")) if (strstr(lpCmdLine, "-demo"))
@ -277,7 +282,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
{ {
fillChar = -7; fillChar = -7;
} }
gdrv::fill_bitmap(&gfr_display, 1, 10, 299u - someTimeCounter, 0, fillChar); gdrv::fill_bitmap(&gfr_display, 1, 10, 299 - someTimeCounter, 0, fillChar);
} }
--someTimeCounter; --someTimeCounter;
then = now; then = now;
@ -286,6 +291,15 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
} }
} }
gdrv::destroy_bitmap(&gfr_display);
options::uninit();
midi::music_shutdown();
pb::uninit();
Sound::Close();
gdrv::uninit();
DestroyWindow(hwnd_frame);
options::path_uninit();
UnregisterClassA(windowClass, hinst);
return return_value; return return_value;
} }
@ -499,23 +513,18 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
no_time_loss = 1; no_time_loss = 1;
switch (wParam) switch (wParam)
{ {
case 0x191u: case Menu1_Launch_Ball:
end_pause(); end_pause();
pb::launch_ball(); pb::launch_ball();
break; break;
case 0x192u: case Menu1_Pause_Resume_Game:
pause(); pause();
break; break;
case 0x193u: case Menu1_Demo:
if (!single_step)
pause();
options::toggle(wParam);
break;
case 0x194u:
end_pause(); end_pause();
pb::toggle_demo(); pb::toggle_demo();
break; break;
case 0x195u: case Menu1_Select_Table:
{ {
if (!single_step) if (!single_step)
pause(); pause();
@ -548,55 +557,53 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
} }
break; break;
} }
case 0x196u: case Menu1_1Player:
if (!single_step) case Menu1_2Players:
pause(); case Menu1_3Players:
options::keyboard(); case Menu1_4Players:
break;
case 0x198u:
case 0x199u:
case 0x19Au:
case 0x19Bu:
options::toggle(wParam); options::toggle(wParam);
new_game(); new_game();
break; break;
case 301: case Menu1_Help_Topics:
if (!single_step) if (!single_step)
pause(); pause();
help_introduction(hinst, hWnd); help_introduction(hinst, hWnd);
return DefWindowProcA(hWnd, Msg, wParam, lParam); break;
case 0x6A: case 106: // End game button?
pb::end_game(); pb::end_game();
return DefWindowProcA(hWnd, Msg, wParam, lParam); break;
case 201: case Menu1_Full_Screen:
case 202: case Menu1_Sounds:
case Menu1_Music:
if (!single_step) if (!single_step)
pause(); pause();
options::toggle(wParam); options::toggle(wParam);
break; break;
case 204: case Menu1_Player_Controls:
case 204: // Second controls button?
if (!single_step) if (!single_step)
pause(); pause();
options::keyboard(); options::keyboard();
break; break;
case 0x69u: case Menu1_Exit:
PostMessageA(hWnd, 0x12u, 0, 0); PostMessageA(hWnd, WM_QUIT, 0, 0);
return DefWindowProcA(hWnd, Msg, wParam, lParam); break;
case 0x65u: case Menu1_New_Game:
new_game(); new_game();
return DefWindowProcA(hWnd, Msg, wParam, lParam); break;
case 0x66u: case Menu1_About_Pinball:
if (!single_step) if (!single_step)
pause(); pause();
a_dialog(hinst, hWnd); a_dialog(hinst, hWnd);
return DefWindowProcA(hWnd, Msg, wParam, lParam); break;
case 0x67u: case Menu1_High_Scores:
if (!single_step) if (!single_step)
pause(); pause();
pb::high_scores(); pb::high_scores();
return DefWindowProcA(hWnd, Msg, wParam, lParam); break;
case 1: case 1: // Unknown button
midi::restart_midi_seq(lParam); midi::restart_midi_seq(lParam);
break;
default: default:
break; break;
} }