mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
add playernames to radar
This commit is contained in:
parent
1cd5c53156
commit
200c211623
7 changed files with 83 additions and 12 deletions
|
|
@ -1410,9 +1410,11 @@ class MarbleWorld extends Scheduler {
|
||||||
this.predictions.removeMarbleFromPrediction(otherMarble);
|
this.predictions.removeMarbleFromPrediction(otherMarble);
|
||||||
this.scene.removeChild(otherMarble);
|
this.scene.removeChild(otherMarble);
|
||||||
this.collisionWorld.removeMarbleEntity(otherMarble.collider);
|
this.collisionWorld.removeMarbleEntity(otherMarble.collider);
|
||||||
|
this.collisionWorld.removeMovingEntity(otherMarble.collider);
|
||||||
this.playGui.removePlayer(cc.id);
|
this.playGui.removePlayer(cc.id);
|
||||||
this.clientMarbles.remove(cc);
|
this.clientMarbles.remove(cc);
|
||||||
otherMarble.dispose();
|
otherMarble.dispose();
|
||||||
|
this.marbles.remove(otherMarble);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -592,7 +592,7 @@ class PreviewWorld extends Scheduler {
|
||||||
marb.controllable = false;
|
marb.controllable = false;
|
||||||
marb.init(null, null, () -> {
|
marb.init(null, null, () -> {
|
||||||
marb.collisionWorld = this.collisionWorld;
|
marb.collisionWorld = this.collisionWorld;
|
||||||
this.collisionWorld.addMovingEntity(marb.collider);
|
// this.collisionWorld.addMovingEntity(marb.collider);
|
||||||
this.scene.addChild(marb);
|
this.scene.addChild(marb);
|
||||||
this.marbles.push(marb);
|
this.marbles.push(marb);
|
||||||
onFinish(marb);
|
onFinish(marb);
|
||||||
|
|
@ -602,7 +602,7 @@ class PreviewWorld extends Scheduler {
|
||||||
public function removeMarble(marb:Marble) {
|
public function removeMarble(marb:Marble) {
|
||||||
if (this.marbles.remove(marb)) {
|
if (this.marbles.remove(marb)) {
|
||||||
this.scene.removeChild(marb);
|
this.scene.removeChild(marb);
|
||||||
this.collisionWorld.removeMovingEntity(marb.collider);
|
// this.collisionWorld.removeMovingEntity(marb.collider);
|
||||||
marb.dispose();
|
marb.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
67
src/Radar.hx
67
src/Radar.hx
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import hxd.res.BitmapFont;
|
||||||
import h3d.Matrix;
|
import h3d.Matrix;
|
||||||
import src.DtsObject;
|
import src.DtsObject;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
|
|
@ -8,6 +9,9 @@ import src.GameObject;
|
||||||
import h2d.Scene;
|
import h2d.Scene;
|
||||||
import src.MarbleWorld;
|
import src.MarbleWorld;
|
||||||
import src.Util;
|
import src.Util;
|
||||||
|
import src.Marble;
|
||||||
|
import src.Settings;
|
||||||
|
import src.ResourceLoader;
|
||||||
|
|
||||||
class Radar {
|
class Radar {
|
||||||
var level:MarbleWorld;
|
var level:MarbleWorld;
|
||||||
|
|
@ -15,6 +19,8 @@ class Radar {
|
||||||
|
|
||||||
var g:Graphics;
|
var g:Graphics;
|
||||||
|
|
||||||
|
var marbleNameTexts:Array<h2d.Text>;
|
||||||
|
|
||||||
public var ellipseScreenFraction = new Vector(0.79, 0.9);
|
public var ellipseScreenFraction = new Vector(0.79, 0.9);
|
||||||
public var fullArrowLength = 60.0;
|
public var fullArrowLength = 60.0;
|
||||||
public var fullArrowWidth = 40.0;
|
public var fullArrowWidth = 40.0;
|
||||||
|
|
@ -29,6 +35,7 @@ class Radar {
|
||||||
public function new(level:MarbleWorld, scene2d:Scene) {
|
public function new(level:MarbleWorld, scene2d:Scene) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.scene2d = scene2d;
|
this.scene2d = scene2d;
|
||||||
|
this.marbleNameTexts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
|
|
@ -54,6 +61,32 @@ class Radar {
|
||||||
if (@:privateAccess level.endPad != null && gemCount == 0) {
|
if (@:privateAccess level.endPad != null && gemCount == 0) {
|
||||||
renderArrow(@:privateAccess level.endPad.getAbsPos().getPosition(), 0xE6E6E6);
|
renderArrow(@:privateAccess level.endPad.getAbsPos().getPosition(), 0xE6E6E6);
|
||||||
}
|
}
|
||||||
|
var fadeDistance = level.scene.camera.zFar * 0.1;
|
||||||
|
for (marbleName in marbleNameTexts) {
|
||||||
|
if (marbleName != null)
|
||||||
|
marbleName.alpha = 0;
|
||||||
|
}
|
||||||
|
for (marble in level.marbles) {
|
||||||
|
if (marble != level.marble) {
|
||||||
|
var shapePos = marble.getAbsPos().getPosition();
|
||||||
|
var shapeDir = shapePos.sub(level.scene.camera.pos);
|
||||||
|
var shapeDist = shapeDir.lengthSq();
|
||||||
|
if (shapeDist == 0 || shapeDist > level.scene.camera.zFar * level.scene.camera.zFar) {
|
||||||
|
dontRenderName(marble);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var validProjection = frustumHasPoint(level.scene.camera.frustum, shapePos);
|
||||||
|
if (!validProjection) {
|
||||||
|
dontRenderName(marble);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
shapePos.z += 0.5; // Vertical offset
|
||||||
|
|
||||||
|
var projectedPos = level.scene.camera.project(shapePos.x, shapePos.y, shapePos.z, scene2d.width, scene2d.height);
|
||||||
|
var opacity = (shapeDist < fadeDistance) ? 1.0 : (1.0 - (shapeDist - fadeDistance) / (level.scene.camera.zFar - fadeDistance));
|
||||||
|
renderName(projectedPos, marble, opacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,6 +103,12 @@ class Radar {
|
||||||
g.clear();
|
g.clear();
|
||||||
scene2d.removeChild(g);
|
scene2d.removeChild(g);
|
||||||
g = null;
|
g = null;
|
||||||
|
for (txt in marbleNameTexts) {
|
||||||
|
if (txt != null) {
|
||||||
|
scene2d.removeChild(txt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
marbleNameTexts = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline function planeDistance(plane:h3d.col.Plane, p:Vector) {
|
inline function planeDistance(plane:h3d.col.Plane, p:Vector) {
|
||||||
|
|
@ -388,4 +427,32 @@ class Radar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderName(pos:Vector, marble:Marble, opacity:Float) {
|
||||||
|
var marbleId = @:privateAccess marble.connection.getMarbleId();
|
||||||
|
while (marbleNameTexts.length <= marbleId)
|
||||||
|
marbleNameTexts.push(null);
|
||||||
|
if (marbleNameTexts[marbleId] == null) {
|
||||||
|
var arialb14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
|
||||||
|
var arialb14b = new BitmapFont(arialb14fontdata.entry);
|
||||||
|
@:privateAccess arialb14b.loader = ResourceLoader.loader;
|
||||||
|
var arialBold14 = arialb14b.toSdfFont(cast 16 * Settings.uiScale, MultiChannel);
|
||||||
|
|
||||||
|
marbleNameTexts[marbleId] = new h2d.Text(arialBold14, scene2d);
|
||||||
|
marbleNameTexts[marbleId].textColor = 0xFFFF00;
|
||||||
|
}
|
||||||
|
var textObj = marbleNameTexts[marbleId];
|
||||||
|
textObj.text = @:privateAccess marble.connection.getName();
|
||||||
|
textObj.setPosition(pos.x - textObj.textWidth / 2, pos.y - textObj.textHeight);
|
||||||
|
textObj.alpha = opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dontRenderName(marble:Marble) {
|
||||||
|
var marbleId = @:privateAccess marble.connection.getMarbleId();
|
||||||
|
while (marbleNameTexts.length <= marbleId)
|
||||||
|
marbleNameTexts.push(null);
|
||||||
|
if (marbleNameTexts[marbleId] != null) {
|
||||||
|
marbleNameTexts[marbleId].alpha = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,8 @@ class CollisionWorld {
|
||||||
|
|
||||||
public function removeMovingEntity(entity:CollisionEntity) {
|
public function removeMovingEntity(entity:CollisionEntity) {
|
||||||
this.dynamicEntities.remove(entity);
|
this.dynamicEntities.remove(entity);
|
||||||
|
this.dynamicOctree.remove(entity);
|
||||||
|
this.dynamicEntitySet.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateTransform(entity:CollisionEntity) {
|
public function updateTransform(entity:CollisionEntity) {
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ import net.NetPacket.GemPickupPacket;
|
||||||
class GemPredictionStore {
|
class GemPredictionStore {
|
||||||
var predictions:Array<Bool>;
|
var predictions:Array<Bool>;
|
||||||
|
|
||||||
public function new() {
|
public inline function new() {
|
||||||
predictions = [];
|
predictions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alloc() {
|
public inline function alloc() {
|
||||||
predictions.push(true);
|
predictions.push(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -18,11 +18,11 @@ class GemPredictionStore {
|
||||||
return predictions[netIndex];
|
return predictions[netIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function acknowledgeGemPickup(packet:GemPickupPacket) {
|
public inline function acknowledgeGemPickup(packet:GemPickupPacket) {
|
||||||
predictions[packet.gemId] = true;
|
predictions[packet.gemId] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function acknowledgeGemSpawn(packet:GemSpawnPacket) {
|
public inline function acknowledgeGemSpawn(packet:GemSpawnPacket) {
|
||||||
for (gemId in packet.gemIds)
|
for (gemId in packet.gemIds)
|
||||||
predictions[gemId] = false;
|
predictions[gemId] = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,12 @@ class MoveManager {
|
||||||
var maxMoves = 45;
|
var maxMoves = 45;
|
||||||
var maxSendMoveListSize = 30;
|
var maxSendMoveListSize = 30;
|
||||||
|
|
||||||
var serverTargetMoveListSize = 4;
|
var serverTargetMoveListSize = 3;
|
||||||
var serverMaxMoveListSize = 8;
|
var serverMaxMoveListSize = 8;
|
||||||
var serverAvgMoveListSize = 4.0;
|
var serverAvgMoveListSize = 3.0;
|
||||||
var serverSmoothMoveAvg = 0.15;
|
var serverSmoothMoveAvg = 0.15;
|
||||||
var serverMoveListSizeSlack = 1.5;
|
var serverMoveListSizeSlack = 1.5;
|
||||||
var serverDefaultMinTargetMoveListSize = 4;
|
var serverDefaultMinTargetMoveListSize = 3;
|
||||||
var serverAbnormalMoveCount = 0;
|
var serverAbnormalMoveCount = 0;
|
||||||
var serverLastRecvMove = 0;
|
var serverLastRecvMove = 0;
|
||||||
var serverLastAckMove = 0;
|
var serverLastAckMove = 0;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ import net.NetPacket.PowerupPickupPacket;
|
||||||
class PowerupPredictionStore {
|
class PowerupPredictionStore {
|
||||||
var predictions:Array<Float>;
|
var predictions:Array<Float>;
|
||||||
|
|
||||||
public function new() {
|
public inline function new() {
|
||||||
predictions = [];
|
predictions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alloc() {
|
public inline function alloc() {
|
||||||
predictions.push(Math.NEGATIVE_INFINITY);
|
predictions.push(Math.NEGATIVE_INFINITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ class PowerupPredictionStore {
|
||||||
return predictions[netIndex];
|
return predictions[netIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function acknowledgePowerupPickup(packet:PowerupPickupPacket, timeState:TimeState, futureTicks:Int) {
|
public inline function acknowledgePowerupPickup(packet:PowerupPickupPacket, timeState:TimeState, futureTicks:Int) {
|
||||||
predictions[packet.powerupItemId] = timeState.currentAttemptTime - futureTicks * 0.032; // Approximate
|
predictions[packet.powerupItemId] = timeState.currentAttemptTime - futureTicks * 0.032; // Approximate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue