void TreatBackgroundDynlights() { ARX_PROFILE_FUNC(); for(size_t i = 0; i < MAX_LIGHTS; i++) { EERIE_LIGHT *light = GLight[i]; if(light && (light->extras & EXTRAS_SEMIDYNAMIC)) { float fMaxdist = player.m_telekinesis ? 850 : 300; if(!fartherThan(light->pos, ACTIVECAM->orgTrans.pos, fMaxdist)) { ComputeLight2DPos(light); } else { light->m_screenRect.max.x = -1; light->m_screenRect.min.x = 1; } if(!light->m_ignitionStatus) { // just extinguished if(lightHandleIsValid(light->m_ignitionLightHandle)) { lightHandleGet(light->m_ignitionLightHandle)->exist = 0; light->m_ignitionLightHandle = LightHandle(); for(size_t l = 0; l < entities.size(); l++) { const EntityHandle handle = EntityHandle(l); Entity * e = entities[handle]; if(e && (e->ioflags & IO_MARKER)) { Vec3f _pos2 = GetItemWorldPosition(e); if(!fartherThan(light->pos, _pos2, 300.f)) { SendIOScriptEvent(e, SM_CUSTOM, "douse"); } } } } } else { // just light up if(!lightHandleIsValid(light->m_ignitionLightHandle)) { for(size_t l = 0; l < entities.size(); l++) { const EntityHandle handle = EntityHandle(l); Entity * e = entities[handle]; if(e && (e->ioflags & IO_MARKER)) { Vec3f _pos2 = GetItemWorldPosition(e); if(!fartherThan(light->pos, _pos2, 300.f)) { SendIOScriptEvent(e, SM_CUSTOM, "fire"); } } } light->m_ignitionLightHandle = GetFreeDynLight(); } if(lightHandleIsValid(light->m_ignitionLightHandle)) { EERIE_LIGHT *dynamicLight = lightHandleGet(light->m_ignitionLightHandle); dynamicLight->pos = light->pos; dynamicLight->fallstart = light->fallstart; dynamicLight->fallend = light->fallend; dynamicLight->m_isIgnitionLight = true; dynamicLight->intensity = light->intensity; dynamicLight->ex_flaresize = light->ex_flaresize; dynamicLight->extras = light->extras; dynamicLight->duration = std::numeric_limits<long>::max(); dynamicLight->rgb = light->rgb - light->rgb * light->ex_flicker * randomColor3f() * 0.5f; dynamicLight->rgb = componentwise_max(dynamicLight->rgb, Color3f::black); RecalcLight(dynamicLight); } } } } for(size_t i = 0; i < MAX_DYNLIGHTS; i++) { EERIE_LIGHT * el = &DynLight[i]; if(el->exist && el->duration) { float tim = (float)float(arxtime) - (float)el->time_creation; float duration = (float)el->duration; if(tim >= duration) { float sub = framedelay * 0.001f; el->rgb.r -= sub; el->rgb.g -= sub; el->rgb.b -= sub; if(el->rgb.r < 0) el->rgb.r = 0.f; if(el->rgb.g < 0) el->rgb.g = 0.f; 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; } } } } }
void TreatBackgroundDynlights() { ARX_PROFILE_FUNC(); for(size_t i = 0; i < g_staticLightsMax; i++) { EERIE_LIGHT * light = g_staticLights[i]; if(light && (light->extras & EXTRAS_SEMIDYNAMIC)) { float fMaxdist = player.m_telekinesis ? 850 : 300; if(!fartherThan(light->pos, g_camera->m_pos, fMaxdist)) { ComputeLight2DPos(light); } else { light->m_screenRect = Rectf(1, 0, -1, 0); // Intentionally invalid } if(!light->m_ignitionStatus) { // just extinguished EERIE_LIGHT * dynLight = lightHandleGet(light->m_ignitionLightHandle); if(dynLight) { dynLight->m_exists = false; light->m_ignitionLightHandle = LightHandle(); for(size_t l = 0; l < entities.size(); l++) { const EntityHandle handle = EntityHandle(l); Entity * e = entities[handle]; if(e && (e->ioflags & IO_MARKER)) { Vec3f _pos2 = GetItemWorldPosition(e); if(!fartherThan(light->pos, _pos2, 300.f)) { SendIOScriptEvent(NULL, e, SM_CUSTOM, "douse"); } } } } } else { // just light up if(!lightHandleGet(light->m_ignitionLightHandle)) { for(size_t l = 0; l < entities.size(); l++) { const EntityHandle handle = EntityHandle(l); Entity * e = entities[handle]; if(e && (e->ioflags & IO_MARKER)) { Vec3f _pos2 = GetItemWorldPosition(e); if(!fartherThan(light->pos, _pos2, 300.f)) { SendIOScriptEvent(NULL, e, SM_CUSTOM, "fire"); } } } light->m_ignitionLightHandle = GetFreeDynLight(); } EERIE_LIGHT * dynamicLight = lightHandleGet(light->m_ignitionLightHandle); if(dynamicLight) { dynamicLight->pos = light->pos; dynamicLight->fallstart = light->fallstart; dynamicLight->fallend = light->fallend; dynamicLight->m_isIgnitionLight = true; dynamicLight->intensity = light->intensity; dynamicLight->ex_flaresize = light->ex_flaresize; dynamicLight->extras = light->extras; dynamicLight->duration = GameDurationMs(std::numeric_limits<long>::max()); dynamicLight->rgb = light->rgb - light->rgb * light->ex_flicker * randomColor3f() * 0.5f; dynamicLight->rgb = componentwise_max(dynamicLight->rgb, Color3f::black); RecalcLight(dynamicLight); } } } } for(size_t i = 0; i < g_dynamicLightsMax; i++) { EERIE_LIGHT * el = &g_dynamicLights[i]; if(el->m_exists && el->duration != 0) { const GameDuration elapsed = g_gameTime.now() - el->creationTime; const GameDuration duration = el->duration; if(elapsed >= duration) { float sub = g_gameTime.lastFrameDuration() / GameDurationMs(1000); el->rgb.r -= sub; el->rgb.g -= sub; el->rgb.b -= sub; if(el->rgb.r < 0) el->rgb.r = 0.f; if(el->rgb.g < 0) el->rgb.g = 0.f; if(el->rgb.b < 0) el->rgb.b = 0.f; if(el->rgb.r + el->rgb.g + el->rgb.b == 0) { el->m_exists = false; el->duration = 0; } } } } }
void ARX_MAGICAL_FLARES_Update() { if(!flarenum) return; shinum++; if(shinum >= 10) { shinum = 1; } long TICKS = long(arxtime) - FRAMETICKS; FRAMETICKS = (unsigned long)(arxtime); if(TICKS < 0) { return; } bool key = !GInput->actionPressed(CONTROLS_CUST_MAGICMODE); RenderMaterial mat; mat.setBlendType(RenderMaterial::Additive); EERIE_LIGHT * light = lightHandleGet(torchLightHandle); for(long j = 1; j < 5; j++) { TextureContainer * surf; switch(j) { case 2: surf = flaretc.lumignon; break; case 3: surf = flaretc.lumignon2; break; case 4: surf = flaretc.plasm; break; default: surf = flaretc.shine[shinum]; break; } mat.setTexture(surf); for(size_t i = 0; i < MAX_FLARES; i++) { FLARES & flare = magicFlares[i]; if(!flare.exist || flare.type != j) { continue; } flare.tolive -= float(TICKS * 2); if(flare.flags & 1) { flare.tolive -= float(TICKS * 4); } else if (key) { flare.tolive -= float(TICKS * 6); } float z = (flare.tolive * 0.00025f); float s; if(flare.type == 1) { s = flare.size * 2 * z; } else if(flare.type == 4) { s = flare.size * 2.f * z + 10.f; } else { s = flare.size; } if(flare.tolive <= 0.f || flare.pos.y < -64.f || s < 3.f) { removeFlare(flare); continue; } if(flare.type == 1 && z < 0.6f) { z = 0.6f; } Color3f c = flare.rgb * z; flare.tv.color = c.toRGB(); flare.v.p = flare.tv.p; light->rgb = componentwise_max(light->rgb, c); if(lightHandleIsValid(flare.dynlight)) { EERIE_LIGHT * el = lightHandleGet(flare.dynlight); el->pos = flare.v.p; el->rgb = c; } mat.setDepthTest(flare.io != NULL); if(flare.bDrawBitmap) { s *= 2.f * minSizeRatio(); EERIEAddBitmap(mat, flare.v.p, s, s, surf, Color::fromRGBA(flare.tv.color)); } else { EERIEAddSprite(mat, flare.v.p, s * 0.025f + 1.f, Color::fromRGBA(flare.tv.color), 2.f); } } } light->rgb = componentwise_min(light->rgb, Color3f::white); }
void ARX_MAGICAL_FLARES_Update() { if(!g_magicFlaresCount) return; shinum++; if(shinum >= 10) { shinum = 1; } PlatformDuration diff = g_platformTime.lastFrameDuration(); bool key = !GInput->actionPressed(CONTROLS_CUST_MAGICMODE); RenderMaterial mat; mat.setBlendType(RenderMaterial::Additive); EERIE_LIGHT * light = lightHandleGet(torchLightHandle); for(long j = 1; j < 5; j++) { TextureContainer * surf; switch(j) { case 2: surf = g_magicFlareTextures.lumignon; break; case 3: surf = g_magicFlareTextures.lumignon2; break; case 4: surf = g_magicFlareTextures.plasm; break; default: surf = g_magicFlareTextures.shine[shinum]; break; } mat.setTexture(surf); for(size_t i = 0; i < g_magicFlaresMax; i++) { MagicFlare & flare = g_magicFlares[i]; if(!flare.exist || flare.type != j) { continue; } flare.tolive -= diff * 2; if(flare.flags & 1) { flare.tolive -= diff * 4; } else if(key) { flare.tolive -= diff * 6; } float z = flare.tolive / PlatformDurationMs(4000); float size; if(flare.type == 1) { size = flare.size * 2 * z; } else if(flare.type == 4) { size = flare.size * 2.f * z * (4.0f / 3.0f); } else { size = flare.size; } if(flare.tolive <= 0 || flare.pos.y < -64.f || size < 3.f) { removeFlare(flare); continue; } if(flare.type == 1 && z < 0.6f) { z = 0.6f; } Color3f color = flare.rgb * z; light->rgb = componentwise_max(light->rgb, color); EERIE_LIGHT * el = lightHandleGet(flare.dynlight); if(el) { el->pos = flare.p; el->rgb = color; } mat.setDepthTest(flare.io != NULL); if(flare.bDrawBitmap) { Vec3f pos = Vec3f(flare.p.x - size / 2.0f, flare.p.y - size / 2.0f, flare.p.z); EERIEAddBitmap(mat, pos, size, size, surf, Color(color)); } else { EERIEAddSprite(mat, flare.p, size * 0.025f + 1.f, Color(color), 2.f); } } } light->rgb = componentwise_min(light->rgb, Color3f::white); }
//************************************************************************************* //************************************************************************************* void TreatBackgroundDynlights() { long n; for (size_t i = 0; i < MAX_LIGHTS; i++) { if ((GLight[i] != NULL) && (GLight[i]->extras & EXTRAS_SEMIDYNAMIC)) { float fMaxdist = 300; if (Project.telekinesis) fMaxdist = 850; if(!fartherThan(GLight[i]->pos, ACTIVECAM->pos, fMaxdist)) { ComputeLight2DPos(GLight[i]); } if (GLight[i]->status == 0) { // vient de s'éteindre if (GLight[i]->tl > 0) { DynLight[GLight[i]->tl].exist = 0; GLight[i]->tl = -1; Vec3f _pos2; for(size_t l = 0; l < entities.size(); l++) { if(entities[l] && (entities[l]->ioflags & IO_MARKER)) { GetItemWorldPosition(entities[l], &_pos2); if(!fartherThan(GLight[i]->pos, _pos2, 300.f)) { SendIOScriptEvent(entities[l], SM_CUSTOM, "douse"); } } } } } else { // vient de s'allumer if (GLight[i]->tl <= 0) { Vec3f _pos2; for(size_t l = 0; l < entities.size(); l++) { if(entities[l] && (entities[l]->ioflags & IO_MARKER)) { GetItemWorldPosition(entities[l], &_pos2); if(!fartherThan(GLight[i]->pos, _pos2, 300.f)) { SendIOScriptEvent(entities[l], SM_CUSTOM, "fire"); } } } GLight[i]->tl = GetFreeDynLight(); } n = GLight[i]->tl; if(n != -1) { DynLight[n].pos = GLight[i]->pos; DynLight[n].exist = 1; DynLight[n].fallstart = GLight[i]->fallstart; DynLight[n].fallend = GLight[i]->fallend; DynLight[n].type = TYP_SPECIAL1; DynLight[n].intensity = GLight[i]->intensity; DynLight[n].ex_flaresize = GLight[i]->ex_flaresize; DynLight[n].extras = GLight[i]->extras; DynLight[n].duration = std::numeric_limits<long>::max(); DynLight[n].rgb.r = GLight[i]->rgb.r - GLight[i]->rgb.r * GLight[i]->ex_flicker.r * rnd() * ( 1.0f / 2 ); DynLight[n].rgb.g = GLight[i]->rgb.g - GLight[i]->rgb.g * GLight[i]->ex_flicker.g * rnd() * ( 1.0f / 2 ); DynLight[n].rgb.b = GLight[i]->rgb.b - GLight[i]->rgb.b * GLight[i]->ex_flicker.b * rnd() * ( 1.0f / 2 ); DynLight[n].rgb = componentwise_max(DynLight[n].rgb, Color3f::black); DynLight[n].rgb255 = DynLight[n].rgb * 255.f; DynLight[n].falldiff = DynLight[n].fallend - DynLight[n].fallstart; DynLight[n].falldiffmul = 1.f / DynLight[n].falldiff; DynLight[n].precalc = DynLight[n].intensity * GLOBAL_LIGHT_FACTOR; } } } } }
void ARX_MAGICAL_FLARES_Draw() { if(!flarenum) return; shinum++; if(shinum >= 10) { shinum = 1; } long TICKS = long(arxtime) - FRAMETICKS; FRAMETICKS = (unsigned long)(arxtime); if(TICKS < 0) { return; } GRenderer->SetRenderState(Renderer::DepthWrite, false); GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne); GRenderer->SetRenderState(Renderer::AlphaBlending, true); bool key = !GInput->actionPressed(CONTROLS_CUST_MAGICMODE); for(long j = 1; j < 5; j++) { TextureContainer * surf; switch(j) { case 2: surf = flaretc.lumignon; break; case 3: surf = flaretc.lumignon2; break; case 4: surf = flaretc.plasm; break; default: surf = flaretc.shine[shinum]; break; } for(long i = 0; i < MAX_FLARES; i++) { FLARES & flare = magicFlares[i]; if(!flare.exist || flare.type != j) { continue; } flare.tolive -= float(TICKS * 2); if(flare.flags & 1) { flare.tolive -= float(TICKS * 4); } else if (key) { flare.tolive -= float(TICKS * 6); } float z = (flare.tolive * 0.00025f); float s; if(flare.type == 1) { s = flare.size * 2 * z; } else if(flare.type == 4) { s = flare.size * 2.f * z + 10.f; } else { s = flare.size; } if(flare.tolive <= 0.f || flare.y < -64.f || s < 3.f) { if(flare.io && ValidIOAddress(flare.io)) { flare.io->flarecount--; } if(ValidDynLight(flare.dynlight)) { DynLight[flare.dynlight].exist = 0; } flare.dynlight = -1; flare.exist = 0; flarenum--; continue; } if(flare.type == 1 && z < 0.6f) { z = 0.6f; } Color3f c = flare.rgb * z; flare.tv.color = c.toBGR(); flare.v.p = flare.tv.p; DynLight[0].rgb = componentwise_max(DynLight[0].rgb, c); if(ValidDynLight(flare.dynlight)) { EERIE_LIGHT * el = &DynLight[flare.dynlight]; el->pos = flare.v.p; el->rgb = c; } if(!flare.io) { GRenderer->SetRenderState(Renderer::DepthTest, false); } else { GRenderer->SetRenderState(Renderer::DepthTest, true); } if(flare.bDrawBitmap) { s *= 2.f; EERIEDrawBitmap(flare.v.p.x, flare.v.p.y, s, s, flare.v.p.z, surf, Color::fromBGRA(flare.tv.color)); } else { EERIEDrawSprite(&flare.v, s * 0.025f + 1.f, surf, Color::fromBGRA(flare.tv.color), 2.f); } } } DynLight[0].rgb = componentwise_min(DynLight[0].rgb, Color3f::white); GRenderer->SetRenderState(Renderer::DepthWrite, true); GRenderer->SetRenderState(Renderer::DepthTest, true); }