[gamecode] Macro-ize the progs type names

Now they'll never get out of sync again :)
This commit is contained in:
Bill Currie 2022-01-18 12:24:43 +09:00
parent 2df64384c1
commit 978d6fd3e8
5 changed files with 78 additions and 55 deletions

View file

@ -135,7 +135,8 @@ include_qf_progs = \
include/QF/pr_comp.h \
include/QF/pr_debug.h \
include/QF/pr_obj.h \
include/QF/pr_type.h
include/QF/pr_type.h \
include/QF/pr_type_names.h
include_qf_scene = \
include/QF/scene/entity.h \

View file

@ -51,23 +51,9 @@ PR_VEC_TYPE (pr_ulong_t, pr_ulvec4_t, 4);
PR_VEC_TYPE (double, pr_dvec2_t, 2);
PR_VEC_TYPE (double, pr_dvec4_t, 4);
#define EV_TYPE(type) ev_##type,
typedef enum {
ev_void,
ev_string,
ev_float,
ev_vector,
ev_entity,
ev_field,
ev_func,
ev_pointer, // end of v6 types
ev_quat,
ev_integer,
ev_uinteger,
ev_short, // value is embedded in the opcode
ev_double,
ev_long,
ev_ulong,
#include "QF/progs/pr_type_names.h"
ev_invalid, // invalid type. used for instruction checking
ev_type_count // not a type, gives number of types
} etype_t;

View file

@ -0,0 +1,49 @@
/*
pr_type_names.h
Progs type names
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2022 Bill Currie <bill@taniwha.org>
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifndef EV_TYPE
#define EV_TYPE(event)
#endif
EV_TYPE(void)
EV_TYPE(string)
EV_TYPE(float)
EV_TYPE(vector)
EV_TYPE(entity)
EV_TYPE(field)
EV_TYPE(func)
EV_TYPE(pointer) // end of v6 types
EV_TYPE(quat)
EV_TYPE(integer)
EV_TYPE(uinteger)
EV_TYPE(short) // value is embedded in the opcode
EV_TYPE(double)
EV_TYPE(long)
EV_TYPE(ulong)
#undef EV_TYPE

View file

@ -33,6 +33,31 @@
#include "QF/progs.h"
VISIBLE const pr_ushort_t pr_type_size[ev_type_count] = {
1, // ev_void
1, // ev_string
1, // ev_float
3, // ev_vector
1, // ev_entity
1, // ev_field
1, // ev_func
1, // ev_pointer
4, // ev_quat
1, // ev_integer
1, // ev_uinteger
0, // ev_short value in opcode
2, // ev_double
2, // ev_long
2, // ev_ulong
0, // ev_invalid not a valid/simple type
};
#define EV_TYPE(type) #type,
VISIBLE const char * const pr_type_name[ev_type_count] = {
#include "QF/progs/pr_type_names.h"
"invalid",
};
const opcode_t pr_opcodes[512] = {
#include "libs/gamecode/pr_opcode.cinc"
};

View file

@ -44,44 +44,6 @@
#include "compat.h"
VISIBLE const pr_ushort_t pr_type_size[ev_type_count] = {
1, // ev_void
1, // ev_string
1, // ev_float
3, // ev_vector
1, // ev_entity
1, // ev_field
1, // ev_func
1, // ev_pointer
4, // ev_quat
1, // ev_integer
1, // ev_uinteger
0, // ev_short value in opcode
2, // ev_double
2, // ev_long
2, // ev_ulong
0, // ev_invalid not a valid/simple type
};
VISIBLE const char * const pr_type_name[ev_type_count] = {
"void",
"string",
"float",
"vector",
"entity",
"field",
"function",
"pointer",
"quaternion",
"integer",
"uinteger",
"short",
"double",
"long",
"ulong",
"invalid",
};
// default format is "%Ga, %Gb, %gc"
// V global_string, contents, void
// G global_string, contents