Skip to content

Commit

Permalink
qcvm work
Browse files Browse the repository at this point in the history
  • Loading branch information
BraXi committed Sep 12, 2024
1 parent 4492b12 commit 5a9c6c6
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 107 deletions.
8 changes: 4 additions & 4 deletions src/engine/script/qcvm_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ char* Scr_ValueString(etype_t type, eval_t* val)
sprintf(line, "entity %i", (int)NUM_FOR_ENT(VM_TO_ENT(val->edict)));
break;
case ev_function:
f = active_qcvm->functions + val->function;
f = active_qcvm->pFunctions + val->function;
sprintf(line, "%s()", Scr_GetString(f->s_name));
break;
case ev_field:
Expand Down Expand Up @@ -136,7 +136,7 @@ char* Scr_ValueStringDeveloper(etype_t type, eval_t* val)
sprintf(line, "%i [entity]", (int)NUM_FOR_ENT(VM_TO_ENT(val->edict)));
break;
case ev_function:
f = active_qcvm->functions + val->function;
f = active_qcvm->pFunctions + val->function;
sprintf(line, "%s [function]", Scr_GetString(f->s_name));
break;
case ev_field:
Expand Down Expand Up @@ -190,7 +190,7 @@ char* Scr_UglyValueString(etype_t type, eval_t* val)
//sprintf(line, "%i", NUM_FOR_EDICT(PROG_TO_GENT(val->edict))); // braxi -- fixme
break;
case ev_function:
f = active_qcvm->functions + val->function;
f = active_qcvm->pFunctions + val->function;
sprintf(line, "%s", Scr_GetString(f->s_name));
break;
case ev_field:
Expand Down Expand Up @@ -236,7 +236,7 @@ char* Scr_GlobalString(int ofs)

CheckScriptVM(__FUNCTION__);

