Skip to content

Commit 0e31365

Browse files
committed
Merge branch 'test' of https://github.com/EternalDawn1/sbox-public into test
2 parents 93a047b + f64d929 commit 0e31365

File tree

96 files changed

+8459
-3430
lines changed

Some content is hidden

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

96 files changed

+8459
-3430
lines changed

engine/Definitions/common/Physics/IPhysicsBody.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,6 @@ native class IPhysicsBody as NativeEngine.IPhysicsBody
123123
bool IsTouching( IPhysicsShape pShape, bool bTriggers );
124124

125125
void SetTrigger( bool trigger );
126+
127+
void ResetProxy();
126128
}

engine/Definitions/common/Physics/IPhysicsShape.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,6 @@ native class IPhysicsShape as NativeEngine.IPhysicsShape
8383
}
8484

8585
bool IsTouching( IPhysicsShape pShape, bool bTriggers );
86+
87+
void ResetProxy();
8688
}

engine/Definitions/common/Physics/IPhysicsWorld.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ native class IPhysicsWorld
4444
IPhysicsJoint AddSphericalJoint( IPhysicsBody pBody1, IPhysicsBody pBody2, Transform localFrame1, Transform localFrame2 );
4545
IPhysicsJoint AddMotorJoint( IPhysicsBody pBody1, IPhysicsBody pBody2, Transform localFrame1, Transform localFrame2 );
4646
IPhysicsJoint AddWheelJoint( IPhysicsBody pBody1, IPhysicsBody pBody2, Transform localFrame1, Transform localFrame2 );
47+
IPhysicsJoint AddFilterJoint( IPhysicsBody pBody1, IPhysicsBody pBody2 );
4748

4849
//
4950
// Sets the collision rules using a json serialized Sandbox.Internal.CollisionRules

engine/Definitions/tools/widgetutil.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ native static class WidgetUtil Native.WidgetUtil
1818

1919
static void PaintSetFont( QPainter painter, string fontName, int size, int weight, bool italic, bool heightInPixels );
2020
static SwapChainHandle_t CreateSwapChain( QWidget target, RenderMultisampleType_t nMSAAAmount );
21+
static bool UpdateSwapChainMSAA( SwapChainHandle_t swapChain, RenderMultisampleType_t nMSAAAmount );
2122

2223
static void SetWindowNoActivate( QWidget widget );
2324

engine/Sandbox.Engine/Core/Diagnostics/Profiler/ETWLogger.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ public void Start( bool noUpload = false )
4040
WorkingDirectory = Path.Combine( Environment.CurrentDirectory, "bin", "managed" )
4141
};
4242

43-
var profilerProcess = Process.Start( startInfo );
43+
try
44+
{
45+
Process.Start( startInfo );
46+
}
47+
catch
48+
{
49+
CleanUp();
50+
51+
throw;
52+
}
53+
4454
_pipeServer.WaitForConnection();
4555

4656
_writer = new StreamWriter( _pipeServer ) { AutoFlush = true };

engine/Sandbox.Engine/Core/Interop/Handle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ internal static int RegisterHandle( IntPtr ptr, uint type )
137137
if ( type == Types.PhysicsPulleyJoint ) return New( ptr, ( h ) => new Sandbox.Physics.PulleyJoint( h ) );
138138
if ( type == Types.PhysicsMotorJoint ) return New( ptr, ( h ) => new Sandbox.Physics.ControlJoint( h ) );
139139
if ( type == Types.PhysicsWheelJoint ) return New( ptr, ( h ) => new Sandbox.Physics.WheelJoint( h ) );
140+
if ( type == Types.PhysicsFilterJoint ) return New( ptr, ( h ) => new Sandbox.Physics.PhysicsJoint( h ) );
140141
if ( type == Types.PhysicsJoint ) return New( ptr, ( h ) => new Sandbox.Physics.PhysicsJoint( h ) );
141142

