use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.
the class Entity method replaceComponentInternal.
private void replaceComponentInternal(int index, IComponent replacement) {
IComponent previousComponent = _components[index];
if (replacement != previousComponent) {
_components[index] = replacement;
_componentsCache = null;
if (replacement != null) {
notifyComponentReplaced(index, previousComponent, replacement);
} else {
_componentIndicesCache = null;
notifyComponentRemoved(index, previousComponent);
}
getComponentPool(index).push(previousComponent);
} else {
notifyComponentReplaced(index, previousComponent, replacement);
}
}
use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.
the class Entity method getComponents.
@Override
public IComponent[] getComponents() {
if (_componentsCache == null) {
List<IComponent> componentsCache = EntitasCache.getIComponentList();
for (int i = 0; i < _components.length; i++) {
IComponent component = _components[i];
if (component != null) {
componentsCache.add(component);
}
}
_componentsCache = new IComponent[componentsCache.size()];
componentsCache.toArray(_componentsCache);
EntitasCache.pushIComponentList(componentsCache);
}
return _componentsCache;
}
use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.
the class ContextTest method updateGroupsComponentReplacedTest.
@Test
public void updateGroupsComponentReplacedTest() {
Position position = new Position();
Position position2 = new Position();
Group<TestEntity> groupE = context.getGroup(TestMatcher.Position());
groupE.OnEntityUpdated((IGroup<TestEntity> group, final TestEntity entity, int index, IComponent previousComponent, IComponent nc) -> {
System.out.println("Removed...........");
assertEquals(position2, nc);
});
entity.addComponent(TestComponentIds.Position, position);
context.updateGroupsComponentReplaced(entity, TestComponentIds.Position, position, position2, context._groupsForIndex);
}
use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.
the class SceneManagerGDX method initialize.
@Override
public void initialize() {
if (engine.getManager(PhysicsManagerGDX.class) == null)
throw new EntitasException("SceneManagerGDX", "SceneManagerGDX needs load PhysicsManagerGDX on the engine");
physics = engine.getManager(PhysicsManagerGDX.class);
rayHandler = new RayHandler(physics.getPhysics());
PreferencesManagerGDX preferences = engine.getManager(PreferencesManagerGDX.class);
rayHandler.setAmbientLight(preferences.AMBIENT_LIGHT);
rayHandler.setBlur(preferences.BLUR);
rayHandler.setCulling(preferences.CULLING);
rayHandler.setGammaCorrection(preferences.GAMMA_CORRECTION);
rayHandler.setBlurNum(preferences.BLUR_NUM);
rayHandler.setShadows(preferences.SHADOWS);
rayHandler.useDiffuseLight(preferences.USE_DIFFUSE_LIGHT);
//rayHandler.update();
AssetsManagerGDX assetsManager = engine.getManager(AssetsManagerGDX.class);
for (EntityFactory factory : entityFactories.values()) {
factory.loadAssets(engine);
}
assetsManager.finishLoading();
addLightFactory(PointLight.class, (SceneManager sceneManager, IComponent c) -> {
CPointLight component = (CPointLight) c;
return new PointLight(rayHandler, component.raysNum, component.color, component.distance, component.position.x, component.position.y);
});
addLightFactory(DirectionalLight.class, (SceneManager sceneManager, IComponent c) -> {
LogManagerGDX.debug("SceneManager", "create directional ligth");
CDirectionalLight component = (CDirectionalLight) c;
return new DirectionalLight(rayHandler, component.raysNum, component.color, component.direcction);
});
addLightFactory(ChainLight.class, (SceneManager sceneManager, IComponent c) -> {
LogManagerGDX.debug("SceneManager", "create ChainLight");
CChainLight component = (CChainLight) c;
return new ChainLight(rayHandler, component.raysNum, component.color, component.distance, component.rayDirecction, component.chain);
});
addLightFactory(ConeLight.class, (SceneManager sceneManager, IComponent c) -> {
LogManagerGDX.debug("SceneManager", "create ConeLight");
CConeLight component = (CConeLight) c;
return new ConeLight(rayHandler, component.raysNum, component.color, component.distance, component.position.x, component.position.y, component.directionDegree, component.coneDegree);
});
}
use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.
the class ContextTest method clearComponentPoolTest.
@Test
public void clearComponentPoolTest() {
Stack[] cpool = context.getComponentPools();
cpool[0] = new Stack<IComponent>();
cpool[0].push(new Position());
assertEquals(1, cpool[0].size());
context.clearComponentPool(0);
assertTrue(cpool[0].empty());
}
Aggregations