0

Update: WorldConfiguration and World are still the same,

WorldConfiguration setup = new WorldConfigurationBuilder()
                .with(new HelloSystemArtemis())
                .with(new RenderSystem(batch, environment))
                .with(new BulletSystem(this))
                .with(new PlayerSystem(perspectiveCamera, batch, gameUi, this))
                .with(new AthmosphereSystem(modelComponent,
                        bulletComponent))
                .with(new MovementSystem(this))
                .with(new StatusSystem(this))
                .with(new EnemySystem(this))
                .build();
        World world = new World(setup);
        world.setDelta(delta);
        int entityId = world.create();
        world.edit(entityId).create(HelloComponentArtemis.class).message = "\n\rHello Oxyddians!\n\r";

Decided to post full code for clarity reason, in fact can't explain from where the problem is coming, even if I got errors that point me to

@All({ModelComponentArtemis.class, ModelComponentArtemis.class})
public class AthmosphereSystem extends BaseSystem {
    private static OxyddiA game;
    private static Assets assets = new Assets();
    private ComponentMapper<ModelComponentArtemis> mc;
    private ComponentMapper<BulletComponentArtemis> bc;
    public AthmosphereSystem(ComponentMapper<ModelComponentArtemis> mc,
                             ComponentMapper<BulletComponentArtemis> bc) {
        this.mc = mc;
        this.bc = bc;
    }

    @Override
    protected void processSystem() {
        int entity = world.create();
        ModelComponentArtemis mc = new ModelComponentArtemis(assets.Athmosphere,0,0,0);
        mc.create(entity); //Not working
        BulletComponentArtemis bc = new BulletComponentArtemis();
        btCollisionShape shape = Bullet.obtainStaticNodeShape(assets.Athmosphere.nodes);
        bc.bodyInfo = new   btRigidBody.btRigidBodyConstructionInfo(0, null, shape,   Vector3.Zero);
        bc.body = new btRigidBody(bc.bodyInfo);
        bc.body.userData = entity;
        bc.motionState = new MotionState(mc.instance.transform);
        ((btRigidBody)  bc.body).setMotionState(bc.motionState);
        bc.create(entity); //Not working
        return entity; //Not working as well
    }
}

ModelComponent used in this approach

public class ModelComponentArtemis extends Component {

    public Model model;
    public ModelInstance instance;
    public ModelComponentArtemis(Model model, float x, float y, float z)
    {
        this.model = model;
        this.instance = new ModelInstance(model, new Matrix4().setToTranslation(x, y, z));
    }

    public void reset() {
    }
}

BulletComponent used in this approach

public class BulletComponentArtemis extends Component {
    public MotionState motionState;
    public btRigidBody.btRigidBodyConstructionInfo bodyInfo;
    public btCollisionObject body;
    public Model model;

    public void init() {
        ModelComponentArtemis modelComponent = new ModelComponentArtemis(model,0,0,0);
        BulletComponentArtemis bulletComponent = new BulletComponentArtemis();
        btCollisionShape shape = Bullet.obtainStaticNodeShape(model.nodes);
        bulletComponent.bodyInfo = new   btRigidBody.btRigidBodyConstructionInfo(0, null, shape,   Vector3.Zero);
        bulletComponent.body = new btRigidBody(bulletComponent.bodyInfo);
        Object bCuD = null;
        bulletComponent.body.userData = bCuD;
        bulletComponent.motionState = new MotionState(modelComponent.instance.transform);
        ((btRigidBody)  bulletComponent.body).setMotionState(bulletComponent.motionState);
    }

    public void reset() {
    }
}

And of course the BulletSystem used in this project

@All(ModelComponentArtemis.class)
public class BulletSystem extends EntitySystem
{
    public Entity e;
    public final btCollisionConfiguration collisionConfiguration;
    public final btCollisionDispatcher dispatcher;
    public final btBroadphaseInterface broadphase;
    public final btConstraintSolver solver;
    public final btDiscreteDynamicsWorld collisionWorld;
    public GameWorld gameWorld;
    public PreGameWorld preGameWorld;
    private final btGhostPairCallback ghostPairCallback;
    public final int maxSubSteps = 5;
    public final float fixedTimeStep = 0.2f / 60f;
    private EntityContactListener myContactListener;

