#Impact of having a lot of consumers

1 messages · Page 1 of 1 (latest)

zealous dagger
#

I wonder how Java is handling me creating a bunch of Consumer instances.

I will elaborate for my current scenario. I'm making a small game. When loading the models & scenes, I'm linking a Scene (containing a Model) to for example a Entity. This Scene allows operations like changing the position. When linking a scene to my Entity, I also make sure to give the Entity a Consumer

Let's assume that I will use a Consumer<Pos> to handle position changes.

It would look like this:

class Entity {
  Consumer<Pos> con;
  void changePosition(Pos p) {
    con.accept(p);
  }

  Consumer<Pos> init(Visitor v) {
    this.con = v.load(this);
  }
}

class Visitor {

  Consumer<Pos> load(Entity e) {
    GLTFModel m = new GLTF().load("");
    Scene s = new Scene(m);
    return (pos) -> s.setPos(pos);
  }

}

I will probably use another way of doing this. I wonder what would happen to performance if I had about 1000 or more of these Consumer<Pos> registered. Is it bad for memory? Is it encouraged to do something like this?

brazen roverBOT
#

<@&987246399047479336> please have a look, thanks.

zealous dagger
#

Impact of having a lot of consumers

ripe slate
#

wait

#

what kind of visitor pattern is that?

#

The point of visitor is doing the double indirection already, no need to add a consumer on top

#

Also, what GLTF library are you using? 😛

zealous dagger
#

Yeah I was thinking my visitor was a little wrong

#

I'm using LibGDX for now

#

The reason for the visitor is to have some rotations & positioning done for the model. This way my renderer & my game object don't have to care about it.

#

I will probably have to use some adapter pattern to interact with a Scene from a Entity or something. I just wonder if having this amount of consumers is bad at all (not in the software architecture perspective)

ripe slate
#

libgdx for the gltf?

#

Depends tbh, if the runtime can figure out which consumer is called in a specific spot, it will probably also just inline the implementation

#

But that strongly depends on how it's set up

#

As usual, check the performance first, then figure out why it's slow, then you can improve

#

Don't sweat it too much and just build stuff

zealous dagger
#

Thanks man. I will probably use a class that interacts with the Scene instead of using consumers. More future proof

#

I’m spending enough thoughts on the design to ensure not having to redo everything

ripe slate
#

I roughly model a scene as a collection of instances, where every instance contains a mesh and a rotation/scale/translation

#

every mesh contains primitives with vertex and facebuffers

zealous dagger
#

?