예제 #1
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
		public SGubbinMeta(CGameRegistrator.ENetworkPrefab prefabID, SCellPos parentAbsoluteCell, Vector3 position, Quaternion rotation, Vector3 linearVelocity, Vector3 angularVelocity, bool hasNetworkedEntityScript, bool hasRigidBody)
		{
			mPrefabID = prefabID;
			mParentAbsoluteCell = parentAbsoluteCell;
			mPosition = position;
			mRotation = rotation;
			mLinearVelocity = linearVelocity;
			mAngularVelocity = angularVelocity;
			mHasNetworkedEntityScript = hasNetworkedEntityScript;
			mHasRigidBody = hasRigidBody;
		}
예제 #2
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float FogDensity(SCellPos absoluteCell) { return SampleNoise_FogDensity(absoluteCell); }
예제 #3
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	private void MarkGubbinsToPreserve()
	{
		// Find gubbins that are not within proximity to the cells.

		//foreach (CRegisteredGubbin gubbin in mGubbins)
		//{
		//    foreach (System.Collections.Generic.KeyValuePair<SCellPos, CCellContent> pair in mCells)
		//    {
		//        if (RelativeCellWithinProximityOfPoint(pair.Key - mCentreCell, gubbin.mEntity.transform.position, gubbin.mBoundingRadius))
		//        {
		//            gubbin.mAlternator = mbValidGubbinValue;
		//            break;
		//        }
		//    }
		//}

		foreach (CRegisteredGubbin gubbin in mGubbins)
		{
			Vector3 gubbinPosition = gubbin.mEntity.transform.position;
			SCellPos occupiedRelativeCell = RelativePointToRelativeCell(gubbinPosition);
			int iCellsInARow = 1 + (Mathf.CeilToInt((gubbin.mBoundingRadius / cellRadius) - 1) * 2);    // Centre point plus neighbours per axis.   E.g. 1,3,5,7,9...
			int iNeighboursPerDirection = (iCellsInARow - 1) / 2;                                       // Neighbours per direction.                E.g. 0,2,4,6,8...

			// Iterate through all 3 axis, checking the centre cell first.
			int x = 0;
			int y = 0;
			int z = 0;
			do
			{
				do
				{
					do
					{
						// Check if this cell is loaded.
						SCellPos neighbouringRelativeCell = new SCellPos(occupiedRelativeCell.x + x, occupiedRelativeCell.y + y, occupiedRelativeCell.z + z);
						if (RelativeCellWithinProximityOfPoint(neighbouringRelativeCell, gubbinPosition, gubbin.mBoundingRadius))
						{
							if (mCells.ContainsKey(neighbouringRelativeCell + mCentreCell))
							{
								gubbin.mAlternator = mbValidGubbinValue;
								x = y = z = -1;  // Way to break the nested loop.
							}
						}

						++z; if (z > iNeighboursPerDirection) z = -iNeighboursPerDirection;
					} while (z != 0);

					++y; if (y > iNeighboursPerDirection) y = -iNeighboursPerDirection;
				} while (y != 0);

				++x; if (x > iNeighboursPerDirection) x = -iNeighboursPerDirection;
			} while (x != 0);
		}
	}
예제 #4
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	private void LoadDebris(SCellPos absoluteCell)
	{

	}
예제 #5
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	private void LoadSparseAsteroids(SCellPos absoluteCell)
	{
		float fCellRadius = cellRadius;

		uint uiNumAsteroids = SparseAsteroidCount(absoluteCell);
		for (uint ui = 0; ui < uiNumAsteroids; ++ui)
		{
			mGubbinsToLoad.Add(new SGubbinMeta((CGameRegistrator.ENetworkPrefab)Random.Range((ushort)CGameRegistrator.ENetworkPrefab.Asteroid_FIRST, (ushort)CGameRegistrator.ENetworkPrefab.Asteroid_LAST + 1),    // Random asteroid prefab.
												absoluteCell,   // Parent cell.
												new Vector3(Random.Range(-fCellRadius, fCellRadius), Random.Range(-fCellRadius, fCellRadius), Random.Range(-fCellRadius, fCellRadius)), // Position within parent cell.
												Random.rotationUniform, // Rotation.
												Vector3.zero/*Random.onUnitSphere * Random.Range(0.0f, 75.0f)*/,    // Linear velocity.
												Vector3.zero/*Random.onUnitSphere * Random.Range(0.0f, 2.0f)*/, // Angular velocity.
												true,   // Has NetworkedEntity script.
												false    // Has a rigid body.
												));
		}
	}
예제 #6
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float SampleNoise_ResourceAmount(SCellPos absoluteCell)
	{
		float sample = SampleNoise(absoluteCell, 0.01f, ENoiseLayer.AsteroidResourceAmount);
		float start = 0.75f, end = 0.9f;
		sample = (sample - start) / (end - start);
		return sample < 0.0f ? 0.0f : sample > 1.0f ? 1.0f : sample;
	}
