불필요한 작업을 피하기 위해 실제로 필요할 때까지 그 일을 미룬다.
class Transform {
public:
static Transform Origin();
Transform Combine(Transform& other);
};
class GraphNode {
public:
GraphNode(Mesh* mesh)
:mesh_(mesh),
local_(Transform::Origin()),
dirty_(true) {
}
void SetTransform(Transform local);
void Render(Transform parentWorld, bool dirty);
void RenderMesh(Mesh* mesh, Transform world);
private:
Transform world_;
bool dirty_;
static const int MAX_CHILDREN = 10;
Transform local_;
Mesh* mesh_;
GraphNode* children_[MAX_CHILDREN];
int numChilren_;
};
void GraphNode::SetTransform(Transform local) {
local_ = local;
dirty_ = true;
}
void GraphNode::Render(Transform parentWorld, bool dirty) {
dirty |= dirty_;
if (dirty) {
//더티플래그로 최소한의 월드 변환 계산을 하면 된다.
world_ = local_.Combine(parentWorld);
dirty_ = false;
}
if (mesh_) RenderMesh(mesh_, world_);
for (int i = 0; i < numChilren_; i++)
{
children_[i]->Render(world_, dirty);
}
}