mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-11-22 08:50:18 +01:00
Compare commits
2 commits
c7f5f8cd30
...
ec13bca129
Author | SHA1 | Date | |
---|---|---|---|
|
ec13bca129 | ||
|
c29acb12d0 |
6 changed files with 103 additions and 72 deletions
|
@ -413,6 +413,19 @@ void gdrv::copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int heigh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gdrv::ScrollBitmapHorizontal(gdrv_bitmap8* bmp, int xStart)
|
||||||
|
{
|
||||||
|
auto srcPtr = bmp->BmpBufPtr1;
|
||||||
|
auto startOffset = xStart >= 0 ? 0 : -xStart;
|
||||||
|
auto endOffset = xStart >= 0 ? xStart : 0;
|
||||||
|
auto length = bmp->Width - std::abs(xStart);
|
||||||
|
for (int y = bmp->Height; y > 0; --y)
|
||||||
|
{
|
||||||
|
std::memmove(srcPtr + endOffset, srcPtr + startOffset, length);
|
||||||
|
srcPtr += bmp->Stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void gdrv::grtext_draw_ttext_in_box(LPCWSTR text, int xOff, int yOff, int width, int height)
|
void gdrv::grtext_draw_ttext_in_box(LPCWSTR text, int xOff, int yOff, int width, int height)
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
int srcXOff, int srcYOff);
|
int srcXOff, int srcYOff);
|
||||||
static void copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff,
|
static void copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff,
|
||||||
gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff);
|
gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff);
|
||||||
|
static void ScrollBitmapHorizontal(gdrv_bitmap8* bmp, int xStart);
|
||||||
static void grtext_draw_ttext_in_box(LPCWSTR text, int xOff, int yOff, int width, int height);
|
static void grtext_draw_ttext_in_box(LPCWSTR text, int xOff, int yOff, int width, int height);
|
||||||
private:
|
private:
|
||||||
/*COLORONCOLOR or HALFTONE*/
|
/*COLORONCOLOR or HALFTONE*/
|
||||||
|
|
|
@ -225,12 +225,15 @@ void pb::ballset(int x, int y)
|
||||||
ball->Speed = maths::normalize_2d(&ball->Acceleration);
|
ball->Speed = maths::normalize_2d(&ball->Acceleration);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pb::frame(int time)
|
void pb::frame(int time)
|
||||||
{
|
{
|
||||||
static int frameTime = 0;
|
static int frameTime = 0;
|
||||||
|
|
||||||
if (time > 100)
|
if (time > 100)
|
||||||
time = 100;
|
time = 100;
|
||||||
|
if (time <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
float timeMul = time * 0.001f;
|
float timeMul = time * 0.001f;
|
||||||
if (!mode_countdown(time))
|
if (!mode_countdown(time))
|
||||||
{
|
{
|
||||||
|
@ -284,7 +287,6 @@ int pb::frame(int time)
|
||||||
MainTable->tilt(time_now);
|
MainTable->tilt(time_now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
|
void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
static void toggle_demo();
|
static void toggle_demo();
|
||||||
static void replay_level(int demoMode);
|
static void replay_level(int demoMode);
|
||||||
static void ballset(int x, int y);
|
static void ballset(int x, int y);
|
||||||
static int frame(int time);
|
static void frame(int time);
|
||||||
static void timed_frame(float timeNow, float timeDelta, bool drawBalls);
|
static void timed_frame(float timeNow, float timeDelta, bool drawBalls);
|
||||||
static void window_size(int* width, int* height);
|
static void window_size(int* width, int* height);
|
||||||
static void pause_continue();
|
static void pause_continue();
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "splash.h"
|
#include "splash.h"
|
||||||
|
#include "render.h"
|
||||||
|
|
||||||
|
const int TargetFrameTime = 8;
|
||||||
|
|
||||||
HINSTANCE winmain::hinst = nullptr;
|
HINSTANCE winmain::hinst = nullptr;
|
||||||
HWND winmain::hwnd_frame = nullptr;
|
HWND winmain::hwnd_frame = nullptr;
|
||||||
|
@ -27,8 +30,6 @@ int winmain::last_mouse_y;
|
||||||
int winmain::mouse_down;
|
int winmain::mouse_down;
|
||||||
int winmain::no_time_loss;
|
int winmain::no_time_loss;
|
||||||
|
|
||||||
DWORD winmain::then;
|
|
||||||
DWORD winmain::now;
|
|
||||||
UINT winmain::iFrostUniqueMsg;
|
UINT winmain::iFrostUniqueMsg;
|
||||||
bool winmain::restart = false;
|
bool winmain::restart = false;
|
||||||
|
|
||||||
|
@ -50,6 +51,10 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
options::ReadOptions();
|
options::ReadOptions();
|
||||||
auto regSpaceCadet = pinball::get_rc_string(166, 0);
|
auto regSpaceCadet = pinball::get_rc_string(166, 0);
|
||||||
|
|
||||||
|
// Needed for sub 16ms sleep
|
||||||
|
if (timeBeginPeriod(1) == TIMERR_NOERROR)
|
||||||
|
atexit(ResetTimer);
|
||||||
|
|
||||||
if (options::get_int(regSpaceCadet, "Table Version", 1) <= 1)
|
if (options::get_int(regSpaceCadet, "Table Version", 1) <= 1)
|
||||||
{
|
{
|
||||||
auto tmpBuf = memory::allocate(0x1F4u);
|
auto tmpBuf = memory::allocate(0x1F4u);
|
||||||
|
@ -220,7 +225,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
pb::replay_level(0);
|
pb::replay_level(0);
|
||||||
|
|
||||||
DWORD someTimeCounter = 300u, prevTime = 0u;
|
DWORD someTimeCounter = 300u, prevTime = 0u;
|
||||||
then = timeGetTime();
|
int sleepRemainder = 0, frameDuration = TargetFrameTime;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (!someTimeCounter)
|
if (!someTimeCounter)
|
||||||
|
@ -243,32 +248,6 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWindowTextA(hwnd_frame, buf);
|
SetWindowTextA(hwnd_frame, buf);
|
||||||
|
|
||||||
if (DispGRhistory)
|
|
||||||
{
|
|
||||||
if (!gfr_display.BmpBufPtr1)
|
|
||||||
{
|
|
||||||
auto plt = static_cast<PALETTEENTRY*>(malloc(1024u));
|
|
||||||
auto pltPtr = &plt[10];
|
|
||||||
for (int i1 = 0, i2 = 0; i1 < 256 - 10; ++i1, i2 += 8)
|
|
||||||
{
|
|
||||||
unsigned char blue = i2, redGreen = i2;
|
|
||||||
if (i2 > 255)
|
|
||||||
{
|
|
||||||
blue = 255;
|
|
||||||
redGreen = i1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pltPtr++ = {redGreen, redGreen, blue};
|
|
||||||
}
|
|
||||||
gdrv::display_palette(plt);
|
|
||||||
free(plt);
|
|
||||||
gdrv::create_bitmap(&gfr_display, 400, 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
gdrv::blit(&gfr_display, 0, 0, 0, 0, 300, 10);
|
|
||||||
gdrv::fill_bitmap(&gfr_display, 300, 10, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
prevTime = curTime;
|
prevTime = curTime;
|
||||||
}
|
}
|
||||||
|
@ -284,50 +263,64 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
|
|
||||||
if (has_focus)
|
if (has_focus)
|
||||||
{
|
{
|
||||||
if (mouse_down)
|
if (mouse_down && frameDuration >= 2)
|
||||||
{
|
{
|
||||||
now = timeGetTime();
|
/*last_mouse_n is in client coordinates*/
|
||||||
if (now - then >= 2)
|
POINT Point;
|
||||||
{
|
GetCursorPos(&Point);
|
||||||
/*last_mouse_n is in client coordinates*/
|
ScreenToClient(hwnd_frame, &Point);
|
||||||
POINT Point;
|
pb::ballset(last_mouse_x - Point.x, Point.y - last_mouse_y);
|
||||||
GetCursorPos(&Point);
|
Point = POINT{ last_mouse_x, last_mouse_y };
|
||||||
ScreenToClient(hwnd_frame, &Point);
|
ClientToScreen(hwnd_frame, &Point);
|
||||||
pb::ballset(last_mouse_x - Point.x, Point.y - last_mouse_y);
|
SetCursorPos(Point.x, Point.y);
|
||||||
Point = POINT{last_mouse_x, last_mouse_y};
|
|
||||||
ClientToScreen(hwnd_frame, &Point);
|
|
||||||
SetCursorPos(Point.x, Point.y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!single_step)
|
if (!single_step)
|
||||||
{
|
{
|
||||||
auto curTime = timeGetTime();
|
auto frameStart = timeGetTime();
|
||||||
now = curTime;
|
auto dt = frameDuration;
|
||||||
if (no_time_loss)
|
if (!no_time_loss)
|
||||||
{
|
pb::frame(dt);
|
||||||
then = curTime;
|
else
|
||||||
no_time_loss = 0;
|
no_time_loss = 0;
|
||||||
|
|
||||||
|
if (DispGRhistory)
|
||||||
|
{
|
||||||
|
auto width = render::vscreen.Width / 2;
|
||||||
|
auto height = 64;
|
||||||
|
if (!gfr_display.BmpBufPtr1)
|
||||||
|
{
|
||||||
|
gdrv::create_bitmap(&gfr_display, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
gdrv::ScrollBitmapHorizontal(&gfr_display, -1);
|
||||||
|
|
||||||
|
float target = TargetFrameTime;
|
||||||
|
auto scale = height / target / 2;
|
||||||
|
gdrv::fill_bitmap(&gfr_display, 1, height, width - 1, 0, 0); // Background
|
||||||
|
|
||||||
|
auto targetVal = dt < target ? dt : target;
|
||||||
|
auto targetHeight = min(static_cast<int>(std::round(targetVal * scale)), height);
|
||||||
|
gdrv::fill_bitmap(&gfr_display, 1, targetHeight, width - 1, height - targetHeight, -1); // Target
|
||||||
|
|
||||||
|
auto diffVal = dt < target ? target - dt : dt - target;
|
||||||
|
auto diffHeight = min(static_cast<int>(std::round(diffVal * scale)), height);
|
||||||
|
gdrv::fill_bitmap(&gfr_display, 1, diffHeight, width - 1, height - targetHeight - diffHeight, 1); // Target diff
|
||||||
|
|
||||||
|
gdrv::blit(&gfr_display, 0, 0, render::vscreen.Width - width, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curTime == then)
|
auto updateEnd = timeGetTime();
|
||||||
{
|
auto sleepDuration = TargetFrameTime - (int)(updateEnd - frameStart) - sleepRemainder;
|
||||||
Sleep(8u);
|
|
||||||
}
|
if (sleepDuration > 0)
|
||||||
else if (pb::frame(curTime - then))
|
Sleep(sleepDuration);
|
||||||
{
|
|
||||||
if (gfr_display.BmpBufPtr1)
|
auto frameEnd = timeGetTime();
|
||||||
{
|
sleepRemainder = (frameEnd - updateEnd) - sleepDuration;
|
||||||
auto deltaT = now - then + 10;
|
frameDuration = min(frameEnd - frameStart, TargetFrameTime * 2);
|
||||||
auto fillChar = static_cast<char>(deltaT);
|
|
||||||
if (deltaT > 236)
|
--someTimeCounter;
|
||||||
{
|
|
||||||
fillChar = -7;
|
|
||||||
}
|
|
||||||
gdrv::fill_bitmap(&gfr_display, 1, 10, 299 - someTimeCounter, 0, fillChar);
|
|
||||||
}
|
|
||||||
--someTimeCounter;
|
|
||||||
then = now;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,13 +530,32 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
|
||||||
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
||||||
switch (wParam)
|
switch (wParam)
|
||||||
{
|
{
|
||||||
case 'H':
|
case 'G':
|
||||||
DispGRhistory = 1;
|
DispGRhistory ^= 1;
|
||||||
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
||||||
case 'Y':
|
case 'Y':
|
||||||
SetWindowTextA(hWnd, "Pinball");
|
SetWindowTextA(hWnd, "Pinball");
|
||||||
DispFrameRate = DispFrameRate == 0;
|
DispFrameRate = DispFrameRate == 0;
|
||||||
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
||||||
|
case 'O':
|
||||||
|
{
|
||||||
|
auto plt = static_cast<PALETTEENTRY*>(malloc(1024u));
|
||||||
|
auto pltPtr = &plt[10];
|
||||||
|
for (int i1 = 0, i2 = 0; i1 < 256 - 10; ++i1, i2 += 8)
|
||||||
|
{
|
||||||
|
unsigned char blue = i2, redGreen = i2;
|
||||||
|
if (i2 > 255)
|
||||||
|
{
|
||||||
|
blue = 255;
|
||||||
|
redGreen = i1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pltPtr++ = { redGreen, redGreen, blue };
|
||||||
|
}
|
||||||
|
gdrv::display_palette(plt);
|
||||||
|
free(plt);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case VK_F1:
|
case VK_F1:
|
||||||
pb::frame(10);
|
pb::frame(10);
|
||||||
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
return DefWindowProcW(hWnd, Msg, wParam, lParam);
|
||||||
|
|
|
@ -26,11 +26,14 @@ public:
|
||||||
private:
|
private:
|
||||||
static int return_value, bQuit, DispFrameRate, DispGRhistory, activated;
|
static int return_value, bQuit, DispFrameRate, DispGRhistory, activated;
|
||||||
static int has_focus, mouse_down, last_mouse_x, last_mouse_y, no_time_loss;
|
static int has_focus, mouse_down, last_mouse_x, last_mouse_y, no_time_loss;
|
||||||
static DWORD then, now;
|
|
||||||
static UINT iFrostUniqueMsg;
|
static UINT iFrostUniqueMsg;
|
||||||
static gdrv_bitmap8 gfr_display;
|
static gdrv_bitmap8 gfr_display;
|
||||||
static HCURSOR mouse_hsave;
|
static HCURSOR mouse_hsave;
|
||||||
static bool restart;
|
static bool restart;
|
||||||
|
|
||||||
static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
|
static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
|
||||||
|
static void ResetTimer()
|
||||||
|
{
|
||||||
|
timeEndPeriod(1u);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue