Commit 36b71d01 authored by AnimeGitB's avatar AnimeGitB
Browse files

Clean up some Position usage to avoid unneccessary unpacks

parent dbf2b91d
...@@ -13,7 +13,6 @@ import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType; ...@@ -13,7 +13,6 @@ import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq; import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq;
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo; import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp; import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
public class GadgetGatherObject extends GadgetContent { public class GadgetGatherObject extends GadgetContent {
...@@ -69,11 +68,10 @@ public class GadgetGatherObject extends GadgetContent { ...@@ -69,11 +68,10 @@ public class GadgetGatherObject extends GadgetContent {
scene, scene,
player, player,
GameData.getItemDataMap().get(itemId), GameData.getItemDataMap().get(itemId),
new Position( getGadget().getPosition().clone()
getGadget().getPosition().getX() + (float)Utils.randomRange(1,5) / 5, .addY(2f)
getGadget().getPosition().getY() + 2f, .addX(Utils.randomFloatRange(-1f, 1f))
getGadget().getPosition().getZ() + (float)Utils.randomRange(1,5) / 5 .addZ(Utils.randomFloatRange(-1f, 1f)),
),
1, 1,
true); true);
......
...@@ -11,7 +11,6 @@ import emu.grasscutter.game.world.Scene; ...@@ -11,7 +11,6 @@ import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.GatherGadgetInfoOuterClass.GatherGadgetInfo; import emu.grasscutter.net.proto.GatherGadgetInfoOuterClass.GatherGadgetInfo;
import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq; import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq;
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo; import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
public class GadgetGatherPoint extends GadgetContent { public class GadgetGatherPoint extends GadgetContent {
...@@ -61,14 +60,13 @@ public class GadgetGatherPoint extends GadgetContent { ...@@ -61,14 +60,13 @@ public class GadgetGatherPoint extends GadgetContent {
for (int i = 0 ; i < times ; i++) { for (int i = 0 ; i < times ; i++) {
EntityItem item = new EntityItem( EntityItem item = new EntityItem(
scene, scene,
player, player,
GameData.getItemDataMap().get(itemId), GameData.getItemDataMap().get(itemId),
new Position( getGadget().getPosition().clone()
getGadget().getPosition().getX() + (float)Utils.randomRange(1,5) / 5, .addY(2f)
getGadget().getPosition().getY() + 2f, .addX(Utils.randomFloatRange(-1f, 1f))
getGadget().getPosition().getZ() + (float)Utils.randomRange(1,5) / 5 .addZ(Utils.randomFloatRange(-1f, 1f)),
),
1, 1,
true); true);
......
...@@ -25,11 +25,7 @@ public class MapMark { ...@@ -25,11 +25,7 @@ public class MapMark {
public MapMark(MapMarkPoint mapMarkPoint) { public MapMark(MapMarkPoint mapMarkPoint) {
this.sceneId = mapMarkPoint.getSceneId(); this.sceneId = mapMarkPoint.getSceneId();
this.name = mapMarkPoint.getName(); this.name = mapMarkPoint.getName();
this.position = new Position( this.position = new Position(mapMarkPoint.getPos());
mapMarkPoint.getPos().getX(),
mapMarkPoint.getPos().getY(),
mapMarkPoint.getPos().getZ()
);
this.mapMarkPointType = mapMarkPoint.getPointType(); this.mapMarkPointType = mapMarkPoint.getPointType();
this.monsterId = mapMarkPoint.getMonsterId(); this.monsterId = mapMarkPoint.getMonsterId();
this.mapMarkFromType = mapMarkPoint.getFromType(); this.mapMarkFromType = mapMarkPoint.getFromType();
......
...@@ -497,11 +497,7 @@ public class StaminaManager extends BasePlayerManager { ...@@ -497,11 +497,7 @@ public class StaminaManager extends BasePlayerManager {
} }
} }
previousState = currentState; previousState = currentState;
previousCoordinates = new Position( previousCoordinates = currentCoordinates.clone();
currentCoordinates.getX(),
currentCoordinates.getY(),
currentCoordinates.getZ()
);
} }
} }
......
...@@ -17,19 +17,17 @@ public class HandlerPersonalSceneJumpReq extends PacketHandler { ...@@ -17,19 +17,17 @@ public class HandlerPersonalSceneJumpReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
PersonalSceneJumpReq req = PersonalSceneJumpReq.parseFrom(payload); PersonalSceneJumpReq req = PersonalSceneJumpReq.parseFrom(payload);
var player = session.getPlayer();
// get the scene point // get the scene point
String code = session.getPlayer().getSceneId() + "_" + req.getPointId(); String code = player.getSceneId() + "_" + req.getPointId();
ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(code); ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(code);
if (scenePointEntry != null) { if (scenePointEntry != null) {
float x = scenePointEntry.getPointData().getTranPos().getX(); Position pos = scenePointEntry.getPointData().getTranPos().clone(); // This might not need cloning
float y = scenePointEntry.getPointData().getTranPos().getY();
float z = scenePointEntry.getPointData().getTranPos().getZ();
Position pos = new Position(x, y, z);
int sceneId = scenePointEntry.getPointData().getTranSceneId(); int sceneId = scenePointEntry.getPointData().getTranSceneId();
session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), sceneId, pos); player.getWorld().transferPlayerToScene(player, sceneId, pos);
session.send(new PacketPersonalSceneJumpRsp(sceneId, pos)); session.send(new PacketPersonalSceneJumpRsp(sceneId, pos));
} }
......
...@@ -9,7 +9,6 @@ import emu.grasscutter.net.packet.PacketHandler; ...@@ -9,7 +9,6 @@ import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp; import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.SceneTransToPointReq) @Opcodes(PacketOpcodes.SceneTransToPointReq)
public class HandlerSceneTransToPointReq extends PacketHandler { public class HandlerSceneTransToPointReq extends PacketHandler {
...@@ -17,21 +16,19 @@ public class HandlerSceneTransToPointReq extends PacketHandler { ...@@ -17,21 +16,19 @@ public class HandlerSceneTransToPointReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload); SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload);
var player = session.getPlayer();
String code = req.getSceneId() + "_" + req.getPointId(); String code = req.getSceneId() + "_" + req.getPointId();
ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(code); ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(code);
if (scenePointEntry != null) { if (scenePointEntry != null) {
float x = scenePointEntry.getPointData().getTranPos().getX(); if (player.getWorld().transferPlayerToScene(player, req.getSceneId(), TeleportType.WAYPOINT, scenePointEntry.getPointData().getTranPos().clone())) {
float y = scenePointEntry.getPointData().getTranPos().getY(); session.send(new PacketSceneTransToPointRsp(player, req.getPointId(), req.getSceneId()));
float z = scenePointEntry.getPointData().getTranPos().getZ(); return;
if (session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getSceneId(), TeleportType.WAYPOINT, new Position(x, y, z))) {
session.send(new PacketSceneTransToPointRsp(session.getPlayer(), req.getPointId(), req.getSceneId()));
} }
} else {
session.send(new PacketSceneTransToPointRsp());
} }
session.send(new PacketSceneTransToPointRsp());
} }
} }
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.managers.mapmark.MapMark; import emu.grasscutter.game.managers.mapmark.MapMark;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.*; import emu.grasscutter.net.proto.*;
...@@ -21,13 +20,7 @@ public class PacketMarkMapRsp extends BasePacket { ...@@ -21,13 +20,7 @@ public class PacketMarkMapRsp extends BasePacket {
MapMarkPointOuterClass.MapMarkPoint.Builder markPoint = MapMarkPointOuterClass.MapMarkPoint.newBuilder(); MapMarkPointOuterClass.MapMarkPoint.Builder markPoint = MapMarkPointOuterClass.MapMarkPoint.newBuilder();
markPoint.setSceneId(mapMark.getSceneId()); markPoint.setSceneId(mapMark.getSceneId());
markPoint.setName(mapMark.getName()); markPoint.setName(mapMark.getName());
markPoint.setPos(mapMark.getPosition().toProto());
VectorOuterClass.Vector.Builder positionVector = VectorOuterClass.Vector.newBuilder();
positionVector.setX(mapMark.getPosition().getX());
positionVector.setY(mapMark.getPosition().getY());
positionVector.setZ(mapMark.getPosition().getZ());
markPoint.setPos(positionVector.build());
markPoint.setPointType(mapMark.getMapMarkPointType()); markPoint.setPointType(mapMark.getMapMarkPointType());
markPoint.setFromType(mapMark.getMapMarkFromType()); markPoint.setFromType(mapMark.getMapMarkFromType());
markPoint.setMonsterId(mapMark.getMonsterId()); markPoint.setMonsterId(mapMark.getMonsterId());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment