This commit is contained in:
John Alanbrook 2022-08-12 19:03:56 +00:00
parent 406b2b491f
commit b0d2757f70
29 changed files with 519 additions and 442 deletions

View file

@ -96,6 +96,12 @@ engine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE)
$(CLINK) $< $(LINK) $(CLINK) $< $(LINK)
@echo Finished build @echo Finished build
bs: engine
cp engine brainstorm
ed: engine
cp engine editor
$(ENGINE): $(eobjects) bin/libglfw3.a $(ENGINE): $(eobjects) bin/libglfw3.a
@echo Making library engine.a @echo Making library engine.a
@ar r $(ENGINE) $(eobjects) @ar r $(ENGINE) $(eobjects)

0
editor/camera.rb Normal file
View file

View file

@ -0,0 +1,10 @@
window = win_make("editor")
nuke_cb(window, :editor)
def editor
editor_render()
end
def update(dt)
end

View file

@ -3,6 +3,7 @@
#include "gameobject.h" #include "gameobject.h"
#include <string.h> #include <string.h>
#include "mathc.h" #include "mathc.h"
#include "nuke.h"
cpBody *ballBody = NULL; cpBody *ballBody = NULL;
cpSpace *space = NULL; cpSpace *space = NULL;
@ -58,6 +59,14 @@ void phys2d_circleinit(struct phys2d_circle *circle,
init_phys2dshape(&circle->shape, go); init_phys2dshape(&circle->shape, go);
} }
void circle_gui(struct phys2d_circle *circle)
{
nk_property_float(ctx, "Radius", 1.f, &circle->radius, 10000.f, 1.f, 1.f);
nk_property_float2(ctx, "Offset", 0.f, circle->offset, 1.f, 0.01f, 0.01f);
phys2d_applycircle(circle);
}
struct phys2d_segment *Make2DSegment(struct mGameObject *go) struct phys2d_segment *Make2DSegment(struct mGameObject *go)
{ {
struct phys2d_segment *new = malloc(sizeof(struct phys2d_segment)); struct phys2d_segment *new = malloc(sizeof(struct phys2d_segment));
@ -81,6 +90,14 @@ void phys2d_seginit(struct phys2d_segment *seg, struct mGameObject *go)
init_phys2dshape(&seg->shape, go); init_phys2dshape(&seg->shape, go);
} }
void segment_gui(struct phys2d_segment *seg)
{
nk_property_float2(ctx, "a", 0.f, seg->a, 1.f, 0.01f, 0.01f);
nk_property_float2(ctx, "b", 0.f, seg->b, 1.f, 0.01f, 0.01f);
phys2d_applyseg(seg);
}
struct phys2d_box *Make2DBox(struct mGameObject *go) struct phys2d_box *Make2DBox(struct mGameObject *go)
{ {
struct phys2d_box *new = malloc(sizeof(struct phys2d_box)); struct phys2d_box *new = malloc(sizeof(struct phys2d_box));
@ -105,6 +122,17 @@ void phys2d_boxinit(struct phys2d_box *box, struct mGameObject *go)
phys2d_applybox(box); phys2d_applybox(box);
} }
void box_gui(struct phys2d_box *box)
{
nk_property_float(ctx, "Width", 0.f, &box->w, 1000.f, 1.f, 1.f);
nk_property_float(ctx, "Height", 0.f, &box->h, 1000.f, 1.f, 1.f);
nk_property_float2(ctx, "Offset", 0.f, &box->offset, 1.f, 0.01f, 0.01f);
nk_property_float(ctx, "Radius", 0.f, &box->r, 100.f, 1.f, 0.1f);
phys2d_applybox(box);
}
struct phys2d_poly *Make2DPoly(struct mGameObject *go) struct phys2d_poly *Make2DPoly(struct mGameObject *go)
{ {
struct phys2d_poly *new = malloc(sizeof(struct phys2d_poly)); struct phys2d_poly *new = malloc(sizeof(struct phys2d_poly));
@ -138,6 +166,20 @@ void phys2d_polyaddvert(struct phys2d_poly *poly)
free(oldpoints); free(oldpoints);
} }
void poly_gui(struct phys2d_poly *poly)
{
if (nk_button_label(ctx, "Add Poly Vertex")) phys2d_polyaddvert(poly);
for (int i = 0; i < poly->n; i++) {
nk_property_float2(ctx, "#P", 0.f, &poly->points[i*2], 1.f, 0.1f, 0.1f);
}
nk_property_float(ctx, "Radius", 0.01f, &poly->radius, 1000.f, 1.f, 0.1f);
phys2d_applypoly(poly);
}
struct phys2d_edge *Make2DEdge(struct mGameObject *go) struct phys2d_edge *Make2DEdge(struct mGameObject *go)
{ {
struct phys2d_edge *new = malloc(sizeof(struct phys2d_edge)); struct phys2d_edge *new = malloc(sizeof(struct phys2d_edge));
@ -198,6 +240,21 @@ void phys2d_edgeaddvert(struct phys2d_edge *edge)
free(oldshapes); free(oldshapes);
} }
void edge_gui(struct phys2d_edge *edge)
{
if (nk_button_label(ctx, "Add Edge Vertex")) phys2d_edgeaddvert(edge);
for (int i = 0; i < edge->n; i++) {
//ImGui::PushID(i);
nk_property_float2(ctx, "E", 0.f, &edge->points[i*2], 1.f, 0.01f, 0.01f);
//ImGui::PopID();
}
nk_property_float(ctx, "Thickness", 0.01f, &edge->thickness, 1.f, 0.01f, 0.01f);
phys2d_applyedge(edge);
}
#include "debugdraw.h" #include "debugdraw.h"
#include "gameobject.h" #include "gameobject.h"
#include <math.h> #include <math.h>

View file

