Removed the 80 character column rule. Becoming impractical.

This commit is contained in:
igor
2026-04-17 03:19:13 -07:00
parent a8a3b57f8a
commit 9bc7fa3b52
4 changed files with 163 additions and 464 deletions
+88 -279
View File
@@ -55,8 +55,7 @@ static U32 SafeTruncateUInt64(U64 Value)
return Result;
}
debug_read_file_result DEBUGPlatformReadEntireFile(thread_context *Thread,
const char *Filename)
debug_read_file_result DEBUGPlatformReadEntireFile(thread_context *Thread, const char *Filename)
{
debug_read_file_result Result;
memset(&Result, 0, sizeof(Result));
@@ -100,12 +99,9 @@ debug_read_file_result DEBUGPlatformReadEntireFile(thread_context *Thread,
return Result;
}
B32 DEBUGPlatformWriteEntireFile(thread_context *Thread,
const char *Filename, U32 MemorySize,
void *Memory)
B32 DEBUGPlatformWriteEntireFile(thread_context *Thread, const char *Filename, U32 MemorySize, void *Memory)
{
S32 FileHandle = open(Filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR |
S_IRGRP | S_IROTH);
S32 FileHandle = open(Filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if(FileHandle == -1)
return FALSE;
@@ -141,8 +137,7 @@ static sdl_window_dimension SDLGetWindowDimension(SDL_Window *Window)
return Dimension;
}
static void SDLResizeTexture(offscreen_buffer *Buffer,
SDL_Renderer *Renderer, int Width, int Height)
static void SDLResizeTexture(offscreen_buffer *Buffer, SDL_Renderer *Renderer, int Width, int Height)
{
if(Buffer->Texture)
SDL_DestroyTexture(Buffer->Texture);
@@ -152,9 +147,7 @@ static void SDLResizeTexture(offscreen_buffer *Buffer,
S32 BytesPerPixel = 4;
Buffer->Texture = SDL_CreateTexture(Renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
Width, Height);
Buffer->Texture = SDL_CreateTexture(Renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Width, Height);
Buffer->Memory = malloc(Width * Height * BytesPerPixel);
Buffer->Height = Height;
@@ -162,9 +155,7 @@ static void SDLResizeTexture(offscreen_buffer *Buffer,
Buffer->Pitch = Width * BytesPerPixel;
}
static void SDLDisplayBufferInWindow(offscreen_buffer Buffer,
SDL_Window *Window,
SDL_Renderer *Renderer)
static void SDLDisplayBufferInWindow(offscreen_buffer Buffer, SDL_Window *Window, SDL_Renderer *Renderer)
{
S32 OffsetX = 10;
S32 OffsetY = 10;
@@ -179,8 +170,7 @@ static void SDLDisplayBufferInWindow(offscreen_buffer Buffer,
/* TODO: We temporarily introduce the target rectangle to avoid
* stretching the canvas. */
/* SDL_RenderCopy(Renderer, Buffer.Texture, 0, 0); */
SDL_Rect dest_rect = { OffsetX, OffsetY,
RESOLUTION_WIDTH, RESOLUTION_HEIGHT };
SDL_Rect dest_rect = { OffsetX, OffsetY, RESOLUTION_WIDTH, RESOLUTION_HEIGHT };
SDL_RenderCopy(Renderer, Buffer.Texture, 0, (const SDL_Rect *)(&dest_rect));
SDL_RenderPresent(Renderer);
}
@@ -194,8 +184,7 @@ static void SDLInitControllers()
continue;
if(ControllerIndex >= MAX_CONTROLLERS)
break;
ControllerHandles[ControllerIndex] =
SDL_GameControllerOpen(JoystickIndex);
ControllerHandles[ControllerIndex] = SDL_GameControllerOpen(JoystickIndex);
ControllerIndex++;
}
}
@@ -203,10 +192,7 @@ static void SDLInitControllers()
/*
static void SDLDeinitControllers()
{
for(S32 ControllerIndex = 0;
ControllerIndex < MAX_CONTROLLERS;
ControllerIndex++)
{
for(S32 ControllerIndex = 0; ControllerIndex < MAX_CONTROLLERS; ControllerIndex++) {
if(ControllerHandles[ControllerIndex])
SDL_GameControllerClose(ControllerHandles[ControllerIndex]);
}
@@ -230,8 +216,7 @@ static void SDLInitSound(S32 SamplesPerSecond, S32 BufferSize)
}
}
static void SDLFillSoundBuffer(sdl_sound_output *SoundOutput,
S32 BytesToWrite)
static void SDLFillSoundBuffer(sdl_sound_output *SoundOutput, S32 BytesToWrite)
{
SDL_QueueAudio(1, SoundOutput->Samples, BytesToWrite);
}
@@ -241,8 +226,7 @@ static void SDLClearSoundBuffer(sdl_sound_output *SoundOutput)
memset(SoundOutput->Samples, 0, SoundOutput->SecondaryBufferSize);
}
static void SDLProcessKeyboardMessage(game_button_state *NewState,
B32 IsDown)
static void SDLProcessKeyboardMessage(game_button_state *NewState, B32 IsDown)
{
if(NewState->EndedDown != IsDown) {
NewState->EndedDown = IsDown;
@@ -250,14 +234,10 @@ static void SDLProcessKeyboardMessage(game_button_state *NewState,
}
}
static void SDLProcessInputDigitalButton(SDL_GameController *Controller,
game_button_state *OldState,
SDL_GameControllerButton Button,
game_button_state *NewState)
static void SDLProcessInputDigitalButton(SDL_GameController *Controller, game_button_state *OldState, SDL_GameControllerButton Button, game_button_state *NewState)
{
NewState->EndedDown = SDL_GameControllerGetButton(Controller, Button);
NewState->HalfTransitionCount =
(OldState->EndedDown != NewState->EndedDown) ? 1 : 0;
NewState->HalfTransitionCount = (OldState->EndedDown != NewState->EndedDown) ? 1 : 0;
}
static void HandleEvent(SDL_Event *Event)
@@ -274,14 +254,12 @@ static void HandleEvent(SDL_Event *Event)
switch(Event->window.event) {
/* TODO: We temporarily disable for ease of writing the
* rendering code. */
#if 0
case SDL_WINDOWEVENT_SIZE_CHANGED: {
sdl_window_dimension Dimension;
Dimension = SDLGetWindowDimension(Window);
/* TODO: For now we fix the width and height. */
SDLResizeTexture(&GlobalBackbuffer, Renderer,
Dimension.Width, Dimension.Height);
#if 0
/* TODO: For now we fix the width and height. */
case SDL_WINDOWEVENT_SIZE_CHANGED: {
sdl_window_dimension Dimension = SDLGetWindowDimension(Window);
SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height);
} break;
#endif
@@ -328,53 +306,29 @@ static void SDLProcessMessages(sdl_state *SDLState,
if(Event.key.repeat == 0) {
if(KeyCode == SDLK_w) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.MoveUp,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->MoveUp, IsDown);
} else if(KeyCode == SDLK_s) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.MoveDown,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->MoveDown, IsDown);
} else if(KeyCode == SDLK_a) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.MoveLeft,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->MoveLeft, IsDown);
} else if(KeyCode == SDLK_d) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.MoveRight,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->MoveRight, IsDown);
} else if(KeyCode == SDLK_q) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.LeftShoulder,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->LeftShoulder, IsDown);
} else if(KeyCode == SDLK_e) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.RightShoulder,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->RightShoulder, IsDown);
} else if(KeyCode == SDLK_UP) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.ActionUp,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->ActionUp, IsDown);
} else if(KeyCode == SDLK_DOWN) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.ActionDown,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->ActionDown, IsDown);
} else if(KeyCode == SDLK_LEFT) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.ActionLeft,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->ActionLeft, IsDown);
} else if(KeyCode == SDLK_RIGHT) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.ActionRight,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->ActionRight, IsDown);
} else if(KeyCode == SDLK_ESCAPE) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.Start,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->Start, IsDown);
} else if(KeyCode == SDLK_SPACE) {
SDLProcessKeyboardMessage(
&KeyboardController->u.buttons.Back,
IsDown);
SDLProcessKeyboardMessage(&KeyboardController->Back, IsDown);
}
}
@@ -404,11 +358,9 @@ static F32 SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold)
{
F32 Result = 0.0f;
if(Value < -(F32)DeadZoneThreshold)
Result = ((Value + (F32)DeadZoneThreshold) /
(32768.0f - (F32)DeadZoneThreshold));
Result = ((Value + (F32)DeadZoneThreshold) / (32768.0f - (F32)DeadZoneThreshold));
else if(Value > (F32)DeadZoneThreshold)
Result = ((Value + (F32)DeadZoneThreshold) /
(32767.0f - (F32)DeadZoneThreshold));
Result = ((Value + (F32)DeadZoneThreshold) / (32767.0f - (F32)DeadZoneThreshold));
return Result;
}
@@ -441,9 +393,7 @@ typedef struct sdl_game_code {
void *GameCodeDLL;
U32 DLLLastWriteTime;
void (*UpdateAndRender)(thread_context *Thread, game_memory *,
game_input *, game_offscreen_buffer *,
game_sound_output_buffer *);
void (*UpdateAndRender)(thread_context *Thread, game_memory *, game_input *, game_offscreen_buffer *, game_sound_output_buffer *);
B32 IsValid;
} sdl_game_code;
@@ -470,10 +420,7 @@ static sdl_game_code SDLLoadGameCode(char *DLLPath)
if(Result.GameCodeDLL) {
Result.DLLLastWriteTime = GetLastWriteTime(DLLPath);
Result.UpdateAndRender =
(void(*)(thread_context *, game_memory *, game_input *,
game_offscreen_buffer *, game_sound_output_buffer *))
dlsym(Result.GameCodeDLL, "UpdateAndRender");
Result.UpdateAndRender = (void(*)(thread_context *, game_memory *, game_input *, game_offscreen_buffer *, game_sound_output_buffer *)) dlsym(Result.GameCodeDLL, "UpdateAndRender");
if(!Result.UpdateAndRender) {
/* TODO: Diagnostic. dlerror() */
}
@@ -590,12 +537,9 @@ S32 main(S32 argc, char *argv[])
memset(&SDLState, 0, sizeof(SDLState));
SDLGetEXEDirPath(SDLState.EXEDirPath, sizeof(SDLState.EXEDirPath));
SDLGetDLLPath(SDLState.DLLPath, sizeof(SDLState.DLLPath),
SDLState.EXEDirPath);
SDLGetDLLPath(SDLState.DLLPath, sizeof(SDLState.DLLPath), SDLState.EXEDirPath);
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER |
SDL_INIT_AUDIO))
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO)) {
/* TODO: This didn't work . . . */
}
@@ -604,11 +548,7 @@ S32 main(S32 argc, char *argv[])
/* NOTE: Floating windows are not supported oficially by Wayland
* protocol. However, SDL_WINDOW_ALWAYS_ON_TOP does work on KDE
* under Wayland. I have not tested GNOME. */
SDL_Window *Window = SDL_CreateWindow("Handmade Hero",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
RESOLUTION_WIDTH, RESOLUTION_HEIGHT,
SDL_WINDOW_RESIZABLE);
SDL_Window *Window = SDL_CreateWindow("Handmade Hero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESOLUTION_WIDTH, RESOLUTION_HEIGHT, SDL_WINDOW_RESIZABLE);
/*SDL_WINDOW_RESIZABLE |
SDL_WINDOW_ALWAYS_ON_TOP);*/
@@ -616,10 +556,8 @@ S32 main(S32 argc, char *argv[])
SDL_DisplayMode display_mode;
SDL_GetCurrentDisplayMode(0, &display_mode);
SDL_Renderer *Renderer =
SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH),
(display_mode.h - RESOLUTION_HEIGHT));
SDL_Renderer *Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH), (display_mode.h - RESOLUTION_HEIGHT));
/* "Wayland needs an event loop and rendering or it won't function."
* https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */
@@ -644,27 +582,20 @@ S32 main(S32 argc, char *argv[])
GlobalRunning = TRUE;
sdl_window_dimension Dimension = SDLGetWindowDimension(Window);
SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width,
Dimension.Height);
SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height);
sdl_sound_output SoundOutput;
memset(&SoundOutput, 0, sizeof(SoundOutput));
SoundOutput.SamplesPerSecond = 48000;
SoundOutput.BytesPerSample = sizeof(S16) * 2;
SoundOutput.SecondaryBufferSize =
SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample;
SoundOutput.SecondaryBufferSize = SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample;
SoundOutput.tSine = 0;
SoundOutput.LatencySampleCount =
SoundOutput.SamplesPerSecond / 15;
SoundOutput.LatencySampleCount = SoundOutput.SamplesPerSecond / 15;
SDLInitSound(SoundOutput.SamplesPerSecond,
SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample /
60);
SDLInitSound(SoundOutput.SamplesPerSecond, SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample / 60);
SDL_PauseAudio(0);
SoundOutput.Samples =
calloc(SoundOutput.SamplesPerSecond,
SoundOutput.BytesPerSample);
SoundOutput.Samples = calloc(SoundOutput.SamplesPerSecond, SoundOutput.BytesPerSample);
/* SoundOutput.Samples =
* malloc(SoundOutput.SecondaryBufferSize); */
/* NOTE: calloc auto clears to zero */
@@ -674,30 +605,18 @@ S32 main(S32 argc, char *argv[])
memset(&GameMemory, 0, sizeof(GameMemory));
GameMemory.PermanentStorageSize = MB(64);
GameMemory.TransientStorageSize = GB(1);
GameMemory.DEBUGPlatformReadEntireFile =
&DEBUGPlatformReadEntireFile;
GameMemory.DEBUGPlatformWriteEntireFile =
&DEBUGPlatformWriteEntireFile;
GameMemory.DEBUGPlatformFreeFileMemory =
&DEBUGPlatformFreeFileMemory;
GameMemory.DEBUGPlatformReadEntireFile = &DEBUGPlatformReadEntireFile;
GameMemory.DEBUGPlatformWriteEntireFile = &DEBUGPlatformWriteEntireFile;
GameMemory.DEBUGPlatformFreeFileMemory = &DEBUGPlatformFreeFileMemory;
SDLState.TotalSize =
GameMemory.PermanentStorageSize +
GameMemory.TransientStorageSize;
SDLState.TotalSize = GameMemory.PermanentStorageSize + GameMemory.TransientStorageSize;
/* NOTE: On MacOS and Linux, mmap seems to zero-fill anonymous
* memory as a side-effect of security. */
SDLState.GameMmemoryBlock =
mmap(BaseAddress, (size_t)SDLState.TotalSize, PROT_READ |
PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
SDLState.GameMmemoryBlock = mmap(BaseAddress, (size_t)SDLState.TotalSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
GameMemory.PermanentStorage = SDLState.GameMmemoryBlock;
GameMemory.TransientStorage =
(U8 *)(GameMemory.PermanentStorage) +
GameMemory.PermanentStorageSize;
GameMemory.TransientStorage = (U8 *)(GameMemory.PermanentStorage) + GameMemory.PermanentStorageSize;
if(SoundOutput.Samples &&
GameMemory.PermanentStorage &&
GameMemory.TransientStorage)
{
if(SoundOutput.Samples && GameMemory.PermanentStorage && GameMemory.TransientStorage) {
game_input Input[2];
U64 LastCounter;
@@ -734,193 +653,83 @@ S32 main(S32 argc, char *argv[])
Game = SDLLoadGameCode(SDLState.DLLPath);
}
U32 SDLMouseButtons =
SDL_GetMouseState(&(NewInput->MouseX),
&(NewInput->MouseY));
U32 SDLMouseButtons = SDL_GetMouseState(&(NewInput->MouseX), &(NewInput->MouseY));
NewInput->MouseZ = 0; /* TODO: Support mouse wheel? */
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[0]),
SDL_BUTTON_LMASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[1]),
SDL_BUTTON_MMASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[2]),
SDL_BUTTON_RMASK & SDLMouseButtons);
/* WARNING: TODO: SDL_BUTTON_X1MASK and
* SDL_BUTTON_X2MASK cannot be on at the
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[0]), SDL_BUTTON_LMASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[1]), SDL_BUTTON_MMASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[2]), SDL_BUTTON_RMASK & SDLMouseButtons);
/* WARNING: TODO: SDL_BUTTON_X1MASK and SDL_BUTTON_X2MASK cannot be on at the
* same time for some reason. */
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[3]),
SDL_BUTTON_X1MASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[4]),
SDL_BUTTON_X2MASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[3]), SDL_BUTTON_X1MASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[4]), SDL_BUTTON_X2MASK & SDLMouseButtons);
game_controller_input *OldKeyboardController =
GetController(OldInput, 0);
game_controller_input *NewKeyboardController =
GetController(NewInput, 0);
game_controller_input *OldKeyboardController = GetController(OldInput, 0);
game_controller_input *NewKeyboardController = GetController(NewInput, 0);
game_controller_input ZeroController;
memset(&ZeroController, 0, sizeof(ZeroController));
*NewKeyboardController = ZeroController;
NewKeyboardController->IsConnected = TRUE;
for(U32 ButtonIndex = 0;
ButtonIndex < ARRAY_SIZE(
NewKeyboardController->u.Buttons);
ButtonIndex++)
{
NewKeyboardController->
u.Buttons[ButtonIndex].EndedDown =
OldKeyboardController->
u.Buttons[ButtonIndex].
EndedDown;
for(U32 ButtonIndex = 0; ButtonIndex < ARRAY_SIZE(NewKeyboardController->Buttons); ButtonIndex++) {
NewKeyboardController->Buttons[ButtonIndex].EndedDown = OldKeyboardController->Buttons[ButtonIndex].EndedDown;
}
SDLProcessMessages(&SDLState, NewKeyboardController);
for(U32 ControllerIndex = 0;
ControllerIndex < MAX_CONTROLLERS;
ControllerIndex++)
{
game_controller_input *OldController,
*NewController;
for(U32 ControllerIndex = 0; ControllerIndex < MAX_CONTROLLERS; ControllerIndex++) {
game_controller_input *OldController = GetController(OldInput, ControllerIndex+1);
game_controller_input *NewController = GetController(NewInput, ControllerIndex+1);
OldController =
GetController(OldInput, ControllerIndex+1);
NewController =
GetController(NewInput, ControllerIndex+1);
if(ControllerHandles[ControllerIndex] != 0 &&
SDL_GameControllerGetAttached(
ControllerHandles[ControllerIndex]))
{
NewController->IsAnalog =
OldController->IsAnalog;
if(ControllerHandles[ControllerIndex] != 0 && SDL_GameControllerGetAttached(ControllerHandles[ControllerIndex])) {
NewController->IsAnalog = OldController->IsAnalog;
NewController->IsConnected = TRUE;
S16 StickX =
SDL_GameControllerGetAxis(
ControllerHandles[ControllerIndex],
SDL_CONTROLLER_AXIS_LEFTX);
S16 StickY =
SDL_GameControllerGetAxis(
ControllerHandles[ControllerIndex],
SDL_CONTROLLER_AXIS_LEFTY);
S16 StickX = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTX);
S16 StickY = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTY);
NewController->IsAnalog = TRUE;
NewController->StickAverageX =
SDLProcessInputStickValue((F32)StickX,
CONTROLLER_LEFT_THUMB_DEADZONE);
NewController->StickAverageY =
SDLProcessInputStickValue((F32)StickY,
CONTROLLER_LEFT_THUMB_DEADZONE);
NewController->StickAverageX = SDLProcessInputStickValue((F32)StickX, CONTROLLER_LEFT_THUMB_DEADZONE);
NewController->StickAverageY = SDLProcessInputStickValue((F32)StickY, CONTROLLER_LEFT_THUMB_DEADZONE);
if((NewController->StickAverageX != 0.0f) ||
(NewController->StickAverageY != 0.0f))
{
if((NewController->StickAverageX != 0.0f) || (NewController->StickAverageY != 0.0f)) {
NewController->IsAnalog = TRUE;
}
if(SDL_GameControllerGetButton(
ControllerHandles[ControllerIndex],
SDL_CONTROLLER_BUTTON_DPAD_UP))
{
if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_UP)) {
NewController->StickAverageY = -1.0f;
NewController->IsAnalog = FALSE;
}
if(SDL_GameControllerGetButton(
ControllerHandles[ControllerIndex],
SDL_CONTROLLER_BUTTON_DPAD_DOWN))
{
if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_DOWN)) {
NewController->StickAverageY = 1.0f;
NewController->IsAnalog = FALSE;
}
if(SDL_GameControllerGetButton(
ControllerHandles[ControllerIndex],
SDL_CONTROLLER_BUTTON_DPAD_LEFT))
{
if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_LEFT)) {
NewController->StickAverageX = -1.0f;
NewController->IsAnalog = FALSE;
}
if(SDL_GameControllerGetButton(
ControllerHandles[ControllerIndex],
SDL_CONTROLLER_BUTTON_DPAD_RIGHT))
{
if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_RIGHT)) {
NewController->StickAverageX = 1.0f;
NewController->IsAnalog = FALSE;
}
F32 Threshold = 0.5f;
SDLProcessInputDigitalButton(
ControllerHandles[
(NewController->StickAverageY <
-Threshold) ? 1 : 0],
&OldController->u.buttons.MoveUp,
SDL_CONTROLLER_BUTTON_A,
&NewController->u.buttons.MoveUp);
SDLProcessInputDigitalButton(
ControllerHandles[
(NewController->StickAverageY >
Threshold) ? 1 : 0],
&OldController->u.buttons.MoveDown,
SDL_CONTROLLER_BUTTON_A,
&NewController->u.buttons.MoveDown);
SDLProcessInputDigitalButton(
ControllerHandles[
(NewController->StickAverageX <
-Threshold) ? 1 : 0],
&OldController->u.buttons.MoveLeft,
SDL_CONTROLLER_BUTTON_A,
&NewController->u.buttons.MoveLeft);
SDLProcessInputDigitalButton(
ControllerHandles[
(NewController->StickAverageX >
Threshold) ? 1 : 0],
&OldController->u.buttons.MoveRight,
SDL_CONTROLLER_BUTTON_A,
&NewController->u.buttons.MoveRight);
SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageY < -Threshold) ? 1 : 0], &OldController->MoveUp, SDL_CONTROLLER_BUTTON_A, &NewController->MoveUp);
SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageY > Threshold) ? 1 : 0], &OldController->MoveDown, SDL_CONTROLLER_BUTTON_A, &NewController->MoveDown);
SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageX < -Threshold) ? 1 : 0], &OldController->MoveLeft, SDL_CONTROLLER_BUTTON_A, &NewController->MoveLeft);
SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageX > Threshold) ? 1 : 0], &OldController->MoveRight, SDL_CONTROLLER_BUTTON_A, &NewController->MoveRight);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.ActionDown,
SDL_CONTROLLER_BUTTON_A,
&NewController->u.buttons.ActionDown);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.ActionRight,
SDL_CONTROLLER_BUTTON_B,
&NewController->u.buttons.ActionRight);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.ActionLeft,
SDL_CONTROLLER_BUTTON_X,
&NewController->u.buttons.ActionLeft);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.ActionUp,
SDL_CONTROLLER_BUTTON_Y,
&NewController->u.buttons.ActionUp);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.LeftShoulder,
SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
&NewController->u.buttons.LeftShoulder);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.RightShoulder,
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
&NewController->u.buttons.RightShoulder);
SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionDown, SDL_CONTROLLER_BUTTON_A, &NewController->ActionDown);
SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionRight, SDL_CONTROLLER_BUTTON_B, &NewController->ActionRight);
SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionLeft, SDL_CONTROLLER_BUTTON_X, &NewController->ActionLeft);
SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionUp, SDL_CONTROLLER_BUTTON_Y, &NewController->ActionUp);
SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->LeftShoulder, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, &NewController->LeftShoulder);
SDLProcessInputDigitalButton( ControllerHandles[ControllerIndex], &OldController->RightShoulder, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, &NewController->RightShoulder);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.Start,
SDL_CONTROLLER_BUTTON_START,
&NewController->u.buttons.Start);
SDLProcessInputDigitalButton(
ControllerHandles[ControllerIndex],
&OldController->u.buttons.Back,
SDL_CONTROLLER_BUTTON_BACK,
&NewController->u.buttons.Back);
SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->Start, SDL_CONTROLLER_BUTTON_START, &NewController->Start);
SDLProcessInputDigitalButton( ControllerHandles[ControllerIndex], &OldController->Back, SDL_CONTROLLER_BUTTON_BACK, &NewController->Back);
} else {
/* NOTE: This controller is not plugged in. */
NewController->IsConnected = FALSE;