diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /common/ihfx | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'common/ihfx')
| -rw-r--r-- | common/ihfx/HFXConfig.h | 59 | ||||
| -rw-r--r-- | common/ihfx/IHFX.h | 707 | ||||
| -rw-r--r-- | common/ihfx/IHFXParam.h | 572 | ||||
| -rw-r--r-- | common/ihfx/ihfxeffect.h | 327 | ||||
| -rw-r--r-- | common/ihfx/types/hfxvec3.h | 306 | ||||
| -rw-r--r-- | common/ihfx/types/inl_hfxMath.h | 141 | ||||
| -rw-r--r-- | common/ihfx/util/hfxinterfacehelper.h | 54 |
7 files changed, 2166 insertions, 0 deletions
diff --git a/common/ihfx/HFXConfig.h b/common/ihfx/HFXConfig.h new file mode 100644 index 0000000..9249424 --- /dev/null +++ b/common/ihfx/HFXConfig.h @@ -0,0 +1,59 @@ +#ifndef NOVINT_HFX_CONFIG_H +#define NOVINT_HFX_CONFIG_H +// COMPILER VERSION +#if _MSC_VER +#if _MSC_VER >= 1500 +#define HFX_MSVC9 +#define HFX_MSVC 9 // Microsoft Visual C++ 2008 + +#elif _MSC_VER >= 1400 +#define HFX_MSVC8 +#define HFX_MSVC 8 // Microsoft Visual C++ 2005 + +#elif _MSC_VER >= 1300 +#define HFX_MSVC7 +#define HFX_MSVC 7 // Microsoft Visual C++ 2003 + +#else +#define HFX_MSVC6 +#define HFX_MSVC 6 // Microsoft Visual C++ 6 + +#endif +#endif + +//HFX_PURE_INTERFACE +#if HFX_MSVC >= 7 +#define HFX_PURE_INTERFACE __declspec(novtable) +#else +#define HFX_PURE_INTERFACE +#endif + +//HFX_ABSTRACT +#if HFX_MSVC >= 8 +#define HFX_ABSTRACT abstract +#else +#define HFX_ABSTRACT +#endif + +#define HFX_EXPLICIT explicit + +//HFX_INLINE +#if _MSC_VER>=1000 +#define HFX_INLINE __forceinline + +#else +#define HFX_INLINE inline +#endif + +//HFX_ALIGN +#if HFX_MSVC > 6 +#define HFX_ALIGN(nBits) __declspec(align(nBits)) +#else +#define HFX_ALIGN(nBits) +#endif + +#define HFX_MEMSET memset +#define HFX_MEMCPY memcpy + +#endif +
\ No newline at end of file diff --git a/common/ihfx/IHFX.h b/common/ihfx/IHFX.h new file mode 100644 index 0000000..227d699 --- /dev/null +++ b/common/ihfx/IHFX.h @@ -0,0 +1,707 @@ +#ifndef I_NOVINT_HFX +#define I_NOVINT_HFX + +#define HFX_VERSION_MAJOR 0 +#define HFX_VERSION_MAJOR_SZ "0" +#define HFX_VERSION_MINOR 5 +#define HFX_VERSION_MINOR_SZ "5" +#define HFX_VERSION_FLOAT 0.5 +#include "util/HFXInterfaceHelper.h" + +//( NovintHFX ) +#include "HFXConfig.h" +//( HFXClasses ) +namespace std{ + template<class _Ty> + class allocator; + template <class _Ty, + class _Ax > class vector; +}; + +#if _MSC_VER < 1400 +#define VECTOR_TYPE(type) std::vector<type> +#endif + +#if _MSC_VER >= 1400 +#define VECTOR_TYPE(type) ::std::vector<type, ::std::allocator<type> > +#endif + +#pragma warning( disable : 4251 ) +class EffectTag; + +//ensure these are not int he NovintHFX namespace. +#include "IHFXParam.h" +#include "IHFXEffect.h" + +typedef int _declspec(dllimport) (*LinkHFX_Fn)( const char * password, const char *cmdline, void **effects, void **system ); +//temporarily disable warning regarding to data classes +// needing external classes +#pragma warning(disable:4661) +//forward decl. +class IDevice; +class IStack; +struct IBaseEffectParams; +class IBaseEffect; +//( HapticsMath ) +#include "Types/hfxVec3.h" +//( HapticsSystem ) +struct IHapticEffectParamGroup; +typedef IHapticEffectParamGroup IHFXParamGroup; +typedef int DeviceIndex; +typedef unsigned long hfxPreciseTime; +typedef bool (*EnableMouseFn)( void ); + +enum eMouseMove +{ + eHFXMM_Delta=0, + eHFXMM_Absolute=0, +}; + +enum eMouseButton +{ + eHFXMM_1232=0,//1=left 2=right 3=middle 4=right + eHFXMM_1111,//1=left 2=left 3=left 4=left + eHFXMM_1342,//1=left 2=middle 3=4th 4=right + eHFXMM_None, +}; +enum eMouseMethod +{ + eHFXMouseMeth_OSInput=0, + eHFXMouseMeth_fMouse, + eHFXMouseMeth_useCallback, + eHFXMouseMeth_smartDelta, + eHFXMouseMeth_delta, + eHFXMouseMeth_COUNT, +}; +enum eMouseClick +{ + eHFXMC_Left=0, + eHFXMC_Right, + eHFXMC_Middle, + eHFXMC_Fourth, + eHFXMC_COUNT, +}; +typedef bool (*MouseEmulationFn)( const double &devicex_pos, + const double &devicey_pos, + const double &devicez_pos, + const double &devicex_delta, + const double &devicey_delta, + const double &devicez_delta, + const int &buttons_down, + const int &buttons_pressed, + const int &buttons_released, + bool moved, + /* adjust if you would liek to send a mouse button */ + bool buttonsDown[eHFXMC_COUNT] + ); + +struct ApplicationData +{ +}; +typedef void (*RollCallIndexSetCallBack)(IDevice *pDevice, const int devices_left); +class HFX_PURE_INTERFACE IHapticsSystem +{ +public: + + // call this method prior to shutting down the game. + virtual void ShutDown(bool hard=false) =0; + // THIS FUNCTION MUST BE CALLED BY YOUR APPLICATION AND RETURN TRUE PRIOR TO CREATING A DEVICE! + // window = the HWND of the program. + // returns weather or not the applicationdata was sufficent. + virtual bool AttachApplication(ApplicationData &app) =0; + virtual bool AttachApplicationByProcessName(ApplicationData &app, const char *szProcessName) =0; + + // If you want to use more than 1 device set this before. NOTE: for multiple devices you must use device lock + //HFX_VIRTUAL bool SetOptionalDeviceCount( unsigned int nDevices ); + + // Use this function to create a device. (note: when making multiple devices they must be connected in numerical order.) + virtual bool RunDevice(IDevice **ppDevice, const char *deviceName=0, const char *configDir=0) =0; + + // When using multiple devices you _MUST_ lock devices after device connection attempts are made. + virtual void LockDevices() =0; + + // When using mutliple devices you _MUST_ unlock devices once they are locked to connect more devices and then lock again afterwards. + virtual void UnlockDevices() =0; + + // Note: this will return the max number of devices specified in the constructor of HapticsSystem. + virtual unsigned int GetTargetDeviceCount() const =0; + + // connects multiple devices at once. returns number of devices connected. + // if targetNumber==-1 then all connected devices will be ran. + virtual int RunMultipleDevices(const int targetNumber=-1) =0; + + // returns true if device was stopped. + virtual bool StopRunningDevice(IDevice **ppDevice) =0; + + // returns true if all instances were stopped. + virtual bool StopAllRunningDevices() =0; + + //this will ask the user to press a button on each device. the order in which they + // press a button on each connected device will order their device id from zero to the number + // of falcons the user has minus one. + // note: without roll call devices are ordered by their serial number. + // returns false if only one falcon is connected. + virtual bool RollCallDevices(RollCallIndexSetCallBack CallBackFn=0,bool bCreateThread=false) =0; + + // will return true untill roll call is over. + virtual bool IsInRollCall() const =0; + + // updates roll call data. only call this if your in a roll call and the roll call was not started + // with bCreateThread set to true. + // returns true if still in roll call. + virtual bool RollCallUpdate() =0; + + // cancles roll call in progress. if ApplyMadeChanges is true the devices who responded + // to the roll call will be set in and the unset will be moved to the end of the index list. + virtual bool StopRollCall(bool ApplyMadeChanges=false) =0; + + //only call this ONCE per game input tick. + // returns number of devices updated. + virtual int InputUpdate(); + + //void SetMouseMode(HWND window,eHFXMouseMove MoveMode=eHFXMM_Delta,eHFXMouseButton ButtonMode=eHFXMM_1232); + virtual void SetMouseMode(eMouseMove MoveMode=eHFXMM_Delta,eMouseButton ButtonMode=eHFXMM_1232) =0; + virtual void StartMouse(IDevice *pDev) =0; + virtual void StartMouse(const DeviceIndex device) =0; + virtual void StartMouse() =0; + virtual void MouseUpdate() =0; + virtual void StopMouse() =0; + + // returns if we are in cursor emulation. If pDevice is null it will return weather any device is in mouse emulation. + virtual bool IsMouseMode(const IDevice *pDevice=0) =0; + + //returns true if forces are allowed. + virtual bool ForcesAllowed() =0; + + //returns true if input is allowed. + virtual bool InputAllowed() =0; + + //returns true if forces are enabled. + // Note: this could be true and forces may not be allowed. + // MouseMode RollCall window focus and possibly other things will not allow forces. + virtual bool ForcesEnabled() =0; + + //HFX_VIRTUAL void DisableForces() HFX_PURE; + //HFX_VIRTUAL void EnableForces() HFX_PURE; + //returns device of index nDevice + virtual IDevice *GetRunningDeviceByIndex(const DeviceIndex nDevice) const =0; + + //returns device on hardware index. + virtual IDevice *GetRunningDeviceByHardwareIndex(const int nSerialOrder) const =0; + + //returns number of running devices. + virtual int RunningDeviceCount() const =0; + + //returns number of devices connected to the users computer. + virtual int ConnectedDeviceCount() const =0; + + // this will re count available devices. + // use ConnectedDeviceCount() to get the count. + virtual void RecountConnectedDevices() =0; + + virtual bool AllocateEffectParameter(IHFXParamGroup *&pIEffectParam, HFXEffectID associatedClass, const char *copyCachedSettings=0, const char *storageName=0) =0; + HFX_INLINE bool AllocateEffectParameter(IHFXParamGroup *&pIEffectParam, const char *copyCachedSettings=(const char*)0, const char *storageName=0 ){return AllocateEffectParameter(pIEffectParam, 0, copyCachedSettings, storageName);} + virtual bool DeallocateEffectParameter(IHFXParamGroup *&ppIEffectParam) =0; + + virtual unsigned int GetCachedParameterCount() const =0; + virtual IHFXParamGroup *GetCachedParameter(const char *name) =0; + virtual IHFXParamGroup *GetCachedParameter(const unsigned int name) =0; + virtual const char *GetCachedParameterName(const unsigned int id) const =0; + + // Note: any format ( besides Bitfile ) where it cannot find the file specified will try to + // load a encoded bitfile if it does not exist. A bit file will be generated when you load any + // format. When release time comes around just delete the iniFile and include the bitfile output + + // each format has a way to turn this functionality off. if you + virtual bool CacheEffectParametersINI( const char *iniFile ) =0; + + virtual bool CacheEffectParametersBitfile( const char *bitFile ) =0; + // will add .nvnt extension + virtual bool SaveCache( const char *file ) =0; + + //HFX_VIRTUAL bool LoadHFXModule( const char *moduleName, const char *modulePassword=0 ) HFX_PURE; + virtual hfxPreciseTime GetBaseTime() const =0; + virtual hfxPreciseTime GetRunTime() const =0; + virtual double GetRunTimeSeconds() const =0; + virtual double GetBaseTimeSeconds() const =0; + + virtual bool CreateNewEffectStack(const char *uniqueName, IStack**ppStack, unsigned int inputDevices=0) =0; + virtual bool DeleteEffectStack(IStack**ppStack) =0; + virtual IStack* FindEffectStack(const char *name) =0; + + //command support + //HFX_VIRTUAL int RunCommand( const char *cmd ) HFX_PURE; + + //HFX_VIRTUAL bool InitFromXML(ApplicationData &appdata,unsigned int &devices, const char *xmlLoc) HFX_PURE; + + virtual int LogMessage(const int type, const char *fmt, ...); + virtual int LogMessage(const char *fmt, ...); + + virtual bool SetMouseEmulation( eMouseMethod method ) =0; + virtual bool SetMouseEmulationFunction( MouseEmulationFn method_function ) =0; + #ifndef HFX_INTERNAL + inline bool SetMouseEmulation( MouseEmulationFn method_function ){if(!method_function) return false; return ( SetMouseEmulation(eHFXMouseMeth_useCallback) && SetMouseEmulationFunction(method_function)); } + #endif + virtual bool ScaleDeviceCoordsForCursor( double &x, double &y, double width=-1, double height=-1, double offsetx=-1, double offsety=-1 ) =0; + // try and put device to sleep. if null all devices will try to sleep. devices will sleep untill touched. + virtual void AttemptSlumber(IDevice *device=0) =0; + + virtual void ActivateDynamicWindowHandler(const char *windowClassName, const char *windowText, unsigned int msHeartInterval=70) =0; + virtual void DeactivateDynamicWindowHandler() =0; + virtual bool IsDynamicWindowHandlerRunning() const =0; + + virtual HFXEffectID RegisterEffectClass(const char *tag, HFXCreate_t alloc, HFXDestroy_t dealloc, HFXNEED needs, IHFXParamGroup *defaults=0) =0; +#define HFX_NON_ELEMENT 0xFFFFF0 + virtual bool SetParameterGroupVar(IHFXParamGroup ¶ms, HFXParamID var, const char *string, unsigned int element=HFX_NON_ELEMENT) =0; + virtual bool SetParameterGroupVar(IHFXParamGroup ¶ms, const char *varString, const char *string, unsigned int element=HFX_NON_ELEMENT) =0; + virtual HFXEffectID LookupEffectIDByName(const char *name) const =0; + virtual const char *LookupEffectNameByID(HFXEffectID id) const =0; + + // only call if explicit stack syncs are enabled + virtual void SyncEffectStacks() =0; + + virtual HFXParamID EnumerateEffectParameters( HFXEffectID id, HFXParamID LastParamID ) =0; + virtual bool CacheEffectParameterGroupCopy(const char *cachename, IHFXParamGroup *params) =0; + virtual bool SaveEffectParameterCache(const char *filename, const char *type = "ini") =0; + virtual void DoReport() =0; +}; + +//( HapticsDevice ) +//HFX BUTTON DEFINES : Based on HDL Button Defines. +#define HFX_BUTTON_1 0x00000001 /**< Mask for button 1 */ +#define HFX_BUTTON_2 0x00000002 /**< Mask for button 2 */ +#define HFX_BUTTON_3 0x00000004 /**< Mask for button 3 */ +#define HFX_BUTTON_4 0x00000008 /**< Mask for button 4 */ +#define HFX_BUTTON_ANY 0xffffffff /**< Mask for any button */ + +//Internal class. +struct HFX_PURE_INTERFACE IDeviceData +{ +}; + +namespace NovintHFX{ + class Device; + class Stack; + namespace Effects{ + struct command_info; + int ProcessCommand( IBaseEffect *pEffect, const char *argv[], const unsigned int argc ); + } +}; +// This function callback type will be used with SetServoLoopCallbackFunction. +// The main difference between hdlServoOp and this is that you get the device. +typedef int (*OldServoLoopFn) (void *pParam, class IDevice *pDevice, double outforces[3]); +class HFX_PURE_INTERFACE IDevice +{ +public: + //Is this device able to output forces? + virtual bool AcceptingForces() const =0; + + //The device is connected. + virtual bool IsConnected() const =0; + + //Sets pos to the tool Position. + virtual void GetToolPosition(double pos[3]) const =0; + virtual void GetToolPositionWorkspace(double pos[3]) const =0; + virtual void GetButtonData(int *down=0, int *pressed=0, int *released=0) const =0; + virtual void GetCurrentForce(double force[3]) const =0; + virtual bool IsButtonDown( int nButton ) const =0; + virtual IStack *GetEffectStack() =0; + virtual const DeviceIndex GetIndex() const =0; + virtual int GetHardwareIndex() const =0; + virtual void InputUpdate() =0; + + virtual bool ConnectStack( IStack *stack ) =0; + virtual bool DisconnectStack( IStack *stack ) =0; + + // This function is here for quick integration into games which already have a few custom + // effects of their own. Taking the old ServoOp function and adding in pDevice + virtual void SetServoLoopCallbackFunction( OldServoLoopFn old_fn, void *pParam ) =0; + + // you should never call this unless your in a callback running on servo. + virtual void _GetServoData(double toolpos[3], int &buttons) =0; + + virtual __int64 GetSerialNumber() const =0; + + virtual BoundingBox3 GetWorkspace() const =0; + + virtual void SetEngineData(void *data) =0; + virtual void *GetEngineData() const =0; + + virtual bool HasRested( unsigned int msDur=1 ) const =0; + virtual bool IsSleeping(bool justForces=false) const =0; + virtual bool TriggerFade(unsigned int msMuteTime, unsigned int msDuration, bool forceOverride=false) =0; + virtual void ForceSlumber() =0; + virtual void SetForceScale(const double &scale) =0; + virtual double GetForceScale() const =0; +}; + +//( HapticsStack ) +class Processor; +//EFFECT STACK +//note one stack per device handle only. +class HFX_PURE_INTERFACE IStack +{ +public: + + // Returns true if effect was created. + // -- + // NOTE: NOT ALL EFFECTS ( SUCH AS SELF DELETING ) + // WILL ALLOW YOU TO HAVE A HANDLE TO IT. + // CHECKING POINTER VALIDITY OF THE HANDLE IN THE + // CREATE NEW EFFECT WILL ONLY LET YOU KNOW IF + // ANYTHING WAS SET TO IT, NOT NECCISARILLY IF + // THE EFFECT WAS CREATED. + // -- + virtual bool CreateCachedEffect(IHFXEffect *&pHandle, const char *entry, const char *instancename=0 ); + + template<typename T> + HFX_INLINE bool CreateCachedEffect(T *&pTypedHandle, const char *entry, const char *instanceName=0) + { + return CreateCachedEffect((IHFXEffect*&)pTypedHandle, entry, instanceName); + } + HFX_INLINE bool CreateCachedEffect(const char *entry){ return CreateCachedEffect(hfxNoHandle, entry); } + + virtual bool CreateNewEffect(IHFXEffect *&ppHandle, HFXEffectID effectName, IHFXParamGroup *params, const char *instanceName=0); + + template<typename T> + HFX_INLINE bool CreateNewEffect(T *&pTypedHandle, HFXEffectID effectName, IHFXParamGroup *params, const char *instanceName=0) + { + return CreateNewEffect((IHFXEffect*&)pTypedHandle, effectName, params, instanceName); + } + + HFX_INLINE bool CreateNewEffect(HFXEffectID effectName, IHFXParamGroup *params){ return CreateNewEffect(hfxNoHandle, effectName, params, 0); }; + // Returns NULL if there was no effect using that name. + // -- + // NOTE: YOU SHOULD ONLY HAVE ONE HANDLE OF A EFFECT + // IN AS A MEMBER VARIABLE ( NON LOCAL ). OTHERWISE + // YOU RISK INVALID POINTERS IF YOU DELETE THE EFFECT. + // WITH A SECOND REFERENCE. + virtual IHFXEffect *FindRunningEffect(const char *instanceName) const =0; + // Returns true if effect was deleted + // -- + // NOTE: THIS IS ONLY FOR EFFECTS WHICH NEED TO BE + // DELETED MANUALLY. MANY EFFECTS WILL DELETE + // THEMSELFS AND THOSE EFFECTS YOU SHOULD NOT + // EVER RECEIVE HANDLES FOR. + // -- + virtual bool DeleteRunningEffect(IHFXEffect *&effect) =0; + + template<typename T> + HFX_INLINE bool DeleteRunningEffect(T *&pTypedEffect) + { + return DeleteRunningEffect((IHFXEffect*&)pTypedEffect); + } + + virtual void GetLastForce(double force[3])const =0; + + virtual void SetDeviceLock(bool state) =0; + virtual bool IsDeviceListLocked() const =0; + + // returns true if device was added or is already a member. if slot is -1 it will just enter the device + // as the next available slot. + virtual bool AddDevice(IDevice*pDevice, int slot=-1) =0; + + // returns the device in slot + virtual IDevice *GetDeviceInSlot(unsigned int id=0) const =0; + + virtual void GetCalclatedForces(double force[3]) =0; + virtual const char *Name() const =0; + + //command support + //HFX_VIRTUAL int RunCommand( const char *cmd ) HFX_PURE; + + virtual void *GetUserData() const =0; + virtual void SetUserData(void*data) =0; + + virtual void SetVolume( const double &scale ) =0; + virtual double GetVolume() const =0; + + virtual unsigned int GetTargetDeviceCount() const =0; + + virtual void SetEngineData(void *data) =0; + virtual void *GetEngineData() const =0; + + virtual void SetEffectUserData(IHFXEffect *pEffect, void *pData) =0; + virtual void *GetEffectUserData(IHFXEffect *pEffect) =0; +}; + +//( HapticsEffect ) +struct HFX_PURE_INTERFACE IRegister +{ +public: + virtual void AllocateEffect(IHFXEffect *&pEffectPtr) =0; + virtual void DeallocateEffect(IHFXEffect *&pEffectPtr) =0; + virtual void AllocateParameterGroup(IHFXParamGroup *&pEffectPtr) =0; + virtual void DeallocateParameterGroup(IHFXParamGroup *&pEffectPtr) =0; + virtual const char *GetTagName() const =0; +}; + +#define HFX_PROCESSOR_PARAM_FORCESCALE 4294967293 +#define HFX_PROCESSOR_PARAM_TIMESCALE 4294967294 + +class HFX_PURE_INTERFACE IProcessor +{ +public: + + // call this to mute and unmute this effect. (note: effect will still be updated, just will not output force.) + // note : this setting will not be applied untill the next sync op ( InputUpdate ) called by the application. + virtual void SetMuted(bool mute) =0; + virtual void SetPaused(bool pause) =0; + + // see if the effect is muted. + HFX_INLINE bool IsMuted() const { return ((GetEffectState() & HFXSTATE_MUTE)!=0); } + + // see if the effect is explicitly paused. + HFX_INLINE bool IsPaused() const { return ((GetEffectState() & HFXSTATE_PAUSE)!=0); } + + // scale this force (NOTE: THIS IS SEPERATE FROM PARAMETER SCALE!) + virtual void SetForceScale( double scale ) =0; + virtual double GetForceScale( ) const =0; + + virtual const char *GetEffectTypeName() const =0; + + // override this function to return the number of falcons this + // effect requires. + HFX_INLINE unsigned int RequiredDeviceCount() const + { + HFXNEED needs= GetEffectNeeds(); + return HFXNEED_UTIL_COUNT_DEVICES(needs); + } + + // returns true if the effect is running. + HFX_INLINE bool IsRunning() const {return ( (GetEffectState() & (HFXSTATE_RUNNING)) != 0 );} + + // if your effect is not self deleting and requires runtime data you should override this to true. + HFX_INLINE bool CanBeHandled() const { return (GetEffectNeeds() & HFXNEED_ENCAPSULATED)==0; } + + // this lets the haptic effect stack know you are done with this effect and it is waiting to be deleted. + // CANNOT BE OVERRIDDEN ( see OnFlaggedForRemoval() ) + virtual void FlagForRemoval() =0; + + //Stack functions! + friend class NovintHFX::Stack; + friend int NovintHFX::Effects::ProcessCommand( IBaseEffect *pEffect, const char *argv[], const unsigned int argc ); + + // do not use. + //HFX_VIRTUAL bool Stop() HFX_PURE; + + // DO NOT OVERRIDE! + HFX_INLINE bool NeedsRemoval() const + { return ( ( GetEffectNeeds() & HFXNEED_REMOVE ) ? ( ( ( GetEffectState() & HFXSTATE_RUNNING ) ) ? false : true ) : false ); } + + // DO NOT OVERRIDE! + HFX_INLINE bool WantsSyncOp() const + { + return (((GetEffectNeeds() & HFXNEED_SYNC)!=0) && ((GetEffectState() & HFXSTATE_WANT_SYNC)!=0)); + } + // DO NOT OVERRIDE! + virtual bool WantsUpdate() const {return (((GetEffectNeeds() & HFXNEED_PROCESS)!=0) && ((GetEffectState() & HFXSTATE_WANT_UPDATE)!=0) && ((GetEffectState() & HFXSTATE_RUNNING)!=0));} + + virtual HFXSTATE GetEffectState() const =0; + virtual const HFXNEED &GetEffectNeeds() const =0; + + virtual void *_output() const =0; + + virtual const double &Runtime() const =0; + virtual const double &Frametime() const =0; + + virtual IStack *GetStack() =0; + virtual IHFXSystem *GetSystem() =0; + virtual void *GetUserData() =0; + virtual void SetUserData(void *userData) =0; + HFX_INLINE hfxVec3 &Output() { return *(reinterpret_cast<hfxVec3*>(_output())); } + HFX_INLINE const hfxVec3 &Output() const{return *(reinterpret_cast<const hfxVec3*>(_output()));} + HFX_INLINE double &operator[](int i){ return (Output().m[i]); }; + HFX_INLINE const double &operator[](int i)const{ return (Output()[i]); }; + HFX_INLINE bool IsOutputValid() const { return !IsOutputNaN();} + HFX_INLINE bool IsOutputNaN() const { const double *o=Output(); return(o[0]!=o[0]||o[1]!=o[1]||o[2]!=o[2]);} + HFX_INLINE hfxVec3 &operator =(const hfxVec3 &vect){hfxVec3 &out = Output(); out = vect; return out;} +}; +typedef IProcessor IHFXProcessor; +typedef char HFX_VarType; + +#define HFX_Double 'd' +#define HFX_Float 'f' +#define HFX_Int 'i' +#define HFX_Bool 'b' +#define HFX_Other 'o' +#define HFX_Pointer 'p' +#define HFX_Null 0 + + +#pragma warning( default : 4251 ) + +#ifdef HFX_MODULE_LAYER +#include HFX_MODULE_LAYER +#endif + +#define ConnectNovintHFX YOU_MUST_INCLUDE_WINDOWS_PRIOR_TO_INCLUDING_INovintHFX_h +#endif + +// to connect windows.h must be included +#if ( !defined(I_NOVINT_HFX_WINDOWS) && ( defined(_INC_WINDOWS) || defined(LoadLibrary) && defined(HMODULE) ) ) && !defined(STATIC_IHFX) +#define I_NOVINT_HFX_WINDOWS + +#ifdef ConnectNovintHFX +#undef ConnectNovintHFX +#endif + +extern HMODULE dllNovintHFX_; +extern IHapticsSystem *_hfx; + +//quick helper class to ensure novint hfx unloads properly. +struct NovintHFXCloseHelper +{ + NovintHFXCloseHelper() : forceSkipQuit(false) + { + static bool ONE_INSTANCE_ONLY=true; + if(!ONE_INSTANCE_ONLY) + { +#ifdef _DEBUG + // look at the call stack and please remove whatever is calling this constructor. + // there should be only one HFX_INIT_VARS. + DebugBreak(); +#endif + ExitProcess(100); + } + ONE_INSTANCE_ONLY = false; + }; + bool forceSkipQuit; + ~NovintHFXCloseHelper() + { + if(!forceSkipQuit&&_hfx) + { + _hfx->ShutDown(true); + } + }; +}; +extern NovintHFXCloseHelper _hfx_close; + +#define HFX_INIT_VARS() \ + HMODULE dllNovintHFX_=0; \ + IHapticsSystem *_hfx =0; \ + NovintHFXCloseHelper _hfx_close; + +// if windows is included heres a inline function to get the interface! +inline bool ConnectNovintHFX( IHapticsSystem **ppSystem, void *window, const char *cmd, void*pCursorEnableFn=0, unsigned int TargetDevices=1) +{ + if(ppSystem==0) + return false; + + char szNovintDir[ MAX_PATH ]; + char szNovintDll[ MAX_PATH ]; + if ( GetEnvironmentVariableA( "NOVINT_DEVICE_SUPPORT", szNovintDir, sizeof( szNovintDir ) ) == 0 || !V_IsAbsolutePath( szNovintDir ) ) + { + return false; + } + + unsigned int tries = 0; + while(dllNovintHFX_==0) + { + const char *dllName = HFX_DYNAMIC_LIBRARY_NAME(tries); + if(!dllName) + break; + V_sprintf_safe( szNovintDll, "%s\\bin\\%s", szNovintDir, dllName ); + dllNovintHFX_ = LoadLibraryA( szNovintDll ); + if(!dllNovintHFX_) + tries++; + } + + NovintHFX_ExposeInterfaceFn connectFn = 0; + if(dllNovintHFX_) + { + connectFn = (NovintHFX_ExposeInterfaceFn)GetProcAddress(dllNovintHFX_, HFX_CONNECT_FUNCTION_NAME()); + } + if(!connectFn){ + // if direct load failed.. + if(dllNovintHFX_) + { + FreeLibrary(dllNovintHFX_); + } + V_sprintf_safe( szNovintDll, "%s\\bin\\%s", szNovintDir, "hfx.dll" ); + dllNovintHFX_ = LoadLibraryA( szNovintDll ); + if(dllNovintHFX_) + { + connectFn = (NovintHFX_ExposeInterfaceFn)GetProcAddress(dllNovintHFX_, "CreateHFX"); + } + } + if(connectFn&&connectFn((void **)ppSystem, window, cmd, HFX_VERSION_MAJOR, HFX_VERSION_MINOR, pCursorEnableFn, TargetDevices )==0) + { + _hfx = (*ppSystem); + return true; + } + + return false; +} +#ifndef HFX_STRIPPED +inline bool ConnectNovintHFX_XML( IHapticsSystem **ppSystem, void *window, const char *xml, void*pCursorEnableFn=0, unsigned int TargetDevices=1) +{ + if(ppSystem==0) + return false; + + char szNovintDir[ MAX_PATH ]; + char szNovintDll[ MAX_PATH ]; + if ( GetEnvironmentVariable( "NOVINT_DEVICE_SUPPORT", szNovintDir, sizeof( szNovintDir ) ) == 0 || !V_IsAbsolutePath( szNovintDir ) ) + { + return false; + } + + unsigned int tries = 0; + while(dllNovintHFX_==0) + { + const char *dllName = HFX_DYNAMIC_LIBRARY_NAME(tries); + if(!dllName) + break; + V_sprintf_safe( szNovintDll, "%s\\bin\\%s", szNovintDir, dllName ); + dllNovintHFX_ = LoadLibraryA( szNovintDll ); + if(!dllNovintHFX_) + tries++; + } + NovintHFX_ExposeInterfaceFn connectFn = 0; + if(dllNovintHFX_) + { + connectFn = (NovintHFX_ExposeInterfaceFn)GetProcAddress(dllNovintHFX_, HFX_CONNECT_FUNCTION_NAME_XML()); + } + if(!connectFn){ + if(dllNovintHFX_) + { + FreeLibrary(dllNovintHFX_); + dllNovintHFX_=0; + } + V_sprintf_safe( szNovintDll, "%s\\bin\\%s", szNovintDir, "hfx.dll" ); + dllNovintHFX_ = LoadLibraryA( szNovintDll ); + if(dllNovintHFX_) + { + connectFn = (NovintHFX_ExposeInterfaceFn)GetProcAddress(dllNovintHFX_, "CreateHFX_XML"); + } + + } + if(connectFn&&connectFn((void **)ppSystem, window, xml, HFX_VERSION_MAJOR, HFX_VERSION_MINOR, pCursorEnableFn, TargetDevices )==0) + { + _hfx = (*ppSystem); + return true; + } + return false; +} +#endif +inline bool ConnectNovintHFX( IHapticsSystem **ppSystem, HWND hwnd, const char *cmd, void*pCursorEnableFn=0, unsigned int TargetDevices=1 ){ return ConnectNovintHFX( ppSystem, (void*)hwnd, cmd, pCursorEnableFn, TargetDevices); } +inline void DisconnectNovintHFX(IHapticsSystem **ppSystem=0) +{ + if(dllNovintHFX_&&_hfx) + { + IHapticsSystem *pTemp = _hfx; + _hfx = 0; + _hfx_close.forceSkipQuit=true; + if(ppSystem) + { + *ppSystem = 0; + } + pTemp->ShutDown(); + if(FreeLibrary(dllNovintHFX_)) + { + dllNovintHFX_ = 0; + } + } +} +#endif + diff --git a/common/ihfx/IHFXParam.h b/common/ihfx/IHFXParam.h new file mode 100644 index 0000000..13d3b1e --- /dev/null +++ b/common/ihfx/IHFXParam.h @@ -0,0 +1,572 @@ +#ifndef IHFXPARAM_H_ +#define IHFXPARAM_H_ +#include ".\\HFXConfig.h" + +class IHapticEffect; +typedef IHapticEffect IHFXEffect; +#ifdef HFX_64BIT +#define HFX_NULL_HANDLE ((IHFXEffect*)(unsigned long)0x000000000000001) +#else +#define HFX_NULL_HANDLE ((IHFXEffect*)(unsigned long)0x00000001) +#endif +static IHFXEffect *hfxNoHandle=HFX_NULL_HANDLE; + +typedef unsigned __int32 HFXParamID; +typedef unsigned __int32 HFXEffectID; + +// if a invalid char is added it will show up as '`' +// if a '?' it will be the same as a '_' +// any upper case chars will be converted to lowercase. + + +#define HFX_PARAM_ENCODE_CHAR_LOWER(lowercase_alpha_or_underscore) \ + (lowercase_alpha_or_underscore ? ( ( lowercase_alpha_or_underscore < ('~'+1) ) ? \ + ( (lowercase_alpha_or_underscore)-('^') ) : 2 ) : 0) + +#define HFX_PARAM_ENCODE_CHAR_UPPER(upper_alpha) \ + (upper_alpha!=0 ? ( (upper_alpha>'>') ? \ + ((upper_alpha)-('>')) : ( ((upper_alpha>'/')&&(upper_alpha<':')) ? \ + ((upper_alpha + 32)-('>')) : (2) ) \ + ) : 0) + +#define HFX_PARAM_ENCODE_CHAR(alpha_or_underscore) \ + (alpha_or_underscore ?(alpha_or_underscore < '_') ? \ + HFX_PARAM_ENCODE_CHAR_UPPER(alpha_or_underscore) : \ + HFX_PARAM_ENCODE_CHAR_LOWER(alpha_or_underscore):0 ) + +#define HFX_PARAM_PACK_CHAR(char, index) \ + ( char ? ((char) << (index * 5)) : 0 ) + +#define HFX_PARAM_ENCODE_STRING_CHAR(char) ( (char < '_') ? (HFX_PARAM_ENCODE_CHAR_UPPER(char)) : (HFX_PARAM_ENCODE_CHAR_LOWER(char)) ) + +#define HFX_PARAM_ENCODE_AND_PACK_CHAR(char, index) \ + HFX_PARAM_PACK_CHAR(HFX_PARAM_ENCODE_CHAR(char), index) + + +#define TC unsigned int + +#define HFX_PARAM_ENCODE_STRING(ConstCharPtr7) \ + ( ConstCharPtr7 ? \ + (ConstCharPtr7[0]!=0 ? \ + ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[0])) << 0) | \ + (ConstCharPtr7[1]!=0 ? \ + ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[1])) << 5) | \ + (ConstCharPtr7[2]!=0 ? \ + ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[2])) << 10) | \ + (ConstCharPtr7[3]!=0 ? \ + ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[3])) << 15) | \ + (ConstCharPtr7[4]!=0 ? \ + ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[4])) << 20) | \ + (ConstCharPtr7[5]!=0 ? \ + ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[5])) << 25) \ + : (unsigned)0) \ + : (unsigned)0) \ + : (unsigned)0) \ + : (unsigned)0) \ + : (unsigned)0) \ + : (unsigned)0) \ + : (unsigned)0) + +#define HFX_PARAM_ENCODE_6(c1,c2,c3,c4,c5,c6) \ + ((HFXParamID)\ + ( HFX_PARAM_ENCODE_AND_PACK_CHAR(c1,0) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c2,1) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c3,2) \ + | HFX_PARAM_ENCODE_AND_PACK_CHAR(c4,3) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c5,4) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c6,5) )) + +#define HFX_PARAM_ENCODE_5(c1,c2,c3,c4,c5) \ + HFX_PARAM_ENCODE_6(c1,c2,c3,c4,c5,0) + +#define HFX_PARAM_ENCODE_4(c1,c2,c3,c4) \ + HFX_PARAM_ENCODE_6(c1,c2,c3,c4,0,0) + +#define HFX_PARAM_ENCODE_3(c1,c2,c3) \ + HFX_PARAM_ENCODE_6(c1,c2,c3,0,0,0) + +#define HFX_PARAM_ENCODE_2(c1,c2) \ + HFX_PARAM_ENCODE_6(c1,c2,0,0,0,0) + +#define HFX_PARAM_ENCODE_1(c1) \ + HFX_PARAM_ENCODE_6(c1,0,0,0,0,0) + +#define HFX_PARAM_DECODE_TO(char7, hfxparamid) \ + (char7)[0] = HFX_CHAR_ID(hfxparamid, 0); \ + (char7)[1] = (char7)[0] ? HFX_CHAR_ID(hfxparamid, 1) : 0; \ + (char7)[2] = (char7)[1] ? HFX_CHAR_ID(hfxparamid, 2) : 0; \ + (char7)[3] = (char7)[2] ? HFX_CHAR_ID(hfxparamid, 3) : 0; \ + (char7)[4] = (char7)[3] ? HFX_CHAR_ID(hfxparamid, 4) : 0; \ + (char7)[5] = (char7)[4] ? HFX_CHAR_ID(hfxparamid, 5) : 0; \ + (char7)[6] = 0 + +HFX_INLINE HFXParamID HFX_PARAM_ENCODE_VA(char c1, char c2=0, char c3=0, char c4=0, char c5=0, char c6=0) +{ + return HFX_PARAM_ENCODE_6(c1,c2,c3,c4,c5,c6); +} + +#if HFX_MSVC > 7 +//max of 6! +#define HFX_PARAM_ENCODE(...) HFX_PARAM_ENCODE_VA(__VA_ARGS__) +#else +#define HFX_PARAM_ENCODE HFX_PARAM_ENCODE_VA +#endif + + +#define HFX_PARAM_ENCODE_4(c1,c2,c3,c4) HFX_PARAM_ENCODE_6(c1,c2,c3,c4,0,0) + +#define HFX_5BIT_MASK ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4)) + +#define HFX_MASK_ID(paramid, index)((paramid>>(index*5)) & (HFX_5BIT_MASK)) + +#define HFX_CHAR_ID(paramid, index) \ + (HFX_MASK_ID(paramid,index)?HFX_MASK_ID(paramid,index)+'^':0) + +// usage : char hfxParamText[] = HFX_PARAMETER_DECODE(hfxParamID); +#define HFX_PARAM_DECODE(hfxparam) { \ + HFX_CHAR_ID(hfxparam,0), \ + HFX_CHAR_ID(hfxparam,1), \ + HFX_CHAR_ID(hfxparam,2), \ + HFX_CHAR_ID(hfxparam,3), \ + HFX_CHAR_ID(hfxparam,4), \ + HFX_CHAR_ID(hfxparam,5),0} + + +enum HFXParamType +{ + HFXPARAM_NULL = 0, + HFXPARAM_INT = 'i', + HFXPARAM_FLOAT = 'f', + HFXPARAM_DOUBLE = 'd', + HFXPARAM_BOOL = 'b', + HFXPARAM_INT_ARRAY = 'I', + HFXPARAM_FLOAT_ARRAY = 'F', + HFXPARAM_DOUBLE_ARRAY = 'D', + HFXPARAM_BOOL_ARRAY = 'B', +}; + +typedef unsigned char HFXPARAM; + +enum HFXArray +{ + HFXARRAY_NOTARRAY=0, + HFXARRAY_COPY=1,// + HFXARRAY_INDEX=2, +}; +typedef unsigned char HFXARRAY; +typedef void *HFXVarValue; +struct HFX_PURE_INTERFACE IHapticEffectParamGroup +{ + +#ifndef HFX_NO_PARAMETER_CLASS_MACROS +// declare this inside user implementated parametergroup class definitions. +#define HFX_PARAMETER_GROUP(classname, baseclass, defaultEffect) \ + typedef classname ParameterGroup; \ + typedef baseclass SuperGroup; \ + typedef defaultEffect EffectClass; \ + using SuperGroup::SetVar; \ + using SuperGroup::GetVar; \ + using SuperGroup::SetVarFloat; \ + using SuperGroup::SetVarInt; \ + using SuperGroup::SetVarDouble; \ + using SuperGroup::GetVarBool; \ + using SuperGroup::GetVarFloat; \ + using SuperGroup::GetVarInt; \ + using SuperGroup::GetVarDouble; + +#define HFX_PARAMETER_ID(name, type) \ + static const HFXParamID ID_##name; \ + static const char * const ID_##name##_String; +// declare this inside user implementated parametergroup class definitions +// for each variable you want to be accessible through +// parameter filetypes or set/get functions. These macros will make the variable +// you specify. +// specify a seperate membername for readability. +// REMEMBER: name should be no longer than 6 letters, membername can be as long as you want. +#define HFX_PARAMETER_FLOAT(name, membername) \ + HFX_PARAMETER_ID(float_##name); \ + union{float name; float m_fl##name; float membername;}; \ + static const float ID_float_##name##_Default; + +#define HFX_PARAMETER_DOUBLE(name, membername) \ + HFX_PARAMETER_ID(double_##name); \ + union{double name; double m_dbl##name; double membername;}; \ + static const bool ID_double_##name##_Default + +#define HFX_PARAMETER_BOOL(name, membername) \ + HFX_PARAMETER_ID(bool_##name); \ + union{bool name:1; bool m_b##name:1; bool membername:1;}; \ + static const bool ID_bool_##name##_Default; + +#define HFX_PARAMETER_INT(name, membername) \ + HFX_PARAMETER_ID(int_##name); \ + union{int name; int m_i##name; int membername;}; \ + static const int ID_int_##name##_Default; + +#define HFX_PARAMETER_FLOAT_ARRAY(size, name, membername) \ + HFX_PARAMETER_ID(float##size##_##name); \ + union{float name; float m_fl##size##name; float membername;}; \ + static const float ID_float##size##_##name##_Default[size]; + +#define HFX_PARAMETER_DOUBLE_ARRAY(size, name, membername) \ + HFX_PARAMETER_ID(double##size##_##name); \ + union{double name[size]; double m_dbl##size##name[size]; double membername[size];}; \ + static const bool ID_double##size##_##name##_Default[size]; + +#define HFX_PARAMETER_BOOL_ARRAY(size, name, membername) \ + HFX_PARAMETER_ID(bool##size##_##name); \ + union{bool name[size]; bool m_b##size##name[size]; bool membername[size];}; \ + static const bool ID_bool##size##_##name##_Default[size]; + +#define HFX_PARAMETER_INT_ARRAY(size, name, membername) \ + HFX_PARAMETER_ID(int##size##_##name); \ + union{int name[size]; int m_i##name[size]; int membername[size];}; \ + static const int ID_int##size##_##name##_Default; +#endif + //virtual bool RunSetCommand( char *cmd ) = 0; + //virtual HFXEffectID StandardEffectName() const = 0; + + // ACTUAL OVERRIDES! + virtual bool SetVar(const HFXParamID id, void *value, HFXParamType t, + HFXARRAY settype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0, bool allowMake=false) = 0; + + virtual bool GetVar(const HFXParamID id, void *value, HFXParamType t, + HFXARRAY gettype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0 )const = 0; + +#ifndef HFX_NO_OVERLOADED_PARAMETER + + HFX_INLINE bool SetVarByName(const char *name, HFXVarValue value, HFXParamType t, + bool allowMake ) + {return SetVar(HFX_PARAM_ENCODE_STRING(name), value, t, HFXARRAY_NOTARRAY, 0, allowMake);} + + HFX_INLINE bool SetVar(const HFXParamID name, HFXVarValue value, HFXParamType t, + bool allowMake ) + {return SetVar(name, value, t, HFXARRAY_NOTARRAY, 0, allowMake);} + + HFX_INLINE bool SetVarByName(const char *name, HFXVarValue value, HFXParamType t, + HFXARRAY settype, unsigned int indexORcount, bool allowMake ) + {return SetVar(HFX_PARAM_ENCODE_STRING(name), value, t, settype, indexORcount, allowMake);} + + HFX_INLINE bool SetVarByName(const char *name, const double value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE, allowMake);} + HFX_INLINE bool SetVar(const HFXParamID name, const double value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE, allowMake);} + HFX_INLINE bool SetVarByName(const char *name, const bool value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL, allowMake);} + HFX_INLINE bool SetVar(const HFXParamID name, const bool value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL, allowMake);} + HFX_INLINE bool SetVarByName(const char *name, const float value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT, allowMake);} + HFX_INLINE bool SetVar(const HFXParamID name, const float value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT, allowMake);} + HFX_INLINE bool SetVarByName(const char *name, const int value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT, allowMake);} + HFX_INLINE bool SetVar(const HFXParamID name, const int value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_INT, allowMake);} + + HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const double *value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const double *value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const bool *value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const bool *value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const float *value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const float *value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const int *value, bool allowMake=false) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const int *value, bool allowMake=false) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);} + + template<typename T, int S> + HFX_INLINE bool SetVarTypeArrayByName(const char *name, const T (value)[S], bool allowMake = false) + {return SetVarArrayByName(name, S, (const T*)value, allowMake);} + + template<typename T, int S> + HFX_INLINE bool SetVarTypeArray(const HFXParamID name, const T (value)[S], bool allowMake = false) + {return SetVarArray(name, S, (const T*)value, allowMake);} + + HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const double value) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const double value) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const bool value) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const bool value) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const float value) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const float value) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const int value) + {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const int value) + {return SetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);} + + HFX_INLINE bool GetVarByName(const char *name, void *value, HFXParamType t, + HFXARRAY gettype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0 )const + {return GetVar(HFX_PARAM_ENCODE_STRING(name), value, t, gettype, indexORcount);} + + HFX_INLINE bool GetVarByName(const char *name, float &value )const + {return GetVarByName(name, (void*)&value, HFXPARAM_FLOAT);} + HFX_INLINE bool GetVar( const HFXParamID name, float &value )const + {return GetVar(name, (void*)&value, HFXPARAM_FLOAT);} + HFX_INLINE bool GetVarByName(const char *name, double &value )const + {return GetVarByName(name, (void*)&value, HFXPARAM_DOUBLE);} + HFX_INLINE bool GetVar( const HFXParamID name, double &value )const + {return GetVar(name, (void*)&value, HFXPARAM_DOUBLE);} + HFX_INLINE bool GetVarByName(const char *name, int &value )const + {return GetVarByName(name, (void*)&value, HFXPARAM_INT);} + HFX_INLINE bool GetVar( const HFXParamID name, int &value )const + {return GetVar(name, (void*)&value, HFXPARAM_INT);} + HFX_INLINE bool GetVarByName(const char *name, bool &value )const + {return GetVarByName(name, (void*)&value, HFXPARAM_BOOL);} + HFX_INLINE bool GetVar( const HFXParamID name, bool &value )const + {return GetVar(name, (void*)&value, HFXPARAM_BOOL);} + + HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, float &value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex);} + HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, float &value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex);} + HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, double &value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex);} + HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, double &value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex);} + HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, bool &value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex);} + HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, bool &value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex);} + HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, int &value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex);} + HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, int &value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex);} + + + HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, int *&value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize);} + HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, float *&value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize);} + HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, double *&value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize);} + HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, bool *&value)const + {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize);} + + HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, float *&value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize);} + HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, double *&value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize);} + HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, bool *&value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize);} + HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, int *&value)const + {return GetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize);} + + template<typename T, int S> + HFX_INLINE bool GetVarTypeArrayByName(const char *name, T (value)[S])const + {return GetVarArrayByName(name, S, (T*&)value);} + + template<typename T, int S> + HFX_INLINE bool GetVarTypeArray(const HFXParamID name, T (value)[S])const + {return GetVarArray(name, S, (T*&)value);} + + //strict access start. (ensures type is set) use these for typing or parsing. + HFX_INLINE bool SetVarFloatByName(const char *name, const float value, bool allowMake=false) + { return SetVarByName(name, value, allowMake); } + HFX_INLINE bool SetVarFloat(const HFXParamID name, const float value, bool allowMake=false) + { return SetVar(name, value, allowMake); } + HFX_INLINE bool SetVarDoubleByName(const char *name, const double value, bool allowMake=false) + { return SetVarByName(name, value, allowMake); } + HFX_INLINE bool SetVarDouble(const HFXParamID name, const double value, bool allowMake=false) + { return SetVar(name, value, allowMake); } + HFX_INLINE bool SetVarIntByName(const char *name, const int value, bool allowMake=false) + { return SetVarByName(name, value, allowMake); } + HFX_INLINE bool SetVarInt(const HFXParamID name, const int value, bool allowMake=false) + { return SetVar(name, value, allowMake); } + HFX_INLINE bool SetVarBoolByName(const char *name, const bool value, bool allowMake=false) + { return SetVarByName(name, value, allowMake); } + HFX_INLINE bool SetVarBool(const HFXParamID name, const bool value, bool allowMake=false) + { return SetVar(name, value, allowMake); } + + + HFX_INLINE bool SetVarDoubleArrayByName(const char * name, unsigned int size, const double *value, bool allowMake=false) + { return SetVarArrayByName(name, size, value, allowMake); } + HFX_INLINE bool SetVarDoubleArray(const HFXParamID name, unsigned int size, const double *value, bool allowMake=false) + { return SetVarArray(name, size, value, allowMake); } + HFX_INLINE bool SetVarFloatArrayByName(const char * name, unsigned int size, const float *value, bool allowMake=false) + { return SetVarArrayByName(name, size, value, allowMake); } + HFX_INLINE bool SetVarFloatArray(const HFXParamID name, unsigned int size, const float *value, bool allowMake=false) + { return SetVarArray(name, size, value, allowMake); } + HFX_INLINE bool SetVarIntArrayByName(const char * name, unsigned int size, const int *value, bool allowMake=false) + { return SetVarArrayByName(name, size, value, allowMake); } + HFX_INLINE bool SetVarIntArray(const HFXParamID name, unsigned int size, const int *value, bool allowMake=false) + { return SetVarArray(name, size, value, allowMake); } + HFX_INLINE bool SetVarBoolArrayByName(const char * name, unsigned int size, const bool *value, bool allowMake=false) + { return SetVarArrayByName(name, size, value, allowMake); } + HFX_INLINE bool SetVarBoolArray(const HFXParamID name, unsigned int size, const bool *value, bool allowMake=false) + { return SetVarArray(name, size, value, allowMake); } + + HFX_INLINE bool SetVarFloatElementByName(const char * name, unsigned int index, const float value) + { return SetVarElementByName(name, index, value); } + HFX_INLINE bool SetVarFloatElement(const HFXParamID name, unsigned int index, const float value) + { return SetVarElement(name, index, value); } + HFX_INLINE bool SetVarIntElementByName(const char * name, unsigned int index, const int value) + { return SetVarElementByName(name, index, value); } + HFX_INLINE bool SetVarIntElement(const HFXParamID name, unsigned int index, const int value) + { return SetVarElement(name, index, value); } + HFX_INLINE bool SetVarBoolElementByName(const char * name, unsigned int index, const bool value) + { return SetVarElementByName(name, index, value); } + HFX_INLINE bool SetVarBoolElement(const HFXParamID name, unsigned int index, const bool value) + { return SetVarElement(name, index, value); } + HFX_INLINE bool SetVarDoubleElementByName(const char * name, unsigned int index, const double value) + { return SetVarElementByName(name, index, value); } + HFX_INLINE bool SetVarDoubleElement(const HFXParamID name, unsigned int index, const double value) + { return SetVarElement(name, index, value); } + + HFX_INLINE bool SetVarDoubleArrayByFloatArray(const HFXParamID name, unsigned int size, const float *value, bool allowMake=false) + { + double *__d_ = new double[size]; + for(unsigned int i=0;i!=size;i++) + __d_[i]=(double)value[i]; + bool retval; + retval = SetVarDoubleArray(name, size, __d_, allowMake); + delete [] __d_; + return retval; + } + HFX_INLINE bool SetVarDoubleArrayByFloatArrayByName(const char *name, unsigned int size, const float *value, bool allowMake=false) + { return SetVarDoubleArrayByFloatArray(HFX_PARAM_ENCODE_STRING(name),size,value,allowMake); } + + HFX_INLINE bool GetVarFloatByName(const char *name, float &value)const + { return GetVarByName(name, value); } + HFX_INLINE bool GetVarDoubleByName(const char *name, double &value)const + { return GetVarByName(name, value); } + HFX_INLINE bool GetVarIntByName(const char *name, int &value)const + { return GetVarByName(name, value); } + HFX_INLINE bool GetVarBoolByName(const char *name, bool &value)const + { return GetVarByName(name, value); } + + HFX_INLINE bool GetVarFloatElementByName(const char *name, unsigned int index, float &value)const + { return GetVarElementByName(name, index, value); } + HFX_INLINE bool GetVarDoubleElementByName(const char *name, unsigned int index, double &value)const + { return GetVarElementByName(name, index, value); } + HFX_INLINE bool GetVarIntElementByName(const char *name, unsigned int index, int &value)const + { return GetVarElementByName(name, index, value); } + HFX_INLINE bool GetVarBoolElementByName(const char *name, unsigned int index, bool &value)const + { return GetVarElementByName(name, index, value); } + + HFX_INLINE bool GetVarFloatArrayByName(const char *name, unsigned int size, float *&value)const + { return GetVarArrayByName(name, size, value); } + HFX_INLINE bool GetVarDoubleArrayByName(const char *name, unsigned int size, double *&value)const + { return GetVarArrayByName(name, size, value); } + HFX_INLINE bool GetVarIntArrayByName(const char *name, unsigned int size, int *&value)const + { return GetVarArrayByName(name, size, value); } + HFX_INLINE bool GetVarBoolArrayByName(const char *name, unsigned int size, bool *&value)const + { return GetVarArrayByName(name, size, value); } + + HFX_INLINE bool GetVarFloat(const HFXParamID name, float &value)const + { return GetVar(name, value); } + HFX_INLINE bool GetVarDouble(const HFXParamID name, double &value)const + { return GetVar(name, value); } + HFX_INLINE bool GetVarInt(const HFXParamID name, int &value)const + { return GetVar(name, value); } + HFX_INLINE bool GetVarBool(const HFXParamID name, bool &value)const + { return GetVar(name, value); } + + HFX_INLINE bool GetVarFloatElement(const HFXParamID name, unsigned int index, float &value)const + { return GetVarElement(name, index, value); } + HFX_INLINE bool GetVarDoubleElement(const HFXParamID name, unsigned int index, double &value)const + { return GetVarElement(name, index, value); } + HFX_INLINE bool GetVarIntElement(const HFXParamID name, unsigned int index, int &value)const + { return GetVarElement(name, index, value); } + HFX_INLINE bool GetVarBoolElement(const HFXParamID name, unsigned int index, bool &value)const + { return GetVarElement(name, index, value); } + + HFX_INLINE bool GetVarFloatArray(const HFXParamID name, unsigned int size, float *&value)const + { return GetVarArray(name, size, value); } + HFX_INLINE bool GetVarDoubleArray(const HFXParamID name, unsigned int size, double *&value)const + { return GetVarArray(name, size, value); } + HFX_INLINE bool GetVarIntArray(const HFXParamID name, unsigned int size, int *&value)const + { return GetVarArray(name, size, value); } + HFX_INLINE bool GetVarBoolArray(const HFXParamID name, unsigned int size, bool *&value)const + { return GetVarArray(name, size, value); } + + HFX_INLINE bool GetVarDoubleArrayByFloatArray(const HFXParamID name, unsigned int size, float *&value) const + { + double *__d_ = new double[size]; + for(unsigned int i=0;i!=size;i++) + __d_[i]=(double)value[i]; + bool retval; + if(retval = GetVarDoubleArray(name, size, __d_)) + for(unsigned int i = 0;i!=size;i++) + value[i]=(float)__d_[i]; + delete [] __d_; + return retval; + } + HFX_INLINE bool GetVarDoubleArrayByFloatArrayByName(const char *name, unsigned int size, float *&value) const + { return GetVarDoubleArrayByFloatArray(HFX_PARAM_ENCODE_STRING(name),size,value); } + + // util helpers + // Vec3 and Vec3f + HFX_INLINE bool SetVarVec3ByName(const char *name, const double *hfxVect3, bool bAllowMake=false) + {return SetVarDoubleArrayByName(name, 3, hfxVect3, bAllowMake);} + HFX_INLINE bool SetVarVec3(const HFXParamID name, const double *hfxVect3, bool bAllowMake=false) + {return SetVarDoubleArray(name, 3, hfxVect3, bAllowMake);} + HFX_INLINE bool GetVarVec3ByName(const char *name, double *&hfxVect3) const + {return GetVarDoubleArrayByName(name, 3, hfxVect3);} + HFX_INLINE bool GetVarVec3(const HFXParamID name, double *&hfxVect3) const + {return GetVarDoubleArray(name, 3, hfxVect3);} + + HFX_INLINE bool SetVarVec3fByName(const char *name, const float *hfxVect3f, bool bAllowMake=false) + {return SetVarFloatArrayByName(name, 3, hfxVect3f, bAllowMake);} + HFX_INLINE bool SetVarVec3f(const HFXParamID name, const float *hfxVect3f, bool bAllowMake=false) + {return SetVarFloatArray(name, 3, hfxVect3f, bAllowMake);} + HFX_INLINE bool GetVarVec3fByName(const char *name, float *&hfxVect3f) const + {return GetVarFloatArrayByName(name, 3, hfxVect3f);} + HFX_INLINE bool GetVarVec3f(const HFXParamID name, float *&hfxVect3f) const + {return GetVarFloatArray(name, 3, hfxVect3f);} + //strict access end. +#endif +/* + virtual bool SetVar(HFXParamID id, const char *value, HFXParamType t, + HFXARRAY settype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0) = 0; + + virtual bool GetVar(HFXParamID id, const char *value, HFXParamType t, + HFXARRAY gettype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0 )const = 0; +*/ + virtual class IStack *GetDefaultStack() const=0; + virtual void SetDefaultStack(class IStack *stack)=0; + + virtual bool Copy(IHapticEffectParamGroup *&group) const=0; + + virtual HFXEffectID StandardEffectID() const=0; + virtual void ChangeStandardEffectID(const HFXEffectID type)=0; + // creation + virtual bool CreateStandardEffect( IHFXEffect *&pHandle, class IStack *createOnStack=0, const char *customName=0 )=0; + HFX_INLINE bool CreateStandardEffect( IStack *createOnStack ) + { + return CreateStandardEffect(hfxNoHandle, createOnStack, 0); + } + template<typename T> + HFX_INLINE bool CreateStandardEffect( T *&pHandle, class IStack *createOnStack=0, const char *customName=0) + { + return CreateStandardEffect((IHFXEffect *&)pHandle, createOnStack, customName); + } + HFX_INLINE HFXParamType GetVarTypeByName(const char *param, unsigned int *arraysize=0) const{ return GetVarType(HFX_PARAM_ENCODE_STRING(param), arraysize); } + virtual HFXParamType GetVarType(const HFXParamID param, unsigned int *arraysize=0) const=0; + +}; +typedef IHapticEffectParamGroup IHFXParamGroup; + +#define HFX_PARAMETER_INIT(classname, type, name, defaultvalue) \ + const char * const classname::ID_##type##name##_String = #name; \ + const HFXParamID classname::ID_##type##name = HFX_PARAM_ENCODE_STRING(classname::ID_##type##name##_String); \ + const type classname::ID_##type##name##_Default = defaultvalue; + +typedef void (*HFXPGCreate_t)(IHFXParamGroup*&ptr); +typedef void (*HFXPGDestroy_t)(IHFXParamGroup*&ptr); + +template<typename T> +void HFXDefaultAllocateParameterGroup(IHFXParamGroup *&ptr){ptr = new T;}; + +template<typename T> +void HFXDefaultDeallocateParameterGroup(IHFXParamGroup *&ptr){if(!ptr)return; delete ((T*)ptr); ptr=0;}; + +#endif +
\ No newline at end of file diff --git a/common/ihfx/ihfxeffect.h b/common/ihfx/ihfxeffect.h new file mode 100644 index 0000000..002b2ca --- /dev/null +++ b/common/ihfx/ihfxeffect.h @@ -0,0 +1,327 @@ + +#ifndef IHFXEFFECT_H_ +#define IHFXEFFECT_H_ +#include ".\\HFXConfig.h" +#include ".\\IHFXParam.h" + +struct IHapticEffectParamGroup; +typedef IHapticEffectParamGroup IHFXParamGroup; +class IProcessor; +typedef IProcessor IHFXProcessor; +class IStack; +typedef IStack IHFXStack; +enum HFXStateBits +{ + // when a state variable is made it uses the below value + HFXSTATE_INITIAL =0, + // explicite pause + HFXSTATE_PAUSE =(1<<0), + // explicite mute + HFXSTATE_MUTE =(1<<1), + // the effect has gone into its exit phase. + HFXSTATE_EXITING =(1<<2), + HFXSTATE_WANT_SYNC =(1<<3), + HFXSTATE_CLIENT_ONLY =4, + //everything below will be uncontrolled by servo + HFXSTATE_WANT_UPDATE =(1<<HFXSTATE_CLIENT_ONLY), + HFXSTATE_RUNNING =(1<<(HFXSTATE_CLIENT_ONLY+1)), + HFXSTATE_HAULT =(1<<(HFXSTATE_CLIENT_ONLY+2)), + HFXSTATE_HOLDING_EFFECT =(1<<(HFXSTATE_CLIENT_ONLY+3)), + HFXSTATE_COUNT =8, + // number of state bits before non servo controlled bits +}; +typedef unsigned __int8 HFXSTATE; +typedef HFXSTATE HFXStateStorage; + +#if WIN64 +typedef const HFXStateStorage &HFXStateTransfer; +#else +typedef const HFXStateStorage HFXStateTransfer; +#endif + +// utility union, takes up same memory as a flagset but gives you +// inline operators and helper functions for state flags +union HFX_ALIGN(8) HFXStateFlags +{ +public: + //default constructor + HFX_INLINE HFXStateFlags(){}; + + //copy constructor + HFX_INLINE HFXStateFlags(const HFXStateFlags ©) : Storage(copy.Storage){}; + + HFX_INLINE HFXStateFlags(HFXStateStorage flags) : Storage(flags){}; + + HFX_INLINE HFXStateFlags( + bool bRunning, bool bPaused, bool bMuted, bool bHaulted, bool bExiting + ) : Storage((bRunning ? HFXSTATE_RUNNING : 0)| + (bPaused ? HFXSTATE_PAUSE : 0)| + (bMuted ? HFXSTATE_MUTE : 0)| + (bHaulted ? HFXSTATE_HAULT : 0)| + (bExiting ? HFXSTATE_EXITING : 0) ) + {}; + // actual flags. (shared memory) + HFXStateStorage Storage; + // flags in boolean form. (shared memory) + struct { + bool Running:1; + bool Paused:1; + bool Muted:1; + bool Haulted:1; + bool Exiting:1; + }; + // flags in bool group ( for -> operator ) + struct HFXStateFlagGroup{ + bool Running:1; + bool Paused:1; + bool Muted:1; + bool Haulted:1; + bool Exiting:1; + }Flags; + + // type cast operators to flagstorage type + HFX_INLINE operator HFXStateStorage &(){return Storage;} + HFX_INLINE operator const HFXStateStorage &()const{return Storage;} + HFX_INLINE operator HFXStateStorage (){return Storage;} + HFX_INLINE operator const HFXStateStorage ()const{return Storage;} + + // at operator to get reference of storage. + HFX_INLINE HFXStateStorage &operator *(){return Storage;}; + HFX_INLINE const HFXStateStorage &operator *()const{return Storage;}; + + // bool operator, to see if there are any flags set. + HFX_INLINE bool operator()(int bit){return (Storage & bit)!=0;}; + + // -> operator to get boolean access flags quickly. + HFX_INLINE HFXStateFlagGroup *operator ->(){return &Flags;}; + HFX_INLINE const HFXStateFlagGroup *operator ->()const{return &Flags;}; + + HFX_INLINE HFXStateStorage *operator &(){return &Storage;}; + HFX_INLINE const HFXStateStorage *operator &()const{return &Storage;}; + + HFX_INLINE HFXStateStorage &operator =(HFXStateTransfer state){Storage = state; return Storage;} + HFX_INLINE HFXStateStorage &operator |=(HFXStateTransfer state){Storage |= state; return Storage;} + HFX_INLINE HFXStateStorage &operator &=(HFXStateTransfer state){Storage &= state; return Storage;} + HFX_INLINE HFXStateStorage &operator ^=(HFXStateTransfer state){Storage |= state; return Storage;} + HFX_INLINE HFXStateStorage operator ~()const{return ~Storage;} + HFX_INLINE HFXStateStorage operator |(HFXStateTransfer state){return (Storage|state);} + HFX_INLINE HFXStateStorage operator &(HFXStateTransfer state){return (Storage&state);} + HFX_INLINE HFXStateStorage operator ^(HFXStateTransfer state){return (Storage^state);} + HFX_INLINE bool operator ==(HFXStateTransfer state){return (Storage==state);} + HFX_INLINE bool operator !=(HFXStateTransfer state){return (Storage!=state);} + HFX_INLINE bool operator !(){return (Storage==0);} + HFX_INLINE operator bool(){return (Storage!=0);} + HFX_INLINE HFXStateFlags *UtilPointer(){return this;}; + HFX_INLINE const HFXStateFlags *UtilPointer()const{return this;}; + HFX_INLINE HFXStateFlags &Util(){return *this;}; + HFX_INLINE const HFXStateFlags &Util()const{return *this;}; +}; + +enum HFXNeeds +{ + //effect has a application thread time sync + HFXNEED_SYNC =(1 << 0), + //effect has a servo thread time update + HFXNEED_PROCESS =(1 << 1), + //effect takes parameters + HFXNEED_SET =(1 << 2), + //effect needs stack access + HFXNEED_STACK =(1 << 3), + //device slots. if you need a device you need a stack. + HFXNEED_DEVICE1 =(1 << 4), + HFXNEED_DEVICE2 =(1 << 5), + HFXNEED_DEVICE3 =(1 << 6), + HFXNEED_DEVICE4 =(1 << 7), + HFXNEED_DEVICE5 =(1 << 8), + HFXNEED_DEVICE6 =(1 << 9), + HFXNEED_DEVICE7 =(1 << 10), + HFXNEED_DEVICE8 =(1 << 11), + //ability to create/destroy sub effects + HFXNEED_MANAGE =(1 << 12), + //effect needs to know how long its been running. + HFXNEED_RUNTIME =(1 << 13), + //effect needs to know how long its been since the last time its processed a function. + HFXNEED_FRAMETIME =(1 << 14), + //effect needs a fixed time sent to its framtime + HFXNEED_FIXEDTIME =(1 << 15), + //effect has a init function + HFXNEED_INSTANCE =(1 << 16), + //effect needs owning stack's parent access + HFXNEED_PARENT =(1 << 17), + //effect is self deleting + HFXNEED_REMOVE =(1 << 18), + //effect does not give handles. these effects need to be self deleting + HFXNEED_ENCAPSULATED =(1 << 19), + + HFXNEED_EXIT =(1 << 20), + + //state change inform flags + HFXNEED_STATE_INFORM =(1 << 21), + HFXNEED_RUNNING_INFORM =(1 << 22), + HFXNEED_PAUSE_INFORM =(1 << 23), + HFXNEED_HAULT_INFORM =(1 << 24), + HFXNEED_MUTE_INFORM =(1 << 25), + HFXNEED_EXITING_INFORM =(1 << 26), + + // USE THE BELOW FLAGS TO DECLARE FEATURES TO A EFFECT CLASS WHEN REGISTERING + HFXNEED_DECL_SYNC =(HFXNEED_SYNC), + HFXNEED_DECL_PROCESS =(HFXNEED_PROCESS), + HFXNEED_DECL_STACK =(HFXNEED_STACK), + HFXNEED_DECL_DEVICE1 =(HFXNEED_DEVICE1|HFXNEED_DECL_STACK), + HFXNEED_DECL_DEVICE2 =(HFXNEED_DEVICE2|HFXNEED_DECL_STACK), + HFXNEED_DECL_DEVICE3 =(HFXNEED_DEVICE3|HFXNEED_DECL_STACK), + HFXNEED_DECL_DEVICE4 =(HFXNEED_DEVICE4|HFXNEED_DECL_STACK), + HFXNEED_DECL_DEVICE5 =(HFXNEED_DEVICE5|HFXNEED_DECL_STACK), + HFXNEED_DECL_DEVICE6 =(HFXNEED_DEVICE6|HFXNEED_DECL_STACK), + HFXNEED_DECL_DEVICE7 =(HFXNEED_DEVICE7|HFXNEED_DECL_STACK), + HFXNEED_DECL_DEVICE8 =(HFXNEED_DEVICE8|HFXNEED_DECL_STACK), + HFXNEED_DECL_RUNTIME =(HFXNEED_RUNTIME), + HFXNEED_DECL_FRAMETIME =(HFXNEED_FRAMETIME), + // there is no decl for HFXNEED_FIXEDTIME as it is pointless without + // a runtime or frametime decl. + HFXNEED_DECL_FIXEDFRAME =(HFXNEED_FRAMETIME|HFXNEED_FIXEDTIME), + HFXNEED_DECL_FIXEDRUNTIME =(HFXNEED_DECL_RUNTIME|HFXNEED_FIXEDTIME), + HFXNEED_DECL_MANAGE =(HFXNEED_DECL_FRAMETIME|HFXNEED_DECL_STACK), + HFXNEED_DECL_REMOVE =(HFXNEED_REMOVE), + HFXNEED_DECL_ENCAPSULATED =(HFXNEED_ENCAPSULATED|HFXNEED_DECL_REMOVE), + HFXNEED_DECL_PARENT =(HFXNEED_PARENT), + HFXNEED_DECL_INSTANCE =(HFXNEED_INSTANCE), + HFXNEED_DECL_SET =(HFXNEED_SET), + // there is no HFXNEED_STATE_INFORM declare as it would be pointless without a + // declaration of specific informs + HFXNEED_DECL_RUNNING_INFORM =(HFXNEED_RUNNING_INFORM|HFXNEED_STATE_INFORM), + HFXNEED_DECL_PAUSE_INFORM =(HFXNEED_PAUSE_INFORM|HFXNEED_STATE_INFORM), + HFXNEED_DECL_MUTE_INFORM =(HFXNEED_MUTE_INFORM|HFXNEED_STATE_INFORM), + HFXNEED_DECL_EXITING_INFORM =(HFXNEED_EXITING_INFORM|HFXNEED_STATE_INFORM), + HFXNEED_DECL_HAULT_INFORM =(HFXNEED_HAULT_INFORM|HFXNEED_STATE_INFORM), + // only use this if you will actually be using all informs! + HFXNEED_DECL_TOTAL_INFORM =( HFXNEED_RUNNING_INFORM|HFXNEED_PAUSE_INFORM| + HFXNEED_MUTE_INFORM|HFXNEED_EXITING_INFORM| + HFXNEED_STATE_INFORM), + // INFORMATION FLAGS + HFXNEED_INFO_DEVICE =( HFXNEED_DEVICE1|HFXNEED_DEVICE2| + HFXNEED_DEVICE3|HFXNEED_DEVICE4| + HFXNEED_DEVICE5|HFXNEED_DEVICE6| + HFXNEED_DEVICE7|HFXNEED_DEVICE8), +}; + +#define HFXNEED_UTIL_COUNT_DEVICES(flags) \ + ( ( ( (flags) & HFXNEED_INFO_DEVICE ) != 0) ? ( \ + ( ( ( (flags) & HFXNEED_DEVICE1 ) != 0) ? 1 : 0 ) + \ + ( ( ( (flags) & HFXNEED_DEVICE2 ) != 0) ? 1 : 0 ) + \ + ( ( ( (flags) & HFXNEED_DEVICE3 ) != 0) ? 1 : 0 ) + \ + ( ( ( (flags) & HFXNEED_DEVICE4 ) != 0) ? 1 : 0 ) + \ + ( ( ( (flags) & HFXNEED_DEVICE5 ) != 0) ? 1 : 0 ) + \ + ( ( ( (flags) & HFXNEED_DEVICE6 ) != 0) ? 1 : 0 ) + \ + ( ( ( (flags) & HFXNEED_DEVICE7 ) != 0) ? 1 : 0 ) + \ + ( ( ( (flags) & HFXNEED_DEVICE8 ) != 0) ? 1 : 0 ) ) \ + : 0 ) + +typedef unsigned __int32 HFXNEED; + +#define HFX_XCHANGE 16 +#define HFX_YCHANGE 17 +#define HFX_ZCHANGE 18 + +enum HFXResult +{ + HFXRESULT_ERROR =-2, + HFXRESULT_FINISHED =-1, + HFXRESULT_CONTINUE =0, + // x axis was set + HFXRESULT_XCHANGED =(1 << HFX_XCHANGE), + // y axis was set + HFXRESULT_YCHANGED =(1 << HFX_YCHANGE), + // z axis was set + HFXRESULT_ZCHANGED =(1 << HFX_ZCHANGE), + // x and y axis was set + HFXRESULT_XYCHANGED =(HFXRESULT_XCHANGED|HFXRESULT_YCHANGED), + // x and z axis was set + HFXRESULT_XZCHANGED =(HFXRESULT_XCHANGED|HFXRESULT_ZCHANGED), + // y and z axis was set + HFXRESULT_YZCHANGED =(HFXRESULT_YCHANGED|HFXRESULT_ZCHANGED), + // x and y axis was set + HFXRESULT_YXCHANGED =HFXRESULT_XYCHANGED, + // x and z axis was set + HFXRESULT_ZXCHANGED =HFXRESULT_XZCHANGED, + // y and z axis was set + HFXRESULT_ZYCHANGED =HFXRESULT_YZCHANGED, + // x, y and z axis set + HFXRESULT_XYZCHANGED =(HFXRESULT_XCHANGED|HFXRESULT_YCHANGED|HFXRESULT_ZCHANGED), + HFXRESULT_CHANGED =HFXRESULT_XYZCHANGED, +}; + +typedef int HFXRESULT; + + +class HFX_PURE_INTERFACE IHapticEffect +{ +public: + // return false if you decide the processor given to you is not sufficient + // or any other reason the effect should not be made. + // !called one time only. before any other funciton calls. + // IF YOU WANT THIS TO BE CALLED YOU MUST REGISTER YOUR EFFECT WITH HFXNEED_DECL_INSTANCE + virtual bool Initialize(IHFXProcessor &processor)=0; + // called by the game thread and blocks the haptics thread so the game and haptics loop are safe inside. + // IF YOU WANT THIS TO BE CALLED YOU MUST REGISTER YOUR EFFECT WITH HFXNEED_DECL_SYNC + virtual HFXRESULT SyncOp(IHFXProcessor &processor)=0; + //called at haptic rate. should set the output parameter to the target output force. + // calculation should optimized and precise in here. + // IF YOU WANT THIS TO BE CALLED YOU MUST REGISTER YOUR EFFECT WITH HFXNEED_DECL_PROCESS + virtual HFXRESULT Update(IHFXProcessor &processor)=0; + //return true if parameters sent to you are sufficient. + virtual bool Set(IHFXProcessor &processor, IHFXParamGroup *parameter)=0; + //notification of state change. + // WILL ONLY BE CALLED IF YOU DECLARE YOUR EFFECT REGISTER WITH A _INFORM decl and will ONLY be called with those. + // note: state will be only one bit. for every bit changed on sync this function will be called. + virtual void OnStateChange(IHFXProcessor &processor, HFXSTATE state, bool flagged)=0; +}; +typedef IHapticEffect IHFXEffect; + +typedef void (*hfxFilterFunction)(double outvect[3]); +typedef void (*HFXCreate_t)(IHFXEffect*&ptr); +typedef void (*HFXDestroy_t)(IHFXEffect*&ptr); + +template<typename T> +void HFXDefaultAllocateEffect(IHFXEffect *&ptr){ptr = new T;}; + +template<typename T> +void HFXDefaultDeallocateEffect(IHFXEffect *&ptr){if(!ptr)return; delete ((T*)ptr); ptr=0;}; + +class IHapticsSystem; +typedef IHapticsSystem IHFXSystem; +class IDevice; +typedef IDevice IHFXDevice; +class IStack; +typedef IStack IHFXStack; + +// T == effect class +template<typename T> +inline HFXEffectID HFXDefaultRegisterEffect(IHFXSystem &hfxSystem, const char *tag, HFXNEED needs, IHFXParamGroup *defaults, HFXCreate_t specialCreate = HFXDefaultAllocateEffect<T>, HFXDestroy_t specialDestroy = HFXDefaultDeallocateEffect<T> ) +{ + hfxSystem.LogMessage((const int)1,"EFFECT REGISTERING! %s Size = %i \n", tag, sizeof(T)); + return hfxSystem.RegisterEffectClass( + tag, + specialCreate, + specialDestroy, + needs, + defaults); +}; + +// T == effect class +// P == parametergroup class +template<typename T, typename P> +inline HFXEffectID HFXDefaultRegisterEffect(IHFXSystem &hfxSystem, const char *tag, HFXNEED needs, HFXCreate_t specialCreate = 0, HFXDestroy_t specialDestroy = 0) +{ + P *pGroup = new P; + HFXEffectID retval=0; + if(pGroup->CopyDefaults(pGroup)) + { + retval = HFXDefaultRegisterEffect<T>(hfxSystem, tag, needs, pGroup, specialCreate, specialDestroy); + } + delete pGroup; + return retval; +}; + +#endif +
\ No newline at end of file diff --git a/common/ihfx/types/hfxvec3.h b/common/ihfx/types/hfxvec3.h new file mode 100644 index 0000000..be8bb8d --- /dev/null +++ b/common/ihfx/types/hfxvec3.h @@ -0,0 +1,306 @@ + + +#ifndef HFX_INTERNAL +struct HFX_vect3Base32 +{ + union + { + struct + { + float x; + float y; + float z; + }; + struct + { + float x; + float y; + float z; + } axis; + struct + { + float right; + float up; + float backward; + } direction; + struct + { + float pitch; + float yaw; + float roll; + } rotation; + struct + { + float wide; + float tall; + float deep; + } dimension; + float m[3]; + }; +}; +// 192 == 3 * 64 == 3 doubles +struct HFX_vect3Base64 +{ + union + { + struct + { + double x; + double y; + double z; + }; + struct + { + double x; + double y; + double z; + } axis; + struct + { + double right; + double up; + double backward; + } direction; + struct + { + double pitch; + double yaw; + double roll; + } rotation; + struct + { + double wide; + double tall; + double deep; + } dimension; + double m[3]; + }; +}; +#endif +#ifdef HFX_INTERNAL +struct hfxVec3internal +#endif +#ifndef HFX_INTERNAL +struct hfxVec3 +#endif + : public HFX_vect3Base64 +{ +#ifndef HFX_INTERNAL + HFX_INLINE HFX_EXPLICIT hfxVec3(const double &_x, const double &_y, const double &_z); + HFX_INLINE HFX_EXPLICIT hfxVec3(const double array_d[3] ); + HFX_INLINE hfxVec3(const hfxVec3 &_copy); +#ifdef HFX_ZERO_INIT + HFX_INLINE HFX_EXPLICIT hfxVec3(); +#endif HFX_ZERO_INIT + HFX_INLINE hfxVec3(); +#endif + + HFX_INLINE double &operator [](int i); + HFX_INLINE const double &operator[](int i) const; + + HFX_INLINE operator double *(); + HFX_INLINE operator const double *() const; + + HFX_INLINE hfxVec3 operator -() const; + + HFX_INLINE hfxVec3 operator -(const hfxVec3 &vect) const; + HFX_INLINE hfxVec3 &operator -=(const hfxVec3 &vect); + + HFX_INLINE hfxVec3 operator +(const hfxVec3 &vect) const; + HFX_INLINE hfxVec3 &operator +=(const hfxVec3 &vect); + + HFX_INLINE hfxVec3 operator *(const hfxVec3 &vect) const; + HFX_INLINE hfxVec3 operator *(const double &df) const; + //HFX_INLINE hfxVec3 operator *(const float f) const; + //HFX_INLINE hfxVec3 operator *(const int i){return ((*this)*((double)i));}; + + HFX_INLINE hfxVec3 operator /(const hfxVec3 &vect) const; + HFX_INLINE hfxVec3 operator /(const double &df) const; + //HFX_INLINE hfxVec3 operator /(const float f) const; + //HFX_INLINE hfxVec3 operator /(const int i){return ((*this)/((double)i));}; + + HFX_INLINE hfxVec3 &operator /=(const hfxVec3 &vect); + HFX_INLINE hfxVec3 &operator /=(const double &df); + //HFX_INLINE hfxVec3 &operator /=(const float f); + //HFX_INLINE hfxVec3 &operator /=(const int i){return ((*this)/=((double)i));}; + + HFX_INLINE hfxVec3 &operator *=(const hfxVec3 &vect); + HFX_INLINE hfxVec3 &operator *=(const double &df); + //HFX_INLINE hfxVec3 &operator *=(const float f); + //HFX_INLINE hfxVec3 &operator *=(const int i){return ((*this)*=((double)i));}; + HFX_INLINE hfxVec3 &operator =(const hfxVec3 &vect); + HFX_INLINE hfxVec3 &operator =(const double &all); + //HFX_INLINE hfxVec3 &operator =(const float all); + //HFX_INLINE hfxVec3 &operator =(const int i){return ((*this)=((double)i));} + + HFX_INLINE const double *operator *()const; + HFX_INLINE double *operator *(); + + HFX_INLINE hfxVec3 Cross(const hfxVec3 &vect) const; + HFX_INLINE double Dot( const hfxVec3 &vect ) const; + HFX_INLINE double Magnitude() const; + // get normalize + HFX_INLINE hfxVec3 Normalized() const; + // normalize in place + HFX_INLINE hfxVec3 &Normalize(); + HFX_INLINE bool IsValid() const; + HFX_INLINE bool IsNaN() const; +#ifdef HFX_INTERNAL + HFX_INLINE hfxVec3internal *GetVec3Pointer(){ return (this); }; + HFX_INLINE const hfxVec3internal *GetVec3Pointer()const{ return (this); }; + HFX_INLINE operator hfxVec3 &(){ return *(reinterpret_cast<hfxVec3*>(this)); } + HFX_INLINE operator const hfxVec3 &()const { return *(reinterpret_cast<const hfxVec3*>(this)); } +#endif +#ifndef HFX_PAT_DOESNT_KNOW + HFX_INLINE double Length() const; + HFX_INLINE hfxVec3 Normal() const; +#endif +}; +#ifndef HFX_INTERNAL +#ifndef HFX_NO_TYPEDEFS +typedef hfxVec3 Vect3; +#endif +struct hfxVec3F : public HFX_vect3Base32 +{ + HFX_INLINE hfxVec3F(const float _x, const float _y, const float _z); + HFX_INLINE hfxVec3F(const float array_f[3] ); + HFX_INLINE hfxVec3F(const hfxVec3F &_copy); + HFX_INLINE hfxVec3F(); + + HFX_INLINE float &operator [](int i); + HFX_INLINE const float &operator[](int i) const; + + HFX_INLINE operator float *(); + HFX_INLINE operator const float *() const; + + HFX_INLINE hfxVec3F operator -() const; + + HFX_INLINE hfxVec3F operator -(const hfxVec3F &vect) const; + HFX_INLINE hfxVec3F &operator -=(const hfxVec3F &vect); + + HFX_INLINE hfxVec3F operator +(const hfxVec3F &vect) const; + HFX_INLINE hfxVec3F &operator +=(const hfxVec3F &vect); + + HFX_INLINE hfxVec3F operator *(const hfxVec3F &vect) const; + HFX_INLINE hfxVec3F operator *(const float f) const; + //HFX_INLINE hfxVec3F operator *(const double &df) const; + //HFX_INLINE hfxVec3F operator *(const int i){return ((*this)*(double)i);}; + + HFX_INLINE hfxVec3F operator /(const hfxVec3F &vect) const; + HFX_INLINE hfxVec3F operator /(const float f) const; + //HFX_INLINE hfxVec3F operator /(const double &df) const; + //HFX_INLINE hfxVec3F operator /(const int i){return ((*this)/(double)i);}; + + HFX_INLINE hfxVec3F &operator /=(const hfxVec3F &vect); + HFX_INLINE hfxVec3F &operator /=(const float f); + //HFX_INLINE hfxVec3F &operator /=(const double &df); + //HFX_INLINE hfxVec3F &operator /=(const int i){return ((*this)/=(double)i);}; + + HFX_INLINE hfxVec3F &operator *=(const hfxVec3F &vect); + HFX_INLINE hfxVec3F &operator *=(const float f); + //HFX_INLINE hfxVec3F &operator *=(const double &df); + //HFX_INLINE hfxVec3F &operator *=(const int i){return ((*this)*=(double)i);}; + + HFX_INLINE hfxVec3F &operator =(const hfxVec3F &vect); + HFX_INLINE hfxVec3F &operator =(const float all); + //HFX_INLINE hfxVec3F &operator =(const double &all); + //HFX_INLINE hfxVec3F &operator =(const int i){return ((*this)=(double)i);} + + HFX_INLINE const float *operator *()const; + HFX_INLINE float *operator *(); + + HFX_INLINE hfxVec3F Cross(const hfxVec3F &vect) const; + HFX_INLINE float Dot( const hfxVec3F &vect ) const; + HFX_INLINE float Magnitude() const; + // get normalize + HFX_INLINE hfxVec3F Normalized() const; + // normalize in place + HFX_INLINE hfxVec3F &Normalize(); + HFX_INLINE bool IsValid() const; + HFX_INLINE bool IsNaN() const; +#ifndef HFX_PAT_DOESNT_KNOW + HFX_INLINE float Length() const; + HFX_INLINE hfxVec3F Normal() const; +#endif +}; + +struct _box3Base +{ + union + { + struct{ + HFX_vect3Base64 bound_min; + HFX_vect3Base64 bound_max; + }box; + HFX_vect3Base64 min_max[2]; + struct + { + double left; + double down; + double forward; + double right; + double up; + double backward; + }side; + double m[6]; + }; +}; +struct BoundingBox3 : public _box3Base +{ + inline BoundingBox3(const double &left=0, const double &down=0, const double &forward=0, + const double &right=0, const double &up=0, const double &backward=0) + { + side.left = left; + side.down = down; + side.forward = forward; + side.right = right; + side.up = up; + side.backward = backward; + } + inline BoundingBox3(const hfxVec3 &bMin, const hfxVec3 &bMax) + { + BoxMin() = bMin; + BoxMax() = bMax; + } + inline hfxVec3 &BoxMin(){return (hfxVec3&)box.bound_min;}; + inline const hfxVec3 &BoxMin() const {return (const hfxVec3&)box.bound_min;}; + inline hfxVec3 &BoxMax(){return (hfxVec3&)box.bound_max;}; + inline const hfxVec3 &BoxMax() const {return (const hfxVec3&)box.bound_max;}; + inline hfxVec3 Center() const { return (BoxMin() + BoxMax())/(double)2.0; }; + inline hfxVec3 Dimensions() const { return BoxMax() - BoxMin();}; + inline hfxVec3 SpaceBetweenCentered(const BoundingBox3 &other) const {return other.Dimensions() - Dimensions();}; + inline BoundingBox3 SpaceBetween(const BoundingBox3 &other) const {return other - *this;} + inline BoundingBox3 &SetDimensions(const hfxVec3 &dimm) { hfxVec3 cent = Center(); hfxVec3 dim = dimm/2.0; BoxMin() = cent - dim; BoxMax() = cent + dim; return *this; } + inline BoundingBox3 &SetCenter(const hfxVec3 ¢) { hfxVec3 dim = Dimensions(); BoxMin() = cent - dim; BoxMax() = cent + dim; return *this; } + inline operator hfxVec3 *(){return (hfxVec3*)min_max;}; + inline operator const hfxVec3 *() const {return (const hfxVec3*)min_max;}; + inline operator double *() {return m;}; + inline operator const double *() const {return m;}; + inline BoundingBox3 operator -(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() - vect, BoxMax() - vect ); } + inline BoundingBox3 operator +(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() + vect, BoxMax() + vect ); } + inline BoundingBox3 operator *(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() * vect, BoxMax() * vect ); } + inline BoundingBox3 operator /(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() / vect, BoxMax() / vect ); } + inline BoundingBox3 operator *(const double &df) const{ return BoundingBox3( BoxMin() * df, BoxMax() * df ); } + inline BoundingBox3 operator /(const double &df) const{ return BoundingBox3( BoxMin() / df, BoxMax() / df ); } + inline BoundingBox3 operator -(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() - bbox.BoxMin(), BoxMax() - bbox.BoxMax() ); } + inline BoundingBox3 operator +(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() + bbox.BoxMin(), BoxMax() + bbox.BoxMax() ); } + inline BoundingBox3 operator *(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() * bbox.BoxMin(), BoxMax() * bbox.BoxMax() ); } + inline BoundingBox3 operator /(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() / bbox.BoxMin(), BoxMax() / bbox.BoxMax() ); } + inline BoundingBox3 &operator =(const BoundingBox3 &bbox) { BoxMin() = bbox.BoxMin(); BoxMax() = bbox.BoxMax(); return *this; } + inline BoundingBox3 &operator -=(const hfxVec3 &vect){ BoxMin()-=vect; BoxMax()-=vect; return *this; } + inline BoundingBox3 &operator +=(const hfxVec3 &vect){ BoxMin()+=vect; BoxMax()+=vect; return *this; } + inline BoundingBox3 &operator *=(const hfxVec3 &vect){ BoxMin()*=vect; BoxMax()*=vect; return *this; } + inline BoundingBox3 &operator /=(const hfxVec3 &vect){ BoxMin()/=vect; BoxMax()/=vect; return *this; } + inline BoundingBox3 &operator *=(const double &df){ BoxMin()*=df; BoxMax()*=df; return *this; } + inline BoundingBox3 &operator /=(const double &df){ BoxMin()/=df; BoxMax()/=df; return *this; } + inline BoundingBox3 &operator -=(const BoundingBox3 &bbox){ BoxMin()-=bbox.BoxMin(); BoxMax()-=bbox.BoxMax(); return *this; } + inline BoundingBox3 &operator +=(const BoundingBox3 &bbox){ BoxMin()+=bbox.BoxMin(); BoxMax()+=bbox.BoxMax(); return *this; } + inline BoundingBox3 &operator *=(const BoundingBox3 &bbox){ BoxMin()*=bbox.BoxMin(); BoxMax()*=bbox.BoxMax(); return *this; } + inline BoundingBox3 &operator /=(const BoundingBox3 &bbox){ BoxMin()/=bbox.BoxMin(); BoxMax()/=bbox.BoxMax(); return *this; } +}; +#endif +#include "inl_hfxMath.h" +#ifdef HFX_INTERNAL +typedef ::hfxVec3 hfxVec3; +//VECTOR CLASS +#endif diff --git a/common/ihfx/types/inl_hfxMath.h b/common/ihfx/types/inl_hfxMath.h new file mode 100644 index 0000000..2a0b0bc --- /dev/null +++ b/common/ihfx/types/inl_hfxMath.h @@ -0,0 +1,141 @@ +#ifndef _INC_MATH +#include HFX_NO_MERGE(math.h) +#endif +#define HFXVEC3(other,oper)return HFXVEC3T(x##oper##other.x,y##oper##other.y,z##oper##other.z) +#define HFXVEC3F(other,oper) return HFXVEC3T(x##oper##other,y##oper##other,z##oper##other) +#ifndef HFX_INTERNAL +#define HFXVEC3SELF(other,oper)x##oper##other.x;y##oper##other.y;z##oper##other.z;return(*this) +#define HFXVEC3FSELF(other,oper) x##oper##other;y##oper##other;z##oper##other;return(*this) +#endif +#ifdef HFX_INTERNAL +#define HFXVEC3SELF(other,oper)x##oper##other.x;y##oper##other.y;z##oper##other.z;return *(reinterpret_cast<hfxVec3*>(this)) +#define HFXVEC3FSELF(other,oper) x##oper##other;y##oper##other;z##oper##other;return *(reinterpret_cast<hfxVec3*>(this)) +#endif +// 192 bit vect3 +#define HFXVEC3T hfxVec3 +#ifdef HFX_INTERNAL +#define HFXVEC3_DEFTYPE hfxVec3internal +#endif +#ifndef HFX_INTERNAL +#define HFXVEC3_DEFTYPE hfxVec3 +#ifdef HFX_ZERO_INIT +HFX_INLINE HFX_EXPLICIT hfxVec3::hfxVec3() +{ + HFX_MEMSET(m,0,sizeof(double)*3); +} +#endif +HFX_INLINE hfxVec3::hfxVec3() +{ + __assume(0); +} +HFX_INLINE hfxVec3::hfxVec3(const double &_x, const double &_y, const double &_z){x=_x;y=_y;z=_z;}; +HFX_INLINE hfxVec3::hfxVec3(const hfxVec3 &_copy){HFX_MEMCPY(m,_copy.m,sizeof(double)*3);}; +HFX_INLINE hfxVec3::hfxVec3(const double *array_d){HFX_MEMCPY(m,array_d,sizeof(double)*3);} +#endif + +HFX_INLINE bool HFXVEC3_DEFTYPE::IsValid()const{return(!IsNaN());} +HFX_INLINE bool HFXVEC3_DEFTYPE::IsNaN()const{return (x!=x||y!=y||z!=z);} + +HFX_INLINE double HFXVEC3_DEFTYPE::Magnitude()const{return(sqrt(x*x+y*y+z*z));} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::Normalized()const{hfxVec3 copy(m);return(copy.Normalize());} +#ifndef HFX_INTERNAL +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::Normalize(){double l=Magnitude();x/=l;y/=l;z/=l;return(*this);} +#endif +#ifdef HFX_INTERNAL +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::Normalize(){double l=Magnitude();x/=l;y/=l;z/=l;return(*(reinterpret_cast<hfxVec3*>(this)));} +#endif +#ifndef HFX_PAT_DOESNT_KNOW +HFX_INLINE double HFXVEC3_DEFTYPE::Length()const{return(Magnitude());}; +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::Normal()const{return Normalized();}; +#endif +HFX_INLINE double HFXVEC3_DEFTYPE::Dot( const hfxVec3 &v )const{return(x*v.x+y*v.y+z*v.z);} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::Cross(const hfxVec3 &v)const{return hfxVec3(x*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x);} + +HFX_INLINE const double &HFXVEC3_DEFTYPE::operator [](int i)const{return(m[i]);}; +HFX_INLINE double &HFXVEC3_DEFTYPE::operator [](int i){return(m[i]);}; +HFX_INLINE HFXVEC3_DEFTYPE::operator const double *() const{return(m);} +HFX_INLINE HFXVEC3_DEFTYPE::operator double *(){return(m);} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::operator -()const{return(hfxVec3(-x,-y,-z));} +HFX_INLINE double *HFXVEC3_DEFTYPE::operator *(){return(m);}; +HFX_INLINE const double *HFXVEC3_DEFTYPE::operator *()const{return(m);}; + +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::operator *(const hfxVec3 &v)const{HFXVEC3(v,*);} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::operator +(const hfxVec3 &v)const{HFXVEC3(v,+);} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::operator -(const hfxVec3 &v)const{HFXVEC3(v,-);} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::operator /(const hfxVec3 &v)const{HFXVEC3(v,/);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator =(const hfxVec3 &v){HFXVEC3SELF(v,=);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator *=(const hfxVec3 &v){HFXVEC3SELF(v,*=);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator +=(const hfxVec3 &v){HFXVEC3SELF(v,+=);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator -=(const hfxVec3 &v){HFXVEC3SELF(v,-=);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator /=(const hfxVec3 &v){HFXVEC3SELF(v,/=);} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::operator *(const double &d)const{HFXVEC3F(d,*);} +HFX_INLINE hfxVec3 HFXVEC3_DEFTYPE::operator /(const double &d)const{HFXVEC3F(d,/);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator *=(const double &d){HFXVEC3FSELF(d,*=);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator /=(const double &d){HFXVEC3FSELF(d,/=);} +//HFX_INLINE hfxVec3 hfxVec3::operator *(const float f)const{HFXVEC3F((double)f,*);} +//HFX_INLINE hfxVec3 hfxVec3::operator /(const float f)const{HFXVEC3F((double)f,/);} +//HFX_INLINE hfxVec3 &hfxVec3::operator *=(const float f){HFXVEC3FSELF((double)f,*=);} +//HFX_INLINE hfxVec3 &hfxVec3::operator /=(const float f){HFXVEC3FSELF((double)f,/=);} +HFX_INLINE hfxVec3 &HFXVEC3_DEFTYPE::operator =(const double &d){x=y=z=d;return(*this);} +//HFX_INLINE hfxVec3 &hfxVec3::operator =(const float f){x=y=z=(double)f;return(*this);} +#undef HFXVEC3T +#undef HFXVEC3_DEFTYPE +#ifndef HFX_INTERNAL +// 96 bit vect3 +#define HFXVEC3T hfxVec3F +HFX_INLINE hfxVec3F::hfxVec3F() +{ +#ifdef HFX_ZERO_INIT + HFX_MEMSET(m,0,sizeof(float)*3); +#endif +} +HFX_INLINE hfxVec3F::hfxVec3F(const float _x, const float _y, const float _z){x=_x;y=_y;z=_z;}; +HFX_INLINE hfxVec3F::hfxVec3F(const hfxVec3F &_copy){HFX_MEMCPY(m,_copy.m,sizeof(float)*3);}; +HFX_INLINE hfxVec3F::hfxVec3F(const float *array_d){HFX_MEMCPY(m,array_d,sizeof(float)*3);} + +HFX_INLINE bool hfxVec3F::IsValid()const{return(!IsNaN());} +HFX_INLINE bool hfxVec3F::IsNaN()const{return (x!=x||y!=y||z!=z);} + +HFX_INLINE float hfxVec3F::Magnitude()const{return(sqrt(x*x+y*y+z*z));} +HFX_INLINE hfxVec3F hfxVec3F::Normalized()const{float l=Magnitude();return(hfxVec3F(x/l,y/l,z/l));} +HFX_INLINE hfxVec3F &hfxVec3F::Normalize(){float l=Magnitude();x/=l;y/=l;z/=l;return(*this);} +#ifndef HFX_PAT_DOESNT_KNOW +HFX_INLINE float hfxVec3F::Length()const{return(Magnitude());}; +HFX_INLINE hfxVec3F hfxVec3F::Normal()const{return Normalized();}; +#endif +HFX_INLINE float hfxVec3F::Dot( const hfxVec3F &v )const{return(x*v.x+y*v.y+z*v.z);} +HFX_INLINE hfxVec3F hfxVec3F::Cross(const hfxVec3F &v)const{return hfxVec3F(x*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x);} + +HFX_INLINE const float &hfxVec3F::operator [](int i)const{return(m[i]);}; +HFX_INLINE float &hfxVec3F::operator [](int i){return(m[i]);}; +HFX_INLINE hfxVec3F::operator const float *() const{return(m);} +HFX_INLINE hfxVec3F::operator float *(){return(m);} +HFX_INLINE hfxVec3F hfxVec3F::operator -()const{return(hfxVec3F(-x,-y,-z));} +HFX_INLINE float *hfxVec3F::operator *(){return(m);}; +HFX_INLINE const float *hfxVec3F::operator *()const{return(m);}; + +HFX_INLINE hfxVec3F hfxVec3F::operator *(const hfxVec3F &v)const{HFXVEC3(v,*);} +HFX_INLINE hfxVec3F hfxVec3F::operator +(const hfxVec3F &v)const{HFXVEC3(v,+);} +HFX_INLINE hfxVec3F hfxVec3F::operator -(const hfxVec3F &v)const{HFXVEC3(v,-);} +HFX_INLINE hfxVec3F hfxVec3F::operator /(const hfxVec3F &v)const{HFXVEC3(v,/);} +HFX_INLINE hfxVec3F &hfxVec3F::operator =(const hfxVec3F &v){HFXVEC3SELF(v,=);} +HFX_INLINE hfxVec3F &hfxVec3F::operator *=(const hfxVec3F &v){HFXVEC3SELF(v,*=);} +HFX_INLINE hfxVec3F &hfxVec3F::operator +=(const hfxVec3F &v){HFXVEC3SELF(v,+=);} +HFX_INLINE hfxVec3F &hfxVec3F::operator -=(const hfxVec3F &v){HFXVEC3SELF(v,-=);} +HFX_INLINE hfxVec3F &hfxVec3F::operator /=(const hfxVec3F &v){HFXVEC3SELF(v,/=);} +//HFX_INLINE hfxVec3F hfxVec3F::operator *(const double &d)const{HFXVEC3F((float)d,*);} +//HFX_INLINE hfxVec3F hfxVec3F::operator /(const double &d)const{HFXVEC3F((float)d,/);} +//HFX_INLINE hfxVec3F &hfxVec3F::operator *=(const double &d){HFXVEC3FSELF((float)d,*=);} +//HFX_INLINE hfxVec3F &hfxVec3F::operator /=(const double &d){HFXVEC3FSELF((float)d,/=);} +HFX_INLINE hfxVec3F hfxVec3F::operator *(const float f)const{HFXVEC3F(f,*);} +HFX_INLINE hfxVec3F hfxVec3F::operator /(const float f)const{HFXVEC3F(f,/);} +HFX_INLINE hfxVec3F &hfxVec3F::operator *=(const float f){HFXVEC3FSELF(f,*=);} +HFX_INLINE hfxVec3F &hfxVec3F::operator /=(const float f){HFXVEC3FSELF(f,/=);} +//HFX_INLINE hfxVec3F &hfxVec3F::operator =(const double &d){x=y=z=(float)d;return(*this);} +HFX_INLINE hfxVec3F &hfxVec3F::operator =(const float f){x=y=z=f;return(*this);} +#endif +#undef HFXVEC3T +#undef HFXVEC3 +#undef HFXVEC3SELF +#undef HFXVEC3F +#undef HFXVEC3FSELF
\ No newline at end of file diff --git a/common/ihfx/util/hfxinterfacehelper.h b/common/ihfx/util/hfxinterfacehelper.h new file mode 100644 index 0000000..354749e --- /dev/null +++ b/common/ihfx/util/hfxinterfacehelper.h @@ -0,0 +1,54 @@ + +typedef int (*NovintHFX_ExposeInterfaceFn)(void **ppInterface, void *hwnd, const char *cmd, unsigned int versionMaj, unsigned int versionMin, void *pMouseEnableFN, unsigned int TargetDevices); +inline const char *HFX_GetVersionMajorString(){ + return HFX_VERSION_MAJOR_SZ; +} +inline const char *HFX_GetVersionMinorString(){ + return HFX_VERSION_MINOR_SZ; +} +inline const char *HFX_CONNECT_FUNCTION_NAME(){ + return "_export_ExposeInterfaceHFX_" HFX_VERSION_MAJOR_SZ "_" HFX_VERSION_MINOR_SZ "_"; +} +inline const char *HFX_CONNECT_FUNCTION_NAME_XML(){ + return "_export_ExposeInterfaceHFX_XML_" HFX_VERSION_MAJOR_SZ "_" HFX_VERSION_MINOR_SZ "_"; +} +inline const char *HFX_DYNAMIC_LIBRARY_NAME(const unsigned int tries = 0){ + switch(tries) + { + default: + return 0; + break; + +#ifdef HFX_DLL_CUSTOM_NAME + case 0: + return HFX_DLL_CUSTOM_NAME; + break; +#endif + +#ifndef HFX_DLL_CUSTOM_NAME + case 0: +#else + case 1: +#endif + return "NovintHFX_" HFX_VERSION_MAJOR_SZ "." HFX_VERSION_MINOR_SZ ".dll"; + break; + +#ifndef HFX_DLL_CUSTOM_NAME + case 1: +#else + case 2: +#endif + return "NovintHFX.dll"; + break; + + }; +} +inline unsigned int HFX_GetVersionMajor(){ + return HFX_VERSION_MAJOR; +} +inline unsigned int HFX_GetVersionMinor(){ + return HFX_VERSION_MINOR; +} +inline double HFX_GetVersion(){ + return HFX_VERSION_FLOAT; +}
\ No newline at end of file |