From a3a0e1eae12889a0887109e14dfab05378a5be07 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sun, 19 Jul 2020 22:39:10 +0000 Subject: [PATCH] Do the _xyz thing for vectors in structs. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5736 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/qclib/qcc_pr_comp.c | 2 ++ engine/qclib/qcc_pr_lex.c | 29 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index 9f22da8ae..03c9111f6 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -15693,6 +15693,8 @@ QCC_sref_t QCC_PR_ParseInitializerType_Internal(int arraysize, QCC_def_t *basede break; if ((type)->params[partnum].isvirtual) continue; //these are pre-initialised.... + if ((type)->params[partnum].optional) + continue; //float parts of a vector. def.cast = (type)->params[partnum].type; def.ofs = (type)->params[partnum].ofs; diff --git a/engine/qclib/qcc_pr_lex.c b/engine/qclib/qcc_pr_lex.c index 2e4e58807..2d43126cf 100644 --- a/engine/qclib/qcc_pr_lex.c +++ b/engine/qclib/qcc_pr_lex.c @@ -17,6 +17,7 @@ void QCC_FreeDef(QCC_def_t *def); extern pbool destfile_explicit; extern char destfile[1024]; +static const QCC_sref_t nullsref = {0}; #define MAXINCLUDEDIRS 8 char qccincludedir[MAXINCLUDEDIRS][256]; //the -src path, for #includes @@ -5821,6 +5822,7 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail) { struct QCC_typeparam_s *parms = NULL, *oldparm; int numparms = 0; + int ofs; unsigned int arraysize; char *parmname; @@ -6013,8 +6015,8 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail) } } - parms = realloc(parms, sizeof(*parms) * (numparms+1)); - oldparm = QCC_PR_FindStructMember(newt, parmname, &parms[numparms].ofs); + parms = realloc(parms, sizeof(*parms) * (numparms+4)); + oldparm = QCC_PR_FindStructMember(newt, parmname, &ofs); if (oldparm && oldparm->arraysize == arraysize && !typecmp_lax(oldparm->type, type)) { if (!isvirt) @@ -6022,16 +6024,17 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail) } else if (structtype == ev_union) { - parms[numparms].ofs = 0; + ofs = 0; if (type->size*(arraysize?arraysize:1) > newt->size) newt->size = type->size*(arraysize?arraysize:1); } else { - parms[numparms].ofs = newt->size; + ofs = newt->size; newt->size += type->size*(arraysize?arraysize:1); } + parms[numparms].ofs = ofs; parms[numparms].arraysize = arraysize; parms[numparms].out = false; parms[numparms].optional = false; @@ -6040,6 +6043,24 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail) parms[numparms].type = type; parms[numparms].defltvalue = defaultval; numparms++; + + if (type->type == ev_vector && arraysize == 0) + { //add in vec_x/y/z members too. + int c; + for (c = 0; c < 3; c++) + { + parms[numparms].ofs = ofs + c; + parms[numparms].arraysize = arraysize; + parms[numparms].out = false; + parms[numparms].optional = true; + parms[numparms].isvirtual = isvirt; + parms[numparms].paramname = qccHunkAlloc(strlen(pr_token)+3); + sprintf(parms[numparms].paramname, "%s_%c", parmname, 'x'+c); + parms[numparms].type = type_float; + parms[numparms].defltvalue = nullsref; + numparms++; + } + } } if (!numparms) QCC_PR_ParseError(ERR_NOTANAME, "%s %s has no members", structtype==ev_union?"union":"struct", newt->name);