]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Remove hook system. Was a fun little experiment but is too bulky and impractical
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 8 Jun 2020 14:46:09 +0000 (14:46 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 8 Jun 2020 14:46:09 +0000 (14:46 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12648 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
csprogs.c
csprogs.h
hook.c [deleted file]
hook.h [deleted file]
host.c
makefile.inc
quakedef.h

diff --git a/cmd.c b/cmd.c
index bd92ddb974e56e2f4a4268608d9b512e54957a11..fecc7bd939c87dd3a9a857ca0e20c3503a182ecb 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -2027,8 +2027,6 @@ A complete command line has been parsed, so try to execute it
 FIXME: lookupnoadd the token to speed search?
 ============
 */
-extern hook_t *csqc_concmd;
-
 void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qboolean lockmutex)
 {
        int oldpos;
@@ -2050,7 +2048,7 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb
        {
                if (!strcasecmp(cmd->argv[0], func->name))
                {
-                       if (func->csqcfunc && Hook_Call(csqc_concmd, text)->bval)       //[515]: csqc
+                       if (func->csqcfunc && CL_VM_ConsoleCommand(text))       //[515]: csqc
                                goto done;
                        break;
                }
index 61e6bae9d5e8db6a059fc368f121d7ed1008fa91..7f1ea820cbb54574bbd119aeb00d8db5393ab944 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -502,9 +502,7 @@ qboolean CL_VM_UpdateView (double frametime)
        return true;
 }
 
-hook_t *csqc_concmd;
-
-qboolean CL_VM_ConsoleCommand (hook_val_t *arg)
+qboolean CL_VM_ConsoleCommand (const char *text)
 {
        prvm_prog_t *prog = CLVM_prog;
        int restorevm_tempstringsbuf_cursize;
@@ -517,7 +515,7 @@ qboolean CL_VM_ConsoleCommand (hook_val_t *arg)
                PRVM_clientglobalfloat(time) = cl.time;
                PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
                restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
-               PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, arg->str);
+               PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, text);
                prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_ConsoleCommand), "QC function CSQC_ConsoleCommand is missing");
                prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
                r = CSQC_RETURNVAL != 0;
index 46b71eba6ab7969758b281fe4a85a50fabf58849..a8420e850b5a5e25bced988d0943c26b264767fe 100644 (file)
--- a/csprogs.h
+++ b/csprogs.h
@@ -91,7 +91,7 @@ void CL_VM_ShutDown(void);
 void CL_VM_UpdateIntermissionState(int intermission);
 void CL_VM_UpdateShowingScoresState(int showingscores);
 qboolean CL_VM_InputEvent(int eventtype, float x, float y);
-qboolean CL_VM_ConsoleCommand(hook_val_t *arg);
+qboolean CL_VM_ConsoleCommand(const char *text);
 void CL_VM_UpdateDmgGlobals(int dmg_take, int dmg_save, vec3_t dmg_origin);
 void CL_VM_UpdateIntermissionState(int intermission);
 qboolean CL_VM_Event_Sound(int sound_num, float volume, int channel, float attenuation, int ent, vec3_t pos, int flags, float speed);
