Skip to content

Commit 2fe2f66

Browse files
committed
gamepad support wip
1 parent e41fb43 commit 2fe2f66

File tree

6 files changed

+650
-22
lines changed

6 files changed

+650
-22
lines changed

cmake/sokol.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if(APPLE)
2727
"-framework Metal"
2828
"-framework MetalKit"
2929
"-framework AudioToolbox"
30+
"-framework GameController"
3031
)
3132

3233
elseif(LINUX)

src/system/sokol/main.c

+19-11
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,7 @@
2626
#include <time.h>
2727
#include <limits.h>
2828

29-
#include <sokol_app.h>
30-
#include <sokol_gfx.h>
31-
#include <sokol_time.h>
32-
#include <sokol_audio.h>
33-
#include <sokol_glue.h>
34-
#include <util/sokol_color.h>
35-
#include <util/sokol_gl.h>
36-
37-
#if !defined(NDEBUG)
38-
#include <sokol_log.h>
39-
#endif
29+
#include "sokol.h"
4030

4131
#include "studio/system.h"
4232
#include "crt.h"
@@ -338,6 +328,22 @@ static void drawImage(Rect r,sg_image image, sg_sampler sampler)
338328
sgl_disable_texture();
339329
}
340330

331+
static void handleGamepad(App *app)
332+
{
333+
sgamepad_record_state();
334+
335+
for(s32 i = 0; i < MIN(sizeof(tic80_gamepads), sgamepad_get_max_supported_gamepads()); i++)
336+
{
337+
sgamepad_gamepad_state state;
338+
sgamepad_get_gamepad_state(i, &state);
339+
340+
if(state.left_stick.direction_x)
341+
{
342+
// !TODO: smth pressed
343+
}
344+
}
345+
}
346+
341347
static void frame(void *userdata)
342348
{
343349
App *app = userdata;
@@ -351,6 +357,7 @@ static void frame(void *userdata)
351357

352358
handleMouse(app);
353359
handleKeyboard(app);
360+
handleGamepad(app);
354361
studio_tick(app->studio, app->input);
355362

356363
app->input.mouse.relative = studio_mem(app->studio)->ram->input.mouse.relative;
@@ -682,6 +689,7 @@ sapp_desc sokol_main(s32 argc, char* argv[])
682689

683690
app->audio.desc.num_channels = TIC80_SAMPLE_CHANNELS;
684691
saudio_setup(&app->audio.desc);
692+
sgamepad_init();
685693

686694
app->studio = studio_create(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./", INT32_MAX, tic_layout_qwerty, app);
687695

src/system/sokol/sokol.c

+1-10
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,5 @@
2222

2323
#define SOKOL_IMPL
2424

25-
#include <sokol_app.h>
26-
#include <sokol_gfx.h>
27-
#include <sokol_time.h>
28-
#include <sokol_audio.h>
29-
#include <sokol_glue.h>
30-
#include <util/sokol_gl.h>
31-
#include <util/sokol_color.h>
25+
#include "sokol.h"
3226

33-
#if !defined(NDEBUG)
34-
#include <sokol_log.h>
35-
#endif

src/system/sokol/sokol.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// MIT License
2+
3+
// Copyright (c) 2017 Vadim Grigoruk @nesbox // [email protected]
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
#pragma once
24+
25+
#include <sokol_app.h>
26+
#include <sokol_gfx.h>
27+
#include <sokol_time.h>
28+
#include <sokol_audio.h>
29+
#include <sokol_glue.h>
30+
#include <util/sokol_color.h>
31+
#include <util/sokol_gl.h>
32+
33+
#if !defined(NDEBUG)
34+
#include <sokol_log.h>
35+
#endif
36+
37+
#include "sokol_gamepad.h"

0 commit comments

Comments
 (0)