예제 #7
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float SampleNoise_DebrisDensity(SCellPos absoluteCell)
	{
		float sample = SampleNoise(absoluteCell, 0.25f, ENoiseLayer.DebrisDensity);
		float start = 0.0f, end = 1.0f;
		sample = (sample - start) / (end - start);
		return sample < 0.0f ? 0.0f : sample > 1.0f ? 1.0f : sample;
	}
예제 #8
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float SampleNoise_SparseAsteroid(SCellPos absoluteCell)
	{
		float sample = SampleNoise(absoluteCell, 0.01f, ENoiseLayer.SparseAsteroidCount);
		float start = 0.5f, end = 0.9f;
		sample = (sample - start) / (end - start);
		return sample < 0.0f ? 0.0f : sample > 1.0f ? 1.0f : sample;
	}
예제 #9
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public Vector3 RelativeCellToRelativePoint(SCellPos relativeCell)
	{
        return new Vector3(relativeCell.x * cellDiameter, relativeCell.y * cellDiameter, relativeCell.z * cellDiameter);
	}
예제 #10
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float SampleNoise(SCellPos absoluteCell, float sampleScale, ENoiseLayer noiseLayer)
	{
		Vector3 samplePoint = AbsoluteCellNoiseSamplePoint(absoluteCell, sampleScale);
		return 0.5f + 0.5f * mNoises[(uint)noiseLayer].Generate(samplePoint.x, samplePoint.y, samplePoint.z);
	}
예제 #11
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public Vector3 AbsoluteCellNoiseSamplePoint(SCellPos absoluteCell, float sampleScale)
	{
		return new Vector3((sampleScale * absoluteCell.x * cellDiameter / cellRadius), (sampleScale * absoluteCell.y * cellDiameter / cellRadius), (sampleScale * absoluteCell.z * cellDiameter / cellRadius));
	}
예제 #12
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	void UnloadAbsoluteCell(SCellPos absoluteCell)
	{
		// Todo: Save stuff to file.
		mCells.Remove(absoluteCell); // Unload the cell.
	}
예제 #13
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	void LoadAbsoluteCell(SCellPos absoluteCell)
	{
		// If the cell was queued for loading, it will already have an entry in the cell dictionary, but unlike Add(); the [] operator allows overwriting existing elements in the dictionary.
		mCells[absoluteCell] = new CCellContent(mbValidCellValue, ECellState.Loaded); // Create cell with updated alternator to indicate cell is within proximity of observer.

		// Load the content for the cell.
		//if (false)   // TODO: If the content for the cell is on file...
		//{
		//    // TODO: Load content from SQL.
		//}
		//else    // This cell is not on file, so it has not been visited...
		{
			// Generate the content in the cell.
			LoadEnemyShips(absoluteCell);
			LoadAsteroidClusters(absoluteCell);
			LoadSparseAsteroids(absoluteCell);
			LoadDebris(absoluteCell);
		}
	}
예제 #14
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float ResourceAmount(SCellPos absoluteCell) { return 800 * SampleNoise_ResourceAmount(absoluteCell); }
예제 #15
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public Vector3 AbsoluteCellToAbsolutePoint(SCellPos absoluteCell)
	{
        return new Vector3(absoluteCell.x * cellDiameter, absoluteCell.y * cellDiameter, absoluteCell.z * cellDiameter);
	}
예제 #16
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public uint EnemyShipCount(SCellPos absoluteCell) { return (uint)Mathf.RoundToInt(1/*maxEnemyShips*/ * SampleNoise_EnemyShipDensity(absoluteCell)); }
예제 #17
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public bool RelativeCellWithinProximityOfPoint(SCellPos relativeCell, Vector3 point, float pointRadius)
	{
		Vector3 cellCentrePos = new Vector3(relativeCell.x * cellDiameter, relativeCell.y * cellDiameter, relativeCell.z * cellDiameter);
		float cellBoundingSphereRadius = cellDiameter * 0.86602540378443864676372317075294f;
        return (cellCentrePos - point).sqrMagnitude <= cellBoundingSphereRadius * cellBoundingSphereRadius + pointRadius * pointRadius;
	}
예제 #18
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float SampleNoise_AsteroidCluster(SCellPos absoluteCell)
	{
		float sample = SampleNoise(absoluteCell, 0.1f, ENoiseLayer.AsteroidClusterCount);
		float start = 0.8f, end = 0.9f;
		sample = (sample - start) / (end - start);
		return sample < 0.0f ? 0.0f : sample > 1.0f ? 1.0f : sample;
	}
