prep for input publishing to dooms

This commit is contained in:
oxmox 2023-02-23 07:12:18 +01:00
parent 8b9f391c53
commit 663be5c54b
3 changed files with 36 additions and 1 deletions

View file

@ -609,7 +609,15 @@ int doom_controller_loop(ControllerContext &ctx)
} }
if (ImGui::IsKeyPressed(ImGuiKey_F10, false)) if (ImGui::IsKeyPressed(ImGuiKey_F10, false))
{
ctx.uiVisible = !ctx.uiVisible; ctx.uiVisible = !ctx.uiVisible;
// FIXME: sadly this has issues: after toggling the ui off and
// on again the mouse cursor is invisible. Even using
// SDL_ShowCursor() unconditionally did not fix it. I suspect
// it's caused by some interaction between SLD and ImGui.
//if (SDL_SetRelativeMouseMode(ctx.uiVisible ? SDL_TRUE : SDL_FALSE) < 0)
// log_warn("SDL_SetRelativeMouseMode: %s", SDL_GetError());
}
} }
static ImVec2 panStartPos; static ImVec2 panStartPos;
@ -707,7 +715,7 @@ int main(int argc, char *argv[])
dp_sdl_fatal("SDL_CreateRenderer"); dp_sdl_fatal("SDL_CreateRenderer");
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
auto imgui = ImGui::CreateContext(); /*auto imgui = */ImGui::CreateContext();
ImGui::GetIO().IniFilename = "doompanning_ui.ini"; ImGui::GetIO().IniFilename = "doompanning_ui.ini";
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
ImGui_ImplSDL2_InitForSDLRenderer(window, renderer); ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);

View file

@ -82,9 +82,29 @@ typedef struct __attribute__((packed, aligned(4)))
DP_DoomCommand cmd; DP_DoomCommand cmd;
} MsgMcstCommand; } MsgMcstCommand;
// Doom input event types (from d_event.h).
typedef enum doom_evtype_t
{
DP_ev_keydown,
DP_ev_keyup,
DP_ev_mouse,
DP_ev_joystick
} dp_doom_evtype_t;
// Doom event structure (from d_event.h).
typedef struct
{
dp_doom_evtype_t type;
int data1; // keys / mouse/joystick buttons
int data2; // mouse/joystick x move
int data3; // mouse/joystick y move
} dp_doom_event_t;
typedef struct __attribute__((packed, aligned(4))) typedef struct __attribute__((packed, aligned(4)))
{ {
MessageBase head; MessageBase head;
u8 eventCount;
dp_doom_event_t events[1];
} MsgInputs; } MsgInputs;
void dp_errno_fatal(const char *const msg); void dp_errno_fatal(const char *const msg);

View file

@ -55,6 +55,8 @@ struct DoomContext
nng_socket sub; nng_socket sub;
doomid_t id; doomid_t id;
DP_DoomState state; DP_DoomState state;
u8 eventCount;
dp_doom_event_t events[MAXEVENTS];
DoomStateFunc *f; DoomStateFunc *f;
}; };
@ -206,6 +208,11 @@ void IB_StartTic (void)
event.data1 = xlatekey(sdl_event.key.keysym.sym); event.data1 = xlatekey(sdl_event.key.keysym.sym);
D_PostEvent(&event); D_PostEvent(&event);
*/ */
_Static_assert(sizeof(event_t) == sizeof(dp_doom_event_t),
"Size mismatch between dooms event_t and doompannings dp_doom_event_t. Packing?");
event_t event;
static int button_state;
//SDL_Event sdl_event;
} }
void IB_GetFramebuffer(unsigned char **pixels, size_t *pitch) void IB_GetFramebuffer(unsigned char **pixels, size_t *pitch)