Fixed crash when default entity type is loaded from file and implemented functionality to treat default entity types as invisible colliders

dev
Shariq Shah 5 years ago
parent 5ea0d73d3d
commit 61afe3d0d7
  1. 12
      assets/entities/collision_default.symtres
  2. 8
      assets/entities/turret.symtres
  3. 0
      assets/models/default.symbres
  4. 13
      assets/scenes/scene_1.symtres
  5. BIN
      assets/sounds/turret_hum.wav
  6. 2
      src/common/version.h
  7. 2
      src/game/editor.c
  8. 6
      src/game/entity.c
  9. 20
      src/game/player.c
  10. 2
      src/game/scene.c
  11. 9
      todo.txt

@ -0,0 +1,12 @@
Entity
{
type : 1
scale : 1.000 1.000 1.000
rotation : 0.000 0.000 0.000 1.000
position : -5.000 2.000 14.000
flags : 1
name : Collision
bounding_box_min : -0.500 -0.500 -0.500
bounding_box_max : 0.500 0.500 0.500
}

@ -95,16 +95,16 @@ Entity
{
type : 7
scale : 1.000 1.000 1.000
volume : 1.0000
volume : 0.5000
rolloff_factor : 0.9500
rotation : 0.000 0.000 0.000 1.000
loop : true
sound_min_distance : 0.0000
position : 0.000 0.000 0.000
flags : 9
source_filename : sounds/windy_ambience.ogg
sound_type : 2
sound_max_distance : 30.0000
source_filename : sounds/turret_hum.wav
sound_type : 1
sound_max_distance : 40.0000
name : Turret_Ambient_Sound
bounding_box_min : -0.500 -0.500 -0.500
sound_attenuation_type : 2

@ -21,9 +21,9 @@ Player
{
type : 2
scale : 1.000 1.000 1.000
rotation : 0.000 -0.488 0.000 0.873
rotation : 0.000 0.345 0.000 0.939
player_key_mask : 0
position : -55.691 2.167 -8.502
position : -10.436 2.167 27.829
flags : 1
player_health : 100
name : Player
@ -32,6 +32,15 @@ Player
bounding_box_max : 1.500 1.500 1.000
}
Scene_Entity_Entry
{
scale : 1.000 4.000 -10.000
rotation : 0.000 0.000 0.000 1.000
position : -29.000 3.000 25.000
filename : collision_default
name : Collision
}
Scene_Entity_Entry
{
scale : 1.000 1.000 1.000

Binary file not shown.

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

@ -174,7 +174,7 @@ void editor_init(struct Editor* editor)
void editor_init_entities(struct Editor* editor)
{
editor->selected_entity = NULL;
editor->cursor_entity = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "sphere.symbres", MAT_UNSHADED);
editor->cursor_entity = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "cube.symbres", MAT_UNSHADED);
editor->cursor_entity->base.flags |= EF_TRANSIENT | EF_SKIP_RENDER | EF_HIDE_IN_EDITOR_SCENE_HIERARCHY | EF_IGNORE_RAYCAST;
}

