Skip to content

Commit 36f0223

Browse files
authored
Merge branch 'master' into test
2 parents 930c949 + 9331f2b commit 36f0223

62 files changed

Lines changed: 8420 additions & 2856 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

engine/Definitions/common/Physics/IPhysicsBody.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,6 @@ native class IPhysicsBody as NativeEngine.IPhysicsBody
125125
void SetTrigger( bool trigger );
126126

127127
void ResetProxy();
128+
129+
void SetBullet( bool bEnabled );
128130
}

engine/Sandbox.Engine/Scene/Components/Collider/Rigidbody.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,27 @@ public Rotation InertiaTensorRotation
296296
}
297297
}
298298

299+
/// <summary>
300+
/// Enable enhanced continuous collision detection (CCD) for this body.
301+
/// When enabled, the body performs CCD against dynamic bodies
302+
/// (but not against other bodies with enhanced CCD enabled).
303+
/// This is useful for fast-moving objects like bullets or rockets
304+
/// that need reliable collision detection.
305+
/// </summary>
306+
[Advanced, Property]
307+
public bool EnhancedCcd
308+
{
309+
get;
310+
set
311+
{
312+
if ( field == value ) return;
313+
314+
field = value;
315+
316+
if ( _body.IsValid() ) _body.EnhancedCcd = value;
317+
}
318+
}
319+
299320
/// <summary>
300321
/// Resets the inertia tensor and its rotation to the values automatically calculated from the attached colliders.
301322
/// This removes any custom overrides set via <see cref="InertiaTensor"/> or <see cref="InertiaTensorRotation"/>.
@@ -391,6 +412,8 @@ void EnsureBodyCreated()
391412
_body.Velocity = _lastVelocity;
392413
_body.AngularVelocity = _lastAngularVelocity;
393414

415+
_body.EnhancedCcd = EnhancedCcd;
416+
394417
// Make sure we clear these so we don't reapply them again later
395418
_lastVelocity = default;
396419
_lastAngularVelocity = default;

engine/Sandbox.Engine/Scene/Components/Component.Flags.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public enum ComponentFlags
5050
/// Don't serialize this component when cloning
5151
/// </summary>
5252
NotCloned = 256,
53+
54+
/// <summary>
55+
/// Can edit advanced properties in the component inspector
56+
/// </summary>
57+
ShowAdvancedProperties = 512,
5358
}
5459

5560
public partial class Component

engine/Sandbox.Engine/Scene/Components/Component.Serialize.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public JsonNode Serialize( GameObject.SerializeOptions options = null )
3737
{
3838
{ JsonKeys.Type, t.SerializedName },
3939
{ JsonKeys.Id, Id },
40-
{ JsonKeys.Enabled, Enabled }
40+
{ JsonKeys.Enabled, Enabled },
41+
{ JsonKeys.Flags, (long)Flags }
4142
};
4243

4344
if ( (isSceneForNetwork || isSingleNetworkObject) && this is INetworkSnapshot sw )
@@ -102,6 +103,8 @@ public void Deserialize( JsonObject node )
102103
Id = (Guid)id;
103104
}
104105

106+
DeserializeFlags( node );
107+
105108
if ( node.TryGetPropertyValue( JsonKeys.Snapshot, out var snapshotNode ) && this is INetworkSnapshot sw )
106109
{
107110
var data = snapshotNode.Deserialize<byte[]>();
@@ -117,6 +120,18 @@ public void Deserialize( JsonObject node )
117120
Enabled = (bool)(jsonData[JsonKeys.Enabled] ?? true);
118121
}
119122

