Beispiel #1
0
CharacterObject* GameWorld::createPlayer(const glm::vec3& pos, const glm::quat& rot, GameObjectID gid)
{
	// Player object ID is hardcoded to 0.
	auto pt = data->findObjectType<CharacterData>(0);
	if( pt ) {
		// Model name is also hardcoded.
		std::string modelname = "player";
		std::string texturename = "player";

		// Ensure the relevant data is loaded.
		data->loadDFF(modelname + ".dff");
		data->loadTXD(texturename + ".txd");

		ModelRef m = data->models[modelname];

		if(m && m->resource) {
			auto ped = new CharacterObject( this, pos, rot, m, nullptr );
			ped->setGameObjectID(gid);
			ped->setLifetime(GameObject::PlayerLifetime);
			players.push_back(new PlayerController(ped));
			pedestrianPool.insert(ped);
            allObjects.push_back( ped );
			return ped;
		}
	}
	return nullptr;
}
Beispiel #2
0
VehicleObject* GameWorld::tryToSpawnVehicle(VehicleGenerator& gen)
{
	constexpr float kMinClearRadius = 10.f;

	if (gen.remainingSpawns <= 0) {
		return nullptr;
	}

	/// @todo take into account maxDelay as well
	if (gen.lastSpawnTime + gen.minDelay > int(state->basic.timeMS)) {
		return nullptr;
	}

	/// @todo verify this logic
	auto position = gen.position;
	if (position.z < -90.f) {
		position = getGroundAtPosition(position);
	}

	// Ensure there's no existing vehicles near our spawn point
	for (auto& v : vehiclePool.objects)
	{
		if (glm::distance2(position, v.second->getPosition())
				< kMinClearRadius * kMinClearRadius) {
			return nullptr;
		}
	}

	int id = gen.vehicleID;
	if (id == -1) {
		// Random ID found by dice roll
		id = 134;
		/// @todo use zone information to decide vehicle id
	}

	auto vehicle = createVehicle(
				id,
				position);
	vehicle->setHeading(gen.heading);
	vehicle->setLifetime(GameObject::TrafficLifetime);

	/// @todo apply vehicle colours
	/// @todo apply locked & alarm thresholds

	// According to http://www.gtamodding.com/wiki/014C the spawn limit
	// doesn't work.
#if 0
	if (gen.remainingSpawns < 101) {
		gen.remainingSpawns --;
	}
#endif

	gen.lastSpawnTime = state->basic.timeMS;

	return vehicle;
}
//The constructor.
Particle::Particle()
{
    //Setting the default values.
    setPosition(Vector3(0, 0, 0));
    setVelocity(Vector3(0, 0, 0));
    setStartColor(Vector4(1, 1, 1, 1));
    setEndColor(Vector4(1, 1, 1, 1));
    setStartSize(1);
    setEndSize(1);
    setLifetime(1);
}
//The complete constructor.
Particle::Particle(Vector3 position, Vector3 velocity, Vector4 startColor,
                   Vector4 endColor, float startSize,
                   float endSize, float lifetime)
{
    //Setting the values passed in.
    setPosition(position);
    setVelocity(velocity);
    setStartColor(startColor);
    setEndColor(endColor);
    setStartSize(startSize);
    setEndSize(endSize);
    setLifetime(lifetime);
}
Beispiel #5
0
void NotificationItem::restoreState(QSettings* settings)
{
    //settings = Core::ICore::instance()->settings();
    setSoundCollectionPath(Utils::PathUtils().InsertDataPath(settings->value(QLatin1String("SoundCollectionPath"), tr("")).toString()));
    setCurrentLanguage(settings->value(QLatin1String("CurrentLanguage"), tr("")).toString());
    setDataObject(settings->value(QLatin1String("DataObject"), tr("")).toString());
    setObjectField(settings->value(QLatin1String("ObjectField"), tr("")).toString());
    setCondition(settings->value(QLatin1String("RangeLimit"), tr("")).toInt());
    setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString());
    setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString());
    setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString());
    setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toInt());
    QVariant value = settings->value(QLatin1String("Value1"), tr(""));
    setSingleValue(value);
    setValueRange2(settings->value(QLatin1String("Value2"), tr("")).toDouble());
    setRetryValue(settings->value(QLatin1String("Repeat"), tr("")).toInt());
    setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt());
    setMute(settings->value(QLatin1String("Mute"), tr("")).toInt());
}
void ServerAllocation::handleRefreshRequest(Request& request) 
{
    TraceL << "Handle Refresh Request" << endl;
    assert(request.methodType() == stun::Message::Refresh);
    assert(request.classType() == stun::Message::Request);

    // 7.2. Receiving a Refresh Request

    // When the server receives a Refresh request, it processes as per
    // Section 4 plus the specific rules mentioned here.

    // The server computes a value called the "desired lifetime" as follows:
    // if the request contains a LIFETIME attribute and the attribute value
    // is 0, then the "desired lifetime" is 0.  Otherwise, if the request
    // contains a LIFETIME attribute, then the server computes the minimum
    // of the client's requested lifetime and the server's maximum allowed
    // lifetime.  If this computed value is greater than the default
    // lifetime, then the "desired lifetime" is the computed value.
    // Otherwise, the "desired lifetime" is the default lifetime.    

    // Compute the appropriate LIFETIME for this allocation.
    auto lifetimeAttr = request.get<stun::Lifetime>();
    if (!lifetimeAttr) {
        return;
    }    
    std::uint32_t desiredLifetime = std::min<std::uint32_t>(_server.options().allocationMaxLifetime / 1000, lifetimeAttr->value());
    //lifetime = min(lifetime, lifetimeAttr->value() * 1000);

    // Subsequent processing depends on the "desired lifetime" value:

    // o  If the "desired lifetime" is 0, then the request succeeds and the
    //    allocation is deleted.

    // o  If the "desired lifetime" is non-zero, then the request succeeds
    //    and the allocation's time-to-expiry is set to the "desired
    //    lifetime".

    if (desiredLifetime > 0)
        setLifetime(desiredLifetime);
    else {
        delete this;
    }

    // If the request succeeds, then the server sends a success response
    // containing:

    // o  A LIFETIME attribute containing the current value of the time-to-
    //    expiry timer.

    //    NOTE: A server need not do anything special to implement
    //    idempotency of Refresh requests over UDP using the "stateless
    //    stack approach".  Retransmitted Refresh requests with a non-zero
    //    "desired lifetime" will simply refresh the allocation.  A
    //    retransmitted Refresh request with a zero "desired lifetime" will
    //    cause a 437 (Allocation Mismatch) response if the allocation has
    //    already been deleted, but the client will treat this as equivalent
    //    to a success response (see below).
    
    stun::Message response(stun::Message::SuccessResponse, stun::Message::Refresh);
    response.setTransactionID(request.transactionID());

    auto resLifetimeAttr = new stun::Lifetime;
    resLifetimeAttr->setValue(desiredLifetime);
    response.add(resLifetimeAttr);
    
    _server.respond(request, response);
    //request.socket->send(response, request.remoteAddress);
}