Example #1
0
			private void PerformRead()
			{
				try
				{
					if (m_voxel == null || m_voxel.Storage == null)
						return;

					Vector3I size = m_localMax - m_localMin;
					m_logger.debugLog("number of coords in box: " + (size.X + 1) * (size.Y + 1) * (size.Z + 1), "PerformRead()");
					ulong processed = 0;
					m_materialLocations.Clear();

					Vector3I vector = new Vector3I();
					for (vector.X = m_localMin.X; vector.X < m_localMax.X; vector.X += QUERY_STEP)
						for (vector.Y = m_localMin.Y; vector.Y < m_localMax.Y; vector.Y += QUERY_STEP)
							for (vector.Z = m_localMin.Z; vector.Z < m_localMax.Z; vector.Z += QUERY_STEP)
								if (vector.DistanceSquared(odPosVoxelStorage) <= rangeSquared)
								{
									m_voxel.Storage.ReadRange(m_storage, MyStorageDataTypeFlags.ContentAndMaterial, QUERY_LOD, vector, vector + QUERY_MAX);
									
									Vector3I index = Vector3I.Zero;
									Vector3I size3D = m_storage.Size3D;
									for (index.X = 0; index.X < size3D.X; index.X++)
										for (index.Y = 0; index.Y < size3D.Y; index.Y++)
											for (index.Z = 0; index.Z < size3D.Z; index.Z++)
											{
												int linear = m_storage.ComputeLinear(ref index);
												if (m_storage.Content(linear) > MyVoxelConstants.VOXEL_ISO_LEVEL)
												{
													byte mat = m_storage.Material(linear);
													if (RareMaterials[mat])
													{
														//m_logger.debugLog("mat: " + mat + ", content: " + m_storage.Content(linear) + ", vector: " + vector + ", position: " + vector + index
														//	+ ", name: " + MyDefinitionManager.Static.GetVoxelMaterialDefinition(mat).MinedOre, "PerformRead()");
														m_materialLocations[vector + index] = mat;
														processed++;
														goto Finished_Deposit;
													}
												}
											}

Finished_Deposit:
									processed++;
								}

					m_logger.debugLog("read " + processed + " chunks" + ", number of mats: " + m_materialLocations.Count, "PerformRead()", Logger.severity.DEBUG);
				}
				finally
				{
					lock_readVoxels.ReleaseExclusive();
					onFinished.Invoke();
				}
			}
Example #2
0
            /// <summary>
            /// Start the reads if it is not already running.
            /// </summary>
            /// <param name="onFinished">Invoked when reads finish, not invoked if already running.</param>
            /// <returns>True if started, false if already running.</returns>
            public void Read()
            {
                using (lock_throwOut.AcquireExclusiveUsing())
                    m_throwOutVoxelData = Globals.ElapsedTime + LifeSpan_VoxelData;

                NeedsUpdate = false;
                Vector3D m_oreDetectorPosition = m_oreDetector.GetPosition();
                Vector3D worldMin = m_oreDetectorPosition - m_maxRange;
                Vector3D worldMax = m_oreDetectorPosition + m_maxRange;

                float rangeSquared = m_maxRange * m_maxRange;

                Vector3I odPosVoxelStorage, m_localMin, m_localMax;
                MyVoxelCoordSystems.WorldPositionToVoxelCoord(m_voxel.PositionLeftBottomCorner, ref m_oreDetectorPosition, out odPosVoxelStorage);
                MyVoxelCoordSystems.WorldPositionToVoxelCoord(m_voxel.PositionLeftBottomCorner, ref worldMin, out m_localMin);
                MyVoxelCoordSystems.WorldPositionToVoxelCoord(m_voxel.PositionLeftBottomCorner, ref worldMax, out m_localMax);

                MyVoxelBase vox = m_voxel as MyVoxelBase;
                if (m_voxel == null || m_voxel.Storage == null)
                    return;

                m_localMin = Vector3I.Clamp(m_localMin, vox.StorageMin, vox.StorageMax);
                m_localMax = Vector3I.Clamp(m_localMax, vox.StorageMin, vox.StorageMax);
                m_localMin >>= QUERY_LOD;
                m_localMax >>= QUERY_LOD;
                odPosVoxelStorage >>= QUERY_LOD;
                m_logger.debugLog("minLocal: " + m_localMin + ", maxLocal: " + m_localMax + ", odPosVoxelStorage: " + odPosVoxelStorage);

                Vector3I size = m_localMax - m_localMin;
                m_logger.debugLog("number of coords in box: " + (size.X + 1) * (size.Y + 1) * (size.Z + 1));
                ulong processed = 0;
                m_materialLocations.Clear();

                Vector3I vector = new Vector3I();
                for (vector.X = m_localMin.X; vector.X < m_localMax.X; vector.X += QUERY_STEP)
                    for (vector.Y = m_localMin.Y; vector.Y < m_localMax.Y; vector.Y += QUERY_STEP)
                        for (vector.Z = m_localMin.Z; vector.Z < m_localMax.Z; vector.Z += QUERY_STEP)
                            if (vector.DistanceSquared(odPosVoxelStorage) <= rangeSquared)
                            {
                                m_voxel.Storage.ReadRange(m_storage, MyStorageDataTypeFlags.ContentAndMaterial, QUERY_LOD, vector, vector + QUERY_MAX);

                                Vector3I index = Vector3I.Zero;
                                Vector3I size3D = m_storage.Size3D;
                                for (index.X = 0; index.X < size3D.X; index.X++)
                                    for (index.Y = 0; index.Y < size3D.Y; index.Y++)
                                        for (index.Z = 0; index.Z < size3D.Z; index.Z++)
                                        {
                                            int linear = m_storage.ComputeLinear(ref index);
                                            if (m_storage.Content(linear) > MyVoxelConstants.VOXEL_ISO_LEVEL)
                                            {
                                                byte mat = m_storage.Material(linear);
                                                if (RareMaterials[mat])
                                                {
                                                    //m_logger.debugLog("mat: " + mat + ", content: " + m_storage.Content(linear) + ", vector: " + vector + ", position: " + vector + index
                                                    //	+ ", name: " + MyDefinitionManager.Static.GetVoxelMaterialDefinition(mat).MinedOre, "Read()");
                                                    m_materialLocations[vector + index] = mat;
                                                    processed++;
                                                    goto Finished_Deposit;
                                                }
                                            }
                                        }

                Finished_Deposit:
                                processed++;
                            }

                m_logger.debugLog("read " + processed + ", chunks" + ", number of mats: " + m_materialLocations.Count, Logger.severity.DEBUG);
            }