Re-implemented parts of sound source property inspector

dev
Shariq Shah 6 years ago
parent b12b480c3d
commit ee13448c4a
  1. 4
      assets/entities/turret.symtres
  2. 2
      src/common/version.h
  3. 69
      src/game/editor.c
  4. 2
      src/game/enemy.c
  5. 7
      src/game/entity.c
  6. 1
      src/game/entity.h
  7. 5
      src/game/scene.c
  8. 9
      src/game/sound_source.c
  9. 7
      src/game/sound_source.h
  10. 2
      todo.txt

@ -35,7 +35,7 @@ Entity
loop : false loop : false
sound_min_distance : 0.0000 sound_min_distance : 0.0000
active : true active : true
playing : false paused : true
position : 0.000 0.000 0.000 position : 0.000 0.000 0.000
bouding_box_min : -0.500 -0.500 -0.500 bouding_box_min : -0.500 -0.500 -0.500
source_filename : sounds/bullet_1.wav source_filename : sounds/bullet_1.wav
@ -56,7 +56,7 @@ Entity
loop : true loop : true
sound_min_distance : 0.0000 sound_min_distance : 0.0000
active : true active : true
playing : true paused : false
position : 0.000 0.000 0.000 position : 0.000 0.000 0.000
bouding_box_min : -0.500 -0.500 -0.500 bouding_box_min : -0.500 -0.500 -0.500
source_filename : sounds/windy_ambience.ogg source_filename : sounds/windy_ambience.ogg

@ -4,7 +4,7 @@
/* Auto generated version file. DO NOT MODIFY */ /* Auto generated version file. DO NOT MODIFY */
#define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MAJOR 0
#define SYMMETRY_VERSION_MINOR 1 #define SYMMETRY_VERSION_MINOR 1
#define SYMMETRY_VERSION_REVISION 325 #define SYMMETRY_VERSION_REVISION 326
#define SYMMETRY_VERSION_BRANCH "dev" #define SYMMETRY_VERSION_BRANCH "dev"
#endif #endif

