Skip to content

Commit

Permalink
Light: Use bool
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Jun 26, 2018
1 parent 28cccdf commit 262889e
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/ai/PathFinder.cpp
Expand Up @@ -444,7 +444,7 @@ float PathFinder::getIlluminationCost(const Vec3f & pos) const {

for(size_t i = 0; i < slight_c; i++) {

if(!slight_l[i] || !slight_l[i]->exist || !slight_l[i]->m_ignitionStatus) {
if(!slight_l[i] || !slight_l[i]->m_exists || !slight_l[i]->m_ignitionStatus) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/game/Player.cpp
Expand Up @@ -243,7 +243,7 @@ void ARX_PLAYER_KillTorch() {
giveToPlayer(player.torch);

player.torch = NULL;
lightHandleGet(torchLightHandle)->exist = 0;
lightHandleGet(torchLightHandle)->m_exists = false;
}

void ARX_PLAYER_ClickedOnTorch(Entity * io)
Expand Down Expand Up @@ -294,7 +294,7 @@ static void ARX_PLAYER_ManageTorch() {
ARX_SOUND_Stop(SND_TORCH_LOOP);
player.torch->destroy();
player.torch = NULL;
lightHandleGet(torchLightHandle)->exist = 0;
lightHandleGet(torchLightHandle)->m_exists = false;
}

}
Expand Down
7 changes: 4 additions & 3 deletions src/graphics/effects/LightFlare.cpp
Expand Up @@ -123,10 +123,11 @@ void goFor2DFX() {

for(size_t i = 0; i < g_culledDynamicLightsCount; i++) {
const EERIE_LIGHT & el = *g_culledDynamicLights[i];

if(!el.exist || !el.m_isVisible)
if(!el.m_exists || !el.m_isVisible) {
continue;

}

if(el.extras & EXTRAS_FLARE) {
if(el.m_flareFader > 0.f) {
Vec3f ltvv = EE_RT(el.pos);
Expand Down
8 changes: 4 additions & 4 deletions src/graphics/particle/ParticleEffects.cpp
Expand Up @@ -427,7 +427,7 @@ void ManageTorch() {
el->intensity = 1.6f;
el->fallstart = 280.f + rr * 20.f;
el->fallend = el->fallstart + 280.f;
el->exist = 1;
el->m_exists = true;
el->rgb = player.m_torchColor - Color3f(rr, rr, rr) * Color3f(0.1f, 0.1f, 0.1f);
el->duration = 0;
el->extras = 0;
Expand All @@ -438,7 +438,7 @@ void ManageTorch() {
el->intensity = 1.8f;
el->fallstart = 480.f;
el->fallend = el->fallstart + 480.f;
el->exist = 1;
el->m_exists = true;
el->rgb = Color3f(1.f, .5f, .8f);
el->duration = 0;
el->extras = 0;
Expand All @@ -453,10 +453,10 @@ void ManageTorch() {
el->fallstart = 140.f + float(count) * 0.333333f + rr * 5.f;
el->fallend = 220.f + float(count) * 0.5f + rr * 5.f;
el->intensity = 1.6f;
el->exist = 1;
el->m_exists = true;
el->rgb = Color3f(0.01f * count, 0.009f * count, 0.008f * count);
} else {
el->exist = 0;
el->m_exists = false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/Hud.cpp
Expand Up @@ -547,7 +547,7 @@ void CurrentTorchIconGui::updateInput() {
ARX_SOUND_PlaySFX(SND_TORCH_END);
ARX_SOUND_Stop(SND_TORCH_LOOP);
player.torch = NULL;
lightHandleGet(torchLightHandle)->exist = 0;
lightHandleGet(torchLightHandle)->m_exists = false;
io->ignition = 1;
Set_DragInter(io);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/Interface.cpp
Expand Up @@ -1933,7 +1933,7 @@ void ArxGame::manageEditorControls() {
EERIE_LIGHT * light = g_staticLights[i];

if( light
&& light->exist
&& light->m_exists
&& !fartherThan(light->pos, player.pos, fMaxdist)
&& !(light->extras & EXTRAS_NO_IGNIT)
&& light->m_screenRect.contains(Vec2f(DANAEMouse))
Expand Down Expand Up @@ -1978,7 +1978,7 @@ void ArxGame::manageEditorControls() {
EERIE_LIGHT * light = g_staticLights[i];

if( light
&& light->exist
&& light->m_exists
&& !fartherThan(light->pos, player.pos, fMaxdist)
&& !(light->extras & EXTRAS_NO_IGNIT)
&& light->m_screenRect.contains(Vec2f(DANAEMouse))
Expand Down
4 changes: 2 additions & 2 deletions src/gui/book/Book.cpp
Expand Up @@ -1072,14 +1072,14 @@ void StatsPage::RenderBookPlayerCharacter() {
EERIE_LIGHT eLight2;

eLight1.pos = Vec3f(50.f, 50.f, 200.f);
eLight1.exist = 1;
eLight1.m_exists = true;
eLight1.rgb = Color3f(0.15f, 0.06f, 0.003f);
eLight1.intensity = 8.8f;
eLight1.fallstart = 2020;
eLight1.fallend = eLight1.fallstart + 60;
RecalcLight(&eLight1);

eLight2.exist = 1;
eLight2.m_exists = true;
eLight2.pos = Vec3f(-50.f, -50.f, -200.f);
eLight2.rgb = Color3f::gray(0.6f);
eLight2.intensity = 3.8f;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/book/Necklace.cpp
Expand Up @@ -124,7 +124,7 @@ void ARX_INTERFACE_ManageOpenedBook_Finish(const Vec2f & mousePos, Rectf rect, f
EERIE_LIGHT tl = *light;

light->pos = Vec3f(500.f, -1960.f, 1590.f);
light->exist = 1;
light->m_exists = true;
light->rgb = Color3f(0.6f, 0.7f, 0.9f);
light->intensity = 1.8f;
light->fallstart = 4520.f;
Expand Down
40 changes: 18 additions & 22 deletions src/scene/Light.cpp
Expand Up @@ -130,9 +130,8 @@ void EERIE_LIGHT_GlobalInit() {

for(size_t i = 0; i < g_staticLightsMax; i++) {
if(g_staticLights[i]) {
EERIE_LIGHT * dynLight = lightHandleGet(g_staticLights[i]->m_ignitionLightHandle);
if(dynLight) {
dynLight->exist = 0;
if(EERIE_LIGHT * dynLight = lightHandleGet(g_staticLights[i]->m_ignitionLightHandle)) {
dynLight->m_exists = false;
}
delete g_staticLights[i];
g_staticLights[i] = NULL;
Expand Down Expand Up @@ -193,7 +192,7 @@ void TreatBackgroundDynlights() {
// just extinguished
EERIE_LIGHT * dynLight = lightHandleGet(light->m_ignitionLightHandle);
if(dynLight) {
dynLight->exist = 0;
dynLight->m_exists = false;
light->m_ignitionLightHandle = LightHandle();
for(size_t l = 0; l < entities.size(); l++) {
const EntityHandle handle = EntityHandle(l);
Expand Down Expand Up @@ -247,7 +246,7 @@ void TreatBackgroundDynlights() {
for(size_t i = 0; i < g_dynamicLightsMax; i++) {
EERIE_LIGHT * el = &g_dynamicLights[i];

if(el->exist && el->duration != 0) {
if(el->m_exists && el->duration != 0) {
const GameDuration elapsed = g_gameTime.now() - el->creationTime;
const GameDuration duration = el->duration;

Expand All @@ -268,7 +267,7 @@ void TreatBackgroundDynlights() {
el->rgb.b = 0.f;

if(el->rgb.r + el->rgb.g + el->rgb.b == 0) {
el->exist = 0;
el->m_exists = false;
el->duration = 0;
}
}
Expand All @@ -283,7 +282,7 @@ void PrecalcDynamicLighting(const Vec3f & camPos, float camDepth) {
g_culledDynamicLightsCount = 0;

BOOST_FOREACH(EERIE_LIGHT & light, g_dynamicLights) {
if(light.exist && light.rgb != Color3f::black) {
if(light.m_exists && light.rgb != Color3f::black) {
light.m_isVisible = closerThan(light.pos, camPos, camDepth + light.fallend);
if(light.m_isVisible) {
RecalcLight(&light);
Expand All @@ -303,7 +302,7 @@ void PrecalcIOLighting(const Vec3f & pos, float radius) {
EERIE_LIGHT * el = g_staticLights[i];

if( el
&& el->exist
&& el->m_exists
&& el->m_ignitionStatus
&& !(el->extras & EXTRAS_SEMIDYNAMIC)
&& (el->pos.x >= pos.x - radius)
Expand All @@ -324,7 +323,7 @@ void PrecalcIOLighting(const Vec3f & pos, float radius) {

static bool lightHandleIsValid(LightHandle num)
{
return (long)num.handleData() >= 0 && ((size_t)num.handleData() < g_dynamicLightsMax) && g_dynamicLights[num.handleData()].exist;
return (long)num.handleData() >= 0 && ((size_t)num.handleData() < g_dynamicLightsMax) && g_dynamicLights[num.handleData()].m_exists;
}

EERIE_LIGHT * lightHandleGet(LightHandle lightHandle) {
Expand All @@ -337,26 +336,25 @@ EERIE_LIGHT * lightHandleGet(LightHandle lightHandle) {

void lightHandleDestroy(LightHandle & handle) {

EERIE_LIGHT * light = lightHandleGet(handle);
if(light) {
light->exist = 0;
if(EERIE_LIGHT * light = lightHandleGet(handle)) {
light->m_exists = false;
}

handle = LightHandle();
}

void endLightDelayed(LightHandle & handle, GameDuration delay) {

EERIE_LIGHT * light = lightHandleGet(handle);
if(light) {
if(EERIE_LIGHT * light = lightHandleGet(handle)) {
light->duration = delay;
light->creationTime = g_gameTime.now();
}

}

void resetDynLights() {
for(size_t i = 0; i < g_dynamicLightsMax; i++) {
g_dynamicLights[i].exist = 0;
g_dynamicLights[i].m_exists = false;
}
}

Expand All @@ -365,8 +363,8 @@ LightHandle GetFreeDynLight() {

for(size_t i = 1; i < g_dynamicLightsMax; i++) {
EERIE_LIGHT & light = g_dynamicLights[i];
if(!(light.exist)) {
light.exist = 1;
if(!light.m_exists) {
light.m_exists = true;
light.m_isIgnitionLight = false;
light.intensity = 1.3f;
light.m_isVisible = true;
Expand Down Expand Up @@ -396,13 +394,11 @@ EERIE_LIGHT * dynLightCreate() {


void ClearDynLights() {

for(size_t i = 0; i < g_dynamicLightsMax; i++) {
if(g_dynamicLights[i].exist) {
g_dynamicLights[i].exist = 0;
}
g_dynamicLights[i].m_exists = false;
}

for(size_t i = 0; i < g_staticLightsMax; i++) {
if(g_staticLights[i]) {
g_staticLights[i]->m_ignitionLightHandle = LightHandle();
Expand Down
4 changes: 2 additions & 2 deletions src/scene/Light.h
Expand Up @@ -96,7 +96,7 @@ DECLARE_FLAGS_OPERATORS(ExtrasType)

struct EERIE_LIGHT {

char exist;
bool m_exists;
bool m_isIgnitionLight; // TODO refactor special case
bool m_isVisible;
ExtrasType extras;
Expand Down Expand Up @@ -128,7 +128,7 @@ struct EERIE_LIGHT {
math::Quantizer m_storedFlameTime;

EERIE_LIGHT()
: exist(0)
: m_exists(false)
, m_isIgnitionLight(false)
, m_isVisible(false)
, extras(0)
Expand Down
4 changes: 2 additions & 2 deletions src/scene/LoadLevel.cpp
Expand Up @@ -300,7 +300,7 @@ bool DanaeLoadLevel(const res::path & file, bool loadEntities) {
if(j >= 0) {
EERIE_LIGHT * el = g_staticLights[j];

el->exist = 1;
el->m_exists = true;
el->m_isVisible = true;
el->fallend = dlight->fallend;
el->fallstart = dlight->fallstart;
Expand Down Expand Up @@ -469,7 +469,7 @@ bool DanaeLoadLevel(const res::path & file, bool loadEntities) {
if(j >= 0) {
EERIE_LIGHT * el = g_staticLights[j];

el->exist = 1;
el->m_exists = true;
el->m_isVisible = true;
el->fallend = dlight->fallend;
el->fallstart = dlight->fallstart;
Expand Down

0 comments on commit 262889e

Please sign in to comment.