From d6359d0eb7c63ef121b17f0b9f07365c7b56c0a3 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Jan 2016 16:38:13 +0000 Subject: [PATCH] Use template for object rotation functions --- common/include/editor/eobject.h | 6 ------ common/include/editor/kdefs.h | 26 ++++++++++++++++++++------ similar/editor/eobject.cpp | 32 ++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/common/include/editor/eobject.h b/common/include/editor/eobject.h index ed569e211..8ef2b4a5b 100644 --- a/common/include/editor/eobject.h +++ b/common/include/editor/eobject.h @@ -33,12 +33,6 @@ namespace dsx { int ObjectSelectNextInMine(void); int ObjectSelectPrevInMine(void); -int ObjectDecreaseBankBig(); -int ObjectIncreaseBankBig(); -int ObjectDecreasePitchBig(); -int ObjectIncreasePitchBig(); -int ObjectDecreaseHeadingBig(); -int ObjectIncreaseHeadingBig(); int ObjectFlipObject(); } #endif diff --git a/common/include/editor/kdefs.h b/common/include/editor/kdefs.h index e587d0b70..2eeb393c2 100644 --- a/common/include/editor/kdefs.h +++ b/common/include/editor/kdefs.h @@ -230,12 +230,26 @@ int ObjectMoveNearer(); int ObjectMoveFurther(); int ObjectSelectNextinSegment(); int ObjectSelectNextType(); -int ObjectDecreaseBank(); -int ObjectIncreaseBank(); -int ObjectDecreasePitch(); -int ObjectIncreasePitch(); -int ObjectDecreaseHeading(); -int ObjectIncreaseHeading(); + +template +int ObjectChangeRotation(); + +#define ROTATION_UNIT (4096/4) + +#define ObjectDecreaseBank ObjectChangeRotation<0, -ROTATION_UNIT, 0> +#define ObjectIncreaseBank ObjectChangeRotation<0, ROTATION_UNIT, 0> +#define ObjectDecreasePitch ObjectChangeRotation<-ROTATION_UNIT, 0, 0> +#define ObjectIncreasePitch ObjectChangeRotation +#define ObjectDecreaseHeading ObjectChangeRotation<0, 0, -ROTATION_UNIT> +#define ObjectIncreaseHeading ObjectChangeRotation<0, 0, ROTATION_UNIT> + +#define ObjectDecreaseBankBig ObjectChangeRotation<0, -(ROTATION_UNIT*4), 0> +#define ObjectIncreaseBankBig ObjectChangeRotation<0, (ROTATION_UNIT*4), 0> +#define ObjectDecreasePitchBig ObjectChangeRotation<-(ROTATION_UNIT*4), 0, 0> +#define ObjectIncreasePitchBig ObjectChangeRotation<(ROTATION_UNIT*4), 0, 0> +#define ObjectDecreaseHeadingBig ObjectChangeRotation<0, 0, -(ROTATION_UNIT*4)> +#define ObjectIncreaseHeadingBig ObjectChangeRotation<0, 0, (ROTATION_UNIT*4)> + int ObjectResetObject(); } #endif diff --git a/similar/editor/eobject.cpp b/similar/editor/eobject.cpp index d10eb5365..399c6f3b2 100644 --- a/similar/editor/eobject.cpp +++ b/similar/editor/eobject.cpp @@ -62,8 +62,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define OBJ_SCALE (F1_0/2) #define OBJ_DEL_SIZE (F1_0/2) -#define ROTATION_UNIT (4096/4) - static void show_objects_in_segment(const vcsegptr_t sp) { range_for (const auto i, objects_in(sp)) @@ -720,19 +718,25 @@ int ObjectFlipObject() return 1; } -int ObjectDecreaseBank() {return rotate_object(Cur_object_index, 0, -ROTATION_UNIT, 0);} -int ObjectIncreaseBank() {return rotate_object(Cur_object_index, 0, ROTATION_UNIT, 0);} -int ObjectDecreasePitch() {return rotate_object(Cur_object_index, -ROTATION_UNIT, 0, 0);} -int ObjectIncreasePitch() {return rotate_object(Cur_object_index, ROTATION_UNIT, 0, 0);} -int ObjectDecreaseHeading() {return rotate_object(Cur_object_index, 0, 0, -ROTATION_UNIT);} -int ObjectIncreaseHeading() {return rotate_object(Cur_object_index, 0, 0, ROTATION_UNIT);} +template +int ObjectChangeRotation() +{ + return rotate_object(vobjptridx(Cur_object_index), p, b, h); +} -int ObjectDecreaseBankBig() {return rotate_object(Cur_object_index, 0, -(ROTATION_UNIT*4), 0);} -int ObjectIncreaseBankBig() {return rotate_object(Cur_object_index, 0, (ROTATION_UNIT*4), 0);} -int ObjectDecreasePitchBig() {return rotate_object(Cur_object_index, -(ROTATION_UNIT*4), 0, 0);} -int ObjectIncreasePitchBig() {return rotate_object(Cur_object_index, (ROTATION_UNIT*4), 0, 0);} -int ObjectDecreaseHeadingBig() {return rotate_object(Cur_object_index, 0, 0, -(ROTATION_UNIT*4));} -int ObjectIncreaseHeadingBig() {return rotate_object(Cur_object_index, 0, 0, (ROTATION_UNIT*4));} +template int ObjectDecreaseBank(); +template int ObjectIncreaseBank(); +template int ObjectDecreasePitch(); +template int ObjectIncreasePitch(); +template int ObjectDecreaseHeading(); +template int ObjectIncreaseHeading(); + +template int ObjectDecreaseBankBig(); +template int ObjectIncreaseBankBig(); +template int ObjectDecreasePitchBig(); +template int ObjectIncreasePitchBig(); +template int ObjectDecreaseHeadingBig(); +template int ObjectIncreaseHeadingBig(); // ----------------------------------------------------------------------------------------------------- // Move object around based on clicks in 2d screen.