CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.53k stars 4.16k forks source link

Tents dont provide darkness #44421

Closed Scintile closed 4 years ago

Scintile commented 4 years ago

Describe the bug

If you put up a tent (i used regular one), light from the outside will shine inside Same thing happens with vehicles

Steps To Reproduce

  1. Use a tent to place it (i used regular tent and placed it to the south of me, but large tent has the same problem)
  2. Get inside and close the door
  3. If it is bright outside it will be bright inside (so you cant sleep)

Alternative -

  1. Find/build a vehicle
  2. Ensure that all doors are opaque, roof is present on all tiles (i made sure that even walls have roof) and that all ground tiles have aisles
  3. If it is bright outside it will be bright inside

Expected behavior

It should be dark in the tent or vehicle when you close its door

Versions and configuration

Scintile commented 4 years ago

Confirmed that this problem happens even with experimental z level vision turned off. Also noticed that if you have a truck (for example) with opaque doors, walls all around and roof (including tiles that has walls) it will still be bright inside

Zireael07 commented 4 years ago

The truck thing was already reported I believe, but I can't find it now.

Both are probably related to PR #42830

Scintile commented 4 years ago

Well, i added vehicle part to my post anyway

miguel-swanson commented 4 years ago

43303 is the vehicle lighting issue, which is what I thought of when I saw this issue.

natsirt721 commented 4 years ago

In my experience, most tents IRL are fairly translucent and will still allow an appreciable amount of light in. I have comfortably read a book and played cards in a larger tent during the daytime without a light. Not saying that there isn't a bug to be addressed here, but something to consider.

Scintile commented 4 years ago

Im 100% sure you used to be able to sleep inside without any blindfolds

natsirt721 commented 4 years ago

Oh, I meant IRL, not in game. Editing original to indicate that.

Scintile commented 4 years ago

Ah, yeah, irl they are pretty thin. If you set one up in a forest you will have a hard time reading, but if sun is shining on the tent directly - its bright enough inside Another problem i just encounered - i was chilling in the tent on the roof, waiting for darkness so i could sneak away from some flaming eyes, and one eye decided to fly above my tent. It was visible to me, and it was able to do his bullshit to me. Even though tent roof should have stopped him

Aivean commented 4 years ago

If nobody picks this up within the next couple of days, I'll fix it. I'm familiar with sunlight cache code.

Aivean commented 4 years ago

Ok, while thinking of the best way to fix this, I've discovered a fundamental problem.