@ -57,22 +57,26 @@ void phys2d_circleinit(struct phys2d_circle *circle,
struct mGameObject *go); struct mGameObject *go);
void phys2d_applycircle(struct phys2d_circle *circle); void phys2d_applycircle(struct phys2d_circle *circle);
void phys2d_dbgdrawcircle(struct phys2d_circle *circle); void phys2d_dbgdrawcircle(struct phys2d_circle *circle);
void circle_gui(struct phys2d_circle *circle);
struct phys2d_segment *Make2DSegment(struct mGameObject *go); struct phys2d_segment *Make2DSegment(struct mGameObject *go);
void phys2d_seginit(struct phys2d_segment *seg, struct mGameObject *go); void phys2d_seginit(struct phys2d_segment *seg, struct mGameObject *go);
void phys2d_applyseg(struct phys2d_segment *seg); void phys2d_applyseg(struct phys2d_segment *seg);
void phys2d_dbgdrawseg(struct phys2d_segment *seg); void phys2d_dbgdrawseg(struct phys2d_segment *seg);
void segment_gui(struct phys2d_segment *seg);
struct phys2d_box *Make2DBox(struct mGameObject *go); struct phys2d_box *Make2DBox(struct mGameObject *go);
void phys2d_boxinit(struct phys2d_box *box, struct mGameObject *go); void phys2d_boxinit(struct phys2d_box *box, struct mGameObject *go);
void phys2d_applybox(struct phys2d_box *box); void phys2d_applybox(struct phys2d_box *box);
void phys2d_dbgdrawbox(struct phys2d_box *box); void phys2d_dbgdrawbox(struct phys2d_box *box);
void box_gui(struct phys2d_box *box);
struct phys2d_poly *Make2DPoly(struct mGameObject *go); struct phys2d_poly *Make2DPoly(struct mGameObject *go);
void phys2d_polyinit(struct phys2d_poly *poly, struct mGameObject *go); void phys2d_polyinit(struct phys2d_poly *poly, struct mGameObject *go);
void phys2d_applypoly(struct phys2d_poly *poly); void phys2d_applypoly(struct phys2d_poly *poly);
void phys2d_dbgdrawpoly(struct phys2d_poly *poly); void phys2d_dbgdrawpoly(struct phys2d_poly *poly);
void phys2d_polyaddvert(struct phys2d_poly *poly); void phys2d_polyaddvert(struct phys2d_poly *poly);
void poly_gui(struct phys2d_poly *poly);
struct phys2d_edge *Make2DEdge(struct mGameObject *go); struct phys2d_edge *Make2DEdge(struct mGameObject *go);
void phys2d_edgeinit(struct phys2d_edge *edge, struct mGameObject *go); void phys2d_edgeinit(struct phys2d_edge *edge, struct mGameObject *go);
@ -80,11 +84,13 @@ void phys2d_applyedge(struct phys2d_edge *edge);
void phys2d_edgeshapeapply(struct phys2d_shape *mshape, cpShape * shape); void phys2d_edgeshapeapply(struct phys2d_shape *mshape, cpShape * shape);
void phys2d_dbgdrawedge(struct phys2d_edge *edge); void phys2d_dbgdrawedge(struct phys2d_edge *edge);
void phys2d_edgeaddvert(struct phys2d_edge *edge); void phys2d_edgeaddvert(struct phys2d_edge *edge);
void edge_gui(struct phys2d_edge *edge);
void phys2d_init(); void phys2d_init();
void phys2d_update(float deltaT); void phys2d_update(float deltaT);
void phys2d_apply(); void phys2d_apply();
void shape_gui(struct phys2d_shape *shape);
#endif #endif

View file

