renombrades extensions .h a .hpp
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
// IWYU pragma: no_include <bits/std_abs.h>
|
||||
#include "path_sprite.h"
|
||||
#include "path_sprite.hpp"
|
||||
|
||||
#include <functional> // Para function
|
||||
#include <utility> // Para move
|
||||
|
||||
// Constructor para paths por puntos (convertido a segundos)
|
||||
Path::Path(const std::vector<SDL_FPoint> &spots_init, float waiting_time_s_init)
|
||||
: spots(spots_init), is_point_path(true) {
|
||||
Path::Path(const std::vector<SDL_FPoint>& spots_init, float waiting_time_s_init)
|
||||
: spots(spots_init),
|
||||
is_point_path(true) {
|
||||
waiting_time_s = waiting_time_s_init;
|
||||
}
|
||||
|
||||
// Devuelve un vector con los puntos que conforman la ruta
|
||||
auto createPath(float start, float end, PathType type, float fixed_pos, int steps, const std::function<double(double)> &easing_function) -> std::vector<SDL_FPoint> {
|
||||
auto createPath(float start, float end, PathType type, float fixed_pos, int steps, const std::function<double(double)>& easing_function) -> std::vector<SDL_FPoint> {
|
||||
std::vector<SDL_FPoint> v;
|
||||
v.reserve(steps);
|
||||
|
||||
@@ -74,50 +75,50 @@ void PathSprite::addPath(Path path, bool centered) {
|
||||
switch (path_centered) {
|
||||
case PathCentered::ON_X: {
|
||||
// Centrar en el eje X (para paths Verticales)
|
||||
const float X_offset = pos_.w / 2.0f; // Asume que pos_.w está inicializado por el constructor de Sprite
|
||||
const float X_offset = pos_.w / 2.0f; // Asume que pos_.w está inicializado por el constructor de Sprite
|
||||
if (path.is_point_path) {
|
||||
const float X_base = !path.spots.empty() ? path.spots.front().x : 0.0f;
|
||||
const float X = X_base - X_offset;
|
||||
for (auto &spot : path.spots) {
|
||||
for (auto& spot : path.spots) {
|
||||
spot.x = X;
|
||||
}
|
||||
} else {
|
||||
// Es un path generado, ajustamos la posición fija (que es X)
|
||||
path.fixed_pos -= X_offset;
|
||||
}
|
||||
paths_.emplace_back(std::move(path)); // Usamos std::move
|
||||
paths_.emplace_back(std::move(path)); // Usamos std::move
|
||||
break;
|
||||
}
|
||||
case PathCentered::ON_Y: {
|
||||
// Centrar en el eje Y (para paths Horizontales)
|
||||
const float Y_offset = pos_.h / 2.0f; // Asume que pos_.h está inicializado
|
||||
const float Y_offset = pos_.h / 2.0f; // Asume que pos_.h está inicializado
|
||||
if (path.is_point_path) {
|
||||
const float Y_base = !path.spots.empty() ? path.spots.front().y : 0.0f;
|
||||
const float Y = Y_base - Y_offset;
|
||||
for (auto &spot : path.spots) {
|
||||
for (auto& spot : path.spots) {
|
||||
spot.y = Y;
|
||||
}
|
||||
} else {
|
||||
// Es un path generado, ajustamos la posición fija (que es Y)
|
||||
path.fixed_pos -= Y_offset;
|
||||
}
|
||||
paths_.emplace_back(std::move(path)); // Usamos std::move
|
||||
paths_.emplace_back(std::move(path)); // Usamos std::move
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Sin centrado
|
||||
paths_.emplace_back(std::move(path)); // Usamos std::move
|
||||
paths_.emplace_back(std::move(path)); // Usamos std::move
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Añade un recorrido generado (en segundos)
|
||||
void PathSprite::addPath(float start, float end, PathType type, float fixed_pos, float duration_s, const std::function<double(double)> &easing_function, float waiting_time_s) {
|
||||
void PathSprite::addPath(float start, float end, PathType type, float fixed_pos, float duration_s, const std::function<double(double)>& easing_function, float waiting_time_s) {
|
||||
paths_.emplace_back(start, end, type, fixed_pos, duration_s, waiting_time_s, easing_function);
|
||||
}
|
||||
|
||||
// Añade un recorrido por puntos (en segundos)
|
||||
void PathSprite::addPath(const std::vector<SDL_FPoint> &spots, float waiting_time_s) {
|
||||
void PathSprite::addPath(const std::vector<SDL_FPoint>& spots, float waiting_time_s) {
|
||||
paths_.emplace_back(spots, waiting_time_s);
|
||||
}
|
||||
|
||||
@@ -130,9 +131,9 @@ void PathSprite::enable() {
|
||||
enabled_ = true;
|
||||
|
||||
// Establece la posición inicial
|
||||
auto &path = paths_.at(current_path_);
|
||||
auto& path = paths_.at(current_path_);
|
||||
if (path.is_point_path) {
|
||||
const auto &p = path.spots.at(path.counter);
|
||||
const auto& p = path.spots.at(path.counter);
|
||||
setPosition(p);
|
||||
} else {
|
||||
// Para paths generados, establecer posición inicial
|
||||
@@ -148,11 +149,11 @@ void PathSprite::enable() {
|
||||
|
||||
// Coloca el sprite en los diferentes puntos del recorrido
|
||||
void PathSprite::moveThroughCurrentPath(float delta_time) {
|
||||
auto &path = paths_.at(current_path_);
|
||||
auto& path = paths_.at(current_path_);
|
||||
|
||||
if (path.is_point_path) {
|
||||
// Lógica para paths por puntos (compatibilidad)
|
||||
const auto &p = path.spots.at(path.counter);
|
||||
const auto& p = path.spots.at(path.counter);
|
||||
setPosition(p);
|
||||
|
||||
if (!path.on_destination) {
|
||||
|
||||
Reference in New Issue
Block a user