@ -320,6 +320,9 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e
struct Entity* new_entity = NULL;
switch(type)
{
case ET_DEFAULT:
new_entity = scene_entity_create(scene, name, parent_entity);
break;
case ET_CAMERA:
{
bool has_fbo = false;
@ -509,12 +512,13 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e
break;
default:
log_warning("Unhandled Entity type '%d' detected", type);
return new_entity;
break;
}
vec3 position = { 0.f, 0.f, 0.f };
quat rotation = { 0.f, 0.f, 0.f, 1.f };
vec3 scale = { 1.f, 1.f, 1.f };
vec3 scale = { 1.f, 1.f, 1.f };
if(hashmap_value_exists(object->data, "position")) position = hashmap_vec3_get(object->data, "position");
if(hashmap_value_exists(object->data, "rotation")) rotation = hashmap_quat_get(object->data, "rotation");

@ -232,7 +232,7 @@ void player_update_physics(struct Player* player, struct Scene* scene, float fix
// Get all the entities that intersect then check the distance if it is less than
// or equal to min_collision_distance then we are colliding
struct Raycast_Result ray_result;
scene_ray_intersect(scene, &forward_ray, &ray_result, ERM_STATIC_MESH);
scene_ray_intersect(scene, &forward_ray, &ray_result, ERM_STATIC_MESH | ERM_DEFAULT);
debug_vars_show_int("Colliding Entities", ray_result.num_entities_intersected);
if(ray_result.num_entities_intersected > 0)
{
@ -270,7 +270,7 @@ void player_update_physics(struct Player* player, struct Scene* scene, float fix
struct Ray downward_ray;
transform_get_absolute_position(player->body_mesh, &downward_ray.origin);
vec3_fill(&downward_ray.direction, 0.f, -1.f, 0.f);
scene_ray_intersect(scene, &downward_ray, &down_ray_result, ERM_STATIC_MESH);
scene_ray_intersect(scene, &downward_ray, &down_ray_result, ERM_STATIC_MESH | ERM_DEFAULT);
if(down_ray_result.num_entities_intersected > 0)
{
for(int i = 0; i < down_ray_result.num_entities_intersected; i++)
@ -376,7 +376,7 @@ void player_on_mousebutton_released(const struct Event* event)
half_height /= 2;
struct Ray bullet_ray = camera_screen_coord_to_ray(player->camera, half_width, half_height);
struct Entity* colliding_entity = scene_ray_intersect_closest(scene, &bullet_ray, ERM_ENEMY);
struct Entity* colliding_entity = scene_ray_intersect_closest(scene, &bullet_ray, ERM_ENEMY | ERM_STATIC_MESH | ERM_DEFAULT);
int intensity = player->weapon_light_intensity_min + rand() % player->weapon_light_intensity_max;
player->weapon_light->intensity = intensity;
@ -386,15 +386,17 @@ void player_on_mousebutton_released(const struct Event* event)
if(!colliding_entity || colliding_entity == player->body_mesh)
return;
if(colliding_entity->type != ET_ENEMY) // If we did not hit an enemy, check if we hit it's mesh instead. If the mesh has a parent enemy entity, assume we hit an enemy otherwise stop
{
if(colliding_entity->transform.parent->type == ET_ENEMY)
colliding_entity = colliding_entity->transform.parent;
else
return;
}
float distance = bv_distance_ray_bounding_box(&bullet_ray, &colliding_entity->derived_bounding_box);
if(distance > 0.f)
{
//vec3 collision_point = bullet_ray.direction;
//vec3_scale(&collision_point, &collision_point, distance);
//vec3_add(&collision_point, &collision_point, &bullet_ray.origin);
//struct Static_Mesh* bullet = scene_static_mesh_create(game_state_get()->scene, "bullet", NULL, "cube.symbres", MAT_UNSHADED);
//struct Light* bullet = entity_load("Spot", DIRT_INSTALL, true);
//if(bullet) transform_set_position(bullet, &collision_point);
enemy_apply_damage((struct Enemy*)colliding_entity, player->damage);
}
}

@ -496,7 +496,7 @@ void scene_write_entity_entry(struct Scene* scene, struct Entity* entity, struct
// For entities with archetypes, we only write the name of the archetype to load
// them from and their transformation info
struct Parser_Object* object = parser_object_new(parser, PO_SCENE_ENTITY_ENTRY);
hashmap_str_set(object->data, "filename", &scene->entity_archetypes[entity->archetype_index][0]);
////hashmap_str_set(object->data, "filename", &scene->entity_archetypes[entity->archetype_index][0]);
hashmap_str_set(object->data, "name", entity->name);
hashmap_vec3_set(object->data, "position", &entity->transform.position);
hashmap_vec3_set(object->data, "scale", &entity->transform.scale);

@ -1,9 +1,8 @@
Todo:
- Game End
- Add functionality to editor that enables adding a default empty entity without having to load it from file
- Fix crash when default entity type is loaded from file
- Don't save parent entity's transform when saving entity archetype. Only save the transformation values for children
- Enemies getting hit by bullets
- Add weapon flash, muzzle mesh to turrets
- Add collision-only entities that can be used to manually approximate collision mesh for an entity
- Save case sensitive file names when scene entity entries
- Disbale all player actions when scene cleared dialog or scene restart dialog are active
- Memory utils that provide allocation tracking
@ -434,4 +433,6 @@ Done:
* Background music track per scene specified in scene properties
* Fixed bug where child entities' absolute position does not change when parent rotates
* Player weapon mesh and lighting
* Added muzzle mesh to player
* Added muzzle mesh to player
* Add weapon flash, muzzle mesh to turrets
* Enemies getting hit by bullets
Loading…
Cancel
Save