Now have a basic prototype lighting system.
This commit is contained in:
parent
1bb04b4562
commit
a9217e8423
4 changed files with 65 additions and 48 deletions
|
@ -10,7 +10,7 @@
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
|
|
||||||
|
|
||||||
#line 115 "ansi_parser.rl"
|
#line 121 "ansi_parser.rl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ static const int ansi_parser_error = 0;
|
||||||
static const int ansi_parser_en_main = 26;
|
static const int ansi_parser_en_main = 26;
|
||||||
|
|
||||||
|
|
||||||
#line 118 "ansi_parser.rl"
|
#line 124 "ansi_parser.rl"
|
||||||
|
|
||||||
#include <ftxui/screen/terminal.hpp>
|
#include <ftxui/screen/terminal.hpp>
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
|
||||||
const wchar_t *eof = pe;
|
const wchar_t *eof = pe;
|
||||||
sf::Color bgcolor($default_bg);
|
sf::Color bgcolor($default_bg);
|
||||||
sf::Color color($default_fg);
|
sf::Color color($default_fg);
|
||||||
sf::Color &target = color;
|
sf::Color* target = &color;
|
||||||
|
|
||||||
|
|
||||||
#line 122 "ansi_parser.cpp"
|
#line 122 "ansi_parser.cpp"
|
||||||
|
@ -132,7 +132,7 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
|
||||||
cs = ansi_parser_start;
|
cs = ansi_parser_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 143 "ansi_parser.rl"
|
#line 149 "ansi_parser.rl"
|
||||||
|
|
||||||
#line 125 "ansi_parser.cpp"
|
#line 125 "ansi_parser.cpp"
|
||||||
{
|
{
|
||||||
|
@ -246,13 +246,13 @@ _match:
|
||||||
case 3:
|
case 3:
|
||||||
#line 43 "ansi_parser.rl"
|
#line 43 "ansi_parser.rl"
|
||||||
{
|
{
|
||||||
target = color;
|
target = &color;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
#line 46 "ansi_parser.rl"
|
#line 46 "ansi_parser.rl"
|
||||||
{
|
{
|
||||||
target = bgcolor;
|
target = &bgcolor;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
@ -263,14 +263,20 @@ _match:
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
#line 54 "ansi_parser.rl"
|
#line 54 "ansi_parser.rl"
|
||||||
{ color = $default_fg; }
|
{
|
||||||
|
color = $default_fg;
|
||||||
|
color_cb(color, bgcolor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
#line 55 "ansi_parser.rl"
|
#line 58 "ansi_parser.rl"
|
||||||
{ bgcolor = $default_bg; }
|
{
|
||||||
|
bgcolor = $default_bg;
|
||||||
|
color_cb(color, bgcolor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
#line 56 "ansi_parser.rl"
|
#line 62 "ansi_parser.rl"
|
||||||
{
|
{
|
||||||
color = $default_bg;
|
color = $default_bg;
|
||||||
bgcolor = $default_fg;
|
bgcolor = $default_fg;
|
||||||
|
@ -278,7 +284,7 @@ _match:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
#line 61 "ansi_parser.rl"
|
#line 67 "ansi_parser.rl"
|
||||||
{
|
{
|
||||||
color = $default_fg;
|
color = $default_fg;
|
||||||
bgcolor = $default_bg;
|
bgcolor = $default_bg;
|
||||||
|
@ -286,40 +292,40 @@ _match:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
#line 66 "ansi_parser.rl"
|
#line 72 "ansi_parser.rl"
|
||||||
{
|
{
|
||||||
color = sf::Color(100,100,100);
|
color = sf::Color(100,100,100);
|
||||||
color_cb(color, bgcolor);
|
color_cb(color, bgcolor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
#line 70 "ansi_parser.rl"
|
#line 76 "ansi_parser.rl"
|
||||||
{
|
{
|
||||||
color = sf::Color::Red;
|
color = sf::Color::Red;
|
||||||
color_cb(color, bgcolor);
|
color_cb(color, bgcolor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
#line 75 "ansi_parser.rl"
|
#line 81 "ansi_parser.rl"
|
||||||
{ target.r = value; }
|
{ target->r = value; }
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
#line 76 "ansi_parser.rl"
|
#line 82 "ansi_parser.rl"
|
||||||
{ target.g = value; }
|
{ target->g = value; }
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
#line 77 "ansi_parser.rl"
|
#line 83 "ansi_parser.rl"
|
||||||
{ target.b = value; }
|
{ target->b = value; }
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
#line 78 "ansi_parser.rl"
|
#line 84 "ansi_parser.rl"
|
||||||
{ value = 0; }
|
{ value = 0; }
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
#line 79 "ansi_parser.rl"
|
#line 85 "ansi_parser.rl"
|
||||||
{}
|
{}
|
||||||
break;
|
break;
|
||||||
#line 292 "ansi_parser.cpp"
|
#line 298 "ansi_parser.cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,10 +342,10 @@ _again:
|
||||||
while ( __nacts-- > 0 ) {
|
while ( __nacts-- > 0 ) {
|
||||||
switch ( *__acts++ ) {
|
switch ( *__acts++ ) {
|
||||||
case 16:
|
case 16:
|
||||||
#line 79 "ansi_parser.rl"
|
#line 85 "ansi_parser.rl"
|
||||||
{}
|
{}
|
||||||
break;
|
break;
|
||||||
#line 310 "ansi_parser.cpp"
|
#line 316 "ansi_parser.cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,12 +353,11 @@ _again:
|
||||||
_out: {}
|
_out: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 144 "ansi_parser.rl"
|
#line 150 "ansi_parser.rl"
|
||||||
|
|
||||||
bool good = pe - p == 0;
|
bool good = pe - p == 0;
|
||||||
|
|
||||||
if(!good) {
|
if(!good) {
|
||||||
println("FAIL AT {}", pe - p);
|
|
||||||
p -= 10;
|
p -= 10;
|
||||||
// dear cthuhlu, save me from the pain that is wstring
|
// dear cthuhlu, save me from the pain that is wstring
|
||||||
for(int i = 0; i < 100; i++) {
|
for(int i = 0; i < 100; i++) {
|
||||||
|
|
|
@ -41,18 +41,24 @@ using namespace fmt;
|
||||||
color_cb(color, bgcolor);
|
color_cb(color, bgcolor);
|
||||||
}
|
}
|
||||||
action is_fg {
|
action is_fg {
|
||||||
target = color;
|
target = &color;
|
||||||
}
|
}
|
||||||
action is_bg {
|
action is_bg {
|
||||||
target = bgcolor;
|
target = &bgcolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
action out {
|
action out {
|
||||||
write_cb(fc);
|
write_cb(fc);
|
||||||
}
|
}
|
||||||
|
|
||||||
action reset_fg { color = $default_fg; }
|
action reset_fg {
|
||||||
action reset_bg { bgcolor = $default_bg; }
|
color = $default_fg;
|
||||||
|
color_cb(color, bgcolor);
|
||||||
|
}
|
||||||
|
action reset_bg {
|
||||||
|
bgcolor = $default_bg;
|
||||||
|
color_cb(color, bgcolor);
|
||||||
|
}
|
||||||
action invert {
|
action invert {
|
||||||
color = $default_bg;
|
color = $default_bg;
|
||||||
bgcolor = $default_fg;
|
bgcolor = $default_fg;
|
||||||
|
@ -72,9 +78,9 @@ using namespace fmt;
|
||||||
color_cb(color, bgcolor);
|
color_cb(color, bgcolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
action red { target.r = value; }
|
action red { target->r = value; }
|
||||||
action blue { target.g = value; }
|
action blue { target->g = value; }
|
||||||
action green { target.b = value; }
|
action green { target->b = value; }
|
||||||
action start { value = 0; }
|
action start { value = 0; }
|
||||||
action end {}
|
action end {}
|
||||||
action log { println("command {}", (char)fc); }
|
action log { println("command {}", (char)fc); }
|
||||||
|
@ -137,7 +143,7 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
|
||||||
const wchar_t *eof = pe;
|
const wchar_t *eof = pe;
|
||||||
sf::Color bgcolor($default_bg);
|
sf::Color bgcolor($default_bg);
|
||||||
sf::Color color($default_fg);
|
sf::Color color($default_fg);
|
||||||
sf::Color &target = color;
|
sf::Color* target = &color;
|
||||||
|
|
||||||
%% write init;
|
%% write init;
|
||||||
%% write exec;
|
%% write exec;
|
||||||
|
@ -145,7 +151,6 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
|
||||||
bool good = pe - p == 0;
|
bool good = pe - p == 0;
|
||||||
|
|
||||||
if(!good) {
|
if(!good) {
|
||||||
println("FAIL AT {}", pe - p);
|
|
||||||
p -= 10;
|
p -= 10;
|
||||||
// dear cthuhlu, save me from the pain that is wstring
|
// dear cthuhlu, save me from the pain that is wstring
|
||||||
for(int i = 0; i < 100; i++) {
|
for(int i = 0; i < 100; i++) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"map": {
|
"map": {
|
||||||
"WALL_TILE": "█",
|
"WALL_TILE": "\ua5b8",
|
||||||
"FLOOR_TILE": "\u2849",
|
"FLOOR_TILE": "\u2849",
|
||||||
"PLAYER_TILE": "♣",
|
"PLAYER_TILE": "\ua66b",
|
||||||
"ENEMY_TILE": "Ω",
|
"ENEMY_TILE": "Ω",
|
||||||
"BG_TILE": "█"
|
"BG_TILE": "█"
|
||||||
},
|
},
|
||||||
|
|
27
systems.cpp
27
systems.cpp
|
@ -159,26 +159,33 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv
|
||||||
// LIGHT: if tile is in light then color ++ otherwise --
|
// LIGHT: if tile is in light then color ++ otherwise --
|
||||||
// LIGHT: is put into the/a collision map and if a cell is a light's neighbor
|
// LIGHT: is put into the/a collision map and if a cell is a light's neighbor
|
||||||
// it gets brighter.
|
// it gets brighter.
|
||||||
const int LIGHT_MIN = 30;
|
const int LIGHT_MIN = 10;
|
||||||
const int LIGHT_MAX = 180;
|
const int LIGHT_MAX = 110;
|
||||||
|
int light_strength = 100; // lower is stronger
|
||||||
|
|
||||||
Point light_at{start.x+x, start.y+y};
|
Point light_at{start.x+x, start.y+y};
|
||||||
int dnum = paths[light_at.y][light_at.x];
|
int dnum = paths[light_at.y][light_at.x];
|
||||||
int light_value = std::clamp(255 - (dnum * 75), LIGHT_MIN, LIGHT_MAX);
|
int light_value = std::clamp(255 - (dnum * light_strength), LIGHT_MIN, LIGHT_MAX);
|
||||||
|
|
||||||
|
// "WALL_TILE": "\u2591",
|
||||||
|
// "WALL_TILE": "\ua5b8",
|
||||||
if(tile == config.WALL_TILE) {
|
if(tile == config.WALL_TILE) {
|
||||||
canvas.DrawText(x * 2, y * 4, tile, Color::HSV(230, 20, 20));
|
canvas.DrawText(x * 2, y * 4, config.WALL_TILE, [](auto &pixel) {
|
||||||
|
pixel.foreground_color = Color::HSV(230, 20, 10);
|
||||||
|
pixel.background_color = Color::HSV(230, 20, 30);
|
||||||
|
});
|
||||||
} else if(DEBUG_MAP) {
|
} else if(DEBUG_MAP) {
|
||||||
string num = format("{:x}", dnum);
|
string num = format("{:x}", dnum);
|
||||||
num = num.size() > 2 ? "*" : num;
|
num = num.size() > 2 ? "*" : num;
|
||||||
|
|
||||||
canvas.DrawText(x * 2, y * 4, num, Color::HSV(dnum * 20, 150, light_value));
|
canvas.DrawText(x * 2, y * 4, num, [dnum, light_value](auto &pixel) {
|
||||||
|
pixel.foreground_color = Color::HSV(dnum * 20, 150, 200);
|
||||||
|
pixel.background_color = Color::HSV(30, 20, light_value / 5);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// floor tile or similar
|
canvas.DrawText(x * 2, y * 4, tile, [light_value](auto &pixel) {
|
||||||
// BUG: no idea why this works but this actually implements decent light
|
pixel.foreground_color = Color::HSV(30, 40, light_value);
|
||||||
canvas.DrawText(x * 2, y * 4, tile, [&, light_value](auto &pixel) {
|
pixel.background_color = Color::HSV(30, 20, light_value / 5);
|
||||||
pixel.foreground_color = Color::HSV(30, light_value / 2, light_value);
|
|
||||||
pixel.background_color = Color::HSV(30, 20, light_value);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue