Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemAnimatedTextures.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
11
13
15
17
18 public Random m_random = new();
19
20 public bool m_waterOrder;
21
23
25
26 public bool m_magmaOrder;
27
29
31
32 public double m_lastAnimateGameTime;
33
35
37
39 get {
41 return m_subsystemBlocksTexture.BlocksTexture;
42 }
44 }
45 }
46
48
49 public virtual void Update(float dt) {
51 && !m_subsystemTime.FixedTimeStep.HasValue
54 float dt2 = (float)Math.Min(m_subsystemTime.GameTime - m_lastAnimateGameTime, 1.0);
55 Texture2D blocksTexture = m_subsystemBlocksTexture.BlocksTexture;
56 if (m_animatedBlocksTexture == null
57 || m_animatedBlocksTexture.Width != blocksTexture.Width
58 || m_animatedBlocksTexture.Height != blocksTexture.Height
62 blocksTexture.Width,
63 blocksTexture.Height,
65 ColorFormat.Rgba8888,
66 DepthFormat.None
67 );
68 AnimatedBlocksTexture.Tag = blocksTexture.Tag;
69 }
70 Rectangle scissorRectangle = Display.ScissorRectangle;
71 RenderTarget2D renderTarget = Display.RenderTarget;
72 Display.RenderTarget = m_animatedBlocksTexture;
73 try {
75 m_primitivesRenderer.TexturedBatch(
76 blocksTexture,
77 false,
78 -1,
83 )
84 .QueueQuad(
85 new Vector2(0f, 0f),
87 0f,
91 );
95 Display.ScissorRectangle = AnimateFireBlocksTexture(dt2);
97 }
98 finally {
99 Display.RenderTarget = renderTarget;
100 Display.ScissorRectangle = scissorRectangle;
101 }
103 && Time.FrameIndex % 2 == 0) {
104 m_animatedBlocksTexture.GenerateMipMaps();
105 }
107 }
108 }
109
110 public override void Load(ValuesDictionary valuesDictionary) {
111 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
113 Display.DeviceReset += Display_DeviceReset;
114 }
115
116 public override void Dispose() {
118 Display.DeviceReset -= Display_DeviceReset;
119 }
120
121 public void Display_DeviceReset() {
123 }
124
126 TexturedBatch2D batch = m_primitivesRenderer.TexturedBatch(
127 m_subsystemBlocksTexture.BlocksTexture,
128 false,
129 0,
131 null,
134 );
135 int num = BlocksManager.Blocks[18].DefaultTextureSlot % 16;
136 int num2 = BlocksManager.Blocks[18].DefaultTextureSlot / 16;
137 double num3 = 1.0 * m_subsystemTime.GameTime;
138 double num4 = 1.0 * m_lastAnimateGameTime;
139 float num5 = MathUtils.Min((float)MathUtils.Remainder(num3, 2.0), 1f);
140 float num6 = MathUtils.Min((float)MathUtils.Remainder(num3 + 1.0, 2.0), 1f);
141 byte b = (byte)(255f * num5);
142 byte b2 = (byte)(255f * num6);
143 if (MathUtils.Remainder(num3, 2.0) >= 1.0
144 && MathUtils.Remainder(num4, 2.0) < 1.0) {
145 m_waterOrder = true;
146 m_waterOffset2 = new Vector2(m_random.Float(0f, 1f), m_random.Float(0f, 1f));
147 }
148 else if (MathUtils.Remainder(num3 + 1.0, 2.0) >= 1.0
149 && MathUtils.Remainder(num4 + 1.0, 2.0) < 1.0) {
150 m_waterOrder = false;
151 m_waterOffset1 = new Vector2(m_random.Float(0f, 1f), m_random.Float(0f, 1f));
152 }
153 Vector2 tcOffset = new Vector2(num, num2) - (m_waterOrder ? m_waterOffset1 : m_waterOffset2);
154 Vector2 tcOffset2 = new Vector2(num, num2) - (m_waterOrder ? m_waterOffset2 : m_waterOffset1);
155 Color color = m_waterOrder ? new Color(b, b, b, b) : new Color(b2, b2, b2, b2);
156 Color color2 = m_waterOrder ? new Color(b2, b2, b2, b2) : new Color(b, b, b, b);
157 float num7 = MathF.Floor((float)MathUtils.Remainder(1.75 * m_subsystemTime.GameTime, 1.0) * 16f) / 16f;
158 float num8 = 0f - num7 + 1f;
159 float num9 = MathF.Floor((float)MathUtils.Remainder(1.75f / MathF.Sqrt(2f) * m_subsystemTime.GameTime, 1.0) * 16f) / 16f;
160 float num10 = 0f - num9 + 1f;
161 Vector2 tc = new(0f, 0f);
162 Vector2 tc2 = new(1f, 1f);
164 batch,
165 num,
166 num2,
167 tc,
168 tc2,
169 tcOffset,
170 color
171 );
173 batch,
174 num,
175 num2,
176 tc,
177 tc2,
178 tcOffset2,
179 color2
180 );
181 tc = new Vector2(num7, 0f);
182 tc2 = new Vector2(num7 + 1f, 1f);
184 batch,
185 num - 1,
186 num2,
187 tc,
188 tc2,
189 tcOffset,
190 color
191 );
193 batch,
194 num - 1,
195 num2,
196 tc,
197 tc2,
198 tcOffset2,
199 color2
200 );
201 tc = new Vector2(num8, 0f);
202 tc2 = new Vector2(num8 + 1f, 1f);
204 batch,
205 num + 1,
206 num2,
207 tc,
208 tc2,
209 tcOffset,
210 color
211 );
213 batch,
214 num + 1,
215 num2,
216 tc,
217 tc2,
218 tcOffset2,
219 color2
220 );
221 tc = new Vector2(0f, num7);
222 tc2 = new Vector2(1f, num7 + 1f);
224 batch,
225 num,
226 num2 - 1,
227 tc,
228 tc2,
229 tcOffset,
230 color
231 );
233 batch,
234 num,
235 num2 - 1,
236 tc,
237 tc2,
238 tcOffset2,
239 color2
240 );
241 tc = new Vector2(0f, num8);
242 tc2 = new Vector2(1f, num8 + 1f);
244 batch,
245 num,
246 num2 + 1,
247 tc,
248 tc2,
249 tcOffset,
250 color
251 );
253 batch,
254 num,
255 num2 + 1,
256 tc,
257 tc2,
258 tcOffset2,
259 color2
260 );
261 tc = new Vector2(num9, num10);
262 tc2 = new Vector2(num9 + 1f, num10 + 1f);
264 batch,
265 num - 1,
266 num2 + 1,
267 tc,
268 tc2,
269 tcOffset,
270 color
271 );
273 batch,
274 num - 1,
275 num2 + 1,
276 tc,
277 tc2,
278 tcOffset2,
279 color2
280 );
281 tc = new Vector2(num10, num10);
282 tc2 = new Vector2(num10 + 1f, num10 + 1f);
284 batch,
285 num + 1,
286 num2 + 1,
287 tc,
288 tc2,
289 tcOffset,
290 color
291 );
293 batch,
294 num + 1,
295 num2 + 1,
296 tc,
297 tc2,
298 tcOffset2,
299 color2
300 );
301 tc = new Vector2(num9, num9);
302 tc2 = new Vector2(num9 + 1f, num9 + 1f);
304 batch,
305 num - 1,
306 num2 - 1,
307 tc,
308 tc2,
309 tcOffset,
310 color
311 );
313 batch,
314 num - 1,
315 num2 - 1,
316 tc,
317 tc2,
318 tcOffset2,
319 color2
320 );
321 tc = new Vector2(num10, num9);
322 tc2 = new Vector2(num10 + 1f, num9 + 1f);
324 batch,
325 num + 1,
326 num2 - 1,
327 tc,
328 tc2,
329 tcOffset,
330 color
331 );
333 batch,
334 num + 1,
335 num2 - 1,
336 tc,
337 tc2,
338 tcOffset2,
339 color2
340 );
341 }
342
344 TexturedBatch2D batch = m_primitivesRenderer.TexturedBatch(
345 m_subsystemBlocksTexture.BlocksTexture,
346 false,
347 0,
349 null,
352 );
353 int num = BlocksManager.Blocks[92].DefaultTextureSlot % 16;
354 int num2 = BlocksManager.Blocks[92].DefaultTextureSlot / 16;
355 double num3 = 0.5 * m_subsystemTime.GameTime;
356 double num4 = 0.5 * m_lastAnimateGameTime;
357 float num5 = MathUtils.Min((float)MathUtils.Remainder(num3, 2.0), 1f);
358 float num6 = MathUtils.Min((float)MathUtils.Remainder(num3 + 1.0, 2.0), 1f);
359 byte b = (byte)(255f * num5);
360 byte b2 = (byte)(255f * num6);
361 if (MathUtils.Remainder(num3, 2.0) >= 1.0
362 && MathUtils.Remainder(num4, 2.0) < 1.0) {
363 m_magmaOrder = true;
364 m_magmaOffset2 = new Vector2(m_random.Float(0f, 1f), m_random.Float(0f, 1f));
365 }
366 else if (MathUtils.Remainder(num3 + 1.0, 2.0) >= 1.0
367 && MathUtils.Remainder(num4 + 1.0, 2.0) < 1.0) {
368 m_magmaOrder = false;
369 m_magmaOffset1 = new Vector2(m_random.Float(0f, 1f), m_random.Float(0f, 1f));
370 }
371 Vector2 tcOffset = new Vector2(num, num2) - (m_magmaOrder ? m_magmaOffset1 : m_magmaOffset2);
372 Vector2 tcOffset2 = new Vector2(num, num2) - (m_magmaOrder ? m_magmaOffset2 : m_magmaOffset1);
373 Color color = m_magmaOrder ? new Color(b, b, b, b) : new Color(b2, b2, b2, b2);
374 Color color2 = m_magmaOrder ? new Color(b2, b2, b2, b2) : new Color(b, b, b, b);
375 float num7 = MathF.Floor((float)MathUtils.Remainder(0.4 * m_subsystemTime.GameTime, 1.0) * 16f) / 16f;
376 float num8 = 0f - num7 + 1f;
377 float num9 = MathF.Floor((float)MathUtils.Remainder(0.4 / Math.Sqrt(2) * m_subsystemTime.GameTime, 1.0) * 16f) / 16f;
378 float num10 = 0f - num9 + 1f;
379 Vector2 tc = new(0f, 0f);
380 Vector2 tc2 = new(1f, 1f);
382 batch,
383 num,
384 num2,
385 tc,
386 tc2,
387 tcOffset,
388 color
389 );
391 batch,
392 num,
393 num2,
394 tc,
395 tc2,
396 tcOffset2,
397 color2
398 );
399 tc = new Vector2(num7, 0f);
400 tc2 = new Vector2(num7 + 1f, 1f);
402 batch,
403 num - 1,
404 num2,
405 tc,
406 tc2,
407 tcOffset,
408 color
409 );
411 batch,
412 num - 1,
413 num2,
414 tc,
415 tc2,
416 tcOffset2,
417 color2
418 );
419 tc = new Vector2(num8, 0f);
420 tc2 = new Vector2(num8 + 1f, 1f);
422 batch,
423 num + 1,
424 num2,
425 tc,
426 tc2,
427 tcOffset,
428 color
429 );
431 batch,
432 num + 1,
433 num2,
434 tc,
435 tc2,
436 tcOffset2,
437 color2
438 );
439 tc = new Vector2(0f, num7);
440 tc2 = new Vector2(1f, num7 + 1f);
442 batch,
443 num,
444 num2 - 1,
445 tc,
446 tc2,
447 tcOffset,
448 color
449 );
451 batch,
452 num,
453 num2 - 1,
454 tc,
455 tc2,
456 tcOffset2,
457 color2
458 );
459 tc = new Vector2(0f, num8);
460 tc2 = new Vector2(1f, num8 + 1f);
462 batch,
463 num,
464 num2 + 1,
465 tc,
466 tc2,
467 tcOffset,
468 color
469 );
471 batch,
472 num,
473 num2 + 1,
474 tc,
475 tc2,
476 tcOffset2,
477 color2
478 );
479 tc = new Vector2(num9, num10);
480 tc2 = new Vector2(num9 + 1f, num10 + 1f);
482 batch,
483 num - 1,
484 num2 + 1,
485 tc,
486 tc2,
487 tcOffset,
488 color
489 );
491 batch,
492 num - 1,
493 num2 + 1,
494 tc,
495 tc2,
496 tcOffset2,
497 color2
498 );
499 tc = new Vector2(num10, num10);
500 tc2 = new Vector2(num10 + 1f, num10 + 1f);
502 batch,
503 num + 1,
504 num2 + 1,
505 tc,
506 tc2,
507 tcOffset,
508 color
509 );
511 batch,
512 num + 1,
513 num2 + 1,
514 tc,
515 tc2,
516 tcOffset2,
517 color2
518 );
519 tc = new Vector2(num9, num9);
520 tc2 = new Vector2(num9 + 1f, num9 + 1f);
522 batch,
523 num - 1,
524 num2 - 1,
525 tc,
526 tc2,
527 tcOffset,
528 color
529 );
531 batch,
532 num - 1,
533 num2 - 1,
534 tc,
535 tc2,
536 tcOffset2,
537 color2
538 );
539 tc = new Vector2(num10, num9);
540 tc2 = new Vector2(num10 + 1f, num9 + 1f);
542 batch,
543 num + 1,
544 num2 - 1,
545 tc,
546 tc2,
547 tcOffset,
548 color
549 );
551 batch,
552 num + 1,
553 num2 - 1,
554 tc,
555 tc2,
556 tcOffset2,
557 color2
558 );
559 }
560
562 int defaultTextureSlot = BlocksManager.Blocks[104].DefaultTextureSlot;
563 float num = m_animatedBlocksTexture.Width / 16;
564 int num2 = defaultTextureSlot % 16;
565 int num3 = defaultTextureSlot / 16;
566 m_screenSpaceFireRenderer.ParticleSize = 1f * num;
567 m_screenSpaceFireRenderer.ParticleSpeed = 1.9f * num;
568 m_screenSpaceFireRenderer.ParticlesPerSecond = 24f;
569 m_screenSpaceFireRenderer.MinTimeToLive = float.PositiveInfinity;
570 m_screenSpaceFireRenderer.MaxTimeToLive = float.PositiveInfinity;
571 m_screenSpaceFireRenderer.ParticleAnimationOffset = 1f;
572 m_screenSpaceFireRenderer.ParticleAnimationPeriod = 3f;
573 m_screenSpaceFireRenderer.Origin = new Vector2(num2, num3 + 3) * num + new Vector2(0f, 0.5f * m_screenSpaceFireRenderer.ParticleSize);
574 m_screenSpaceFireRenderer.Width = num;
575 m_screenSpaceFireRenderer.CutoffPosition = num3 * num;
576 m_screenSpaceFireRenderer.Update(dt);
578 return new Rectangle((int)(num2 * num), (int)(num3 * num), (int)num, (int)(num * 3f));
579 }
580
581 public virtual void DrawBlocksTextureSlot(TexturedBatch2D batch,
582 int slotX,
583 int slotY,
584 Vector2 tc1,
585 Vector2 tc2,
586 Vector2 tcOffset,
587 Color color) {
588 float s = m_animatedBlocksTexture.Width / 16f;
589 batch.QueueQuad(
590 new Vector2(slotX, slotY) * s,
591 new Vector2(slotX + 1, slotY + 1) * s,
592 0f,
593 (tc1 + tcOffset) / 16f,
594 (tc2 + tcOffset) / 16f,
595 color
596 );
597 }
598 }
599}
Engine.Color Color
static readonly BlendState Opaque
static readonly BlendState AlphaBlend
static readonly DepthStencilState None
static void Clear(Vector4? color, float? depth=null, int? stencil=null)
static Rectangle ScissorRectangle
static RenderTarget2D RenderTarget
static readonly RasterizerState CullNone
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Vector2 texCoord1, Vector2 texCoord2, Color color)
static float Remainder(float x, float y)
static int Min(int x1, int x2)
static int FrameIndex
定义 Time.cs:26
static bool PeriodicEvent(double period, double offset)
定义 Time.cs:63
int DefaultTextureSlot
virtual void DrawBlocksTextureSlot(TexturedBatch2D batch, int slotX, int slotY, Vector2 tc1, Vector2 tc2, Vector2 tcOffset, Color color)
override void Load(ValuesDictionary valuesDictionary)
ValuesDictionary ValuesDictionary
static Color Transparent
定义 Color.cs:5
static Color White
static readonly Matrix Identity
static readonly Vector2 Zero
static readonly Vector2 One