diff --git a/hook.c b/hook.c
deleted file mode 100644 (file)
index 344f9e9..0000000
--- a/hook.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
-Copyright (C) 2020 Cloudwalk
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-#include "quakedef.h"
-#include "hook.h"
-
-mempool_t *hooks;
-
-hook_t *_Hook_Register(hook_t *hook, const char *name, void *func, unsigned int argc)
-{
-       if (hook) {
-               Con_Printf("Hook %s already registered\n",hook->name);
-       } else {
-               hook = (hook_t *)Mem_Alloc(hooks, sizeof(hook_t));
-               hook->name = Mem_Alloc(hooks, strlen(name) + 1);
-               hook->arg = Mem_Alloc(hooks, sizeof(hook_val_t) * argc);
-
-               memcpy(hook->name, name, strlen(name) + 1);
-               hook->func = func;
-               hook->argc = argc;
-       }
-       return hook;
-}
-
-// Needs NULL pad to know when va_list ends.
-hook_val_t *_Hook_Call(hook_t *hook, ... )
-{
-       uintptr_t arg_ptr; // Align to platform size
-       va_list arg_list;
-       unsigned int i = 0;
-
-       if(!hook)
-               return (hook_val_t *)NULL;
-
-       va_start(arg_list, hook);
-
-       arg_ptr = va_arg(arg_list,intptr_t);
-
-       if((void *)arg_ptr && !hook->argc)
-               goto overflow;
-
-       // Loop until we encounter that NULL pad, but stop if we overflow.
-       while ((void *)arg_ptr != NULL && i != hook->argc)
-       {
-               if (i > hook->argc)
-                       goto overflow;
-               hook->arg[i].val = arg_ptr;
-               arg_ptr = va_arg(arg_list,intptr_t);
-               i++;
-       }
-
-       va_end(arg_list);
-
-       // Should be fairly obvious why it's bad if args don't match
-       if(i != hook->argc)
-               goto underflow;
-       // Call it
-       hook->ret.uval = (uintptr_t)hook->func(hook->arg);
-       
-       if (hook->ret.val)
-               return &hook->ret;
-       return (hook_val_t *)NULL;
-
-underflow:
-       Sys_Error("Hook_Call: Attempt to call hook '%s' with incorrect number of arguments. Got %i, expected %i\n", hook->name, i, hook->argc);
-overflow:
-       Sys_Error("Hook_Call: Stack overflow calling hook '%s' (argc = %u)\n", hook->name, hook->argc);
-
-}
-
-void Hook_Init(void)
-{
-       hooks = Mem_AllocPool("hooks",0,NULL);
-       return;
-}
\ No newline at end of file
diff --git a/hook.h b/hook.h
deleted file mode 100644 (file)
index d3a56fd..0000000
--- a/hook.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-Copyright (C) 2020 Cloudwalk
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-// hook.h
-
-#ifndef HOOK_H
-#define HOOK_H
-
-typedef union hook_val_s
-{
-       intptr_t val;
-       uintptr_t uval;
-       void *ptr;
-       char *str;
-       int ival;
-       unsigned int uival;
-       double fval;
-       qboolean bval;
-} hook_val_t;
-
-typedef struct hook_s
-{
-       char *name;
-       hook_val_t *(*func)(hook_val_t *hook);
-       hook_val_t *arg;
-       hook_val_t ret;
-       unsigned int argc;
-} hook_t;
-
-hook_t *_Hook_Register(hook_t *hook, const char *name, void *func, unsigned int argc);
-hook_val_t *_Hook_Call(hook_t *hook, ... );
-void Hook_Init(void);
-void Hook_Shutdown(void);
-
-// For your convenience
-#define Hook_Register(hook, func, argc) _Hook_Register(hook, #hook, func, argc)
-#define Hook_Call(hook, ... ) _Hook_Call(hook, __VA_ARGS__, NULL)
-
-#endif
\ No newline at end of file
diff --git a/host.c b/host.c
index 5459a444816446c77910206cac0add0ed29e1393..5c6af792322dfd2aad3691e544a429de462322f2 100644 (file)
--- a/host.c
+++ b/host.c
@@ -1168,8 +1168,6 @@ void Host_UnlockSession(void)
        }
 }
 
-extern hook_t *csqc_concmd;
-
 /*
 ====================
 Host_Init
@@ -1239,8 +1237,6 @@ static void Host_Init (void)
        // initialize memory subsystem cvars/commands
        Memory_Init_Commands();
 
-       Hook_Init();
-       csqc_concmd = Hook_Register(csqc_concmd,CL_VM_ConsoleCommand,1);
        // initialize console and logging and its cvars/commands
        Con_Init();
 
index b43af1b07889349444e13afd704b5126b64cce85..f77a9776c8430b3a983f2c10379de0bea10f41d0 100644 (file)
@@ -111,7 +111,6 @@ OBJ_COMMON= \
        gl_rsurf.o \
        gl_textures.o \
        hmac.o \
-       hook.o \
        host.o \
        host_cmd.o \
        image.o \
index d07a93a5a38b9494c0848901866892247c3e5e2c..8b9ea4d8aaf0242c64011bcf0fcbfdfa89541589 100644 (file)
@@ -376,7 +376,6 @@ extern char engineversion[128];
 #include "sys.h"
 #include "vid.h"
 #include "mathlib.h"
-#include "hook.h"
 
 #include "r_textures.h"