Kaynağa Gözat

Reorganized Node, Component, Drawable & Camera member variables for more optimal access.
Several Camera getter functions changed to const.

Lasse Öörni 13 yıl önce
ebeveyn
işleme
5bc2c61d88

+ 3 - 3
Docs/ScriptAPI.dox

@@ -1430,10 +1430,10 @@ Methods:<br>
 - void Remove()
 - void MarkNetworkUpdate() const
 - void SetOrthoSize(const Vector2&)
-- Frustum GetSplitFrustum(float, float)
+- Frustum GetSplitFrustum(float, float) const
 - Ray GetScreenRay(float, float)
-- float GetDistance(const Vector3&)
-- float GetDistanceSquared(const Vector3&)
+- float GetDistance(const Vector3&) const
+- float GetDistanceSquared(const Vector3&) const
 
 Properties:<br>
 - ShortStringHash type (readonly)

+ 4 - 4
Engine/Engine/GraphicsAPI.cpp

@@ -58,10 +58,10 @@ static void RegisterCamera(asIScriptEngine* engine)
     
     RegisterComponent<Camera>(engine, "Camera");
     engine->RegisterObjectMethod("Camera", "void SetOrthoSize(const Vector2&in)", asMETHODPR(Camera, SetOrthoSize, (const Vector2&), void), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Camera", "Frustum GetSplitFrustum(float, float)", asMETHOD(Camera, GetSplitFrustum), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Camera", "Frustum GetSplitFrustum(float, float) const", asMETHOD(Camera, GetSplitFrustum), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "Ray GetScreenRay(float, float)", asMETHOD(Camera, GetScreenRay), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Camera", "float GetDistance(const Vector3&in)", asMETHOD(Camera, GetDistance), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Camera", "float GetDistanceSquared(const Vector3&in)", asMETHOD(Camera, GetDistanceSquared), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Camera", "float GetDistance(const Vector3&in) const", asMETHOD(Camera, GetDistance), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Camera", "float GetDistanceSquared(const Vector3&in) const", asMETHOD(Camera, GetDistanceSquared), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "void set_nearClip(float)", asMETHOD(Camera, SetNearClip), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "float get_nearClip() const", asMETHOD(Camera, GetNearClip), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "void set_farClip(float)", asMETHOD(Camera, SetFarClip), asCALL_THISCALL);
@@ -86,7 +86,7 @@ static void RegisterCamera(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Camera", "uint get_viewMask() const", asMETHOD(Camera, GetViewMask), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "void set_viewOverrideFlags(uint)", asMETHOD(Camera, SetViewOverrideFlags), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "uint get_viewOverrideFlags() const", asMETHOD(Camera, GetViewOverrideFlags), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Camera", "const Frustum& get_frustum()", asMETHOD(Camera, GetFrustum), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Camera", "const Frustum& get_frustum() const", asMETHOD(Camera, GetFrustum), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "const Matrix4& get_projection() const", asMETHODPR(Camera, GetProjection, () const, const Matrix4&), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "const Matrix3x4& get_inverseWorldTransform() const", asMETHOD(Camera, GetInverseWorldTransform), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "Frustum get_viewSpaceFrustum() const", asMETHOD(Camera, GetViewSpaceFrustum), asCALL_THISCALL);

+ 10 - 10
Engine/Graphics/Camera.cpp

@@ -44,7 +44,10 @@ OBJECTTYPESTATIC(Camera);
 
 Camera::Camera(Context* context) :
     Component(context),
-    projectionOffset_(Vector2::ZERO),
+    inverseWorldDirty_(true),
+    projectionDirty_(true),
+    frustumDirty_(true),
+    orthographic_(false),
     nearClip_(DEFAULT_NEARCLIP),
     farClip_(DEFAULT_FARCLIP),
     fov_(DEFAULT_FOV),
@@ -54,12 +57,9 @@ Camera::Camera(Context* context) :
     lodBias_(1.0f),
     viewMask_(DEFAULT_VIEWMASK),
     viewOverrideFlags_(VO_NONE),
-    orthographic_(false),
+    projectionOffset_(Vector2::ZERO),
     autoAspectRatio_(true),
-    flipVertical_(false),
-    frustumDirty_(true),
-    projectionDirty_(true),
-    inverseWorldDirty_(true)
+    flipVertical_(false)
 {
 }
 
@@ -199,7 +199,7 @@ float Camera::GetNearClip() const
         return 0.0f;
 }
 
-Frustum Camera::GetSplitFrustum(float nearClip, float farClip)
+Frustum Camera::GetSplitFrustum(float nearClip, float farClip) const
 {
     Frustum ret;
     
@@ -270,7 +270,7 @@ Ray Camera::GetScreenRay(float x, float y)
     return ret;
 }
 