@ -45,8 +45,6 @@ static char setpath[MAXPATH];
// TODO: Pack this into a bitfield // TODO: Pack this into a bitfield
static struct editorVars editor = { 0 }; static struct editorVars editor = { 0 };
bool flashlightOn = false;
// Lighting effect flags // Lighting effect flags
static bool renderAO = true; static bool renderAO = true;
static bool renderDynamicShadows = true; static bool renderDynamicShadows = true;
@ -60,8 +58,6 @@ const char *allowed_extensions[] = { "jpg", "png", "gltf", "glsl" };
static const char *editor_filename = "editor.ini"; static const char *editor_filename = "editor.ini";
//static ImGuiIO *io = NULL;
struct asset { struct asset {
char *key; char *key;
struct fileasset *value; struct fileasset *value;
@ -426,10 +422,8 @@ void editor_init(struct mSDLWindow *window)
glfwSetMouseButtonCallback(window->window, edit_mouse_cb); glfwSetMouseButtonCallback(window->window, edit_mouse_cb);
} }
void editor_input()
{
}
// TODO: Implement
int editor_wantkeyboard() int editor_wantkeyboard()
{ {
return 0; return 0;
@ -835,19 +829,10 @@ nk_end(ctx);
void editor_render() void editor_render()
{ {
nuke_start();
struct nk_colorf bg;
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
if (cur_project) if (cur_project)
editor_project_gui(); editor_project_gui();
else else
editor_proj_select_gui(); editor_proj_select_gui();
editor_project_gui();
nuke_end();
} }
@ -1140,277 +1125,6 @@ void editor_import_project(char *path)
vec_add(projects, gp); vec_add(projects, gp);
} }
/////// Object GUIs
#include "light.h"
#include "transform.h"
#include "static_actor.h"
/*
void light_gui(struct mLight *light)
{
object_gui(&light->obj);
if (nk_tree_push(ctx, NK_TREE_NODE, "Light", NK_MINIMIZED)) {
nk_property_float(ctx, "Strength", 0.f, &light->strength, 1.f, 0.01f, 0.001f);
// ImGui::ColorEdit3("Color", &light->color[0]);
nk_checkbox_label(ctx, "Dynamic", (bool *) &light->dynamic);
nk_tree_pop(ctx);
}
}
void pointlight_gui(struct mPointLight *light)
{
light_gui(&light->light);
if (nk_tree_push(ctx, NK_TREE_NODE, "Point Light", NK_MINIMIZED)) {
nk_property_float(ctx, "Constant", 0.f, &light->constant, 1.f, 0.01f, 0.001f);
nk_property_float(ctx, "Linear", 0.f, &light->linear, 0.3f, 0.01f, 0.001f);
nk_property_float(ctx, "Quadratic", 0.f, &light->quadratic, 0.3f, 0.01f, 0.001f);
nk_tree_pop(ctx);
}
}
void spotlight_gui(struct mSpotLight *spot)
{
light_gui(&spot->light);
if (nk_tree_push(ctx, NK_TREE_NODE, "Spotlight", NK_MINIMIZED)) {
nk_property_float(ctx, "Linear", 0.f, &spot->linear, 1.f, 0.01f, 0.001f);
nk_property_float(ctx, "Quadratic", 0.f, &spot->quadratic, 1.f, 0.01f, 0.001f);
nk_property_float(ctx, "Distance", 0.f, &spot->distance, 200.f, 1.f, 0.1f, 200.f);
nk_property_float(ctx, "Cutoff Degrees", 0.f, &spot->cutoff, 0.7f, 0.01f, 0.001f);
nk_property_float(ctx, "Outer Cutoff Degrees", 0.f, &spot->outerCutoff, 0.7f, 0.01f, 0.001f);
nk_tree_pop(ctx);
}
}
*/
void staticactor_gui(struct mStaticActor *sa)
{
object_gui(&sa->obj);
if (nk_tree_push(ctx, NK_TREE_NODE, "Model", NK_MINIMIZED)) {
nk_checkbox_label(ctx, "Cast Shadows", &sa->castShadows);
nk_labelf(ctx, NK_TEXT_LEFT, "Model path: %s", sa->currentModelPath);
//ImGui::SameLine();
if (nk_button_label(ctx, "Load model")) {
//asset_command = set_new_model;
curActor = sa;
}
}
}
void nk_property_float3(struct nk_context *ctx, const char *label, float min, float *val, float max, float step, float dragstep) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, label, NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 3);
nk_property_float(ctx, "X", min, &val[0], max, step, dragstep);
nk_property_float(ctx, "Y", min, &val[1], max, step, dragstep);
nk_property_float(ctx, "Z", min, &val[2], max, step, dragstep);
}
void nk_property_float2(struct nk_context *ctx, const char *label, float min, float *val, float max, float step, float dragstep) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, label, NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 2);
nk_property_float(ctx, "X", min, &val[0], max, step, dragstep);
nk_property_float(ctx, "Y", min, &val[1], max, step, dragstep);
}
void trans_drawgui(struct mTransform *T)
{
nk_property_float3(ctx, "Position", -1000.f, T->position, 1000.f, 1.f, 1.f);
nk_property_float3(ctx, "Rotation", 0.f, T->rotation, 360.f, 1.f, 0.1f);
nk_property_float(ctx, "Scale", 0.f, &T->scale, 1000.f, 0.1f, 0.1f);
}
void nk_radio_button_label(struct nk_contex *ctx, const char *label, int *val, int cmp) {
if (nk_option_label(ctx, label, (bool)*val == cmp)) *val = cmp;
}
void object_gui(struct mGameObject *go)
{
float temp_pos[2];
temp_pos[0] = cpBodyGetPosition(go->body).x;
temp_pos[1] = cpBodyGetPosition(go->body).y;
draw_point(temp_pos[0], temp_pos[1], 3);
nk_property_float2(ctx, "Position", 0.f, temp_pos, 1.f, 0.01f, 0.01f);
cpVect tvect = { temp_pos[0], temp_pos[1] };
cpBodySetPosition(go->body, tvect);
float mtry = cpBodyGetAngle(go->body);
float modtry = fmodf(mtry * RAD2DEGS, 360.f);
float modtry2 = modtry;
nk_property_float(ctx, "Angle", -1000.f, &modtry, 1000.f, 0.5f, 0.5f);
modtry -= modtry2;
cpBodySetAngle(go->body, mtry + (modtry * DEG2RADS));
nk_property_float(ctx, "Scale", 0.f, &go->scale, 1000.f, 0.01f, 0.001f);
nk_layout_row_dynamic(ctx, 25, 4);
if (nk_button_label(ctx, "Start")) {
}
if (nk_button_label(ctx, "Update")) {
}
if (nk_button_label(ctx, "Fixed Update")) {
}
if (nk_button_label(ctx, "End")) {
}
nk_layout_row_dynamic(ctx, 25, 3);
nk_radio_button_label(ctx, "Static", &go->bodytype, CP_BODY_TYPE_STATIC);
nk_radio_button_label(ctx, "Dynamic", &go->bodytype, CP_BODY_TYPE_DYNAMIC);
nk_radio_button_label(ctx, "Kinematic", &go->bodytype, CP_BODY_TYPE_KINEMATIC);
cpBodySetType(go->body, go->bodytype);
if (go->bodytype == CP_BODY_TYPE_DYNAMIC) {
nk_property_float(ctx, "Mass", 0.01f, &go->mass, 1000.f, 0.01f, 0.01f);
cpBodySetMass(go->body, go->mass);
}
nk_property_float(ctx, "Friction", 0.f, &go->f, 10.f, 0.01f, 0.01f);
nk_property_float(ctx, "Elasticity", 0.f, &go->e, 2.f, 0.01f, 0.01f);
int n = -1;
for (int i = 0; i < go->components->len; i++) {
//ImGui::PushID(i);
struct component *c =
(struct component *) vec_get(go->components, i);
if (c->draw_debug)
c->draw_debug(c->data);
if (nk_tree_push(ctx, NK_TREE_NODE, c->name, NK_MINIMIZED)) {
if (nk_button_label(ctx, "Del")) {
n = i;
}
c->draw_gui(c->data);
nk_tree_pop(ctx);
}
//ImGui::PopID();
}
if (n >= 0)
gameobject_delcomponent(go, n);
}
void sprite_gui(struct mSprite *sprite)
{
nk_labelf(ctx, NK_TEXT_LEFT, "Path %s", sprite->tex->path);
//ImGui::SameLine();
if (nk_button_label(ctx, "Load texture") && selected_asset != NULL) {
sprite_loadtex(sprite, selected_asset->filename);
}
if (sprite->tex != NULL) {
nk_labelf(ctx, NK_TEXT_LEFT, "%s", sprite->tex->path);
nk_labelf(ctx, NK_TEXT_LEFT, "%dx%d", sprite->tex->width, sprite->tex->height);
if (nk_button_label(ctx, "Imgbutton")) editor_selectasset_str(sprite->tex->path);
// if (ImGui::ImageButton ((void *) (intptr_t) sprite->tex->id, ImVec2(50, 50))) {
}
nk_property_float2(ctx, "Sprite Position", -1.f, sprite->pos, 0.f, 0.01f, 0.01f);
nk_layout_row_dynamic(ctx, 25, 3);
if (nk_button_label(ctx, "C")) {
sprite->pos[0] = -0.5f;
sprite->pos[1] = -0.5f;
}
if (nk_button_label(ctx, "U")) {
sprite->pos[0] = -0.5f;
sprite->pos[1] = -1.f;
}
if (nk_button_label(ctx, "D")) {
sprite->pos[0] = -0.5f;
sprite->pos[1] = 0.f;
}
}
void circle_gui(struct phys2d_circle *circle)
{
nk_property_float(ctx, "Radius", 1.f, &circle->radius, 10000.f, 1.f, 1.f);
nk_property_float2(ctx, "Offset", 0.f, circle->offset, 1.f, 0.01f, 0.01f);
phys2d_applycircle(circle);
}
void segment_gui(struct phys2d_segment *seg)
{
nk_property_float2(ctx, "a", 0.f, seg->a, 1.f, 0.01f, 0.01f);
nk_property_float2(ctx, "b", 0.f, seg->b, 1.f, 0.01f, 0.01f);
phys2d_applyseg(seg);
}
void box_gui(struct phys2d_box *box)
{
nk_property_float(ctx, "Width", 0.f, &box->w, 1000.f, 1.f, 1.f);
nk_property_float(ctx, "Height", 0.f, &box->h, 1000.f, 1.f, 1.f);
nk_property_float2(ctx, "Offset", 0.f, &box->offset, 1.f, 0.01f, 0.01f);
nk_property_float(ctx, "Radius", 0.f, &box->r, 100.f, 1.f, 0.1f);
phys2d_applybox(box);
}
void poly_gui(struct phys2d_poly *poly)
{
if (nk_button_label(ctx, "Add Poly Vertex")) phys2d_polyaddvert(poly);
for (int i = 0; i < poly->n; i++) {
//ImGui::PushID(i);
nk_property_float2(ctx, "P", 0.f, &poly->points[i*2], 1.f, 0.1f, 0.1f);
//ImGui::PopID();
}
nk_property_float(ctx, "Radius", 0.01f, &poly->radius, 1000.f, 1.f, 0.1f);
phys2d_applypoly(poly);
}
void edge_gui(struct phys2d_edge *edge)
{
if (nk_button_label(ctx, "Add Edge Vertex")) phys2d_edgeaddvert(edge);
for (int i = 0; i < edge->n; i++) {
//ImGui::PushID(i);
nk_property_float2(ctx, "E", 0.f, &edge->points[i*2], 1.f, 0.01f, 0.01f);
//ImGui::PopID();
}
nk_property_float(ctx, "Thickness", 0.01f, &edge->thickness, 1.f, 0.01f, 0.01f);
phys2d_applyedge(edge);
}
void editor_makenewobject() void editor_makenewobject()
{ {
@ -1466,3 +1180,43 @@ void game_pause()
physOn = 0; physOn = 0;
} }
void sprite_gui(struct mSprite *sprite)
{
nk_labelf(ctx, NK_TEXT_LEFT, "Path %s", sprite->tex->path);
//ImGui::SameLine();
if (nk_button_label(ctx, "Load texture") && selected_asset != NULL) {
sprite_loadtex(sprite, selected_asset->filename);
}
if (sprite->tex != NULL) {
nk_labelf(ctx, NK_TEXT_LEFT, "%s", sprite->tex->path);
nk_labelf(ctx, NK_TEXT_LEFT, "%dx%d", sprite->tex->width, sprite->tex->height);
if (nk_button_label(ctx, "Imgbutton")) editor_selectasset_str(sprite->tex->path);
// if (ImGui::ImageButton ((void *) (intptr_t) sprite->tex->id, ImVec2(50, 50))) {
}
nk_property_float2(ctx, "Sprite Position", -1.f, sprite->pos, 0.f, 0.01f, 0.01f);
nk_layout_row_dynamic(ctx, 25, 3);
if (nk_button_label(ctx, "C")) {
sprite->pos[0] = -0.5f;
sprite->pos[1] = -0.5f;
}
if (nk_button_label(ctx, "U")) {
sprite->pos[0] = -0.5f;
sprite->pos[1] = -1.f;
}
if (nk_button_label(ctx, "D")) {
sprite->pos[0] = -0.5f;
sprite->pos[1] = 0.f;
}
}

