예제 #1
0
파일: world.cpp 프로젝트: aap/gtatools
void Instance::releaseIfInactive(void)
{
	WorldObject *op = static_cast<WorldObject*>(objectList->get(id));

	float dist = cam->distanceTo(position)/renderer->lodMult;
	int ai = op->getCorrectAtomic(dist);

	if (ai < 0 && isActive) {
		op->decRefCount();
		isActive = false;
	}
}
예제 #2
0
파일: world.cpp 프로젝트: aap/gtatools
void Instance::addToRenderList(void)
{
	const float fadeThrshd = FADE;

	// set by 'addOpaqueObject'
	if (wasAdded)
		return;

	WorldObject *op = static_cast<WorldObject*>(objectList->get(id));

	float dist = cam->distanceTo(position)/renderer->lodMult - fadeThrshd;
	int ai = op->getCorrectAtomic(dist);

	// frustum cull
	if (op->canDraw())
		if (isCulled() && !(op->flags & 128))
			return;

	// if the instance is too far away, try the LOD version
	if (ai < 0) {
		addLodToRenderList();
		goto release;
	}

	if (isHidden)
		return;

	if (op->modelName == "LODDUMMY")
		return;

	// check for interior (if intr < 0 everything is drawn)
	int intr;
	intr = world->getInterior();
	if (interior != intr && intr >= 0 && !renderer->doCol) {
		if (game == GTAVC) {
			if (interior != 13)
				goto release;
		} if (game == GTASA) {
			// Gotta figure out what's the meaning of this.
			if (interior != 13 && interior != 256 &&
			    interior != 269 && interior != 2048 &&
			    interior != 768 && interior != 512 &&
			    interior != 6144 &&
			    interior != 1024 && interior != 4096)
				goto release;
		}
	}

	// check for time
	if (op->isTimed && !op->isVisibleAtTime(timeCycle.getHour()) &&
	    !renderer->doCol)
		goto release;

	// request model
	if (!isActive) {
		op->incRefCount();
		isActive = true;
	}

	if (!op->canDraw()) {
		addLodToRenderList();
		return;
	}

	float drawDist, distDiff;
	drawDist = op->getDrawDistance(-1);
	distDiff = drawDist - dist;

	if (distDiff < fadeThrshd)
		setFading(distDiff/fadeThrshd);
	else if (getFading() != 1.0f)
		// Increment fading value for instances that are
		// well within the draw dist.
		setFading(getFading()+0.25f);
	else if (op->isFreshlyLoaded)
		setFading(0.0f);
		// Retain the freshlyLoaded flag for other instances.
		// It is cleared by Renderer.
	else
		setFading(1.0f);

	// If a new instance is being faded in or out, also draw LOD
	if (getFading() != 1.0f)
		addLodToRenderList();

	if (!isActive)
		cout << name << " this can't be\n";

	if (op->type == ANIM)
		renderer->addOpaqueObject(this, -1);
	else
		renderer->addOpaqueObject(this, ai);
	return;

release:
	if (isActive) {
		op->decRefCount();
		isActive = false;
	}
	return;
}