TEST( EntityHandlerTest, AddAndRemoveComponentsTemplate ) { SystemHandler system; EntityHandler entity( &system ); Entity ent1 = entity.CreateEntity(); Entity ent2 = entity.CreateEntity(); entity.AddComponents<Component2,Component3>( ent1, Component2(), Component3() ); entity.AddComponents<Component1,Component3>( ent2, Component1(), Component3() ); ASSERT_EQ( (Aspect)(entity.GenerateAspect<Component2,Component3>()), entity.GetEntityAspect( ent1 ) ); ASSERT_EQ( (Aspect)(1ULL << 0 | 1ULL << 2), entity.GetEntityAspect( ent2 ) ); entity.RemoveComponents<Component2>( ent1 ); entity.RemoveComponents<Component3>( ent2 ); ASSERT_EQ( (Aspect)(entity.GenerateAspect<Component3>()), entity.GetEntityAspect( ent1 ) ); ASSERT_EQ( (Aspect)(1ULL << 0), entity.GetEntityAspect( ent2 ) ); entity.RemoveComponents<Component3>( ent1 ); entity.RemoveComponents<Component1>( ent2 ); ASSERT_EQ( (Aspect)(0ULL), entity.GetEntityAspect( ent1 ) ); ASSERT_EQ( (Aspect)(0ULL), entity.GetEntityAspect( ent2 ) ); }
TEST( EntityHandlerTest, CleanRelease ) { SystemHandler system; EntityHandler instance(&system); Entity ent1 = instance.CreateEntity<Component1,Component3>(Component1(),Component3()); Entity ent2 = instance.CreateEntity<Component1,Component2>(Component1(),Component2()); Entity ent3 = instance.CreateEntity<Component1,Component2,Component3>(Component1(),Component2(),Component3()); Entity ent4 = instance.CreateEntity<Component1>(Component1()); EXPECT_EQ(4,instance.GetEntityCount()); EXPECT_EQ(8,instance.GetComponentCount()); instance.DestroyEntity( ent1 ); EXPECT_EQ(3,instance.GetEntityCount()); EXPECT_EQ(6,instance.GetComponentCount()); instance.DestroyEntity( ent3 ); EXPECT_EQ(2,instance.GetEntityCount()); EXPECT_EQ(3,instance.GetComponentCount()); instance.DestroyEntity( ent2 ); EXPECT_EQ(1,instance.GetEntityCount()); EXPECT_EQ(1,instance.GetComponentCount()); instance.DestroyEntity( ent4 ); EXPECT_EQ(0,instance.GetEntityCount()); EXPECT_EQ(0,instance.GetComponentCount()); }
shared_ptr<UniversalMaterial> UniversalMaterial::create(const std::string& name, const Specification& specification) { MaterialCache& cache = _internal::materialCache(); shared_ptr<UniversalMaterial> value = cache[specification]; if (isNull(value)) { // Construct the appropriate material value.reset(new UniversalMaterial()); value->m_bsdf = UniversalBSDF::create( specification.loadLambertian(), specification.loadGlossy(), specification.loadTransmissive(), specification.m_etaTransmit, specification.m_extinctionTransmit, specification.m_etaReflect, specification.m_extinctionReflect); value->m_depthWriteHintDistance = specification.m_depthWriteHintDistance; value->m_customShaderPrefix = specification.m_customShaderPrefix; value->m_refractionHint = specification.m_refractionHint; value->m_mirrorHint = specification.m_mirrorHint; // load emission map value->m_emissive = specification.loadEmissive(); // load bump map if (! specification.m_bump.texture.filename.empty()) { value->m_bump = BumpMap::create(specification.m_bump); } value->m_name = name; value->m_numLightMapDirections = specification.m_numLightMapDirections; for (int i = 0; i < specification.m_numLightMapDirections; ++i) { value->m_lightMap[i] = Component3(specification.m_lightMapConstant, specification.m_lightMap[i]); } // Update the cache cache.set(specification, value); value->computeDefines(value->m_macros); } return value; }