Constrained nuklear.h to nuke.c
This commit is contained in:
parent
075b9950e0
commit
4d577dadb7
7
Makefile
7
Makefile
|
@ -32,6 +32,11 @@ endif
|
||||||
ifeq ($(OPT),small)
|
ifeq ($(OPT),small)
|
||||||
CFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables
|
CFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables
|
||||||
LDFLAGS += -flto
|
LDFLAGS += -flto
|
||||||
|
|
||||||
|
ifeq ($(CC), emcc)
|
||||||
|
LDFLAGS += --closure 1
|
||||||
|
endif
|
||||||
|
|
||||||
INFO := $(addsuffix _small,$(INFO))
|
INFO := $(addsuffix _small,$(INFO))
|
||||||
else
|
else
|
||||||
ifeq ($(OPT), 1)
|
ifeq ($(OPT), 1)
|
||||||
|
@ -63,7 +68,7 @@ ifeq ($(OS), Windows_NT)
|
||||||
ZIP = .zip
|
ZIP = .zip
|
||||||
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
|
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
|
||||||
else ifeq ($(CC), emcc)
|
else ifeq ($(CC), emcc)
|
||||||
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -s ALLOW_MEMORY_GROWTH=1
|
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread
|
||||||
CFLAGS += -pthread
|
CFLAGS += -pthread
|
||||||
LDLIBS += pthread quickjs GL openal c m dl
|
LDLIBS += pthread quickjs GL openal c m dl
|
||||||
CC = emcc
|
CC = emcc
|
||||||
|
|
|
@ -269,8 +269,8 @@ JSValue duk_gui_img(JSContext *js, JSValueConst this, int argc, JSValueConst *ar
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nk_rect js2nk_rect(JSValue v) {
|
struct rect js2rect(JSValue v) {
|
||||||
struct nk_rect rect;
|
struct rect rect;
|
||||||
rect.x = js2number(js_getpropstr(v, "x"));
|
rect.x = js2number(js_getpropstr(v, "x"));
|
||||||
rect.y = js2number(js_getpropstr(v, "y"));
|
rect.y = js2number(js_getpropstr(v, "y"));
|
||||||
rect.w = js2number(js_getpropstr(v, "w"));
|
rect.w = js2number(js_getpropstr(v, "w"));
|
||||||
|
@ -278,7 +278,7 @@ struct nk_rect js2nk_rect(JSValue v) {
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue nk_rect2js(struct nk_rect rect) {
|
JSValue rect2js(struct rect rect) {
|
||||||
JSValue obj = JS_NewObject(js);
|
JSValue obj = JS_NewObject(js);
|
||||||
JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, rect.x));
|
JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, rect.x));
|
||||||
JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, rect.y));
|
JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, rect.y));
|
||||||
|
@ -312,13 +312,13 @@ JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||||
JS_FreeValue(js, tostr);
|
JS_FreeValue(js, tostr);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nk_rect rect = nk_rect(0, 0, 0, 0);
|
struct rect rect = (struct rect){0, 0, 0, 0};
|
||||||
JSValue ret = JS_NULL;
|
JSValue ret = JS_NULL;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 0:
|
case 0:
|
||||||
rect = js2nk_rect(argv[2]);
|
rect = js2rect(argv[2]);
|
||||||
nuke_begin(str, rect, NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_TITLE);
|
nuke_begin(str, rect);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -367,7 +367,7 @@ JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||||
|
|
||||||
case 10:
|
case 10:
|
||||||
rect = nuke_win_get_bounds();
|
rect = nuke_win_get_bounds();
|
||||||
ret = nk_rect2js(rect);
|
ret = rect2js(rect);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 11:
|
case 11:
|
||||||
|
|
|
@ -1,29 +1,28 @@
|
||||||
|
#include "nuke.h"
|
||||||
#define NK_INCLUDE_STANDARD_IO
|
#define NK_INCLUDE_STANDARD_IO
|
||||||
|
|
||||||
#define NK_IMPLEMENTATION
|
#define NK_IMPLEMENTATION
|
||||||
#define NK_KEYSTATE_BASED_INPUT
|
#define NK_KEYSTATE_BASED_INPUT
|
||||||
|
#define NK_INCLUDE_FIXED_TYPES
|
||||||
|
#define NK_INCLUDE_STANDARD_VARARGS
|
||||||
|
#define NK_INCLUDE_FONT_BAKING
|
||||||
|
#define NK_INCLUDE_DEFAULT_FONT
|
||||||
|
#define NK_INCLUDE_STANDARD_BOOL
|
||||||
|
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||||
|
#define NK_INCLUDE_STANDARD_IO
|
||||||
|
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||||
|
|
||||||
#define STBTT_STATIC
|
#define STBTT_STATIC
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "nuke.h"
|
|
||||||
|
|
||||||
#if defined __linux__
|
|
||||||
#define SOKOL_GLCORE33
|
|
||||||
#elif __EMSCRIPTEN__
|
|
||||||
#define SOKOL_GLES3
|
|
||||||
#elif __WIN32
|
|
||||||
#define SOKOL_GLCORE33
|
|
||||||
#define SOKOL_WIN32_FORCE_MAIN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sokol/sokol_gfx.h"
|
#include "sokol/sokol_gfx.h"
|
||||||
|
|
||||||
#define SOKOL_NUKLEAR_IMPL
|
#define SOKOL_NUKLEAR_IMPL
|
||||||
|
#include "nuklear.h"
|
||||||
#include "sokol/sokol_app.h"
|
#include "sokol/sokol_app.h"
|
||||||
#include "sokol/sokol_nuklear.h"
|
#include "sokol/sokol_nuklear.h"
|
||||||
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -34,7 +33,6 @@
|
||||||
#define MAX_ELEMENT_BUFFER 128 * 1024
|
#define MAX_ELEMENT_BUFFER 128 * 1024
|
||||||
|
|
||||||
struct nk_context *ctx;
|
struct nk_context *ctx;
|
||||||
//static struct nk_glfw nkglfw = {0};
|
|
||||||
|
|
||||||
void nuke_init(struct window *win) {
|
void nuke_init(struct window *win) {
|
||||||
snk_setup(&(snk_desc_t){
|
snk_setup(&(snk_desc_t){
|
||||||
|
@ -44,6 +42,26 @@ void nuke_init(struct window *win) {
|
||||||
ctx = snk_new_frame();
|
ctx = snk_new_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct rect nk2rect(struct nk_rect rect)
|
||||||
|
{
|
||||||
|
struct rect r;
|
||||||
|
r.x = rect.x;
|
||||||
|
r.y = rect.y;
|
||||||
|
r.w = rect.w;
|
||||||
|
r.h = rect.h;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct nk_rect rect2nk(struct rect rect)
|
||||||
|
{
|
||||||
|
struct nk_rect r;
|
||||||
|
r.x = rect.x;
|
||||||
|
r.y = rect.y;
|
||||||
|
r.w = rect.w;
|
||||||
|
r.h = rect.h;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void nuke_start() {
|
void nuke_start() {
|
||||||
ctx = snk_new_frame();
|
ctx = snk_new_frame();
|
||||||
}
|
}
|
||||||
|
@ -52,8 +70,8 @@ void nuke_end() {
|
||||||
snk_render(mainwin.width,mainwin.height);
|
snk_render(mainwin.width,mainwin.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nuke_begin(const char *lbl, struct nk_rect rect, int flags) {
|
int nuke_begin(const char *lbl, struct rect rect) {
|
||||||
return nk_begin(ctx, lbl, rect, flags);
|
return nk_begin(ctx, lbl, rect2nk(rect), NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nuke_begin_win(const char *lbl) {
|
int nuke_begin_win(const char *lbl) {
|
||||||
|
@ -64,8 +82,8 @@ void nuke_stop() {
|
||||||
nk_end(ctx);
|
nk_end(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nk_rect nuke_win_get_bounds() {
|
struct rect nuke_win_get_bounds() {
|
||||||
return nk_window_get_bounds(ctx);
|
return nk2rect(nk_window_get_bounds(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
void nuke_row(int height) {
|
void nuke_row(int height) {
|
||||||
|
|
|
@ -1,26 +1,17 @@
|
||||||
#ifndef NUKE_H
|
#ifndef NUKE_H
|
||||||
#define NUKE_H
|
#define NUKE_H
|
||||||
#define NK_INCLUDE_FIXED_TYPES
|
|
||||||
#define NK_INCLUDE_STANDARD_VARARGS
|
|
||||||
#define NK_INCLUDE_FONT_BAKING
|
|
||||||
#define NK_INCLUDE_DEFAULT_FONT
|
|
||||||
#define NK_INCLUDE_STANDARD_BOOL
|
|
||||||
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
|
||||||
#define NK_INCLUDE_STANDARD_IO
|
|
||||||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
|
||||||
|
|
||||||
#include "nuklear.h"
|
|
||||||
|
|
||||||
|
#include "render.h"
|
||||||
struct window;
|
struct window;
|
||||||
|
|
||||||
void nuke_init(struct window *win);
|
void nuke_init(struct window *win);
|
||||||
void nuke_start();
|
void nuke_start();
|
||||||
void nuke_end();
|
void nuke_end();
|
||||||
|
|
||||||
int nuke_begin(const char *lbl, struct nk_rect rect, int flags);
|
int nuke_begin(const char *lbl, struct rect rect);
|
||||||
int nuke_begin_win(const char *lbl);
|
int nuke_begin_win(const char *lbl);
|
||||||
void nuke_stop();
|
void nuke_stop();
|
||||||
struct nk_rect nuke_win_get_bounds();
|
struct rect nuke_win_get_bounds();
|
||||||
|
|
||||||
void nuke_property_float(const char *lbl, float min, float *val, float max, float step, float dragstep);
|
void nuke_property_float(const char *lbl, float min, float *val, float max, float step, float dragstep);
|
||||||
#define nuke_prop_float nuke_property_float
|
#define nuke_prop_float nuke_property_float
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
#ifndef OPENGL_RENDER_H
|
#ifndef OPENGL_RENDER_H
|
||||||
#define OPENGL_RENDER_H
|
#define OPENGL_RENDER_H
|
||||||
|
|
||||||
|
#if defined __linux__
|
||||||
|
#define SOKOL_GLCORE33
|
||||||
|
#elif __EMSCRIPTEN__
|
||||||
|
#define SOKOL_GLES3
|
||||||
|
#elif __WIN32
|
||||||
|
#define SOKOL_GLCORE33
|
||||||
|
#define SOKOL_WIN32_FORCE_MAIN
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sokol/sokol_gfx.h"
|
#include "sokol/sokol_gfx.h"
|
||||||
#include "HandmadeMath.h"
|
#include "HandmadeMath.h"
|
||||||
|
|
||||||
|
@ -88,6 +97,10 @@ struct boundingbox {
|
||||||
float l;
|
float l;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct rect {
|
||||||
|
float h, w, x, y;
|
||||||
|
};
|
||||||
|
|
||||||
static struct boundingbox cwh2bb(HMM_Vec2 c, HMM_Vec2 wh) {
|
static struct boundingbox cwh2bb(HMM_Vec2 c, HMM_Vec2 wh) {
|
||||||
struct boundingbox bb = {
|
struct boundingbox bb = {
|
||||||
.t = c.Y + wh.Y/2,
|
.t = c.Y + wh.Y/2,
|
||||||
|
|
|
@ -232,6 +232,7 @@ static int ftw_pack(const char *path, const struct stat *sb, int flag)
|
||||||
int pack = 0;
|
int pack = 0;
|
||||||
|
|
||||||
char *ext = strrchr(path, '.');
|
char *ext = strrchr(path, '.');
|
||||||
|
|
||||||
if (!ext)
|
if (!ext)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -243,7 +244,6 @@ static int ftw_pack(const char *path, const struct stat *sb, int flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pack) return 0;
|
if (!pack) return 0;
|
||||||
printf("Packing file %s\n", path);
|
|
||||||
|
|
||||||
long len;
|
long len;
|
||||||
void *file = slurp_file(path, &len);
|
void *file = slurp_file(path, &len);
|
||||||
|
|
|
@ -36,15 +36,6 @@
|
||||||
#define SOKOL_TRACE_HOOKS
|
#define SOKOL_TRACE_HOOKS
|
||||||
#define SOKOL_IMPL
|
#define SOKOL_IMPL
|
||||||
|
|
||||||
#if defined __linux__
|
|
||||||
#define SOKOL_GLCORE33
|
|
||||||
#elif __EMSCRIPTEN__
|
|
||||||
#define SOKOL_GLES3
|
|
||||||
#elif __WIN32
|
|
||||||
#define SOKOL_GLCORE33
|
|
||||||
#define SOKOL_WIN32_FORCE_MAIN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sokol/sokol_gfx.h"
|
#include "sokol/sokol_gfx.h"
|
||||||
#include "sokol/sokol_app.h"
|
#include "sokol/sokol_app.h"
|
||||||
#include "sokol/sokol_audio.h"
|
#include "sokol/sokol_audio.h"
|
||||||
|
@ -296,7 +287,7 @@ double get_timescale()
|
||||||
return timescale;
|
return timescale;
|
||||||
}
|
}
|
||||||
|
|
||||||
sapp_desc sokol_main(int sargc, char **sargs) {
|
sapp_desc sokol_main(int argc, char **argv) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int logout = 0;
|
int logout = 0;
|
||||||
|
@ -333,7 +324,7 @@ sapp_desc sokol_main(int sargc, char **sargs) {
|
||||||
|
|
||||||
int argsize = 0;
|
int argsize = 0;
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
argsize += strlen(args[i]);
|
argsize += strlen(argv[i]);
|
||||||
if (argc > i+1) argsize++;
|
if (argc > i+1) argsize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,17 +332,14 @@ sapp_desc sokol_main(int sargc, char **sargs) {
|
||||||
cmdstr[0] = '\0';
|
cmdstr[0] = '\0';
|
||||||
|
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
strcat(cmdstr, args[i]);
|
strcat(cmdstr, argv[i]);
|
||||||
if (argc > i+1) strcat(cmdstr, " ");
|
if (argc > i+1) strcat(cmdstr, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
script_evalf("cmd_args('%s');", cmdstr);
|
script_evalf("cmd_args('%s');", cmdstr);
|
||||||
|
|
||||||
YughWarn("Width, height %d %d", mainwin.width, mainwin.height);
|
|
||||||
|
|
||||||
sound_init();
|
sound_init();
|
||||||
input_init();
|
input_init();
|
||||||
|
|
||||||
|
|
||||||
return (sapp_desc){
|
return (sapp_desc){
|
||||||
.width = mainwin.width,
|
.width = mainwin.width,
|
||||||
|
|
|
@ -58,7 +58,7 @@ Cmdline.register_cmd("h", function() {
|
||||||
Game.quit();
|
Game.quit();
|
||||||
},
|
},
|
||||||
"Help.");
|
"Help.");
|
||||||
Cmdline.register_cmd("b", function() { Log.warn("PACKING");cmd(124); Game.quit(); }, "Pack the game into the given name.");
|
Cmdline.register_cmd("b", function() { cmd(124); Game.quit(); }, "Pack the game into the given name.");
|
||||||
|
|
||||||
Cmdline.register_cmd("e", function(pawn) {
|
Cmdline.register_cmd("e", function(pawn) {
|
||||||
run("scripts/editor.js");
|
run("scripts/editor.js");
|
||||||
|
@ -2366,7 +2366,11 @@ gameobject.clone("sprite", {
|
||||||
//if (IO.exists("config.js"))
|
//if (IO.exists("config.js"))
|
||||||
// load("config.js");
|
// load("config.js");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var prototypes = {};
|
var prototypes = {};
|
||||||
|
prototypes.load_all = function()
|
||||||
|
{
|
||||||
if (IO.exists("proto.json"))
|
if (IO.exists("proto.json"))
|
||||||
prototypes = JSON.parse(IO.slurp("proto.json"));
|
prototypes = JSON.parse(IO.slurp("proto.json"));
|
||||||
|
|
||||||
|
@ -2386,7 +2390,8 @@ for (var key in prototypes) {
|
||||||
dainty_assign(gameobjects[key], prototypes[key]);
|
dainty_assign(gameobjects[key], prototypes[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function save_gameobjects_as_prototypes() { slurpwrite(JSON.stringify(gameobjects,null,2), "proto.json"); };
|
prototypes.save_gameobjects = function() { slurpwrite(JSON.stringify(gameobjects,null,2), "proto.json"); };
|
||||||
|
|
||||||
var Gamestate = {};
|
var Gamestate = {};
|
||||||
|
|
Loading…
Reference in a new issue