예제 #19
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	void UpdateGalaxyAesthetic(SCellPos absoluteCell)
	{
		// Skybox.
		Shader.SetGlobalTexture("void_Skybox1", mSkyboxes[(uint)ESkybox.Stars]);

		if (RenderSettings.skybox == null)
			RenderSettings.skybox = new Material(Shader.Find("VOID/MultitexturedSkybox"));
		RenderSettings.skybox.SetVector("_Tint", Color.grey);

		Shader.SetGlobalFloat("void_FogStartDistance", 2000.0f);
		Shader.SetGlobalFloat("void_FogEndDistance", 4000.0f);
		Shader.SetGlobalFloat("void_FogDensity", 0.01f);

		// Calculate perspective warp.
		Camera camera = Camera.current;
		if (camera)
		{
			float CAMERA_NEAR = camera.nearClipPlane;
			float CAMERA_FAR = camera.farClipPlane;
			float CAMERA_FOV = camera.fieldOfView;
			float CAMERA_ASPECT_RATIO = camera.aspect;

			float fovWHalf = CAMERA_FOV * 0.5f;

			Vector3 toTop = camera.transform.up * CAMERA_NEAR * Mathf.Tan(fovWHalf * Mathf.Deg2Rad);
			Vector3 toRight = toTop * CAMERA_ASPECT_RATIO;

			Vector3 topLeft = camera.transform.forward * CAMERA_NEAR - toRight + toTop;
			float CAMERA_SCALE = topLeft.magnitude * CAMERA_FAR / CAMERA_NEAR;

			topLeft.Normalize();
			topLeft *= CAMERA_SCALE;

			Vector3 topRight = (camera.transform.forward * CAMERA_NEAR + toRight + toTop).normalized * CAMERA_SCALE;
			Vector3 bottomRight = (camera.transform.forward * CAMERA_NEAR + toRight - toTop).normalized * CAMERA_SCALE;
			Vector3 bottomLeft = (camera.transform.forward * CAMERA_NEAR - toRight - toTop).normalized * CAMERA_SCALE;

			Shader.SetGlobalVector("void_FrustumCornerTopLeft", topLeft);
			Shader.SetGlobalVector("void_FrustumCornerTopRight", topRight);
			Shader.SetGlobalVector("void_FrustumCornerBottomRight", bottomRight);
			Shader.SetGlobalVector("void_FrustumCornerBottomLeft", bottomLeft);
			Shader.SetGlobalFloat("void_CameraScale", CAMERA_SCALE);
		}
	}
예제 #20
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float SampleNoise_FogDensity(SCellPos absoluteCell)
	{
		float sample = SampleNoise(absoluteCell, 0.000001f, ENoiseLayer.FogDensity);
		float start = 0.4f, end = 0.8f;
		sample = (sample - start) / (end - start);
		return sample < 0.0f ? 0.0f : sample > 1.0f ? 1.0f : sample;
	}
예제 #21
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public uint SparseAsteroidCount(SCellPos absoluteCell) { return (uint)Mathf.RoundToInt(4/*maxAsteroids*/ * SampleNoise_SparseAsteroid(absoluteCell)); }
예제 #22
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float SampleNoise_EnemyShipDensity(SCellPos absoluteCell)
	{
		float sample = SampleNoise(absoluteCell, 0.001f, ENoiseLayer.EnemyShipCount);
		////float start = 0.85f, end = 0.95f;
		//float start = 0.0f, end = 0.001f;
		float start = 1.1f, end = 1.2f;
		sample = (sample - start) / (end - start);
		return sample < 0.0f ? 0.0f : sample > 1.0f ? 1.0f : sample;
	}
예제 #23
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public uint AsteroidClusterCount(SCellPos absoluteCell) { return (uint)Mathf.RoundToInt(1/*maxClusters*/ * SampleNoise_AsteroidCluster(absoluteCell)); }
예제 #24
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	private void LoadAsteroidClusters(SCellPos absoluteCell)
	{
		float fCellRadius = cellRadius;

		uint uiNumAsteroidClusters = AsteroidClusterCount(absoluteCell);
		for (uint uiCluster = 0; uiCluster < uiNumAsteroidClusters; ++uiCluster)
		{
			uint uiNumAsteroidsInCluster = (uint)Random.Range(6, 21);
			for (uint uiAsteroid = 0; uiAsteroid < uiNumAsteroidsInCluster; ++uiAsteroid)
			{
				Vector3 clusterCentre = new Vector3(Random.Range(-fCellRadius, fCellRadius), Random.Range(-fCellRadius, fCellRadius), Random.Range(-fCellRadius, fCellRadius));

				mGubbinsToLoad.Add(new SGubbinMeta((CGameRegistrator.ENetworkPrefab)Random.Range((ushort)CGameRegistrator.ENetworkPrefab.Asteroid_FIRST, (ushort)CGameRegistrator.ENetworkPrefab.Asteroid_LAST + 1),    // Random asteroid prefab.
													absoluteCell,   // Parent cell.
													clusterCentre + Random.onUnitSphere * Random.Range(0.0f, fCellRadius * 0.25f), // Position within parent cell.
													Random.rotationUniform, // Rotation.
													Vector3.zero/*Random.onUnitSphere * Random.Range(0.0f, 75.0f)*/,    // Linear velocity.
													Vector3.zero/*Random.onUnitSphere * Random.Range(0.0f, 2.0f)*/, // Angular velocity.
													true,   // Has NetworkedEntity script.
													true    // Has a rigid body.
													));
			}
		}
	}
