Skip to content

Commit 4c196a9

Browse files
committed
Added table resolution and UI scale options.
gdrv: blit directly to backing store of vScreen texture. Added missing cheat_bump_rank sub, oops. Fixed some warnings.
1 parent c63c670 commit 4c196a9

21 files changed

+138
-183
lines changed

SpaceCadetPinball/Sound.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include "Sound.h"
33

44

5-
#include "pb.h"
6-
75
int Sound::num_channels;
86
unsigned int Sound::enabled_flag = -1;
97

@@ -14,6 +12,7 @@ int Sound::Init(int voices)
1412
channelCount = 8;
1513
num_channels = channelCount;
1614

15+
auto init = Mix_Init(MIX_INIT_MID);
1716
return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
1817
}
1918

@@ -34,17 +33,23 @@ void Sound::Deactivate()
3433

3534
void Sound::Close()
3635
{
36+
Mix_CloseAudio();
3737
Mix_Quit();
3838
}
3939

4040
void Sound::PlaySound(Mix_Chunk* wavePtr, int minChannel, int maxChannel, unsigned int dwFlags, int16_t loops)
4141
{
42-
if (enabled_flag)
42+
if (wavePtr && enabled_flag)
4343
Mix_PlayChannel(-1, wavePtr, loops);
4444
}
4545

4646
Mix_Chunk* Sound::LoadWaveFile(std::string lpName)
4747
{
48+
auto wavFile = fopen(lpName.c_str(), "r");
49+
if (!wavFile)
50+
return nullptr;
51+
fclose(wavFile);
52+
4853
return Mix_LoadWAV(lpName.c_str());
4954
}
5055

SpaceCadetPinball/SpaceCadetPinball.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ int main(int argc, char* argv[])
1212
std::string cmdLine;
1313
for (int i = 0; i < argc; i++)
1414
cmdLine += argv[i];
15-
winmain::WinMain(cmdLine.c_str());
16-
return 0;
15+
16+
// Todo: get rid of restart to change resolution.
17+
int returnCode;
18+
do
19+
{
20+
returnCode = winmain::WinMain(cmdLine.c_str());
21+
}
22+
while (winmain::RestartRequested());
23+
return returnCode;
1724
}
1825
}
1926

SpaceCadetPinball/TPinballComponent.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
4848
zMap = ListZMap->Get(0);
4949
if (ListBitmap)
5050
{
51-
/* Full tilt hack - spliced bitmap includes zMap
52-
* Users access bitmap-zMap in pairs, pad zMap list with 0 for such users
53-
* zdrv does not access zMap when drawing spliced bitmap*/
54-
if (!ListZMap)
55-
{
56-
ListZMap = new objlist_class<zmap_header_type>(0, 4);
57-
for (int index = 0; index < ListBitmap->GetCount(); index++)
58-
{
59-
assertm(ListBitmap->Get(index)->BitmapType == BitmapTypes::Spliced, "Wrong zMap padding");
60-
ListZMap->Add(visual.ZMap);
61-
}
62-
}
63-
6451
rectangle_type bmp1Rect{}, tmpRect{};
6552
auto rootBmp = ListBitmap->Get(0);
6653
bmp1Rect.XPosition = rootBmp->XPosition - table->XOffset;

SpaceCadetPinball/TPinballTable.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ TPinballTable::~TPinballTable()
219219
}
220220
delete BallList;
221221
delete ComponentList;
222+
control::ClearLinks();
222223
}
223224

224225
TPinballComponent* TPinballTable::find_component(LPCSTR componentName)

SpaceCadetPinball/control.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,14 @@ void control::make_links(TPinballTable* table)
592592
make_component_link(simple_components[i]);
593593
}
594594

595+
void control::ClearLinks()
596+
{
597+
TableG = nullptr;
598+
for (auto& component : score_components)
599+
component.Tag->SetComponent(nullptr);
600+
for (auto& component : simple_components)
601+
component->SetComponent(nullptr);
602+
}
595603

596604
TPinballComponent* control::make_component_link(component_tag_base* tag)
597605
{
@@ -904,9 +912,19 @@ void control::table_set_replay(float value)
904912
control_info_text_box_tag.Component->Display(pinball::get_rc_string(0, 0), value);
905913
}
906914