123+
private void DeserializeFlags( JsonObject node )
124+
{
125+
if ( !node.TryGetPropertyValue( JsonKeys.Flags, out var inFlagNode ) )
126+
return;
127+
128+
var inFlags = (ComponentFlags)(long)inFlagNode;
129+
130+
const ComponentFlags savedFlags = ComponentFlags.ShowAdvancedProperties;
131+
132+
Flags = (Flags & ~savedFlags) | (inFlags & savedFlags);
133+
}
134+
120135
internal void PostDeserialize()
121136
{
122137
if ( jsonData is null )

engine/Sandbox.Engine/Scene/Components/Joint/WheelJoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,11 @@ protected override PhysicsJoint CreateJoint( PhysicsPoint point1, PhysicsPoint p
347347
{
348348
localFrame1 = global::Transform.Zero;
349349
localFrame1.Position = point1.LocalPosition;
350-
localFrame1.Rotation = point1.LocalRotation * new Angles( 90, 0, 0 );
350+
localFrame1.Rotation = point1.LocalRotation * new Angles( 90, 0, 0 ) * new Angles( 0, 90, 0 ); // face the right way, steer the right way
351351

352352
localFrame2 = global::Transform.Zero;
353353
localFrame2.Position = point2.Body.Transform.PointToLocal( point1.Transform.Position );
354-
localFrame2.Rotation = point2.Body.Transform.RotationToLocal( point1.Transform.Rotation * new Angles( 90, 0, 0 ) );
354+
localFrame2.Rotation = point2.Body.Transform.RotationToLocal( point1.Transform.Rotation * new Angles( 90, 0, 0 ) * new Angles( 0, 90, 0 ) ); // face the right way, steer the right way
355355
}
356356

357357
if ( !Scene.IsEditor )

engine/Sandbox.Engine/Scene/Components/Render/SkinnedModelRenderer.cs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-

1+
using System.Collections.Concurrent;
2+
23
namespace Sandbox;
34

45
/// <summary>
@@ -519,39 +520,18 @@ bool UpdateGameObjectsFromBones()
519520

520521
return transformsChanged;
521522
}
522-
523-
private IEnumerable<SkinnedModelRenderer> GetMergeDescendants()
523+
internal void MergeDescendants( ConcurrentQueue<GameTransform> changedTransforms = null )
524524
{
525525
foreach ( var child in mergeChildren )
526526
{
527527
if ( !child.IsValid() )
528528
continue;
529529

530-
yield return child;
531-
532-
foreach ( var descendant in child.GetMergeDescendants() )
533-
{
534-
yield return descendant;
535-
}
536-
}
537-
}
538-
539-
internal void MergeDescendants( Action<GameTransform> transformChangedCallback = null )
540-
{
541-
if ( mergeChildren.Count == 0 )
542-
return;
543-
544-
var descendants = GetMergeDescendants();
545-
foreach ( var descendant in descendants )
546-
{
547-
if ( !descendant.IsValid() )
548-
continue;
549-
550-
var so = descendant.SceneModel;
530+
var so = child.SceneModel;
551531
if ( !so.IsValid() )
552532
continue;
553533

554-
var target = descendant.BoneMergeTarget;
534+
var target = child.BoneMergeTarget;
555535
if ( !target.IsValid() )
556536
continue;
557537

@@ -563,19 +543,21 @@ internal void MergeDescendants( Action<GameTransform> transformChangedCallback =
563543
so.MergeBones( parent );
564544

565545
// Updated bones, transform is no longer dirty.
566-
descendant._transformDirty = false;
546+
child._transformDirty = false;
567547

568-
if ( !descendant.UpdateGameObjectsFromBones() )
569-
continue;
570-
571-
if ( transformChangedCallback is not null )
572-
{
573-
transformChangedCallback( descendant.Transform );
574-
}
575-
else if ( ThreadSafe.IsMainThread )
548+
if ( child.UpdateGameObjectsFromBones() )
576549
{
577-
descendant.Transform.TransformChanged();
550+
if ( changedTransforms is not null )
551+
{
552+
changedTransforms.Enqueue( child.Transform );
553+
}
554+
else if ( ThreadSafe.IsMainThread )
555+
{
556+
child.Transform.TransformChanged();
557+
}
578558
}
559+
560+
child.MergeDescendants( changedTransforms );
579561
}
580562
}
581563

engine/Sandbox.Engine/Scene/GameObjectSystems/SceneAnimationSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ void UpdateAnimation()
6565
}
6666
);
6767