View file

@ -5,9 +5,6 @@
#include <stdbool.h> #include <stdbool.h>
#include "resources.h" #include "resources.h"
struct mCamera;
#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
@ -45,10 +42,6 @@ struct mSDLWindow;
void pickGameObject(int pickID); void pickGameObject(int pickID);
int is_allowed_extension(const char *ext); int is_allowed_extension(const char *ext);
void nuk_init(struct mSDLWindow *window);
void editor_init(struct mSDLWindow *window); void editor_init(struct mSDLWindow *window);
void editor_input(); void editor_input();
void editor_render(); void editor_render();
@ -81,37 +74,8 @@ void game_pause();
void get_levels(); void get_levels();
struct mLight;
struct mPointLight;
struct mSpotLight;
struct mStaticActor;
struct mTransform;
struct mGameObject;
struct mSprite;
struct phys2d_circle;
struct phys2d_segment;
struct phys2d_box;
struct phys2d_edge;
struct phys2d_shape;
struct phys2d_poly;
struct flipper;
///////// Object GUIs
void light_gui(struct mLight *light);
void pointlight_gui(struct mPointLight *light);
void spotlight_gui(struct mSpotLight *spot);
void staticactor_gui(struct mStaticActor *sa);
void trans_drawgui(struct mTransform *T);
void object_gui(struct mGameObject *go);
void sprite_gui(struct mSprite *sprite);
void circle_gui(struct phys2d_circle *circle);
void segment_gui(struct phys2d_segment *seg);
void box_gui(struct phys2d_box *box);
void poly_gui(struct phys2d_poly *poly);
void edge_gui(struct phys2d_edge *edge);
void shape_gui(struct phys2d_shape *shape);
void pinball_flipper_gui(struct flipper *flip);
int obj_gui_hierarchy(struct mGameObject *selected); int obj_gui_hierarchy(struct mGameObject *selected);
void sprite_gui(struct mSprite *sprite);
#endif #endif

View file

@ -13,6 +13,10 @@
#define sFPS144 0.007 #define sFPS144 0.007
#define sFPS300 0.003 #define sFPS300 0.003
extern double renderMS;
extern double physMS;
extern double updateMS;
void engine_init(); void engine_init();
void engine_stop(); void engine_stop();

View file

@ -20,11 +20,6 @@ unsigned char temp_bitmap[512 * 512];
struct sFont *font; struct sFont *font;
static struct mShader *shader; static struct mShader *shader;
/*
mfont = MakeFont("notosans.ttf", 300);
text_settype(mfont);
*/
void font_init(struct mShader *textshader) { void font_init(struct mShader *textshader) {
shader = textshader; shader = textshader;
@ -42,6 +37,10 @@ void font_init(struct mShader *textshader) {
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0); glBindVertexArray(0);
// Default font
font = MakeFont("notosans.ttf", 300);
} }
void font_frame(struct mSDLWindow *w) { void font_frame(struct mSDLWindow *w) {

View file

@ -10,9 +10,9 @@
#include <string.h> #include <string.h>
#include <chipmunk/chipmunk.h> #include <chipmunk/chipmunk.h>
#include "resources.h" #include "resources.h"
#include "nuke.h"
struct vec *gameobjects = NULL; struct vec *gameobjects = NULL;
struct mGameObject *updateGO = NULL;
const int nameBuf[MAXNAME] = { 0 }; const int nameBuf[MAXNAME] = { 0 };
const int prefabNameBuf[MAXNAME] = { 0 }; const int prefabNameBuf[MAXNAME] = { 0 };
@ -174,20 +174,11 @@ void toggleprefab(struct mGameObject *go)
} }
} }
void component_update(struct component *c)
{
if (c->update)
c->update(c->data, c->go);
}
void gameobject_update(struct mGameObject *go) void gameobject_update(struct mGameObject *go)
{ {
if (go->update) { if (go->script) {
updateGO = go; script_run(go->script);
script_run(updateGO->update);
} }
vec_walk(go->components, &component_update);
} }
void gameobject_move(struct mGameObject *go, float xs, float ys) void gameobject_move(struct mGameObject *go, float xs, float ys)
@ -208,3 +199,66 @@ void gameobject_rotate(struct mGameObject *go, float as)
void update_gameobjects() { void update_gameobjects() {
vec_walk(gameobjects, &gameobject_update); vec_walk(gameobjects, &gameobject_update);
} }
void object_gui(struct mGameObject *go)
{
float temp_pos[2];
temp_pos[0] = cpBodyGetPosition(go->body).x;
temp_pos[1] = cpBodyGetPosition(go->body).y;
draw_point(temp_pos[0], temp_pos[1], 3);
nk_property_float2(ctx, "Position", 0.f, temp_pos, 1.f, 0.01f, 0.01f);
cpVect tvect = { temp_pos[0], temp_pos[1] };
cpBodySetPosition(go->body, tvect);
float mtry = cpBodyGetAngle(go->body);
float modtry = fmodf(mtry * RAD2DEGS, 360.f);
float modtry2 = modtry;
nk_property_float(ctx, "Angle", -1000.f, &modtry, 1000.f, 0.5f, 0.5f);
modtry -= modtry2;
cpBodySetAngle(go->body, mtry + (modtry * DEG2RADS));
nk_property_float(ctx, "Scale", 0.f, &go->scale, 1000.f, 0.01f, 0.001f);
nk_layout_row_dynamic(ctx, 25, 3);
nk_radio_button_label(ctx, "Static", &go->bodytype, CP_BODY_TYPE_STATIC);
nk_radio_button_label(ctx, "Dynamic", &go->bodytype, CP_BODY_TYPE_DYNAMIC);
nk_radio_button_label(ctx, "Kinematic", &go->bodytype, CP_BODY_TYPE_KINEMATIC);
cpBodySetType(go->body, go->bodytype);
if (go->bodytype == CP_BODY_TYPE_DYNAMIC) {
nk_property_float(ctx, "Mass", 0.01f, &go->mass, 1000.f, 0.01f, 0.01f);
cpBodySetMass(go->body, go->mass);
}
nk_property_float(ctx, "Friction", 0.f, &go->f, 10.f, 0.01f, 0.01f);
nk_property_float(ctx, "Elasticity", 0.f, &go->e, 2.f, 0.01f, 0.01f);
int n = -1;
for (int i = 0; i < go->components->len; i++) {
struct component *c =
(struct component *) vec_get(go->components, i);
if (c->draw_debug)
c->draw_debug(c->data);
if (nk_tree_push(ctx, NK_TREE_NODE, c->name, NK_MINIMIZED)) {
if (nk_button_label(ctx, "Del")) {
n = i;
}
c->draw_gui(c->data);
nk_tree_pop(ctx);
}
}
if (n >= 0)
gameobject_delcomponent(go, n);
}

