Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemBlocksScanner.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
7 public float ScanPeriod = 60f;
8
10
12
13 public int m_pollX;
14
15 public int m_pollZ;
16
17 public int m_pollPass;
18
19 public float m_pollShaftsCount;
20
22
24
26
30 public float MaxShaftsToPollPerFrame = 500f;
31
32 public UpdateOrder UpdateOrder => UpdateOrder.BlocksScanner;
33
34 public virtual Action<TerrainChunk> ScanningChunkCompleted { get; set; }
35
36 public virtual void Update(float dt) {
37 Terrain terrain = m_subsystemTerrain.Terrain;
38 m_pollShaftsCount += terrain.AllocatedChunks.Length * 16 * 16 * dt / ScanPeriod;
40 TerrainChunk terrainChunk = terrain.LoopChunks(m_pollChunkCoordinates.X, m_pollChunkCoordinates.Y, false);
41 if (terrainChunk == null) {
42 return;
43 }
44 while (m_pollShaftsCount >= 1f) {
45 if (terrainChunk.State <= TerrainChunkState.InvalidContents4) {
46 m_pollShaftsCount -= 256f;
47 }
48 else {
49 while (m_pollX < 16) {
50 while (m_pollZ < 16) {
51 if (m_pollShaftsCount < 1f) {
52 return;
53 }
55 int topHeightFast = terrainChunk.GetTopHeightFast(m_pollX, m_pollZ);
57 int num2 = 0;
58 while (num2 <= topHeightFast) {
59 int cellValueFast = terrainChunk.GetCellValueFast(num);
60 int num3 = Terrain.ExtractContents(cellValueFast);
61 if (num3 != 0) {
63 for (int i = 0; i < array.Length; i++) {
64 int x = terrainChunk.Origin.X + m_pollX;
65 int y = num2;
66 int z = terrainChunk.Origin.Y + m_pollZ;
67 try {
68 array[i].OnPoll(cellValueFast, x, y, z, m_pollPass);
69 }
70 catch (Exception e) {
71 Log.Error(
72 $"{array[i]} Poll {BlocksManager.Blocks[num3].GetType().Name} {cellValueFast} at ({x},{y},{z}) \n{e}"
73 );
74 }
75 }
76 }
77 num2++;
78 num++;
79 }
80 m_pollZ++;
81 }
82 m_pollZ = 0;
83 m_pollX++;
84 }
85 m_pollX = 0;
86 }
87 ScanningChunkCompleted?.Invoke(terrainChunk);
88 terrainChunk = terrain.LoopChunks(terrainChunk.Coords.X, terrainChunk.Coords.Y, true, out bool hasLooped);
89 if (terrainChunk == null) {
90 break;
91 }
92 if (hasLooped) {
93 m_pollPass++;
94 }
95 m_pollChunkCoordinates = terrainChunk.Coords;
96 }
97 }
98
99 public override void Load(ValuesDictionary valuesDictionary) {
100 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
101 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
103 m_pollChunkCoordinates = valuesDictionary.GetValue<Point2>("PollChunkCoordinates");
104 Point2 value = valuesDictionary.GetValue<Point2>("PollPoint");
105 m_pollX = value.X;
106 m_pollZ = value.Y;
107 m_pollPass = valuesDictionary.GetValue<int>("PollPass");
109 for (int i = 0; i < m_pollableBehaviorsByContents.Length; i++) {
110 m_pollableBehaviorsByContents[i] = (from s in m_subsystemBlockBehaviors.GetBlockBehaviors(i)
112 select (SubsystemPollableBlockBehavior)s).ToArray();
113 }
114 }
115
116 public override void Save(ValuesDictionary valuesDictionary) {
117 valuesDictionary.SetValue("PollChunkCoordinates", m_pollChunkCoordinates);
118 valuesDictionary.SetValue("PollPoint", new Point2(m_pollX, m_pollZ));
119 valuesDictionary.SetValue("PollPass", m_pollPass);
120 }
121 }
122}
static void Error(object message)
定义 Log.cs:80
SubsystemPollableBlockBehavior[][] m_pollableBehaviorsByContents
SubsystemBlockBehaviors m_subsystemBlockBehaviors
virtual Action< TerrainChunk > ScanningChunkCompleted
override void Load(ValuesDictionary valuesDictionary)
float MaxShaftsToPollPerFrame
每帧会进行多少xz格的方块检查
override void Save(ValuesDictionary valuesDictionary)
void OnPoll(int value, int x, int y, int z, int pollPass)
static int CalculateCellIndex(int x, int y, int z)
TerrainChunkState State
virtual int GetCellValueFast(int index)
virtual int GetTopHeightFast(int x, int z)
static int ExtractContents(int value)
virtual TerrainChunk LoopChunks(int startChunkX, int startChunkZ, bool skipStartChunk, out bool hasLooped)
ValuesDictionary ValuesDictionary