Exemplo n.º 1
0
void ARX_SCENE_Update() {
	arx_assert(portals);
	
	ARX_PROFILE_FUNC();
	
	unsigned long tim = (unsigned long)(arxtime);

	WATEREFFECT+=0.0005f*framedelay;

	long l = ACTIVECAM->cdepth * 0.42f;
	long clip3D = (l / (long)BKG_SIZX) + 1;
	short radius = clip3D + 4;

	// TODO copy-paste background tiles
	int tilex = ACTIVECAM->orgTrans.pos.x * ACTIVEBKG->Xmul;
	int tilez = ACTIVECAM->orgTrans.pos.z * ACTIVEBKG->Zmul;
	tilex = glm::clamp(tilex, 0, ACTIVEBKG->Xsize - 1);
	tilez = glm::clamp(tilez, 0, ACTIVEBKG->Zsize - 1);

	short minx = std::max(tilex - radius, 0);
	short maxx = std::min(tilex + radius, ACTIVEBKG->Xsize - 1);
	short minz = std::max(tilez - radius, 0);
	short maxz = std::min(tilez + radius, ACTIVEBKG->Zsize - 1);

	ACTIVEBKG->fastdata[tilex][tilez].treat = true;
	TreatBackgroundDynlights();
	PrecalcDynamicLighting(minx, minz, maxx, maxz);

	// Go for a growing-square-spirallike-render around the camera position
	// (To maximize Z-Buffer efficiency)

	for(short z = minz; z <= maxz; z++)
	for(short x = minx; x < maxx; x++) {
		ACTIVEBKG->fastdata[x][z].treat = false;
	}

	ResetTileLights();

	long room_num = ARX_PORTALS_GetRoomNumForPosition(ACTIVECAM->orgTrans.pos, 1);
	if(room_num>-1) {

		ARX_PORTALS_InitDrawnRooms();
		size_t roomIndex = static_cast<size_t>(room_num);
		EERIE_FRUSTRUM frustrum;
		CreateScreenFrustrum(&frustrum);
		ARX_PORTALS_Frustrum_ComputeRoom(roomIndex, frustrum);

		for(size_t i = 0; i < RoomDrawList.size(); i++) {
			ARX_PORTALS_Frustrum_RenderRoomTCullSoft(RoomDrawList[i], RoomDraw[RoomDrawList[i]].frustrum, tim);
		}
	} else {
		RoomDrawRelease();
	}

	ARX_THROWN_OBJECT_Manage(checked_range_cast<unsigned long>(framedelay));

	UpdateInter();
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
void PrecalcDynamicLighting(long x0, long z0, long x1, long z1)
{

    TreatBackgroundDynlights();
    TOTPDL = 0;

    float fx0 = ACTIVEBKG->Xdiv * (float)x0;
    float fz0 = ACTIVEBKG->Zdiv * (float)z0;
    float fx1 = ACTIVEBKG->Xdiv * (float)x1;
    float fz1 = ACTIVEBKG->Zdiv * (float)z1;

    for (size_t i = 0; i < MAX_DYNLIGHTS; i++)
    {
        EERIE_LIGHT * el = &DynLight[i];

        if ((el->exist) && (el->rgb.r >= 0.f))
        {

            bool bDist = (distSqr(el->pos, ACTIVECAM->pos) < square(ACTIVECAM->cdepth));

            if ((el->pos.x >= fx0) && (el->pos.x <= fx1)
                    && (el->pos.z >= fz0) && (el->pos.z <= fz1)
                    && bDist)
            {
                el->treat = 1;
                el->rgb255.r = el->rgb.r * 255.f;
                el->rgb255.g = el->rgb.g * 255.f;
                el->rgb255.b = el->rgb.b * 255.f;
                el->falldiff = el->fallend - el->fallstart;
                el->falldiffmul = 1.f / el->falldiff;
                el->precalc = el->intensity * GLOBAL_LIGHT_FACTOR;
                PDL[TOTPDL] = el;
                TOTPDL++;

                if ((size_t)TOTPDL >= MAX_DYNLIGHTS) TOTPDL--;
            }
            else if (el->treat) el->treat = 0;

            if (el->duration)
            {
                float tim = ((float)ARXTime - (float)el->time_creation);
                float duration = (float)el->duration;

                if (tim >= duration)
                {


                    float sub = _framedelay * 0.001f;
                    el->rgb.r -= sub;

                    if (el->rgb.r < 0) el->rgb.r = 0.f;

                    el->rgb.g -= sub;

                    if (el->rgb.g < 0) el->rgb.g = 0.f;

                    el->rgb.b -= sub;

                    if (el->rgb.b < 0) el->rgb.b = 0.f;

                    if (el->rgb.r + el->rgb.g + el->rgb.b == 0)
                    {
                        el->exist = 0;
                        el->duration = 0;
                    }
                }
            }
        }
    }
}