142143
if ( type == Types.PhysicsConicalJoint ) return New( ptr, ( h ) => new Sandbox.Physics.PhysicsJoint( h ) );
@@ -195,6 +196,7 @@ static class Types
195196
internal static uint PhysicsConicalJoint { get; } = StringToken.FindOrCreate( "PhysicsConicalJoint" );
196197
internal static uint PhysicsMotorJoint { get; } = StringToken.FindOrCreate( "PhysicsMotorJoint" );
197198
internal static uint PhysicsWheelJoint { get; } = StringToken.FindOrCreate( "PhysicsWheelJoint" );
199+
internal static uint PhysicsFilterJoint { get; } = StringToken.FindOrCreate( "PhysicsFilterJoint" );
198200
internal static uint PhysicsPulleyJoint { get; } = StringToken.FindOrCreate( "PhysicsPulleyJoint" );
199201
internal static uint PhysicsGenericJoint { get; } = StringToken.FindOrCreate( "PhysicsGenericJoint" );
200202
internal static uint PhysicsNullJoint { get; } = StringToken.FindOrCreate( "PhysicsNullJoint" );

engine/Sandbox.Engine/Editor/Gizmos/Gizmo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static void Select( bool allowUnselect = true, bool allowMultiSelect = tr
8888
return;
8989
}
9090

