diff --git a/libs/console/menu.c b/libs/console/menu.c index b8e9ccaf7..171de8084 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -683,12 +683,14 @@ Menu_Draw (view_t *view) int ret; run_menu_pre (); + PR_PushFrame (&menu_pr_state); PR_RESET_PARAMS (&menu_pr_state); P_INT (&menu_pr_state, 0) = x; P_INT (&menu_pr_state, 1) = y; menu_pr_state.pr_argc = 2; PR_ExecuteProgram (&menu_pr_state, menu->draw); ret = R_INT (&menu_pr_state); + PR_PopFrame (&menu_pr_state); run_menu_post (); if (!ret) return; @@ -718,11 +720,13 @@ Menu_Draw (view_t *view) item = menu->items[menu->cur_item]; if (menu->cursor) { run_menu_pre (); + PR_PushFrame (&menu_pr_state); PR_RESET_PARAMS (&menu_pr_state); P_INT (&menu_pr_state, 0) = x + item->x; P_INT (&menu_pr_state, 1) = y + item->y; menu_pr_state.pr_argc = 2; PR_ExecuteProgram (&menu_pr_state, menu->cursor); + PR_PopFrame (&menu_pr_state); run_menu_post (); } else { r_funcs->Draw_Character (x + item->x, y + item->y, @@ -751,6 +755,7 @@ menu_key_event (const IE_event_t *ie_event) return 0; if (menu->keyevent) { run_menu_pre (); + PR_PushFrame (&menu_pr_state); PR_RESET_PARAMS (&menu_pr_state); P_INT (&menu_pr_state, 0) = key.code; P_INT (&menu_pr_state, 1) = key.unicode; @@ -758,6 +763,7 @@ menu_key_event (const IE_event_t *ie_event) menu_pr_state.pr_argc = 3; PR_ExecuteProgram (&menu_pr_state, menu->keyevent); ret = R_INT (&menu_pr_state); + PR_PopFrame (&menu_pr_state); run_menu_post (); if (ret) return 1; @@ -772,8 +778,8 @@ menu_key_event (const IE_event_t *ie_event) P_INT (&menu_pr_state, 1) = key.code; menu_pr_state.pr_argc = 2; PR_ExecuteProgram (&menu_pr_state, item->func); - PR_PopFrame (&menu_pr_state); ret = R_INT (&menu_pr_state); + PR_PopFrame (&menu_pr_state); run_menu_post (); if (ret) return 1; diff --git a/libs/ruamoko/rua_input.c b/libs/ruamoko/rua_input.c index e54dc73e2..406ce18bc 100644 --- a/libs/ruamoko/rua_input.c +++ b/libs/ruamoko/rua_input.c @@ -283,6 +283,7 @@ rua_listener_func (rua_in_cookie_t *cookie, const void *input) { progs_t *pr = cookie->pr; PR_PushFrame (pr); + PR_RESET_PARAMS (pr); P_POINTER (pr, 0) = cookie->data; P_POINTER (pr, 1) = PR_SetPointer (pr, input);//FIXME check input pr->pr_argc = 2; diff --git a/libs/ruamoko/rua_stdlib.c b/libs/ruamoko/rua_stdlib.c index fa8489d1c..50fd1cc04 100644 --- a/libs/ruamoko/rua_stdlib.c +++ b/libs/ruamoko/rua_stdlib.c @@ -72,12 +72,15 @@ rua_compare (const void *a, const void *b, void *_f) { function_t *f = _f; + PR_PushFrame (f->pr); PR_RESET_PARAMS (f->pr); P_POINTER (f->pr, 0) = PR_SetPointer (f->pr, a); P_POINTER (f->pr, 1) = PR_SetPointer (f->pr, b); f->pr->pr_argc = 2; PR_ExecuteProgram (f->pr, f->func); - return R_INT (f->pr); + int cmp = R_INT (f->pr); + PR_PopFrame (f->pr); + return cmp; } static void diff --git a/nq/include/sv_progs.h b/nq/include/sv_progs.h index 4a74bfb38..79622a1fb 100644 --- a/nq/include/sv_progs.h +++ b/nq/include/sv_progs.h @@ -213,19 +213,29 @@ typedef struct sv_data_s { #define EDICT_FROM_AREA(l) (STRUCT_FROM_LINK(l,sv_data_t,area)->edict) static inline void -sv_pr_touch (edict_t *self, edict_t *other) +sv_pr_exec (edict_t *self, edict_t *other, pr_func_t func) { pr_int_t this; *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); if ((this = sv_pr_state.fields.this) != -1) { + PR_PushFrame (&sv_pr_state); PR_RESET_PARAMS (&sv_pr_state); P_INT (&sv_pr_state, 0) = E_POINTER (self, this); P_INT (&sv_pr_state, 1) = 0; P_INT (&sv_pr_state, 2) = E_POINTER (other, this); } - PR_ExecuteProgram (&sv_pr_state, SVfunc (self, touch)); + PR_ExecuteProgram (&sv_pr_state, func); + if ((this = sv_pr_state.fields.this) != -1) { + PR_PopFrame (&sv_pr_state); + } +} + +static inline void +sv_pr_touch (edict_t *self, edict_t *other) +{ + sv_pr_exec (self, other, SVfunc (self, touch)); } static inline void @@ -236,33 +246,13 @@ sv_pr_use (edict_t *self, edict_t *other) static inline void sv_pr_think (edict_t *self) { - pr_int_t this; - - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); - *sv_globals.other = 0; - if ((this = sv_pr_state.fields.this) != -1) { - PR_RESET_PARAMS (&sv_pr_state); - P_INT (&sv_pr_state, 0) = E_POINTER (self, this); - P_INT (&sv_pr_state, 1) = 0; - P_INT (&sv_pr_state, 2) = 0; - } - PR_ExecuteProgram (&sv_pr_state, SVfunc (self, think)); + sv_pr_exec (self, 0, SVfunc (self, think)); } static inline void sv_pr_blocked (edict_t *self, edict_t *other) { - pr_int_t this; - - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); - if ((this = sv_pr_state.fields.this) != -1) { - PR_RESET_PARAMS (&sv_pr_state); - P_INT (&sv_pr_state, 0) = E_POINTER (self, this); - P_INT (&sv_pr_state, 1) = 0; - P_INT (&sv_pr_state, 2) = E_POINTER (other, this); - } - PR_ExecuteProgram (&sv_pr_state, SVfunc (self, blocked)); + sv_pr_exec (self, other, SVfunc (self, blocked)); } #endif // __sv_progs_h diff --git a/qw/include/sv_progs.h b/qw/include/sv_progs.h index c158461de..e3ebc6b70 100644 --- a/qw/include/sv_progs.h +++ b/qw/include/sv_progs.h @@ -218,19 +218,29 @@ typedef struct sv_data_s { #define EDICT_FROM_AREA(l) (STRUCT_FROM_LINK(l,sv_data_t,area)->edict) static inline void -sv_pr_touch (edict_t *self, edict_t *other) +sv_pr_exec (edict_t *self, edict_t *other, pr_func_t func) { pr_int_t this; *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); if ((this = sv_pr_state.fields.this) != -1) { + PR_PushFrame (&sv_pr_state); PR_RESET_PARAMS (&sv_pr_state); P_INT (&sv_pr_state, 0) = E_POINTER (self, this); P_INT (&sv_pr_state, 1) = 0; P_INT (&sv_pr_state, 2) = E_POINTER (other, this); } - PR_ExecuteProgram (&sv_pr_state, SVfunc (self, touch)); + PR_ExecuteProgram (&sv_pr_state, func); + if ((this = sv_pr_state.fields.this) != -1) { + PR_PopFrame (&sv_pr_state); + } +} + +static inline void +sv_pr_touch (edict_t *self, edict_t *other) +{ + sv_pr_exec (self, other, SVfunc (self, touch)); } static inline void @@ -241,33 +251,13 @@ sv_pr_use (edict_t *self, edict_t *other) static inline void sv_pr_think (edict_t *self) { - pr_int_t this; - - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); - *sv_globals.other = 0; - if ((this = sv_pr_state.fields.this) != -1) { - PR_RESET_PARAMS (&sv_pr_state); - P_INT (&sv_pr_state, 0) = E_POINTER (self, this); - P_INT (&sv_pr_state, 1) = 0; - P_INT (&sv_pr_state, 2) = 0; - } - PR_ExecuteProgram (&sv_pr_state, SVfunc (self, think)); + sv_pr_exec (self, 0, SVfunc (self, think)); } static inline void sv_pr_blocked (edict_t *self, edict_t *other) { - pr_int_t this; - - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); - if ((this = sv_pr_state.fields.this) != -1) { - PR_RESET_PARAMS (&sv_pr_state); - P_INT (&sv_pr_state, 0) = E_POINTER (self, this); - P_INT (&sv_pr_state, 1) = 0; - P_INT (&sv_pr_state, 2) = E_POINTER (other, this); - } - PR_ExecuteProgram (&sv_pr_state, SVfunc (self, blocked)); + sv_pr_exec (self, other, SVfunc (self, blocked)); } #endif // __sv_progs_h