diff options
Diffstat (limited to 'Runtime/Interfaces')
-rw-r--r-- | Runtime/Interfaces/IAnimation.cpp | 13 | ||||
-rw-r--r-- | Runtime/Interfaces/IAnimation.h | 43 | ||||
-rw-r--r-- | Runtime/Interfaces/IAnimationBinding.h | 69 | ||||
-rw-r--r-- | Runtime/Interfaces/IAnimationStateNetworkProvider.cpp | 14 | ||||
-rw-r--r-- | Runtime/Interfaces/IAnimationStateNetworkProvider.h | 22 | ||||
-rw-r--r-- | Runtime/Interfaces/IAudio.cpp | 14 | ||||
-rw-r--r-- | Runtime/Interfaces/IAudio.h | 53 | ||||
-rw-r--r-- | Runtime/Interfaces/IClusterRenderer.cpp | 14 | ||||
-rw-r--r-- | Runtime/Interfaces/IClusterRenderer.h | 16 | ||||
-rw-r--r-- | Runtime/Interfaces/IGfxDevice.cpp | 54 | ||||
-rw-r--r-- | Runtime/Interfaces/IGfxDevice.h | 28 | ||||
-rw-r--r-- | Runtime/Interfaces/IPhysics.cpp | 14 | ||||
-rw-r--r-- | Runtime/Interfaces/IPhysics.h | 72 | ||||
-rw-r--r-- | Runtime/Interfaces/IPhysics2D.cpp | 23 | ||||
-rw-r--r-- | Runtime/Interfaces/IPhysics2D.h | 29 | ||||
-rw-r--r-- | Runtime/Interfaces/IRaycast.cpp | 56 | ||||
-rw-r--r-- | Runtime/Interfaces/IRaycast.h | 73 | ||||
-rw-r--r-- | Runtime/Interfaces/ITerrainManager.cpp | 14 | ||||
-rw-r--r-- | Runtime/Interfaces/ITerrainManager.h | 46 |
19 files changed, 667 insertions, 0 deletions
diff --git a/Runtime/Interfaces/IAnimation.cpp b/Runtime/Interfaces/IAnimation.cpp new file mode 100644 index 0000000..4e63c73 --- /dev/null +++ b/Runtime/Interfaces/IAnimation.cpp @@ -0,0 +1,13 @@ +#include "UnityPrefix.h" +#include "IAnimation.h" + +static IAnimation* gAnimation = NULL; +IAnimation* GetAnimationInterface() +{ + return gAnimation; +} + +void SetAnimationInterface(IAnimation* theInterface) +{ + gAnimation = theInterface; +} diff --git a/Runtime/Interfaces/IAnimation.h b/Runtime/Interfaces/IAnimation.h new file mode 100644 index 0000000..151526e --- /dev/null +++ b/Runtime/Interfaces/IAnimation.h @@ -0,0 +1,43 @@ +#pragma once + +#include "Runtime/BaseClasses/GameObject.h" +#include "Runtime/Utilities/NonCopyable.h" +#include "Runtime/Modules/ExportModules.h" +#include "Runtime/Math/Matrix4x4.h" + +typedef UInt32 BindingHash; + +#include "Runtime/Math/Matrix4x4.h" + +namespace Unity { + class Component; +} + +struct CalculateSkinMatricesTask +{ + // input + const void* skeletonPose; + const UInt16* skeletonIndices; + Matrix4x4f rootPose; + int bindPoseCount; + const Matrix4x4f* bindPose; + // output + Matrix4x4f* outPose; +}; + +typedef void* (*CalculateAnimatorSkinMatricesFunc)(void* userData); + +class EXPORT_COREMODULE IAnimation : public NonCopyable +{ +public: + virtual const void* GetGlobalSpaceSkeletonPose(const Unity::Component& animator) = 0; + + virtual bool CalculateWorldSpaceMatricesMainThread(Unity::Component& animator, const UInt16* indices, size_t count, Matrix4x4f* outMatrices) = 0; + + virtual CalculateAnimatorSkinMatricesFunc GetCalculateAnimatorSkinMatricesFunc() = 0; + + virtual bool PathHashesToIndices(Unity::Component& animator, const BindingHash* bonePathHashes, size_t count, UInt16* outIndices) = 0; +}; + +EXPORT_COREMODULE IAnimation* GetAnimationInterface(); +EXPORT_COREMODULE void SetAnimationInterface(IAnimation* theInterface); diff --git a/Runtime/Interfaces/IAnimationBinding.h b/Runtime/Interfaces/IAnimationBinding.h new file mode 100644 index 0000000..c056a27 --- /dev/null +++ b/Runtime/Interfaces/IAnimationBinding.h @@ -0,0 +1,69 @@ +#pragma once + +class IAnimationBinding +{ +public: +#if UNITY_EDITOR + virtual void GetAllAnimatableProperties (Object& component, std::vector<EditorCurveBinding>& outProperties) const = 0; +#endif + + virtual float GetFloatValue (const UnityEngine::Animation::BoundCurve& bound) const = 0; + virtual void SetFloatValue (const UnityEngine::Animation::BoundCurve& bound, float value) const = 0; + + virtual void SetPPtrValue (const UnityEngine::Animation::BoundCurve& bound, SInt32 value) const= 0; + virtual SInt32 GetPPtrValue (const UnityEngine::Animation::BoundCurve& bound) const = 0; + + virtual bool GenerateBinding (const UnityStr& attribute, bool pptrCurve, UnityEngine::Animation::GenericBinding& outputBinding) const = 0; + virtual ClassIDType BindValue (Object& target, const UnityEngine::Animation::GenericBinding& binding, UnityEngine::Animation::BoundCurve& bound) const = 0; + + virtual std::string SerializedPropertyPathToCurveAttribute (Object& target, const char* propertyPath) const { return std::string(); } + virtual std::string CurveAttributeToSerializedPath (const UnityEngine::Animation::BoundCurve& bound) const { return std::string(); } +}; + +inline const char* ParsePrefixedName (const char* attribute, const char* prefix) +{ + if (BeginsWith(attribute, prefix)) + return attribute + strlen(prefix); + else + return NULL; +} + +inline void AddBinding (std::vector<EditorCurveBinding>& attributes, int classID, const std::string& attribute) +{ + attributes.push_back(EditorCurveBinding ("", classID, NULL, attribute, false)); +} + +inline void AddBindingCheckUnique (std::vector<EditorCurveBinding>& attributes, int startIndex, int classID, const std::string& attribute) +{ + for (int i=startIndex;i<attributes.size();i++) + { + if (attributes[i].classID == classID && attributes[i].attribute == attribute) + return; + } + + attributes.push_back(EditorCurveBinding ("", classID, NULL, attribute, false)); +} + + +inline void AddPPtrBinding (std::vector<EditorCurveBinding>& attributes, int classID, const std::string& attribute) +{ + attributes.push_back(EditorCurveBinding ("", classID, NULL, attribute, true)); +} + +inline int ParseIndexAttributeIndex (const UnityStr& attribute, const char* preString) +{ + const std::string::size_type pos0 = attribute.find_first_of('['); + const std::string::size_type pos1 = attribute.find_first_of(']'); + + if (pos0 == std::string::npos || pos1 == std::string::npos || + !BeginsWith(attribute, preString)) + { + return -1; + } + + Assert(pos0 < pos1); + Assert(pos1 - pos0 > 1); + + return StringToInt(attribute.c_str() + pos0); +} + diff --git a/Runtime/Interfaces/IAnimationStateNetworkProvider.cpp b/Runtime/Interfaces/IAnimationStateNetworkProvider.cpp new file mode 100644 index 0000000..3198cfa --- /dev/null +++ b/Runtime/Interfaces/IAnimationStateNetworkProvider.cpp @@ -0,0 +1,14 @@ +#include "UnityPrefix.h" +#include "IAnimationStateNetworkProvider.h" + +static IAnimationStateNetworkProvider* gAnimationProvider; + +IAnimationStateNetworkProvider* GetIAnimationStateNetworkProvider () +{ + return gAnimationProvider; +} + +void SetIAnimationStateNetworkProvider (IAnimationStateNetworkProvider* manager) +{ + gAnimationProvider = manager; +}
\ No newline at end of file diff --git a/Runtime/Interfaces/IAnimationStateNetworkProvider.h b/Runtime/Interfaces/IAnimationStateNetworkProvider.h new file mode 100644 index 0000000..797c744 --- /dev/null +++ b/Runtime/Interfaces/IAnimationStateNetworkProvider.h @@ -0,0 +1,22 @@ +#pragma once + +class Animation; + +struct AnimationStateForNetwork +{ + bool enabled; + float weight; + float time; +}; + +class IAnimationStateNetworkProvider +{ +public: + + virtual int GetNetworkAnimationStateCount (Animation& animation) = 0; + virtual void GetNetworkAnimationState (Animation& animation, AnimationStateForNetwork* state, int count) = 0; + virtual void SetNetworkAnimationState (Animation& animation, const AnimationStateForNetwork* serialize, int count) = 0; +}; + +EXPORT_COREMODULE IAnimationStateNetworkProvider* GetIAnimationStateNetworkProvider (); +EXPORT_COREMODULE void SetIAnimationStateNetworkProvider (IAnimationStateNetworkProvider* manager);
\ No newline at end of file diff --git a/Runtime/Interfaces/IAudio.cpp b/Runtime/Interfaces/IAudio.cpp new file mode 100644 index 0000000..ca1189c --- /dev/null +++ b/Runtime/Interfaces/IAudio.cpp @@ -0,0 +1,14 @@ +#include "UnityPrefix.h" +#include "IAudio.h" + +static IAudio* gAudio = NULL; + +IAudio* GetIAudio() +{ + return gAudio; +} + +void SetIAudio(IAudio* audio) +{ + gAudio = audio; +}
\ No newline at end of file diff --git a/Runtime/Interfaces/IAudio.h b/Runtime/Interfaces/IAudio.h new file mode 100644 index 0000000..f8d1760 --- /dev/null +++ b/Runtime/Interfaces/IAudio.h @@ -0,0 +1,53 @@ +#pragma once + +#include "Runtime/BaseClasses/BaseObject.h" +#include "Runtime/Audio/correct_fmod_includer.h" + +class Object; +class MovieTexture; +class WWW; +class AudioClip; +struct AudioStats; +namespace FMOD { class DSP; } +class AudioCustomFilter; +class MonoBehaviour; + +class IAudio +{ +public: + virtual void SetPause( bool pause ) = 0; + virtual void FixedUpdate() = 0; + virtual void Update() = 0; + + virtual void StopVideoTextures() = 0; + virtual void UpdateVideoTextures() = 0; + virtual void PauseVideoTextures() = 0; + +#if ENABLE_WWW +#if ENABLE_MOVIES + virtual MovieTexture* CreateMovieTextureFromWWW(WWW& www) = 0; +#endif + virtual AudioClip* CreateAudioClipFromWWW(WWW& www, bool threeD, bool stream, FMOD_SOUND_TYPE audioType) = 0; + virtual AudioClip* CreateAudioClipOGGFromWWW(WWW& www) = 0; +#endif + + virtual bool IsFormatSupportedByPlatform(const char* type) = 0; + +#if ENABLE_AUDIO_FMOD + virtual FMOD::DSP* GetOrCreateDSPFromCustomFilter(AudioCustomFilter* filter) = 0; + virtual AudioCustomFilter* CreateAudioCustomFilter(MonoBehaviour* mb) = 0; + virtual FMOD::DSP* GetDSPFromAudioCustomFilter(AudioCustomFilter* filter) = 0; + virtual void SetBypassOnDSP(FMOD::DSP* dsp, bool state) = 0; +#endif + +#if ENABLE_PROFILER + virtual void GetProfilerStats(AudioStats& stats) = 0; +#endif + virtual void AudioManagerAwakeFromLoad(AwakeFromLoadMode mode) = 0; +}; + +IAudio* CreateAudioModule(); + + +IAudio* EXPORT_COREMODULE GetIAudio(); +void EXPORT_COREMODULE SetIAudio(IAudio* physics);
\ No newline at end of file diff --git a/Runtime/Interfaces/IClusterRenderer.cpp b/Runtime/Interfaces/IClusterRenderer.cpp new file mode 100644 index 0000000..cda6697 --- /dev/null +++ b/Runtime/Interfaces/IClusterRenderer.cpp @@ -0,0 +1,14 @@ +#include "IClusterRenderer.h" +#if ENABLE_CLUSTER_SYNC +static IClusterRenderer* gIClusterRenderer = NULL; + +IClusterRenderer* GetIClusterRenderer() +{ + return gIClusterRenderer; +} + +void SetIClusterRenderer(IClusterRenderer* value) +{ + gIClusterRenderer = value; +} +#endif
\ No newline at end of file diff --git a/Runtime/Interfaces/IClusterRenderer.h b/Runtime/Interfaces/IClusterRenderer.h new file mode 100644 index 0000000..dfc420b --- /dev/null +++ b/Runtime/Interfaces/IClusterRenderer.h @@ -0,0 +1,16 @@ +#pragma once +#if ENABLE_CLUSTER_SYNC +#include "Runtime/Utilities/NonCopyable.h" + +class EXPORT_COREMODULE IClusterRenderer : public NonCopyable +{ +public: + virtual void InitCluster() = 0; + virtual void SynchronizeCluster() = 0; + virtual bool IsMasterOfCluster() = 0; + virtual void ShutdownCluster() = 0; +}; + +EXPORT_COREMODULE IClusterRenderer* GetIClusterRenderer(); +EXPORT_COREMODULE void SetIClusterRenderer(IClusterRenderer* value); +#endif
\ No newline at end of file diff --git a/Runtime/Interfaces/IGfxDevice.cpp b/Runtime/Interfaces/IGfxDevice.cpp new file mode 100644 index 0000000..3e358a0 --- /dev/null +++ b/Runtime/Interfaces/IGfxDevice.cpp @@ -0,0 +1,54 @@ +#include "UnityPrefix.h" +#include "IGfxDevice.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Misc/Plugins.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Shaders/Shader.h" + +static IGfxDevice* gGfxDevice; + +IGfxDevice* GetIGfxDevice () +{ + return gGfxDevice; +} + +void SetIGfxDevice (IGfxDevice* manager) +{ + gGfxDevice = manager; +} + + +void CommonReloadResources(int flags) +{ + if (flags & GfxDevice::kReloadTextures) + Texture::ReloadAll(); + + if (flags & GfxDevice::kReloadShaders) + Shader::ReloadAllShaders(); + + if (flags & GfxDevice::kReleaseRenderTextures) + RenderTexture::ReleaseAll(); +} + +bool InitializeGfxDevice() { + if (!GetIGfxDevice()->InitializeGfxDevice()) + return false; + + GfxDevice& device = GetGfxDevice(); + device.SetMarkerCallback (PluginsRenderMarker); + device.SetSetNativeGfxDeviceCallback (PluginsSetGraphicsDevice); + device.SetReloadCallback (CommonReloadResources); + return true; +} + +void ParseGfxDeviceArgs () { return GetIGfxDevice()->ParseGfxDeviceArgs(); } +bool IsGfxDevice() { return GetIGfxDevice()->IsGfxDevice(); } +GfxDevice& GetGfxDevice() { return GetIGfxDevice()->GetGfxDevice(); } +GfxDevice& GetUncheckedGfxDevice() { return GetIGfxDevice()->GetUncheckedGfxDevice(); } +void DestroyGfxDevice() { GetIGfxDevice()->DestroyGfxDevice(); } + +GfxDevice& GetRealGfxDevice() { return GetIGfxDevice()->GetRealGfxDevice(); } +bool IsRealGfxDeviceThreadOwner() { return GetIGfxDevice()->IsRealGfxDeviceThreadOwner(); } + +GraphicsCaps& gGraphicsCaps { return GetIGfxDevice()->gGraphicsCaps; } diff --git a/Runtime/Interfaces/IGfxDevice.h b/Runtime/Interfaces/IGfxDevice.h new file mode 100644 index 0000000..749c723 --- /dev/null +++ b/Runtime/Interfaces/IGfxDevice.h @@ -0,0 +1,28 @@ +#ifndef IGFXDEVICE_H +#define IGFXDEVICE_H + +class GfxDevice; +class GraphicsCaps; +class GpuProgramParameters; + +class IGfxDevice +{ +public: + virtual bool IsGfxDevice() = 0; + virtual bool InitializeGfxDevice() = 0; + virtual bool IsRealGfxDeviceThreadOwner() = 0; + virtual GfxDevice &GetGfxDevice() = 0; + virtual GfxDevice &GetUncheckedGfxDevice() = 0; + virtual GfxDevice &GetRealGfxDevice() = 0; + virtual void DestroyGfxDevice() = 0; + virtual void ParseGfxDeviceArgs() = 0; + virtual GpuProgramParameters* CreateGpuProgramParameters() = 0; + virtual void DestroyGpuProgramParameters(GpuProgramParameters*) = 0; + virtual GraphicsCaps &gGraphicsCaps = 0; + +}; + +EXPORT_COREMODULE IGfxDevice* GetIGfxDevice (); +EXPORT_COREMODULE void SetIGfxDevice (IGfxDevice* device); + +#endif
\ No newline at end of file diff --git a/Runtime/Interfaces/IPhysics.cpp b/Runtime/Interfaces/IPhysics.cpp new file mode 100644 index 0000000..e7c84b1 --- /dev/null +++ b/Runtime/Interfaces/IPhysics.cpp @@ -0,0 +1,14 @@ +#include "UnityPrefix.h" +#include "IPhysics.h" + +static IPhysics* gIPhysics = NULL; + +IPhysics* GetIPhysics() +{ + return gIPhysics; +} + +void SetIPhysics(IPhysics* phys) +{ + gIPhysics = phys; +}
\ No newline at end of file diff --git a/Runtime/Interfaces/IPhysics.h b/Runtime/Interfaces/IPhysics.h new file mode 100644 index 0000000..d2497b4 --- /dev/null +++ b/Runtime/Interfaces/IPhysics.h @@ -0,0 +1,72 @@ +#pragma once + +#include "Runtime/Math/Vector3.h" +#include "Runtime/Math/Quaternion.h" +#include "Runtime/Utilities/NonCopyable.h" +#include "Runtime/Scripting/ScriptingUtility.h" + +class Rigidbody; +struct PhysicsStats; +class NxTriangleMesh; +class NxConvexMesh; +class NxStream; +class CapsuleCollider; +struct Collision; +namespace Unity { class SkinnedCloth; } +class Collider; +class MeshCollider; +class NxConvexMeshDesc; +class NxTriangleMeshDesc; +class MemoryStream; +class Mesh; +class NxHeightField; +class NxHeightFieldDesc; + +class EXPORT_COREMODULE IPhysics : public NonCopyable +{ +public: + // Collision intersection + struct RigidBodyState + { + Vector3f position; + Quaternionf rotation; + Vector3f velocity; + Vector3f avelocity; + }; + + virtual void SetRigidBodyState( Rigidbody& rigidbody, const RigidBodyState& state ) = 0; + virtual void GetRigidBodyState( const Rigidbody& rigidbody, RigidBodyState* result) = 0; + virtual Vector3f GetRigidBodyVelocity( const Rigidbody& rigidbody) = 0; + virtual Vector3f GetGravity() = 0; + + virtual void* CreateNxMeshFromNxStream(bool convex, const NxStream& stream) = 0; + + virtual void ReleaseNxTriangleMesh(NxTriangleMesh& mesh) = 0; + virtual void ReleaseNxConvexMesh(NxConvexMesh& mesh) = 0; + + virtual void CapsuleColliderSetHeight(CapsuleCollider& collider, float height) = 0; + + virtual ScriptingObjectPtr ConvertContactToMono (Collision* input) = 0; + virtual int GetColliderMaterialInstanceID(Collider& collider) = 0; + virtual int GetColliderSharedMeshInstanceID(MeshCollider& collider) = 0; + + virtual bool CreateNxStreamFromUnityMesh (Mesh* mesh, bool convex, const Matrix4x4f& scalematrix, TransformType transformType, MemoryStream& stream ) = 0; + virtual void* CreateNxMeshFromUnityMesh (Mesh* mesh, bool convex, const Matrix4x4f& scalematrix, TransformType transformType ) = 0; + virtual MemoryStream* CreateNxStreamFromUnityMesh(Mesh& meshData, bool convex) = 0; + + virtual void DeleteMemoryStream(MemoryStream* memory) = 0; + + virtual void ReleaseHeightField(NxHeightField& heightField) = 0; + virtual NxHeightField* CreateNxHeightField(NxHeightFieldDesc& desc) = 0; + +#if ENABLE_CLOTH + virtual void SetUpSkinnedBuffersOnSkinnedCloth (Unity::SkinnedCloth& cloth, void *vertices, void *normals, void *tangents, size_t bufferStride) = 0; +#endif + +#if ENABLE_PROFILER + virtual void GetProfilerStats(PhysicsStats& stats) = 0; +#endif +}; + +EXPORT_COREMODULE IPhysics* GetIPhysics(); +EXPORT_COREMODULE void SetIPhysics(IPhysics* physics);
\ No newline at end of file diff --git a/Runtime/Interfaces/IPhysics2D.cpp b/Runtime/Interfaces/IPhysics2D.cpp new file mode 100644 index 0000000..f94ead4 --- /dev/null +++ b/Runtime/Interfaces/IPhysics2D.cpp @@ -0,0 +1,23 @@ +#include "UnityPrefix.h" +#include "IPhysics2D.h" + + +// -------------------------------------------------------------------------- + + +static IPhysics2D* gIPhysics2D = NULL; + + +// -------------------------------------------------------------------------- + + +IPhysics2D* GetIPhysics2D() +{ + return gIPhysics2D; +} + + +void SetIPhysics2D(IPhysics2D* value) +{ + gIPhysics2D = value; +} diff --git a/Runtime/Interfaces/IPhysics2D.h b/Runtime/Interfaces/IPhysics2D.h new file mode 100644 index 0000000..8cdc8f8 --- /dev/null +++ b/Runtime/Interfaces/IPhysics2D.h @@ -0,0 +1,29 @@ +#pragma once + +// -------------------------------------------------------------------------- + + +struct Physics2DStats; + + +// -------------------------------------------------------------------------- + + +class IPhysics2D +{ +public: + virtual void FixedUpdate () = 0; + virtual void DynamicUpdate () = 0; + virtual void ResetInterpolations () = 0; + +#if ENABLE_PROFILER + virtual void GetProfilerStats (Physics2DStats& stats) = 0; +#endif +}; + + +// -------------------------------------------------------------------------- + + +IPhysics2D* GetIPhysics2D (); +void SetIPhysics2D (IPhysics2D* manager); diff --git a/Runtime/Interfaces/IRaycast.cpp b/Runtime/Interfaces/IRaycast.cpp new file mode 100644 index 0000000..b910856 --- /dev/null +++ b/Runtime/Interfaces/IRaycast.cpp @@ -0,0 +1,56 @@ +#include "UnityPrefix.h" +#include "IRaycast.h" +#include "Runtime/Geometry/Intersection.h" +#include "Runtime/Geometry/AABB.h" +#include "Runtime/Dynamics/PhysicsManager.h" +#include <limits> + +// Test if ray intersects at least one of the aabbs +bool IRaycast::IntersectAny( const Ray& ray, float maxDistance, AABB* shapeBounds, size_t shapeCount ) +{ + const Vector3f halfDir = ray.GetDirection() * maxDistance * 0.5; + const AABB rayBounds(ray.GetOrigin() + halfDir, Abs(halfDir)); + for (size_t s = 0; s < shapeCount; ++s) + { + if (IntersectAABBAABBInclusive(rayBounds, shapeBounds[s])) + return true; + } + return false; +} + +// Test if ray intersects at least one of the aabbs +bool IRaycast::IntersectAny( const BatchedRaycast& ray, AABB* shapeBounds, size_t shapeCount ) +{ + const Vector3f halfDir = (ray.to-ray.from) * 0.5; + const AABB rayBounds(ray.from + halfDir, Abs(halfDir)); + for (size_t s = 0; s < shapeCount; ++s) + { + if (IntersectAABBAABBInclusive(rayBounds, shapeBounds[s])) + return true; + } + return false; +} + +// AABB of ray segments expanded with particle radius +MinMaxAABB IRaycast::ComputeBatchAABB( const dynamic_array<BatchedRaycast>& raycasts ) +{ + MinMaxAABB aabb; + for (size_t q = 0; q < raycasts.size(); ++q) + { + aabb.Encapsulate(raycasts[q].from); + aabb.Encapsulate(raycasts[q].to); + } + return aabb; +} + +static IRaycast* gRaycaster = NULL; + +IRaycast* GetRaycastInterface() +{ + return gRaycaster; +} + +void SetRaycastInterface(IRaycast* theInterface) +{ + gRaycaster = theInterface; +} diff --git a/Runtime/Interfaces/IRaycast.h b/Runtime/Interfaces/IRaycast.h new file mode 100644 index 0000000..18539ae --- /dev/null +++ b/Runtime/Interfaces/IRaycast.h @@ -0,0 +1,73 @@ +#ifndef IRAYCAST_H +#define IRAYCAST_H + +#include "Runtime/Math/Vector3.h" +#include "Runtime/Geometry/Ray.h" +#include "Runtime/Utilities/NonCopyable.h" +#include "Runtime/Utilities/dynamic_array.h" +#include "Runtime/Modules/ExportModules.h" + +class AABB; +class MinMaxAABB; +class Plane; +class Collider; +struct RaycastHit; + +// Collision intersection +struct HitInfo +{ + Vector3f intersection; + Vector3f normal; + int colliderInstanceID; // The instanceID of the intersected Collider component. + int rigidBodyOrColliderInstanceID; // The instanceID of the RigidBody to which the Collider is attached. If there is none then the ID is the same as colliderInstanceID. +}; + +// Batch intersection result +struct BatchedRaycastResult +{ + BatchedRaycastResult(unsigned int i, const HitInfo& h) : index(i), hitInfo(h) {} + unsigned int index; // the index of the result into BatchedRaycast array + HitInfo hitInfo; // the intersection +}; + +// Batch intersection request +struct BatchedRaycast +{ + BatchedRaycast(unsigned int i, const Vector3f& f, const Vector3f& t) : index(i), from(f), to(t) {} + unsigned int index; // user provided index + Vector3f from; // ray origin + Vector3f to; // ray endpoint +}; + +/// Abstract ray tracing class +class EXPORT_COREMODULE IRaycast : public NonCopyable +{ +public: + /// ====================================== + /// Useful intersection methods + + /// Returns true if any shape is intersected along the ray within maxDist + static bool IntersectAny( const Ray& ray, float maxDist, AABB* shapeBounds, size_t shapeCount ); + + /// Version of above taking a pair of points + static bool IntersectAny( const BatchedRaycast& ray, AABB* shapeBounds, size_t shapeCount ); + + /// ====================================== + /// Virtual interface + + /// Intersects all the rays and returns any intersections in results, the return value specifies how many intersections were found. + /// The index entry within BatchedRaycast is user provided while the index in BatchedRaycastResult specifies the BatchedRaycast that it is a result. + size_t virtual BatchIntersect( const dynamic_array<BatchedRaycast>& raycasts, dynamic_array<BatchedRaycastResult>& results, const UInt32 filter, bool staticOnly ) const = 0; + + bool virtual Raycast (const Ray& ray, float distance, int mask, HitInfo& hit) = 0; + +protected: + /// Helper function for computing AABB collection of rays + static MinMaxAABB ComputeBatchAABB( const dynamic_array<BatchedRaycast>& raycasts); +}; + +/// Singleton access +EXPORT_COREMODULE IRaycast* GetRaycastInterface(); +EXPORT_COREMODULE void SetRaycastInterface(IRaycast* theInterface); // argh, using interface raises an C2332 + +#endif diff --git a/Runtime/Interfaces/ITerrainManager.cpp b/Runtime/Interfaces/ITerrainManager.cpp new file mode 100644 index 0000000..10f5c87 --- /dev/null +++ b/Runtime/Interfaces/ITerrainManager.cpp @@ -0,0 +1,14 @@ +#include "UnityPrefix.h" +#include "ITerrainManager.h" + +static ITerrainManager* gTerrainManager; + +ITerrainManager* GetITerrainManager () +{ + return gTerrainManager; +} + +void SetITerrainManager (ITerrainManager* manager) +{ + gTerrainManager = manager; +} diff --git a/Runtime/Interfaces/ITerrainManager.h b/Runtime/Interfaces/ITerrainManager.h new file mode 100644 index 0000000..97f930d --- /dev/null +++ b/Runtime/Interfaces/ITerrainManager.h @@ -0,0 +1,46 @@ +#pragma once +#include <list> + +#include "Runtime/Modules/ExportModules.h" +#include "Runtime/Camera/SceneNode.h" +#include "Runtime/Geometry/AABB.h" +#include "Runtime/Utilities/dynamic_array.h" + +class Light; +class Object; +class TerrainInstance; +class Vector3f; +class NxHeightField; +class Heightmap; + +typedef UNITY_LIST(kMemRenderer, TerrainInstance*) TerrainList; + +class ITerrainManager +{ +public: +#if ENABLE_PHYSICS + virtual NxHeightField* Heightmap_GetNxHeightField(Heightmap& heightmap) = 0; +#endif + virtual int Heightmap_GetMaterialIndex(Heightmap& heightmap) = 0; + virtual Vector3f Heightmap_GetSize(Heightmap& heightmap) = 0; + + /// Extracts the height on the heightmap from a TerrainData + /// Returns true if the heightmap was sampled and the position is inside the terrain extents. + virtual bool GetInterpolatedHeight (const Object* terrainData, const Vector3f& terrainPosition, const Vector3f& position, float& outputHeight) = 0; + + /// Render all terrains + virtual void CullAllTerrains (int cullingMask) = 0; + /// Set the lightmap index on all terrains + virtual void SetLightmapIndexOnAllTerrains (int lightmapIndex) = 0; + virtual void AddTerrainAndSetActive (TerrainInstance* terrain) = 0; + virtual void RemoveTerrain (TerrainInstance* terrain) = 0; + virtual TerrainInstance* GetActiveTerrain () const = 0; + virtual const TerrainList& GetActiveTerrains () const = 0; + virtual void UnloadTerrainsFromGfxDevice () = 0; + virtual void ReloadTerrainsToGfxDevice () = 0; + + virtual void CollectTreeRenderers(dynamic_array<SceneNode>& sceneNodes, dynamic_array<AABB>& boundingBoxes) const = 0; +}; + +EXPORT_COREMODULE ITerrainManager* GetITerrainManager (); +EXPORT_COREMODULE void SetITerrainManager (ITerrainManager* manager); |