val = (void*)&active_qcvm->globals[ofs];
val = (void*)&active_qcvm->pGlobals[ofs];
def = ScrInternal_GlobalAtOfs(ofs);
if (!def)
{
Expand Down
36 changes: 18 additions & 18 deletions src/engine/script/qcvm_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void Scr_RunError(char* error, ...)
Com_Printf("\nError : %s\n\n", string);

Com_Printf("Last statement:\n");
Scr_PrintStatement(active_qcvm->statements + active_qcvm->xstatement);
Scr_PrintStatement(active_qcvm->pStatements + active_qcvm->xstatement);

Com_Printf("\nStack Trace: \n");
Scr_StackTrace();
Expand Down Expand Up @@ -165,7 +165,7 @@ int ScrInternal_EnterFunction(dfunction_t* f)
#endif

for (i = 0; i < c; i++)
active_qcvm->localstack[active_qcvm->localstack_used + i] = ((int*)active_qcvm->globals)[f->parm_start + i];
active_qcvm->localstack[active_qcvm->localstack_used + i] = ((int*)active_qcvm->pGlobals)[f->parm_start + i];
active_qcvm->localstack_used += c;


Expand All @@ -175,7 +175,7 @@ int ScrInternal_EnterFunction(dfunction_t* f)
{
for (j = 0; j < f->parm_size[i]; j++)
{
((int*)active_qcvm->globals)[o] = ((int*)active_qcvm->globals)[OFS_PARM0 + i * 3 + j];
((int*)active_qcvm->pGlobals)[o] = ((int*)active_qcvm->pGlobals)[OFS_PARM0 + i * 3 + j];
o++;
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ int ScrInternal_LeaveFunction()
Scr_RunError("Locals script stack underflow.");

for (i = 0; i < c; i++)
((int*)active_qcvm->globals)[active_qcvm->xfunction->parm_start + i] = active_qcvm->localstack[active_qcvm->localstack_used + i];
((int*)active_qcvm->pGlobals)[active_qcvm->xfunction->parm_start + i] = active_qcvm->localstack[active_qcvm->localstack_used + i];

// up stack
active_qcvm->stackDepth--;
Expand Down Expand Up @@ -249,27 +249,27 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName)
// this is such a mess
if (vm->progsType == VM_SVGAME)
{
sv_globalvars_t *g = (sv_globalvars_t*)vm->globals_struct;
sv_globalvars_t *g = (sv_globalvars_t*)vm->pGlobalsStruct;
if (g->self)
Scr_PrintEntityFields(VM_TO_ENT(g->self));
}
else if (vm->progsType == VM_CLGAME)
{
cl_globalvars_t* g = (cl_globalvars_t*)vm->globals_struct;
cl_globalvars_t* g = (cl_globalvars_t*)vm->pGlobalsStruct;
if (g->self)
Scr_PrintEntityFields(VM_TO_ENT(g->self));
}
else if (vm->progsType == VM_GUI)
{
ui_globalvars_t* g = (ui_globalvars_t*)vm->globals_struct;
ui_globalvars_t* g = (ui_globalvars_t*)vm->pGlobalsStruct;
if (g->self)
Scr_PrintEntityFields(VM_TO_ENT(g->self));
}
Scr_RunError("Incorrect function index %i in %s from %s.", fnum, vmDefs[vm->progsType].filename, callFromFuncName);
return;
}

f = &vm->functions[fnum];
f = &vm->pFunctions[fnum];

vm->runawayCounter = (int)vm_runaway->value;
vm->traceEnabled = false;
Expand All @@ -285,10 +285,10 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName)
{
s++; // next statement

st = &vm->statements[s];
a = (eval_t*)&vm->globals[st->a];
b = (eval_t*)&vm->globals[st->b];
c = (eval_t*)&vm->globals[st->c];
st = &vm->pStatements[s];
a = (eval_t*)&vm->pGlobals[st->a];
b = (eval_t*)&vm->pGlobals[st->b];
c = (eval_t*)&vm->pGlobals[st->c];

if (!--vm->runawayCounter)
{
Expand Down Expand Up @@ -615,7 +615,7 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName)
c->_float = !a->vector[0] && !a->vector[1] && !a->vector[2];
break;
case OP_NOT_S: // not string
c->_float = !a->string || !vm->strings[a->string];
c->_float = !a->string || !vm->pStrings[a->string];
break;
case OP_NOT_FNC: // not function
c->_float = !a->function;
Expand Down Expand Up @@ -781,7 +781,7 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName)
if (!a->function)
Scr_RunError("Call to undefined function.");

newf = &vm->functions[a->function];
newf = &vm->pFunctions[a->function];

if (newf->first_statement < 0)
{
Expand All @@ -805,9 +805,9 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName)

case OP_DONE:
case OP_RETURN:
vm->globals[OFS_RETURN] = vm->globals[st->a];
vm->globals[OFS_RETURN + 1] = vm->globals[st->a + 1];
vm->globals[OFS_RETURN + 2] = vm->globals[st->a + 2];
vm->pGlobals[OFS_RETURN] = vm->pGlobals[st->a];
vm->pGlobals[OFS_RETURN + 1] = vm->pGlobals[st->a + 1];
vm->pGlobals[OFS_RETURN + 2] = vm->pGlobals[st->a + 2];

s = ScrInternal_LeaveFunction();
if (vm->stackDepth == exitdepth)
Expand Down Expand Up @@ -886,7 +886,7 @@ void Scr_PrintEntityFields(vm_entity_t* ent)

for (i = 1; i < active_qcvm->progs->numFieldDefs; i++)
{
d = &active_qcvm->fieldDefs[i];
d = &active_qcvm->pFieldDefs[i];
name = Scr_GetString(d->s_name);
if (name[strlen(name) - 2] == '_')
continue; // skip _x, _y, _z vars
Expand Down
Loading

0 comments on commit 5a9c6c6

Please sign in to comment.