2023-03-24 00:39:00 +00:00
|
|
|
#include "IDrawable.h"
|
2023-03-07 00:10:40 +00:00
|
|
|
#include "Scene.h"
|
2023-01-12 17:21:52 +00:00
|
|
|
#include "SceneCell.h"
|
|
|
|
#include "SceneCellGroup.h"
|
|
|
|
#include "SceneEntity.h"
|
|
|
|
|
|
|
|
namespace cdc {
|
|
|
|
|
2023-03-07 00:10:40 +00:00
|
|
|
SceneEntity::SceneEntity(Scene *scene) : scene(scene) {
|
2023-06-20 15:23:17 +00:00
|
|
|
// called from SceneLayer::AddInstance
|
2023-03-07 00:10:40 +00:00
|
|
|
scene->AddEntity(this);
|
|
|
|
}
|
|
|
|
|
2023-06-19 01:14:07 +00:00
|
|
|
void SceneEntity::ApplyUpdateState(UpdateState *updateState) {
|
|
|
|
// called from UpdateInstances
|
|
|
|
// without this, the object might still render in the correct position
|
2023-06-19 01:26:30 +00:00
|
|
|
// but TransformVolumeAndPivot can't move the culling volume away from origin
|
|
|
|
|
|
|
|
if (updateState->updateFlags & UpdateState::kEnabled) {
|
2024-04-17 18:23:12 +00:00
|
|
|
enabled = updateState->enabled;
|
2023-06-19 01:26:30 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState->updateFlags & UpdateState::kDrawable) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState->updateFlags & UpdateState::kCellGroup) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState->updateFlags & UpdateState::kMatrix) {
|
|
|
|
// TODO
|
2023-06-19 01:14:07 +00:00
|
|
|
setMatrix(updateState->matrix);
|
2023-06-19 01:26:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState->updateFlags & UpdateState::kMoveState) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState->updateFlags & (UpdateState::kUpdateVolume | UpdateState::kDrawable)) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState->updateFlags & (UpdateState::kUpdateFlags | UpdateState::kDrawable)) {
|
|
|
|
// TODO
|
|
|
|
}
|
2023-06-19 01:14:07 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 17:21:52 +00:00
|
|
|
void SceneEntity::setMatrix(Matrix& newMatrix) {
|
|
|
|
matrix = newMatrix;
|
2023-03-24 00:39:00 +00:00
|
|
|
QueryVolumeFromDrawable();
|
2023-01-12 17:21:52 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
Matrix& SceneEntity::getMatrix() {
|
|
|
|
return matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneEntity::setDrawable(IDrawable *newDrawable) {
|
|
|
|
drawable = newDrawable;
|
2023-03-24 00:39:00 +00:00
|
|
|
QueryVolumeFromDrawable();
|
2023-01-12 17:21:52 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
IDrawable *SceneEntity::getDrawable() {
|
|
|
|
return drawable;
|
|
|
|
}
|
|
|
|
|
2023-01-12 17:26:09 +00:00
|
|
|
void SceneEntity::setCellGroup(ISceneCellGroup *newICellGroup) {
|
|
|
|
auto newCellGroup = static_cast<SceneCellGroup*>(newICellGroup);
|
|
|
|
if (sceneCellGroup != newCellGroup) {
|
|
|
|
// TODO
|
|
|
|
sceneCellGroup = newCellGroup;
|
|
|
|
UpdateData(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 00:39:00 +00:00
|
|
|
void SceneEntity::QueryVolumeFromDrawable() { // line 370
|
|
|
|
if (drawable) {
|
|
|
|
drawable->GetBoundingVolume(&cullingVolume);
|
|
|
|
TransformVolumeAndPivot();
|
|
|
|
// TODO
|
|
|
|
} else {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneEntity::TransformVolumeAndPivot() { // line 406
|
|
|
|
cullingVolume.Transform(matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneEntity::UpdateData(bool reInitCell) { // line 464
|
2023-01-12 17:26:09 +00:00
|
|
|
// HACK
|
|
|
|
auto cell = sceneCellGroup->cellByIndex(0);
|
|
|
|
if (reInitCell) {
|
|
|
|
auto subCell = &cell->subCells[0];
|
|
|
|
bool alreadyPresent = false;
|
|
|
|
for (auto ent : subCell->entities)
|
|
|
|
if (ent == this)
|
|
|
|
alreadyPresent = true;
|
|
|
|
if (!alreadyPresent)
|
|
|
|
subCell->entities.push_back(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 17:21:52 +00:00
|
|
|
}
|