forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightmap.h
83 lines (71 loc) · 2.83 KB
/
lightmap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#ifndef CATA_SRC_LIGHTMAP_H
#define CATA_SRC_LIGHTMAP_H
#include <cmath>
#include <ostream>
static constexpr float LIGHT_SOURCE_LOCAL = 0.1f;
static constexpr float LIGHT_SOURCE_BRIGHT = 10.0f;
// Just enough light that you can see the current and adjacent squares with normal vision.
static constexpr float LIGHT_AMBIENT_MINIMAL = 3.7f;
// The threshold between not being able to see anything and things appearing shadowy.
static constexpr float LIGHT_AMBIENT_LOW = 3.5f;
// The lower threshold for seeing well enough to do detail work such as reading or crafting.
static constexpr float LIGHT_AMBIENT_DIM = 5.0f;
// The threshold between things being shadowed and being brightly lit.
static constexpr float LIGHT_AMBIENT_LIT = 10.0f;
/**
* Transparency 101:
* Transparency usually ranges between 0.038 (open air) and 0.38 (regular smoke).
* The bigger the value, the more opaque it is (less light goes through).
* To make sense of the specific value:
* For transparency t, vision becomes "obstructed" (see map::apparent_light_helper) after
* ≈ (2.3 / t) consequent tiles of transparency `t` ( derived from 1 / e^(dist * t) = 0.1 )
* e.g. for smoke with effective transparency 0.38 it's 2.3/0.38 ≈ 6 tiles
* for clean air with t=0.038 dist = 2.3/0.038 ≈ 60 tiles
*
* Note: LIGHT_TRANSPARENCY_SOLID=0 is a special case (it indicates completely opaque tile)
* */
static constexpr float LIGHT_TRANSPARENCY_SOLID = 0.0f;
// Calculated to run out at 60 squares.
// Cumulative transparency should drop to 0.1 or lower over 60 squares,
// Bright sunlight should drop to LIGHT_AMBIENT_LOW over 60 squares.
static constexpr float LIGHT_TRANSPARENCY_OPEN_AIR = 0.038376418216f;
// indicates starting (full) visibility (for seen_cache)
static constexpr float VISIBILITY_FULL = 1.0f;
constexpr inline int LIGHT_RANGE( float b )
{
if( b <= LIGHT_AMBIENT_LOW ) {
return 0;
}
return static_cast<int>( -std::log( LIGHT_AMBIENT_LOW / b ) * ( 1.0 /
LIGHT_TRANSPARENCY_OPEN_AIR ) );
}
enum class lit_level : int {
DARK = 0,
LOW, // Hard to see
BRIGHT_ONLY, // bright but indistinct
LIT,
BRIGHT, // Probably only for light sources
MEMORIZED, // Not a light level but behaves similarly
BLANK // blank space, not an actual light level
};
template<typename T>
constexpr inline bool operator>( const T &lhs, const lit_level &rhs )
{
return lhs > static_cast<T>( rhs );
}
template<typename T>
constexpr inline bool operator<=( const T &lhs, const lit_level &rhs )
{
return !operator>( lhs, rhs );
}
template<typename T>
constexpr inline bool operator!=( const lit_level &lhs, const T &rhs )
{
return static_cast<T>( lhs ) != rhs;
}
inline std::ostream &operator<<( std::ostream &os, const lit_level &ll )
{
return os << static_cast<int>( ll );
}
#endif // CATA_SRC_LIGHTMAP_H