diff --git a/src/game/editor.c b/src/game/editor.c index 2fd3c64..a9219a7 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -156,9 +156,12 @@ void editor_init(struct Editor* editor) event_manager_subscribe(event_manager, EVT_MOUSEMOTION, &editor_on_mousemotion); event_manager_subscribe(event_manager, EVT_KEY_PRESSED, &editor_on_key_press); event_manager_subscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release); +} +void editor_init_entities(struct Editor* editor) +{ editor->cursor_entity = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "sphere.symbres", MAT_UNSHADED); - editor->cursor_entity->base.flags |= EF_TRANSIENT | EF_HIDE_IN_EDITOR_SCENE_HIERARCHY; + editor->cursor_entity->base.flags |= EF_TRANSIENT | EF_SKIP_RENDER | EF_HIDE_IN_EDITOR_SCENE_HIERARCHY; } void editor_init_camera(struct Editor* editor, struct Hashmap* cvars) @@ -1897,7 +1900,6 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor* nk_label(context, "Diffuse Color", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); editor_widget_color_combov4(context, &mesh->model.material_params[MMP_DIFFUSE_COL].val_vec4, 200, 300); - nk_layout_row_dynamic(context, row_height * 4, 2); const char* diffuse_texture_name = texture_get_name(mesh->model.material_params[MMP_DIFFUSE_TEX].val_int); nk_label(context, "Diffuse Texture", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); @@ -1935,11 +1937,10 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor* nk_contextual_end(context); } - nk_layout_row_dynamic(context, row_height, 1); - mesh->model.material_params[MMP_DIFFUSE].val_float = nk_propertyf(context, "Diffuse", 0.f, mesh->model.material_params[MMP_DIFFUSE].val_float, 10.f, 0.5f, 0.1f); - if(mesh->model.material->type == MAT_BLINN) { + nk_layout_row_dynamic(context, row_height, 1); + mesh->model.material_params[MMP_DIFFUSE].val_float = nk_propertyf(context, "Diffuse", 0.f, mesh->model.material_params[MMP_DIFFUSE].val_float, 10.f, 0.5f, 0.1f); nk_layout_row_dynamic(context, row_height, 1); mesh->model.material_params[MMP_SPECULAR].val_float = nk_propertyf(context, "Specular", 0.f, mesh->model.material_params[MMP_SPECULAR].val_float, 10.f, 0.5f, 0.1f); nk_layout_row_dynamic(context, row_height, 1); diff --git a/src/game/editor.h b/src/game/editor.h index b56373e..a032175 100755 --- a/src/game/editor.h +++ b/src/game/editor.h @@ -57,6 +57,7 @@ struct Editor void editor_init(struct Editor* editor_state); void editor_init_camera(struct Editor* editor_state, struct Hashmap* cvars); +void editor_init_entities(struct Editor* editor); void editor_render(struct Editor* editor_state, struct Camera* active_camera); void editor_update(struct Editor* editor_state, float dt); void editor_cleanup(struct Editor* editor_state); diff --git a/src/game/entity.h b/src/game/entity.h index 97c7379..5f48c26 100755 --- a/src/game/entity.h +++ b/src/game/entity.h @@ -52,7 +52,8 @@ enum Entity_Flags EF_SELECTED_IN_EDITOR = 1 << 1, EF_MARKED_FOR_DELETION = 1 << 2, EF_TRANSIENT = 1 << 3, - EF_HIDE_IN_EDITOR_SCENE_HIERARCHY = 1 << 4 + EF_HIDE_IN_EDITOR_SCENE_HIERARCHY = 1 << 4, + EF_SKIP_RENDER = 1 << 5 }; struct Transform diff --git a/src/game/game.c b/src/game/game.c index 3ab7ed0..41204be 100755 --- a/src/game/game.c +++ b/src/game/game.c @@ -108,9 +108,9 @@ bool game_init(struct Window* window, struct Hashmap* cvars) physics_body_set_collision_callback(entity_rigidbody_on_collision); sound_init(game_state->sound); + renderer_init(game_state->renderer); scene_init(game_state->scene); editor_init(game_state->editor); - renderer_init(game_state->renderer); } /* Debug scene setup */ diff --git a/src/game/gl_load.c b/src/game/gl_load.c index 6f00629..3c59d18 100755 --- a/src/game/gl_load.c +++ b/src/game/gl_load.c @@ -57,7 +57,7 @@ void gl_check_error(const char * expression, unsigned int line, const char * fil { case GL_INVALID_OPERATION: error_string = "Invalid Operation"; break; case GL_NO_ERROR: error_string = "No Error"; break; - case GL_INVALID_ENUM: error_string = "Invalid ENUM"; break; + case GL_INVALID_ENUM: error_string = "Invalid Enum"; break; case GL_INVALID_VALUE: error_string = "Invalid Value"; break; case GL_INVALID_FRAMEBUFFER_OPERATION: error_string = "Invalid FrameBuffer Operation"; break; case GL_OUT_OF_MEMORY: error_string = "Out of Memory"; break; diff --git a/src/game/material.c b/src/game/material.c index bd8b1eb..f0295c8 100755 --- a/src/game/material.c +++ b/src/game/material.c @@ -137,6 +137,9 @@ bool material_register_static_mesh(struct Material* material, struct Static_Mesh { material->registered_static_meshes[i] = mesh; + for(int j = 0; j < MMP_MAX; j++) + variant_init_empty(&mesh->model.material_params[j]); + // Set default values for instance parameters switch(material->type) { diff --git a/src/game/renderer.c b/src/game/renderer.c index 49a1e3e..a2852ff 100755 --- a/src/game/renderer.c +++ b/src/game/renderer.c @@ -122,9 +122,9 @@ void renderer_init(struct Renderer* renderer) renderer->composition_shader = shader_create("fbo.vert", "fbo.frag", NULL); renderer->debug_shader = shader_create("debug.vert", "debug.frag", NULL); - renderer->num_culled_slot = editor_debugvar_slot_create("Culled Geom", VT_INT); - renderer->num_rendered_slot = editor_debugvar_slot_create("Rendered Geom", VT_INT); - renderer->num_indices_slot = editor_debugvar_slot_create("Total Indices", VT_INT); + // renderer->num_culled_slot = editor_debugvar_slot_create("Culled Geom", VT_INT); + // renderer->num_rendered_slot = editor_debugvar_slot_create("Rendered Geom", VT_INT); + // renderer->num_indices_slot = editor_debugvar_slot_create("Total Indices", VT_INT); renderer->sprite_batch = malloc(sizeof(*renderer->sprite_batch)); if(!renderer->sprite_batch) @@ -248,7 +248,7 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene) for(int j = 0; j < MAX_MATERIAL_REGISTERED_STATIC_MESHES; j++) { - if(!material->registered_static_meshes[j]) continue; + if(!material->registered_static_meshes[j] || (material->registered_static_meshes[j]->base.flags & EF_SKIP_RENDER)) continue; /* for each registered model, set up uniforms and render */ struct Static_Mesh* mesh = material->registered_static_meshes[j]; @@ -311,9 +311,9 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene) } shader_unbind(); } - editor_debugvar_slot_set_int(renderer->num_rendered_slot, renderer->num_rendered); - editor_debugvar_slot_set_int(renderer->num_culled_slot, renderer->num_culled); - editor_debugvar_slot_set_int(renderer->num_indices_slot, renderer->num_indices); + //editor_debugvar_slot_set_int(renderer->num_rendered_slot, renderer->num_rendered); + //editor_debugvar_slot_set_int(renderer->num_culled_slot, renderer->num_culled); + //editor_debugvar_slot_set_int(renderer->num_indices_slot, renderer->num_indices); renderer->num_culled = renderer->num_rendered = renderer->num_indices = 0; } diff --git a/src/game/scene.c b/src/game/scene.c index 22b51f9..8d3b38d 100755 --- a/src/game/scene.c +++ b/src/game/scene.c @@ -71,6 +71,7 @@ void scene_init(struct Scene* scene) player_init(&scene->player, scene); editor_init_camera(game_state->editor, game_state->cvars); + editor_init_entities(game_state->editor); scene->active_camera_index = game_state_get()->game_mode == GAME_MODE_GAME ? CAM_GAME : CAM_EDITOR; } diff --git a/src/game/scene.h b/src/game/scene.h index d8bc5ea..cc10b94 100755 --- a/src/game/scene.h +++ b/src/game/scene.h @@ -4,12 +4,12 @@ #include "entity.h" #include "renderer.h" -#define MAX_ENTITIES 1024 -#define MAX_LIGHTS 30 -#define MAX_CAMERAS 2 -#define MAX_STATIC_MESHES 1024 -#define MAX_SOUND_SOURCES 128 -#define MAX_ENTITY_ARCHETYPES 32 +#define MAX_ENTITIES 1024 +#define MAX_LIGHTS 30 +#define MAX_CAMERAS 2 +#define MAX_STATIC_MESHES 1024 +#define MAX_SOUND_SOURCES 128 +#define MAX_ENTITY_ARCHETYPES 32 struct Ray; struct Raycast_Result; diff --git a/todo.txt b/todo.txt index 6e4d973..d407d1e 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,6 @@ Todo: + - Save default entity archetype to be loaded when there is not other archetype or in case of an error as fallback + - Bring back debug variable display in editor and allow showing colours, textures etc - Implment/Test reading/writing scene that has a mixture of default entites and entity archetypes - Serialize player, camera properties to file - Implement behaviour that avoids writing normal entities that do not have children or parent to file to avoid inconsistencies when loading them @@ -107,6 +109,7 @@ Improvements: - Improve culling - Allow scaling on all axes at once - Improve grid/immediate mode drawing by switching to glDrawElements instead of glDrawArrays. + - Investigate why transparency is not working for materials Bugs: - Better handling of wav format checking at load time @@ -333,3 +336,5 @@ Done: * Console command to read/write scene to/from file * Implemented flags that specify whether an entity should be written to file or not for example to avoid writing cameras and player to file * In editor, only show entities with specific flags + * Fixed bugs with meshes being registered to uninitialized materials and not rendering + * Added EF_SKIP_RENDER flag to allow entites to skip rendering \ No newline at end of file