Eliminados la mayor parte de accesos a vector mediante at()
This commit is contained in:
@@ -222,121 +222,121 @@ int AnimatedSprite::getIndex(std::string name)
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void AnimatedSprite::animate()
|
||||
{
|
||||
if (!enabled || animation.at(currentAnimation).speed == 0)
|
||||
if (!enabled || animation[currentAnimation].speed == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Calcula el frame actual a partir del contador
|
||||
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).counter / animation.at(currentAnimation).speed;
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
|
||||
|
||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
||||
// en función de la variable loop y coloca el nuevo frame
|
||||
if (animation.at(currentAnimation).currentFrame >= (int)animation.at(currentAnimation).frames.size())
|
||||
if (animation[currentAnimation].currentFrame >= (int)animation[currentAnimation].frames.size())
|
||||
{
|
||||
if (animation.at(currentAnimation).loop == -1)
|
||||
if (animation[currentAnimation].loop == -1)
|
||||
{ // Si no hay loop, deja el último frame
|
||||
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).frames.size();
|
||||
animation.at(currentAnimation).completed = true;
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
|
||||
animation[currentAnimation].completed = true;
|
||||
}
|
||||
else
|
||||
{ // Si hay loop, vuelve al frame indicado
|
||||
animation.at(currentAnimation).counter = 0;
|
||||
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).loop;
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].loop;
|
||||
}
|
||||
}
|
||||
// En caso contrario
|
||||
else
|
||||
{
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setSpriteClip(animation.at(currentAnimation).frames.at(animation.at(currentAnimation).currentFrame));
|
||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||
|
||||
// Incrementa el contador de la animacion
|
||||
animation.at(currentAnimation).counter++;
|
||||
animation[currentAnimation].counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el numero de frames de la animación actual
|
||||
int AnimatedSprite::getNumFrames()
|
||||
{
|
||||
return (int)animation.at(currentAnimation).frames.size();
|
||||
return (int)animation[currentAnimation].frames.size();
|
||||
}
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void AnimatedSprite::setCurrentFrame(int num)
|
||||
{
|
||||
// Descarta valores fuera de rango
|
||||
if (num >= (int)animation.at(currentAnimation).frames.size())
|
||||
if (num >= (int)animation[currentAnimation].frames.size())
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
|
||||
// Cambia el valor de la variable
|
||||
animation.at(currentAnimation).currentFrame = num;
|
||||
animation.at(currentAnimation).counter = 0;
|
||||
animation[currentAnimation].currentFrame = num;
|
||||
animation[currentAnimation].counter = 0;
|
||||
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setSpriteClip(animation.at(currentAnimation).frames.at(animation.at(currentAnimation).currentFrame));
|
||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||
}
|
||||
|
||||
// Establece el valor del contador
|
||||
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
||||
{
|
||||
animation.at(getIndex(name)).counter = num;
|
||||
animation[getIndex(name)].counter = num;
|
||||
}
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||
{
|
||||
animation.at(getIndex(name)).counter = speed;
|
||||
animation[getIndex(name)].counter = speed;
|
||||
}
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
||||
{
|
||||
animation.at(index).counter = speed;
|
||||
animation[index].counter = speed;
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||
{
|
||||
animation.at(getIndex(name)).loop = loop;
|
||||
animation[getIndex(name)].loop = loop;
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(int index, int loop)
|
||||
{
|
||||
animation.at(index).loop = loop;
|
||||
animation[index].loop = loop;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
||||
{
|
||||
animation.at(getIndex(name)).completed = value;
|
||||
animation[getIndex(name)].completed = value;
|
||||
}
|
||||
|
||||
// OLD - Establece el valor de la variable
|
||||
void AnimatedSprite::setAnimationCompleted(int index, bool value)
|
||||
{
|
||||
animation.at(index).completed = value;
|
||||
animation[index].completed = value;
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool AnimatedSprite::animationIsCompleted()
|
||||
{
|
||||
return animation.at(currentAnimation).completed;
|
||||
return animation[currentAnimation].completed;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
||||
{
|
||||
return animation.at(getIndex(name)).frames.at(index);
|
||||
return animation[getIndex(name)].frames[index];
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||
{
|
||||
return animation.at(indexA).frames.at(indexF);
|
||||
return animation[indexA].frames[indexF];
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector
|
||||
@@ -484,9 +484,9 @@ void AnimatedSprite::setCurrentAnimation(std::string name)
|
||||
if (currentAnimation != newAnimation)
|
||||
{
|
||||
currentAnimation = newAnimation;
|
||||
animation.at(currentAnimation).currentFrame = 0;
|
||||
animation.at(currentAnimation).counter = 0;
|
||||
animation.at(currentAnimation).completed = false;
|
||||
animation[currentAnimation].currentFrame = 0;
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,9 +497,9 @@ void AnimatedSprite::setCurrentAnimation(int index)
|
||||
if (currentAnimation != newAnimation)
|
||||
{
|
||||
currentAnimation = newAnimation;
|
||||
animation.at(currentAnimation).currentFrame = 0;
|
||||
animation.at(currentAnimation).counter = 0;
|
||||
animation.at(currentAnimation).completed = false;
|
||||
animation[currentAnimation].currentFrame = 0;
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,7 +513,7 @@ void AnimatedSprite::update()
|
||||
// Establece el rectangulo para un frame de una animación
|
||||
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
||||
{
|
||||
animation.at(index_animation).frames.push_back({x, y, w, h});
|
||||
animation[index_animation].frames.push_back({x, y, w, h});
|
||||
}
|
||||
|
||||
// OLD - Establece el contador para todas las animaciones
|
||||
@@ -528,7 +528,7 @@ void AnimatedSprite::setAnimationCounter(int value)
|
||||
// Reinicia la animación
|
||||
void AnimatedSprite::resetAnimation()
|
||||
{
|
||||
animation.at(currentAnimation).currentFrame = 0;
|
||||
animation.at(currentAnimation).counter = 0;
|
||||
animation.at(currentAnimation).completed = false;
|
||||
animation[currentAnimation].currentFrame = 0;
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].completed = false;
|
||||
}
|
||||
@@ -34,13 +34,13 @@ void Input::update()
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||
{
|
||||
keyBindings.at(input).scancode = code;
|
||||
keyBindings[input].scancode = code;
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||
{
|
||||
gameControllerBindings.at(input).button = button;
|
||||
gameControllerBindings[input].button = button;
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
@@ -65,7 +65,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (keyStates[keyBindings.at(input).scancode] != 0)
|
||||
if (keyStates[keyBindings[input].scancode] != 0)
|
||||
{
|
||||
successKeyboard = true;
|
||||
}
|
||||
@@ -76,11 +76,11 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!keyBindings.at(input).active)
|
||||
if (!keyBindings[input].active)
|
||||
{
|
||||
if (keyStates[keyBindings.at(input).scancode] != 0)
|
||||
if (keyStates[keyBindings[input].scancode] != 0)
|
||||
{
|
||||
keyBindings.at(input).active = true;
|
||||
keyBindings[input].active = true;
|
||||
successKeyboard = true;
|
||||
}
|
||||
else
|
||||
@@ -90,9 +90,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keyStates[keyBindings.at(input).scancode] == 0)
|
||||
if (keyStates[keyBindings[input].scancode] == 0)
|
||||
{
|
||||
keyBindings.at(input).active = false;
|
||||
keyBindings[input].active = false;
|
||||
successKeyboard = false;
|
||||
}
|
||||
else
|
||||
@@ -108,7 +108,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) != 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
||||
{
|
||||
successGameController = true;
|
||||
}
|
||||
@@ -119,11 +119,11 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!gameControllerBindings.at(input).active)
|
||||
if (!gameControllerBindings[input].active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) != 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
||||
{
|
||||
gameControllerBindings.at(input).active = true;
|
||||
gameControllerBindings[input].active = true;
|
||||
successGameController = true;
|
||||
}
|
||||
else
|
||||
@@ -133,9 +133,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) == 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) == 0)
|
||||
{
|
||||
gameControllerBindings.at(input).active = false;
|
||||
gameControllerBindings[input].active = false;
|
||||
successGameController = false;
|
||||
}
|
||||
else
|
||||
@@ -163,7 +163,7 @@ bool Input::checkAnyInput(int device, int index)
|
||||
|
||||
for (int i = 0; i < (int)keyBindings.size(); ++i)
|
||||
{
|
||||
if (mKeystates[keyBindings.at(i).scancode] != 0)
|
||||
if (mKeystates[keyBindings[i].scancode] != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ bool Input::checkAnyInput(int device, int index)
|
||||
{
|
||||
for (int i = 0; i < (int)gameControllerBindings.size(); ++i)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(i).button) != 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[i].button) != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -277,7 +277,7 @@ std::string Input::getControllerName(int index)
|
||||
{
|
||||
if (numGamepads > 0)
|
||||
{
|
||||
return controllerNames.at(index);
|
||||
return controllerNames[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ void Notify::render()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
notifications.at(i).sprite->render();
|
||||
notifications[i].sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,63 +47,63 @@ void Notify::update()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
||||
{
|
||||
notifications.at(i).counter++;
|
||||
notifications[i].counter++;
|
||||
|
||||
// Comprueba los estados
|
||||
if (notifications.at(i).state == ns_rising)
|
||||
if (notifications[i].state == ns_rising)
|
||||
{
|
||||
const float step = ((float)notifications.at(i).counter / notifications.at(i).travelDist);
|
||||
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
||||
const int alpha = 255 * step;
|
||||
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
notifications.at(i).rect.y++;
|
||||
notifications[i].rect.y++;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications.at(i).rect.y--;
|
||||
notifications[i].rect.y--;
|
||||
}
|
||||
notifications.at(i).texture->setAlpha(alpha);
|
||||
notifications[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications.at(i).rect.y == notifications.at(i).y)
|
||||
if (notifications[i].rect.y == notifications[i].y)
|
||||
{
|
||||
notifications.at(i).state = ns_stay;
|
||||
notifications.at(i).texture->setAlpha(255);
|
||||
notifications.at(i).counter = 0;
|
||||
notifications[i].state = ns_stay;
|
||||
notifications[i].texture->setAlpha(255);
|
||||
notifications[i].counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (notifications.at(i).state == ns_stay)
|
||||
else if (notifications[i].state == ns_stay)
|
||||
{
|
||||
if (notifications.at(i).counter == waitTime)
|
||||
if (notifications[i].counter == waitTime)
|
||||
{
|
||||
notifications.at(i).state = ns_vanishing;
|
||||
notifications.at(i).counter = 0;
|
||||
notifications[i].state = ns_vanishing;
|
||||
notifications[i].counter = 0;
|
||||
}
|
||||
}
|
||||
else if (notifications.at(i).state == ns_vanishing)
|
||||
else if (notifications[i].state == ns_vanishing)
|
||||
{
|
||||
|
||||
const float step = (notifications.at(i).counter / (float)notifications.at(i).travelDist);
|
||||
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
||||
const int alpha = 255 * (1 - step);
|
||||
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
notifications.at(i).rect.y--;
|
||||
notifications[i].rect.y--;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications.at(i).rect.y++;
|
||||
notifications[i].rect.y++;
|
||||
}
|
||||
notifications.at(i).texture->setAlpha(alpha);
|
||||
notifications[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications.at(i).rect.y == notifications.at(i).y - notifications.at(i).travelDist)
|
||||
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
|
||||
{
|
||||
notifications.at(i).state = ns_finished;
|
||||
notifications[i].state = ns_finished;
|
||||
}
|
||||
}
|
||||
|
||||
notifications.at(i).sprite->setRect(notifications.at(i).rect);
|
||||
notifications[i].sprite->setRect(notifications[i].rect);
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
@@ -114,10 +114,10 @@ void Notify::clearFinishedNotifications()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (notifications.at(i).state == ns_finished)
|
||||
if (notifications[i].state == ns_finished)
|
||||
{
|
||||
delete notifications.at(i).sprite;
|
||||
delete notifications.at(i).texture;
|
||||
delete notifications[i].sprite;
|
||||
delete notifications[i].texture;
|
||||
notifications.erase(notifications.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ void Screen::renderSpectrumFade()
|
||||
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
||||
const int max = spectrumColor.size() - 1;
|
||||
const int index = max + (0 - max) * step;
|
||||
const color_t c = spectrumColor.at(index);
|
||||
const color_t c = spectrumColor[index];
|
||||
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user