-
-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathDemoSet.cs
More file actions
93 lines (85 loc) · 2.77 KB
/
Copy pathDemoSet.cs
File metadata and controls
93 lines (85 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using DemoContentLoader;
using DemoRenderer;
using Demos.Broken;
using Demos.Demos;
using Demos.Demos.Cars;
using Demos.Demos.Characters;
using Demos.Demos.Dancers;
using Demos.Demos.Sponsors;
using Demos.Demos.Tanks;
using Demos.FC;
using System;
using System.Collections.Generic;
namespace Demos;
/// <summary>
/// Constructs a demo from the set of available demos on demand.
/// </summary>
public class DemoSet
{
struct Option
{
public string Name;
public Func<ContentArchive, Camera, RenderSurface, Demo> Builder;
}
List<Option> options = new();
void AddOption<T>() where T : Demo, new()
{
options.Add(new Option
{
Builder = (content, camera, surface) =>
{
//Note that the actual work is done in the Initialize function rather than a constructor.
//The 'new T()' syntax actually uses reflection and repackages exceptions in an inconvenient way.
//By using Initialize instead, the stack trace and debugger will go right to the source.
var demo = new T();
demo.LoadGraphicalContent(content, surface);
demo.Initialize(content, camera);
return demo;
},
Name = typeof(T).Name
});
}
public DemoSet()
{
AddOption<CompoundFallsThroughFloor>();
AddOption<FcDemo>();
AddOption<CarDemo>();
AddOption<TankDemo>();
AddOption<CharacterDemo>();
AddOption<RagdollTubeDemo>();
AddOption<PyramidDemo>();
AddOption<ColosseumDemo>();
AddOption<NewtDemo>();
AddOption<ClothDemo>();
AddOption<DancerDemo>();
AddOption<PlumpDancerDemo>();
AddOption<ContinuousCollisionDetectionDemo>();
AddOption<PlanetDemo>();
AddOption<PerBodyGravityDemo>();
AddOption<CompoundDemo>();
AddOption<RopeStabilityDemo>();
AddOption<SubsteppingDemo>();
AddOption<ChainFountainDemo>();
AddOption<RopeTwistDemo>();
AddOption<FrictionDemo>();
AddOption<BouncinessDemo>();
AddOption<RayCastingDemo>();
AddOption<SweepDemo>();
AddOption<ContactEventsDemo>();
AddOption<CollisionTrackingDemo>();
AddOption<CollisionQueryDemo>();
AddOption<SolverContactEnumerationDemo>();
AddOption<CustomVoxelCollidableDemo>();
AddOption<BlockChainDemo>();
AddOption<SponsorDemo>();
}
public int Count { get { return options.Count; } }
public string GetName(int index)
{
return options[index].Name;
}
public Demo Build(int index, ContentArchive content, Camera camera, RenderSurface surface)
{
return options[index].Builder(content, camera, surface);
}
}