예제 #25
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	public float DebrisDensity(SCellPos absoluteCell) { return SampleNoise_DebrisDensity(absoluteCell); }
예제 #26
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	private void LoadEnemyShips(SCellPos absoluteCell)
	{
		float fCellRadius = cellRadius;
		uint uiNumEnemyShips = EnemyShipCount(absoluteCell);

		for (uint ui = 0; ui < uiNumEnemyShips; ++ui)
		{
			mGubbinsToLoad.Add(new SGubbinMeta(CGameRegistrator.ENetworkPrefab.EnemyShip,    // Enemy ship prefab.
												absoluteCell,   // Parent cell.
												new Vector3(Random.Range(-fCellRadius, fCellRadius), Random.Range(-fCellRadius, fCellRadius), Random.Range(-fCellRadius, fCellRadius)), // Position within parent cell.
												Random.rotationUniform, // Rotation.
												Vector3.zero/*Random.onUnitSphere * Random.Range(0.0f, 75.0f)*/,    // Linear velocity.
												Vector3.zero/*Random.onUnitSphere * Random.Range(0.0f, 2.0f)*/, // Angular velocity.
												true,   // Has NetworkedEntity script.
												true    // Has a rigid body.
												));
		}
	}
예제 #27
0
파일: CGalaxy.cs 프로젝트: nulhax/VOID
	private void UpdateCellLoadingQueue()
	{
		mbValidCellValue = !mbValidCellValue;   // Alternate the valid cell value. All cells within proximity of an observer will be updated, while all others will retain the old value making it easier to detect and cull them.;

		// Queue for loading: unloaded cells within proximity to observers.
		foreach (CRegisteredObserver observer in mObservers)
		{
			Vector3 observerPosition = observer.mEntity.transform.position;
			SCellPos occupiedRelativeCell = RelativePointToRelativeCell(observerPosition);
			int iCellsInARow = 1 /*Centre cell*/ + (int)mNumExtraNeighbourCells * 2 /*Neighbouring cell rows*/ + (Mathf.CeilToInt((observer.mBoundingRadius / cellRadius) - 1) * 2);    // Centre point plus neighbours per axis.   E.g. 1,3,5,7,9...
			int iNeighboursPerDirection = (iCellsInARow - 1) / 2;                                                                                                                       // Neighbours per direction.                E.g. 0,2,4,6,8...

			for (int x = -iNeighboursPerDirection; x <= iNeighboursPerDirection; ++x)
			{
				for (int y = -iNeighboursPerDirection; y <= iNeighboursPerDirection; ++y)
				{
					for (int z = -iNeighboursPerDirection; z <= iNeighboursPerDirection; ++z)
					{
						// Check if this cell is loaded.
						SCellPos neighbouringRelativeCell = new SCellPos(occupiedRelativeCell.x + x, occupiedRelativeCell.y + y, occupiedRelativeCell.z + z);
						if (RelativeCellWithinProximityOfPoint(neighbouringRelativeCell, observerPosition, observer.mBoundingRadius + cellDiameter * mNumExtraNeighbourCells))
						{
							SCellPos neighbouringAbsoluteCell = neighbouringRelativeCell + mCentreCell;
							CCellContent temp;
							if (mCells.TryGetValue(neighbouringAbsoluteCell, out temp))   // If this cell has already been loaded...
							{
								temp.mAlternator = mbValidCellValue;    // Update alternator to indicate the cell is within proximity to an observer.
								if (temp.mState == ECellState.Unloading) // If this cell is waiting to be unloaded...
								{
									mCellsToUnload.Remove(neighbouringAbsoluteCell);    // Stop it from unloading, as it is now back in proximity to observers.
									temp.mState = ECellState.Loaded;    // Reset cell state to 'loaded', as only loaded cells are queued for unloading.
								}
							}
							else    // This cell has not been loaded...
							{
								mCellsToLoad.Add(neighbouringAbsoluteCell); // Queue cell to load.
								mCells.Add(neighbouringAbsoluteCell, new CCellContent(mbValidCellValue, ECellState.Loading));    // Add cell to dictionary of cells as loading.
							}
						}
					}
				}
			}
		}
	}