Skip to content

Commit

Permalink
Added interactor and pathfind support to D2GS
Browse files Browse the repository at this point in the history
Added interactor and pathfind support to D2GS
Removed some special case code from pathfinder -- was forcing reliance on client code in what should be server-only code
  • Loading branch information
collinsmith committed Dec 20, 2019
1 parent 3cd621c commit 866cdc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 8 additions & 13 deletions core/src/com/riiablo/engine/server/Pathfinder.java
Expand Up @@ -4,14 +4,11 @@
import com.artemis.annotations.All;
import com.artemis.annotations.Wire;
import com.artemis.systems.IteratingSystem;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ai.utils.Collision;
import com.badlogic.gdx.ai.utils.Ray;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Pools;
import com.riiablo.Riiablo;
import com.riiablo.camera.IsometricCamera;
import com.riiablo.engine.server.component.Angle;
import com.riiablo.engine.server.component.Pathfind;
import com.riiablo.engine.server.component.Position;
Expand All @@ -36,9 +33,6 @@ public class Pathfinder extends IteratingSystem {
@Wire(name = "map")
protected Map map;

@Wire(name = "iso")
protected IsometricCamera iso;

private final Vector2 tmpVec2 = new Vector2();
private final Ray<Vector2> ray = new Ray<>(new Vector2(), new Vector2());
private final Collision<Vector2> collision = new Collision<>(new Vector2(), new Vector2());
Expand Down Expand Up @@ -77,13 +71,14 @@ protected void process(int entityId) {
}
}

// FIXME: removes much of the jitter for player -- maybe there's a better solution though
if (entityId == Riiablo.game.player && pathfind.path.getCount() <= 1) {
iso.agg(tmpVec2.set(Gdx.input.getX(), Gdx.input.getY())).unproject().toWorld();
}

Angle angle = mAngle.get(entityId);
angle.target.set(tmpVec2.sub(position0)).nor();
/**
* FIXME: there is a lot of jitter here in the direction for shorter movements because of
* repathing every frame-- need to create some kind of target component which is a target
* entity or target point and if it's down to the last remaining waypoint, set angle to
* the actual point or entity.
*/
tmpVec2.sub(position0);
mAngle.get(entityId).target.set(tmpVec2).nor();

velocity.velocity.set(tmpVec2).setLength(speed);
}
Expand Down
7 changes: 7 additions & 0 deletions server/d2gs/src/com/riiablo/server/d2gs/D2GS.java
Expand Up @@ -32,9 +32,13 @@
import com.riiablo.engine.EntityFactory;
import com.riiablo.engine.server.AnimDataResolver;
import com.riiablo.engine.server.CofManager;
import com.riiablo.engine.server.ItemInteractor;
import com.riiablo.engine.server.ObjectInitializer;
import com.riiablo.engine.server.ObjectInteractor;
import com.riiablo.engine.server.Pathfinder;
import com.riiablo.engine.server.ServerEntityFactory;
import com.riiablo.engine.server.ServerNetworkIdManager;
import com.riiablo.engine.server.WarpInteractor;
import com.riiablo.engine.server.component.Networked;
import com.riiablo.map.DS1;
import com.riiablo.map.DS1Loader;
Expand Down Expand Up @@ -219,6 +223,9 @@ public void create() {
.with(new ServerNetworkIdManager())
.with(new CofManager())
.with(new ObjectInitializer())
.with(new ObjectInteractor(), new WarpInteractor(), new ItemInteractor())

.with(new Pathfinder())

.with(factory)
.with(sync)
Expand Down

0 comments on commit 866cdc0

Please sign in to comment.