dimanche 7 février 2021

What is this called, is the performance reasonable and should I do it?

I'm writing a java game engine once again, and I've decided to take a different approach.

I'm writing interfaces for every part that of the engine that has to be exposed. Then I'll write package-private classes to implement the engine.

(I think it's called the bridge pattern. This way the entire engine can be implemented in many different ways, and it makes the engine more modular.)

The problem I'm running into right now is that there's many 3rd party libraries that I'll be using, but probably not extending, and I don't know how I should go about adding them and letting the people who will use my engine interact with them.

I was thinking of something that I think is called encapsulation, or delegation, but I'm not sure.

For a vector class, it could look something like this:

// Class from another library
class Vector2f {
  public float x, y;

  public void scale(float scalar) {
    x *= scalar;
    y *= scalar;
  }
}

// Public interface from my library
class Vec2 {
  float x, y;

  void mult(float scalar);
}

// Package-private/private implementation from my library
class Vec2Impl extends Vector2f implements Vec2 {
  public void mult(float scalar) {
    super.scale(scalar);
  }
}

Would this work? Do you like this approach and would you like working with it? How much would it affect performance? Considering this is a game engine, and classes like Vectors are intensively used... Please just give me some arguments on why or why not to use this pattern, and what it might be called.

Aucun commentaire:

Enregistrer un commentaire