libgdx/gdx-ai

Vector3 and Vector2 as interface enhancement.

NemesisMate opened this issue · 4 comments

It would be great if we could work with Vector2 and Vector3 being interfaces so we could share code between different platforms without having to refactor things or having to duplicate vectors.

It can be a good practice to use local attributes, like velocity or positions but in some cases, for memory optimization purposes, or even different usage/programming styles (ie: having the position shared between the steering agent and the visual object so it automatically changes the value) it is comfortable to have the same object.

Using, for example the JME3 engine we have a Vector3f (which is the equivalent to the Vector3). Well, if I want to use the Vector3f I have to make the conversions from them or make a thin wrapper/decorator:
"MyVector3 implements Vector".

This is just fine but the same problem can be found: the code must be done or with Vector3 or with MyVector3 so if I want to put/share that code between engines it is not so straight-forward. However, if Vector3 were an interface (MyVector3 implements Vector3), I could do my code and share it between engines without being aware about refactoring it in so much places and without wasting "so much" resources.

I can't see your point but maybe I'm missing something.
The gdx-ai API only makes use of Vector which is an interface.
Also Vector, Vector2 and Vector3 come from libgdx, not gdx-ai.

Well, I was thinking more on doing a "module" that "works" without the need of any specific engine. In the code in here, you do a SteeringAgent with Vector2. Imagine that you create a SteeringAgent2D or/and a SteeringAgent3D that can work without any specific engine, that implements all calculations and do all the logic stuff. It could allow to make components, agents, that can be instantiated just giving the Vector implementation (or a thin wrap with it) of the used engine.

Just now I'm creating my base AbstractSteeringAgent that relies on three axis vectors, equivalents of Vector3 but for JME3 so I have:

public class AbstractSteeringAgent implements Steerable<Vector3> {

So, all the code that goes to/from this agent must do the translation between Vector3 and Vector3f. If I want to avoid this I have to make a MyVector3f that wraps Vector3f implementing the Vector interface and use it like:

public class AbstractSteeringAgent implements Steerable<MyVector3f> {

If I do that and I want to use my AI module with this agent on other engine or I want to share it with other people from other engines (what would allow to make a gdx-ai library with multiple agents and more) that people would have to adapt that code and it usage would be just "import and use". However, if we had a Vector3D (Vector3D extends Vector) interface in gdx-ai MyVector3f could implement it and so, the code could be used by anyone on any engine just wrapping their Vector3 equivalent.

The problem is that Vector and Vector3 are in libgdx and I suspect that the libgdx dev team is not interested in an additional interface in between.

Hm.. yep, there you got me :S. I suppose that the way for that would be to make your own Vector and make Wrappers for the libgdx Vectors but I doubt it worth it so... here remains the idea ;).