Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions server/player/debug/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type Arrow struct {
// HeadSegments is the number of segments that the head of the arrow will be drawn with. The more
// segments, the smoother the head will look. If zero, it will default to 4.
HeadSegments int
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand All @@ -70,6 +73,9 @@ type Box struct {
// Bounds is the size of the box in the world, acting as an offset from the Position. If empty,
// it will default to a 1x1x1 box.
Bounds mgl64.Vec3
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand All @@ -88,6 +94,9 @@ type Circle struct {
// Segments is the number of segments that the circle will be drawn with. The more segments, the smoother
// the circle will look. If empty, it will default to 20.
Segments int
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand All @@ -103,6 +112,9 @@ type Line struct {
// EndPosition is the end position of the line in the world. The line will be drawn from Position to
// EndPosition.
EndPosition mgl64.Vec3
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand All @@ -121,6 +133,9 @@ type Sphere struct {
// Segments is the number of segments that the circle will be drawn with. The more segments, the smoother
// the circle will look. If empty, it will default to 20.
Segments int
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand Down Expand Up @@ -158,6 +173,9 @@ type Text struct {
// HideBackfaceText specifies whether the text should be hidden on the back side of the shape.
// Has no visible effect unless LockRotation is also set.
HideBackfaceText bool
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand Down Expand Up @@ -185,6 +203,9 @@ type Cylinder struct {
// Segments is the number of segments that the cylinder will be drawn with. The more segments, the
// smoother the cylinder will look. If zero, it will default to 20.
Segments int
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand All @@ -206,6 +227,9 @@ type Pyramid struct {
Depth float64
// Height is the height of the pyramid. If zero, it will default to 1.0.
Height float64
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand All @@ -227,6 +251,9 @@ type Ellipsoid struct {
// SegmentsPerAxis is the number of segments that the ellipsoid will be drawn with per axis. The more
// segments, the smoother the ellipsoid will look. If zero, it will default to 20.
SegmentsPerAxis int
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
Expand All @@ -250,6 +277,9 @@ type Cone struct {
// Segments is the number of segments that the cone will be drawn with. The more segments, the smoother
// the cone will look. If zero, it will default to 20.
Segments int
// MaxRenderDistance is the distance from the camera beyond which the client stops drawing the shape. If zero,
// the client draws it at any distance.
MaxRenderDistance float64
// Entity is an optional entity handle to attach the shape to.
Entity *world.EntityHandle
}
31 changes: 31 additions & 0 deletions server/session/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,34 @@ func (s *Session) shapeAttachedEntityRuntimeID(shape debug.Shape) uint64 {
return s.handleRuntimeID(handle)
}

// debugShapeMaxDistance returns the distance beyond which the client stops drawing a debug shape. Every shape
// carries one, but it is a field rather than a method, so each type has to be named.
func debugShapeMaxDistance(shape debug.Shape) float64 {
switch shape := shape.(type) {
case *debug.Arrow:
return shape.MaxRenderDistance
case *debug.Box:
return shape.MaxRenderDistance
case *debug.Circle:
return shape.MaxRenderDistance
case *debug.Line:
return shape.MaxRenderDistance
case *debug.Sphere:
return shape.MaxRenderDistance
case *debug.Text:
return shape.MaxRenderDistance
case *debug.Cylinder:
return shape.MaxRenderDistance
case *debug.Pyramid:
return shape.MaxRenderDistance
case *debug.Ellipsoid:
return shape.MaxRenderDistance
case *debug.Cone:
return shape.MaxRenderDistance
}
return 0
}

// debugShapeToProtocol converts a debug shape to its protocol representation. It also provides defaults
// for some fields such as colour, scale and other per-shape properties.
func debugShapeToProtocol(shape debug.Shape, dim world.Dimension, attachedEntityID uint64) protocol.PrimitiveShape {
Expand All @@ -1214,6 +1242,9 @@ func debugShapeToProtocol(shape debug.Shape, dim world.Dimension, attachedEntity
if attachedEntityID > 0 {
ps.AttachedToEntityID = protocol.Option(int64(attachedEntityID))
}
if dist := debugShapeMaxDistance(shape); dist > 0 {
ps.MaxRenderDistance = protocol.Option(float32(dist))
}
white := color.RGBA{R: 255, G: 255, B: 255, A: 255}
switch shape := shape.(type) {
case *debug.Arrow:
Expand Down