Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemParticles.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
10 public Dictionary<ParticleSystemBase, bool> m_particleSystems = [];
11
13
14 public bool ParticleSystemsDraw = true;
15
16 public bool ParticleSystemsSimulate = true;
17
18 public int[] m_drawOrders = [300];
19
20 public List<ParticleSystemBase> m_endedParticleSystems = [];
21
23
24 public SubsystemSky SubsystemSky { get; private set; }
25
26 public int[] DrawOrders => m_drawOrders;
27
28 public void AddParticleSystem(ParticleSystemBase particleSystem, bool throwOnAlreadyAdded = false) {
29 if (particleSystem.SubsystemParticles == null) {
30 m_particleSystems.Add(particleSystem, true);
31 particleSystem.SubsystemParticles = this;
32 particleSystem.OnAdded();
33 return;
34 }
35 if (throwOnAlreadyAdded) {
36 throw new InvalidOperationException("Particle system is already added.");
37 }
38 }
39
40 public void RemoveParticleSystem(ParticleSystemBase particleSystem, bool throwOnNotFound = false) {
41 if (particleSystem.SubsystemParticles == this) {
42 particleSystem.OnRemoved();
43 m_particleSystems.Remove(particleSystem);
44 particleSystem.SubsystemParticles = null;
45 return;
46 }
47 if (throwOnNotFound) {
48 throw new InvalidOperationException("Particle system is not added.");
49 }
50 }
51
52 public bool ContainsParticleSystem(ParticleSystemBase particleSystem) => particleSystem.SubsystemParticles == this;
53
54 public override void Load(ValuesDictionary valuesDictionary) {
55 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
56 SubsystemSky = Project.FindSubsystem<SubsystemSky>(true);
57 }
58
59 public virtual void Update(float dt) {
62 foreach (ParticleSystemBase key in m_particleSystems.Keys) {
63 try {
64 if (key.Simulate(m_subsystemTime.GameTimeDelta)) {
66 }
67 }
68 catch (Exception e) {
69 Log.Error(e);
71 }
72 }
73 foreach (ParticleSystemBase endedParticleSystem in m_endedParticleSystems) {
74 RemoveParticleSystem(endedParticleSystem);
75 }
76 }
77 }
78
79 public virtual void Draw(Camera camera, int drawOrder) {
81 foreach (ParticleSystemBase key in m_particleSystems.Keys) {
82 try {
83 key.Draw(camera);
84 }
85 catch (Exception e) {
86 Log.Error(e);
87 }
88 }
89 Shader shader = ContentManager.Get<Shader>("Shaders/AlphaTested");
90 shader.GetParameter("u_origin").SetValue(Vector2.Zero);
91 shader.GetParameter("u_viewProjectionMatrix").SetValue(camera.ViewProjectionMatrix);
92 shader.GetParameter("u_viewPosition").SetValue(camera.ViewPosition);
93 shader.GetParameter("u_fogYMultiplier").SetValue(SubsystemSky.VisibilityRangeYMultiplier);
94 shader.GetParameter("u_fogColor").SetValue(new Vector3(SubsystemSky.ViewFogColor));
95 shader.GetParameter("u_hazeStartDensity").SetValue(new Vector2(SubsystemSky.ViewHazeStart, SubsystemSky.ViewHazeDensity));
96 shader.GetParameter("u_fogBottomTopDensity")
97 .SetValue(new Vector3(SubsystemSky.ViewFogBottom, SubsystemSky.ViewFogTop, SubsystemSky.ViewFogDensity));
98 shader.GetParameter("u_alphaThreshold").SetValue(0f);
99 ShaderParameter parameter = shader.GetParameter("u_texture");
100 ShaderParameter parameter2 = shader.GetParameter("u_samplerState");
101 foreach (TexturedBatch3D texturedBatch in PrimitivesRenderer.TexturedBatches) {
102 Display.DepthStencilState = texturedBatch.DepthStencilState;
103 Display.RasterizerState = texturedBatch.RasterizerState;
104 Display.BlendState = texturedBatch.BlendState;
105 parameter.SetValue(texturedBatch.Texture);
106 parameter2.SetValue(texturedBatch.SamplerState);
107 texturedBatch.FlushWithDeviceState(shader);
108 }
110 }
111 }
112 }
113}
Engine.Vector3 Vector3
RasterizerState RasterizerState
DepthStencilState DepthStencilState
void FlushWithDeviceState(bool useAlphaTest, Texture2D texture, SamplerState samplerState, Matrix matrix, Vector4 color, bool clearAfterFlush=true)
virtual ShaderParameter GetParameter(string name, bool allowNull=false)
static void Error(object message)
定义 Log.cs:80
Vector3 ViewPosition
Matrix ViewProjectionMatrix
static object Get(Type type, string name)
SubsystemParticles SubsystemParticles
void Draw(Camera camera)
bool Simulate(float dt)
void AddParticleSystem(ParticleSystemBase particleSystem, bool throwOnAlreadyAdded=false)
PrimitivesRenderer3D PrimitivesRenderer
bool ContainsParticleSystem(ParticleSystemBase particleSystem)
override void Load(ValuesDictionary valuesDictionary)
virtual void Update(float dt)
List< ParticleSystemBase > m_endedParticleSystems
Dictionary< ParticleSystemBase, bool > m_particleSystems
virtual void Draw(Camera camera, int drawOrder)
void RemoveParticleSystem(ParticleSystemBase particleSystem, bool throwOnNotFound=false)
ValuesDictionary ValuesDictionary
static readonly Vector2 Zero