Exemple #1
0
        /*
         * =============
         * ED_ParseEval
         *
         * Can parse either fields or globals
         * returns false if error
         * =============
         */
        public static bool ED_ParseEpair(object @base, ddef_t key, string keyname, string s)
        {
            int i;

            /*ddef_t	*def;
            *  char	*v, *w;*/
            FieldInfo d;

            //dfunction_t	*func;
            Object[] variables = null;
            double[] values    = new double[3];

            //d = (void *)((int *)base + key->ofs);
            d = @base.GetType().GetField(keyname);
            if (d == null)
            {
                variables = ((entvars_t)@base).variables;
            }

            switch ((etype_t)(key.type & ~DEF_SAVEGLOBAL))
            {
            case etype_t.ev_string:
                if (d != null)
                {
                    d.SetValue(@base, getStringIndex(ED_NewString(s)) - 15000);
                }
                else
                {
                    variables[key.ofs - 105] = getStringIndex(ED_NewString(s)) - 15000;
                }
                break;

            case etype_t.ev_float:
                if (d != null)
                {
                    d.SetValue(@base, common.Q_atof(s));
                }
                else
                {
                    variables[key.ofs - 105] = common.Q_atof(s);
                }
                break;

            case etype_t.ev_vector:
                int w = 0;
                int v = 0;
                for (i = 0; i < 3; i++)
                {
                    while (v < s.Length && s[v] != ' ')
                    {
                        v++;
                    }

                    values[i] = common.Q_atof(s.Substring(w, v - w));
                    w         = v = v + 1;
                }
                if (d != null)
                {
                    d.SetValue(@base, values);
                }
                else
                {
                    for (i = 0; i < 3; i++)
                    {
                        variables[key.ofs - 105 + i] = values[i];
                    }
                }
                break;

/*	        case ev_entity:
 *(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s)));
 *                      break;
 *
 *              case ev_field:
 *                      def = ED_FindField (s);
 *                      if (!def)
 *                      {
 *                              Con_Printf ("Can't find field %s\n", s);
 *                              return false;
 *                      }
 *(int *)d = G_INT(def->ofs);
 *                      break;
 *
 *              case ev_function:
 *                      func = ED_FindFunction (s);
 *                      if (!func)
 *                      {
 *                              Con_Printf ("Can't find function %s\n", s);
 *                              return false;
 *                      }
 *(func_t *)d = func - pr_functions;
 *                      break;*/

            default:
                sys_linux.Sys_Error("ERROR");
                break;
            }
            return(true);
        }
    public static string ED_ParseEdict(string data, edict_t ent)
    {
        bool init = false;

        // clear it
        if (ent != sv.edicts[0])        // hack
        {
            ent.Clear();
        }

        // go through all the dictionary pairs
        bool anglehack;

        while (true)
        {
            // parse key
            data = COM_Parse(data);
            if (com_token.StartsWith("}"))
            {
                break;
            }

            if (data == null)
            {
                Sys_Error("ED_ParseEntity: EOF without closing brace");
            }

            string token = com_token;

            // anglehack is to allow QuakeEd to write single scalar angles
            // and allow them to be turned into vectors. (FIXME...)
            if (token == "angle")
            {
                token     = "angles";
                anglehack = true;
            }
            else
            {
                anglehack = false;
            }

            // FIXME: change light to _light to get rid of this hack
            if (token == "light")
            {
                token = "light_lev";    // hack for single light def
            }
            string keyname = token.TrimEnd();

            // parse value
            data = COM_Parse(data);
            if (data == null)
            {
                Sys_Error("ED_ParseEntity: EOF without closing brace");
            }

            if (com_token.StartsWith("}"))
            {
                Sys_Error("ED_ParseEntity: closing brace without data");
            }

            init = true;

            // keynames with a leading underscore are used for utility comments,
            // and are immediately discarded by quake
            if (keyname[0] == '_')
            {
                continue;
            }

            ddef_t key = ED_FindField(keyname);
            if (key == null)
            {
                Con_Printf("'{0}' is not a field\n", keyname);
                continue;
            }

            token = com_token;
            if (anglehack)
            {
                token = "0 " + token + " 0";
            }

            if (!ParsePair(ent, key, token))
            {
                Host_Error("ED_ParseEdict: parse error");
            }
        }

        if (!init)
        {
            ent.free = true;
        }

        return(data);
    }
Exemple #3
0
        /*
        =============
        ED_ParseEval

        Can parse either fields or globals
        returns false if error
        =============
        */
        public static bool ED_ParseEpair(entvars_t @base, ddef_t key, string keyname, string s)
        {
            int i;
            /*ddef_t	*def;
            char	*v, *w;*/
            FieldInfo d;
            //dfunction_t	*func;
            globalval[] variables = null;
            double[] values = new double[3] {0, 0, 0};

            //d = (void *)((int *)base + key->ofs);
            d = typeof(entvars_t).GetField(keyname, BindingFlags.Public | BindingFlags.Instance);
            if (d == null)
                variables = ((entvars_t)@base).variables;

            switch ((etype_t)(key.type & ~DEF_SAVEGLOBAL))
            {
                case etype_t.ev_string:
                    if (d != null) d.SetValue(@base, getStringIndex(ED_NewString(s)) - prog.stringPoolOffset);
                    else variables[key.ofs - 105] = getStringIndex(ED_NewString(s)) - prog.stringPoolOffset;
                    break;

                case etype_t.ev_float:
                    if (d != null) d.SetValue(@base, common.Q_atof(s));
                    else variables[key.ofs - 105] = common.Q_atof(s);
                    break;

                case etype_t.ev_vector:
                    int w = 0;
                    int v = 0;
                    for (i = 0; i < 3; i++)
                    {
                        while (v < s.Length && s[v] != ' ') v++;

                        values[i] = common.Q_atof(s.Substring(w, v - w));
                        w = v = v + 1;
                    }
                    if (d != null) d.SetValue(@base, values);
                    else
                    {
                        for (i = 0; i < 3; i++) variables[key.ofs - 105 + i] = values[i];
                    }
                    break;

                case etype_t.ev_entity:
                    throw new NotImplementedException();
                    //*(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s)));
                    break;

                case etype_t.ev_field:
                    throw new NotImplementedException();
                    //def = ED_FindField (s);
                    //if (!def)
                    //{
                    //    Con_Printf ("Can't find field %s\n", s);
                    //    return false;
                    //}
                    //*(int *)d = G_INT(def->ofs);
                    break;

                case etype_t.ev_function:
                    throw new NotImplementedException();
                    //func = ED_FindFunction (s);
                    //if (!func)
                    //{
                    //    Con_Printf ("Can't find function %s\n", s);
                    //    return false;
                    //}
                    //*(func_t *)d = func - pr_functions;
                    break;

                default:
                    sys_linux.Sys_Error("ERROR");
                    break;
            }
            return true;
        }