    public BulletSystem(GameWorld gameWorld)
    {
        super(Aspect.all(ModelComponentArtemis.class));
        this.gameWorld = gameWorld;
        myContactListener = new EntityContactListener();
        myContactListener.enable();

        collisionConfiguration = new btDefaultCollisionConfiguration();
        dispatcher = new btCollisionDispatcher(collisionConfiguration);
        broadphase = new btAxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
        solver = new btSequentialImpulseConstraintSolver();
        collisionWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
        ghostPairCallback = new btGhostPairCallback();
        broadphase.getOverlappingPairCache().setInternalGhostPairCallback(ghostPairCallback);
        this.collisionWorld.setGravity(new Vector3(0f, -0.5f, 0f));
    }

    public BulletSystem(PreGameWorld preGameWorld)
    {
        this.preGameWorld = preGameWorld;
        myContactListener = new EntityContactListener();
        myContactListener.enable();

        collisionConfiguration = new btDefaultCollisionConfiguration();
        dispatcher = new btCollisionDispatcher(collisionConfiguration);
        broadphase = new btAxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
        solver = new btSequentialImpulseConstraintSolver();
        collisionWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
        ghostPairCallback = new btGhostPairCallback();
        broadphase.getOverlappingPairCache().setInternalGhostPairCallback(ghostPairCallback);
        this.collisionWorld.setGravity(new Vector3(0f, -0.5f, 0f));
    }

    public void update(float deltaTime)
    {
        collisionWorld.stepSimulation(deltaTime, maxSubSteps, fixedTimeStep);
    }

    protected void processSystem(int entityId) {
        this.world.getEntity(entityId).getComponent(BulletComponentArtemis.class);
    }

    @Override
    protected void processSystem() {
    }

    public void dispose()
    {
        collisionWorld.dispose();
        if (solver != null) solver.dispose();
        if (broadphase != null) broadphase.dispose();
        if (dispatcher != null) dispatcher.dispose();
        if (collisionConfiguration != null)
            collisionConfiguration.dispose();
        ghostPairCallback.dispose();
    }
}

With all that in mind, I know I just can't find any solution, Maybe it will be clearer like that for anyone wishing to help Thanks anyawy.

Oxydeme
  • 41
  • 6

1 Answers1

0

Couple of things to note:

  1. you don't need to inject entity instances
  2. working with Entity and EntityEdit is slower than working with int and ComponentMapper/Archetype/EntityTransmuter, but fine for the beginning.

What you probably want to do is creating an AtmosphereSystem (extending BaseSystem) and create the entity within the initialize method or offer a public method (non-static).

If you need to call those entity factory methods, just inject the AtmosphereSystem (or anything extending BaseSystem) by adding a field "AtmosphereSystem atmosphereSytem;" inside any other BaseSystem.

See this gist for a similar use case (factory methods for creating entities).

Ken S
  • 206
  • 2
  • 5
  • Thanks, applyed it and now a new error appeared while testing, gonna add more code it time – Oxydeme Aug 13 '20 at 14:34
  • Can a system be invoked from another simply, like in for example general system, invoking managing system from there? then if I do add the general system to world, will the secondly system be used or should I add every systems to the world? Other than that, can seem to find a clear way of creating an entity, even if I've read the artemis wiki, even I implemented the base explained system, can't find a way to create correct entity, even if I pass world in constructor, still throwing the exception – Oxydeme Aug 13 '20 at 21:44
  • You can inject any other system registered in the world (same as you did with HelloSystemArtemis, RenderSystem and so on) by just adding a field to any other BaseSystem (or anything injected via `world.inject(someObj)`. See this gist: https://gist.github.com/schosin/f5e15233181434da9668bfac83a60fa2 For creating entities, see this gist: https://gist.github.com/schosin/8c6e5463c1380b5afa77d0a797968dfe It creates the entity by calling `int entity = world.create()` and components are added using `posM.create(entity)` and so on. – Ken S Aug 14 '20 at 05:53
  • Is var a variable? a created usefull class, anything integrated to Artemis? – Oxydeme Aug 14 '20 at 11:16
  • Man I decided to detail my code, as said code would come, For anyone, and you to understand what I'm doing wrong, I posted it – Oxydeme Aug 14 '20 at 11:46