|
|
@ -25,6 +25,7 @@ |
|
|
|
#include "gui.h" |
|
|
|
#include "gui.h" |
|
|
|
#include "editor.h" |
|
|
|
#include "editor.h" |
|
|
|
#include "sprite.h" |
|
|
|
#include "sprite.h" |
|
|
|
|
|
|
|
#include "../common/string_utils.h" |
|
|
|
#include "../common/parser.h" |
|
|
|
#include "../common/parser.h" |
|
|
|
#include "../common/hashmap.h" |
|
|
|
#include "../common/hashmap.h" |
|
|
|
#include "../common/variant.h" |
|
|
|
#include "../common/variant.h" |
|
|
@ -96,6 +97,7 @@ bool game_init(struct Window* window, struct Platform_Api* platform_api) |
|
|
|
light_init(); |
|
|
|
light_init(); |
|
|
|
material_init(); |
|
|
|
material_init(); |
|
|
|
entity_init(); |
|
|
|
entity_init(); |
|
|
|
|
|
|
|
platform->physics.init(); |
|
|
|
scene_init(); |
|
|
|
scene_init(); |
|
|
|
|
|
|
|
|
|
|
|
/* Debug scene setup */ |
|
|
|
/* Debug scene setup */ |
|
|
@ -106,132 +108,128 @@ bool game_init(struct Window* window, struct Platform_Api* platform_api) |
|
|
|
|
|
|
|
|
|
|
|
void scene_setup(void) |
|
|
|
void scene_setup(void) |
|
|
|
{
|
|
|
|
{
|
|
|
|
// struct Entity* player = scene_add_new("player", ET_CAMERA);
|
|
|
|
// struct Entity* player = scene_add_new("player", ET_CAMERA);
|
|
|
|
// game_state->player_node = player->id;
|
|
|
|
// game_state->player_node = player->id;
|
|
|
|
// vec3 viewer_pos = {10, 5, 100};
|
|
|
|
// vec3 viewer_pos = {10, 5, 100};
|
|
|
|
// transform_set_position(player, &viewer_pos);
|
|
|
|
// transform_set_position(player, &viewer_pos);
|
|
|
|
// int render_width, render_height;
|
|
|
|
// int render_width, render_height;
|
|
|
|
// render_width = 1024;
|
|
|
|
// render_width = 1024;
|
|
|
|
// render_height = 768;
|
|
|
|
// render_height = 768;
|
|
|
|
// camera_create(player, render_width, render_height);
|
|
|
|
// camera_create(player, render_width, render_height);
|
|
|
|
// camera_attach_fbo(player, render_width, render_height, 1, 1, 1);
|
|
|
|
// camera_attach_fbo(player, render_width, render_height, 1, 1, 1);
|
|
|
|
// vec4_fill(&player->camera.clear_color, 0.3f, 0.6f, 0.9f, 1.0f);
|
|
|
|
// vec4_fill(&player->camera.clear_color, 0.3f, 0.6f, 0.9f, 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
// vec4 color = {1.f, 1.f, 1.f, 1.f };
|
|
|
|
// vec4 color = {1.f, 1.f, 1.f, 1.f };
|
|
|
|
// struct Entity* new_ent = scene_add_new("Model_Entity", ET_STATIC_MESH);
|
|
|
|
// struct Entity* new_ent = scene_add_new("Model_Entity", ET_STATIC_MESH);
|
|
|
|
// vec3 position = {0, 0, -5};
|
|
|
|
// vec3 position = {0, 0, -5};
|
|
|
|
// transform_translate(new_ent, &position, TS_WORLD);
|
|
|
|
// transform_translate(new_ent, &position, TS_WORLD);
|
|
|
|
// new_ent->renderable = true;
|
|
|
|
// new_ent->renderable = true;
|
|
|
|
// model_create(new_ent, "default.pamesh", "Blinn_Phong");
|
|
|
|
// model_create(new_ent, "default.pamesh", "Blinn_Phong");
|
|
|
|
// model_set_material_param(new_ent, "diffuse_color", &color);
|
|
|
|
// model_set_material_param(new_ent, "diffuse_color", &color);
|
|
|
|
// int tex = texture_create_from_file("white.tga", TU_DIFFUSE);
|
|
|
|
// int tex = texture_create_from_file("white.tga", TU_DIFFUSE);
|
|
|
|
// model_set_material_param(new_ent, "diffuse_texture", &tex);
|
|
|
|
// model_set_material_param(new_ent, "diffuse_texture", &tex);
|
|
|
|
// vec3 scale = {1, 1, 1};
|
|
|
|
// vec3 scale = {1, 1, 1};
|
|
|
|
// transform_scale(new_ent, &scale);
|
|
|
|
// transform_scale(new_ent, &scale);
|
|
|
|
|
|
|
|
|
|
|
|
// /* struct Entity* sound_ent = scene_add_as_child("Sound_ENT", ET_SOUND_SOURCE, new_ent->id); */
|
|
|
|
// /* struct Entity* sound_ent = scene_add_as_child("Sound_ENT", ET_SOUND_SOURCE, new_ent->id); */
|
|
|
|
// /* struct Sound_Source* sound_source = &sound_ent->sound_source; */
|
|
|
|
// /* struct Sound_Source* sound_source = &sound_ent->sound_source; */
|
|
|
|
// /* platform->sound.source_create(true, 1, &sound_source->source_handle, &sound_source->buffer_handles[0]); */
|
|
|
|
// /* platform->sound.source_create(true, 1, &sound_source->source_handle, &sound_source->buffer_handles[0]); */
|
|
|
|
// /* platform->sound.source_load_wav(sound_source->source_handle, */
|
|
|
|
// /* platform->sound.source_load_wav(sound_source->source_handle, */
|
|
|
|
// /* sound_source->buffer_handles[0], */
|
|
|
|
// /* sound_source->buffer_handles[0], */
|
|
|
|
// /* "BigExplosion.wav"); */
|
|
|
|
// /* "BigExplosion.wav"); */
|
|
|
|
// /* //sound_source_relative_set(source, true); */
|
|
|
|
// /* //sound_source_relative_set(source, true); */
|
|
|
|
// /* platform->sound.source_volume_set(sound_source->source_handle, 1.f); */
|
|
|
|
// /* platform->sound.source_volume_set(sound_source->source_handle, 1.f); */
|
|
|
|
// /* platform->sound.source_loop_set(sound_source->source_handle, true); */
|
|
|
|
// /* platform->sound.source_loop_set(sound_source->source_handle, true); */
|
|
|
|
// /* platform->sound.source_play(sound_source->source_handle); */
|
|
|
|
// /* platform->sound.source_play(sound_source->source_handle); */
|
|
|
|
|
|
|
|
|
|
|
|
// int parent_node = new_ent->id;
|
|
|
|
// int parent_node = new_ent->id;
|
|
|
|
// int num_suz = 10;
|
|
|
|
// int num_suz = 10;
|
|
|
|
// srand(time(NULL));
|
|
|
|
// srand(time(NULL));
|
|
|
|
// for(int i = 0; i < num_suz; i++)
|
|
|
|
// for(int i = 0; i < num_suz; i++)
|
|
|
|
// {
|
|
|
|
// {
|
|
|
|
// int x = rand() % num_suz;
|
|
|
|
// int x = rand() % num_suz;
|
|
|
|
// int y = rand() % num_suz;
|
|
|
|
// int y = rand() % num_suz;
|
|
|
|
// int z = rand() % num_suz;
|
|
|
|
// int z = rand() % num_suz;
|
|
|
|
// x++; y++; z++;
|
|
|
|
// x++; y++; z++;
|
|
|
|
// struct Entity* suz = scene_add_as_child("Suzanne", ET_STATIC_MESH, parent_node);
|
|
|
|
// struct Entity* suz = scene_add_as_child("Suzanne", ET_STATIC_MESH, parent_node);
|
|
|
|
// //struct Entity* suz = scene_add_new("Suzanne", ET_STATIC_MESH);
|
|
|
|
// //struct Entity* suz = scene_add_new("Suzanne", ET_STATIC_MESH);
|
|
|
|
// suz->renderable = true;
|
|
|
|
// suz->renderable = true;
|
|
|
|
// model_create(suz, "default.pamesh", "Blinn_Phong");
|
|
|
|
// model_create(suz, "default.pamesh", "Blinn_Phong");
|
|
|
|
// model_set_material_param(suz, "diffuse_color", &color);
|
|
|
|
// model_set_material_param(suz, "diffuse_color", &color);
|
|
|
|
// float spec_str = 80.f;
|
|
|
|
// float spec_str = 80.f;
|
|
|
|
// model_set_material_param(suz, "specular_strength", &spec_str);
|
|
|
|
// model_set_material_param(suz, "specular_strength", &spec_str);
|
|
|
|
// vec3 s_pos = {x, 0, z};
|
|
|
|
// vec3 s_pos = {x, 0, z};
|
|
|
|
// transform_translate(suz, &s_pos, TS_WORLD);
|
|
|
|
// transform_translate(suz, &s_pos, TS_WORLD);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// struct Entity* ground = scene_add_new("Ground", ET_STATIC_MESH);
|
|
|
|
// struct Entity* ground = scene_add_new("Ground", ET_STATIC_MESH);
|
|
|
|
// ground->renderable = true;
|
|
|
|
// ground->renderable = true;
|
|
|
|
// model_create(ground, "default.pamesh", "Blinn_Phong");
|
|
|
|
// model_create(ground, "default.pamesh", "Blinn_Phong");
|
|
|
|
// model_set_material_param(ground, "diffuse_color", &color);
|
|
|
|
// model_set_material_param(ground, "diffuse_color", &color);
|
|
|
|
// int white_tex = texture_create_from_file("white.tga", TU_DIFFUSE);
|
|
|
|
// int white_tex = texture_create_from_file("white.tga", TU_DIFFUSE);
|
|
|
|
// model_set_material_param(ground, "diffuse_texture", &white_tex);
|
|
|
|
// model_set_material_param(ground, "diffuse_texture", &white_tex);
|
|
|
|
// float spec_str = 80.f;
|
|
|
|
// float spec_str = 80.f;
|
|
|
|
// model_set_material_param(ground, "specular_strength", &spec_str);
|
|
|
|
// model_set_material_param(ground, "specular_strength", &spec_str);
|
|
|
|
// vec3 pos = {0, -5, 0};
|
|
|
|
// vec3 pos = {0, -5, 0};
|
|
|
|
// vec3 scale_ground = {400.f, 2.f, 400.f};
|
|
|
|
// vec3 scale_ground = {400.f, 2.f, 400.f};
|
|
|
|
// transform_set_position(ground, &pos);
|
|
|
|
// transform_set_position(ground, &pos);
|
|
|
|
// transform_scale(ground, &scale_ground);
|
|
|
|
// transform_scale(ground, &scale_ground);
|
|
|
|
|
|
|
|
|
|
|
|
// /* struct Entity* screen = scene_add_new("Screen", NULL); */
|
|
|
|
// /* struct Entity* screen = scene_add_new("Screen", NULL); */
|
|
|
|
// /* struct Model* screen_model = entity_component_add(screen, C_MODEL, NULL, NULL); */
|
|
|
|
// /* struct Model* screen_model = entity_component_add(screen, C_MODEL, NULL, NULL); */
|
|
|
|
// /* screen_model->geometry_index = geom_find("Quad"); */
|
|
|
|
// /* screen_model->geometry_index = geom_find("Quad"); */
|
|
|
|
// /* struct Entity* screen_camera = scene_add_as_child("Screen_Camera", NULL, screen->node); */
|
|
|
|
// /* struct Entity* screen_camera = scene_add_as_child("Screen_Camera", NULL, screen->node); */
|
|
|
|
// /* struct Transform* screen_camera_tran = entity_component_get(screen_camera, C_TRANSFORM); */
|
|
|
|
// /* struct Transform* screen_camera_tran = entity_component_get(screen_camera, C_TRANSFORM); */
|
|
|
|
// /* transform_rotate(screen_camera_tran, &UNIT_Y, 180.f, TS_WORLD); */
|
|
|
|
// /* transform_rotate(screen_camera_tran, &UNIT_Y, 180.f, TS_WORLD); */
|
|
|
|
// /* struct Camera* cam = entity_component_add(screen_camera, C_CAMERA, 50, 50); */
|
|
|
|
// /* struct Camera* cam = entity_component_add(screen_camera, C_CAMERA, 50, 50); */
|
|
|
|
// /* cam->nearz = 0.1f; */
|
|
|
|
// /* cam->nearz = 0.1f; */
|
|
|
|
// /* cam->farz = 50.f; */
|
|
|
|
// /* cam->farz = 50.f; */
|
|
|
|
// /* camera_update_proj(cam); */
|
|
|
|
// /* camera_update_proj(cam); */
|
|
|
|
// /* camera_attach_fbo(cam, 128, 128, 1, 1, 0); */
|
|
|
|
// /* camera_attach_fbo(cam, 128, 128, 1, 1, 0); */
|
|
|
|
// /* model_set_material_param(screen_model, "diffuse_color", &color); */
|
|
|
|
// /* model_set_material_param(screen_model, "diffuse_color", &color); */
|
|
|
|
// /* model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); */
|
|
|
|
// /* model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); */
|
|
|
|
|
|
|
|
|
|
|
|
// const int MAX_LIGHTS = 3;
|
|
|
|
// const int MAX_LIGHTS = 3;
|
|
|
|
// for(int i = 0; i < MAX_LIGHTS; i++)
|
|
|
|
// for(int i = 0; i < MAX_LIGHTS; i++)
|
|
|
|
// {
|
|
|
|
// {
|
|
|
|
// int x = rand() % MAX_LIGHTS;
|
|
|
|
// int x = rand() % MAX_LIGHTS;
|
|
|
|
// int z = rand() % MAX_LIGHTS;
|
|
|
|
// int z = rand() % MAX_LIGHTS;
|
|
|
|
// x++; z++;
|
|
|
|
// x++; z++;
|
|
|
|
// struct Entity* light_ent = scene_add_new("Light_Ent", ET_LIGHT);
|
|
|
|
// struct Entity* light_ent = scene_add_new("Light_Ent", ET_LIGHT);
|
|
|
|
// vec3 lt_pos = {x * 20, 0, z * 20};
|
|
|
|
// vec3 lt_pos = {x * 20, 0, z * 20};
|
|
|
|
// transform_set_position(light_ent, <_pos);
|
|
|
|
// transform_set_position(light_ent, <_pos);
|
|
|
|
// light_create(light_ent, LT_POINT);
|
|
|
|
// light_create(light_ent, LT_POINT);
|
|
|
|
// vec3_fill(&light_ent->light.color, 1.f / (float)x, 1.f / ((rand() % 10) + 1.f), 1.f / (float)z);
|
|
|
|
// vec3_fill(&light_ent->light.color, 1.f / (float)x, 1.f / ((rand() % 10) + 1.f), 1.f / (float)z);
|
|
|
|
// light_ent->light.intensity = 1.f;
|
|
|
|
// light_ent->light.intensity = 1.f;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// ///* log_message("Sizeof Entity : %d", sizeof(struct Entity)); */
|
|
|
|
/////* log_message("Sizeof Entity : %d", sizeof(struct Entity)); */
|
|
|
|
|
|
|
|
|
|
|
|
// ///* struct Entity* light_ent = entity_find("Ground"); */
|
|
|
|
/////* struct Entity* light_ent = entity_find("Ground"); */
|
|
|
|
// ///* entity_save(light_ent, "ground.ent", DT_INSTALL); */
|
|
|
|
/////* entity_save(light_ent, "ground.ent", DT_INSTALL); */
|
|
|
|
|
|
|
|
|
|
|
|
// //scene_save("test.symtres", DIRT_INSTALL);
|
|
|
|
// struct Entity* suz = entity_find("Suzanne");
|
|
|
|
|
|
|
|
// struct Entity* sound_ent = scene_add_as_child("Sound_Ent", ET_SOUND_SOURCE, suz->id);
|
|
|
|
// //struct Entity* light = entity_load("light.ent", DT_INSTALL);
|
|
|
|
// struct Sound_Source* sound_source = &sound_ent->sound_source;
|
|
|
|
|
|
|
|
//sound_source->source_filename = str_new("sounds/teh_beatz.wav");
|
|
|
|
// struct Entity* suz = entity_find("Suzanne");
|
|
|
|
// sound_source->type = ST_WAV;
|
|
|
|
// struct Entity* sound_ent = scene_add_as_child("Sound_Ent", ET_SOUND_SOURCE, suz->id);
|
|
|
|
// sound_source->attenuation_type = SA_LINEAR;
|
|
|
|
// struct Sound_Source* sound_source = &sound_ent->sound_source;
|
|
|
|
// sound_source->rolloff_factor = 0.95f;
|
|
|
|
// sound_source->source_filename = str_new("sounds/teh_beatz.wav");
|
|
|
|
// sound_source->loop = true;
|
|
|
|
// sound_source->type = ST_WAV;
|
|
|
|
// sound_source->volume = 1.f;
|
|
|
|
// sound_source->attenuation_type = SA_LINEAR;
|
|
|
|
// sound_source->min_distance = 1.f;
|
|
|
|
// sound_source->rolloff_factor = 0.95f;
|
|
|
|
// sound_source->max_distance = 50.f;
|
|
|
|
// sound_source->loop = true;
|
|
|
|
// sound_source->playing = true;
|
|
|
|
// sound_source->volume = 1.f;
|
|
|
|
|
|
|
|
// sound_source->min_distance = 1.f;
|
|
|
|
// sound_source->source_instance = 0;
|
|
|
|
// sound_source->max_distance = 50.f;
|
|
|
|
// sound_source->source = NULL;
|
|
|
|
// sound_source->playing = true;
|
|
|
|
|
|
|
|
|
|
|
|
// entity_apply_sound_params(sound_ent);
|
|
|
|
// sound_source->source_instance = 0;
|
|
|
|
|
|
|
|
// sound_source->source = NULL;
|
|
|
|
// scene_save("test_scene.symtres", DIRT_INSTALL);
|
|
|
|
|
|
|
|
|
|
|
|
// entity_apply_sound_params(sound_ent);
|
|
|
|
if(scene_load("test_scene.symtres", DIRT_INSTALL)) |
|
|
|
|
|
|
|
|
|
|
|
// scene_save("parser_write.symtres", DIRT_INSTALL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(scene_load("parser_write.symtres", DIRT_INSTALL)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
log_message("Scene loaded!"); |
|
|
|
log_message("Scene loaded!"); |
|
|
|
struct Entity* player = entity_find("player"); |
|
|
|
struct Entity* player = entity_find("player"); |
|
|
@ -1678,7 +1676,11 @@ void game_cleanup(void) |
|
|
|
game_state = NULL; |
|
|
|
game_state = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(platform) free(platform); |
|
|
|
if(platform) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
platform->physics.cleanup(); |
|
|
|
|
|
|
|
free(platform); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct Game_State* game_state_get(void) |
|
|
|
struct Game_State* game_state_get(void) |
|
|
|