My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#ifndef __DEM_L1_SCENE_SPS_H__
#define __DEM_L1_SCENE_SPS_H__

#include <Scene/RenderObject.h>
#include <Scene/Light.h>
#include <Scene/SceneNode.h>
#include <Data/QuadTree.h>

// Scene spatial partitioning structure stuff

namespace Scene
{
struct CSPSRecord;

struct CSPSCell
{
typedef CSPSRecord* CIterator;

CArray<CSPSRecord*> Objects;
CArray<CSPSRecord*> Lights;

CIterator Add(CSPSRecord* const & Object);
bool RemoveByValue(CSPSRecord* const & Object);
void Remove(CIterator It) { Sys::Error("There are no persistent handles for arrays due to possible data move!"); }
CIterator Find(CSPSRecord* const & Object) const { return NULL; } //???!!!implement?
};

typedef Data::CQuadTree<CSPSRecord*, CSPSCell> CSPS;
typedef CSPS::CNode CSPSNode;

class CNodeAttribute;

struct CSPSRecord
{
CNodeAttribute& Attr;
CAABB GlobalBox;
CSPSNode* pSPSNode;

CSPSRecord(CNodeAttribute& NodeAttr): Attr(NodeAttr), pSPSNode(NULL) {}
CSPSRecord(const CSPSRecord& Rec): Attr(Rec.Attr), GlobalBox(Rec.GlobalBox), pSPSNode(Rec.pSPSNode) {}

bool IsRenderObject() const { return Attr.IsA(CRenderObject::RTTI); }
bool IsLight() const { return Attr.IsA(CLight::RTTI); }

void GetCenter(vector2& Out) const;
void GetHalfSize(vector2& Out) const;
CSPSNode* GetQuadTreeNode() const { return pSPSNode; }
void SetQuadTreeNode(CSPSNode* pNode) { pSPSNode = pNode; }
};

inline void CSPSRecord::GetCenter(vector2& Out) const
{
n_assert(Attr.GetNode());
const vector3& Pos = Attr.GetNode()->GetWorldPosition();
Out.x = Pos.x;
Out.y = Pos.z;
}
//---------------------------------------------------------------------

inline void CSPSRecord::GetHalfSize(vector2& Out) const
{
Out.x = (GlobalBox.vmax.x - GlobalBox.vmin.x) * 0.5f;
Out.y = (GlobalBox.vmax.z - GlobalBox.vmin.z) * 0.5f;
}
//---------------------------------------------------------------------

// NB: no persistent handle for arrays
inline CSPSCell::CIterator CSPSCell::Add(CSPSRecord* const & Object)
{
if (Object->IsRenderObject())
{
Objects.Add(Object);
return NULL;
}
if (Object->IsLight())
{
Lights.Add(Object);
return NULL;
}
n_assert_dbg(false);
return NULL;
}
//---------------------------------------------------------------------

// Remove by value
inline bool CSPSCell::RemoveByValue(CSPSRecord* const & Object)
{
if (Object->IsRenderObject()) return Objects.RemoveByValue(Object);
if (Object->IsLight()) return Lights.RemoveByValue(Object);
FAIL;
}
//---------------------------------------------------------------------

}

#endif

Change log

r348 by niello11 on May 15, 2014   Diff
More refactoring, Win32 stack trace
implemented
Go to: 
Project members, sign in to write a code review

Older revisions

r318 by niello11 on Jan 21, 2014   Diff
Cool assertion macro implemented
r257 by niello11 on Jul 15, 2013   Diff
nkernel removed, mathlib files are the
only remaining code in the
Src/nebula2. They are moved to DEM_L1
project. bbox3 -> CAABB
r253 by niello11 on Jul 14, 2013   Diff
Broken stuff fixed. AI planner not
tested.
All revisions of this file

File info

Size: 2649 bytes, 97 lines
Powered by Google Project Hosting