mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-19 07:20:50 +00:00
[gamecode] Add tests for the state instructions
This commit is contained in:
parent
0bd05c71ac
commit
1397c94ef5
4 changed files with 128 additions and 0 deletions
|
@ -18,6 +18,7 @@ libs_gamecode_tests = \
|
|||
libs/gamecode/test/test-mem \
|
||||
libs/gamecode/test/test-scale \
|
||||
libs/gamecode/test/test-stack \
|
||||
libs/gamecode/test/test-state \
|
||||
libs/gamecode/test/test-store \
|
||||
libs/gamecode/test/test-string \
|
||||
libs/gamecode/test/test-swizzle \
|
||||
|
@ -130,6 +131,10 @@ libs_gamecode_test_test_stack_SOURCES= \
|
|||
libs_gamecode_test_test_stack_LDADD= $(test_gamecode_libs)
|
||||
libs_gamecode_test_test_stack_DEPENDENCIES= $(test_gamecode_libs)
|
||||
|
||||
libs_gamecode_test_test_state_SOURCES= \
|
||||
libs/gamecode/test/test-state.c
|
||||
libs_gamecode_test_test_state_LDADD= $(test_gamecode_libs)
|
||||
|
||||
libs_gamecode_test_test_store_SOURCES= \
|
||||
libs/gamecode/test/test-store.c
|
||||
libs_gamecode_test_test_store_LDADD= $(test_gamecode_libs)
|
||||
|
|
|
@ -36,4 +36,14 @@ typedef struct {
|
|||
pr_int_t *expect_globals;
|
||||
const char *strings;
|
||||
pr_uint_t string_size;
|
||||
// pointers/globals for state
|
||||
double *double_time;
|
||||
pr_uint_t dtime;
|
||||
float *float_time;
|
||||
pr_uint_t ftime;
|
||||
pr_uint_t self;
|
||||
// fields for state
|
||||
pr_uint_t think;
|
||||
pr_uint_t nextthink;
|
||||
pr_uint_t frame;
|
||||
} test_t;
|
||||
|
|
|
@ -108,6 +108,20 @@ setup_test (test_t *test)
|
|||
if (test->edict_area) {
|
||||
test_pr.pr_edict_area = test_pr.pr_globals + test->edict_area;
|
||||
}
|
||||
if (test->double_time || test->float_time) {
|
||||
test_pr.fields.nextthink = test->nextthink;
|
||||
test_pr.fields.frame = test->frame;
|
||||
test_pr.fields.think = test->think;
|
||||
test_pr.globals.self = (pr_uint_t *) &test_pr.pr_globals[test->self];
|
||||
if (test->double_time) {
|
||||
test_pr.globals.dtime = (double *)&test_pr.pr_globals[test->dtime];
|
||||
*test_pr.globals.dtime = *test->double_time;
|
||||
}
|
||||
if (test->float_time) {
|
||||
test_pr.globals.ftime = (float *) &test_pr.pr_globals[test->ftime];
|
||||
*test_pr.globals.ftime = *test->float_time;
|
||||
}
|
||||
}
|
||||
|
||||
test_progs.numstatements = test->num_statements + 1;
|
||||
test_pr.pr_statements
|
||||
|
|
99
libs/gamecode/test/test-state.c
Normal file
99
libs/gamecode/test/test-state.c
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include "head.c"
|
||||
|
||||
#include "QF/mathlib.h"
|
||||
|
||||
#define DB 0xdeadbeef
|
||||
|
||||
static float float_time = 1;
|
||||
|
||||
static pr_ivec4_t float_state_init[] = {
|
||||
{ 0, 0, DB, DB },
|
||||
{ 10, 11, 20, 21 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
#define f1 0x3f800000
|
||||
#define f11 0x3f8ccccd
|
||||
#define f2 0x40000000
|
||||
static pr_ivec4_t float_state_expect[] = {
|
||||
{ 0, 8, f1, DB },
|
||||
{ 10, 11, 20, 21 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 10, 20, f11, 0 },
|
||||
{ 11, 21, f2, 0 },
|
||||
};
|
||||
|
||||
static dstatement_t float_state_statements[] = {
|
||||
{ OP(0, 0, 0, OP_LEA_A), 4, 0, 1 },
|
||||
{ OP(0, 0, 0, OP_STATE_ft), 4, 6, 0 },
|
||||
{ OP(0, 0, 0, OP_LEA_A), 8, 0, 1 },
|
||||
{ OP(0, 0, 0, OP_STATE_ftt), 5, 7, 2 },
|
||||
};
|
||||
|
||||
static double double_time = 1;
|
||||
|
||||
static pr_ivec4_t double_state_init[] = {
|
||||
{ 0, 0, DB, DB },
|
||||
{ 10, 11, 20, 21 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
#define d1l 0x00000000
|
||||
#define d1h 0x3ff00000
|
||||
#define d11l 0x9999999a
|
||||
#define d11h 0x3ff19999
|
||||
#define d2l 0x00000000
|
||||
#define d2h 0x40000000
|
||||
static pr_ivec4_t double_state_expect[] = {
|
||||
{ 0, 8, d1l, d1h },
|
||||
{ 10, 11, 20, 21 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 10, 20, d11l, d11h },
|
||||
{ 11, 21, d2l, d2h },
|
||||
};
|
||||
|
||||
static dstatement_t double_state_statements[] = {
|
||||
{ OP(0, 0, 0, OP_LEA_A), 4, 0, 1 },
|
||||
{ OP(0, 0, 0, OP_STATE_dt), 4, 6, 0 },
|
||||
{ OP(0, 0, 0, OP_LEA_A), 8, 0, 1 },
|
||||
{ OP(0, 0, 0, OP_STATE_dtt), 5, 7, 2 },
|
||||
};
|
||||
|
||||
test_t tests[] = {
|
||||
{
|
||||
.desc = "float state",
|
||||
.num_globals = num_globals(float_state_init,float_state_expect),
|
||||
.num_statements = num_statements (float_state_statements),
|
||||
.statements = float_state_statements,
|
||||
.init_globals = (pr_int_t *) float_state_init,
|
||||
.expect_globals = (pr_int_t *) float_state_expect,
|
||||
.self = 1,
|
||||
.ftime = 2,
|
||||
.float_time = &float_time,
|
||||
.edict_area = 8,
|
||||
.frame = 0,
|
||||
.think = 1,
|
||||
.nextthink = 2,
|
||||
},
|
||||
{
|
||||
.desc = "double state",
|
||||
.num_globals = num_globals(double_state_init,double_state_expect),
|
||||
.num_statements = num_statements (double_state_statements),
|
||||
.statements = double_state_statements,
|
||||
.init_globals = (pr_int_t *) double_state_init,
|
||||
.expect_globals = (pr_int_t *) double_state_expect,
|
||||
.self = 1,
|
||||
.dtime = 2,
|
||||
.double_time = &double_time,
|
||||
.edict_area = 8,
|
||||
.frame = 0,
|
||||
.think = 1,
|
||||
.nextthink = 2,
|
||||
},
|
||||
};
|
||||
|
||||
#include "main.c"
|
Loading…
Reference in a new issue