mirror of
https://github.com/GayPizzaSpecifications/padlab.git
synced 2025-08-03 13:11:32 +00:00
small cleanups cus I felt like it
This commit is contained in:
28
analogue.c
28
analogue.c
@ -25,6 +25,7 @@ bool UseGamepad(int aJoyid)
|
||||
return false;
|
||||
}
|
||||
|
||||
#define FATAL(CONDITION, RETURN) if (CONDITION) { res = (RETURN); goto error; }
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int res;
|
||||
@ -38,19 +39,10 @@ int main(int argc, char** argv)
|
||||
int winw = WINDOW_WIDTH;
|
||||
int winh = WINDOW_HEIGHT;
|
||||
window = SDL_CreateWindow(CAPTION, winpos, winpos, winw, winh, winflg);
|
||||
if (window == NULL)
|
||||
{
|
||||
res = -1;
|
||||
goto error;
|
||||
}
|
||||
FATAL(window == NULL, -1)
|
||||
|
||||
if (InitDraw(window))
|
||||
{
|
||||
res = -1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
rect rendRect = GetDrawSizeInPixels();
|
||||
FATAL(InitDraw(window), -1)
|
||||
size rendSize = GetDrawSizeInPixels();
|
||||
|
||||
if ((res = SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt")) != -1)
|
||||
printf("read %d mappings from gamecontrollerdb.txt\n", res);
|
||||
@ -127,7 +119,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
winw = event.window.data1;
|
||||
winh = event.window.data2;
|
||||
rendRect = GetDrawSizeInPixels();
|
||||
rendSize = GetDrawSizeInPixels();
|
||||
repaint = true;
|
||||
}
|
||||
else if (event.window.event == SDL_WINDOWEVENT_EXPOSED)
|
||||
@ -228,16 +220,16 @@ int main(int argc, char** argv)
|
||||
SetDrawColour(0x1F1F1FFF);
|
||||
DrawClear();
|
||||
|
||||
const int hrw = rendRect.w / 2;
|
||||
DrawDigital(&(rect){0, 0, hrw, rendRect.h}, &stickl);
|
||||
DrawAnalogue(&(rect){hrw, 0, hrw, rendRect.h}, &stickr);
|
||||
const int hrw = rendSize.w / 2;
|
||||
DrawDigital(&(rect){ 0, 0, hrw, rendSize.h}, &stickl);
|
||||
DrawAnalogue(&(rect){ hrw, 0, hrw, rendSize.h}, &stickr);
|
||||
|
||||
// test player thingo
|
||||
if (showavatar)
|
||||
{
|
||||
plrpos = VecAdd(plrpos, VecScale(stickl.compos, framedelta * 0.5));
|
||||
plrpos.x = pfmod(plrpos.x, rendRect.w);
|
||||
plrpos.y = pfmod(plrpos.y, rendRect.h);
|
||||
plrpos.x = pfmod(plrpos.x, rendSize.w);
|
||||
plrpos.y = pfmod(plrpos.y, rendSize.h);
|
||||
|
||||
SetDrawColour(0xFF0000FF);
|
||||
const int plrSz = 32;
|
||||
|
4
draw.c
4
draw.c
@ -18,9 +18,9 @@ void QuitDraw(void)
|
||||
}
|
||||
|
||||
|
||||
rect GetDrawSizeInPixels(void)
|
||||
size GetDrawSizeInPixels(void)
|
||||
{
|
||||
rect out = {0, 0, 0, 0};
|
||||
size out = {0, 0};
|
||||
SDL_GetRendererOutputSize(rend, &out.w, &out.h);
|
||||
return out;
|
||||
}
|
||||
|
4
draw.h
4
draw.h
@ -26,9 +26,9 @@ void QuitDraw(void);
|
||||
// Get the actual size of the canvas in pixels.
|
||||
//
|
||||
// Returns:
|
||||
// rectangle struct with 'w' and 'h' set to the width &
|
||||
// size struct with 'w' and 'h' set to the width &
|
||||
// height of the canvas in actual pixels.
|
||||
rect GetDrawSizeInPixels(void);
|
||||
size GetDrawSizeInPixels(void);
|
||||
|
||||
// Set the current draw colour.
|
||||
//
|
||||
|
10
maths.h
10
maths.h
@ -6,14 +6,14 @@
|
||||
#define PI 3.141592653589793238462643383279502884L
|
||||
#define TAU 6.283185307179586476925286766559005768L
|
||||
|
||||
#define MAX(LHS, RHS) ((LHS > RHS) ? (LHS) : (RHS))
|
||||
#define MIN(LHS, RHS) ((LHS < RHS) ? (LHS) : (RHS))
|
||||
#define CLAMP(X, A, B) (MIN(B, MAX(A, X)))
|
||||
#define SATURATE(X) (CLAMP(X, 0, 1))
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define CLAMP(X, A, B) (MIN((B), MAX((A), (X))))
|
||||
#define SATURATE(X) (CLAMP((X), 0, 1))
|
||||
|
||||
typedef double vec_t;
|
||||
typedef struct { vec_t x, y; } vector;
|
||||
|
||||
typedef struct { int w, h; } size;
|
||||
typedef struct { int x, y, w, h; } rect;
|
||||
|
||||
static inline vector VecAdd(vector l, vector r)
|
||||
|
Reference in New Issue
Block a user