907-
int control::cheat_bump_rank()
915+
void control::cheat_bump_rank()
908916
{
909-
return 0;
917+
char Buffer[64]{};
918+
919+
auto rank = control_middle_circle_tag.Component->Message(37, 0.0);
920+
if (rank < 9)
921+
{
922+
control_middle_circle_tag.Component->Message(41, 2.0f);
923+
auto rankText = pinball::get_rc_string(RankRcArray[rank], 1);
924+
snprintf(Buffer,sizeof Buffer, pinball::get_rc_string(83, 0), rankText);
925+
control_mission_text_box_tag.Component->Display(Buffer, 8.0);
926+
control_soundwave10_tag.Component->Play();
927+
}
910928
}
911929

912930
bool control::light_on(component_tag<TLight>* tag)

SpaceCadetPinball/control.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class control
7070
static component_tag_base *wormhole_tag_array1[3], *wormhole_tag_array2[3], *wormhole_tag_array3[3];
7171

7272
static void make_links(TPinballTable* table);
73+
static void ClearLinks();
7374
static TPinballComponent* make_component_link(component_tag_base* tag);
7475
static void handler(int code, TPinballComponent* cmp);
7576
static void pbctrl_bdoor_controller(int key);
@@ -81,7 +82,7 @@ class control
8182
static void table_set_multiball();
8283
static void table_bump_ball_sink_lock();
8384
static void table_set_replay(float value);
84-
static int cheat_bump_rank();
85+
static void cheat_bump_rank();
8586
static bool light_on(component_tag<TLight>* tag);
8687
static int SpecialAddScore(int score);
8788
static int AddRankProgress(int rank);

SpaceCadetPinball/fullscrn.cpp

+1-38
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ int fullscrn::screen_mode;
1212
int fullscrn::display_changed;
1313

1414
int fullscrn::resolution = 0;
15-
int fullscrn::maxResolution = 0;
1615
const resolution_info fullscrn::resolution_array[3] =
1716
{
1817
{640, 480, 600, 416, 501},
@@ -103,43 +102,7 @@ void fullscrn::SetResolution(int value)
103102

104103
int fullscrn::GetMaxResolution()
105104
{
106-
return maxResolution;
107-
}
108-
109-
void fullscrn::SetMaxResolution(int value)
110-
{
111-
assertm(value >= 0 && value <= 2, "Resolution value out of bounds");
112-
maxResolution = value;
113-
}
114-
115-
int fullscrn::get_max_supported_resolution()
116-
{
117-
if (!pb::FullTiltMode)
118-
return 0;
119-
120-
int width = 0, height = 0;
121-
get_screen_resolution(&width, &height);
122-
auto result = 0;
123-
124-
for (auto index = 1; index < 3; ++index)
125-
{
126-
auto resPtr = &resolution_array[index];
127-
if (resPtr->ScreenWidth <= width && resPtr->ScreenHeight <= height)
128-
result = index;
129-
}
130-
return result;
131-
}
132-
133-
int fullscrn::get_screen_resolution(int* width, int* height)
134-
{
135-
SDL_DisplayMode dm;
136-
if (SDL_GetDesktopDisplayMode(0, &dm) == 0)
137-
{
138-
*width = dm.w;
139-
*height = dm.h;
140-
return 0;
141-
}
142-
return 1;
105+
return pb::FullTiltMode ? 2 : 0;
143106
}
144107

145108
void fullscrn::window_size_changed()

SpaceCadetPinball/fullscrn.h

-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ class fullscrn
2727
static int GetResolution();
2828
static void SetResolution(int value);
2929
static int GetMaxResolution();
30-
static void SetMaxResolution(int value);
31-
static int get_max_supported_resolution();
32-
static int get_screen_resolution(int* width, int* height);
3330
static void window_size_changed();
3431
private :
3532
static int resolution;
36-
static int maxResolution;
3733

3834
static int enableFullscreen();
3935
static int disableFullscreen();

SpaceCadetPinball/gdrv.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,25 @@ int gdrv::init(int width, int height)
2424
SDL_TEXTUREACCESS_STREAMING,
2525
width, height
2626
);
27-
vScreenPixels = memory::allocate<ColorRgba>(width * height);
2827
vScreenWidth = width;
2928
vScreenHeight = height;
29+
30+
int pitch = 0;
31+
SDL_LockTexture
32+
(
33+
vScreenTex,
34+
nullptr,
35+
reinterpret_cast<void**>(&vScreenPixels),
36+
&pitch
37+
);
38+
assertm(pitch = width* sizeof(ColorRgba), "gdrv: wrong pitch of SDL texture");
3039

