Editor works again

This commit is contained in:
John Alanbrook 2022-08-15 21:38:21 +00:00
parent 638e57e660
commit 4f0a59f581
5 changed files with 120 additions and 126 deletions

View file

@ -55,7 +55,7 @@ edirs += ./source/engine/thirdparty/Chipmunk2D/include ./source/engine/thirdpart
includeflag != $(call prefix,$(edirs) $(eddirs),-I) includeflag != $(call prefix,$(edirs) $(eddirs),-I)
COMPINCLUDE = $(edirs) $(eddirs) COMPINCLUDE = $(edirs) $(eddirs)
WARNING_FLAGS = -Wno-incompatible-function-pointer-types #-Wall -Wwrite-strings -Wunsupported -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic WARNING_FLAGS = -Wno-everything #-Wno-incompatible-function-pointer-types -Wall -Wwrite-strings -Wunsupported -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic
COMPILER_FLAGS = $(includeflag) -I/usr/local/include -g -O0 -MD $(WARNING_FLAGS) -c $< -o $@ COMPILER_FLAGS = $(includeflag) -I/usr/local/include -g -O0 -MD $(WARNING_FLAGS) -c $< -o $@

View file

@ -1,4 +1,4 @@
#include "nuke.h" #include "editor.h"
#include "2dphysics.h" #include "2dphysics.h"
#include "camera.h" #include "camera.h"
@ -6,7 +6,6 @@
#include "datastream.h" #include "datastream.h"
#include "debug.h" #include "debug.h"
#include "debugdraw.h" #include "debugdraw.h"
#include "editor.h"
#include "editorstate.h" #include "editorstate.h"
#include "gameobject.h" #include "gameobject.h"
#include "input.h" #include "input.h"
@ -290,39 +289,39 @@ static void edit_input_cb(GLFWwindow *w, int key, int scancode, int action, int
break; break;
case GLFW_KEY_F2: case GLFW_KEY_F2:
editor.showAssetMenu = !editor.showAssetMenu; NEGATE(editor.assets.show);
break; break;
case GLFW_KEY_F3: case GLFW_KEY_F3:
editor.showStats = !editor.showStats; NEGATE(editor.stats.show);
break; break;
case GLFW_KEY_F4: case GLFW_KEY_F4:
editor.showHierarchy = !editor.showHierarchy; NEGATE(editor.hierarchy.show);
break; break;
case GLFW_KEY_F5: case GLFW_KEY_F5:
editor.showLighting = !editor.showLighting; NEGATE(editor.lighting.show);
break; break;
case GLFW_KEY_F6: case GLFW_KEY_F6:
editor.showGameSettings = !editor.showGameSettings; NEGATE(editor.gamesettings.show);
break; break;
case GLFW_KEY_F7: case GLFW_KEY_F7:
editor.showViewmode = !editor.showViewmode; NEGATE(editor.viewmode.show);
break; break;
case GLFW_KEY_F8: case GLFW_KEY_F8:
editor.showDebugMenu = !editor.showDebugMenu; NEGATE(editor.debug.show);
break; break;
case GLFW_KEY_F9: case GLFW_KEY_F9:
editor.showExport = !editor.showExport; NEGATE(editor.export.show);
break; break;
case GLFW_KEY_F10: case GLFW_KEY_F10:
editor.showLevel = !editor.showLevel; NEGATE(editor.level.show);
break; break;
case GLFW_KEY_F11: case GLFW_KEY_F11:
@ -330,7 +329,7 @@ static void edit_input_cb(GLFWwindow *w, int key, int scancode, int action, int
break; break;
case GLFW_KEY_GRAVE_ACCENT: case GLFW_KEY_GRAVE_ACCENT:
editor.showREPL = !editor.showREPL; NEGATE(editor.repl.show);
break; break;
case GLFW_KEY_K: case GLFW_KEY_K:
@ -390,6 +389,7 @@ static void edit_mouse_cb(GLFWwindow *w, int button, int action, int mods) {
void editor_init(struct mSDLWindow *window) { void editor_init(struct mSDLWindow *window) {
levels = vec_make(MAXNAME, 10); levels = vec_make(MAXNAME, 10);
editor_load_projects(); editor_load_projects();
findPrefabs();
FILE *feditor = fopen(editor_filename, "r"); FILE *feditor = fopen(editor_filename, "r");
if (feditor == NULL) { if (feditor == NULL) {
@ -401,8 +401,11 @@ void editor_init(struct mSDLWindow *window) {
nuke_init(window); nuke_init(window);
window->nuke_gui = editor_render; window->nuke_gui = editor_render;
window_makefullscreen(window);
glfwSetKeyCallback(window->window, edit_input_cb); glfwSetKeyCallback(window->window, edit_input_cb);
glfwSetMouseButtonCallback(window->window, edit_mouse_cb); glfwSetMouseButtonCallback(window->window, edit_mouse_cb);
} }
// TODO: Implement // TODO: Implement
@ -431,35 +434,24 @@ void editor_project_gui() {
static int selected_item = 0; static int selected_item = 0;
static int check = 1; static int check = 1;
int i; /*
if (nk_begin(ctx, "Menu Demo", nk_rect(600, 350, 275, 250), nuk_std)) {
nk_menubar_begin(ctx);
nk_layout_row_dynamic(ctx, 30, 2);
char bbbuf[256];
snprintf(bbbuf, 256, "Current level: %s", current_level[0] == '\0' ? "Level not saved!" : current_level);
nk_label(ctx, bbbuf, NK_TEXT_LEFT);
if (nk_menu_begin_label(ctx, "Windows", NK_TEXT_LEFT, nk_vec2(100, 200))) { if (nk_menu_begin_label(ctx, "Windows", NK_TEXT_LEFT, nk_vec2(100, 200))) {
nk_layout_row_dynamic(ctx, 25, 1); nk_layout_row_dynamic(ctx, 25, 1);
nk_checkbox_label(ctx, "Resources", &editor.showAssetMenu); nk_checkbox_label(ctx, "Resources", &editor.assets.show);
nk_checkbox_label(ctx, "Hierarchy", &editor.showHierarchy); nk_checkbox_label(ctx, "Hierarchy", &editor.hierarchy.show);
nk_checkbox_label(ctx, "Lighting F5", &editor.showLighting); nk_checkbox_label(ctx, "Lighting F5", &editor.lighting.show);
nk_checkbox_label(ctx, "Game Settings F6", &editor.showGameSettings); nk_checkbox_label(ctx, "Game Settings F6", &editor.gamesettings.show);
nk_checkbox_label(ctx, "View F7", &editor.showViewmode); nk_checkbox_label(ctx, "View F7", &editor.viewmode.show);
nk_checkbox_label(ctx, "Debug F8", &editor.showDebugMenu); nk_checkbox_label(ctx, "Debug F8", &editor.debug.show);
nk_checkbox_label(ctx, "Export F9", &editor.showExport); nk_checkbox_label(ctx, "Export F9", &editor.export.show);
nk_checkbox_label(ctx, "Level F10", &editor.showLevel); nk_checkbox_label(ctx, "Level F10", &editor.level.show);
nk_checkbox_label(ctx, "REPL", &editor.showREPL); nk_checkbox_label(ctx, "REPL", &editor.repl.show);
nk_menu_end(ctx); nk_menu_end(ctx);
} }
*/
if (nk_menu_begin_label(ctx, "Levels", NK_TEXT_LEFT, nk_vec2(100, 50))) { NK_MENU_START(level)
nk_layout_row_dynamic(ctx,25,3); nk_layout_row_dynamic(ctx,25,3);
if (nk_button_label(ctx, "New")) { if (nk_button_label(ctx, "New")) {
new_level(); new_level();
@ -478,18 +470,15 @@ void editor_project_gui() {
get_levels(); get_levels();
} }
nk_edit_string_zero_terminated(ctx, NK_EDIT_SIMPLE, levelname, nk_edit_string_zero_terminated(ctx, NK_EDIT_SIMPLE, levelname, MAXNAME - 1, nk_filter_default);
MAXNAME - 1, nk_filter_default);
vec_walk(levels, (void (*)(void *)) & editor_level_btn); nk_layout_row_dynamic(ctx,25,1);
} vec_walk(levels, editor_level_btn);
NK_MENU_END()
nk_menubar_end(ctx); if (editor.export.show) {
} nk_begin(ctx, "Export and Bake", editor.export.rect, nuk_std);
nk_end(ctx);
if (editor.showExport) {
nk_begin(ctx, "Export and Bake", nk_rect_std, nuk_std);
nk_layout_row_dynamic(ctx, 25,2); nk_layout_row_dynamic(ctx, 25,2);
if (nk_button_label(ctx, "Bake")) { if (nk_button_label(ctx, "Bake")) {
} }
@ -500,23 +489,19 @@ void editor_project_gui() {
} }
// Shadow map vars // Shadow map vars
if (editor.showLighting) { NK_MENU_START(lighting)
if (nk_begin(ctx, "Lighting options", nk_rect_std, nuk_std)) {
nk_layout_row_dynamic(ctx, 25, 1); nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, "Directional shadow map", NK_TEXT_LEFT); nk_label(ctx, "Directional shadow map", NK_TEXT_LEFT);
nk_property_float(ctx, "Near plane", -200.f, &near_plane, 200.f, 1.f, nk_property_float(ctx, "Near plane", -200.f, &near_plane, 200.f, 1.f, 0.01f);
0.01f);
nk_property_float(ctx, "Far plane", -200.f, &far_plane, 200.f, 1.f, 0.01f); nk_property_float(ctx, "Far plane", -200.f, &far_plane, 200.f, 1.f, 0.01f);
nk_property_float(ctx, "Shadow lookahead", 0.f, &shadowLookahead, 100.f, nk_property_float(ctx, "Shadow lookahead", 0.f, &shadowLookahead, 100.f, 1.f, 0.01f);
1.f, 0.01f);
nk_property_float(ctx, "Plane size", 0.f, &plane_size, 100.f, 1.f, 0.01f); nk_property_float(ctx, "Plane size", 0.f, &plane_size, 100.f, 1.f, 0.01f);
}
nk_end(ctx);
}
if (editor.showGameSettings) { NK_MENU_END()
nk_begin(ctx, "Game settings", nk_rect_std, nuk_std);
NK_MENU_START(gamesettings)
nk_layout_row_dynamic(ctx,25,1); nk_layout_row_dynamic(ctx,25,1);
// nk_edit_string_zero_terminated(ctx, NK_EDIT_SIMPLE, cur_project->name, // nk_edit_string_zero_terminated(ctx, NK_EDIT_SIMPLE, cur_project->name,
@ -532,18 +517,15 @@ void editor_project_gui() {
if (nk_tree_push(ctx, NK_TREE_NODE, "Quality", NK_MINIMIZED)) { if (nk_tree_push(ctx, NK_TREE_NODE, "Quality", NK_MINIMIZED)) {
nk_tree_pop(ctx); nk_tree_pop(ctx);
} }
nk_end(ctx);
}
if (editor.showStats) { NK_MENU_END()
nk_begin(ctx, "Stats", nk_rect_std, nuk_std);
NK_MENU_START(stats)
nk_labelf(ctx, NK_TEXT_LEFT, "FPS: %2.4f", 1.f / deltaT); nk_labelf(ctx, NK_TEXT_LEFT, "FPS: %2.4f", 1.f / deltaT);
nk_labelf(ctx, NK_TEXT_LEFT, "Triangles rendered: %llu", triCount); nk_labelf(ctx, NK_TEXT_LEFT, "Triangles rendered: %llu", triCount);
nk_end(ctx); NK_MENU_END()
}
if (editor.showREPL) { NK_MENU_START(repl)
nk_begin(ctx, "REPL", nk_rect_std, nuk_std);
nk_layout_row_dynamic(ctx, 300, 1); nk_layout_row_dynamic(ctx, 300, 1);
@ -557,19 +539,15 @@ void editor_project_gui() {
buffer[0] = '\0'; buffer[0] = '\0';
} }
nk_end(ctx); NK_MENU_END()
}
if (editor.showViewmode) { NK_MENU_START(debug)
nk_begin(ctx, "View options", nk_rect_std, nuk_std);
nk_layout_row_dynamic(ctx, 25, 1); nk_layout_row_dynamic(ctx, 25, 1);
nk_property_float(ctx, "Camera FOV", 0.1f, &editorFOV, 90.f, 1.f, 0.1f); nk_property_float(ctx, "Camera FOV", 0.1f, &editorFOV, 90.f, 1.f, 0.1f);
nk_property_float(ctx, "Camera Near Plane", 0.1f, &editorClose, 5.f, 0.1f, nk_property_float(ctx, "Camera Near Plane", 0.1f, &editorClose, 5.f, 0.1f, 0.01f);
0.01f); nk_property_float(ctx, "Camera Far Plane", 50.f, &editorFar, 10000.f, 1.f,1.f);
nk_property_float(ctx, "Camera Far Plane", 50.f, &editorFar, 10000.f, 1.f,
1.f);
if (nk_tree_push(ctx, NK_TREE_NODE, "Shading mode", NK_MINIMIZED)) { if (nk_tree_push(ctx, NK_TREE_NODE, "Shading mode", NK_MINIMIZED)) {
renderMode = renderMode =
@ -600,11 +578,10 @@ void editor_project_gui() {
nk_tree_pop(ctx); nk_tree_pop(ctx);
} }
nk_end(ctx); NK_MENU_END()
}
if (editor.showHierarchy) { NK_MENU_START(hierarchy)
nk_begin(ctx, "Objects", nk_rect_std, nuk_std); nk_layout_row_dynamic(ctx, 25, 1);
if (nk_button_label(ctx, "New Object")) { if (nk_button_label(ctx, "New Object")) {
MakeGameobject(); MakeGameobject();
@ -612,8 +589,7 @@ void editor_project_gui() {
obj_gui_hierarchy(selectedobject); obj_gui_hierarchy(selectedobject);
nk_end(ctx); NK_MENU_END()
}
if (nk_begin(ctx, "Simulate", nk_rect_std, nuk_std)) { if (nk_begin(ctx, "Simulate", nk_rect_std, nuk_std)) {
@ -635,16 +611,13 @@ void editor_project_gui() {
if (nk_begin(ctx, "Prefab Creator", nk_rect_std, nuk_std)) { if (nk_begin(ctx, "Prefab Creator", nk_rect_std, nuk_std)) {
nk_layout_row_dynamic(ctx, 25, 1); nk_layout_row_dynamic(ctx, 25, 1);
vec_walk(prefabs, (void (*)(void *)) & editor_prefab_btn); vec_walk(prefabs, editor_prefab_btn);
nk_end(ctx); nk_end(ctx);
} }
if (editor.showAssetMenu) { NK_MENU_START(assets)
nk_begin(ctx, "Asset Menu", nk_rect_std, nuk_std);
nk_layout_row_dynamic(ctx,25,1); nk_layout_row_dynamic(ctx,25,1);
nk_edit_string_zero_terminated(ctx, nk_edit_string_zero_terminated(ctx, NK_EDIT_SIMPLE, asset_search_buffer, 100, nk_filter_ascii);
NK_EDIT_BOX | NK_EDIT_NO_HORIZONTAL_SCROLL,
asset_search_buffer, 100, nk_filter_ascii);
/* /*
if (data->EventFlag == ImGuiInputTextFlags_CallbackCompletion) { if (data->EventFlag == ImGuiInputTextFlags_CallbackCompletion) {
@ -687,14 +660,12 @@ NULL) ? false : true;
} }
nk_group_end(ctx); nk_group_end(ctx);
nk_end(ctx); NK_MENU_END()
}
if (selected_asset) if (selected_asset)
editor_asset_gui(selected_asset); editor_asset_gui(selected_asset);
if (editor.showDebugMenu) { NK_MENU_START(debug)
nk_begin(ctx, "Debug Menu", nk_rect_std, nuk_std);
if (nk_button_label(ctx, "Reload Shaders")) { if (nk_button_label(ctx, "Reload Shaders")) {
shader_compile_all(); shader_compile_all();
@ -706,14 +677,11 @@ NULL) ? false : true;
nk_property_int(ctx, "Grid 2 Span", 10, &grid2_span, 1000, 1, 1); nk_property_int(ctx, "Grid 2 Span", 10, &grid2_span, 1000, 1, 1);
nk_checkbox_label(ctx, "Draw", &grid2_draw); nk_checkbox_label(ctx, "Draw", &grid2_draw);
nk_property_float(ctx, "Grid Opacity", 0.f, &gridOpacity, 1.f, 0.01f, nk_property_float(ctx, "Grid Opacity", 0.f, &gridOpacity, 1.f, 0.01f, 0.01f);
0.01f);
nk_property_float(ctx, "Small unit", 0.5f, &smallGridUnit, 5.f, 0.1f, 0.1f); nk_property_float(ctx, "Small unit", 0.5f, &smallGridUnit, 5.f, 0.1f, 0.1f);
nk_property_float(ctx, "Big unit", 10.f, &bigGridUnit, 50.f, 1.f, 0.1f); nk_property_float(ctx, "Big unit", 10.f, &bigGridUnit, 50.f, 1.f, 0.1f);
nk_property_float(ctx, "Small thickness", 1.f, &gridSmallThickness, 10.f, nk_property_float(ctx, "Small thickness", 1.f, &gridSmallThickness, 10.f, 0.1f, 0.1f);
0.1f, 0.1f); nk_property_float(ctx, "Big thickness", 1.f, &gridBigThickness, 10.f, 0.1f, 0.1f);
nk_property_float(ctx, "Big thickness", 1.f, &gridBigThickness, 10.f, 0.1f,
0.1f);
static struct nk_colorf smgrd; static struct nk_colorf smgrd;
static struct nk_colorf lgrd; static struct nk_colorf lgrd;
@ -721,8 +689,7 @@ NULL) ? false : true;
nk_color_pick(ctx, &smgrd, NK_RGBA); nk_color_pick(ctx, &smgrd, NK_RGBA);
nk_color_pick(ctx, &lgrd, NK_RGBA); nk_color_pick(ctx, &lgrd, NK_RGBA);
nk_end(ctx); NK_MENU_END()
}
startobjectgui: startobjectgui:
@ -730,7 +697,7 @@ startobjectgui:
draw_point(selectedobject->transform.position[0], draw_point(selectedobject->transform.position[0],
selectedobject->transform.position[1], 5); selectedobject->transform.position[1], 5);
nk_begin(ctx, "Object Parameters", nk_rect_std, nuk_std); NK_FORCE(gameobject)
nk_layout_row_dynamic(ctx, 30, 3); nk_layout_row_dynamic(ctx, 30, 3);
@ -744,34 +711,28 @@ startobjectgui:
goto startobjectgui; goto startobjectgui;
} }
if (selectedobject->editor.prefabSync) { if (selectedobject->editor.prefabSync && nk_button_label(ctx, "Revert"))
if (nk_button_label(ctx, "Revert"))
gameobject_revertprefab(selectedobject); gameobject_revertprefab(selectedobject);
}
nk_label(ctx, "Name", NK_TEXT_LEFT); nk_label(ctx, "Name", NK_TEXT_LEFT);
nk_edit_string_zero_terminated(ctx, 0, selectedobject->editor.mname, 50, nk_edit_string_zero_terminated(ctx, NK_EDIT_SIMPLE, selectedobject->editor.mname, 50, nk_filter_ascii);
nk_filter_ascii);
nk_label(ctx, "Prefab", NK_TEXT_LEFT); nk_label(ctx, "Prefab", NK_TEXT_LEFT);
nk_edit_string_zero_terminated(ctx, 0, selectedobject->editor.prefabName, nk_edit_string_zero_terminated(ctx, NK_EDIT_SIMPLE, selectedobject->editor.prefabName, 50, nk_filter_ascii);
50, nk_filter_ascii);
// Disabled if::::: selectedobject->editor.prefabSync ?
// ImGuiInputTextFlags_ReadOnly : 0);
object_gui(selectedobject); object_gui(selectedobject);
nk_end(ctx); NK_FORCE_END()
nk_begin(ctx, "Components", nk_rect_std, nuk_std);
NK_FORCE(components)
nk_layout_row_dynamic(ctx,25,1);
for (int i = 0; i < ncomponent; i++) { for (int i = 0; i < ncomponent; i++) {
if (nk_button_label(ctx, components[i].name)) { if (nk_button_label(ctx, components[i].name)) {
gameobject_addcomponent(selectedobject, &components[i]); gameobject_addcomponent(selectedobject, &components[i]);
} }
} }
nk_end(ctx); NK_FORCE_END()
} }
} }

View file

@ -5,6 +5,8 @@
#include <stdbool.h> #include <stdbool.h>
#include "resources.h" #include "resources.h"
#include "nuke.h"
#define ASSET_TYPE_NULL 0 #define ASSET_TYPE_NULL 0
#define ASSET_TYPE_IMAGE 1 #define ASSET_TYPE_IMAGE 1
#define ASSET_TYPE_TEXT 2 #define ASSET_TYPE_TEXT 2
@ -18,19 +20,43 @@ struct fileasset {
void *data; void *data;
}; };
typedef struct {
bool show;
struct nk_rect rect;
} editor_win;
struct editorVars { struct editorVars {
bool showStats; editor_win stats;
bool showHierarchy; editor_win hierarchy;
bool showLighting; editor_win lighting;
bool showGameSettings; editor_win gamesettings;
bool showViewmode; editor_win viewmode;
bool showDebugMenu; editor_win debug;
bool showAssetMenu; editor_win assets;
bool showREPL; editor_win repl;
bool showExport; editor_win export;
bool showLevel; editor_win level;
editor_win gameobject;
editor_win components;
}; };
struct mGameObject;
#define NK_MENU_START(VAR) if (editor.VAR.show) { \
if (editor.VAR.rect.w == 0) editor.VAR.rect = nk_rect_std; \
if (nk_begin(ctx, #VAR, editor.VAR.rect, nuk_std)) { \
editor.VAR.rect = nk_window_get_bounds(ctx);
#define NK_MENU_END() } nk_end(ctx); }
#define NK_FORCE(VAR) if (editor.VAR.rect.w == 0) editor.VAR.rect = nk_rect_std; \
if (nk_begin(ctx, #VAR, editor.VAR.rect, nuk_std)) { \
editor.VAR.rect = nk_window_get_bounds(ctx);
#define NK_FORCE_END() } nk_end(ctx);
#define NEGATE(VAR) VAR = ! VAR
struct vec; struct vec;
struct gameproject; struct gameproject;
struct mSprite; struct mSprite;

View file

@ -102,7 +102,7 @@ void gameobject_saveprefab(struct mGameObject *go)
{ {
char prefabfname[60] = { '\0' }; char prefabfname[60] = { '\0' };
strncat(prefabfname, go->editor.prefabName, MAXNAME); strncat(prefabfname, go->editor.prefabName, MAXNAME);
strncat(prefabfname, ".yugh", 10); strncat(prefabfname, EXT_PREFAB, 10);
FILE *pfile = fopen(prefabfname, "w+"); FILE *pfile = fopen(prefabfname, "w+");
gameobject_save(go, pfile); gameobject_save(go, pfile);
fclose(pfile); fclose(pfile);

View file

@ -34,6 +34,13 @@ int main(int argc, char **args) {
engine_init(); engine_init();
const GLFWvidmode *vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
printf("Refresh rate is %d\n", vidmode->refreshRate);
renderMS = 1.0/vidmode->refreshRate;
double framet = fmin(fmin(renderMS,physMS),updateMS);
script_dofile("engine.rb"); script_dofile("engine.rb");
script_dofile("config.rb"); script_dofile("config.rb");
@ -56,16 +63,16 @@ int main(int argc, char **args) {
elapsed = glfwGetTime() - lastTick; elapsed = glfwGetTime() - lastTick;
lastTick = glfwGetTime(); lastTick = glfwGetTime();
renderlag += elapsed; //renderlag += elapsed;
physlag += elapsed; //physlag += elapsed;
if (renderlag >= renderMS) { if (renderlag >= renderMS) {
renderlag -= renderMS; renderlag -= renderMS;
window_renderall();
} }
input_poll(updateMS - elapsed < 0 ? 0 : updateMS - elapsed); window_renderall();
input_poll(renderMS- elapsed < 0 ? 0 : renderMS - elapsed);
window_all_handle_events(); window_all_handle_events();