fix(lighting): llig flicker tambe del YAML del jugador
This commit is contained in:
1 parent
fc9947b87f
commit
0046d526b0
3 files changed
+24
-10
No files matched your search
@@ -142,13 +142,18 @@ void Player::loadFrom(const std::string& yaml_path) {
|
|||||||
// desactivada i els hazards toquen al primer frame, com abans.
|
// desactivada i els hazards toquen al primer frame, com abans.
|
||||||
readImmunityBlock(yaml);
|
readImmunityBlock(yaml);
|
||||||
|
|
||||||
// Bloc opcional `light: { radius: N }` — radi en píxels del cercle
|
// Bloc opcional `light:` — radi i flicker. Extret a un mètode per
|
||||||
// de llum emès pel jugador. 0 = no emet. La forma del gradient és
|
// mantenir `loadFrom` sota el llindar de complexitat de clang-tidy.
|
||||||
// global (data/config/lighting.yaml), no per jugador.
|
readLightBlock(yaml);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::readLightBlock(const fkyaml::node& yaml) {
|
||||||
light_radius = 0;
|
light_radius = 0;
|
||||||
if (yaml.contains("light") && yaml["light"].contains("radius")) {
|
light_flicker = false;
|
||||||
light_radius = yaml["light"]["radius"].get_value<int>();
|
if (!yaml.contains("light")) { return; }
|
||||||
}
|
const auto& l = yaml["light"];
|
||||||
|
if (l.contains("radius")) { light_radius = l["radius"].get_value<int>(); }
|
||||||
|
if (l.contains("flicker")) { light_flicker = l["flicker"].get_value<bool>(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::readCollisionBlock(const fkyaml::node& yaml, const std::string& yaml_path) {
|
void Player::readCollisionBlock(const fkyaml::node& yaml, const std::string& yaml_path) {
|
||||||
|
|||||||
@@ -125,10 +125,12 @@ class Player : public AnimatedSprite {
|
|||||||
inline static int body_height = 0;
|
inline static int body_height = 0;
|
||||||
|
|
||||||
// Radi de la llum emesa pel jugador (en píxels del canvas), llegit
|
// Radi de la llum emesa pel jugador (en píxels del canvas), llegit
|
||||||
// del bloc opcional `light: { radius: N }` del YAML. 0 = no emet.
|
// del bloc opcional `light: { radius: N, flicker: bool }` del YAML.
|
||||||
// Es declara estàtic com la resta de configs del jugador (immunity,
|
// 0 = no emet. Es declara estàtic com la resta de configs del jugador
|
||||||
// jump, ...): tots els jugadors del mateix YAML comparteixen el valor.
|
// (immunity, jump, ...): tots els jugadors del mateix YAML comparteixen
|
||||||
|
// el valor. `light_flicker` activa la modulació "tipus foc" del radi.
|
||||||
inline static int light_radius = 0;
|
inline static int light_radius = 0;
|
||||||
|
inline static bool light_flicker = false;
|
||||||
|
|
||||||
// Ha de cridar-se abans d'instanciar Player; GameScene ho fa al ctor.
|
// Ha de cridar-se abans d'instanciar Player; GameScene ho fa al ctor.
|
||||||
static void loadFrom(const std::string& yaml_path);
|
static void loadFrom(const std::string& yaml_path);
|
||||||
@@ -143,6 +145,7 @@ class Player : public AnimatedSprite {
|
|||||||
// sprite es dibuixa amb `pos_.y - jump_z_`, i la llum ha de seguir-lo
|
// sprite es dibuixa amb `pos_.y - jump_z_`, i la llum ha de seguir-lo
|
||||||
// per a que el cercle "salti" amb el jugador, no es quedi al sòl.
|
// per a que el cercle "salti" amb el jugador, no es quedi al sòl.
|
||||||
[[nodiscard]] static auto getLightRadius() -> int { return light_radius; }
|
[[nodiscard]] static auto getLightRadius() -> int { return light_radius; }
|
||||||
|
[[nodiscard]] static auto getLightFlicker() -> bool { return light_flicker; }
|
||||||
[[nodiscard]] auto getLightCenter() const -> SDL_FPoint;
|
[[nodiscard]] auto getLightCenter() const -> SDL_FPoint;
|
||||||
|
|
||||||
Player(const std::string& anim_key, int id, float x, float y, const Controls& controls, const Map::Info& map_info, int paint_tile_index = -1);
|
Player(const std::string& anim_key, int id, float x, float y, const Controls& controls, const Map::Info& map_info, int paint_tile_index = -1);
|
||||||
@@ -755,6 +758,11 @@ class Player : public AnimatedSprite {
|
|||||||
// readers — `loadFrom` el crida al final.
|
// readers — `loadFrom` el crida al final.
|
||||||
static void readImmunityBlock(const fkyaml::node& yaml);
|
static void readImmunityBlock(const fkyaml::node& yaml);
|
||||||
|
|
||||||
|
// Llig el bloc opcional `light: { radius: N, flicker: bool }` del
|
||||||
|
// YAML i pobla `light_radius` / `light_flicker`. Si manca, els
|
||||||
|
// valors queden a 0 / false (jugador sense llum).
|
||||||
|
static void readLightBlock(const fkyaml::node& yaml);
|
||||||
|
|
||||||
// Activa l'estat ATTACKING en la direcció cardinal indicada (la
|
// Activa l'estat ATTACKING en la direcció cardinal indicada (la
|
||||||
// direcció cap on mira el jugador) i publica `whip_spawn` al bus
|
// direcció cap on mira el jugador) i publica `whip_spawn` al bus
|
||||||
// perquè el GameScene cree el `WhipAttack` corresponent. Posa el
|
// perquè el GameScene cree el `WhipAttack` corresponent. Posa el
|
||||||
|
|||||||
@@ -1018,10 +1018,11 @@ void GameScene::applyLightingPass() {
|
|||||||
// `Lighting::apply` salta el cercle al filtre intern. No fem un
|
// `Lighting::apply` salta el cercle al filtre intern. No fem un
|
||||||
// gating extern aquí (els jugadors són només 1-2 actors i el cost
|
// gating extern aquí (els jugadors són només 1-2 actors i el cost
|
||||||
// d'afegir-los al vector és menyspreable).
|
// d'afegir-los al vector és menyspreable).
|
||||||
|
const bool PLAYER_FLICKER = Player::getLightFlicker();
|
||||||
for (const auto& p : players_) {
|
for (const auto& p : players_) {
|
||||||
if (p->isOutOfPlay()) { continue; }
|
if (p->isOutOfPlay()) { continue; }
|
||||||
const auto C = p->getLightCenter();
|
const auto C = p->getLightCenter();
|
||||||
emitters.push_back({.cx = C.x, .cy = C.y, .radius = PLAYER_R, .flicker = false});
|
emitters.push_back({.cx = C.x, .cy = C.y, .radius = PLAYER_R, .flicker = PLAYER_FLICKER});
|
||||||
}
|
}
|
||||||
for (const auto* e : entity_manager_.getEntities()) {
|
for (const auto* e : entity_manager_.getEntities()) {
|
||||||
const int R = e->getLightRadius();
|
const int R = e->getLightRadius();
|
||||||
|
|||||||
Reference in new issue
Block a user