From 263b160905870f6aa1c5e96089d17603c5c5230a Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 23 Aug 2013 21:53:54 -0500 Subject: [PATCH] Add PFixed and PArray types - These are types that are stored as integers but otherwise handled as floating point values. --- src/dobjtype.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++- src/dobjtype.h | 29 +++++++++++ 2 files changed, 157 insertions(+), 1 deletion(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 267efe43b4..dc1d7aed2e 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -70,6 +70,8 @@ PName *TypeName; PSound *TypeSound; PColor *TypeColor; PStatePointer *TypeState; +PFixed *TypeFixed; +PAngle *TypeAngle; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -314,6 +316,8 @@ void PType::StaticInit() RUNTIME_CLASS(PStruct)->TypeTableType = RUNTIME_CLASS(PStruct); RUNTIME_CLASS(PPrototype)->TypeTableType = RUNTIME_CLASS(PPrototype); RUNTIME_CLASS(PClass)->TypeTableType = RUNTIME_CLASS(PClass); + RUNTIME_CLASS(PFixed)->TypeTableType = RUNTIME_CLASS(PFixed); + RUNTIME_CLASS(PAngle)->TypeTableType = RUNTIME_CLASS(PAngle); TypeTable.AddType(TypeSInt8 = new PInt(1, false)); TypeTable.AddType(TypeUInt8 = new PInt(1, true)); @@ -328,7 +332,8 @@ void PType::StaticInit() TypeTable.AddType(TypeSound = new PSound); TypeTable.AddType(TypeColor = new PColor); TypeTable.AddType(TypeState = new PStatePointer); - + TypeTable.AddType(TypeFixed = new PFixed); + TypeTable.AddType(TypeAngle = new PAngle); } @@ -738,6 +743,128 @@ PColor::PColor() assert(sizeof(PalEntry) == __alignof(PalEntry)); } +/* PFixed *****************************************************************/ + +IMPLEMENT_CLASS(PFixed) + +//========================================================================== +// +// PFixed Default Constructor +// +//========================================================================== + +PFixed::PFixed() +: PFloat(sizeof(fixed_t)) +{ +} + +//========================================================================== +// +// PFixed :: SetValue +// +//========================================================================== + +void PFixed::SetValue(void *addr, int val) +{ + assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address"); + *(fixed_t *)addr = val << FRACBITS; +} + +//========================================================================== +// +// PFixed :: GetValueInt +// +//========================================================================== + +int PFixed::GetValueInt(void *addr) const +{ + assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address"); + return *(fixed_t *)addr >> FRACBITS; +} + +//========================================================================== +// +// PFixed :: GetStoreOp +// +//========================================================================== + +int PFixed::GetStoreOp() const +{ + return OP_SX; +} + +//========================================================================== +// +// PFixed :: GetLoadOp +// +//========================================================================== + +int PFixed::GetLoadOp() const +{ + return OP_LX; +} + +/* PAngle *****************************************************************/ + +IMPLEMENT_CLASS(PAngle) + +//========================================================================== +// +// PAngle Default Constructor +// +//========================================================================== + +PAngle::PAngle() +: PFloat(sizeof(angle_t)) +{ +} + +//========================================================================== +// +// PAngle :: SetValue +// +//========================================================================== + +void PAngle::SetValue(void *addr, int val) +{ + assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address"); + *(angle_t *)addr = Scale(val, ANGLE_90, 90); +} + +//========================================================================== +// +// PAngle :: GetValueInt +// +//========================================================================== + +int PAngle::GetValueInt(void *addr) const +{ + assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address"); + return *(angle_t *)addr / ANGLE_1; +} + +//========================================================================== +// +// PAngle :: GetStoreOp +// +//========================================================================== + +int PAngle::GetStoreOp() const +{ + return OP_SANG; +} + +//========================================================================== +// +// PAngle :: GetLoadOp +// +//========================================================================== + +int PAngle::GetLoadOp() const +{ + return OP_LANG; +} + /* PStatePointer **********************************************************/ IMPLEMENT_CLASS(PStatePointer) diff --git a/src/dobjtype.h b/src/dobjtype.h index 09c6a3fd03..c4fdf48b0b 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -293,6 +293,33 @@ public: PColor(); }; +// Variations of floating point types --------------------------------------- +// These get converted to floats when they're loaded from memory. + +class PFixed : public PFloat +{ + DECLARE_CLASS(PFixed, PFloat); +public: + PFixed(); + + virtual void SetValue(void *addr, int val); + virtual int GetValueInt(void *addr) const; + virtual int GetStoreOp() const; + virtual int GetLoadOp() const; +}; + +class PAngle : public PFloat +{ + DECLARE_CLASS(PAngle, PFloat); +public: + PAngle(); + + virtual void SetValue(void *addr, int val); + virtual int GetValueInt(void *addr) const; + virtual int GetStoreOp() const; + virtual int GetLoadOp() const; +}; + // Pointers ----------------------------------------------------------------- class PStatePointer : public PInt @@ -639,5 +666,7 @@ extern PName *TypeName; extern PSound *TypeSound; extern PColor *TypeColor; extern PStatePointer *TypeState; +extern PFixed *TypeFixed; +extern PAngle *TypeAngle; #endif