diff --git a/source/common/engine/namedef.h b/source/common/engine/namedef.h index 9d5cb27ff..f79be20a5 100644 --- a/source/common/engine/namedef.h +++ b/source/common/engine/namedef.h @@ -152,6 +152,7 @@ xx(stateinfo) xx(DamageFunction) xx(Length) xx(LengthSquared) +xx(Sum) xx(Unit) xx(Angle) xx(PlusZ) diff --git a/source/common/scripting/backend/codegen.cpp b/source/common/scripting/backend/codegen.cpp index 6f6a8e025..5c6d2171e 100644 --- a/source/common/scripting/backend/codegen.cpp +++ b/source/common/scripting/backend/codegen.cpp @@ -8273,7 +8273,7 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx) else if (Self->IsVector()) { // handle builtins: Vectors got 5. - if (MethodName == NAME_Length || MethodName == NAME_LengthSquared || MethodName == NAME_Unit || MethodName == NAME_Angle) + if (MethodName == NAME_Length || MethodName == NAME_LengthSquared || MethodName == NAME_Sum || MethodName == NAME_Unit || MethodName == NAME_Angle) { if (ArgList.Size() > 0) { @@ -9280,6 +9280,7 @@ FxExpression *FxVectorBuiltin::Resolve(FCompileContext &ctx) { case NAME_Length: case NAME_LengthSquared: + case NAME_Sum: case NAME_Angle: ValueType = TypeFloat64; break; @@ -9312,6 +9313,23 @@ ExpEmit FxVectorBuiltin::Emit(VMFunctionBuilder *build) { build->Emit(vecSize == 2 ? OP_DOTV2_RR : vecSize == 3 ? OP_DOTV3_RR : OP_DOTV4_RR, to.RegNum, op.RegNum, op.RegNum); } + else if (Function == NAME_Sum) + { + ExpEmit temp(build, ValueType->GetRegType(), 1); + build->Emit(OP_FLOP, to.RegNum, op.RegNum, FLOP_ABS); + build->Emit(OP_FLOP, temp.RegNum, op.RegNum + 1, FLOP_ABS); + build->Emit(OP_ADDF_RR, to.RegNum, to.RegNum, temp.RegNum); + if (vecSize > 2) + { + build->Emit(OP_FLOP, temp.RegNum, op.RegNum + 2, FLOP_ABS); + build->Emit(OP_ADDF_RR, to.RegNum, to.RegNum, temp.RegNum); + } + if (vecSize > 3) + { + build->Emit(OP_FLOP, temp.RegNum, op.RegNum + 3, FLOP_ABS); + build->Emit(OP_ADDF_RR, to.RegNum, to.RegNum, temp.RegNum); + } + } else if (Function == NAME_Unit) { ExpEmit len(build, REGT_FLOAT);