@ -32,6 +32,7 @@
#include "console.h" #include "console.h"
#include "debug_vars.h" #include "debug_vars.h"
#include "../common/version.h" #include "../common/version.h"
#include "sound_source.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -243,6 +244,15 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
} }
} }
break; break;
case ET_SOUND_SOURCE:
{
struct Sound_Source* sound_source = (struct Sound_Source*)editor->selected_entity;
quat rot = { 0.f, 0.f, 0.f, 1.f };
quat_axis_angle(&rot, &UNIT_X, 90.f);
im_circle(sound_source->min_distance, 32, false, abs_pos, rot, editor->selected_entity_color, 5);
im_circle(sound_source->max_distance, 32, false, abs_pos, rot, editor->selected_entity_color, 5);
}
break;
} }
/* Draw bounding box for selected entity */ /* Draw bounding box for selected entity */
@ -2029,28 +2039,65 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
{ {
struct Sound* sound = game_state->sound; struct Sound* sound = game_state->sound;
struct Sound_Source* sound_source = (struct Sound_Source*)entity; struct Sound_Source* sound_source = (struct Sound_Source*)entity;
bool sound_params_modified = false;
if(nk_tree_push(context, NK_TREE_TAB, "Sound Source", NK_MAXIMIZED)) if(nk_tree_push(context, NK_TREE_TAB, "Sound Source", NK_MAXIMIZED))
{ {
nk_layout_row_dynamic(context, row_height, 2); nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Playing", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Playing", LABEL_FLAGS_ALIGN_LEFT);
int is_playing = sound_source_instance_is_paused(sound, sound_source->source_instance); int is_playing = !sound_source_is_paused(sound, sound_source);
int playing = nk_check_label(context, "", is_playing); int playing = nk_check_label(context, "", is_playing);
if(is_playing && !playing) if(is_playing && !playing)
sound_source_instance_pause(sound, sound_source->source_instance); sound_source_pause(sound, sound_source);
else if(!is_playing && playing) else if(!is_playing && playing)
sound_source_instance_play(sound, sound_source->source_instance); sound_source_play(sound, sound_source);
nk_label(context, "Loop", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Loop", LABEL_FLAGS_ALIGN_LEFT);
int is_looping = sound_source_instance_loop_get(sound, sound_source->source_instance); int is_looping = sound_source->loop;
int looping = nk_check_label(context, "", is_looping); int looping = nk_check_label(context, "", is_looping);
if(is_looping != looping) if(is_looping != looping)
sound_source_instance_loop_set(sound, sound_source->source_instance, looping); {
sound_source->loop = (bool)looping;
sound_params_modified = true;
}
nk_layout_row_dynamic(context, row_height, 1); nk_layout_row_dynamic(context, row_height, 1);
float volume = sound_source_instance_volume_get(sound, sound_source->source_instance); float volume = nk_propertyf(context, "Volume", 0.f, sound_source->volume, 100.f, 0.5f, 0.1f);
volume = nk_propertyf(context, "Volume", 0.f, volume, 10.f, 0.5f, 0.1f); if(volume != sound_source->volume)
sound_source_instance_volume_set(sound, sound_source->source_instance, volume); {
sound_source->volume = volume;
sound_params_modified = true;
}
float min_distance = nk_propertyf(context, "Min Distance", 0.f, sound_source->min_distance, sound_source->max_distance, 0.5f, 0.1f);
if(min_distance != sound_source->min_distance)
{
sound_source->min_distance = min_distance;
sound_params_modified = true;
}
float max_distance = nk_propertyf(context, "Max Distance", sound_source->min_distance, sound_source->max_distance, FLT_MAX, 0.5f, 0.1f);
if(max_distance != sound_source->max_distance)
{
sound_source->max_distance = max_distance;
sound_params_modified = true;
}
float combo_width = nk_widget_width(context), combo_height = row_height * 4;
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Attenuation", LABEL_FLAGS_ALIGN_LEFT);
int new_attenuation = nk_combo_string(context, "None\0Inverse\0Linear\0Exponential", sound_source->attenuation_type, 4, row_height, nk_vec2(combo_width, combo_height));
if(new_attenuation != sound_source->attenuation_type)
{
sound_source->attenuation_type = new_attenuation;
sound_params_modified = true;
}
if(sound_params_modified)
{
sound_source_validate_instance(sound, sound_source);
sound_source_apply_params_to_instance(sound, sound_source);
}
nk_layout_row_dynamic(context, row_height, 2); nk_layout_row_dynamic(context, row_height, 2);
static char sound_source_filename_buffer[MAX_FILENAME_LEN]; static char sound_source_filename_buffer[MAX_FILENAME_LEN];

@ -66,7 +66,7 @@ void enemy_init(struct Enemy* enemy, int type)
void enemy_weapon_sound_set(struct Enemy* enemy, const char* sound_filename, int type) void enemy_weapon_sound_set(struct Enemy* enemy, const char* sound_filename, int type)
{ {
sound_source_buffer_set(game_state_get()->sound, sound_filename, type); sound_source_buffer_set(game_state_get()->sound, enemy->weapon_sound, sound_filename, type);
} }
void enemy_static_mesh_set(struct Enemy* enemy, const char* geometry_filename, int material_type) void enemy_static_mesh_set(struct Enemy* enemy, const char* geometry_filename, int material_type)

@ -20,6 +20,7 @@
#include "texture.h" #include "texture.h"
#include "enemy.h" #include "enemy.h"
#include "event.h" #include "event.h"
#include "sound_source.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -254,7 +255,7 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object, bool writ
{ {
struct Sound_Source* sound_source = (struct Sound_Source*)entity; struct Sound_Source* sound_source = (struct Sound_Source*)entity;
hashmap_str_set(entity_data, "source_filename", sound_source->source_buffer->filename); hashmap_str_set(entity_data, "source_filename", sound_source->source_buffer->filename);
hashmap_bool_set(entity_data, "playing", sound_source->playing); hashmap_bool_set(entity_data, "paused", sound_source_is_paused(game_state_get()->sound, sound_source));
hashmap_int_set(entity_data, "sound_type", sound_source->type); hashmap_int_set(entity_data, "sound_type", sound_source->type);
hashmap_bool_set(entity_data, "loop", sound_source->loop); hashmap_bool_set(entity_data, "loop", sound_source->loop);
hashmap_float_set(entity_data, "volume", sound_source->volume); hashmap_float_set(entity_data, "volume", sound_source->volume);
@ -420,7 +421,6 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e
struct Sound_Source_Buffer* default_source_buffer = sound_source->source_buffer; struct Sound_Source_Buffer* default_source_buffer = sound_source->source_buffer;
uint default_source_instance = sound_source->source_instance; uint default_source_instance = sound_source->source_instance;
if(hashmap_value_exists(object->data, "playing")) sound_source->playing = hashmap_bool_get(object->data, "playing");
if(hashmap_value_exists(object->data, "loop")) sound_source->loop = hashmap_bool_get(object->data, "loop"); if(hashmap_value_exists(object->data, "loop")) sound_source->loop = hashmap_bool_get(object->data, "loop");
if(hashmap_value_exists(object->data, "sound_min_distance")) sound_source->min_distance = hashmap_float_get(object->data, "sound_min_distance"); if(hashmap_value_exists(object->data, "sound_min_distance")) sound_source->min_distance = hashmap_float_get(object->data, "sound_min_distance");
if(hashmap_value_exists(object->data, "sound_max_distance")) sound_source->max_distance = hashmap_float_get(object->data, "sound_max_distance"); if(hashmap_value_exists(object->data, "sound_max_distance")) sound_source->max_distance = hashmap_float_get(object->data, "sound_max_distance");
@ -447,7 +447,8 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e
sound_source_instance_volume_set(sound, sound_source->source_instance, sound_source->volume); sound_source_instance_volume_set(sound, sound_source->source_instance, sound_source->volume);
sound_update_3d(sound); sound_update_3d(sound);
if(sound_source->playing) bool paused = hashmap_value_exists(object->data, "paused") ? hashmap_bool_get(object->data, "paused") : false;
if(!paused)
sound_source_instance_play(sound, sound_source->source_instance); sound_source_instance_play(sound, sound_source->source_instance);
//Stop the default sound source from playing now that we have loaded the actual buffer //Stop the default sound source from playing now that we have loaded the actual buffer

@ -112,7 +112,6 @@ struct Sound_Source
{ {
struct Entity base; struct Entity base;
int type; int type;
bool playing;
bool loop; bool loop;
uint source_instance; uint source_instance;
float min_distance; float min_distance;

@ -655,7 +655,6 @@ struct Sound_Source* scene_sound_source_create(struct Scene* scene, const char*
new_sound_source->loop = loop; new_sound_source->loop = loop;
new_sound_source->min_distance = 0.f; new_sound_source->min_distance = 0.f;
new_sound_source->max_distance = 10.f; new_sound_source->max_distance = 10.f;
new_sound_source->playing = play;
new_sound_source->attenuation_type = SA_LINEAR; new_sound_source->attenuation_type = SA_LINEAR;
new_sound_source->rolloff_factor = 0.95f; new_sound_source->rolloff_factor = 0.95f;
new_sound_source->volume = 1.f; new_sound_source->volume = 1.f;
@ -667,7 +666,7 @@ struct Sound_Source* scene_sound_source_create(struct Scene* scene, const char*
sound_source_instance_volume_set(sound, new_sound_source->source_instance, new_sound_source->volume); sound_source_instance_volume_set(sound, new_sound_source->source_instance, new_sound_source->volume);
sound_update_3d(sound); sound_update_3d(sound);
if(new_sound_source->playing) sound_source_instance_play(sound, new_sound_source->source_instance); if(play) sound_source_instance_play(sound, new_sound_source->source_instance);
} }
else else
{ {
@ -1178,7 +1177,7 @@ struct Entity* scene_entity_duplicate(struct Scene* scene, struct Entity* entity
case ET_SOUND_SOURCE: case ET_SOUND_SOURCE:
{ {
struct Sound_Source* sound_source = (struct Sound_Source*)entity; struct Sound_Source* sound_source = (struct Sound_Source*)entity;
struct Sound_Source* new_sound_source = scene_sound_source_create(scene, entity->name, entity->transform.parent, sound_source->source_buffer->filename, sound_source->type, sound_source->loop, sound_source->playing); struct Sound_Source* new_sound_source = scene_sound_source_create(scene, entity->name, entity->transform.parent, sound_source->source_buffer->filename, sound_source->type, sound_source->loop, !sound_source_is_paused(game_state_get()->sound, sound_source));
if(!new_sound_source) if(!new_sound_source)
return new_entity; return new_entity;
new_sound_source->min_distance = sound_source->min_distance; new_sound_source->min_distance = sound_source->min_distance;

@ -4,9 +4,6 @@
#include "transform.h" #include "transform.h"
#include "../common/log.h" #include "../common/log.h"
static void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity);
static void sound_source_apply_params_to_instance(struct Sound* sound, struct Sound_Source* entity);
void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity) void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity)
{ {
if(!sound_source_instance_is_valid(sound, entity->source_instance)) if(!sound_source_instance_is_valid(sound, entity->source_instance))
@ -78,3 +75,9 @@ void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity, c
} }
} }
} }
bool sound_source_is_paused(struct Sound* sound, struct Sound_Source* entity)
{
sound_source_validate_instance(sound, entity);
return sound_source_instance_is_paused(sound, entity->source_instance);
}

@ -1,13 +1,18 @@
#ifndef SOUND_SOURCE_H #ifndef SOUND_SOURCE_H
#define SOUND_SOURCE_H #define SOUND_SOURCE_H
#include <stdbool.h>
struct Sound_Source; struct Sound_Source;
struct Sound; struct Sound;
void sound_source_play(struct Sound* sound, struct Sound_Source* entity); void sound_source_play(struct Sound* sound, struct Sound_Source* entity);
void sound_source_pause(struct Sound* sound, struct Sound_Source* entity); void sound_source_pause(struct Sound* sound, struct Sound_Source* entity);
void sound_source_stop(struct Sound* sound, struct Sound_Source* entity); void sound_source_stop(struct Sound* sound, struct Sound_Source* entity);
bool sound_source_is_paused(struct Sound* sound, struct Sound_Source* entity);
void sound_source_update_position(struct Sound* sound, struct Sound_Source* entity); void sound_source_update_position(struct Sound* sound, struct Sound_Source* entity);
void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity); void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity, const char* filename, int type);
void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity);
void sound_source_apply_params_to_instance(struct Sound* sound, struct Sound_Source* entity);
#endif #endif

@ -5,7 +5,6 @@ Todo:
- Level-wide events and responses - Level-wide events and responses
- Main menu as a level or just have a pause menu where game's options etc can be changed? - Main menu as a level or just have a pause menu where game's options etc can be changed?
- Implement separate property window for player related variables that can be shown in the editor similar to renderer settings etc - Implement separate property window for player related variables that can be shown in the editor similar to renderer settings etc
- Add all sound source properties to propery inspector
- Fix rotate gizmo's origin not being set to the selected entity - Fix rotate gizmo's origin not being set to the selected entity
- Player shooting - Player shooting
- Player jump cooldown, don't allow jump until a certian time interval has passed, even if we're grounded - Player jump cooldown, don't allow jump until a certian time interval has passed, even if we're grounded
@ -403,3 +402,4 @@ Done:
* Fix Turret losing target at diagonals * Fix Turret losing target at diagonals
* Add turret properties to property inspector * Add turret properties to property inspector
* Add another ambient sound_source entity as child to enemy entity * Add another ambient sound_source entity as child to enemy entity
* Add all sound source properties to propery inspector
Loading…
Cancel
Save