Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WindGrid.cs
Go to the documentation of this file.
1using System;
3
5
6public class WindGrid
7{
8 private struct WindCoord
9 {
10 public int Time;
11
12 public int DirectionX;
13
14 public int DirectionY;
15 }
16
17 private WindCoord[,] _grid = new WindCoord[1, 1];
18
19 private int _width = 1;
20
21 private int _height = 1;
22
23 private int _gameTime;
24
25 public void SetSize(int targetWidth, int targetHeight)
26 {
27 _width = Math.Max(_width, targetWidth);
28 _height = Math.Max(_height, targetHeight);
29 ResizeGrid();
30 }
31
32 public void Update()
33 {
34 _gameTime++;
36 {
38 }
39 }
40
41 public void GetWindTime(int tileX, int tileY, int timeThreshold, out int windTimeLeft, out int directionX, out int directionY)
42 {
43 WindCoord windCoord = _grid[tileX % _width, tileY % _height];
44 directionX = windCoord.DirectionX;
45 directionY = windCoord.DirectionY;
46 if (windCoord.Time + timeThreshold < _gameTime)
47 {
48 windTimeLeft = 0;
49 }
50 else
51 {
52 windTimeLeft = _gameTime - windCoord.Time;
53 }
54 }
55
56 private void ResizeGrid()
57 {
58 if (_width > _grid.GetLength(0) || _height > _grid.GetLength(1))
59 {
61 }
62 }
63
64 private void SetWindTime(int tileX, int tileY, int directionX, int directionY)
65 {
66 int num = tileX % _width;
67 int num2 = tileY % _height;
68 _grid[num, num2].Time = _gameTime;
69 _grid[num, num2].DirectionX = directionX;
70 _grid[num, num2].DirectionY = directionY;
71 }
72
73 private void ScanPlayers()
74 {
75 if (Main.netMode == 0)
76 {
78 }
79 else if (Main.netMode == 1)
80 {
81 for (int i = 0; i < 255; i++)
82 {
83 ScanPlayer(i);
84 }
85 }
86 }
87
88 private void ScanPlayer(int i)
89 {
90 Player player = Main.player[i];
91 if (!player.active || player.dead || (player.velocity.X == 0f && player.velocity.Y == 0f) || !Utils.CenteredRectangle(Main.Camera.Center, Main.Camera.UnscaledSize).Intersects(player.Hitbox) || player.velocity.HasNaNs())
92 {
93 return;
94 }
95 int directionX = Math.Sign(player.velocity.X);
96 int directionY = Math.Sign(player.velocity.Y);
97 foreach (Point item in Collision.GetTilesIn(player.TopLeft, player.BottomRight))
98 {
99 SetWindTime(item.X, item.Y, directionX, directionY);
100 }
101 }
102}
static int Sign(decimal value)
Definition Math.cs:1202
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static List< Point > GetTilesIn(Vector2 TopLeft, Vector2 BottomRight)
Vector2 velocity
Definition Entity.cs:16
Rectangle Hitbox
Definition Entity.cs:164
void SetWindTime(int tileX, int tileY, int directionX, int directionY)
Definition WindGrid.cs:64
void SetSize(int targetWidth, int targetHeight)
Definition WindGrid.cs:25
void GetWindTime(int tileX, int tileY, int timeThreshold, out int windTimeLeft, out int directionX, out int directionY)
Definition WindGrid.cs:41
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static Camera Camera
Definition Main.cs:289
static bool SettingsEnabled_TilesSwayInWind
Definition Main.cs:1372
static Player[] player
Definition Main.cs:1803
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604