Skip to content

Commit 09d7634

Browse files
committed
Support mouse relative mode via submission queue
This commit adds support for automatic mouse capture control via the new submission queue feature. With this modification, the cursor will be captured once the game screen become visible and be released when the menu is opened.
1 parent d5e4c52 commit 09d7634

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/i_system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void I_Tactile (int on, int off, int total);
8989

9090
void I_Error (char *error, ...);
9191

92+
void I_SetRelativeMode(boolean enabled);
9293

9394
#endif
9495
//-----------------------------------------------------------------------------

src/m_menu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,7 @@ void M_StartControlPanel (void)
17001700
return;
17011701

17021702
menuactive = 1;
1703+
I_SetRelativeMode(false);
17031704
currentMenu = &MainDef; // JDC
17041705
itemOn = currentMenu->lastOn; // JDC
17051706
}
@@ -1784,6 +1785,7 @@ void M_Drawer (void)
17841785
void M_ClearMenus (void)
17851786
{
17861787
menuactive = 0;
1788+
I_SetRelativeMode(true);
17871789
// if (!netgame && usergame && paused)
17881790
// sendpause = true;
17891791
}

src/riscv/i_system.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,31 @@ static submission_queue_t submission_queue = {
108108
static unsigned int event_count = 0;
109109
const int queues_capacity = 128;
110110

111+
void
112+
I_SetRelativeMode(boolean enabled)
113+
{
114+
emu_submission_t submission;
115+
submission.type = RELATIVE_MODE_SUBMISSION;
116+
submission.mouse.enabled = enabled;
117+
submission_queue.base[submission_queue.end++] = submission;
118+
submission_queue.end &= queues_capacity - 1;
119+
register int a0 asm("a0") = 1;
120+
register int a7 asm("a7") = 0xfeed;
121+
asm volatile("scall" : "+r"(a0) : "r"(a7));
122+
}
123+
111124
void
112125
I_Init(void)
113126
{
114127
void *base = malloc(sizeof(emu_event_t) * queues_capacity + sizeof(emu_submission_t) * queues_capacity);
115128
event_queue.base = base;
116-
submission_queue.base = base;
129+
submission_queue.base = base + sizeof(emu_event_t) * queues_capacity;
117130
register int a0 asm("a0") = (uintptr_t) base;
118131
register int a1 asm("a1") = queues_capacity;
119132
register int a2 asm("a2") = (uintptr_t) &event_count;
120133
register int a7 asm("a7") = 0xc0de;
121134
asm volatile("scall" : "+r"(a0) : "r"(a1), "r"(a2), "r"(a7));
135+
I_SetRelativeMode(true);
122136
}
123137

124138

0 commit comments

Comments
 (0)