Beispiel #1
0
DEF_TEST(StreamPeek_BlockMemoryStream, rep) {
    const static int kSeed = 1234;
    SkRandom valueSource(kSeed);
    SkRandom rand(kSeed << 1);
    uint8_t buffer[4096];
    SkDynamicMemoryWStream dynamicMemoryWStream;
    for (int i = 0; i < 32; ++i) {
        // Randomize the length of the blocks.
        size_t size = rand.nextRangeU(1, sizeof(buffer));
        for (size_t j = 0; j < size; ++j) {
            buffer[j] = valueSource.nextU() & 0xFF;
        }
        dynamicMemoryWStream.write(buffer, size);
    }
    SkAutoTDelete<SkStreamAsset> asset(dynamicMemoryWStream.detachAsStream());
    SkAutoTUnref<SkData> expected(SkData::NewUninitialized(asset->getLength()));
    uint8_t* expectedPtr = static_cast<uint8_t*>(expected->writable_data());
    valueSource.setSeed(kSeed);  // reseed.
    // We want the exact same same "random" string of numbers to put
    // in expected. i.e.: don't rely on SkDynamicMemoryStream to work
    // correctly while we are testing SkDynamicMemoryStream.
    for (size_t i = 0; i < asset->getLength(); ++i) {
        expectedPtr[i] = valueSource.nextU() & 0xFF;
    }
    stream_peek_test(rep, asset, expected);
}
Beispiel #2
0
void SimulateParticleMovement(PartSysEmitter* emitter, float timeToSimulateSecs) {

	const auto& spec = emitter->GetSpec();

	// Used as a factor in integrating the acceleration to retroactively calculate
	// its influence on the particle position
	auto accelIntegrationFactor = timeToSimulateSecs * timeToSimulateSecs * 0.5f;

	auto& state = emitter->GetParticleState();
	auto it = emitter->NewIterator();
	while (it.HasNext()) {
		auto particleIdx = it.Next();
		auto particleAge = emitter->GetParticleAge(particleIdx);

		ParticleValueSource valueSource(emitter, particleIdx, particleAge);

		auto x = state.GetState(PSF_X, particleIdx);
		auto y = state.GetState(PSF_Y, particleIdx);
		auto z = state.GetState(PSF_Z, particleIdx);

		auto velX = state.GetState(PSF_VEL_X, particleIdx);
		auto velY = state.GetState(PSF_VEL_Y, particleIdx);
		auto velZ = state.GetState(PSF_VEL_Z, particleIdx);

		// Calculate new position of particle based on velocity
		x += timeToSimulateSecs * velX;
		y += timeToSimulateSecs * velY;
		z += timeToSimulateSecs * velZ;

		// Apply acceleration to velocity (retroactively to position as well)
		float value;
		if (valueSource.GetValue(part_accel_X, &value)) {
			x += accelIntegrationFactor * value;
			velX += timeToSimulateSecs * value;
		}
		if (valueSource.GetValue(part_accel_Y, &value)) {
			y += accelIntegrationFactor * value;
			velY += timeToSimulateSecs * value;
		}
		if (valueSource.GetValue(part_accel_Z, &value)) {
			z += accelIntegrationFactor * value;
			velZ += timeToSimulateSecs * value;
		}

		/*
			Apply Velocity Var
		*/
		if (spec->GetParticleVelocityCoordSys() == PartSysCoordSys::Polar) {
			if (spec->GetParticlePosCoordSys() != PartSysCoordSys::Polar) {
				// Velocity is polar, positions are not -> convert velocity
				auto azimuth = emitter->GetParamValue(part_velVariation_X, particleIdx, particleAge);
				auto inclination = emitter->GetParamValue(part_velVariation_Y, particleIdx, particleAge);
				auto radius = emitter->GetParamValue(part_velVariation_Z, particleIdx, particleAge);

				auto cartesianVel = SphericalDegToCartesian(azimuth, inclination, radius);
				x += cartesianVel.x * timeToSimulateSecs;
				y += cartesianVel.y * timeToSimulateSecs;
				z += cartesianVel.z * timeToSimulateSecs;
			} else {
				// Modify the spherical coordinates of the particle directly
				if (valueSource.GetValue(part_velVariation_X, &value)) {
					auto azimuth = state.GetStatePtr(PSF_POS_AZIMUTH, particleIdx);
					*azimuth += value * timeToSimulateSecs;
				}
				if (valueSource.GetValue(part_velVariation_Y, &value)) {
					auto inclination = state.GetStatePtr(PSF_POS_INCLINATION, particleIdx);
					*inclination += value * timeToSimulateSecs;
				}
				if (valueSource.GetValue(part_velVariation_Z, &value)) {
					auto radius = state.GetStatePtr(PSF_POS_RADIUS, particleIdx);
					*radius += value * timeToSimulateSecs;
				}
			}

		} else {
			// Cartesian velocity seems pretty simple here
			if (valueSource.GetValue(part_velVariation_X, &value)) {
				x += value * timeToSimulateSecs;
			}
			if (valueSource.GetValue(part_velVariation_Y, &value)) {
				y += value * timeToSimulateSecs;
			}
			if (valueSource.GetValue(part_velVariation_Z, &value)) {
				z += value * timeToSimulateSecs;
			}
		}
		
		/*
			Apply Pos Var
		*/
		float xPosVar, yPosVar, zPosVar;

		if (spec->GetParticlePosCoordSys() == PartSysCoordSys::Polar) {
			// Get current particle spherical coordinates
			auto azimuth = state.GetState(PSF_POS_AZIMUTH, particleIdx);
			auto inclination = state.GetState(PSF_POS_INCLINATION, particleIdx);
			auto radius = state.GetState(PSF_POS_RADIUS, particleIdx);

			// Modify them according to position variation parameters
			if (valueSource.GetValue(part_posVariation_X, &value)) {
				azimuth += value;
			}
			if (valueSource.GetValue(part_posVariation_Y, &value)) {
				inclination += value;
			}
			if (valueSource.GetValue(part_posVariation_Z, &value)) {
				radius += value;
			}

			// Convert the position that has been modified this way to cartesian
			auto cartesianPosVar = SphericalDegToCartesian(azimuth, inclination, radius);

			// Add the current unmodified particle pos to get to the final position
			xPosVar = cartesianPosVar.x;
			yPosVar = cartesianPosVar.y;
			zPosVar = cartesianPosVar.z;
		} else {
			xPosVar = emitter->GetParamValue(part_posVariation_X, particleIdx, particleAge);
			yPosVar = emitter->GetParamValue(part_posVariation_Y, particleIdx, particleAge);
			zPosVar = emitter->GetParamValue(part_posVariation_Z, particleIdx, particleAge);
		}
		
		// Save new particle state
		state.SetState(PSF_X, particleIdx, x);
		state.SetState(PSF_Y, particleIdx, y);
		state.SetState(PSF_Z, particleIdx, z);
		state.SetState(PSF_VEL_X, particleIdx, velX);
		state.SetState(PSF_VEL_Y, particleIdx, velY);
		state.SetState(PSF_VEL_Z, particleIdx, velZ);
		state.SetState(PSF_POS_VAR_X, particleIdx, x + xPosVar);
		state.SetState(PSF_POS_VAR_Y, particleIdx, y + yPosVar);
		state.SetState(PSF_POS_VAR_Z, particleIdx, z + zPosVar);
	}

}