68-
// Now merge any descendants
69-
System.Threading.Tasks.Parallel.ForEach( rootRenderers.Where( x => !x.BoneMergeTarget.IsValid() ), _animParallelOptions, x => x.MergeDescendants( ChangedTransforms.Enqueue ) );
68+
// Now merge any descendants without allocating per-merge delegates
69+
System.Threading.Tasks.Parallel.ForEach( rootRenderers.Where( x => !x.BoneMergeTarget.IsValid() ), _animParallelOptions, renderer => renderer.MergeDescendants( ChangedTransforms ) );
7070

7171
while ( ChangedTransforms.TryDequeue( out var tx ) )
7272
{

engine/Sandbox.Engine/Scene/GameObjectSystems/SceneSpriteSystem.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ private static RenderGroupKey GetRenderGroupKey( ISpriteRenderGroup component, G
231231
flags |= InstanceGroupFlags.Additive;
232232
}
233233

234+
if ( component.Opaque )
235+
{
236+
flags |= InstanceGroupFlags.Opaque;
237+
}
238+
234239
RenderGroupKey renderGroupKey = new()
235240
{
236241
GroupFlags = flags,
@@ -281,6 +286,7 @@ private SpriteBatchSceneObject CreateRenderGroup( RenderGroupKey renderGroupKey
281286
renderGroupObject.Flags.ExcludeGameLayer = (renderGroupKey.GroupFlags & InstanceGroupFlags.CastOnlyShadow) != 0;
282287
renderGroupObject.Sorted = (renderGroupKey.GroupFlags & InstanceGroupFlags.Transparent) != 0;
283288
renderGroupObject.Additive = (renderGroupKey.GroupFlags & InstanceGroupFlags.Additive) != 0;
289+
renderGroupObject.Opaque = (renderGroupKey.GroupFlags & InstanceGroupFlags.Opaque) != 0;
284290
renderGroupObject.Tags.SetFrom( new TagSet( renderGroupKey.Tags ) );
285291
renderGroupKey.RenderLayer.Apply( renderGroupObject );
286292

@@ -362,6 +368,7 @@ internal enum InstanceGroupFlags
362368
CastShadow = 1 << 0,
363369
CastOnlyShadow = 1 << 1,
364370
Transparent = 1 << 2,
365-
Additive = 1 << 3
371+
Additive = 1 << 3,
372+
Opaque = 1 << 4
366373
}
367374
}

engine/Sandbox.Engine/Systems/Physics/PhysicsBody.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,4 +1233,16 @@ internal void ResetProxy()
12331233
{
12341234
native.ResetProxy();
12351235
}
1236+
1237+
/// <summary>
1238+
/// Enable enhanced continuous collision detection (CCD) for this body.
1239+
/// When enabled, the body performs CCD against dynamic bodies
1240+
/// (but not against other bodies with enhanced CCD enabled).
1241+
/// This is useful for fast-moving objects like bullets or rockets
1242+
/// that need reliable collision detection.
1243+
/// </summary>
1244+
public bool EnhancedCcd
1245+
{
1246+
set => native.SetBullet( value );
1247+
}
12361248
}

engine/Sandbox.Engine/Systems/SceneSystem/SpriteBatchSceneObject.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal sealed class SpriteBatchSceneObject : SceneCustomObject
1313
public bool Sorted { get; set; } = false;
1414
public bool Filtered { get; set; } = false;
1515
public bool Additive { get; set; } = false;
16+
public bool Opaque { get; set; } = false;
1617

1718
internal Dictionary<Guid, SpriteRenderer> Components = new();
1819

@@ -512,6 +513,7 @@ public override void RenderSceneObject()
512513
Graphics.ResourceBarrierTransition( SpriteBufferOut, ResourceState.Common );
513514

514515
Graphics.Attributes.SetCombo( "D_BLEND", Additive ? 1 : 0 );
516+
Graphics.Attributes.SetCombo( "D_OPAQUE", Opaque ? 1 : 0 );
515517

516518
// Sort
517519
if ( Sorted )

0 commit comments

Comments
 (0)