-const Frustum& Camera::GetFrustum()
+const Frustum& Camera::GetFrustum() const
 {
     if (frustumDirty_)
     {
@@ -419,7 +419,7 @@ Vector3 Camera::GetUpVector()
     return GetWorldTransform().RotationMatrix() * Vector3::UP;
 }
 
-float Camera::GetDistance(const Vector3& worldPos)
+float Camera::GetDistance(const Vector3& worldPos) const
 {
     if (!orthographic_)
     {
@@ -430,7 +430,7 @@ float Camera::GetDistance(const Vector3& worldPos)
         return fabsf((GetInverseWorldTransform() * worldPos).z_);
 }
 
-float Camera::GetDistanceSquared(const Vector3& worldPos)
+float Camera::GetDistanceSquared(const Vector3& worldPos) const
 {
     if (!orthographic_)
     {

+ 18 - 18
Engine/Graphics/Camera.h

@@ -98,7 +98,7 @@ public:
     /// Return auto aspect ratio flag.
     bool GetAutoAspectRatio() const { return autoAspectRatio_; }
     /// Return frustum in world space.
-    const Frustum& GetFrustum();
+    const Frustum& GetFrustum() const;
     /// Return API-specific projection matrix.
     const Matrix4& GetProjection() const;
     /// Return either API-specific or API-independent (D3D convention) projection matrix.
@@ -108,7 +108,7 @@ public:
     /// Return half view size.
     float GetHalfViewSize() const;
     /// Return frustum split by custom near and far clip distances.
-    Frustum GetSplitFrustum(float nearClip, float farClip);
+    Frustum GetSplitFrustum(float nearClip, float farClip) const;
     /// Return frustum in view space.
     Frustum GetViewSpaceFrustum() const;
     /// Return split frustum in view space.
@@ -126,9 +126,9 @@ public:
     /// Return vertical flipping mode.
     bool GetFlipVertical() const { return flipVertical_; }
     /// Return distance to position. In orthographic mode uses only Z coordinate.
-    float GetDistance(const Vector3& worldPos);
+    float GetDistance(const Vector3& worldPos) const;
     /// Return squared distance to position. In orthographic mode uses only Z coordinate.
-    float GetDistanceSquared(const Vector3& worldPos);
+    float GetDistanceSquared(const Vector3& worldPos) const;
     /// Return a scene node's LOD scaled distance.
     float GetLodDistance(float distance, float scale, float bias) const;
     /// Return if projection parameters are valid for rendering and raycasting.
@@ -144,14 +144,20 @@ protected:
     virtual void OnMarkedDirty(Node* node);
     
 private:
-    /// Cached frustum.
-    Frustum frustum_;
-    /// Cached projection matrix.
-    mutable Matrix4 projection_;
     /// Cached inverse world transform matrix.
     mutable Matrix3x4 inverseWorld_;
-    /// Projection offset.
-    Vector2 projectionOffset_;
+    /// Cached projection matrix.
+    mutable Matrix4 projection_;
+    /// Cached frustum.
+    mutable Frustum frustum_;
+    /// Inverse world transform dirty flag.
+    mutable bool inverseWorldDirty_;
+    /// Projection matrix dirty flag.
+    mutable bool projectionDirty_;
+    /// Frustum dirty flag.
+    mutable bool frustumDirty_;
+    /// Orthographic mode flag.
+    bool orthographic_;
     /// Near clip distance.
     float nearClip_;
     /// Far clip distance.
@@ -170,16 +176,10 @@ private:
     unsigned viewMask_;
     /// View override flags.
     unsigned viewOverrideFlags_;
-    /// Orthographic mode flag.
-    bool orthographic_;
+    /// Projection offset.
+    Vector2 projectionOffset_;
     /// Auto aspect ratio flag.
     bool autoAspectRatio_;
     /// Flip vertical flag.
     bool flipVertical_;
-    /// Frustum dirty flag.
-    bool frustumDirty_;
-    /// Projection matrix dirty flag.
-    mutable bool projectionDirty_;
-    /// Inverse world transform dirty flag.
-    mutable bool inverseWorldDirty_;
 };

+ 17 - 17
Engine/Graphics/Drawable.cpp

@@ -39,31 +39,31 @@ OBJECTTYPESTATIC(Drawable);
 
 Drawable::Drawable(Context* context) :
     Component(context),
-    octant_(0),
-    viewFrame_(0),
-    viewCamera_(0),
-    firstLight_(0),
-    drawDistance_(0.0f),
-    shadowDistance_(0.0f),
-    lodBias_(1.0f),
+    drawableFlags_(0),
+    worldBoundingBoxDirty_(true),
+    visible_(true),
+    castShadows_(false),
+    occluder_(false),
+    occludee_(true),
+    updateQueued_(false),
+    reinsertionQueued_(false),
     viewMask_(DEFAULT_VIEWMASK),
     lightMask_(DEFAULT_LIGHTMASK),
     shadowMask_(DEFAULT_SHADOWMASK),
     zoneMask_(DEFAULT_ZONEMASK),
-    maxLights_(0),
+    viewFrameNumber_(0),
     distance_(0.0f),
     lodDistance_(0.0f),
+    drawDistance_(0.0f),
+    shadowDistance_(0.0f),
     sortValue_(0.0f),
-    viewFrameNumber_(0),
+    lodBias_(1.0f),
     basePassFlags_(0),
-    drawableFlags_(0),
-    visible_(true),
-    castShadows_(false),
-    occluder_(false),
-    occludee_(true),
-    worldBoundingBoxDirty_(true),
-    updateQueued_(false),
-    reinsertionQueued_(false)
+    maxLights_(0),
+    octant_(0),
+    firstLight_(0),
+    viewFrame_(0),
+    viewCamera_(0)
 {
 }
 

+ 42 - 42
Engine/Graphics/Drawable.h

@@ -224,30 +224,24 @@ protected:
     /// Move into another octree octant.
     void SetOctant(Octant* octant) { octant_ = octant; }
     
-    /// Octree octant.
-    Octant* octant_;
     /// World bounding box.
     BoundingBox worldBoundingBox_;
-    /// Last view's frameinfo. Not safe to dereference.
-    const FrameInfo* viewFrame_;
-    /// Last view's camera. Not safe to dereference.
-    Camera* viewCamera_;
-    /// Per-pixel lights affecting this drawable.
-    PODVector<Light*> lights_;
-    /// Per-vertex lights affecting this drawable.
-    PODVector<Light*> vertexLights_;
-    /// First per-pixel light added this frame.
-    Light* firstLight_;
-    /// Current zone.
-    WeakPtr<Zone> zone_;
-    /// Previous zone.
-    WeakPtr<Zone> lastZone_;
-    /// Draw distance.
-    float drawDistance_;
-    /// Shadow distance.
-    float shadowDistance_;
-    /// LOD bias.
-    float lodBias_;
+    /// Drawable flags.
+    unsigned char drawableFlags_;
+    /// Bounding box dirty flag.
+    bool worldBoundingBoxDirty_;
+    /// Visible flag.
+    bool visible_;
+    /// Shadowcaster flag.
+    bool castShadows_;
+    /// Occluder flag.
+    bool occluder_;
+    /// Occludee flag.
+    bool occludee_;
+    /// Octree update queued flag.
+    bool updateQueued_;
+    /// Octree reinsertion queued flag.
+    bool reinsertionQueued_;
     /// View mask.
     unsigned viewMask_;
     /// Light mask.
@@ -256,34 +250,40 @@ protected:
     unsigned shadowMask_;
     /// Zone mask.
     unsigned zoneMask_;
-    /// Maximum lights.
-    unsigned maxLights_;
+    /// Last visible frame number.
+    unsigned viewFrameNumber_;
     /// Current distance to camera.
     float distance_;
     /// LOD scaled distance.
     float lodDistance_;
+    /// Draw distance.
+    float drawDistance_;
+    /// Shadow distance.
+    float shadowDistance_;
     /// Current sort value.
     float sortValue_;
-    /// Last visible frame number.
-    unsigned viewFrameNumber_;
+    /// LOD bias.
+    float lodBias_;
     /// Base pass flags.
     unsigned basePassFlags_;
-    /// Drawable flags.
-    unsigned char drawableFlags_;
-    /// Visible flag.
-    bool visible_;
-    /// Shadowcaster flag.
-    bool castShadows_;
-    /// Occluder flag.
-    bool occluder_;
-    /// Occludee flag.
-    bool occludee_;
-    /// Bounding box dirty flag.
-    bool worldBoundingBoxDirty_;
-    /// Octree update queued flag.
-    bool updateQueued_;
-    /// Octree reinsertion queued flag.
-    bool reinsertionQueued_;
+    /// Maximum lights.
+    unsigned maxLights_;
+    /// Octree octant.
+    Octant* octant_;
+    /// First per-pixel light added this frame.
+    Light* firstLight_;
+    /// Per-pixel lights affecting this drawable.
+    PODVector<Light*> lights_;
+    /// Per-vertex lights affecting this drawable.
+    PODVector<Light*> vertexLights_;
+    /// Current zone.
+    WeakPtr<Zone> zone_;
+    /// Previous zone.
+    WeakPtr<Zone> lastZone_;
+    /// Last view's frameinfo. Not safe to dereference.
+    const FrameInfo* viewFrame_;
+    /// Last view's camera. Not safe to dereference.
+    Camera* viewCamera_;
 };
 
 inline bool CompareDrawables(Drawable* lhs, Drawable* rhs)

+ 2 - 2
Engine/Scene/Component.cpp

@@ -34,8 +34,8 @@ OBJECTTYPESTATIC(Component);
 
 Component::Component(Context* context) :
     Serializable(context),
-    id_(0),
-    node_(0)
+    node_(0),
+    id_(0)
 {
 }
 

+ 2 - 2
Engine/Scene/Component.h

@@ -99,10 +99,10 @@ protected:
     /// %Set scene node. Called by Node when creating the component.
     void SetNode(Node* node);
     
-    /// Unique ID within the scene.
-    unsigned id_;
     /// Scene node.
     Node* node_;
+    /// Unique ID within the scene.
+    unsigned id_;
     /// Per-user network replication states.
     PODVector<ComponentReplicationState*> replicationStates_;
 };

+ 6 - 6
Engine/Scene/Node.cpp

@@ -41,17 +41,17 @@ OBJECTTYPESTATIC(Node);
 
 Node::Node(Context* context) :
     Serializable(context),
-    id_(0),
+    worldTransform_(Matrix3x4::IDENTITY),
+    dirty_(false),
+    networkUpdate_(false),
+    rotateCount_(0),
     parent_(0),
     scene_(0),
-    owner_(0),
+    id_(0),
     position_(Vector3::ZERO),
     rotation_(Quaternion::IDENTITY),
     scale_(Vector3::ONE),
-    worldTransform_(Matrix3x4::IDENTITY),
-    rotateCount_(0),
-    dirty_(false),
-    networkUpdate_(false)
+    owner_(0)
 {
 }
 

+ 26 - 25
Engine/Scene/Node.h

@@ -324,11 +324,6 @@ protected:
     /// Create a child node with specific ID.
     Node* CreateChild(unsigned id, CreateMode mode);
     
-    /// User variables.
-    VariantMap vars_;
-    /// Per-user network replication states.
-    PODVector<NodeReplicationState*> replicationStates_;
-    
 private:
     /// Recalculate the world transform.
     void UpdateWorldTransform() const;
@@ -341,44 +336,50 @@ private:
     /// Clone node recursively.
     Node* CloneRecursive(Node* parent, SceneResolver& resolver, CreateMode mode);
     
-    /// Unique ID within the scene.
-    unsigned id_;
+    /// World-space transform matrix.
+    mutable Matrix3x4 worldTransform_;
+    /// World transform needs update flag.
+    mutable bool dirty_;
+    /// Network update queued flag.
+    bool networkUpdate_;
+    /// Consecutive rotation count for rotation renormalization.
+    unsigned short rotateCount_;
     /// Parent scene node.
     Node* parent_;
     /// Scene (root node.)
     Scene* scene_;
-    /// Owner connection in networking.
-    Connection* owner_;
+    /// Unique ID within the scene.
+    unsigned id_;
     /// Position.
     Vector3 position_;
     /// Rotation.
     Quaternion rotation_;
     /// Scale.
     Vector3 scale_;
-    /// World-space transform matrix.
-    mutable Matrix3x4 worldTransform_;
-    /// Name.
-    String name_;
-    /// Name hash.
-    StringHash nameHash_;
-    /// Child scene nodes.
-    Vector<SharedPtr<Node> > children_;
     /// Components.
     Vector<SharedPtr<Component> > components_;
+    /// Child scene nodes.
+    Vector<SharedPtr<Node> > children_;
     /// Node listeners.
     Vector<WeakPtr<Component> > listeners_;
     /// Nodes this node depends on for network updates.
     PODVector<Node*> dependencyNodes_;
-    /// Previous user variables for network updates.
-    VariantMap previousVars_;
+    /// Owner connection in networking.
+    Connection* owner_;
+    /// Name.
+    String name_;
+    /// Name hash.
+    StringHash nameHash_;
     /// Attribute buffer for network updates.
     mutable VectorBuffer attrBuffer_;
-    /// Consecutive rotation count for rotation renormalization.
-    unsigned char rotateCount_;
-    /// World transform needs update flag.
-    mutable bool dirty_;
-    /// Network update queued flag.
-    bool networkUpdate_;
+    
+protected:
+    /// User variables.
+    VariantMap vars_;
+    /// Previous user variables for network updates.
+    VariantMap previousVars_;
+    /// Per-user network replication states.
+    PODVector<NodeReplicationState*> replicationStates_;
 };
 
 template <class T> T* Node::CreateComponent(CreateMode mode) { return static_cast<T*>(CreateComponent(T::GetTypeStatic(), mode)); }