View file

@ -37,10 +37,7 @@ struct mGameObject {
float f; /* friction */ float f; /* friction */
float e; /* elasticity */ float e; /* elasticity */
struct vec *components; struct vec *components;
char *start; char *script;
char *update;
char *fixedupdate;
char *stop;
}; };
struct mGameObject *MakeGameobject(); struct mGameObject *MakeGameobject();
@ -71,4 +68,6 @@ void update_gameobjects();
void gameobject_move(struct mGameObject *go, float xs, float ys); void gameobject_move(struct mGameObject *go, float xs, float ys);
void gameobject_rotate(struct mGameObject *go, float as); void gameobject_rotate(struct mGameObject *go, float as);
void object_gui(struct mGameObject *go);
#endif #endif

View file

@ -1,4 +1,5 @@
#include "input.h" #include "input.h"
#include "vec.h"
int32_t mouseWheelX = 0; int32_t mouseWheelX = 0;
int32_t mouseWheelY = 0; int32_t mouseWheelY = 0;
@ -10,6 +11,8 @@ int quit = 0;
static double c_xpos; static double c_xpos;
static double c_ypos; static double c_ypos;
static struct vec downkeys;
static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos) static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos)
{ {
xchange = (int)xpos - c_xpos; xchange = (int)xpos - c_xpos;
@ -29,20 +32,68 @@ void input_init()
{ {
glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb); glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb);
glfwSetScrollCallback(mainwin->window, scroll_cb); glfwSetScrollCallback(mainwin->window, scroll_cb);
} }
void input_poll() void call_input_down(int *key) {
const char *keyname = glfwGetKeyName(*key, 0);
char keystr[50] = {'\0'};
snprintf(keystr, 50, "input_%s_down", keyname);
script_call(keystr);
}
/* This is called once every frame - or more if we want it more! */
void input_poll(double wait)
{ {
ychange = 0; ychange = 0;
xchange = 0; xchange = 0;
mouseWheelX = 0; mouseWheelX = 0;
mouseWheelY = 0; mouseWheelY = 0;
glfwPollEvents(); glfwWaitEventsTimeout(wait);
//editor_input(&e); //editor_input(&e);
vec_walk(&downkeys, call_input_down);
}
int same_key(int *key1, int *key2) {
return *key1 == *key2;
}
void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods)
{
if (downkeys.data == NULL) {
downkeys = vec_init(sizeof(key), 10);
}
char keystr[50] = {'\0'};
strcat(keystr, "input_");
strcat(keystr, glfwGetKeyName(key, 0));
switch (action) {
case GLFW_PRESS:
strcat(keystr, "_pressed");
int *foundkey = vec_find(&downkeys, same_key, &key);
if (foundkey == NULL) {
vec_add(&downkeys, &key);
}
break;
case GLFW_RELEASE:
strcat(keystr, "_released");
int found = vec_find_n(&downkeys, same_key, &key);
if (found != -1) {
vec_delete(&downkeys, found);
}
break;
case GLFW_REPEAT:
strcat(keystr, "_rep");
break;
}
script_call(keystr);
} }
void cursor_hide() void cursor_hide()
@ -57,5 +108,12 @@ void cursor_show()
int action_down(int scancode) int action_down(int scancode)
{ {
return glfwGetKey(mainwin->window, scancode); int *foundkey = vec_find(&downkeys, same_key, &scancode);
return foundkey != NULL;
}
int action_up(int scancode)
{
int *foundkey = vec_find(&downkeys, same_key, &scancode);
return foundkey == NULL;
} }

View file