Current semantics of the "INDOORS" flag (if implemented according to spec) essentially prohibits skylights (see #42008). Without adding additional flags and/or other hacks to support skylights specifically, we can either have the shade inside the tents/vehicles or working skylights.

So, I have two options:

  1. An easy option to fix tents and vehicles (by checking outside_cache in build_sunlight_cache) and break skylights (hopefully without breaking #31851).

  2. Second approach is much more involved and consists of two parts:

    • Currently almost every floor in the game is marked as "INDOORS". I think it is a legacy from the non-zlevel times, when we did not have proper roofs. I would need to revisit every usage of "INDOORS" flag, remove it from the most of the floors and change how the outside_cache is built (make it rely on the presence of the real roof above, not just on the "INDOORS" flag). This way we can still use the "INDOORS" flag for the single-tile-high structures that need to block sunlight.
    • To support skylights I'd need to introduce yet another cache, something like "floor_transparency_cache" that would be used by sunlight. Such cache would be slightly different from the "floor_cache" and "outside_cache" and would be set by roofs, floors, walls, as well as by the "INDOORS" flag. Separate cache is necessary, because in the case of skylight, tiles directly below it are "inside", but still lit up by sun.

@kevingranade and @jbytheway , I believe you might have some valuable input on this.

jbytheway commented 4 years ago

Something along the lines of your second solution is probably ultimately what we need. Currently INDOORS is overloaded with multiple meanings. It's used e.g. for determining where rain falls as well as lighting effects. IMO it should be entirely divorced from all lighting effects.

Still, I don't think this implies that we need a new cache. There are two notable chunks of code which are relevant to sunlight:

Back when sunlight casting was originally introduced (#30250) Kevin planned to have the sunlight come in at an angle, rather than directly downwards. I'm actually working on implementing that right now, which would be a fairly major change to the first point here. Along the way I was rather expecting to basically revert #42830 and fix the "dark walls" issue by something more along the lines of my suggestion in the second point here.

These changes I'm working on are a major feature that shouldn't land before 0.F release, so we probably need a need a different fix for 0.F. And we should probably look for the least disruptive fix, since we are in feature freeze. My instinct is that the simplest fix would be to revert #42830 (hopefully fixing the vehicles and tents issues) and fix the dark-walls-bug in a different by tweaking map::generate_lightmap to cast light sideways into walls in the same way it is currently cast into windows.

But any of these changes need unit tests, so we should get #42835 merged before any attempt to fix this.

jbytheway commented 4 years ago

A good place to start would be to revert #42830 locally and test my hypothesis that it fixes the vehicle and/or tent issues. It would be very helpful if you could try that.

Aivean commented 4 years ago

@jbytheway , thanks for your comment.

I think the quick and dirty fix for tents and trucks doesn't require reverting #42830. It's basically adding here following condition:

if (!outside_cache[x][y] && !outside_cache[prev_x][prev_y]) {
    continue;
}

This is what I suggested as the approach №1.

I just tested it and it works: fixes trucks and tents, doesn't break #31851, but breaks skylights (revert of the #42830 will break them too).

Do you think such fix would suffice for now?

Aivean commented 4 years ago

A good place to start would be to revert #42830 locally and test my hypothesis that it fixes the vehicle and/or tent issues. It would be very helpful if you could try that.

Yes, you are correct, reverting #42830 will fix trucks and tents as well, this bug was introduced here, specifically by removing && outside_cache[x][y] part from the if clause.

jbytheway commented 4 years ago

I think we can find something that doesn't break skylights. It would suffice to check "is this tile inside a vehicle or tent" here instead. It's just a question of whether that would be too slow. Maybe vehicles and tents should be taken into account when building the floor cache, and set the tiles above them to be floored?

Aivean commented 4 years ago

Well, yes, that can work well enough for vehicles, but that would be a HUGE hack for tents.

Currently tents are single-tile-high and their floors have the infamous "INDOORS" flag, that is supposed to mean that there is a fake "roof" above them. We can distinguish tent floor from other "INDOORS" floors by adding another flag that would share semantics with "INDOORS", but you understand why I'm reluctant to suggest that.

Alternatively we can just make tents 3d, i.e. add real roof above them. However this also seems a bit involved.

jbytheway commented 4 years ago

My instinct is in fact that a new flag for "has an opaque ceiling that isn't represented by a floor in the tile above" is the easiest short-term solution. I don't have a good sense for how messy it would be to make tents have real roofs. Not sure we'd want that anyway, since they're not walkable-on.

But probably we should let @kevingranade weigh in.

Fosheze commented 4 years ago

Well, yes, that can work well enough for vehicles, but that would be a HUGE hack for tents.

Bear with me here as I'm aware that this idea sounds phenomenally dumb, buuuut... Why not just make tents foldable vehicles? Use wire for the frames for minimum durability with "plastic sheet" walls, roof and door. It would work essentially the same from the players perspective and this would also limit the scope of the problem solely to vehicles for now until 0.F. As far as I'm aware they are the only item that deploys like this where light casting is a concern. Tents always seemed a little hacky to me anyways with how any damage would immediately turn it into the useless broken tent item. Changing them to vehicles would allow survivors to repair their tent or even craft their own.

Scintile commented 4 years ago

One thing i dont like about vehicles is how you cant really put items on the ground. You instead put items inside the tile. And I dont know how things like rollmats will work with tent-vehicles. (and you already can repair tents and create your own)

Fosheze commented 4 years ago

One thing i dont like about vehicles is how you cant really put items on the ground. You instead put items inside the tile. And I dont know how things like rollmats will work with tent-vehicles. (and you already can repair tents and create your own)

A simple solution to that problem would be to create a "plastic sheet" tent floor part (filling the same role as an aisle) with a high storage volume but basically no durability (to prevent it from being used as vehicle storage). I was also unaware that broken tents could be fixed but what I was more referring too when I said create their own was the creation of custom sized tents with other foldable amenities (battery powered lights, funnel and tank, etc.).

Zireael07 commented 4 years ago

Vehicles are a nasty thing to maintain, and any "quasi-vehicle" ideas tend to get shot down for that reason.

kevingranade commented 4 years ago

It very much sounds like the best option is to have the tent code place a roof over the tent, that's how we handle this kind of thing now. That can either be an explicit roof entry or an entry that just gets inferred by build_transparency_cache(). Likewise vehicles should get roof entries when the transparency cache is rebuilt.

Aivean commented 4 years ago

Ok, sounds like a plan.

The only issue though, currently transparency_cache implies "horizontal transparency" in addition to "vertical transparency". If roofs above tents and vehicles are to set the transparency cache, they would block vision and horizontal light in the corresponding z-level.

I'll try to evaluate floor_cache for that purpose instead.

Scintile commented 4 years ago

I have no experience with coding and stuff like that, but wouldnt creating a roof over a tent cause problems if you try to set up a tent in a building? You know, with a normal roof above you

Fosheze commented 4 years ago

I have no experience with coding and stuff like that, but wouldnt creating a roof over a tent cause problems if you try to set up a tent in a building? You know, with a normal roof above you

Just going to tack onto this that there is a setup tent spawned by default in Mil. Surplus stores so this is going to be a fairly common thing.

Scintile commented 4 years ago

I also found tents in random basements

jbytheway commented 4 years ago

That might be an issue if we used explicit roofs, but it shouldn't be a problem with inferred roofs. So I guess that suggests using the latter approach.