6d7060ceb5
Cada entity declara su color de linea via parametro opcional. Cuando
alpha==0 el pipeline cae al color global del oscilador (compatibilidad
con el comportamiento anterior).
Defaults::Palette (defaults.hpp):
- SHIP = blanco neutro
- BULLET = verde laser
- PENTAGON = azul "esquivador"
- QUADRAT = rojo "tank"
- MOLINILLO = magenta agresivo
Pipeline:
- linea(): parametro SDL_Color color (default {0,0,0,0}). En .cpp,
fuente del color = color.a>0 ? color : g_current_line_color.
- render_shape(): parametro SDL_Color color que propaga a cada linea
del shape.
- Debris: campo color en la struct; explode() recibe SDL_Color color
y lo guarda en cada fragment; draw() lo pasa a linea().
Aplicacion:
- Ship::draw -> Palette::SHIP.
- Bullet::draw -> Palette::BULLET.
- Enemy::draw -> Palette::{PENTAGON,QUADRAT,MOLINILLO} segun type_.
- CollisionSystem detectBulletEnemy: debris hereda color del enemy.
- GameScene::tocado: debris hereda Palette::SHIP.
Smoke test xvfb OK.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.9 KiB
C++
54 lines
1.9 KiB
C++
// line_renderer.cpp - Implementación de renderizado de líneas (SDL3 GPU)
|
||
// © 1999 Visente i Sergi (versión Pascal)
|
||
// © 2025 Port a C++20 con SDL3
|
||
|
||
#include "core/rendering/line_renderer.hpp"
|
||
|
||
namespace Rendering {
|
||
|
||
// Color global compartido (actualizado por ColorOscillator via SDLManager).
|
||
SDL_Color g_current_line_color = {255, 255, 255, 255};
|
||
|
||
// Grosor global por defecto. Configurable via setLineThickness.
|
||
// 1.5 da una línea visible y crujiente; 1.0 se ve demasiado fino en pantallas grandes.
|
||
float g_current_line_thickness = 1.5F;
|
||
|
||
void linea(Renderer* renderer,
|
||
int x1, int y1, int x2, int y2,
|
||
float brightness,
|
||
float thickness,
|
||
SDL_Color color) {
|
||
if (renderer == nullptr) {
|
||
return;
|
||
}
|
||
|
||
// Coords lógicas (1280×720). El shader hace el mapeo a NDC; el viewport
|
||
// del SDLManager hace el letterbox a píxeles físicos.
|
||
const float FX1 = static_cast<float>(x1);
|
||
const float FY1 = static_cast<float>(y1);
|
||
const float FX2 = static_cast<float>(x2);
|
||
const float FY2 = static_cast<float>(y2);
|
||
|
||
// color.alpha==0 → usar global del oscilador. alpha>0 → color directo.
|
||
const SDL_Color SOURCE = (color.a > 0) ? color : g_current_line_color;
|
||
const float R = (static_cast<float>(SOURCE.r) * brightness) / 255.0F;
|
||
const float G = (static_cast<float>(SOURCE.g) * brightness) / 255.0F;
|
||
const float B = (static_cast<float>(SOURCE.b) * brightness) / 255.0F;
|
||
|
||
const float W = (thickness > 0.0F) ? thickness : g_current_line_thickness;
|
||
|
||
renderer->pushLine(FX1, FY1, FX2, FY2, W, R, G, B, 1.0F);
|
||
}
|
||
|
||
void setLineColor(SDL_Color color) { g_current_line_color = color; }
|
||
|
||
void setLineThickness(float thickness) {
|
||
if (thickness > 0.0F) {
|
||
g_current_line_thickness = thickness;
|
||
}
|
||
}
|
||
|
||
auto getLineThickness() -> float { return g_current_line_thickness; }
|
||
|
||
} // namespace Rendering
|