@ -12,13 +12,15 @@ extern float deltaT;
extern int quit; extern int quit;
void input_init(); void input_init();
void input_poll(); void input_poll(double wait);
void cursor_hide(); void cursor_hide();
void cursor_show(); void cursor_show();
int action_down(int scancode); int action_down(int scancode);
void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods);
struct inputaction struct inputaction
{ {
int scancode; int scancode;

View file

@ -158,3 +158,45 @@ void spotlight_prepshader(struct mSpotLight *light, struct mShader *shader,
} }
*/ */
/*
void light_gui(struct mLight *light)
{
object_gui(&light->obj);
if (nk_tree_push(ctx, NK_TREE_NODE, "Light", NK_MINIMIZED)) {
nk_property_float(ctx, "Strength", 0.f, &light->strength, 1.f, 0.01f, 0.001f);
// ImGui::ColorEdit3("Color", &light->color[0]);
nk_checkbox_label(ctx, "Dynamic", (bool *) &light->dynamic);
nk_tree_pop(ctx);
}
}
void pointlight_gui(struct mPointLight *light)
{
light_gui(&light->light);
if (nk_tree_push(ctx, NK_TREE_NODE, "Point Light", NK_MINIMIZED)) {
nk_property_float(ctx, "Constant", 0.f, &light->constant, 1.f, 0.01f, 0.001f);
nk_property_float(ctx, "Linear", 0.f, &light->linear, 0.3f, 0.01f, 0.001f);
nk_property_float(ctx, "Quadratic", 0.f, &light->quadratic, 0.3f, 0.01f, 0.001f);
nk_tree_pop(ctx);
}
}
void spotlight_gui(struct mSpotLight *spot)
{
light_gui(&spot->light);
if (nk_tree_push(ctx, NK_TREE_NODE, "Spotlight", NK_MINIMIZED)) {
nk_property_float(ctx, "Linear", 0.f, &spot->linear, 1.f, 0.01f, 0.001f);
nk_property_float(ctx, "Quadratic", 0.f, &spot->quadratic, 1.f, 0.01f, 0.001f);
nk_property_float(ctx, "Distance", 0.f, &spot->distance, 200.f, 1.f, 0.1f, 200.f);
nk_property_float(ctx, "Cutoff Degrees", 0.f, &spot->cutoff, 0.7f, 0.01f, 0.001f);
nk_property_float(ctx, "Outer Cutoff Degrees", 0.f, &spot->outerCutoff, 0.7f, 0.01f, 0.001f);
nk_tree_pop(ctx);
}
}
*/

View file

@ -56,4 +56,8 @@ extern struct mDirectionalLight *dLight;
*/ */
void light_gui(struct mLight *light);
void pointlight_gui(struct mPointLight *light);
void spotlight_gui(struct mSpotLight *spot);
#endif #endif

View file

@ -11,26 +11,16 @@
#include "script.h" #include "script.h"
#include "string.h" #include "string.h"
#include "window.h" #include "window.h"
#include "editor.h"
#include "engine.h"
extern mrb_state *mrb; extern mrb_state *mrb;
#include "nuklear.h" #include "nuklear.h"
extern struct nk_context *ctx; extern struct nk_context *ctx;
int fib(int n) {
if (n < 2) return n;
return fib(n-1) + fib(n-2);
}
/* FFI */ /* FFI */
mrb_value mrb_fib(mrb_state *mrb, mrb_value self) {
int n;
mrb_get_args(mrb, "i", &n);
return mrb_fixnum_value(fib(n));
}
mrb_value mrb_load(mrb_state *mrb, mrb_value self) { mrb_value mrb_load(mrb_state *mrb, mrb_value self) {
char *path; char *path;
mrb_get_args(mrb, "z!", &path); mrb_get_args(mrb, "z!", &path);
@ -90,11 +80,13 @@ mrb_value mrb_ui_begin(mrb_state *mrb, mrb_value self) {
mrb_value mrb_ui_rendertext(mrb_state *mrb, mrb_value self) { mrb_value mrb_ui_rendertext(mrb_state *mrb, mrb_value self) {
char *s; char *s;
mrb_float pos[2], size, ol; mrb_float pos[2];
mrb_float size, ol;
mrb_get_args(mrb, "zffff", &s, &pos[0], &pos[1], &size, &ol); mrb_get_args(mrb, "zffff", &s, &pos[0], &pos[1], &size, &ol);
static float white[3] = {1.f, 1.f, 1.f}; static float white[3] = {1.f, 1.f, 1.f};
renderText(s, pos, size, white, ol); float fpos[2] = {(float)pos[0], (float)pos[1]};
renderText(s, fpos, size, white, ol);
return self; return self;
} }
@ -108,6 +100,29 @@ mrb_value mrb_win_make(mrb_state *mrb, mrb_value self) {
return mrb_float_value(mrb, new->id); return mrb_float_value(mrb, new->id);
} }
mrb_value mrb_win_cmd(mrb_state *mrb, mrb_value self) {
mrb_float win, cmd;
mrb_get_args(mrb, "ff", &win, &cmd);
struct mSDLWindow *new = window_i(win);
switch ((int)cmd)
{
case 0: // toggle fullscreen
window_togglefullscreen(new);
break;
case 1: // Fullscreen on
window_makefullscreen(new);
break;
case 2: // Fullscreen off
window_unfullscreen(new);
break;
}
return self;
}
mrb_value mrb_nuke_cb(mrb_state *mrb, mrb_value self) { mrb_value mrb_nuke_cb(mrb_state *mrb, mrb_value self) {
mrb_float win; mrb_float win;
mrb_sym cb; mrb_sym cb;
@ -133,30 +148,89 @@ mrb_value mrb_sound_make(mrb_state *mrb, mrb_value self) {
} }
mrb_value mrb_sound_cmd(mrb_state *mrb, mrb_value self) { mrb_value mrb_sound_cmd(mrb_state *mrb, mrb_value self) {
mrb_float sound, cmd;
mrb_get_args(mrb, "ff", &sound, &cmd);
switch ((int)cmd)
{
case 0: // play
break;
case 1: // pause
break;
case 2: // stop
break;
case 3: // play from beginning
break;
}
return self;
} }
mrb_value mrb_settings_cmd(mrb_state *mrb, mrb_value self) {
mrb_float cmd, val;
mrb_get_args(mrb, "ff", &cmd, &val);
switch((int)cmd)
{
case 0: // render fps
renderMS = (double)val;
break;
case 1:
updateMS = (double)val;
break;
case 2:
physMS = (double)val;
break;
}
return self;
}
mrb_value mrb_sprite_make(mrb_state *mrb, mrb_value self) {
struct mSprite *new = gui_makesprite();
}
mrb_value mrb_editor_render(mrb_state *mrb, mrb_value self) {
editor_render();
return self;
}
#define MRB_FUNC(NAME, ARGS) mrb_define_method(mrb, mrb->object_class, #NAME, mrb_ ## NAME, ARGS)
void ffi_load() { void ffi_load() {
mrb_define_method(mrb, mrb->object_class, "fib", mrb_fib, MRB_ARGS_REQ(1)); MRB_FUNC(load, MRB_ARGS_REQ(1));
mrb_define_method(mrb, mrb->object_class, "load", mrb_load, MRB_ARGS_REQ(1)); MRB_FUNC(ui_label, MRB_ARGS_REQ(1));
mrb_define_method(mrb, mrb->object_class, "ui_label", mrb_ui_label, MRB_ARGS_REQ(1)); MRB_FUNC(ui_btn, MRB_ARGS_REQ(1));
mrb_define_method(mrb, mrb->object_class, "ui_btn", mrb_ui_btn, MRB_ARGS_REQ(1)); MRB_FUNC(ui_nel, MRB_ARGS_REQ(2));
mrb_define_method(mrb, mrb->object_class, "ui_nel", mrb_ui_nel, MRB_ARGS_REQ(2)); MRB_FUNC(ui_begin, MRB_ARGS_REQ(3));
mrb_define_method(mrb, mrb->object_class, "ui_begin", mrb_ui_begin, MRB_ARGS_REQ(3));
mrb_define_method(mrb, mrb->object_class, "ui_prop", mrb_ui_prop, MRB_ARGS_REQ(6)); MRB_FUNC(ui_prop, MRB_ARGS_REQ(6));
mrb_define_method(mrb, mrb->object_class, "ui_text", mrb_ui_text, MRB_ARGS_REQ(2)); MRB_FUNC(ui_text, MRB_ARGS_REQ(2));
mrb_define_method(mrb, mrb->object_class, "ui_rendertext", mrb_ui_rendertext, MRB_ARGS_REQ(5)); MRB_FUNC(ui_rendertext, MRB_ARGS_REQ(5));
mrb_define_method(mrb, mrb->object_class, "c_reload", mrb_c_reload, MRB_ARGS_REQ(1)); MRB_FUNC(sprite_make, MRB_ARGS_REQ(1));
mrb_define_method(mrb, mrb->object_class, "win_make", mrb_win_make, MRB_ARGS_REQ(1)); MRB_FUNC(c_reload, MRB_ARGS_REQ(1));
mrb_define_method(mrb, mrb->object_class, "nuke_cb", mrb_nuke_cb, MRB_ARGS_REQ(2));
mrb_define_method(mrb, mrb->object_class, "gui_cb", mrb_gui_cb, MRB_ARGS_REQ(2));
mrb_define_method(mrb, mrb->object_class, "sound_make", mrb_sound_make, MRB_ARGS_REQ(1)); MRB_FUNC(win_make, MRB_ARGS_REQ(1));
mrb_define_method(mrb, mrb->object_class, "sound_cmd", mrb_sound_cmd, MRB_ARGS_REQ(2)); MRB_FUNC(win_cmd, MRB_ARGS_REQ(2));
MRB_FUNC(nuke_cb, MRB_ARGS_REQ(2));
MRB_FUNC(gui_cb, MRB_ARGS_REQ(2));
MRB_FUNC(sound_make, MRB_ARGS_REQ(1));
MRB_FUNC(sound_cmd, MRB_ARGS_REQ(2));
MRB_FUNC(editor_render, MRB_ARGS_REQ(0));
MRB_FUNC(settings_cmd, MRB_ARGS_REQ(2));
} }

View file

@ -42,3 +42,24 @@ void nuke_end()
nk_end(ctx); nk_end(ctx);
nk_glfw3_render(&nkglfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); nk_glfw3_render(&nkglfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
} }
void nk_property_float3(struct nk_context *ctx, const char *label, float min, float *val, float max, float step, float dragstep) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, label, NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 3);
nk_property_float(ctx, "X", min, &val[0], max, step, dragstep);
nk_property_float(ctx, "Y", min, &val[1], max, step, dragstep);
nk_property_float(ctx, "Z", min, &val[2], max, step, dragstep);
}
void nk_property_float2(struct nk_context *ctx, const char *label, float min, float *val, float max, float step, float dragstep) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, label, NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 2);
nk_property_float(ctx, "X", min, &val[0], max, step, dragstep);
nk_property_float(ctx, "Y", min, &val[1], max, step, dragstep);
}
void nk_radio_button_label(struct nk_context *ctx, const char *label, int *val, int cmp) {
if (nk_option_label(ctx, label, (bool)*val == cmp)) *val = cmp;
}