3140
return 0;
3241
}
3342

3443
int gdrv::uninit()
3544
{
3645
SDL_DestroyTexture(vScreenTex);
37-
memory::free(vScreenPixels);
3846
return 0;
3947
}
4048

@@ -191,14 +199,6 @@ int gdrv::destroy_bitmap(gdrv_bitmap8* bmp)
191199
return 0;
192200
}
193201

194-
void gdrv::start_blit_sequence()
195-
{
196-
}
197-
198-
void gdrv::end_blit_sequence()
199-
{
200-
}
201-
202202
void gdrv::blit(gdrv_bitmap8* bmp, int xSrc, int ySrc, int xDest, int yDest, int width, int height)
203203
{
204204
StretchDIBitsScaled(
@@ -321,22 +321,20 @@ int gdrv::StretchDIBitsScaled(int xSrc, int ySrc, int xDst, int yDst,
321321

322322
void gdrv::BlitScreen()
323323
{
324-
unsigned char* lockedPixels = nullptr;
325324
int pitch = 0;
325+
SDL_UnlockTexture(vScreenTex);
326+
SDL_RenderCopy(winmain::Renderer, vScreenTex, nullptr, &DestinationRect);
326327
SDL_LockTexture
327328
(
328329
vScreenTex,
329330
nullptr,
330-
reinterpret_cast<void**>(&lockedPixels),
331+
reinterpret_cast<void**>(&vScreenPixels),
331332
&pitch
332333
);
333-
std::memcpy(lockedPixels, vScreenPixels, vScreenWidth * vScreenHeight * 4);
334-
SDL_UnlockTexture(vScreenTex);
335-
SDL_RenderCopyEx(winmain::Renderer, vScreenTex, nullptr, &DestinationRect, 0, nullptr, SDL_FLIP_NONE);
336334
}
337335

338336
void gdrv::ApplyPalette(gdrv_bitmap8& bmp)
339-
{
337+
{
340338
if (bmp.BitmapType == BitmapTypes::None)
341339
return;
342340
assertm(bmp.BitmapType != BitmapTypes::Spliced, "gdrv: wrong bitmap type");

SpaceCadetPinball/gdrv.h

-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class gdrv
6666
static int create_bitmap(gdrv_bitmap8& bmp, const struct dat8BitBmpHeader& header);
6767
static int destroy_bitmap(gdrv_bitmap8* bmp);
6868
static int display_palette(ColorRgba* plt);
69-
static void start_blit_sequence();
70-
static void end_blit_sequence();
7169
static void blit(gdrv_bitmap8* bmp, int xSrc, int ySrc, int xDest, int yDest, int width, int height);
7270
static void blat(gdrv_bitmap8* bmp, int xDest, int yDest);
7371
static void fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar);

SpaceCadetPinball/high_score.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void high_score::show_and_set_high_score_dialog(high_score_struct* table, int sc
135135
dlg_score = score;
136136
dlg_hst = table;
137137
dlg_enter_name = 1;
138-
strncpy(default_name, defaultName, sizeof default_name);
138+
strncpy(default_name, defaultName, sizeof default_name - 1);
139139
ShowDialog = true;
140140
}
141141

SpaceCadetPinball/loader.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ void loader::loadfrom(DatFile* datFile)
105105

106106
void loader::unload()
107107
{
108-
int index;
109-
for (index = 1; index < sound_count; ++index)
108+
for (int index = 1; index < sound_count; ++index)
109+
{
110110
Sound::FreeSound(sound_list[index].WavePtr);
111+
sound_list[index].Loaded = 0;
112+
sound_list[index].WavePtr = nullptr;
113+
}
111114

112-
if (sound_list[index].PtrToSmth)
113-
memory::free(sound_list[index].PtrToSmth);
114115
sound_count = 1;
115116
}
116117

SpaceCadetPinball/loader.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct soundListStruct
1818
int GroupIndex;
1919
int Loaded;
2020
float Duration;
21-
char* PtrToSmth;
2221
};
2322

2423
struct visualKickerStruct

0 commit comments

Comments
 (0)