Skip to content

Commit

Permalink
#5443: Add unit test checking that light bounds change after modifyin…
Browse files Browse the repository at this point in the history
…g the spawnarg
  • Loading branch information
codereader committed Dec 25, 2020
1 parent f2ca16a commit e6b6725
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/Selection.cpp
Expand Up @@ -3,11 +3,15 @@
#include "ishaders.h"
#include "imap.h"
#include "ifilter.h"
#include "ilightnode.h"
#include "ibrush.h"
#include "ipatch.h"
#include "ientity.h"
#include "ieclass.h"
#include "algorithm/Scene.h"
#include "scenelib.h"
#include "selectionlib.h"
#include "string/convert.h"

namespace test
{
Expand Down Expand Up @@ -47,4 +51,30 @@ TEST_F(SelectionTest, ApplyShadersToForcedVisibleObjects)
EXPECT_EQ(patchNode->getPatch().getShader(), ("textures/common/caulk"));
}

// #5443: Size display of lights doesn't change when modifying "light_radius"
TEST_F(SelectionTest, LightBoundsChangedAfterRadiusChange)
{
auto eclass = GlobalEntityClassManager().findOrInsert("light", false);
auto entityNode = GlobalEntityModule().createEntity(eclass);

EXPECT_TRUE(Node_getLightNode(entityNode));
auto* entity = Node_getEntity(entityNode);
entity->setKeyValue("light_radius", "300 200 100");
GlobalMapModule().getRoot()->addChildNode(entityNode);

Node_setSelected(entityNode, true);

auto defaultBounds = string::convert<Vector3>(entity->getKeyValue("light_radius"));

EXPECT_TRUE(GlobalSelectionSystem().getWorkZone().bounds.getExtents().isEqual(defaultBounds, 0.01));

// Modify just the light_radius spawnarg
entity->setKeyValue("light_radius", "30 20 10");

// The work zone should have adapted itself to the new bounds
// assuming that the LightNode recalculates its AABB
auto changedBounds = string::convert<Vector3>(entity->getKeyValue("light_radius"));
EXPECT_TRUE(GlobalSelectionSystem().getWorkZone().bounds.getExtents().isEqual(changedBounds, 0.01));
}

}
11 changes: 11 additions & 0 deletions test/resources/tdm/def/lights.def
@@ -0,0 +1,11 @@
entityDef light
{
"editor_light" "1"
"editor_color" "0 1 0"
"editor_mins" "-8 -8 -8"
"editor_maxs" "8 8 8"
"editor_rotatable" "1"

"editor_displayFolder" "Lights/Sources"
"spawnclass" "idLight"
}

0 comments on commit e6b6725

Please sign in to comment.