View file

@ -12,4 +12,8 @@ void nuke_init(struct mSDLWindow *win);
void nuke_start(); void nuke_start();
void nuke_end(); void nuke_end();
void nk_property_float3(struct nk_context *ctx, const char *label, float min, float *val, float max, float step, float dragstep);
void nk_property_float2(struct nk_context *ctx, const char *label, float min, float *val, float max, float step, float dragstep);
void nk_radio_button_label(struct nk_context *ctx, const char *label, int *val, int cmp);
#endif #endif

View file

@ -1,32 +1,41 @@
#include "registry.h" #include "registry.h"
#include "gameobject.h" #include "gameobject.h"
#include "2dphysics.h" #include "2dphysics.h"
#include <editor.h> #include "editor.h"
#include "sprite.h" #include "sprite.h"
struct component components[MAXNAME] = { 0 }; struct component components[MAXNAME] = { 0 };
int ncomponent = 0; int ncomponent = 0;
#define REGISTER_COMP(NAME) register_component(#NAME, sizeof(struct NAME), &make_ ## NAME, &dbgdraw_ ## NAME, & ## NAME ## _gui, & ## NAME ## _init,
void registry_init() void registry_init()
{ {
/*
REGISTER_COMP(sprite);
REGISTER_COMP(2d_circle);
REGISTER_COMP(2d_segment);
REGISTER_COMP(2d_box);
REGISTER_COMP(2d_polygon);
REGISTER_COMP(2d_edge);
*/
register_component("Sprite", sizeof(struct mSprite), &MakeSprite, NULL, register_component("Sprite", sizeof(struct mSprite), &MakeSprite, NULL,
&sprite_gui, &sprite_init, NULL); &sprite_gui, &sprite_init);
register_component("2D Circle Collider", sizeof(struct phys2d_circle), register_component("2D Circle Collider", sizeof(struct phys2d_circle),
&Make2DCircle, &phys2d_dbgdrawcircle, &circle_gui, &Make2DCircle, &phys2d_dbgdrawcircle, &circle_gui,
&phys2d_circleinit, NULL); &phys2d_circleinit);
register_component("2D Segment", sizeof(struct phys2d_segment), register_component("2D Segment", sizeof(struct phys2d_segment),
&Make2DSegment, &phys2d_dbgdrawseg, &segment_gui, &Make2DSegment, &phys2d_dbgdrawseg, &segment_gui,
&phys2d_seginit, NULL); &phys2d_seginit);
register_component("2D Box", sizeof(struct phys2d_box), &Make2DBox, register_component("2D Box", sizeof(struct phys2d_box), &Make2DBox,
&phys2d_dbgdrawbox, &box_gui, &phys2d_boxinit, &phys2d_dbgdrawbox, &box_gui, &phys2d_boxinit);
NULL);
register_component("2D Polygon", sizeof(struct phys2d_poly), register_component("2D Polygon", sizeof(struct phys2d_poly),
&Make2DPoly, &phys2d_dbgdrawpoly, &poly_gui, &Make2DPoly, &phys2d_dbgdrawpoly, &poly_gui,
&phys2d_polyinit, NULL); &phys2d_polyinit);
register_component("2D Edge", sizeof(struct phys2d_edge), &Make2DEdge, register_component("2D Edge", sizeof(struct phys2d_edge), &Make2DEdge,
&phys2d_dbgdrawedge, &edge_gui, &phys2d_edgeinit, &phys2d_dbgdrawedge, &edge_gui, &phys2d_edgeinit);
NULL);
} }
void register_component(const char *name, size_t size, void register_component(const char *name, size_t size,
@ -34,8 +43,7 @@ void register_component(const char *name, size_t size,
struct component * c), struct component * c),
void(*draw_debug)(void *data), void(*draw_debug)(void *data),
void(*draw_gui)(void *data), void(*draw_gui)(void *data),
void(*init)(void *data, struct mGameObject * go), void(*init)(void *data, struct mGameObject * go))
void(*update)(void *data, struct mGameObject * go))
{ {
struct component *c = &components[ncomponent++]; struct component *c = &components[ncomponent++];
c->name = name; c->name = name;
@ -55,7 +63,3 @@ void comp_draw_debug(struct component *c) {
void comp_draw_gui(struct component *c) { void comp_draw_gui(struct component *c) {
c->draw_gui(c->data); c->draw_gui(c->data);
} }
void comp_update(struct component *c, struct mGameObject *go) {
c->update(c->data, go);
}

View file

@ -13,7 +13,6 @@ struct component {
struct mGameObject *go; struct mGameObject *go;
void (*draw_debug)(void *data); void (*draw_debug)(void *data);
void (*draw_gui)(void *data); void (*draw_gui)(void *data);
void (*update)(void *data, struct mGameObject * go);
int id; int id;
int datasize; int datasize;
void (*init)(void *data, struct mGameObject * go); void (*init)(void *data, struct mGameObject * go);
@ -29,12 +28,9 @@ void comp_update(struct component *c, struct mGameObject *go);
void registry_init(); void registry_init();
void register_component(const char *name, size_t size, void register_component(const char *name, size_t size,
void (*make)(struct mGameObject * go, void (*make)(struct mGameObject * go, struct component * c),
struct component * c),
void(*draw_debug)(void *data), void(*draw_debug)(void *data),
void(*draw_gui)(void *data), void(*draw_gui)(void *data),
void(*init)(void *data, struct mGameObject * go), void(*init)(void *data, struct mGameObject * go));
void(*update)(void *data,
struct mGameObject * go));
#endif #endif

View file

@ -11,6 +11,7 @@
#include <string.h> #include <string.h>
#include "vec.h" #include "vec.h"
static struct mGameObject *gui_go = NULL; static struct mGameObject *gui_go = NULL;
@ -41,6 +42,7 @@ struct mSprite *MakeSprite(struct mGameObject *go)
sprite->size[1] = 1.f; sprite->size[1] = 1.f;
sprite->tex = NULL; sprite->tex = NULL;
sprite_init(sprite, go); sprite_init(sprite, go);
sprite->index = sprites.last;
return sprite; return sprite;
} }
@ -220,3 +222,4 @@ struct mSprite *gui_makesprite()
struct mSprite *new = MakeSprite(gui_go); struct mSprite *new = MakeSprite(gui_go);
return new; return new;
} }

View file

