/// <summary> /// Some parameters should be initialized when the emitter first runs, rather than in the constructor /// </summary> protected unsafe void DelayedInitialization(ParticleSystem parentSystem) { if (hasBeenInitialized) { return; } hasBeenInitialized = true; // RandomNumberGenerator creation { uint rngSeed = 0; // EmitterRandomSeedMethod.Fixed if (randomSeedMethod == EmitterRandomSeedMethod.Time) { // Stopwatch has maximum possible frequency, so rngSeeds initialized at different times will be different rngSeed = unchecked ((uint)Stopwatch.GetTimestamp()); } else if (randomSeedMethod == EmitterRandomSeedMethod.Position) { // Different float have different uint representation so randomness should be good // The only problem occurs when the three position components are the same var posX = parentSystem.Translation.X; var posY = parentSystem.Translation.Y; var posZ = parentSystem.Translation.Z; var uintX = *((uint *)(&posX)); var uintY = *((uint *)(&posY)); var uintZ = *((uint *)(&posZ)); // Add some randomness to prevent glitches when positions are the same (diagonal) uintX ^= (uintX >> 19); uintY ^= (uintY >> 8); rngSeed = uintX ^ uintY ^ uintZ; } RandomSeedGenerator = new ParticleRandomSeedGenerator(rngSeed); } }
/// <summary> /// Some parameters should be initialized when the emitter first runs, rather than in the constructor /// </summary> protected unsafe void DelayedInitialization(ParticleSystem parentSystem) { if (hasBeenInitialized) return; hasBeenInitialized = true; // RandomNumberGenerator creation { uint rngSeed = 0; // EmitterRandomSeedMethod.Fixed if (randomSeedMethod == EmitterRandomSeedMethod.Time) { // Stopwatch has maximum possible frequency, so rngSeeds initialized at different times will be different rngSeed = unchecked((uint)Stopwatch.GetTimestamp()); } else if (randomSeedMethod == EmitterRandomSeedMethod.Position) { // Different float have different uint representation so randomness should be good // The only problem occurs when the three position components are the same var posX = parentSystem.Translation.X; var posY = parentSystem.Translation.Y; var posZ = parentSystem.Translation.Z; var uintX = *((uint*)(&posX)); var uintY = *((uint*)(&posY)); var uintZ = *((uint*)(&posZ)); // Add some randomness to prevent glitches when positions are the same (diagonal) uintX ^= (uintX >> 19); uintY ^= (uintY >> 8); rngSeed = uintX ^ uintY ^ uintZ; } RandomSeedGenerator = new ParticleRandomSeedGenerator(rngSeed); } }