Skip to content

Commit

Permalink
Version 0.10.1-wip_03
Browse files Browse the repository at this point in the history
- Ajustes en el algoritmo de calculo del efecto "panning" de los efectos sonido, para un mejor equilibrio de volumen.
- Añadida la funcionalidad de "rumble" para los controladores que lo soporten.
- Optimizada la lectura del estado de las teclas.
  • Loading branch information
knightfox75 committed Mar 4, 2020
1 parent 55a0c00 commit cda1f8d
Show file tree
Hide file tree
Showing 38 changed files with 91 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Source/ngn.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Archivo principal de la libreria
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Archivo principal de la libreria
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
21 changes: 17 additions & 4 deletions Source/ngn_audio_clip.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Clips de audio
Proyecto iniciado el 1 de Febrero del 2016
Expand Down Expand Up @@ -67,6 +67,9 @@ NGN_AudioClip::NGN_AudioClip() {
// Volumen
_volume = 0;

// Multiplicador de volumen para la atenuacion panoramica
_panning_attenuation = 1.0f;

}


Expand All @@ -87,12 +90,14 @@ void NGN_AudioClip::Clip(NGN_AudioClipData* clip) {

/*** Reproduce el sonido ***/
void NGN_AudioClip::Play(
int32_t volume, // Volumen inicial
int32_t volume, // Volumen inicial
int32_t pan, // Nivel de panning (-100 a 100)
bool loop // Loop?
) {

sound.setRelativeToListener(true);
sound.setMinDistance(1.0f);
sound.setAttenuation(0.0f);
Panning(pan);

_volume = volume;
Expand Down Expand Up @@ -155,7 +160,8 @@ void NGN_AudioClip::Volume(int32_t volume) {
_volume = volume;
if (_volume < 0) _volume = 0;
if (_volume > 100) _volume = 100;
sound.setVolume(_volume);
int32_t v = (int32_t)((float)_volume * _panning_attenuation);
sound.setVolume(v);
}


Expand Down Expand Up @@ -204,11 +210,18 @@ void NGN_AudioClip::Panning(int32_t pan) {
if (_panning > 100) _panning = 100;

// Calculos de angulo
float angle = ((3.141592f * ((float)(-_panning + 100))) / 200.0f);
float angle = ((PI * ((float)(-_panning + 100))) / 200.0f);
float x = std::cos(angle);
float z = std::sin(angle);
sound.setPosition(x, 0.0f, z);

// Calculos de la compensacion de la atenuacion panoramica
_panning_attenuation = (1.0f - (std::abs(x) / 2.0f));

// Reajusta el nivel de volumen
int32_t v = (int32_t)((float)_volume * _panning_attenuation);
sound.setVolume(v);

}


Expand Down
3 changes: 2 additions & 1 deletion Source/ngn_audio_clip.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Clips de audio
Proyecto iniciado el 1 de Febrero del 2016
Expand Down Expand Up @@ -137,6 +137,7 @@ class NGN_AudioClip {
// Parametros
int32_t _panning;
int32_t _volume;
float _panning_attenuation;

};

Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_camera.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Camara virtual en 2D
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_camera.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Camara virtual en 2D
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_canvas.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Canvas - Capa de dibujo
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_canvas.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Canvas - Capa de dibujo
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_collisions.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Sistema de colisiones
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_collisions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Sistema de colisiones
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_defines.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Definiciones de prototipos
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
6 changes: 3 additions & 3 deletions Source/ngn_defines.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Definiciones de prototipos
Proyecto iniciado el 1 de Febrero del 2016
Expand Down Expand Up @@ -60,8 +60,8 @@
/*** Version de N'gine ***/
static const int32_t NGN_VERSION_MAJOR = 0; // Version mayor
static const int32_t NGN_VERSION_MINOR = 10; // Version menor
static const int32_t NGN_VERSION_PATCH = 0; // Version parche
static const std::string NGN_VERSION_METADATA = "a"; // Version metadatos
static const int32_t NGN_VERSION_PATCH = 1; // Version parche
static const std::string NGN_VERSION_METADATA = "wip_03"; // Version metadatos

/*** Definiciones ***/
static const int32_t NGN_DEFAULT_VALUE = 0x7FFFFFFF; // Valor de "defecto"
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_graphics.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_graphics.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_gui.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
GUI - Interfaz grafica de usuario
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_gui.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
GUI - Interfaz grafica de usuario
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
45 changes: 30 additions & 15 deletions Source/ngn_input.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Meotodos de entrada
Proyecto iniciado el 1 de Febrero del 2016
Expand Down Expand Up @@ -92,20 +92,8 @@ NGN_Key::~NGN_Key() {
/*** Actualiza la tecla ***/
void NGN_Key::Update() {

if (held) {
if (last) {
down = false;
} else {
down = true;
}
} else {
down = false;
if (last) {
up = true;
} else {
up = false;
}
}
down = held & !last;
up = !held & last;

last = held;

Expand Down Expand Up @@ -547,6 +535,8 @@ void NGN_Input::GameControllerReset(uint8_t idx) {
controller[idx].pov_down.Reset();
controller[idx].pov_left.Reset();
controller[idx].pov_right.Reset();
controller[idx].rumble_available = false;
controller[idx].haptic = NULL;

}

Expand Down Expand Up @@ -673,6 +663,15 @@ void NGN_Input::AddControllers(int32_t gc) {
controller[i].button_number = SDL_JoystickNumButtons(joy);
if (controller[i].button_number > GAME_CONTROLLER_BUTTONS) controller[i].button_number = GAME_CONTROLLER_BUTTONS;
if (SDL_JoystickNumHats(joy) > 0) controller[i].pov_available = true;
// Efecto "rumble"
controller[i].haptic = SDL_HapticOpen(i);
if (controller[i].haptic) {
if (SDL_HapticRumbleInit(controller[i].haptic) == 0) {
controller[i].rumble_available = true;
} else {
SDL_HapticClose(controller[i].haptic);
}
}
// Guarda este JOY en la lista de controladores disponibles
add_joy.name = name;
add_joy.slot = i;
Expand Down Expand Up @@ -707,6 +706,8 @@ void NGN_Input::RemoveControllers() {
joy = controller[slot].joy;
// Si el Joystick no esta disponible...
if (!SDL_JoystickGetAttached(joy)) {
// Si esta abiero el sistema de "haptic", cierralo
if (controller[slot].haptic) SDL_HapticClose(controller[slot].haptic);
// Cierra el controlador
SDL_JoystickClose(joy);
// Reinicialo
Expand All @@ -726,5 +727,19 @@ void NGN_Input::RemoveControllers() {



/*** Efecto simple de "rumble" en el controlador ***/
int32_t NGN_Input::ControllerRumble(uint32_t controller_id, float intensity, uint32_t duration) {

// Fuera de rando
if (controller_id > GAME_CONTROLLERS) return -1;
// Game controller disponible
if (!controller[controller_id].available) return -1;
// Rumble disponible
if (!controller[controller_id].rumble_available) return -1;
// Rango de fuerza incorrecto
if ((intensity < 0.0f) || (intensity > 1.0f)) return -1;

// Aplica el efecto rumble
return SDL_HapticRumblePlay(controller[controller_id].haptic, intensity, duration);

}
6 changes: 5 additions & 1 deletion Source/ngn_input.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Meotodos de entrada
Proyecto iniciado el 1 de Febrero del 2016
Expand Down Expand Up @@ -157,6 +157,8 @@ class NGN_Input {
NGN_Key pov_down; // POV como teclas cursor (Abajo)
NGN_Key pov_left; // POV como teclas cursor (Izquierda)
NGN_Key pov_right; // POV como teclas cursor (Derecha)
bool rumble_available; // Dispone de efecto "rumble"
SDL_Haptic* haptic; // Puntero a la informacion del "haptic"
};

// Lista de controladores disponibles
Expand Down Expand Up @@ -220,6 +222,8 @@ class NGN_Input {
controller_data controller[GAME_CONTROLLERS];
int32_t controllers;

// Efecto simple de "rumble" para el controlador
int32_t ControllerRumble(uint32_t controller_id, float intensity, uint32_t duration);


// Actualiza el estado de los dispositivos de entrada
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_load.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Funciones de carga de archivos
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_load.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Funciones de carga de archivos
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_music_clip.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Clips de musica
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_music_clip.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Clips de musica
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_render.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_render.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
2 changes: 1 addition & 1 deletion Source/ngn_sound.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
N'gine Lib for C++
*** Version 0.10.0-a ***
*** Version 0.10.1-wip_03 ***
Sonido
Proyecto iniciado el 1 de Febrero del 2016
Expand Down
Loading

0 comments on commit cda1f8d

Please sign in to comment.