@ -24,6 +24,7 @@ struct mSprite {
mfloat_t size[2]; mfloat_t size[2];
float rotation; float rotation;
mfloat_t color[3]; mfloat_t color[3];
int index;
struct Anim2D anim; struct Anim2D anim;
struct mGameObject *go; struct mGameObject *go;
@ -47,4 +48,5 @@ void gui_init();
void sprite_draw_all(); void sprite_draw_all();
#endif #endif

View file

@ -74,3 +74,21 @@ Serialize *make_staticactor()
return nactor; return nactor;
} }
*/ */
#include "nuke.h"
void staticactor_gui(struct mStaticActor *sa)
{
object_gui(&sa->obj);
if (nk_tree_push(ctx, NK_TREE_NODE, "Model", NK_MINIMIZED)) {
nk_checkbox_label(ctx, "Cast Shadows", &sa->castShadows);
nk_labelf(ctx, NK_TEXT_LEFT, "Model path: %s", sa->currentModelPath);
//ImGui::SameLine();
if (nk_button_label(ctx, "Load model")) {
//asset_command = set_new_model;
curActor = sa;
}
}
}

View file

@ -17,7 +17,7 @@ void staticactor_draw_dbg_color_pick(struct mShader *s);
void staticactor_draw_models(struct mShader *s); void staticactor_draw_models(struct mShader *s);
void staticactor_draw_shadowcasters(struct mShader *s); void staticactor_draw_shadowcasters(struct mShader *s);
struct mStaticActor *MakeStaticActor(); struct mStaticActor *MakeStaticActor();
void staticactor_gui(struct mStaticActor *sa);
extern struct mStaticActor *curActor; extern struct mStaticActor *curActor;

View file

@ -42,3 +42,12 @@ mfloat_t *trans_left(mfloat_t * res, const struct mTransform *trans)
{ {
return vec3_rotate_quat(res, LEFT, trans->rotation); return vec3_rotate_quat(res, LEFT, trans->rotation);
} }
#include "nuke.h"
void trans_drawgui(struct mTransform *T)
{
nk_property_float3(ctx, "Position", -1000.f, T->position, 1000.f, 1.f, 1.f);
nk_property_float3(ctx, "Rotation", 0.f, T->rotation, 360.f, 1.f, 0.1f);
nk_property_float(ctx, "Scale", 0.f, &T->scale, 1000.f, 0.1f, 0.1f);
}

View file

@ -20,7 +20,7 @@ mfloat_t *trans_up(mfloat_t * res, const struct mTransform *trans);
mfloat_t *trans_down(mfloat_t * res, const struct mTransform *trans); mfloat_t *trans_down(mfloat_t * res, const struct mTransform *trans);
mfloat_t *trans_right(mfloat_t * res, const struct mTransform *trans); mfloat_t *trans_right(mfloat_t * res, const struct mTransform *trans);
mfloat_t *trans_left(mfloat_t * res, const struct mTransform *trans); mfloat_t *trans_left(mfloat_t * res, const struct mTransform *trans);
void trans_drawgui(struct mTransform *T);
//extern Serialize *make_transform(); //extern Serialize *make_transform();

View file

@ -54,38 +54,14 @@ void window_close_callback(GLFWwindow *w)
quit = 1; quit = 1;
} }
void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods)
{
char keystr[50] = {'\0'};
strcat(keystr, "input_");
strcat(keystr, glfwGetKeyName(key, 0));
switch (action) {
case GLFW_PRESS:
strcat(keystr, "_down");
break;
case GLFW_RELEASE:
strcat(keystr, "_up");
break;
case GLFW_REPEAT:
strcat(keystr, "_rep");
break;
}
script_call(keystr);
/* Example callback function
if (key == GLFW_KEY_F && action == GLFW_PRESS) {
printf("Pressed F.\n");
if (w == customerWindow->window) window_togglefullscreen(customerWindow);
}
*/
}
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height, uint32_t flags) struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height, uint32_t flags)
{ {
struct mSDLWindow *w; struct mSDLWindow *w;
if (windows.data == NULL) { if (windows.data == NULL) {
windows = vec_init(sizeof(struct mSDLWindow), 5); windows = vec_init(sizeof(struct mSDLWindow), 5);
w = vec_add(&windows, NULL); w = vec_add(&windows, NULL);
@ -234,8 +210,14 @@ void window_all_handle_events()
void window_makefullscreen(struct mSDLWindow *w) void window_makefullscreen(struct mSDLWindow *w)
{ {
glfwMaximizeWindow(w->window); if (!w->fullscreen)
w->fullscreen = true; window_togglefullscreen(w);
}
void window_unfullscreen(struct mSDLWindow *w)
{
if (w->fullscreen)
window_togglefullscreen(w);
} }
void window_togglefullscreen(struct mSDLWindow *w) void window_togglefullscreen(struct mSDLWindow *w)
@ -243,7 +225,7 @@ void window_togglefullscreen(struct mSDLWindow *w)
w->fullscreen = !w->fullscreen; w->fullscreen = !w->fullscreen;
if (w->fullscreen) { if (w->fullscreen) {
window_makefullscreen(w); glfwMaximizeWindow(w->window);
} else { } else {
glfwRestoreWindow(w->window); glfwRestoreWindow(w->window);
} }
@ -259,6 +241,8 @@ void window_makecurrent(struct mSDLWindow *w)
} }
void window_swap(struct mSDLWindow *w) void window_swap(struct mSDLWindow *w)
{ {
glfwSwapBuffers(w->window); glfwSwapBuffers(w->window);

View file

@ -38,6 +38,7 @@ void window_all_handle_events();
void window_makecurrent(struct mSDLWindow *w); void window_makecurrent(struct mSDLWindow *w);
void window_makefullscreen(struct mSDLWindow *w); void window_makefullscreen(struct mSDLWindow *w);
void window_togglefullscreen(struct mSDLWindow *w); void window_togglefullscreen(struct mSDLWindow *w);
void window_unfullscreen(struct mSDLWindow *w);
void window_swap(struct mSDLWindow *w); void window_swap(struct mSDLWindow *w);
void window_seticon(struct mSDLWindow *w, struct Texture *icon); void window_seticon(struct mSDLWindow *w, struct Texture *icon);
int window_hasfocus(struct mSDLWindow *w); int window_hasfocus(struct mSDLWindow *w);

View file

@ -8,8 +8,13 @@
int physOn = 0; int physOn = 0;
double renderlag = 0; double renderlag = 0;
double physlag = 0;
double updatelag = 0;
double renderMS = 1/60.f;
double physMS = 1/120.f;
double updateMS = 1/60.f;
static double renderMS = 0.033;
int main(int argc, char **args) { int main(int argc, char **args) {
engine_init(); engine_init();
@ -23,27 +28,24 @@ int main(int argc, char **args) {
renderMS = 0.033; renderMS = 0.033;
double lastTick; double lastTick;
double frameTick;
while (!quit) { while (!quit) {
double elapsed; double elapsed;
double lastTick; elapsed = glfwGetTime() - lastTick;
frameTick = glfwGetTime(); lastTick = glfwGetTime();
elapsed = frameTick - lastTick;
lastTick = frameTick;
renderlag += elapsed; renderlag += elapsed;
physlag += elapsed;
input_poll();
window_all_handle_events();
script_update(elapsed);
if (renderlag >= renderMS) { if (renderlag >= renderMS) {
renderlag -= renderMS; renderlag -= renderMS;
window_renderall(); window_renderall();
} }
input_poll(updateMS - elapsed < 0 ? 0 : updateMS - elapsed);
window_all_handle_events();
script_update(updateMS);
} }
} }