[gamecode] Switch dot products to give a scalar

Making them give a vector was a mistake for Ruamoko. I've probably got a
mess to clean up in game-source, but oh well.
This commit is contained in:
Bill Currie 2023-08-31 15:32:52 +09:00
parent c9734aa945
commit a66fb80517
8 changed files with 21 additions and 43 deletions

View file

@ -563,7 +563,7 @@ typedef struct pr_va_list_s {
|(((0x##c) & 0xfff) << 0) )
#define PROG_ID_VERSION 6
#define PROG_V6P_VERSION PROG_VERSION_ENCODE(0,fff,00a)
#define PROG_VERSION PROG_VERSION_ENCODE(0,fff,010)
#define PROG_VERSION PROG_VERSION_ENCODE(0,fff,011)
typedef struct pr_chunk_s {
pr_uint_t offset;

View file

@ -552,9 +552,9 @@ vecops_formats = {
"vop_type": ['F', 'D'],
"vec_widths": [
"3, 3, 3",
"2, 2, 2",
"3, 3, 3",
"4, 4, 4",
"2, 2, 1",
"3, 3, 1",
"4, 4, 1",
"2, 2, 2",
"4, 3, 3",
"3, 4, 3",

View file

@ -2618,17 +2618,13 @@ pr_exec_ruamoko (progs_t *pr, int exitdepth)
}
break;
case OP_CDOT_F:
OPC(vec2) = dot2f (OPA(vec2), OPB(vec2));
OPC(float) = dot2f (OPA(vec2), OPB(vec2))[0];
break;
case OP_VDOT_F:
{
vec_t d = DotProduct (&OPA(float),
&OPB(float));
VectorSet (d, d, d, &OPC(float));
}
OPC(float) = DotProduct (&OPA(float), &OPB(float));
break;
case OP_QDOT_F:
OPC(vec4) = dotf (OPA(vec4), OPB(vec4));
OPC(float) = dotf (OPA(vec4), OPB(vec4))[0];
break;
case OP_CMUL_F:
OPC(vec2) = cmulf (OPA(vec2), OPB(vec2));
@ -2659,17 +2655,13 @@ pr_exec_ruamoko (progs_t *pr, int exitdepth)
}
break;
case OP_CDOT_D:
OPC(dvec2) = dot2d (OPA(dvec2), OPB(dvec2));
OPC(double) = dot2d (OPA(dvec2), OPB(dvec2))[0];
break;
case OP_VDOT_D:
{
double d = DotProduct (&OPA(double),
&OPB(double));
VectorSet (d, d, d, &OPC(double));
}
OPC(double) = DotProduct (&OPA(double), &OPB(double));
break;
case OP_QDOT_D:
OPC(dvec4) = dotd (OPA(dvec4), OPB(dvec4));
OPC(double) = dotd (OPA(dvec4), OPB(dvec4))[0];
break;
case OP_CMUL_D:
OPC(dvec2) = cmuld (OPA(dvec2), OPB(dvec2));

View file

@ -28,17 +28,17 @@ static pr_vec4_t float_globals_init[] = {
static pr_vec4_t float_globals_expect[] = {
{3, 4, 5, 12},
{63, 63, -33, 56},
{63, 0, -33, 56},
{1, 2, 3, 8},
{4, 5, 6, 8},
{32, 32, 32, 7},
{32, 0, 0, 7},
{-3, 6, -3, 7},
{1, 2, 3, 4},
{5, 6, 7, 8},
{2, 3, 4, 0},
{70, 70, 70, 70},
{70, 0, 0, 0},
{24, 48, 48, -6},
{36, 102, 120, 7},
@ -102,17 +102,17 @@ static pr_dvec4_t double_globals_init[] = {
static pr_dvec4_t double_globals_expect[] = {
{3, 4, 5, 12},
{63, 63, -33, 56},
{63, 0, -33, 56},
{1, 2, 3, 8},
{4, 5, 6, 8},
{32, 32, 32, 7},
{32, 0, 0, 7},
{-3, 6, -3, 7},
{1, 2, 3, 4},
{5, 6, 7, 8},
{2, 3, 4, 0},
{70, 70, 70, 70},
{70, 0, 0, 0},
{24, 48, 48, -6},
{36, 102, 120, 7},

View file

@ -314,10 +314,7 @@ scale_expr (type_t *type, expr_t *a, expr_t *b)
static expr_t *
dot_expr (type_t *type, expr_t *a, expr_t *b)
{
auto vec_type = get_type (a);
auto dot = new_binary_expr (DOT, a, b);
dot->e.expr.type = vector_type (vec_type, type_width (vec_type));
dot = array_expr (dot, new_short_expr (0));
dot->e.expr.type = type;
return dot;
}
@ -466,8 +463,7 @@ pga3_wxyz_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto dot_type = algebra_mvec_type (alg, 0x20);
auto vb = offset_cast (dot_type,
new_swizzle_expr (b, "-x-y-z0"), 0);
auto vb = offset_cast (dot_type, new_swizzle_expr (b, "-x-y-z0"), 0);
auto sa = offset_cast (stype, a, 0);
c[5] = scale_expr (dot_type, vb, sa);
}

View file

@ -836,15 +836,7 @@ static expr_t *
vector_dot (int op, expr_t *e1, expr_t *e2)
{
expr_t *e = new_binary_expr (DOT, e1, e2);
if (options.code.progsversion == PROG_VERSION) {
e->e.expr.type = &type_vector;
if (op == '*') {
// vector * vector is dot product in v6 progs (ick)
e = new_alias_expr (&type_float, e);
}
} else {
e->e.expr.type = &type_float;
}
e->e.expr.type = &type_float;
return e;
}

View file

@ -2,10 +2,8 @@ void printf (string fmt, ...) = #0;
#if __RUAMOKO__ > 1
#define dot @dot
#define X .y
#else
#define dot *
#define X
#endif
void forcelive (float z)
@ -20,7 +18,7 @@ float foo (vector _v, float _z)
_z = 0;
forcelive (_z);
forcelive (z);
return (v dot *(vector*)(&v.y))X;
return v dot *(vector*)(&v.y);
}
int
@ -30,5 +28,5 @@ main (int argc, string *argv)
vector w = [2, 3, 4];
float f;
printf ("%v %g %g %g\n", v, v dot v, v dot w, f=foo (v, 4));
return f != (v dot w)X;
return f != v dot w;
}

View file

@ -12,7 +12,7 @@ main ()
printf ("cross product failed\n");
return 1;
};
if (vc != [1, 1, 1]) {
if (vc != 1) {
printf ("dot product failed\n");
return 1;
}