91-
if ( Active.Selection.Contains( Object ) )
91+
if ( Object is not null && Active.Selection.Contains( Object ) )
9292
{
9393
Active.Selection.Remove( Object );
9494
return;
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using static Sandbox.Clothing;
2+
3+
namespace Sandbox;
4+
5+
/// <summary>
6+
/// Utility class to make random outfits for the avatar. Uses a predefined set of groups and chances.
7+
/// </summary>
8+
internal static class AvatarRandomizer
9+
{
10+
public struct Group
11+
{
12+
public float Chance;
13+
public ClothingCategory[] Categories;
14+
}
15+
16+
private static readonly Group Head = new Group
17+
{
18+
Chance = 1.0f,
19+
Categories =
20+
[
21+
ClothingCategory.Hat,
22+
ClothingCategory.HatCap,
23+
ClothingCategory.Hair,
24+
ClothingCategory.HairShort,
25+
ClothingCategory.HairLong,
26+
ClothingCategory.HairMedium
27+
]
28+
};
29+
30+
private static readonly Group Legs = new Group
31+
{
32+
Chance = 1.0f,
33+
Categories =
34+
[
35+
ClothingCategory.Trousers,
36+
ClothingCategory.Shorts,
37+
ClothingCategory.Underwear,
38+
ClothingCategory.Skirt
39+
]
40+
};
41+
42+
private static readonly Group Torso = new Group
43+
{
44+
Chance = 1.0f,
45+
Categories =
46+
[
47+
ClothingCategory.Shirt,
48+
ClothingCategory.TShirt,
49+
ClothingCategory.Tops
50+
]
51+
};
52+
53+
private static readonly Group Feet = new Group
54+
{
55+
Chance = 1.0f,
56+
Categories =
57+
[
58+
ClothingCategory.Shoes,
59+
ClothingCategory.Boots
60+
]
61+
};
62+
63+
private static readonly Group Jackets = new Group
64+
{
65+
Chance = 0.5f,
66+
Categories =
67+
[
68+
ClothingCategory.Jacket,
69+
ClothingCategory.Vest,
70+
ClothingCategory.Coat,
71+
ClothingCategory.Cardigan
72+
]
73+
};
74+
75+
private static readonly Group FacialHair = new Group
76+
{
77+
Chance = 0.3f,
78+
Categories =
79+
[
80+
ClothingCategory.FacialHairBeard,
81+
ClothingCategory.FacialHairGoatee,
82+
ClothingCategory.FacialHairSideburns
83+
]
84+
};
85+
86+
private static readonly Group Glasses = new Group
87+
{
88+
Chance = 0.5f,
89+
Categories =
90+
[
91+
ClothingCategory.GlassesEye,
92+
ClothingCategory.GlassesSun
93+
]
94+
};
95+
96+
private static readonly Group Gloves = new Group
97+
{
98+
Chance = 0.2f,
99+
Categories =
100+
[
101+
ClothingCategory.Gloves
102+
]
103+
};
104+
105+
private static readonly Group[] Groups =
106+
{
107+
Head,
108+
Legs,
109+
Torso,
110+
Feet,
111+
Jackets,
112+
FacialHair,
113+
Glasses,
114+
Gloves
115+
};
116+
117+
public static IEnumerable<ClothingContainer.ClothingEntry> GetRandom()
118+
{
119+
//
120+
// Not using Game.Random here -- this could be applied in the editor and we're not ticking in-game
121+
//
122+
var rnd = new Random();
123+
var all = ResourceLibrary.GetAll<Clothing>();
124+
125+
foreach ( var rule in Groups )
126+
{
127+
if ( rnd.Float() > rule.Chance ) continue;
128+
129+
var category = rnd.FromArray( rule.Categories );
130+
var options = all.Where( c => c.Category == category ).ToList();
131+
132+
if ( options == null || options.Count == 0 )
133+
{
134+
continue;
135+
}
136+
137+
var item = rnd.FromList( options );
138+
if ( !item.IsValid() ) continue;
139+
140+
yield return new ClothingContainer.ClothingEntry( item )
141+
{
142+
Tint = rnd.Float()
143+
};
144+
}
145+
}
146+
}

engine/Sandbox.Engine/Resources/Terrain/TerrainStorage.Upgrade.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Sandbox;
88

99
public partial class TerrainStorage
1010
{
11-
public override int ResourceVersion => 1;
11+
public override int ResourceVersion => 2;
1212

1313
[Expose, JsonUpgrader( typeof( TerrainStorage ), 1 )]
1414
static void Upgrader_v1( JsonObject obj )
@@ -48,6 +48,69 @@ static void Upgrader_v1( JsonObject obj )
4848
obj.Remove( "RootObject" );
4949
}
5050

51+
[Expose, JsonUpgrader( typeof( TerrainStorage ), 2 )]
52+
static void Upgrader_v2( JsonObject obj )
53+
{
54+
if ( obj["Maps"] is not JsonObject maps )
55+
return;
56+
57+
if ( maps.ContainsKey( "indexedsplatmap" ) )
58+
return;
59+
60+
if ( maps["splatmap"] is not JsonValue splatmapValue )
61+
return;
62+
63+
// We need to convert our old splatmat(RGBA) into an indexed control map which contains much more information
64+
// that is all packed together. We also merge our hole map into a single bit of our new indexed map.
65+
var splatmapBase64 = splatmapValue.Deserialize<string>();
66+
var splatmapData = TerrainMaps.Decompress<Color32>( Convert.FromBase64String( splatmapBase64 ) );
67+
68+
// Cache holes map, so we can pack it
69+
byte[] holesData = null;
70+
if ( maps["holesmap"] is JsonValue holesValue )
71+
{
72+
var holesBase64 = holesValue.Deserialize<string>();
73+
holesData = TerrainMaps.Decompress<byte>( Convert.FromBase64String( holesBase64 ) ).ToArray();
74+
}
75+
76+
var compactData = new CompactTerrainMaterial[splatmapData.Length];
77+
78+
// Take the top two most contributing materials, and pack them with base material + overlay with the weight
79+
for ( int i = 0; i < splatmapData.Length; i++ )
80+
{
81+
var legacy = splatmapData[i];
82+
bool isHole = holesData != null && holesData[i] != 0;
83+
84+
// Find the two materials with highest weights
85+
var topTwo = new[] { (legacy.r, 0), (legacy.g, 1), (legacy.b, 2), (legacy.a, 3) }
86+
.OrderByDescending( x => x.Item1 )
87+
.Take( 2 )
88+
.ToArray();
89+
90+
// Calculate blend factor between base and overlay
91+
byte blendFactor = 0;
92+
int totalWeight = topTwo[0].Item1 + topTwo[1].Item1;
93+
if ( totalWeight > 0 )
94+
{
95+
blendFactor = (byte)((topTwo[1].Item1 * 255) / totalWeight);
96+
}
97+
98+
compactData[i] = new CompactTerrainMaterial(
99+
baseTextureId: (byte)topTwo[0].Item2,
100+
overlayTextureId: (byte)topTwo[1].Item2,
101+
blendFactor: blendFactor,
102+
isHole: isHole
103+
);
104+
}
105+
106+
// Add compact format to maps
107+
var compactBase64 = Convert.ToBase64String( TerrainMaps.Compress<CompactTerrainMaterial>( compactData ) );
108+
maps["splatmap"] = compactBase64;
109+
110+
// Remove legacy holesmap
111+
maps.Remove( "holesmap" );
112+
}
113+
51114
static Span<ushort> ResampleHeightmap( Span<ushort> original, int originalSize, int newSize )
52115
{
53116
// Create SKBitmap with the original data copied in

0 commit comments

Comments
 (0)