shaders
This commit is contained in:
parent
eb3e576521
commit
e0f3985b00
|
@ -1,23 +1,23 @@
|
|||
#include "2dphysics.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "gameobject.h"
|
||||
#include <string.h>
|
||||
#include "mathc.h"
|
||||
#include "nuke.h"
|
||||
#include "debug.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "debugdraw.h"
|
||||
#include <math.h>
|
||||
#include <chipmunk/chipmunk_unsafe.h>
|
||||
#include "stb_ds.h"
|
||||
#include <assert.h>
|
||||
#include <chipmunk/chipmunk_unsafe.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "2dphysics.h"
|
||||
|
||||
#include "tinyspline.h"
|
||||
|
||||
#include "script.h"
|
||||
#include "ffi.h"
|
||||
#include "script.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
|
@ -33,20 +33,17 @@ float static_color[3] = {0.22f, 0.271f, 1.f};
|
|||
|
||||
unsigned int category_masks[32];
|
||||
|
||||
void set_cat_mask(int cat, unsigned int mask)
|
||||
{
|
||||
void set_cat_mask(int cat, unsigned int mask) {
|
||||
category_masks[cat] = mask;
|
||||
}
|
||||
|
||||
void color2float(struct color color, float *fcolor)
|
||||
{
|
||||
void color2float(struct color color, float *fcolor) {
|
||||
fcolor[0] = (float)color.r / 255;
|
||||
fcolor[1] = (float)color.g / 255;
|
||||
fcolor[2] = (float)color.b / 255;
|
||||
}
|
||||
|
||||
struct color float2color(float *fcolor)
|
||||
{
|
||||
struct color float2color(float *fcolor) {
|
||||
struct color new;
|
||||
new.r = fcolor[0] * 255;
|
||||
new.b = fcolor[1] * 255;
|
||||
|
@ -54,8 +51,7 @@ struct color float2color(float *fcolor)
|
|||
return new;
|
||||
}
|
||||
|
||||
cpShape *phys2d_query_pos(cpVect pos)
|
||||
{
|
||||
cpShape *phys2d_query_pos(cpVect pos) {
|
||||
cpShapeFilter filter;
|
||||
filter.group = CP_NO_GROUP;
|
||||
filter.mask = CP_ALL_CATEGORIES;
|
||||
|
@ -68,8 +64,7 @@ cpShape *phys2d_query_pos(cpVect pos)
|
|||
|
||||
int *qhits;
|
||||
|
||||
void querylist(cpShape *shape, cpContactPointSet *points, void *data)
|
||||
{
|
||||
void querylist(cpShape *shape, cpContactPointSet *points, void *data) {
|
||||
int go = shape2gameobject(shape);
|
||||
int in = 0;
|
||||
for (int i = 0; i < arrlen(qhits); i++) {
|
||||
|
@ -82,8 +77,7 @@ void querylist(cpShape *shape, cpContactPointSet *points, void *data)
|
|||
if (!in) arrput(qhits, go);
|
||||
}
|
||||
|
||||
void querylistbodies(cpBody *body, void *data)
|
||||
{
|
||||
void querylistbodies(cpBody *body, void *data) {
|
||||
cpBB *bbox = data;
|
||||
if (cpBBContainsVect(*bbox, cpBodyGetPosition(body))) {
|
||||
int go = body2id(body);
|
||||
|
@ -101,8 +95,7 @@ void querylistbodies(cpBody *body, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
int *phys2d_query_box_points(cpVect pos, cpVect wh, cpVect *points, int n)
|
||||
{
|
||||
int *phys2d_query_box_points(cpVect pos, cpVect wh, cpVect *points, int n) {
|
||||
cpShape *box = cpBoxShapeNew(NULL, wh.x, wh.y, 0.f);
|
||||
cpTransform T = {0};
|
||||
T.a = 1;
|
||||
|
@ -123,8 +116,7 @@ int *phys2d_query_box_points(cpVect pos, cpVect wh, cpVect *points, int n)
|
|||
return qhits;
|
||||
}
|
||||
|
||||
int *phys2d_query_box(cpVect pos, cpVect wh)
|
||||
{
|
||||
int *phys2d_query_box(cpVect pos, cpVect wh) {
|
||||
cpShape *box = cpBoxShapeNew(NULL, wh.x, wh.y, 0.f);
|
||||
cpTransform T = {0};
|
||||
T.a = 1;
|
||||
|
@ -145,8 +137,7 @@ int *phys2d_query_box(cpVect pos, cpVect wh)
|
|||
return qhits;
|
||||
}
|
||||
|
||||
int *phys2d_query_shape(struct phys2d_shape *shape)
|
||||
{
|
||||
int *phys2d_query_shape(struct phys2d_shape *shape) {
|
||||
if (qhits) arrfree(qhits);
|
||||
|
||||
cpSpaceShapeQuery(space, shape->shape, querylist, NULL);
|
||||
|
@ -154,8 +145,7 @@ int *phys2d_query_shape(struct phys2d_shape *shape)
|
|||
return qhits;
|
||||
}
|
||||
|
||||
int cpshape_enabled(cpShape *c)
|
||||
{
|
||||
int cpshape_enabled(cpShape *c) {
|
||||
cpShapeFilter filter = cpShapeGetFilter(c);
|
||||
if (filter.categories == ~CP_ALL_CATEGORIES && filter.mask == ~CP_ALL_CATEGORIES)
|
||||
return 0;
|
||||
|
@ -163,8 +153,7 @@ int cpshape_enabled(cpShape *c)
|
|||
return 1;
|
||||
}
|
||||
|
||||
float *shape_outline_color(cpShape *shape)
|
||||
{
|
||||
float *shape_outline_color(cpShape *shape) {
|
||||
switch (cpBodyGetType(cpShapeGetBody(shape))) {
|
||||
case CP_BODY_TYPE_DYNAMIC:
|
||||
return dynamic_color;
|
||||
|
@ -179,8 +168,7 @@ float *shape_outline_color(cpShape *shape)
|
|||
return static_color;
|
||||
}
|
||||
|
||||
float *shape_color(cpShape *shape)
|
||||
{
|
||||
float *shape_color(cpShape *shape) {
|
||||
if (!cpshape_enabled(shape)) return disabled_color;
|
||||
|
||||
if (cpShapeGetSensor(shape)) return trigger_color;
|
||||
|
@ -188,8 +176,7 @@ float *shape_color(cpShape *shape)
|
|||
return dbg_color;
|
||||
}
|
||||
|
||||
struct color shape_color_s(cpShape *shape)
|
||||
{
|
||||
struct color shape_color_s(cpShape *shape) {
|
||||
float *c = shape_color(shape);
|
||||
struct color col;
|
||||
col.r = c[0] * 255;
|
||||
|
@ -198,8 +185,7 @@ struct color shape_color_s(cpShape *shape)
|
|||
return col;
|
||||
}
|
||||
|
||||
void phys2d_init()
|
||||
{
|
||||
void phys2d_init() {
|
||||
space = cpSpaceNew();
|
||||
cpVect grav = {0, phys2d_gravity};
|
||||
phys2d_set_gravity(grav);
|
||||
|
@ -211,13 +197,11 @@ void phys2d_set_gravity(cpVect v) {
|
|||
cpSpaceSetGravity(space, v);
|
||||
}
|
||||
|
||||
void phys2d_update(float deltaT)
|
||||
{
|
||||
void phys2d_update(float deltaT) {
|
||||
cpSpaceStep(space, deltaT);
|
||||
}
|
||||
|
||||
void init_phys2dshape(struct phys2d_shape *shape, int go, void *data)
|
||||
{
|
||||
void init_phys2dshape(struct phys2d_shape *shape, int go, void *data) {
|
||||
shape->go = go;
|
||||
shape->data = data;
|
||||
go_shape_apply(id2go(go)->body, shape->shape, id2go(go));
|
||||
|
@ -225,16 +209,14 @@ void init_phys2dshape(struct phys2d_shape *shape, int go, void *data)
|
|||
cpShapeSetUserData(shape->shape, shape);
|
||||
}
|
||||
|
||||
void phys2d_shape_del(struct phys2d_shape *shape)
|
||||
{
|
||||
void phys2d_shape_del(struct phys2d_shape *shape) {
|
||||
if (!shape->shape) return;
|
||||
cpSpaceRemoveShape(space, shape->shape);
|
||||
cpShapeFree(shape->shape);
|
||||
}
|
||||
|
||||
/***************** CIRCLE2D *****************/
|
||||
struct phys2d_circle *Make2DCircle(int go)
|
||||
{
|
||||
struct phys2d_circle *Make2DCircle(int go) {
|
||||
struct phys2d_circle *new = malloc(sizeof(struct phys2d_circle));
|
||||
|
||||
new->radius = 10.f;
|
||||
|
@ -248,18 +230,15 @@ struct phys2d_circle *Make2DCircle(int go)
|
|||
return new;
|
||||
}
|
||||
|
||||
float phys2d_circle_moi(struct phys2d_circle *c, float m)
|
||||
{
|
||||
float phys2d_circle_moi(struct phys2d_circle *c, float m) {
|
||||
return cpMomentForCircle(m, 0, c->radius, c->offset);
|
||||
}
|
||||
|
||||
void phys2d_circledel(struct phys2d_circle *c)
|
||||
{
|
||||
void phys2d_circledel(struct phys2d_circle *c) {
|
||||
phys2d_shape_del(&c->shape);
|
||||
}
|
||||
|
||||
cpVect world2go(struct gameobject *go, cpVect worldpos)
|
||||
{
|
||||
cpVect world2go(struct gameobject *go, cpVect worldpos) {
|
||||
cpTransform T = {0};
|
||||
cpVect pos = cpBodyGetPosition(go->body);
|
||||
worldpos.x -= pos.x;
|
||||
|
@ -276,8 +255,7 @@ cpVect world2go(struct gameobject *go, cpVect worldpos)
|
|||
return worldpos;
|
||||
}
|
||||
|
||||
cpVect go2world(struct gameobject *go, cpVect gopos)
|
||||
{
|
||||
cpVect go2world(struct gameobject *go, cpVect gopos) {
|
||||
cpVect pos = cpBodyGetPosition(go->body);
|
||||
float angle = cpBodyGetAngle(go->body);
|
||||
cpTransform T = {0};
|
||||
|
@ -290,15 +268,13 @@ cpVect go2world(struct gameobject *go, cpVect gopos)
|
|||
return cpTransformPoint(T, gopos);
|
||||
}
|
||||
|
||||
cpVect gotransformpoint(struct gameobject *go, cpVect point)
|
||||
{
|
||||
cpVect gotransformpoint(struct gameobject *go, cpVect point) {
|
||||
point.x *= go->scale * go->flipx;
|
||||
point.y *= go->scale * go->flipy;
|
||||
return point;
|
||||
}
|
||||
|
||||
cpVect bodytransformpoint(cpBody *body, cpVect offset)
|
||||
{
|
||||
cpVect bodytransformpoint(cpBody *body, cpVect offset) {
|
||||
cpVect pos = cpBodyGetPosition(body);
|
||||
float d = sqrt(pow(offset.x, 2.f) + pow(offset.y, 2.f));
|
||||
float a = atan2(offset.y, offset.x) + cpBodyGetAngle(body);
|
||||
|
@ -307,20 +283,17 @@ cpVect bodytransformpoint(cpBody *body, cpVect offset)
|
|||
return pos;
|
||||
}
|
||||
|
||||
void phys2d_dbgdrawcpcirc(cpCircleShape *c)
|
||||
{
|
||||
void phys2d_dbgdrawcpcirc(cpCircleShape *c) {
|
||||
cpVect pos = bodytransformpoint(cpShapeGetBody(c), cpCircleShapeGetOffset(c));
|
||||
float radius = cpCircleShapeGetRadius(c);
|
||||
draw_circle(pos.x, pos.y, radius, 2, shape_color(c), 1);
|
||||
}
|
||||
|
||||
void phys2d_dbgdrawcircle(struct phys2d_circle *circle)
|
||||
{
|
||||
void phys2d_dbgdrawcircle(struct phys2d_circle *circle) {
|
||||
phys2d_dbgdrawcpcirc((cpCircleShape *)circle->shape.shape);
|
||||
}
|
||||
|
||||
void phys2d_applycircle(struct phys2d_circle *circle)
|
||||
{
|
||||
void phys2d_applycircle(struct phys2d_circle *circle) {
|
||||
struct gameobject *go = id2go(circle->shape.go);
|
||||
|
||||
float radius = circle->radius * go->scale;
|
||||
|
@ -332,8 +305,7 @@ void phys2d_applycircle(struct phys2d_circle *circle)
|
|||
|
||||
/************* BOX2D ************/
|
||||
|
||||
struct phys2d_box *Make2DBox(int go)
|
||||
{
|
||||
struct phys2d_box *Make2DBox(int go) {
|
||||
struct phys2d_box *new = malloc(sizeof(struct phys2d_box));
|
||||
|
||||
new->w = 50.f;
|
||||
|
@ -349,13 +321,11 @@ struct phys2d_box *Make2DBox(int go)
|
|||
return new;
|
||||
}
|
||||
|
||||
float phys2d_box_moi(struct phys2d_box *box, float m)
|
||||
{
|
||||
float phys2d_box_moi(struct phys2d_box *box, float m) {
|
||||
return cpMomentForBox(m, box->w, box->h);
|
||||
}
|
||||
|
||||
cpTransform go2transform(struct gameobject *go, cpVect offset, float angle)
|
||||
{
|
||||
cpTransform go2transform(struct gameobject *go, cpVect offset, float angle) {
|
||||
cpTransform T = {0};
|
||||
T.a = cos(angle) * go->scale * go->flipx;
|
||||
T.b = -sin(angle) * go->scale * go->flipx;
|
||||
|
@ -366,13 +336,11 @@ cpTransform go2transform(struct gameobject *go, cpVect offset, float angle)
|
|||
return T;
|
||||
}
|
||||
|
||||
void phys2d_boxdel(struct phys2d_box *box)
|
||||
{
|
||||
void phys2d_boxdel(struct phys2d_box *box) {
|
||||
phys2d_shape_del(&box->shape);
|
||||
}
|
||||
|
||||
void phys2d_applybox(struct phys2d_box *box)
|
||||
{
|
||||
void phys2d_applybox(struct phys2d_box *box) {
|
||||
phys2d_boxdel(box);
|
||||
struct gameobject *go = id2go(box->shape.go);
|
||||
cpVect off;
|
||||
|
@ -386,23 +354,18 @@ void phys2d_applybox(struct phys2d_box *box)
|
|||
init_phys2dshape(&box->shape, box->shape.go, box);
|
||||
}
|
||||
|
||||
void phys2d_dbgdrawbox(struct phys2d_box *box)
|
||||
{
|
||||
void phys2d_dbgdrawbox(struct phys2d_box *box) {
|
||||
int n = cpPolyShapeGetCount(box->shape.shape);
|
||||
float points[n * 2];
|
||||
cpVect points[n * 2];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
cpVect p = bodytransformpoint(cpShapeGetBody(box->shape.shape), cpPolyShapeGetVert(box->shape.shape, i));
|
||||
points[i*2] = p.x;
|
||||
points[i*2+1] = p.y;
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
points[i] = bodytransformpoint(cpShapeGetBody(box->shape.shape), cpPolyShapeGetVert(box->shape.shape, i));
|
||||
|
||||
draw_poly(points, n, shape_color(box->shape.shape));
|
||||
}
|
||||
/************** POLYGON ************/
|
||||
|
||||
struct phys2d_poly *Make2DPoly(int go)
|
||||
{
|
||||
struct phys2d_poly *Make2DPoly(int go) {
|
||||
struct phys2d_poly *new = malloc(sizeof(struct phys2d_poly));
|
||||
|
||||
new->points = NULL;
|
||||
|
@ -416,8 +379,7 @@ struct phys2d_poly *Make2DPoly(int go)
|
|||
return new;
|
||||
}
|
||||
|
||||
float phys2d_poly_moi(struct phys2d_poly *poly, float m)
|
||||
{
|
||||
float phys2d_poly_moi(struct phys2d_poly *poly, float m) {
|
||||
float moi = cpMomentForPoly(m, arrlen(poly->points), poly->points, cpvzero, poly->radius);
|
||||
if (moi <= 0) {
|
||||
YughError("Polygon MOI is negative. Returning one;");
|
||||
|
@ -427,27 +389,23 @@ float phys2d_poly_moi(struct phys2d_poly *poly, float m)
|
|||
return moi;
|
||||
}
|
||||
|
||||
void phys2d_polydel(struct phys2d_poly *poly)
|
||||
{
|
||||
void phys2d_polydel(struct phys2d_poly *poly) {
|
||||
arrfree(poly->points);
|
||||
phys2d_shape_del(&poly->shape);
|
||||
}
|
||||
|
||||
void phys2d_polyaddvert(struct phys2d_poly *poly)
|
||||
{
|
||||
void phys2d_polyaddvert(struct phys2d_poly *poly) {
|
||||
arrput(poly->points, cpvzero);
|
||||
}
|
||||
|
||||
void phys2d_poly_setverts(struct phys2d_poly *poly, cpVect *verts)
|
||||
{
|
||||
void phys2d_poly_setverts(struct phys2d_poly *poly, cpVect *verts) {
|
||||
if (!verts) return;
|
||||
arrfree(poly->points);
|
||||
poly->points = verts;
|
||||
phys2d_applypoly(poly);
|
||||
}
|
||||
|
||||
void phys2d_applypoly(struct phys2d_poly *poly)
|
||||
{
|
||||
void phys2d_applypoly(struct phys2d_poly *poly) {
|
||||
if (arrlen(poly->points) <= 0) return;
|
||||
struct gameobject *go = id2go(poly->shape.go);
|
||||
|
||||
|
@ -457,28 +415,22 @@ void phys2d_applypoly(struct phys2d_poly *poly)
|
|||
cpPolyShapeSetRadius(poly->shape.shape, poly->radius);
|
||||
cpSpaceReindexShapesForBody(space, cpShapeGetBody(poly->shape.shape));
|
||||
}
|
||||
void phys2d_dbgdrawpoly(struct phys2d_poly *poly)
|
||||
{
|
||||
void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
|
||||
float *color = shape_color(poly->shape.shape);
|
||||
|
||||
if (arrlen(poly->points) >= 3) {
|
||||
int n = cpPolyShapeGetCount(poly->shape.shape);
|
||||
float points[n * 2];
|
||||
cpVect points[n];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
cpVect p = bodytransformpoint(cpShapeGetBody(poly->shape.shape), cpPolyShapeGetVert(poly->shape.shape, i));
|
||||
points[i*2] = p.x;
|
||||
points[i*2+1] = p.y;
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
points[i] = bodytransformpoint(cpShapeGetBody(poly->shape.shape), cpPolyShapeGetVert(poly->shape.shape, i));
|
||||
|
||||
draw_poly(points, n, color);
|
||||
}
|
||||
|
||||
}
|
||||
/****************** EDGE 2D**************/
|
||||
|
||||
struct phys2d_edge *Make2DEdge(int go)
|
||||
{
|
||||
struct phys2d_edge *Make2DEdge(int go) {
|
||||
struct phys2d_edge *new = malloc(sizeof(struct phys2d_edge));
|
||||
new->points = NULL;
|
||||
arrsetlen(new->points, 0);
|
||||
|
@ -495,8 +447,7 @@ struct phys2d_edge *Make2DEdge(int go)
|
|||
return new;
|
||||
}
|
||||
|
||||
float phys2d_edge_moi(struct phys2d_edge *edge, float m)
|
||||
{
|
||||
float phys2d_edge_moi(struct phys2d_edge *edge, float m) {
|
||||
float moi = 0;
|
||||
for (int i = 0; i < arrlen(edge->points) - 1; i++)
|
||||
moi += cpMomentForSegment(m, edge->points[i], edge->points[i + 1], edge->thickness);
|
||||
|
@ -504,13 +455,11 @@ float phys2d_edge_moi(struct phys2d_edge *edge, float m)
|
|||
return moi;
|
||||
}
|
||||
|
||||
void phys2d_edgedel(struct phys2d_edge *edge)
|
||||
{
|
||||
void phys2d_edgedel(struct phys2d_edge *edge) {
|
||||
phys2d_shape_del(&edge->shape);
|
||||
}
|
||||
|
||||
void phys2d_edgeaddvert(struct phys2d_edge *edge)
|
||||
{
|
||||
void phys2d_edgeaddvert(struct phys2d_edge *edge) {
|
||||
arrput(edge->points, cpvzero);
|
||||
if (arrlen(edge->points) > 1)
|
||||
arrput(edge->shapes, cpSpaceAddShape(space, cpSegmentShapeNew(id2go(edge->shape.go)->body, cpvzero, cpvzero, edge->thickness)));
|
||||
|
@ -518,15 +467,13 @@ void phys2d_edgeaddvert(struct phys2d_edge *edge)
|
|||
phys2d_applyedge(edge);
|
||||
}
|
||||
|
||||
void phys2d_edge_rmvert(struct phys2d_edge *edge, int index)
|
||||
{
|
||||
void phys2d_edge_rmvert(struct phys2d_edge *edge, int index) {
|
||||
assert(arrlen(edge->points) > index && index >= 0);
|
||||
|
||||
arrdel(edge->points, index);
|
||||
|
||||
if (arrlen(edge->points) == 0) return;
|
||||
|
||||
|
||||
if (index == 0) {
|
||||
cpSpaceRemoveShape(space, edge->shapes[index]);
|
||||
cpShapeFree(edge->shapes[index]);
|
||||
|
@ -546,31 +493,27 @@ void phys2d_edge_rmvert(struct phys2d_edge *edge, int index)
|
|||
phys2d_applyedge(edge);
|
||||
}
|
||||
|
||||
void phys2d_edge_setvert(struct phys2d_edge *edge, int index, cpVect val)
|
||||
{
|
||||
void phys2d_edge_setvert(struct phys2d_edge *edge, int index, cpVect val) {
|
||||
assert(arrlen(edge->points) > index && index >= 0);
|
||||
edge->points[index] = val;
|
||||
|
||||
phys2d_applyedge(edge);
|
||||
}
|
||||
|
||||
void phys2d_edge_clearverts(struct phys2d_edge *edge)
|
||||
{
|
||||
void phys2d_edge_clearverts(struct phys2d_edge *edge) {
|
||||
for (int i = arrlen(edge->points) - 1; i >= 0; i--) {
|
||||
phys2d_edge_rmvert(edge, i);
|
||||
}
|
||||
}
|
||||
|
||||
void phys2d_edge_addverts(struct phys2d_edge *edge, cpVect *verts)
|
||||
{
|
||||
void phys2d_edge_addverts(struct phys2d_edge *edge, cpVect *verts) {
|
||||
for (int i = 0; i < arrlen(verts); i++) {
|
||||
phys2d_edgeaddvert(edge);
|
||||
phys2d_edge_setvert(edge, i, verts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void phys2d_applyedge(struct phys2d_edge *edge)
|
||||
{
|
||||
void phys2d_applyedge(struct phys2d_edge *edge) {
|
||||
struct gameobject *go = id2go(edge->shape.go);
|
||||
|
||||
for (int i = 0; i < arrlen(edge->shapes); i++) {
|
||||
|
@ -587,8 +530,7 @@ void phys2d_applyedge(struct phys2d_edge *edge)
|
|||
cpSpaceReindexShapesForBody(space, id2go(edge->shape.go)->body);
|
||||
}
|
||||
|
||||
void phys2d_dbgdrawedge(struct phys2d_edge *edge)
|
||||
{
|
||||
void phys2d_dbgdrawedge(struct phys2d_edge *edge) {
|
||||
edge->draws++;
|
||||
if (edge->draws > 1) {
|
||||
if (edge->draws >= arrlen(edge->shapes))
|
||||
|
@ -611,26 +553,22 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge)
|
|||
draw_points(drawpoints, arrlen(edge->points), 2, kinematic_color);
|
||||
}
|
||||
|
||||
|
||||
/************ COLLIDER ****************/
|
||||
void shape_enabled(struct phys2d_shape *shape, int enabled)
|
||||
{
|
||||
void shape_enabled(struct phys2d_shape *shape, int enabled) {
|
||||
if (enabled)
|
||||
cpShapeSetFilter(shape->data, CP_SHAPE_FILTER_ALL);
|
||||
else
|
||||
cpShapeSetFilter(shape->data, CP_SHAPE_FILTER_NONE);
|
||||
}
|
||||
|
||||
int shape_is_enabled(struct phys2d_shape *shape)
|
||||
{
|
||||
int shape_is_enabled(struct phys2d_shape *shape) {
|
||||
if (cpshape_enabled(shape->shape))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void shape_set_sensor(struct phys2d_shape *shape, int sensor)
|
||||
{
|
||||
void shape_set_sensor(struct phys2d_shape *shape, int sensor) {
|
||||
if (!shape->shape) {
|
||||
struct phys2d_edge *edge = shape->data;
|
||||
|
||||
|
@ -640,8 +578,7 @@ void shape_set_sensor(struct phys2d_shape *shape, int sensor)
|
|||
cpShapeSetSensor(shape->shape, sensor);
|
||||
}
|
||||
|
||||
int shape_get_sensor(struct phys2d_shape *shape)
|
||||
{
|
||||
int shape_get_sensor(struct phys2d_shape *shape) {
|
||||
if (!shape->shape) {
|
||||
return cpShapeGetSensor(((struct phys2d_edge *)(shape->data))->shapes[0]);
|
||||
}
|
||||
|
@ -652,8 +589,7 @@ void phys2d_reindex_body(cpBody *body) {
|
|||
cpSpaceReindexShapesForBody(space, body);
|
||||
}
|
||||
|
||||
void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb)
|
||||
{
|
||||
void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb) {
|
||||
cpShape *shape1;
|
||||
cpShape *shape2;
|
||||
cpArbiterGetShapes(arb, &shape1, &shape2);
|
||||
|
@ -669,8 +605,7 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb)
|
|||
#define CTYPE_BEGIN 0
|
||||
#define CTYPE_SEP 1
|
||||
|
||||
static cpBool handle_collision(cpArbiter *arb, int type)
|
||||
{
|
||||
static cpBool handle_collision(cpArbiter *arb, int type) {
|
||||
cpBody *body1;
|
||||
cpBody *body2;
|
||||
cpArbiterGetBodies(arb, &body1, &body2);
|
||||
|
@ -705,32 +640,27 @@ static cpBool handle_collision(cpArbiter *arb, int type)
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cpBool script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data)
|
||||
{
|
||||
static cpBool script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data) {
|
||||
return handle_collision(arb, CTYPE_BEGIN);
|
||||
}
|
||||
|
||||
static cpBool script_phys_cb_separate(cpArbiter *arb, cpSpace *space, void *data)
|
||||
{
|
||||
static cpBool script_phys_cb_separate(cpArbiter *arb, cpSpace *space, void *data) {
|
||||
return handle_collision(arb, CTYPE_SEP);
|
||||
}
|
||||
|
||||
void phys2d_rm_go_handlers(int go)
|
||||
{
|
||||
void phys2d_rm_go_handlers(int go) {
|
||||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
||||
handler->userData = NULL;
|
||||
handler->beginFunc = NULL;
|
||||
handler->separateFunc = NULL;
|
||||
}
|
||||
|
||||
void phys2d_setup_handlers(int go)
|
||||
{
|
||||
void phys2d_setup_handlers(int go) {
|
||||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
||||
handler->userData = (void *)go;
|
||||
handler->beginFunc = script_phys_cb_begin;
|
||||
|
@ -739,13 +669,11 @@ void phys2d_setup_handlers(int go)
|
|||
|
||||
static int airborne = 0;
|
||||
|
||||
void inair(cpBody *body, cpArbiter *arbiter, void *data)
|
||||
{
|
||||
void inair(cpBody *body, cpArbiter *arbiter, void *data) {
|
||||
airborne = 0;
|
||||
}
|
||||
|
||||
int phys2d_in_air(cpBody *body)
|
||||
{
|
||||
int phys2d_in_air(cpBody *body) {
|
||||
airborne = 1;
|
||||
cpBodyEachArbiter(body, inair, NULL);
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef TWODPHYSICS_H
|
||||
#define TWODPHYSICS_H
|
||||
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include "script.h"
|
||||
#include <chipmunk/chipmunk.h>
|
||||
|
||||
struct gameobject;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef THREEDPHYSICS_H
|
||||
#define THREEDPHYSICS_H
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "light.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/*
|
||||
void Light::serialize(FILE * file)
|
||||
{
|
||||
|
|
|
@ -4,32 +4,31 @@
|
|||
#include "shader.h"
|
||||
#include "texture.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void DrawMesh(struct mesh *mesh, struct shader *shader)
|
||||
{
|
||||
void DrawMesh(struct mesh *mesh, struct shader *shader) {
|
||||
// bind appropriate textures
|
||||
uint32_t diffuseNr = 1;
|
||||
uint32_t specularNr = 1;
|
||||
uint32_t normalNr = 1;
|
||||
uint32_t heightNr = 1;
|
||||
|
||||
for (int i = 0; i < (mesh->te - mesh->textures); i++) {
|
||||
// for (int i = 0; i < (mesh->te - mesh->textures); i++) {
|
||||
// glActiveTexture(GL_TEXTURE0 + i); // active proper texture unit before binding
|
||||
// retrieve texture number (the N in diffuse_textureN)
|
||||
char number = 0;
|
||||
// char number = 0;
|
||||
// TODO: malloc every single frame ... nope! Change to stack
|
||||
/*char *name = malloc(sizeof(char) *(strlen(mesh->textures[i].type) + 2));*/
|
||||
/*
|
||||
if (mesh->textures[i].type == TEX_DIFF)
|
||||
number = diffuseNr++;
|
||||
else if (mesh->textures[i].type == TEX_SPEC)
|
||||
number = specularNr++;
|
||||
else if (mesh->textures[i].type == TEX_NORM)
|
||||
number = normalNr++;
|
||||
else if (mesh->textures[i].type == TEX_HEIGHT)
|
||||
number = heightNr++;
|
||||
// if (mesh->textures[i].type == TEX_DIFF)
|
||||
// number = diffuseNr++;
|
||||
// else if (mesh->textures[i].type == TEX_SPEC)
|
||||
// number = specularNr++;
|
||||
// else if (mesh->textures[i].type == TEX_NORM)
|
||||
// number = normalNr++;
|
||||
// else if (mesh->textures[i].type == TEX_HEIGHT)
|
||||
// number = heightNr++;
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -39,37 +38,10 @@ void DrawMesh(struct mesh *mesh, struct shader *shader)
|
|||
*/
|
||||
}
|
||||
|
||||
// draw mesh
|
||||
glBindVertexArray(mesh->VAO);
|
||||
DrawMeshAgain(mesh);
|
||||
|
||||
// DEBUG
|
||||
// triCount += indices.size() / 3;
|
||||
void DrawMeshAgain(struct mesh *mesh) {
|
||||
}
|
||||
|
||||
|
||||
void DrawMeshAgain(struct mesh *mesh)
|
||||
{
|
||||
}
|
||||
|
||||
struct mesh *MakeMesh(struct Vertex *vertices, struct Vertex *ve,
|
||||
uint32_t * indices, uint32_t * ie,
|
||||
struct Texture *textures, struct Texture *te)
|
||||
{
|
||||
struct mesh *newmesh = (struct mesh *) malloc(sizeof(struct mesh));
|
||||
newmesh->vertices = vertices;
|
||||
newmesh->ve = ve;
|
||||
newmesh->indices = indices;
|
||||
newmesh->ie = ie;
|
||||
newmesh->textures = textures;
|
||||
newmesh->te = te;
|
||||
|
||||
setupmesh(newmesh);
|
||||
return newmesh;
|
||||
}
|
||||
|
||||
void setupmesh(struct mesh *mesh)
|
||||
{
|
||||
void setupmesh(struct mesh *mesh) {
|
||||
/*
|
||||
// create buffers/arrays
|
||||
glGenVertexArrays(1, &mesh->VAO);
|
||||
|
|
|
@ -2,38 +2,18 @@
|
|||
#define MESH_H
|
||||
|
||||
#include "mathc.h"
|
||||
#include "sokol/sokol_gfx.h"
|
||||
#include <stdint.h>
|
||||
|
||||
struct shader;
|
||||
struct Texture;
|
||||
|
||||
#define MAX_BONE_INFLUENCE 4
|
||||
|
||||
struct Vertex {
|
||||
mfloat_t Position[3];
|
||||
mfloat_t Normal[3];
|
||||
mfloat_t TexCoords[2];
|
||||
mfloat_t Tangent[3];
|
||||
mfloat_t Bitangent[3];
|
||||
|
||||
int m_BoneIDs[MAX_BONE_INFLUENCE];
|
||||
|
||||
float m_Weights[MAX_BONE_INFLUENCE];
|
||||
};
|
||||
|
||||
struct mesh {
|
||||
struct Vertex *vertices;
|
||||
struct Vertex *ve;
|
||||
uint32_t *indices;
|
||||
uint32_t *ie;
|
||||
struct Texture *textures;
|
||||
struct Texture *te;
|
||||
uint32_t VAO, VBO, EBO;
|
||||
sg_bindings bind;
|
||||
uint32_t face_count;
|
||||
};
|
||||
|
||||
struct mesh *MakeMesh(struct Vertex *vertices, struct Vertex *ve,
|
||||
uint32_t * indices, uint32_t * ie,
|
||||
struct Texture *textures, struct Texture *te);
|
||||
struct mesh *MakeMesh(struct Vertex *vertices, struct Vertex *ve, uint32_t *indices, uint32_t *ie, struct Texture *textures, struct Texture *te);
|
||||
void setupmesh(struct mesh *mesh); /* Loads mesh into the GPU */
|
||||
void DrawMesh(struct mesh *mesh, struct shader *shader);
|
||||
void DrawMeshAgain(struct mesh *mesh); /* Draws whatever mesh was drawn last */
|
||||
|
|
|
@ -5,10 +5,27 @@
|
|||
#include "resources.h"
|
||||
#include "shader.h"
|
||||
#include "stb_ds.h"
|
||||
#include "font.h"
|
||||
|
||||
#include "openglrender.h"
|
||||
|
||||
// #define HANDMADE_MATH_USE_TURNS
|
||||
#include "HandmadeMath.h"
|
||||
|
||||
#include "math.h"
|
||||
#include "time.h"
|
||||
|
||||
#define CGLTF_IMPLEMENTATION
|
||||
#include <cgltf.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
#include "mathc.h"
|
||||
|
||||
#include "sokol/sokol_gfx.h"
|
||||
|
||||
static struct {
|
||||
char *key;
|
||||
struct Texture *value;
|
||||
|
@ -18,6 +35,59 @@ static void processnode();
|
|||
static void processmesh();
|
||||
static void processtexture();
|
||||
|
||||
static sg_shader model_shader;
|
||||
static sg_pipeline model_pipe;
|
||||
|
||||
void model_init() {
|
||||
YughWarn("Creating model");
|
||||
model_shader = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/diffuse_v.glsl"),
|
||||
.fs.source = slurp_text("shaders/diffuse_f.glsl"),
|
||||
.vs.uniform_blocks[0] = {
|
||||
.size = sizeof(float) * 16 * 4,
|
||||
.uniforms = {
|
||||
[0] = {.name = "vp", .type = SG_UNIFORMTYPE_MAT4},
|
||||
[1] = {.name = "model", .type = SG_UNIFORMTYPE_MAT4},
|
||||
[2] = {.name = "proj", .type = SG_UNIFORMTYPE_MAT4},
|
||||
[3] = {.name = "lsm", .type = SG_UNIFORMTYPE_MAT4},
|
||||
}},
|
||||
|
||||
.fs.uniform_blocks[0] = {
|
||||
.size = sizeof(float) * 3 * 5,
|
||||
.uniforms = {
|
||||
[0] = {.name = "point_pos", .type = SG_UNIFORMTYPE_FLOAT3},
|
||||
[1] = {.name = "dir_dir", .type = SG_UNIFORMTYPE_FLOAT3},
|
||||
[2] = {.name = "view_pos", .type = SG_UNIFORMTYPE_FLOAT3},
|
||||
[3] = {.name = "spot_pos", .type = SG_UNIFORMTYPE_FLOAT3},
|
||||
[4] = {.name = "spot_dir", .type = SG_UNIFORMTYPE_FLOAT3},
|
||||
},
|
||||
},
|
||||
|
||||
.fs.images[0] = {.name = "diffuse", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT},
|
||||
.fs.images[1] = { .name = "normmap", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT},
|
||||
.fs.images[2] = {.name = "shadow_map", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT},
|
||||
|
||||
});
|
||||
|
||||
model_pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = model_shader,
|
||||
.layout = {
|
||||
.attrs = {
|
||||
[0].format = SG_VERTEXFORMAT_FLOAT3,
|
||||
[0].buffer_index = 0, /* position */
|
||||
[1].format = SG_VERTEXFORMAT_FLOAT2,
|
||||
[1].buffer_index = 1, /* tex coords */
|
||||
[2].format = SG_VERTEXFORMAT_FLOAT3,
|
||||
[2].buffer_index = 2, /* normal */
|
||||
},
|
||||
},
|
||||
.index_type = SG_INDEXTYPE_UINT16,
|
||||
.cull_mode = SG_CULLMODE_FRONT,
|
||||
.depth.write_enabled = true,
|
||||
.depth.compare = SG_COMPAREFUNC_LESS_EQUAL
|
||||
});
|
||||
}
|
||||
|
||||
struct model *GetExistingModel(const char *path) {
|
||||
if (!path || path[0] == '\0') return NULL;
|
||||
|
||||
|
@ -27,8 +97,18 @@ struct model *GetExistingModel(const char *path) {
|
|||
return MakeModel(path);
|
||||
}
|
||||
|
||||
/* TODO: Make this a hash compare for speedup */
|
||||
cgltf_attribute *get_attr_type(cgltf_primitive p, cgltf_attribute_type t)
|
||||
{
|
||||
for (int i = 0; i < p.attributes_count; i++) {
|
||||
if (p.attributes[i].type == t)
|
||||
return &p.attributes[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct model *MakeModel(const char *path) {
|
||||
YughWarn("Making the model from %s.", path);
|
||||
cgltf_options options = {0};
|
||||
cgltf_data *data = NULL;
|
||||
cgltf_result result = cgltf_parse_file(&options, path, &data);
|
||||
|
@ -45,188 +125,166 @@ struct model *MakeModel(const char *path) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct model *model = malloc(sizeof(struct model));
|
||||
struct model *model = calloc(1, sizeof(*model));
|
||||
/* TODO: Optimize by grouping by material. One material per draw. */
|
||||
YughWarn("Model has %d materials.", data->materials_count);
|
||||
|
||||
model->meshes = malloc(sizeof(struct mesh) * data->meshes_count);
|
||||
float vs[65535*3];
|
||||
uint16_t idxs[65535];
|
||||
|
||||
for (int i = 0; i < data->nodes_count; i++) {
|
||||
for (int i = 0; i < data->meshes_count; i++) {
|
||||
cgltf_mesh *mesh = &data->meshes[i];
|
||||
struct mesh newmesh = {0};
|
||||
arrput(model->meshes,newmesh);
|
||||
|
||||
if (data->nodes[i].mesh) {
|
||||
cgltf_mesh *mesh = data->nodes[i].mesh;
|
||||
YughWarn("Making mesh %d. It has %d primitives.", i, mesh->primitives_count);
|
||||
|
||||
for (int j = 0; j < mesh->primitives_count; j++) {
|
||||
cgltf_primitive primitive = mesh->primitives[j];
|
||||
|
||||
if (primitive.indices) {
|
||||
int c = primitive.indices->count;
|
||||
memcpy(idxs, cgltf_buffer_view_data(primitive.indices->buffer_view), sizeof(uint16_t) * c);
|
||||
|
||||
model->meshes[j].bind.index_buffer = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data.ptr = idxs,
|
||||
.data.size = sizeof(uint16_t) * c,
|
||||
.type = SG_BUFFERTYPE_INDEXBUFFER});
|
||||
|
||||
model->meshes[j].face_count = c;
|
||||
} else {
|
||||
YughWarn("Model does not have indices. Generating them.");
|
||||
int c = primitive.attributes[0].data->count;
|
||||
model->meshes[j].face_count = c;
|
||||
for (int z = 0; z < c; z++)
|
||||
idxs[z] = z;
|
||||
|
||||
model->meshes[j].bind.index_buffer = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data.ptr = idxs,
|
||||
.data.size = sizeof(uint16_t) * c,
|
||||
.type = SG_BUFFERTYPE_INDEXBUFFER});
|
||||
}
|
||||
|
||||
if (primitive.material->has_pbr_metallic_roughness && primitive.material->pbr_metallic_roughness.base_color_texture.texture) {
|
||||
// YughWarn("Texture is %s.", primitive.material->pbr_metallic_roughness.base_color_texture.texture->image->uri);
|
||||
|
||||
model->meshes[j].bind.fs_images[0] = texture_pullfromfile(primitive.material->pbr_metallic_roughness.base_color_texture.texture->image->uri)->id;
|
||||
} else
|
||||
model->meshes[j].bind.fs_images[0] = texture_pullfromfile("k")->id;
|
||||
|
||||
cgltf_texture *tex;
|
||||
if (tex = primitive.material->normal_texture.texture) {
|
||||
model->meshes[j].bind.fs_images[1] = texture_pullfromfile(tex->image->uri)->id;
|
||||
} else
|
||||
model->meshes[j].bind.fs_images[1] = texture_pullfromfile("k")->id;
|
||||
|
||||
model->meshes[j].bind.fs_images[2] = ddimg;
|
||||
|
||||
int has_norm = 0;
|
||||
|
||||
for (int k = 0; k < primitive.attributes_count; k++) {
|
||||
cgltf_attribute attribute = primitive.attributes[k];
|
||||
|
||||
switch (attribute.type) {
|
||||
int n = cgltf_accessor_unpack_floats(attribute.data, NULL, 0); /* floats per element x num elements */
|
||||
|
||||
cgltf_accessor_unpack_floats(attribute.data, vs, n);
|
||||
|
||||
switch (attribute.type) {
|
||||
case cgltf_attribute_type_position:
|
||||
// float *vs = malloc(sizeof(float) * cgltf_accessor_unpack_floats(attribute.accessor, NULL, attribute.accessor.count);
|
||||
// cgltf_accessor_unpack_floats(attribute.accessor, vs, attribute.accessor.count);
|
||||
model->meshes[j].bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data.ptr = vs,
|
||||
.data.size = sizeof(float) * n});
|
||||
break;
|
||||
|
||||
case cgltf_attribute_type_normal:
|
||||
has_norm = 1;
|
||||
model->meshes[j].bind.vertex_buffers[2] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data.ptr = vs,
|
||||
.data.size = sizeof(float) * n});
|
||||
break;
|
||||
|
||||
|
||||
case cgltf_attribute_type_tangent:
|
||||
break;
|
||||
|
||||
case cgltf_attribute_type_texcoord:
|
||||
model->meshes[j].bind.vertex_buffers[1] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data.ptr = vs,
|
||||
.data.size = sizeof(float) * n});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_norm) {
|
||||
YughWarn("Model does not have normals. Generating them.");
|
||||
float norms[3 * model->meshes[j].face_count];
|
||||
|
||||
|
||||
cgltf_attribute *pa = get_attr_type(primitive, cgltf_attribute_type_position);
|
||||
int n = cgltf_accessor_unpack_floats(pa->data, NULL,0);
|
||||
float ps[n];
|
||||
cgltf_accessor_unpack_floats(pa->data,ps,n);
|
||||
|
||||
for (int i = 0; i < model->meshes[j].face_count/3; i++) {
|
||||
int o = i*9;
|
||||
HMM_Vec3 a = {ps[o], ps[o+1],ps[o+2]};
|
||||
o += 3;
|
||||
HMM_Vec3 b = {ps[o], ps[o+1],ps[o+2]};
|
||||
o += 3;
|
||||
HMM_Vec3 c = {ps[o], ps[o+1],ps[o+2]};
|
||||
HMM_Vec3 norm = HMM_NormV3(HMM_Cross(HMM_SubV3(b,a), HMM_SubV3(c,a)));
|
||||
for (int j = 0; j < 3; j++) {
|
||||
norms[i*9+j*3+0] = norm.X;
|
||||
norms[i*9+j*3+1] = norm.Y;
|
||||
norms[i*9+j*3+2] = norm.Z;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: DELETE
|
||||
static void processnode() {
|
||||
|
||||
for (uint32_t i = 0; i < node->mNumMeshes; i++) {
|
||||
aiMesh *mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
*mp = processMesh(mesh, scene);
|
||||
mp++;
|
||||
model->meshes[j].bind.vertex_buffers[2] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data.ptr = norms,
|
||||
.data.size = sizeof(float) * model->meshes[j].face_count * 3
|
||||
});
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < node->mNumChildren; i++) {
|
||||
processnode(node->mChildren[i], scene);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
static void processmesh() {
|
||||
/*
|
||||
Vertex *vertices =
|
||||
(Vertex *) malloc(sizeof(Vertex) * mesh->mNumVertices);
|
||||
Vertex *vp = vertices + mesh->mNumVertices;
|
||||
Vertex *p = vertices;
|
||||
for (int i = 0; i < mesh->mNumVertices; i++) {
|
||||
// positions
|
||||
(p + i)->Position.x = mesh->mVertices[i][0];
|
||||
(p + i)->Position.y = mesh->mVertices[i][1];
|
||||
(p + i)->Position.z = mesh->mVertices[i][2];
|
||||
|
||||
|
||||
// normals
|
||||
if (mesh->HasNormals()) {
|
||||
(p + i)->Normal.x = mesh->mNormals[i][0];
|
||||
(p + i)->Normal.y = mesh->mNormals[i].y;
|
||||
(p + i)->Normal.z = mesh->mNormals[i].z;
|
||||
}
|
||||
|
||||
// texture coordinates
|
||||
if (mesh->mTextureCoords[0]) {
|
||||
glm::vec2 vec;
|
||||
// a vertex can contain up to 8 different texture coordinates. We thus make the assumption that we won't
|
||||
// use models where a vertex can have multiple texture coordinates so we always take the first set (0).
|
||||
(p + i)->TexCoords.x = mesh->mTextureCoords[0][i].x;
|
||||
(p + i)->TexCoords.y = mesh->mTextureCoords[0][i].y;
|
||||
|
||||
// tangent
|
||||
(p + i)->Tangent.x = mesh->mTangents[i].x;
|
||||
(p + i)->Tangent.y = mesh->mTangents[i].y;
|
||||
(p + i)->Tangent.z = mesh->mTangents[i].z;
|
||||
|
||||
// bitangent
|
||||
(p + i)->Bitangent.x = mesh->mBitangents[i].x;
|
||||
(p + i)->Bitangent.y = mesh->mBitangents[i].y;
|
||||
(p + i)->Bitangent.z = mesh->mBitangents[i].z;
|
||||
|
||||
} else
|
||||
(p + i)->TexCoords = glm::vec2(0.0f, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO: Done quickly, find better way. Go through for loop twice!
|
||||
int numindices = 0;
|
||||
// now walk through each of the mesh's faces (a face is a mesh its triangle) and retrieve the corresponding vertex indices.
|
||||
for (uint32_t i = 0; i < mesh->mNumFaces; i++) {
|
||||
numindices += mesh->mFaces[i].mNumIndices;
|
||||
}
|
||||
|
||||
uint32_t *indices = (uint32_t *) malloc(sizeof(uint32_t) * numindices);
|
||||
uint32_t *ip = indices;
|
||||
|
||||
for (uint32_t i = 0; i < mesh->mNumFaces; i++) {
|
||||
for (uint32_t j = 0; j < mesh->mFaces[i].mNumIndices; j++) {
|
||||
*ip = mesh->mFaces[i].mIndices[j];
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// std::vector<Texture> textures;
|
||||
aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];
|
||||
|
||||
// TODO: Allocating 100 to be safe, can probably be way less
|
||||
textures_loaded = (Texture *) malloc(sizeof(Texture) * 100);
|
||||
tp = textures_loaded;
|
||||
// we assume a convention for sampler names in the shaders. Each diffuse texture should be named
|
||||
// as 'texture_diffuseN' where N is a sequential number ranging from 1 to MAX_SAMPLER_NUMBER.
|
||||
// Same applies to other texture as the following list summarizes:
|
||||
// diffuse: texture_diffuseN
|
||||
// specular: texture_specularN
|
||||
// normal: texture_normalN
|
||||
|
||||
// 1. diffuse maps
|
||||
loadMaterialTextures(material, aiTextureType_DIFFUSE,
|
||||
"texture_diffuse");
|
||||
|
||||
// 2. specular maps
|
||||
loadMaterialTextures(material, aiTextureType_SPECULAR,
|
||||
"texture_specular");
|
||||
|
||||
// 3. normal maps
|
||||
loadMaterialTextures(material, aiTextureType_NORMALS,
|
||||
"texture_normal");
|
||||
|
||||
// 4. height maps
|
||||
loadMaterialTextures(material, aiTextureType_AMBIENT,
|
||||
"texture_height");
|
||||
|
||||
|
||||
// return a mesh object created from the extracted mesh data
|
||||
return Mesh(vertices, vp, indices, ip, textures_loaded, tp);
|
||||
|
||||
*/
|
||||
return model;
|
||||
}
|
||||
|
||||
// TODO: This routine mallocs inside the function
|
||||
static void processtexture() {
|
||||
/*
|
||||
for (uint32_t i = 0; i < mat->GetTextureCount(type); i++) {
|
||||
aiString str;
|
||||
mat->GetTexture(type, i, &str);
|
||||
for (Texture * tpp = textures_loaded; tpp != tp; tpp++) {
|
||||
if (strcmp(tpp->path, str.data) == 0)
|
||||
goto next; // Check if we already have this texture
|
||||
HMM_Vec3 eye = {50,10,5};
|
||||
|
||||
void draw_model(struct model *model, HMM_Mat4 amodel, HMM_Mat4 lsm) {
|
||||
HMM_Mat4 proj = HMM_Perspective_RH_ZO(45, 1200.f / 720, 0.1, 10000);
|
||||
HMM_Vec3 center = {0.f, 0.f, 0.f};
|
||||
HMM_Vec3 up = {0.f, 1.f, 0.f};
|
||||
HMM_Mat4 view = HMM_LookAt_RH(eye, center, up);
|
||||
|
||||
HMM_Mat4 vp = HMM_MulM4(proj, view);
|
||||
HMM_Mat4 mvp = HMM_MulM4(vp, amodel);
|
||||
|
||||
HMM_Vec3 lp = {1, 1, 1};
|
||||
HMM_Vec3 dir_dir = HMM_NormV3(HMM_SubV3(center, dirl_pos));
|
||||
|
||||
HMM_Mat4 m2[4];
|
||||
m2[0] = view;
|
||||
m2[1] = amodel;
|
||||
m2[2] = proj;
|
||||
m2[3] = lsm;
|
||||
|
||||
HMM_Vec3 f_ubo[5];
|
||||
f_ubo[0] = lp;
|
||||
f_ubo[1] = dir_dir;
|
||||
f_ubo[2] = eye;
|
||||
f_ubo[3] = eye;
|
||||
f_ubo[4] = eye;
|
||||
|
||||
sg_apply_pipeline(model_pipe);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(m2));
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, SG_RANGE_REF(f_ubo));
|
||||
|
||||
|
||||
for (int i = 0; i < arrlen(model->meshes); i++) {
|
||||
sg_apply_bindings(&model->meshes[i].bind);
|
||||
sg_draw(0, model->meshes[i].face_count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
tp->id = TextureFromFile(str.data, this->directory);
|
||||
tp->type = (char *) malloc(sizeof(char) * strlen(typeName));
|
||||
strcpy(tp->type, typeName);
|
||||
tp->path = (char *) malloc(sizeof(char) * strlen(str.data));
|
||||
strcpy(tp->path, str.data);
|
||||
|
||||
tp++;
|
||||
|
||||
next:;
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void draw_models(struct model *model, struct shader *shader)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// TODO: Come back to this; simple optimization
|
||||
void draw_model(struct model *model, struct shader *shader) {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#ifndef MODEL_H
|
||||
#define MODEL_H
|
||||
|
||||
struct mesh;
|
||||
#include "mesh.h"
|
||||
#include "HandmadeMath.h"
|
||||
|
||||
extern HMM_Vec3 eye;
|
||||
struct shader;
|
||||
|
||||
struct model {
|
||||
struct mesh *meshes;
|
||||
struct mesh *mp;
|
||||
};
|
||||
|
||||
/* Get the model at a path, or create and return if it doesn't exist */
|
||||
|
@ -18,7 +20,9 @@ struct model *MakeModel(const char *path);
|
|||
/* Load a model from memory into the GPU */
|
||||
void loadmodel(struct model *model);
|
||||
|
||||
void draw_model(struct model *model, struct shader *shader);
|
||||
void model_init();
|
||||
|
||||
void draw_model(struct model *model, HMM_Mat4 amodel, HMM_Mat4 lsm);
|
||||
void draw_models(struct model *model, struct shader *shader);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "skybox.h"
|
||||
|
||||
#include "shader.h"
|
||||
#include "camera.h"
|
||||
#include <string.h>
|
||||
#include "shader.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "openglrender.h"
|
||||
|
||||
|
@ -48,11 +48,9 @@ static const float skyboxVertices[216] = {
|
|||
1.0f, -1.0f, -1.0f,
|
||||
1.0f, -1.0f, -1.0f,
|
||||
-1.0f, -1.0f, 1.0f,
|
||||
1.0f, -1.0f, 1.0f
|
||||
};
|
||||
1.0f, -1.0f, 1.0f};
|
||||
|
||||
struct mSkybox *MakeSkybox(const char *cubemap)
|
||||
{
|
||||
struct mSkybox *MakeSkybox(const char *cubemap) {
|
||||
/*
|
||||
struct mSkybox *newskybox = malloc(sizeof(struct mSkybox));
|
||||
|
||||
|
@ -110,8 +108,7 @@ struct mSkybox *MakeSkybox(const char *cubemap)
|
|||
}
|
||||
|
||||
void skybox_draw(const struct mSkybox *skybox,
|
||||
const struct mCamera *camera)
|
||||
{
|
||||
const struct mCamera *camera) {
|
||||
/*
|
||||
shader_use(skybox->shader);
|
||||
|
||||
|
|
3553
source/engine/HandmadeMath.h
Normal file
3553
source/engine/HandmadeMath.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,311 +0,0 @@
|
|||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
/*
|
||||
* To support platform where unsigned long cannot be used interchangeably with
|
||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||
* unsigned long long or similar (this results in different C++ name mangling).
|
||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||
* platforms where the size of a pointer is larger than the size of long.
|
||||
*/
|
||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||
#define KHRONOS_USE_INTPTR_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef KHRONOS_USE_INTPTR_T
|
||||
typedef intptr_t khronos_intptr_t;
|
||||
typedef uintptr_t khronos_uintptr_t;
|
||||
#elif defined(_WIN64)
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
|
@ -1,6 +1,6 @@
|
|||
#include "anim.h"
|
||||
#include "stb_ds.h"
|
||||
#include "log.h"
|
||||
#include "stb_ds.h"
|
||||
|
||||
struct anim make_anim() {
|
||||
struct anim a = {0};
|
||||
|
|
|
@ -16,5 +16,4 @@ struct anim make_anim();
|
|||
struct anim anim_add_keyframe(struct anim a, struct keyframe f);
|
||||
double anim_val(struct anim anim, double t);
|
||||
|
||||
|
||||
#endif
|
|
@ -3,21 +3,18 @@
|
|||
#include "gameobject.h"
|
||||
#include "input.h"
|
||||
|
||||
|
||||
const float CAMERA_MINSPEED = 1.f;
|
||||
const float CAMERA_MAXSPEED = 300.f;
|
||||
const float CAMERA_ROTATESPEED = 6.f;
|
||||
|
||||
void cam_goto_object(struct mCamera *cam, struct mTransform *transform)
|
||||
{
|
||||
void cam_goto_object(struct mCamera *cam, struct mTransform *transform) {
|
||||
mfloat_t fwd[3] = {0.f};
|
||||
vec3_subtract(cam->transform.position, transform->position,
|
||||
vec3_multiply_f(fwd, trans_forward(fwd, transform),
|
||||
10.f));
|
||||
}
|
||||
|
||||
void cam_inverse_goto(struct mCamera *cam, struct mTransform *transform)
|
||||
{
|
||||
void cam_inverse_goto(struct mCamera *cam, struct mTransform *transform) {
|
||||
mfloat_t fwd[3] = {0.f};
|
||||
vec3_add(transform->position, cam->transform.position,
|
||||
vec3_multiply_f(fwd, trans_forward(fwd, &cam->transform),
|
||||
|
@ -25,8 +22,7 @@ void cam_inverse_goto(struct mCamera *cam, struct mTransform *transform)
|
|||
}
|
||||
|
||||
mfloat_t *getviewmatrix(mfloat_t view[16],
|
||||
const struct mCamera *const camera)
|
||||
{
|
||||
const struct mCamera *const camera) {
|
||||
mfloat_t fwd[3] = {0.f};
|
||||
mfloat_t look[3] = {0.f};
|
||||
vec3_rotate_quat(fwd, FORWARD, camera->transform.rotation);
|
||||
|
@ -39,8 +35,7 @@ mfloat_t *getviewmatrix(mfloat_t view[16],
|
|||
UP); */
|
||||
}
|
||||
|
||||
void camera_2d_update(struct mCamera *camera, float deltaT)
|
||||
{
|
||||
void camera_2d_update(struct mCamera *camera, float deltaT) {
|
||||
static mfloat_t frame[3];
|
||||
vec3_zero(frame);
|
||||
if (action_down(GLFW_KEY_W))
|
||||
|
@ -60,7 +55,6 @@ void camera_2d_update(struct mCamera *camera, float deltaT)
|
|||
vec3_multiply_f(frame, frame,
|
||||
camera->speed * speedMult * deltaT));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
|
||||
#define MAXPATH 256 /* 255 chars + null */
|
||||
#define MAXNAME 50
|
||||
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
#include "datastream.h"
|
||||
|
||||
#include "render.h"
|
||||
#include "config.h"
|
||||
#include "shader.h"
|
||||
#include "resources.h"
|
||||
#include "sound.h"
|
||||
#include <stdbool.h>
|
||||
#include "log.h"
|
||||
#include "texture.h"
|
||||
#include <stdlib.h>
|
||||
#include "mix.h"
|
||||
#include "limits.h"
|
||||
#include "iir.h"
|
||||
#include "dsp.h"
|
||||
#include "iir.h"
|
||||
#include "limits.h"
|
||||
#include "log.h"
|
||||
#include "mix.h"
|
||||
#include "render.h"
|
||||
#include "resources.h"
|
||||
#include "shader.h"
|
||||
#include "sound.h"
|
||||
#include "texture.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct shader *vid_shader;
|
||||
|
||||
static void ds_update_texture(uint32_t unit, uint32_t texture, plm_plane_t * plane)
|
||||
{
|
||||
static void ds_update_texture(uint32_t unit, uint32_t texture, plm_plane_t *plane) {
|
||||
/*
|
||||
glActiveTexture(unit);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
@ -25,8 +24,7 @@ static void ds_update_texture(uint32_t unit, uint32_t texture, plm_plane_t * pla
|
|||
*/
|
||||
}
|
||||
|
||||
static void render_frame(plm_t * mpeg, plm_frame_t * frame, void *user)
|
||||
{
|
||||
static void render_frame(plm_t *mpeg, plm_frame_t *frame, void *user) {
|
||||
struct datastream *ds = user;
|
||||
shader_use(ds->shader);
|
||||
/*
|
||||
|
@ -36,8 +34,7 @@ static void render_frame(plm_t * mpeg, plm_frame_t * frame, void *user)
|
|||
*/
|
||||
}
|
||||
|
||||
static void render_audio(plm_t * mpeg, plm_samples_t * samples, void *user)
|
||||
{
|
||||
static void render_audio(plm_t *mpeg, plm_samples_t *samples, void *user) {
|
||||
struct datastream *ds = user;
|
||||
short t;
|
||||
|
||||
|
@ -47,8 +44,7 @@ static void render_audio(plm_t * mpeg, plm_samples_t * samples, void *user)
|
|||
}
|
||||
}
|
||||
|
||||
struct Texture *ds_maketexture(struct datastream *ds)
|
||||
{
|
||||
struct Texture *ds_maketexture(struct datastream *ds) {
|
||||
/*
|
||||
struct Texture *new = malloc(sizeof(*new));
|
||||
new->id = ds->texture_cb;
|
||||
|
@ -58,8 +54,7 @@ struct Texture *ds_maketexture(struct datastream *ds)
|
|||
*/
|
||||
}
|
||||
|
||||
void ds_openvideo(struct datastream *ds, const char *video, const char *adriver)
|
||||
{
|
||||
void ds_openvideo(struct datastream *ds, const char *video, const char *adriver) {
|
||||
// ds_stop(ds);
|
||||
char buf[MAXPATH] = {'\0'};
|
||||
sprintf(buf, "%s%s", "video/", video);
|
||||
|
@ -74,8 +69,7 @@ void ds_openvideo(struct datastream *ds, const char *video, const char *adriver)
|
|||
plm_get_framerate(ds->plm),
|
||||
plm_get_samplerate(ds->plm),
|
||||
plm_get_num_audio_streams(ds->plm),
|
||||
plm_get_duration(ds->plm)
|
||||
);
|
||||
plm_get_duration(ds->plm));
|
||||
|
||||
ds->astream = soundstream_make();
|
||||
struct dsp_filter astream_filter;
|
||||
|
@ -87,7 +81,6 @@ void ds_openvideo(struct datastream *ds, const char *video, const char *adriver)
|
|||
struct dsp_iir *iir = lpf.data;
|
||||
iir->in = astream_filter;
|
||||
|
||||
|
||||
struct dsp_filter hpf = hpf_make(1, 2000);
|
||||
struct dsp_iir *hiir = hpf.data;
|
||||
hiir->in = astream_filter;
|
||||
|
@ -113,8 +106,7 @@ void ds_openvideo(struct datastream *ds, const char *video, const char *adriver)
|
|||
ds->playing = true;
|
||||
}
|
||||
|
||||
struct datastream *MakeDatastream()
|
||||
{
|
||||
struct datastream *MakeDatastream() {
|
||||
struct datastream *newds = malloc(sizeof(*newds));
|
||||
/*
|
||||
if (!vid_shader) vid_shader = MakeShader("videovert.glsl", "videofrag.glsl");
|
||||
|
@ -148,34 +140,29 @@ struct datastream *MakeDatastream()
|
|||
return newds;
|
||||
}
|
||||
|
||||
void ds_advance(struct datastream *ds, double s)
|
||||
{
|
||||
void ds_advance(struct datastream *ds, double s) {
|
||||
if (ds->playing) {
|
||||
plm_decode(ds->plm, s);
|
||||
}
|
||||
}
|
||||
|
||||
void ds_seek(struct datastream *ds, double time)
|
||||
{
|
||||
void ds_seek(struct datastream *ds, double time) {
|
||||
// clear_raw(ds->audio_device);
|
||||
plm_seek(ds->plm, time, false);
|
||||
}
|
||||
|
||||
void ds_advanceframes(struct datastream *ds, int frames)
|
||||
{
|
||||
void ds_advanceframes(struct datastream *ds, int frames) {
|
||||
for (int i = 0; i < frames; i++) {
|
||||
plm_frame_t *frame = plm_decode_video(ds->plm);
|
||||
render_frame(ds->plm, frame, ds);
|
||||
}
|
||||
}
|
||||
|
||||
void ds_pause(struct datastream *ds)
|
||||
{
|
||||
void ds_pause(struct datastream *ds) {
|
||||
ds->playing = false;
|
||||
}
|
||||
|
||||
void ds_stop(struct datastream *ds)
|
||||
{
|
||||
void ds_stop(struct datastream *ds) {
|
||||
if (ds->plm != NULL) {
|
||||
plm_destroy(ds->plm);
|
||||
ds->plm = NULL;
|
||||
|
@ -186,21 +173,17 @@ void ds_stop(struct datastream *ds)
|
|||
}
|
||||
|
||||
// TODO: Must be a better way
|
||||
int ds_videodone(struct datastream *ds)
|
||||
{
|
||||
return (ds->plm == NULL)
|
||||
|| plm_get_time(ds->plm) >= plm_get_duration(ds->plm);
|
||||
int ds_videodone(struct datastream *ds) {
|
||||
return (ds->plm == NULL) || plm_get_time(ds->plm) >= plm_get_duration(ds->plm);
|
||||
}
|
||||
|
||||
double ds_remainingtime(struct datastream *ds)
|
||||
{
|
||||
double ds_remainingtime(struct datastream *ds) {
|
||||
if (ds->plm != NULL)
|
||||
return plm_get_duration(ds->plm) - plm_get_time(ds->plm);
|
||||
else
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
double ds_length(struct datastream *ds)
|
||||
{
|
||||
double ds_length(struct datastream *ds) {
|
||||
return plm_get_duration(ds->plm);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef DATASTREAM_H
|
||||
#define DATASTREAM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <pl_mpeg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct soundstream;
|
||||
|
||||
|
|
|
@ -11,74 +11,162 @@
|
|||
#include "stb_ds.h"
|
||||
#include "sokol/sokol_gfx.h"
|
||||
|
||||
static uint32_t circleVBO;
|
||||
static uint32_t circleVAO;
|
||||
static struct shader *circleShader;
|
||||
#include "font.h"
|
||||
|
||||
static uint32_t gridVBO;
|
||||
static uint32_t gridVAO;
|
||||
static struct shader *gridShader;
|
||||
static sg_pipeline grid_pipe;
|
||||
static sg_bindings grid_bind;
|
||||
static sg_shader grid_shader;
|
||||
static int grid_c = 0;
|
||||
|
||||
static uint32_t rectVBO;
|
||||
static uint32_t rectVAO;
|
||||
static struct shader *rectShader;
|
||||
static sg_pipeline rect_pipe;
|
||||
static sg_bindings rect_bind;
|
||||
static sg_shader rect_shader;
|
||||
static int rect_c = 0;
|
||||
|
||||
typedef struct {
|
||||
float proj[16];
|
||||
float res[2];
|
||||
} circle_ubo;
|
||||
static sg_pipeline circle_pipe;
|
||||
static sg_bindings circle_bind;
|
||||
static sg_shader csg;
|
||||
static int circle_count = 0;
|
||||
static int circle_vert_c = 7;
|
||||
|
||||
void debug_flush()
|
||||
{
|
||||
sg_apply_pipeline(circle_pipe);
|
||||
sg_apply_bindings(&circle_bind);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(projection));
|
||||
|
||||
sg_draw(0,4,circle_count);
|
||||
circle_count = 0;
|
||||
|
||||
sg_apply_pipeline(rect_pipe);
|
||||
sg_apply_bindings(&rect_bind);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS,0,SG_RANGE_REF(projection));
|
||||
sg_draw(0,rect_c*2,1);
|
||||
rect_c = 0;
|
||||
}
|
||||
|
||||
static sg_shader_uniform_block_desc projection_ubo = {
|
||||
.size = sizeof(projection),
|
||||
.uniforms = {
|
||||
[0] = { .name = "proj", .type = SG_UNIFORMTYPE_MAT4 },
|
||||
}
|
||||
};
|
||||
|
||||
void debugdraw_init()
|
||||
{
|
||||
sg_shader csg = sg_make_shader(&(sg_shader_desc){
|
||||
csg = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/circlevert.glsl"),
|
||||
.fs.source = slurp_text("shaders/circlefrag.glsl"),
|
||||
.vs.uniform_blocks[0] = {
|
||||
.size = sizeof(circle_ubo),
|
||||
.uniforms = {
|
||||
[0] = { .name = "proj", .type = SG_UNIFORMTYPE_MAT4 },
|
||||
[1] = { .name = "res", .type = SG_UNIFORMTYPE_FLOAT2 },
|
||||
}
|
||||
}
|
||||
.vs.uniform_blocks[0] = projection_ubo,
|
||||
});
|
||||
/*
|
||||
float gridverts[] = {
|
||||
-1.f, -1.f,
|
||||
1.f, -1.f,
|
||||
-1.f, 1.f,
|
||||
1.f, 1.f
|
||||
|
||||
circle_pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = csg,
|
||||
.layout = {
|
||||
.attrs = {
|
||||
[0].format = SG_VERTEXFORMAT_FLOAT2,
|
||||
[0].buffer_index = 1,
|
||||
[1].format = SG_VERTEXFORMAT_FLOAT3,
|
||||
[2].format = SG_VERTEXFORMAT_FLOAT2,
|
||||
[3].format = SG_VERTEXFORMAT_FLOAT
|
||||
},
|
||||
.buffers[0].step_func = SG_VERTEXSTEP_PER_INSTANCE,
|
||||
},
|
||||
.primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
||||
.cull_mode = SG_CULLMODE_BACK,
|
||||
.colors[0].blend = {
|
||||
.enabled = true,
|
||||
.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
|
||||
.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.src_factor_alpha = SG_BLENDFACTOR_SRC_ALPHA,
|
||||
.src_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA
|
||||
},
|
||||
.label = "circle pipeline"
|
||||
});
|
||||
|
||||
circle_bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.size = sizeof(float)*circle_vert_c*5000,
|
||||
.usage = SG_USAGE_STREAM,
|
||||
});
|
||||
|
||||
float circleverts[8] = {
|
||||
-1,-1,
|
||||
-1,1,
|
||||
1,-1,
|
||||
1,1
|
||||
};
|
||||
|
||||
gridShader = MakeShader("gridvert.glsl", "gridfrag.glsl");
|
||||
shader_setUBO(gridShader, "Projection", 0);
|
||||
glGenBuffers(1, &gridVBO);
|
||||
glGenVertexArrays(1, &gridVAO);
|
||||
glBindVertexArray(gridVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, gridVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(gridverts), &gridverts, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
circle_bind.vertex_buffers[1] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data = SG_RANGE(circleverts),
|
||||
.usage = SG_USAGE_IMMUTABLE,
|
||||
});
|
||||
|
||||
rectShader = MakeShader("linevert.glsl", "linefrag.glsl");
|
||||
shader_setUBO(rectShader, "Projection", 0);
|
||||
glGenBuffers(1, &rectVBO);
|
||||
glGenVertexArrays(1, &rectVAO);
|
||||
*/
|
||||
|
||||
grid_shader = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/gridvert.glsl"),
|
||||
.fs.source = slurp_text("shaders/gridfrag.glsl"),
|
||||
.vs.uniform_blocks[0] = projection_ubo,
|
||||
.vs.uniform_blocks[1] = {
|
||||
.size = sizeof(float)*2,
|
||||
.uniforms = { [0] = { .name = "offset", .type = SG_UNIFORMTYPE_FLOAT2 } } },
|
||||
.fs.uniform_blocks[0] = {
|
||||
.size = sizeof(float)*5,
|
||||
.uniforms = {
|
||||
[0] = { .name = "thickness", .type = SG_UNIFORMTYPE_FLOAT },
|
||||
[1] = { .name = "span", .type = SG_UNIFORMTYPE_FLOAT },
|
||||
[2] = { .name = "color", .type = SG_UNIFORMTYPE_FLOAT3 },
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
grid_pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = grid_shader,
|
||||
.layout = {
|
||||
.attrs = {
|
||||
[0].format = SG_VERTEXFORMAT_FLOAT2
|
||||
}
|
||||
},
|
||||
.primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
||||
// .cull_mode = SG_CULLMODE_BACK,
|
||||
.label = "grid pipeline",
|
||||
.colors[0] = {
|
||||
.blend = {
|
||||
.enabled = true,
|
||||
.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
|
||||
.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.op_rgb = SG_BLENDOP_ADD,
|
||||
.src_factor_alpha = SG_BLENDFACTOR_SRC_ALPHA,
|
||||
.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.op_alpha = SG_BLENDOP_ADD
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
grid_bind.vertex_buffers[0] = circle_bind.vertex_buffers[1];
|
||||
|
||||
rect_shader = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/linevert.glsl"),
|
||||
.fs.source = slurp_text("shaders/linefrag.glsl"),
|
||||
.vs.uniform_blocks[0] = projection_ubo
|
||||
});
|
||||
|
||||
rect_pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = rect_shader,
|
||||
.layout = {
|
||||
.attrs = { [0].format = SG_VERTEXFORMAT_FLOAT2 }
|
||||
},
|
||||
.primitive_type = SG_PRIMITIVETYPE_LINES
|
||||
});
|
||||
|
||||
rect_bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.size = sizeof(float)*2*10000,
|
||||
.usage = SG_USAGE_STREAM
|
||||
});
|
||||
}
|
||||
|
||||
void draw_line(int x1, int y1, int x2, int y2, float *color)
|
||||
void draw_line(cpVect s, cpVect e, float *color)
|
||||
{
|
||||
shader_use(rectShader);
|
||||
float verts[] = {
|
||||
x1, y1,
|
||||
x2, y2
|
||||
};
|
||||
|
||||
cpVect verts[2] = {s, e};
|
||||
draw_poly(verts, 2, color);
|
||||
}
|
||||
|
||||
|
@ -153,8 +241,8 @@ void draw_edge(cpVect *points, int n, struct color color, int thickness)
|
|||
|
||||
float col[3] = {(float)color.r/255, (float)color.g/255, (float)color.b/255};
|
||||
|
||||
shader_use(rectShader);
|
||||
shader_setvec3(rectShader, "linecolor", col);
|
||||
// shader_use(rectShader);
|
||||
// shader_setvec3(rectShader, "linecolor", col);
|
||||
/*
|
||||
if (thickness <= 1) {
|
||||
// glLineStipple(1, 0x00FF);
|
||||
|
@ -204,29 +292,16 @@ void draw_edge(cpVect *points, int n, struct color color, int thickness)
|
|||
|
||||
void draw_circle(int x, int y, float radius, int pixels, float *color, int fill)
|
||||
{
|
||||
/* shader_use(circleShader);
|
||||
|
||||
float verts[] = {
|
||||
x - radius, y - radius, -1, -1,
|
||||
x + radius, y - radius, 1, -1,
|
||||
x - radius, y + radius, -1, 1,
|
||||
x + radius, y + radius, 1, 1
|
||||
};
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, circleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_DYNAMIC_DRAW);
|
||||
|
||||
shader_setfloat(circleShader, "radius", radius);
|
||||
shader_setint(circleShader, "thickness", pixels);
|
||||
shader_setvec3(circleShader, "dbgColor", color);
|
||||
shader_setbool(circleShader, "fill", fill);
|
||||
shader_setfloat(circleShader, "zoom", cam_zoom());
|
||||
|
||||
glBindVertexArray(circleVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
*/
|
||||
float cv[circle_vert_c] = {0};
|
||||
cv[0] = color[0];
|
||||
cv[1] = color[1];
|
||||
cv[2] = color[2];
|
||||
cv[3] = x;
|
||||
cv[4] = y;
|
||||
cv[5] = radius;
|
||||
cv[6] = fill;
|
||||
sg_append_buffer(circle_bind.vertex_buffers[0], SG_RANGE_REF(cv));
|
||||
circle_count++;
|
||||
}
|
||||
|
||||
void draw_rect(int x, int y, int w, int h, float *color)
|
||||
|
@ -234,11 +309,11 @@ void draw_rect(int x, int y, int w, int h, float *color)
|
|||
float hw = w / 2.f;
|
||||
float hh = h / 2.f;
|
||||
|
||||
float verts[] = {
|
||||
x - hw, y - hh,
|
||||
x + hw, y - hh,
|
||||
x + hw, y + hh,
|
||||
x - hw, y + hh
|
||||
cpVect verts[4] = {
|
||||
{ .x = x-hw, .y = y-hh },
|
||||
{ .x = x+hw, .y = y-hh },
|
||||
{ .x = x+hw, .y = y+hh },
|
||||
{ .x = x-hw, .y = y+hh }
|
||||
};
|
||||
|
||||
draw_poly(verts, 4, color);
|
||||
|
@ -253,27 +328,33 @@ void draw_box(struct cpVect c, struct cpVect wh, struct color color)
|
|||
void draw_arrow(struct cpVect start, struct cpVect end, struct color color, int capsize)
|
||||
{
|
||||
float col[3] = {(float)color.r/255, (float)color.g/255, (float)color.b/255};
|
||||
draw_line(start.x, start.y, end.x, end.y, col);
|
||||
draw_line(start, end, col);
|
||||
|
||||
draw_cppoint(end, capsize, color);
|
||||
}
|
||||
|
||||
void draw_grid(int width, int span)
|
||||
{
|
||||
/* shader_use(gridShader);
|
||||
shader_setint(gridShader, "thickness", width);
|
||||
shader_setint(gridShader, "span", span);
|
||||
|
||||
cpVect offset = cam_pos();
|
||||
offset = cpvmult(offset, 1/cam_zoom());
|
||||
offset.x -= mainwin->width/2;
|
||||
offset.y -= mainwin->height/2;
|
||||
|
||||
shader_setvec2(gridShader, "offset", &offset);
|
||||
sg_apply_pipeline(grid_pipe);
|
||||
sg_apply_bindings(&grid_bind);
|
||||
|
||||
glBindVertexArray(gridVAO);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
*/
|
||||
float col[3] = { 0.3, 0.5, 0.8};
|
||||
|
||||
float fubo[5];
|
||||
fubo[0] = width;
|
||||
fubo[1] = span;
|
||||
fubo[2] = col;
|
||||
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(projection));
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 1, SG_RANGE_REF(offset));
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, SG_RANGE_REF(fubo));
|
||||
|
||||
sg_draw(0,4,1);
|
||||
}
|
||||
|
||||
void draw_point(int x, int y, float r, float *color)
|
||||
|
@ -293,8 +374,33 @@ void draw_points(struct cpVect *points, int n, float size, float *color)
|
|||
draw_point(points[i].x, points[i].y, size, color);
|
||||
}
|
||||
|
||||
void draw_poly(float *points, int n, float *color)
|
||||
void draw_poly(cpVect *points, int n, float *color)
|
||||
{
|
||||
if (n == 2) {
|
||||
sg_range t;
|
||||
t.ptr = points;
|
||||
t.size = sizeof(cpVect)*2;
|
||||
sg_append_buffer(rect_bind.vertex_buffers[0], &t);
|
||||
rect_c += 1;
|
||||
return;
|
||||
} else if (n <= 1) return;
|
||||
|
||||
|
||||
cpVect buffer[2*n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
buffer[i*2] = points[i];
|
||||
buffer[i*2+1] = points[i+1];
|
||||
}
|
||||
|
||||
buffer[2*n-1] = points[0];
|
||||
|
||||
sg_range t;
|
||||
t.ptr = buffer;
|
||||
t.size = sizeof(cpVect)*2*n;
|
||||
|
||||
sg_append_buffer(rect_bind.vertex_buffers[0], &t);
|
||||
|
||||
rect_c += n;
|
||||
/* shader_use(rectShader);
|
||||
shader_setvec3(rectShader, "linecolor", color);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||
|
@ -312,17 +418,6 @@ void draw_poly(float *points, int n, float *color)
|
|||
*/
|
||||
}
|
||||
|
||||
void draw_polyvec(cpVect *points, int n, float *color)
|
||||
{
|
||||
float drawvec[n*2];
|
||||
for (int i = 0; i < n; i++) {
|
||||
drawvec[i*2] = points[i].x;
|
||||
drawvec[i*2+1] = points[i].y;
|
||||
}
|
||||
|
||||
draw_poly(drawvec, n, color);
|
||||
}
|
||||
|
||||
void debugdraw_flush()
|
||||
{
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
struct color;
|
||||
|
||||
void debugdraw_init();
|
||||
void draw_line(int x1, int y1, int x2, int y2, float *color);
|
||||
void draw_line(cpVect s, cpVect e, float *color);
|
||||
void draw_edge(struct cpVect *points, int n, struct color color, int thickness);
|
||||
void draw_points(struct cpVect *points, int n, float size, float *color);
|
||||
void draw_arrow(struct cpVect start, struct cpVect end, struct color, int capsize);
|
||||
|
@ -15,7 +15,7 @@ void draw_rect(int x, int y, int w, int h, float *color);
|
|||
void draw_box(struct cpVect c, struct cpVect wh, struct color color);
|
||||
void draw_point(int x, int y, float r, float *color);
|
||||
void draw_cppoint(struct cpVect point, float r, struct color color);
|
||||
void draw_poly(float *points, int n, float *color);
|
||||
void draw_poly(cpVect *points, int n, float *color);
|
||||
|
||||
void debug_flush();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
#include "resources.h"
|
||||
|
||||
#include "nuklear.h"
|
||||
#include "nuke.h"
|
||||
|
||||
#define ASSET_TYPE_NULL 0
|
||||
#define ASSET_TYPE_IMAGE 1
|
||||
|
|
|
@ -16,37 +16,34 @@
|
|||
#define PL_MPEG_IMPLEMENTATION
|
||||
#include <pl_mpeg.h>
|
||||
|
||||
|
||||
#ifdef EDITOR
|
||||
#include "editor.h"
|
||||
#endif
|
||||
|
||||
#include "render.h"
|
||||
|
||||
#include "openglrender.h"
|
||||
#include "window.h"
|
||||
#include "camera.h"
|
||||
#include "input.h"
|
||||
#include "sprite.h"
|
||||
#include "2dphysics.h"
|
||||
#include "camera.h"
|
||||
#include "gameobject.h"
|
||||
#include "input.h"
|
||||
#include "log.h"
|
||||
#include "openglrender.h"
|
||||
#include "resources.h"
|
||||
#include "timer.h"
|
||||
#include "script.h"
|
||||
#include "sprite.h"
|
||||
#include "timer.h"
|
||||
#include "window.h"
|
||||
|
||||
#include "sound.h"
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
void error_callback(int error, const char *description)
|
||||
{
|
||||
void error_callback(int error, const char *description) {
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
YughError("GLFW Error: %s", description);
|
||||
}
|
||||
|
||||
void engine_init()
|
||||
{
|
||||
void engine_init() {
|
||||
glfwSetErrorCallback(error_callback);
|
||||
/* Initialize GLFW */
|
||||
if (!glfwInit()) {
|
||||
|
|
|
@ -2,31 +2,32 @@
|
|||
|
||||
#include "script.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "2dphysics.h"
|
||||
#include "anim.h"
|
||||
#include "debug.h"
|
||||
#include "window.h"
|
||||
#include "debugdraw.h"
|
||||
#include "editor.h"
|
||||
#include "engine.h"
|
||||
#include "log.h"
|
||||
#include "input.h"
|
||||
#include "gameobject.h"
|
||||
#include "openglrender.h"
|
||||
#include "2dphysics.h"
|
||||
#include "sprite.h"
|
||||
#include "anim.h"
|
||||
#include "yugine.h"
|
||||
#include "nuke.h"
|
||||
#include "sound.h"
|
||||
#include "font.h"
|
||||
#include "sound.h"
|
||||
#include "music.h"
|
||||
#include "gameobject.h"
|
||||
#include "input.h"
|
||||
#include "level.h"
|
||||
#include "tinyspline.h"
|
||||
#include "log.h"
|
||||
#include "mix.h"
|
||||
#include "debugdraw.h"
|
||||
#include "music.h"
|
||||
#include "nuke.h"
|
||||
#include "openglrender.h"
|
||||
#include "sound.h"
|
||||
#include "sprite.h"
|
||||
#include "stb_ds.h"
|
||||
#include <ftw.h>
|
||||
#include "string.h"
|
||||
#include "tinyspline.h"
|
||||
#include "window.h"
|
||||
#include "yugine.h"
|
||||
#include <assert.h>
|
||||
#include <ftw.h>
|
||||
|
||||
#include "model.h"
|
||||
|
||||
#include "miniaudio.h"
|
||||
|
||||
|
@ -41,77 +42,63 @@
|
|||
(byte & 0x02 ? '1' : '0'), \
|
||||
(byte & 0x01 ? '1' : '0')
|
||||
|
||||
int js2int(JSValue v)
|
||||
{
|
||||
int js2int(JSValue v) {
|
||||
int32_t i;
|
||||
JS_ToInt32(js, &i, v);
|
||||
return i;
|
||||
}
|
||||
|
||||
JSValue int2js(int i)
|
||||
{
|
||||
JSValue int2js(int i) {
|
||||
return JS_NewInt64(js, i);
|
||||
}
|
||||
|
||||
JSValue str2js(const char *c)
|
||||
{
|
||||
JSValue str2js(const char *c) {
|
||||
return JS_NewString(js, c);
|
||||
}
|
||||
|
||||
double js2number(JSValue v)
|
||||
{
|
||||
double js2number(JSValue v) {
|
||||
double g;
|
||||
JS_ToFloat64(js, &g, v);
|
||||
return g;
|
||||
}
|
||||
|
||||
int js2bool(JSValue v)
|
||||
{
|
||||
int js2bool(JSValue v) {
|
||||
return JS_ToBool(js, v);
|
||||
}
|
||||
|
||||
JSValue float2js(double g)
|
||||
{
|
||||
JSValue float2js(double g) {
|
||||
return JS_NewFloat64(js, g);
|
||||
}
|
||||
|
||||
JSValue num2js(double g)
|
||||
{
|
||||
JSValue num2js(double g) {
|
||||
return float2js(g);
|
||||
}
|
||||
|
||||
struct gameobject *js2go(JSValue v)
|
||||
{
|
||||
struct gameobject *js2go(JSValue v) {
|
||||
return id2go(js2int(v));
|
||||
}
|
||||
|
||||
void *js2ptr(JSValue v)
|
||||
{
|
||||
void *js2ptr(JSValue v) {
|
||||
void *p;
|
||||
JS_ToInt64(js, &p, v);
|
||||
return p;
|
||||
}
|
||||
|
||||
JSValue ptr2js(void *ptr)
|
||||
{
|
||||
JSValue ptr2js(void *ptr) {
|
||||
return JS_NewInt64(js, (long)ptr);
|
||||
}
|
||||
|
||||
struct timer *js2timer(JSValue v)
|
||||
{
|
||||
struct timer *js2timer(JSValue v) {
|
||||
return id2timer(js2int(v));
|
||||
}
|
||||
|
||||
|
||||
double js_get_prop_number(JSValue v, const char *p)
|
||||
{
|
||||
double js_get_prop_number(JSValue v, const char *p) {
|
||||
double num;
|
||||
JS_ToFloat64(js, &num, JS_GetPropertyStr(js, v, p));
|
||||
return num;
|
||||
}
|
||||
|
||||
struct glrect js2glrect(JSValue v)
|
||||
{
|
||||
struct glrect js2glrect(JSValue v) {
|
||||
struct glrect rect;
|
||||
rect.s0 = js_get_prop_number(v, "s0");
|
||||
rect.s1 = js_get_prop_number(v, "s1");
|
||||
|
@ -120,19 +107,16 @@ struct glrect js2glrect(JSValue v)
|
|||
return rect;
|
||||
}
|
||||
|
||||
JSValue js_arridx(JSValue v, int idx)
|
||||
{
|
||||
JSValue js_arridx(JSValue v, int idx) {
|
||||
return JS_GetPropertyUint32(js, v, idx);
|
||||
}
|
||||
|
||||
int js_arrlen(JSValue v)
|
||||
{
|
||||
int js_arrlen(JSValue v) {
|
||||
int len;
|
||||
JS_ToInt32(js, &len, JS_GetPropertyStr(js, v, "length"));
|
||||
return len;
|
||||
}
|
||||
struct color js2color(JSValue v)
|
||||
{
|
||||
struct color js2color(JSValue v) {
|
||||
struct color color = {0, 0, 0};
|
||||
color.r = js2int(js_arridx(v, 0));
|
||||
color.g = js2int(js_arridx(v, 1));
|
||||
|
@ -140,16 +124,14 @@ struct color js2color(JSValue v)
|
|||
return color;
|
||||
}
|
||||
|
||||
cpVect js2vec2(JSValue v)
|
||||
{
|
||||
cpVect js2vec2(JSValue v) {
|
||||
cpVect vect;
|
||||
vect.x = js2number(js_arridx(v, 0));
|
||||
vect.y = js2number(js_arridx(v, 1));
|
||||
return vect;
|
||||
}
|
||||
|
||||
cpBitmask js2bitmask(JSValue v)
|
||||
{
|
||||
cpBitmask js2bitmask(JSValue v) {
|
||||
cpBitmask mask = 0;
|
||||
int len = js_arrlen(v);
|
||||
|
||||
|
@ -163,8 +145,7 @@ cpBitmask js2bitmask(JSValue v)
|
|||
return mask;
|
||||
}
|
||||
|
||||
cpVect *js2cpvec2arr(JSValue v)
|
||||
{
|
||||
cpVect *js2cpvec2arr(JSValue v) {
|
||||
int n = js_arrlen(v);
|
||||
cpVect *points = NULL;
|
||||
|
||||
|
@ -174,8 +155,7 @@ cpVect *js2cpvec2arr(JSValue v)
|
|||
return points;
|
||||
}
|
||||
|
||||
JSValue bitmask2js(cpBitmask mask)
|
||||
{
|
||||
JSValue bitmask2js(cpBitmask mask) {
|
||||
JSValue arr = JS_NewArray(js);
|
||||
for (int i = 0; i < 11; i++) {
|
||||
int on = mask & 1 << i;
|
||||
|
@ -185,30 +165,26 @@ JSValue bitmask2js(cpBitmask mask)
|
|||
return arr;
|
||||
}
|
||||
|
||||
void vec2float(cpVect v, float *f)
|
||||
{
|
||||
void vec2float(cpVect v, float *f) {
|
||||
f[0] = v.x;
|
||||
f[1] = v.y;
|
||||
}
|
||||
|
||||
JSValue vec2js(cpVect v)
|
||||
{
|
||||
JSValue vec2js(cpVect v) {
|
||||
JSValue array = JS_NewArray(js);
|
||||
JS_SetPropertyInt64(js, array, 0, JS_NewFloat64(js, v.x));
|
||||
JS_SetPropertyInt64(js, array, 1, JS_NewFloat64(js, v.y));
|
||||
return array;
|
||||
}
|
||||
|
||||
JSValue vecarr2js(cpVect *points, int n)
|
||||
{
|
||||
JSValue vecarr2js(cpVect *points, int n) {
|
||||
JSValue array = JS_NewArray(js);
|
||||
for (int i = 0; i < n; i++)
|
||||
JS_SetPropertyInt64(js, array, i, vec2js(points[i]));
|
||||
return array;
|
||||
}
|
||||
|
||||
JSValue duk_gui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_gui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *s = JS_ToCString(js, argv[0]);
|
||||
cpVect pos = js2vec2(argv[1]);
|
||||
|
||||
|
@ -219,8 +195,7 @@ JSValue duk_gui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *a
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_ui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_ui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *s = JS_ToCString(js, argv[0]);
|
||||
cpVect pos = js2vec2(argv[1]);
|
||||
|
||||
|
@ -233,8 +208,7 @@ JSValue duk_ui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *ar
|
|||
return ret;
|
||||
}
|
||||
|
||||
JSValue duk_cursor_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_cursor_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *s = JS_ToCString(js, argv[0]);
|
||||
cpVect pos = js2vec2(argv[1]);
|
||||
|
||||
|
@ -248,8 +222,7 @@ JSValue duk_cursor_text(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_gui_img(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_gui_img(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *img = JS_ToCString(js, argv[0]);
|
||||
cpVect pos = js2vec2(argv[1]);
|
||||
gui_draw_img(img, pos.x, pos.y);
|
||||
|
@ -257,8 +230,7 @@ JSValue duk_gui_img(JSContext *js, JSValueConst this, int argc, JSValueConst *ar
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
struct nk_rect js2nk_rect(JSValue v)
|
||||
{
|
||||
struct nk_rect js2nk_rect(JSValue v) {
|
||||
struct nk_rect rect;
|
||||
rect.x = js2number(JS_GetPropertyStr(js, v, "x"));
|
||||
rect.y = js2number(JS_GetPropertyStr(js, v, "y"));
|
||||
|
@ -267,8 +239,7 @@ struct nk_rect js2nk_rect(JSValue v)
|
|||
return rect;
|
||||
}
|
||||
|
||||
JSValue nk_rect2js(struct nk_rect rect)
|
||||
{
|
||||
JSValue nk_rect2js(struct nk_rect rect) {
|
||||
JSValue obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, rect.x));
|
||||
JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, rect.y));
|
||||
|
@ -277,8 +248,7 @@ JSValue nk_rect2js(struct nk_rect rect)
|
|||
return obj;
|
||||
}
|
||||
|
||||
JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
float editnum;
|
||||
int editint;
|
||||
|
@ -378,8 +348,7 @@ JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
return ret;
|
||||
}
|
||||
|
||||
JSValue duk_win_make(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_win_make(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *title = JS_ToCString(js, argv[0]);
|
||||
int w = js2int(argv[1]);
|
||||
int h = js2int(argv[2]);
|
||||
|
@ -389,8 +358,7 @@ JSValue duk_win_make(JSContext *js, JSValueConst this, int argc, JSValueConst *a
|
|||
return JS_NewInt64(js, win->id);
|
||||
}
|
||||
|
||||
JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
static_assert(sizeof(tsReal) * 2 == sizeof(cpVect));
|
||||
|
||||
tsBSpline spline;
|
||||
|
@ -441,9 +409,7 @@ JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return arr;
|
||||
}
|
||||
|
||||
|
||||
JSValue ints2js(int *ints)
|
||||
{
|
||||
JSValue ints2js(int *ints) {
|
||||
JSValue arr = JS_NewArray(js);
|
||||
for (int i = 0; i < arrlen(ints); i++)
|
||||
JS_SetPropertyUint32(js, arr, i, int2js(ints[i]));
|
||||
|
@ -451,8 +417,7 @@ JSValue ints2js(int *ints)
|
|||
return arr;
|
||||
}
|
||||
|
||||
int vec_between(cpVect p, cpVect a, cpVect b)
|
||||
{
|
||||
int vec_between(cpVect p, cpVect a, cpVect b) {
|
||||
cpVect n;
|
||||
n.x = b.x - a.x;
|
||||
n.y = b.y - a.y;
|
||||
|
@ -465,13 +430,11 @@ int vec_between(cpVect p, cpVect a, cpVect b)
|
|||
0 indicates 'p' comes before the first point.
|
||||
arrlen(segs) indicates it comes after the last point.
|
||||
*/
|
||||
int point2segindex(cpVect p, cpVect *segs, double slop)
|
||||
{
|
||||
int point2segindex(cpVect p, cpVect *segs, double slop) {
|
||||
float shortest = slop < 0 ? INFINITY : slop;
|
||||
int best = -1;
|
||||
|
||||
for (int i = 0; i < arrlen(segs)-1; i++)
|
||||
{
|
||||
for (int i = 0; i < arrlen(segs) - 1; i++) {
|
||||
float a = (segs[i + 1].y - segs[i].y) / (segs[i + 1].x - segs[i].x);
|
||||
float c = segs[i].y - (a * segs[i].x);
|
||||
float b = -1;
|
||||
|
@ -521,12 +484,10 @@ int point2segindex(cpVect p, cpVect *segs, double slop)
|
|||
best = arrlen(segs);
|
||||
}
|
||||
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
int file_exists(char *path)
|
||||
{
|
||||
int file_exists(char *path) {
|
||||
FILE *o = fopen(path, "r");
|
||||
if (o) {
|
||||
fclose(o);
|
||||
|
@ -540,8 +501,7 @@ static char *dukext;
|
|||
static JSValue dukarr;
|
||||
static int dukidx;
|
||||
|
||||
static int duk2path(const char *path, const struct stat *sb, int typeflag)
|
||||
{
|
||||
static int duk2path(const char *path, const struct stat *sb, int typeflag) {
|
||||
if (typeflag == FTW_F) {
|
||||
char *ext = strrchr(path, '.');
|
||||
if (ext && !strcmp(ext, dukext))
|
||||
|
@ -551,8 +511,7 @@ static int duk2path(const char *path, const struct stat *sb, int typeflag)
|
|||
return 0;
|
||||
}
|
||||
|
||||
JSValue dukext2paths(char *ext)
|
||||
{
|
||||
JSValue dukext2paths(char *ext) {
|
||||
dukext = ext;
|
||||
dukarr = JS_NewArray(js);
|
||||
dukidx = 0;
|
||||
|
@ -560,8 +519,7 @@ JSValue dukext2paths(char *ext)
|
|||
return dukarr;
|
||||
}
|
||||
|
||||
JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
const char *str = NULL;
|
||||
const char *str2 = NULL;
|
||||
|
@ -953,6 +911,30 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
case 96:
|
||||
color2float(js2color(argv[2]), id2sprite(js2int(argv[1]))->color);
|
||||
break;
|
||||
|
||||
case 97:
|
||||
eye = HMM_AddV3(eye, (HMM_Vec3){0, 0.01, 0});
|
||||
break;
|
||||
|
||||
case 98:
|
||||
eye = HMM_AddV3(eye, (HMM_Vec3){0, -0.01, 0});
|
||||
break;
|
||||
|
||||
case 99:
|
||||
eye = HMM_AddV3(eye, (HMM_Vec3){-0.01, 0, 0});
|
||||
break;
|
||||
|
||||
case 100:
|
||||
eye = HMM_AddV3(eye, (HMM_Vec3){0.01, 0,0});
|
||||
break;
|
||||
|
||||
case 101:
|
||||
eye = HMM_AddV3(eye, (HMM_Vec3){0,0,-0.01});
|
||||
break;
|
||||
|
||||
case 102:
|
||||
eye = HMM_AddV3(eye,(HMM_Vec3){0,0,0.01});
|
||||
break;
|
||||
}
|
||||
|
||||
if (str)
|
||||
|
@ -967,8 +949,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_register(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_register(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
|
||||
struct callee c;
|
||||
|
@ -1017,19 +998,16 @@ JSValue duk_register(JSContext *js, JSValueConst this, int argc, JSValueConst *a
|
|||
}
|
||||
|
||||
return JS_NULL;
|
||||
|
||||
}
|
||||
|
||||
void gameobject_add_shape_collider(int go, struct callee c, struct phys2d_shape *shape)
|
||||
{
|
||||
void gameobject_add_shape_collider(int go, struct callee c, struct phys2d_shape *shape) {
|
||||
struct shape_cb shapecb;
|
||||
shapecb.shape = shape;
|
||||
shapecb.cbs.begin = c;
|
||||
arrpush(id2go(go)->shape_cbs, shapecb);
|
||||
}
|
||||
|
||||
JSValue duk_register_collide(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_register_collide(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
int go = js2int(argv[3]);
|
||||
struct callee c;
|
||||
|
@ -1057,8 +1035,7 @@ JSValue duk_register_collide(JSContext *js, JSValueConst this, int argc, JSValue
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_sys_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_sys_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
|
||||
switch (cmd) {
|
||||
|
@ -1086,30 +1063,24 @@ JSValue duk_sys_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *ar
|
|||
case 5:
|
||||
return JS_NewBool(js, sim_playing());
|
||||
|
||||
|
||||
case 6:
|
||||
return JS_NewBool(js, sim_paused());
|
||||
|
||||
|
||||
case 7:
|
||||
return JS_NewInt64(js, MakeGameobject());
|
||||
|
||||
|
||||
case 8:
|
||||
return JS_NewInt64(js, frame_fps());
|
||||
|
||||
|
||||
case 9: /* Clear the level out */
|
||||
new_level();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_make_gameobject(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_gameobject(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int g = MakeGameobject();
|
||||
struct gameobject *go = get_gameobject_from_id(g);
|
||||
|
||||
|
@ -1126,8 +1097,7 @@ JSValue duk_make_gameobject(JSContext *js, JSValueConst this, int argc, JSValueC
|
|||
return JS_NewInt64(js, g);
|
||||
}
|
||||
|
||||
JSValue duk_yughlog(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_yughlog(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
const char *s = JS_ToCString(js, argv[1]);
|
||||
const char *f = JS_ToCString(js, argv[2]);
|
||||
|
@ -1141,8 +1111,7 @@ JSValue duk_yughlog(JSContext *js, JSValueConst this, int argc, JSValueConst *ar
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_set_body(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_set_body(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
int id = js2int(argv[1]);
|
||||
struct gameobject *go = get_gameobject_from_id(id);
|
||||
|
@ -1208,8 +1177,7 @@ JSValue duk_set_body(JSContext *js, JSValueConst this, int argc, JSValueConst *a
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_q_body(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_q_body(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int q = js2int(argv[0]);
|
||||
struct gameobject *go = get_gameobject_from_id(js2int(argv[1]));
|
||||
|
||||
|
@ -1239,14 +1207,12 @@ JSValue duk_q_body(JSContext *js, JSValueConst this, int argc, JSValueConst *arg
|
|||
|
||||
case 7:
|
||||
return JS_NewBool(js, phys2d_in_air(go->body));
|
||||
|
||||
}
|
||||
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_make_sprite(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_sprite(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int go = js2int(argv[0]);
|
||||
const char *path = JS_ToCString(js, argv[1]);
|
||||
cpVect pos = js2vec2(argv[2]);
|
||||
|
@ -1262,8 +1228,7 @@ JSValue duk_make_sprite(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
}
|
||||
|
||||
/* Make anim from texture */
|
||||
JSValue duk_make_anim2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_anim2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *path = JS_ToCString(js, argv[0]);
|
||||
int frames = js2int(argv[1]);
|
||||
int fps = js2int(argv[2]);
|
||||
|
@ -1275,8 +1240,7 @@ JSValue duk_make_anim2d(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return ptr2js(anim);
|
||||
}
|
||||
|
||||
JSValue duk_make_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int go = js2int(argv[0]);
|
||||
cpVect size = js2vec2(argv[1]);
|
||||
cpVect offset = js2vec2(argv[2]);
|
||||
|
@ -1295,8 +1259,7 @@ JSValue duk_make_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return boxval;
|
||||
}
|
||||
|
||||
JSValue duk_cmd_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_cmd_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
struct phys2d_box *box = js2ptr(argv[1]);
|
||||
cpVect arg;
|
||||
|
@ -1325,8 +1288,7 @@ JSValue duk_cmd_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst *
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int go = js2int(argv[0]);
|
||||
double radius = js2number(argv[1]);
|
||||
|
||||
|
@ -1342,8 +1304,7 @@ JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueCon
|
|||
return circleval;
|
||||
}
|
||||
|
||||
JSValue duk_cmd_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_cmd_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
struct phys2d_circle *circle = js2ptr(argv[1]);
|
||||
|
||||
|
@ -1363,8 +1324,7 @@ JSValue duk_cmd_circle2d(JSContext *js, JSValueConst this, int argc, JSValueCons
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_make_poly2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_poly2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int go = js2int(argv[0]);
|
||||
struct phys2d_poly *poly = Make2DPoly(go);
|
||||
phys2d_poly_setverts(poly, js2cpvec2arr(argv[1]));
|
||||
|
@ -1375,8 +1335,7 @@ JSValue duk_make_poly2d(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return polyval;
|
||||
}
|
||||
|
||||
JSValue duk_cmd_poly2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_cmd_poly2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
struct phys2d_poly *poly = js2ptr(argv[1]);
|
||||
|
||||
|
@ -1391,8 +1350,7 @@ JSValue duk_cmd_poly2d(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_make_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int go = js2int(argv[0]);
|
||||
struct phys2d_edge *edge = Make2DEdge(go);
|
||||
|
||||
|
@ -1411,8 +1369,7 @@ JSValue duk_make_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return edgeval;
|
||||
}
|
||||
|
||||
JSValue duk_cmd_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_cmd_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
struct phys2d_edge *edge = js2ptr(argv[1]);
|
||||
|
||||
|
@ -1432,8 +1389,7 @@ JSValue duk_cmd_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_inflate_cpv(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_inflate_cpv(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
cpVect *points = js2cpvec2arr(argv[0]);
|
||||
int n = js2int(argv[1]);
|
||||
double d = js2number(argv[2]);
|
||||
|
@ -1451,8 +1407,7 @@ JSValue duk_inflate_cpv(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
}
|
||||
|
||||
/* These are anims for controlling properties on an object */
|
||||
JSValue duk_anim(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_anim(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
JSValue prop = argv[0];
|
||||
int keyframes = js_arrlen(argv[1]);
|
||||
YughInfo("Processing %d keyframes.", keyframes);
|
||||
|
@ -1476,8 +1431,7 @@ JSValue duk_anim(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_make_timer(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue duk_make_timer(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
double secs = js2number(argv[1]);
|
||||
struct callee *c = malloc(sizeof(*c));
|
||||
c->fn = JS_DupValue(js, argv[0]);
|
||||
|
@ -1489,8 +1443,7 @@ JSValue duk_make_timer(JSContext *js, JSValueConst this, int argc, JSValueConst
|
|||
|
||||
#define DUK_FUNC(NAME, ARGS) JS_SetPropertyStr(js, JS_GetGlobalObject(js), #NAME, JS_NewCFunction(js, duk_##NAME, #NAME, ARGS));
|
||||
|
||||
void ffi_load()
|
||||
{
|
||||
void ffi_load() {
|
||||
DUK_FUNC(yughlog, 4)
|
||||
DUK_FUNC(nuke, 6)
|
||||
DUK_FUNC(make_gameobject, 7)
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
#include "font.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "render.h"
|
||||
#include <shader.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <shader.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <window.h>
|
||||
#include "log.h"
|
||||
|
||||
#include "openglrender.h"
|
||||
|
||||
#include "stb_truetype.h"
|
||||
#include "stb_rect_pack.h"
|
||||
#include "stb_image_write.h"
|
||||
#include "stb_rect_pack.h"
|
||||
#include "stb_truetype.h"
|
||||
|
||||
struct sFont *font;
|
||||
static struct shader *shader;
|
||||
static sg_shader fontshader;
|
||||
|
||||
|
||||
unsigned char *slurp_file(const char *filename) {
|
||||
FILE *f = fopen(filename, "rb");
|
||||
|
@ -53,8 +52,7 @@ char *slurp_text(const char *filename) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
int slurp_write(const char *txt, const char *filename)
|
||||
{
|
||||
int slurp_write(const char *txt, const char *filename) {
|
||||
FILE *f = fopen(filename, "w");
|
||||
if (!f) return 1;
|
||||
|
||||
|
@ -63,12 +61,15 @@ int slurp_write(const char *txt, const char *filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static sg_shader fontshader;
|
||||
static sg_bindings bind_text;
|
||||
static sg_pipeline pipe_text;
|
||||
|
||||
void font_init(struct shader *textshader) {
|
||||
shader = textshader;
|
||||
static float text_buffer[16 * 40000];
|
||||
static uint16_t text_idx_buffer[6 * 40000];
|
||||
static float color_buffer[3 * 40000];
|
||||
|
||||
void font_init(struct shader *textshader) {
|
||||
fontshader = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/textvert.glsl"),
|
||||
.fs.source = slurp_text("shaders/textfrag.glsl"),
|
||||
|
@ -76,16 +77,9 @@ void font_init(struct shader *textshader) {
|
|||
.size = sizeof(float) * 16,
|
||||
// .layout = SG_UNIFORMLAYOUT_STD140,
|
||||
.uniforms = {
|
||||
[0] = { .name = "projection", .type = SG_UNIFORMTYPE_MAT4 }
|
||||
}
|
||||
},
|
||||
[0] = {.name = "projection", .type = SG_UNIFORMTYPE_MAT4}}},
|
||||
|
||||
.fs.images[0] = {
|
||||
.name = "text",
|
||||
.image_type = SG_IMAGETYPE_2D,
|
||||
.sampler_type = SG_SAMPLERTYPE_FLOAT
|
||||
}
|
||||
});
|
||||
.fs.images[0] = {.name = "text", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT}});
|
||||
|
||||
pipe_text = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = fontshader,
|
||||
|
@ -96,48 +90,38 @@ void font_init(struct shader *textshader) {
|
|||
[1].format = SG_VERTEXFORMAT_FLOAT2,
|
||||
[1].buffer_index = 0,
|
||||
[2].format = SG_VERTEXFORMAT_FLOAT3,
|
||||
[2].buffer_index = 1},
|
||||
.buffers[2].step_func = SG_VERTEXSTEP_PER_INSTANCE,
|
||||
[2].buffer_index = 1,
|
||||
},
|
||||
},
|
||||
// .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
||||
.label = "text pipeline",
|
||||
.index_type = SG_INDEXTYPE_UINT16
|
||||
});
|
||||
.index_type = SG_INDEXTYPE_UINT16});
|
||||
|
||||
bind_text.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.size = sizeof(float)*16*500,
|
||||
.size = sizeof(float) * 16 * 40000,
|
||||
.type = SG_BUFFERTYPE_VERTEXBUFFER,
|
||||
.usage = SG_USAGE_STREAM,
|
||||
.label = "text buffer"
|
||||
});
|
||||
.label = "text buffer"});
|
||||
|
||||
bind_text.vertex_buffers[1] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.size = sizeof(float)*3*40000,
|
||||
.size = sizeof(float) * 3 * 4 * 40000,
|
||||
.type = SG_BUFFERTYPE_VERTEXBUFFER,
|
||||
.usage = SG_USAGE_STREAM,
|
||||
.label = "text color buffer"
|
||||
});
|
||||
.label = "text color buffer"});
|
||||
|
||||
bind_text.index_buffer = sg_make_buffer(&(sg_buffer_desc){
|
||||
.size = sizeof(uint16_t)*6*500,
|
||||
.size = sizeof(uint16_t) * 6 * 40000,
|
||||
.type = SG_BUFFERTYPE_INDEXBUFFER,
|
||||
.usage = SG_USAGE_STREAM,
|
||||
.label = "text index buffer"
|
||||
});
|
||||
.label = "text index buffer"});
|
||||
|
||||
font = MakeFont("LessPerfectDOSVGA.ttf", 16);
|
||||
bind_text.fs_images[0] = font->texID;
|
||||
}
|
||||
|
||||
void font_frame(struct window *w) {
|
||||
shader_use(shader);
|
||||
}
|
||||
|
||||
struct sFont *MakeFont(const char *fontfile, int height)
|
||||
{
|
||||
struct sFont *MakeFont(const char *fontfile, int height) {
|
||||
YughInfo("Making font %s.", fontfile);
|
||||
|
||||
int packsize = 128;
|
||||
int packsize = 1024;
|
||||
|
||||
struct sFont *newfont = calloc(1, sizeof(struct sFont));
|
||||
newfont->height = height;
|
||||
|
@ -173,9 +157,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
|||
.mag_filter = SG_FILTER_NEAREST,
|
||||
.data.subimage[0][0] = {
|
||||
.ptr = bitmap,
|
||||
.size = packsize*packsize
|
||||
}
|
||||
});
|
||||
.size = packsize * packsize}});
|
||||
|
||||
free(ttf_buffer);
|
||||
free(bitmap);
|
||||
|
@ -202,8 +184,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
|||
|
||||
static int curchar = 0;
|
||||
|
||||
void draw_char_box(struct Character c, float cursor[2], float scale, float color[3])
|
||||
{
|
||||
void draw_char_box(struct Character c, float cursor[2], float scale, float color[3]) {
|
||||
int x, y, w, h;
|
||||
|
||||
x = cursor[0];
|
||||
|
@ -216,18 +197,33 @@ void draw_char_box(struct Character c, float cursor[2], float scale, float color
|
|||
draw_rect(x, y, w, h, color);
|
||||
}
|
||||
|
||||
void text_flush()
|
||||
{
|
||||
void text_flush() {
|
||||
if (curchar == 0) return;
|
||||
sg_apply_pipeline(pipe_text);
|
||||
sg_apply_bindings(&bind_text);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(projection));
|
||||
|
||||
sg_range verts;
|
||||
verts.ptr = text_buffer;
|
||||
verts.size = sizeof(float) * 16 * curchar;
|
||||
sg_update_buffer(bind_text.vertex_buffers[0], &verts);
|
||||
|
||||
sg_range idxs;
|
||||
idxs.ptr = text_idx_buffer;
|
||||
idxs.size = sizeof(uint16_t) * 6 * curchar;
|
||||
sg_update_buffer(bind_text.index_buffer, &idxs);
|
||||
|
||||
sg_range c = {
|
||||
.ptr = color_buffer,
|
||||
.size = sizeof(float) * 3 * 4 * curchar};
|
||||
|
||||
sg_update_buffer(bind_text.vertex_buffers[1], &c);
|
||||
|
||||
sg_draw(0, 6 * curchar, 1);
|
||||
curchar = 0;
|
||||
}
|
||||
|
||||
void fill_charverts(float *verts, float cursor[2], float scale, struct Character c, float *offset)
|
||||
{
|
||||
void fill_charverts(float *verts, float cursor[2], float scale, struct Character c, float *offset) {
|
||||
float w = c.Size[0] * scale;
|
||||
float h = c.Size[1] * scale;
|
||||
|
||||
|
@ -238,16 +234,14 @@ void fill_charverts(float *verts, float cursor[2], float scale, struct Character
|
|||
xpos, ypos, c.rect.s0, c.rect.t1,
|
||||
xpos + w, ypos, c.rect.s1, c.rect.t1,
|
||||
xpos, ypos + h, c.rect.s0, c.rect.t0,
|
||||
xpos + w, ypos + h, c.rect.s1, c.rect.t0
|
||||
};
|
||||
xpos + w, ypos + h, c.rect.s1, c.rect.t0};
|
||||
|
||||
memcpy(verts, v, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
static int drawcaret = 0;
|
||||
|
||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct shader *shader, float color[3])
|
||||
{
|
||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, float color[3]) {
|
||||
float shadowcolor[3] = {0.f, 0.f, 0.f};
|
||||
float shadowcursor[2];
|
||||
|
||||
|
@ -257,38 +251,29 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
|||
fill_charverts(verts, cursor, scale, c, offset);
|
||||
|
||||
/* Check if the vertex is off screen */
|
||||
if (verts[5] < 0 || verts[10] < 0 || verts[0] > window_i(0)->width || verts[1] > window_i(0)->height)
|
||||
if (verts[5] < -window_i(0)->width / 2.f || verts[9] < -window_i(0)->height / 2.f || verts[0] > window_i(0)->width / 2.f || verts[1] > window_i(0)->height / 2.f)
|
||||
return;
|
||||
|
||||
curchar++;
|
||||
/* SET COLOR ? */
|
||||
uint16_t pts[6] = {
|
||||
0, 1, 2,
|
||||
2, 1, 3
|
||||
};
|
||||
2, 1, 3};
|
||||
|
||||
for (int i = 0; i < 6; i++) pts[i] += curchar*4;
|
||||
|
||||
sg_append_buffer(bind_text.vertex_buffers[0], SG_RANGE_REF(verts));
|
||||
sg_append_buffer(bind_text.vertex_buffers[1], SG_RANGE_REF(color));
|
||||
sg_append_buffer(bind_text.index_buffer, SG_RANGE_REF(pts));
|
||||
for (int i = 0; i < 6; i++)
|
||||
pts[i] += curchar * 4;
|
||||
|
||||
memcpy(text_buffer + (16 * curchar), verts, sizeof(verts));
|
||||
for (int i = 0; i < 4; i++)
|
||||
memcpy(color_buffer + (12 * curchar) + (3 * i), color, sizeof(color));
|
||||
memcpy(text_idx_buffer + (6 * curchar), pts, sizeof(pts));
|
||||
curchar++;
|
||||
return;
|
||||
|
||||
// fill_charverts(verts, cursor, scale, c, offset);
|
||||
|
||||
/*
|
||||
if (drawcaret == curchar) {
|
||||
draw_char_box(c, cursor, scale, color);
|
||||
shader_use(shader);
|
||||
shader_setvec3(shader, "textColor", color);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, font->texID);
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
}
|
||||
*/
|
||||
// sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, SG_RANGE_REF(shadowcolor));
|
||||
/*
|
||||
sg_append_buffer(bind_text.vertex_buffers[0], SG_RANGE_REF(verts));
|
||||
|
||||
|
@ -308,17 +293,15 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
|||
*/
|
||||
offset[0] = offset[1] = 0;
|
||||
fill_charverts(verts, cursor, scale, c, offset);
|
||||
/* SET COLOR ? */
|
||||
|
||||
sg_update_buffer(bind_text.vertex_buffers[0], SG_RANGE_REF(verts));
|
||||
}
|
||||
|
||||
void text_settype(struct sFont *mfont)
|
||||
{
|
||||
void text_settype(struct sFont *mfont) {
|
||||
font = mfont;
|
||||
}
|
||||
|
||||
int renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw, int caret)
|
||||
{
|
||||
int renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw, int caret) {
|
||||
int len = strlen(text);
|
||||
drawcaret = caret;
|
||||
|
||||
|
@ -332,29 +315,18 @@ int renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3]
|
|||
float *usecolor = color;
|
||||
|
||||
while (*line != '\0') {
|
||||
|
||||
switch (*line) {
|
||||
case '\n':
|
||||
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
|
||||
if (isblank(*line)) {
|
||||
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor);
|
||||
cursor[0] += font->Characters[*line].Advance * scale;
|
||||
line++;
|
||||
} else if (isspace(*line)) {
|
||||
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor);
|
||||
cursor[1] -= scale * font->height;
|
||||
cursor[0] = pos[0];
|
||||
line++;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
|
||||
cursor[0] += font->Characters[*line].Advance * scale;
|
||||
line++;
|
||||
break;
|
||||
} else {
|
||||
|
||||
case '\t':
|
||||
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
|
||||
cursor[0] += font->Characters[*line].Advance * scale;
|
||||
line++;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
wordstart = line;
|
||||
int wordWidth = 0;
|
||||
|
||||
|
@ -369,18 +341,16 @@ int renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3]
|
|||
}
|
||||
|
||||
while (wordstart < line) {
|
||||
sdrawCharacter(font->Characters[*wordstart], cursor, scale, shader, usecolor);
|
||||
sdrawCharacter(font->Characters[*wordstart], cursor, scale, usecolor);
|
||||
cursor[0] += font->Characters[*wordstart].Advance * scale;
|
||||
wordstart++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if (caret > curchar) {
|
||||
draw_char_box(font->Characters[69], cursor, scale, color);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
return cursor[1] - pos[1];
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define FONT_H
|
||||
|
||||
#include "mathc.h"
|
||||
#include "texture.h"
|
||||
#include "sokol/sokol_gfx.h"
|
||||
#include "texture.h"
|
||||
|
||||
struct shader;
|
||||
struct window;
|
||||
|
@ -14,7 +14,6 @@ struct Character {
|
|||
mfloat_t Bearing[2]; // Offset from baseline to left/top of glyph
|
||||
unsigned int Advance; // Horizontal offset to advance to next glyph
|
||||
struct glrect rect;
|
||||
|
||||
};
|
||||
|
||||
struct sFont {
|
||||
|
@ -25,9 +24,8 @@ struct sFont {
|
|||
};
|
||||
|
||||
void font_init(struct shader *s);
|
||||
void font_frame(struct window *w);
|
||||
struct sFont *MakeFont(const char *fontfile, int height);
|
||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct shader *shader, float color[3]);
|
||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, float color[3]);
|
||||
void text_settype(struct sFont *font);
|
||||
int renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw, int caret);
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include "gameobject.h"
|
||||
|
||||
#include "2dphysics.h"
|
||||
#include "debugdraw.h"
|
||||
#include "input.h"
|
||||
#include "log.h"
|
||||
#include "nuke.h"
|
||||
#include "resources.h"
|
||||
#include "script.h"
|
||||
#include "shader.h"
|
||||
#include "sprite.h"
|
||||
#include "2dphysics.h"
|
||||
#include "script.h"
|
||||
#include "input.h"
|
||||
#include <string.h>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include "resources.h"
|
||||
#include "nuke.h"
|
||||
#include "log.h"
|
||||
#include "debugdraw.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "stb_ds.h"
|
||||
|
||||
|
@ -20,26 +20,23 @@ static int first = -1;
|
|||
const int nameBuf[MAXNAME] = {0};
|
||||
const int prefabNameBuf[MAXNAME] = {0};
|
||||
|
||||
struct gameobject *get_gameobject_from_id(int id)
|
||||
{ if (id < 0) return NULL;
|
||||
|
||||
return &gameobjects[id];
|
||||
}
|
||||
|
||||
struct gameobject *id2go(int id)
|
||||
{
|
||||
struct gameobject *get_gameobject_from_id(int id) {
|
||||
if (id < 0) return NULL;
|
||||
|
||||
return &gameobjects[id];
|
||||
}
|
||||
|
||||
int body2id(cpBody *body)
|
||||
{
|
||||
struct gameobject *id2go(int id) {
|
||||
if (id < 0) return NULL;
|
||||
|
||||
return &gameobjects[id];
|
||||
}
|
||||
|
||||
int body2id(cpBody *body) {
|
||||
return (int)cpBodyGetUserData(body);
|
||||
}
|
||||
|
||||
cpBody *id2body(int id)
|
||||
{
|
||||
cpBody *id2body(int id) {
|
||||
struct gameobject *go = id2go(id);
|
||||
|
||||
if (go)
|
||||
|
@ -48,14 +45,12 @@ cpBody *id2body(int id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int shape2gameobject(cpShape *shape)
|
||||
{
|
||||
int shape2gameobject(cpShape *shape) {
|
||||
struct phys2d_shape *s = cpShapeGetUserData(shape);
|
||||
return s->go;
|
||||
}
|
||||
|
||||
int pos2gameobject(cpVect pos)
|
||||
{
|
||||
int pos2gameobject(cpVect pos) {
|
||||
cpShape *hit = phys2d_query_pos(pos);
|
||||
|
||||
if (hit) {
|
||||
|
@ -80,24 +75,20 @@ int id_from_gameobject(struct gameobject *go) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
void gameobject_set_sensor(int id, int sensor)
|
||||
{
|
||||
void gameobject_set_sensor(int id, int sensor) {
|
||||
id2go(id)->sensor = sensor;
|
||||
gameobject_apply(id2go(id));
|
||||
}
|
||||
|
||||
int go2id(struct gameobject *go)
|
||||
{
|
||||
int go2id(struct gameobject *go) {
|
||||
return id_from_gameobject(go);
|
||||
}
|
||||
|
||||
void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go)
|
||||
{
|
||||
void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
|
||||
cpShapeSetFriction(shape, go->f);
|
||||
cpShapeSetElasticity(shape, go->e);
|
||||
cpShapeSetCollisionType(shape, go2id(go));
|
||||
|
||||
|
||||
/* cpShapeFilter filter;
|
||||
filter.group = go2id(go);
|
||||
filter.categories = 1<<go->layer;
|
||||
|
@ -106,8 +97,7 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go)
|
|||
*/
|
||||
}
|
||||
|
||||
void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go)
|
||||
{
|
||||
void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go) {
|
||||
float moment = cpBodyGetMoment(go->body);
|
||||
struct phys2d_shape *s = cpShapeGetUserData(shape);
|
||||
if (!s) {
|
||||
|
@ -119,8 +109,7 @@ void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go)
|
|||
cpBodySetMoment(go->body, moment);
|
||||
}
|
||||
|
||||
void gameobject_apply(struct gameobject *go)
|
||||
{
|
||||
void gameobject_apply(struct gameobject *go) {
|
||||
cpBodySetType(go->body, go->bodytype);
|
||||
cpBodyEachShape(go->body, go_shape_apply, go);
|
||||
|
||||
|
@ -136,8 +125,7 @@ void gameobject_apply(struct gameobject *go)
|
|||
}
|
||||
}
|
||||
|
||||
static void gameobject_setpickcolor(struct gameobject *go)
|
||||
{
|
||||
static void gameobject_setpickcolor(struct gameobject *go) {
|
||||
/*
|
||||
float r = ((go->editor.id & 0x000000FF) >> 0) / 255.f;
|
||||
float g = ((go->editor.id & 0x0000FF00) >> 8) / 255.f;
|
||||
|
@ -149,8 +137,7 @@ static void gameobject_setpickcolor(struct gameobject *go)
|
|||
*/
|
||||
}
|
||||
|
||||
int MakeGameobject()
|
||||
{
|
||||
int MakeGameobject() {
|
||||
struct gameobject go = {
|
||||
.scale = 1.f,
|
||||
.bodytype = CP_BODY_TYPE_STATIC,
|
||||
|
@ -204,8 +191,7 @@ void gameobject_clean(int id) {
|
|||
}
|
||||
|
||||
/* Really more of a "mark for deletion" ... */
|
||||
void gameobject_delete(int id)
|
||||
{
|
||||
void gameobject_delete(int id) {
|
||||
id2go(id)->next = first;
|
||||
first = id;
|
||||
|
||||
|
@ -231,8 +217,7 @@ void gameobjects_cleanup() {
|
|||
}
|
||||
}
|
||||
|
||||
void gameobject_move(struct gameobject *go, cpVect vec)
|
||||
{
|
||||
void gameobject_move(struct gameobject *go, cpVect vec) {
|
||||
cpVect p = cpBodyGetPosition(go->body);
|
||||
p.x += vec.x;
|
||||
p.y += vec.y;
|
||||
|
@ -241,8 +226,7 @@ void gameobject_move(struct gameobject *go, cpVect vec)
|
|||
phys2d_reindex_body(go->body);
|
||||
}
|
||||
|
||||
void gameobject_rotate(struct gameobject *go, float as)
|
||||
{
|
||||
void gameobject_rotate(struct gameobject *go, float as) {
|
||||
cpFloat a = cpBodyGetAngle(go->body);
|
||||
a += as * deltaT;
|
||||
cpBodySetAngle(go->body, a);
|
||||
|
@ -262,8 +246,7 @@ void gameobject_setpos(struct gameobject *go, cpVect vec) {
|
|||
phys2d_reindex_body(go->body);
|
||||
}
|
||||
|
||||
void object_gui(struct gameobject *go)
|
||||
{
|
||||
void object_gui(struct gameobject *go) {
|
||||
/*
|
||||
float temp_pos[2];
|
||||
temp_pos[0] = cpBodyGetPosition(go->body).x;
|
||||
|
@ -328,14 +311,12 @@ void object_gui(struct gameobject *go)
|
|||
*/
|
||||
}
|
||||
|
||||
|
||||
void body_draw_shapes_dbg(cpBody *body, cpShape *shape, void *data) {
|
||||
struct phys2d_shape *s = cpShapeGetUserData(shape);
|
||||
s->debugdraw(s->data);
|
||||
}
|
||||
|
||||
void gameobject_draw_debug(int go)
|
||||
{
|
||||
void gameobject_draw_debug(int go) {
|
||||
struct gameobject *g = id2go(go);
|
||||
if (!g || !g->body) return;
|
||||
|
||||
|
@ -350,8 +331,11 @@ void gameobject_draw_debugs() {
|
|||
gameobject_draw_debug(i);
|
||||
}
|
||||
|
||||
|
||||
static struct {struct gameobject go; cpVect pos; float angle; } *saveobjects = NULL;
|
||||
static struct {
|
||||
struct gameobject go;
|
||||
cpVect pos;
|
||||
float angle;
|
||||
} *saveobjects = NULL;
|
||||
|
||||
void gameobject_saveall() {
|
||||
arrfree(saveobjects);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef GAMEOBJECT_H
|
||||
#define GAMEOBJECT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "mathc.h"
|
||||
#include "config.h"
|
||||
#include <stdbool.h>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include "2dphysics.h"
|
||||
#include "config.h"
|
||||
#include "mathc.h"
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct shader;
|
||||
struct sprite;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <glad/gl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
#ifndef GLAD_IMPL_UTIL_C_
|
||||
#define GLAD_IMPL_UTIL_C_
|
||||
|
@ -18,8 +18,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int GLAD_GL_VERSION_1_0 = 0;
|
||||
int GLAD_GL_VERSION_1_1 = 0;
|
||||
int GLAD_GL_VERSION_1_2 = 0;
|
||||
|
@ -38,8 +36,6 @@ int GLAD_GL_VERSION_4_2 = 0;
|
|||
int GLAD_GL_VERSION_4_3 = 0;
|
||||
int GLAD_GL_VERSION_4_4 = 0;
|
||||
|
||||
|
||||
|
||||
PFNGLACCUMPROC glad_glAccum = NULL;
|
||||
PFNGLACTIVESHADERPROGRAMPROC glad_glActiveShaderProgram = NULL;
|
||||
PFNGLACTIVETEXTUREPROC glad_glActiveTexture = NULL;
|
||||
|
@ -963,7 +959,6 @@ PFNGLWINDOWPOS3IVPROC glad_glWindowPos3iv = NULL;
|
|||
PFNGLWINDOWPOS3SPROC glad_glWindowPos3s = NULL;
|
||||
PFNGLWINDOWPOS3SVPROC glad_glWindowPos3sv = NULL;
|
||||
|
||||
|
||||
static void glad_gl_load_GL_VERSION_1_0(GLADuserptrloadfunc load, void *userptr) {
|
||||
if (!GLAD_GL_VERSION_1_0) return;
|
||||
glad_glAccum = (PFNGLACCUMPROC)load(userptr, "glAccum");
|
||||
|
@ -1942,8 +1937,6 @@ static void glad_gl_load_GL_VERSION_4_4( GLADuserptrloadfunc load, void* userptr
|
|||
glad_glClearTexSubImage = (PFNGLCLEARTEXSUBIMAGEPROC)load(userptr, "glClearTexSubImage");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(GL_ES_VERSION_3_0) || defined(GL_VERSION_3_0)
|
||||
#define GLAD_GL_IS_SOME_NEW_VERSION 1
|
||||
#else
|
||||
|
@ -2063,8 +2056,7 @@ static int glad_gl_find_core_gl(void) {
|
|||
"OpenGL ES-CL ",
|
||||
"OpenGL ES ",
|
||||
"OpenGL SC ",
|
||||
NULL
|
||||
};
|
||||
NULL};
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
version = (const char *)glad_glGetString(GL_VERSION);
|
||||
|
@ -2128,21 +2120,13 @@ int gladLoadGLUserPtr( GLADuserptrloadfunc load, void *userptr) {
|
|||
|
||||
if (!glad_gl_find_extensions_gl(version)) return 0;
|
||||
|
||||
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
int gladLoadGL(GLADloadfunc load) {
|
||||
return gladLoadGLUserPtr(glad_gl_get_proc_from_userptr, GLAD_GNUC_EXTENSION(void *) load);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1925,7 +1925,6 @@ typedef void (*GLADpostcallback)(void *ret, const char *name, GLADapiproc apipro
|
|||
#define GL_ZOOM_X 0x0D16
|
||||
#define GL_ZOOM_Y 0x0D17
|
||||
|
||||
|
||||
#include <KHR/khrplatform.h>
|
||||
typedef unsigned int GLenum;
|
||||
typedef unsigned char GLboolean;
|
||||
|
@ -1990,7 +1989,6 @@ typedef unsigned short GLhalfNV;
|
|||
typedef GLintptr GLvdpauSurfaceNV;
|
||||
typedef void(GLAD_API_PTR *GLVULKANPROCNV)(void);
|
||||
|
||||
|
||||
#define GL_VERSION_1_0 1
|
||||
GLAD_API_CALL int GLAD_GL_VERSION_1_0;
|
||||
#define GL_VERSION_1_1 1
|
||||
|
@ -2026,7 +2024,6 @@ GLAD_API_CALL int GLAD_GL_VERSION_4_3;
|
|||
#define GL_VERSION_4_4 1
|
||||
GLAD_API_CALL int GLAD_GL_VERSION_4_4;
|
||||
|
||||
|
||||
typedef void(GLAD_API_PTR *PFNGLACCUMPROC)(GLenum op, GLfloat value);
|
||||
typedef void(GLAD_API_PTR *PFNGLACTIVESHADERPROGRAMPROC)(GLuint pipeline, GLuint program);
|
||||
typedef void(GLAD_API_PTR *PFNGLACTIVETEXTUREPROC)(GLenum texture);
|
||||
|
@ -4795,15 +4792,9 @@ GLAD_API_CALL PFNGLWINDOWPOS3SPROC glad_glWindowPos3s;
|
|||
GLAD_API_CALL PFNGLWINDOWPOS3SVPROC glad_glWindowPos3sv;
|
||||
#define glWindowPos3sv glad_glWindowPos3sv
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GLAD_API_CALL int gladLoadGLUserPtr(GLADuserptrloadfunc load, void *userptr);
|
||||
GLAD_API_CALL int gladLoadGL(GLADloadfunc load);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "input.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ffi.h"
|
||||
#include "font.h"
|
||||
#include "log.h"
|
||||
#include "script.h"
|
||||
#include "stb_ds.h"
|
||||
#include "log.h"
|
||||
#include "ffi.h"
|
||||
#include "time.h"
|
||||
#include "font.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#inlcude "stb_ds.h"
|
||||
#include "stb_ds.h"
|
||||
|
||||
int32_t mouseWheelX = 0;
|
||||
int32_t mouseWheelY = 0;
|
||||
|
@ -45,8 +45,7 @@ static struct {
|
|||
JSValue value;
|
||||
} *jshash = NULL;
|
||||
|
||||
JSValue input2js(const char *input)
|
||||
{
|
||||
JSValue input2js(const char *input) {
|
||||
int idx = shgeti(jshash, input);
|
||||
if (idx != -1)
|
||||
return jshash[idx].value;
|
||||
|
@ -60,36 +59,48 @@ JSValue input2js(const char *input)
|
|||
return n;
|
||||
}
|
||||
|
||||
const char *gamepad2str(int btn)
|
||||
{
|
||||
const char *gamepad2str(int btn) {
|
||||
switch (btn) {
|
||||
case GLFW_GAMEPAD_BUTTON_CROSS: return "cross";
|
||||
case GLFW_GAMEPAD_BUTTON_CIRCLE: return "circle";
|
||||
case GLFW_GAMEPAD_BUTTON_SQUARE: return "square";
|
||||
case GLFW_GAMEPAD_BUTTON_TRIANGLE: return "triangle";
|
||||
case GLFW_GAMEPAD_BUTTON_START: return "start";
|
||||
case GLFW_GAMEPAD_BUTTON_LEFT_BUMPER: return "lbump";
|
||||
case GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER: return "rbump";
|
||||
case GLFW_GAMEPAD_BUTTON_GUIDE: return "guide";
|
||||
case GLFW_GAMEPAD_BUTTON_BACK: return "back";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_UP: return "dup";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_DOWN: return "ddown";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_LEFT: return "dleft";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT: return "dright";
|
||||
case GLFW_GAMEPAD_BUTTON_LEFT_THUMB: return "lthumb";
|
||||
case GLFW_GAMEPAD_BUTTON_RIGHT_THUMB: return "rthumb";
|
||||
case GLFW_GAMEPAD_BUTTON_CROSS:
|
||||
return "cross";
|
||||
case GLFW_GAMEPAD_BUTTON_CIRCLE:
|
||||
return "circle";
|
||||
case GLFW_GAMEPAD_BUTTON_SQUARE:
|
||||
return "square";
|
||||
case GLFW_GAMEPAD_BUTTON_TRIANGLE:
|
||||
return "triangle";
|
||||
case GLFW_GAMEPAD_BUTTON_START:
|
||||
return "start";
|
||||
case GLFW_GAMEPAD_BUTTON_LEFT_BUMPER:
|
||||
return "lbump";
|
||||
case GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER:
|
||||
return "rbump";
|
||||
case GLFW_GAMEPAD_BUTTON_GUIDE:
|
||||
return "guide";
|
||||
case GLFW_GAMEPAD_BUTTON_BACK:
|
||||
return "back";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_UP:
|
||||
return "dup";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_DOWN:
|
||||
return "ddown";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_LEFT:
|
||||
return "dleft";
|
||||
case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT:
|
||||
return "dright";
|
||||
case GLFW_GAMEPAD_BUTTON_LEFT_THUMB:
|
||||
return "lthumb";
|
||||
case GLFW_GAMEPAD_BUTTON_RIGHT_THUMB:
|
||||
return "rthumb";
|
||||
}
|
||||
|
||||
return "NOBTN";
|
||||
}
|
||||
|
||||
void register_pawn(struct callee c)
|
||||
{
|
||||
void register_pawn(struct callee c) {
|
||||
pawn_callee = c;
|
||||
}
|
||||
|
||||
void register_gamepad(struct callee c)
|
||||
{
|
||||
void register_gamepad(struct callee c) {
|
||||
gamepad_callee = c;
|
||||
}
|
||||
|
||||
|
@ -108,8 +119,7 @@ void rm_downkey(int key) {
|
|||
}
|
||||
}
|
||||
|
||||
static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos)
|
||||
{
|
||||
static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos) {
|
||||
mouse_delta.x = xpos - mouse_pos.x;
|
||||
mouse_delta.y = ypos - mouse_pos.y;
|
||||
|
||||
|
@ -125,8 +135,7 @@ static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos)
|
|||
JS_FreeValue(js, argv[3]);
|
||||
}
|
||||
|
||||
static void pawn_call_keydown(int key)
|
||||
{
|
||||
static void pawn_call_keydown(int key) {
|
||||
JSValue argv[4];
|
||||
argv[0] = jsinput;
|
||||
argv[1] = jsnum;
|
||||
|
@ -137,14 +146,12 @@ static void pawn_call_keydown(int key)
|
|||
JS_FreeValue(js, argv[3]);
|
||||
}
|
||||
|
||||
static void scroll_cb(GLFWwindow *w, double xoffset, double yoffset)
|
||||
{
|
||||
static void scroll_cb(GLFWwindow *w, double xoffset, double yoffset) {
|
||||
mouseWheelY = yoffset;
|
||||
mouseWheelX = xoffset;
|
||||
}
|
||||
|
||||
static void mb_cb(GLFWwindow *w, int button, int action, int mods)
|
||||
{
|
||||
static void mb_cb(GLFWwindow *w, int button, int action, int mods) {
|
||||
JSValue argv[3];
|
||||
argv[0] = jsinput;
|
||||
switch (action) {
|
||||
|
@ -169,13 +176,11 @@ static void mb_cb(GLFWwindow *w, int button, int action, int mods)
|
|||
script_callee(pawn_callee, 3, argv);
|
||||
}
|
||||
|
||||
void set_mouse_mode(int mousemode)
|
||||
{
|
||||
void set_mouse_mode(int mousemode) {
|
||||
glfwSetInputMode(mainwin->window, GLFW_CURSOR, mousemode);
|
||||
}
|
||||
|
||||
void char_cb(GLFWwindow *w, unsigned int codepoint)
|
||||
{
|
||||
void char_cb(GLFWwindow *w, unsigned int codepoint) {
|
||||
static char out[2] = {0};
|
||||
static JSValue argv[2];
|
||||
|
||||
|
@ -190,15 +195,13 @@ void char_cb(GLFWwindow *w, unsigned int codepoint)
|
|||
|
||||
static GLFWcharfun nukechar;
|
||||
|
||||
void joystick_add(int id)
|
||||
{
|
||||
void joystick_add(int id) {
|
||||
struct joystick joy = {0};
|
||||
joy.id = id;
|
||||
arrpush(joysticks, joy);
|
||||
}
|
||||
|
||||
void joystick_cb(int jid, int event)
|
||||
{
|
||||
void joystick_cb(int jid, int event) {
|
||||
YughWarn("IN joystick cb");
|
||||
if (event == GLFW_CONNECTED) {
|
||||
for (int i = 0; i < arrlen(joysticks); i++)
|
||||
|
@ -215,9 +218,7 @@ void joystick_cb(int jid, int event)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void input_init()
|
||||
{
|
||||
void input_init() {
|
||||
glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb);
|
||||
glfwSetScrollCallback(mainwin->window, scroll_cb);
|
||||
glfwSetMouseButtonCallback(mainwin->window, mb_cb);
|
||||
|
@ -253,13 +254,11 @@ void input_init()
|
|||
jspos = str2js("pos");
|
||||
}
|
||||
|
||||
void input_to_nuke()
|
||||
{
|
||||
void input_to_nuke() {
|
||||
glfwSetCharCallback(mainwin->window, nukechar);
|
||||
}
|
||||
|
||||
void input_to_game()
|
||||
{
|
||||
void input_to_game() {
|
||||
glfwSetCharCallback(mainwin->window, char_cb);
|
||||
}
|
||||
|
||||
|
@ -385,7 +384,6 @@ const char *keyname_extd(int key, int scancode) {
|
|||
}
|
||||
|
||||
if (kkey) return kkey;
|
||||
|
||||
}
|
||||
|
||||
kkey = glfwGetKeyName(key, scancode);
|
||||
|
@ -403,25 +401,27 @@ void call_input_down(int *key) {
|
|||
script_callee(pawn_callee, 3, argv);
|
||||
}
|
||||
|
||||
|
||||
const char *axis2str(int axis)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_X: return "lx";
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_Y: return "ly";
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_X: return "rx";
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_Y: return "ry";
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_TRIGGER: return "ltrigger";
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER: return "rtrigger";
|
||||
const char *axis2str(int axis) {
|
||||
switch (axis) {
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_X:
|
||||
return "lx";
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_Y:
|
||||
return "ly";
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_X:
|
||||
return "rx";
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_Y:
|
||||
return "ry";
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_TRIGGER:
|
||||
return "ltrigger";
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER:
|
||||
return "rtrigger";
|
||||
}
|
||||
|
||||
return "NOAXIS";
|
||||
}
|
||||
|
||||
/* This is called once every frame - or more if we want it more! */
|
||||
void input_poll(double wait)
|
||||
{
|
||||
void input_poll(double wait) {
|
||||
mouse_delta = cpvzero;
|
||||
mouseWheelX = 0;
|
||||
mouseWheelY = 0;
|
||||
|
@ -450,8 +450,7 @@ void input_poll(double wait)
|
|||
argv[2] = num_cache[1];
|
||||
script_callee(gamepad_callee, 3, argv);
|
||||
}
|
||||
}
|
||||
else if (!state.buttons[b] && joysticks[i].state.buttons[b]) {
|
||||
} else if (!state.buttons[b] && joysticks[i].state.buttons[b]) {
|
||||
argv[2] = num_cache[2];
|
||||
script_callee(gamepad_callee, 3, argv);
|
||||
}
|
||||
|
@ -497,8 +496,7 @@ int key_is_num(int key) {
|
|||
return key <= 57 && key >= 48;
|
||||
}
|
||||
|
||||
void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods)
|
||||
{
|
||||
void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods) {
|
||||
JSValue argv[3];
|
||||
argv[0] = jsinput;
|
||||
argv[1] = input2js(keyname_extd(key, scancode));
|
||||
|
@ -536,18 +534,15 @@ void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods
|
|||
}
|
||||
}
|
||||
|
||||
void cursor_hide()
|
||||
{
|
||||
void cursor_hide() {
|
||||
glfwSetInputMode(mainwin->window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
|
||||
void cursor_show()
|
||||
{
|
||||
void cursor_show() {
|
||||
glfwSetInputMode(mainwin->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
int action_down(int scancode)
|
||||
{
|
||||
int action_down(int scancode) {
|
||||
for (int i = 0; i < arrlen(downkeys); i++) {
|
||||
if (downkeys[i] == scancode)
|
||||
return 1;
|
||||
|
@ -556,8 +551,7 @@ int action_down(int scancode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int action_up(int scancode)
|
||||
{
|
||||
int action_up(int scancode) {
|
||||
int found = 0;
|
||||
for (int i = 0; i < arrlen(downkeys); i++) {
|
||||
if (downkeys[i] == scancode) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "script.h"
|
||||
#include "window.h"
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include "script.h"
|
||||
#include <stdint.h>
|
||||
|
||||
extern int32_t mouseWheelX;
|
||||
extern int32_t mouseWheelY;
|
||||
|
@ -33,8 +33,7 @@ void quit();
|
|||
|
||||
void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods);
|
||||
|
||||
struct inputaction
|
||||
{
|
||||
struct inputaction {
|
||||
int scancode;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
#include "level.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "gameobject.h"
|
||||
#include "resources.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stb_ds.h"
|
||||
|
||||
void save_level(char name[MAXNAME])
|
||||
{
|
||||
void save_level(char name[MAXNAME]) {
|
||||
FILE *lfile = res_open(name, "wb+");
|
||||
|
||||
if (!lfile) return;
|
||||
|
||||
|
||||
int objs = arrlen(gameobjects);
|
||||
fwrite(&objs, sizeof(objs), 1, lfile);
|
||||
|
||||
fclose(lfile);
|
||||
}
|
||||
|
||||
void load_level(char name[MAXNAME])
|
||||
{
|
||||
void load_level(char name[MAXNAME]) {
|
||||
/*
|
||||
FILE *lfile = fopen(name, "rb");
|
||||
|
||||
|
@ -44,8 +41,7 @@ void load_level(char name[MAXNAME])
|
|||
*/
|
||||
}
|
||||
|
||||
void new_level()
|
||||
{
|
||||
void new_level() {
|
||||
for (int i = 0; i < arrlen(gameobjects); i++)
|
||||
gameobject_delete(i);
|
||||
|
||||
|
|
|
@ -13,5 +13,4 @@ void save_level(char name[MAXNAME]);
|
|||
void load_level(char name[MAXNAME]);
|
||||
void new_level();
|
||||
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -27,15 +27,12 @@ extern "C" {
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// CONFIG
|
||||
#define MATHC_USE_INT32
|
||||
#define MATHC_USE_SINGLE_FLOATING_POINT
|
||||
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MATHC_VERSION_YYYY 2019
|
||||
#define MATHC_VERSION_MM 02
|
||||
|
@ -128,9 +125,6 @@ extern const float UNITMAT4[16];
|
|||
typedef float mfloat_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#define MPI 3.1415926536f
|
||||
#define MPI_2 1.5707963268f
|
||||
#define MPI_4 0.7853981634f
|
||||
|
@ -177,7 +171,6 @@ extern const float UNITMAT4[16];
|
|||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* World constants */
|
||||
extern const mfloat_t VEC3ZERO[3];
|
||||
extern const mfloat_t UP[3];
|
||||
|
@ -187,10 +180,6 @@ extern const float UNITMAT4[16];
|
|||
extern const mfloat_t RIGHT[3];
|
||||
extern const mfloat_t LEFT[3];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(MATHC_USE_STRUCT_FUNCTIONS) || defined(MATHC_USE_POINTER_STRUCT_FUNCTIONS)
|
||||
#if defined(MATHC_USE_INT)
|
||||
struct vec2i {
|
||||
|
@ -658,24 +647,17 @@ Matrix 4×4 representation:
|
|||
mfloat_t **vec3_orthonormalization(mfloat_t result[3][3],
|
||||
mfloat_t basis[3][3]);
|
||||
|
||||
|
||||
|
||||
mfloat_t *vec3_rotate_quat(mfloat_t *result, const mfloat_t *v,
|
||||
const mfloat_t *q);
|
||||
|
||||
struct vec3 psvec3_rotate_quat(const struct vec3 *v, struct quat *q);
|
||||
|
||||
|
||||
bool vec4_is_zero(mfloat_t *v0);
|
||||
bool vec4_is_equal(mfloat_t *v0, mfloat_t *v1);
|
||||
mfloat_t *vec4(mfloat_t *result, mfloat_t x, mfloat_t y, mfloat_t z,
|
||||
mfloat_t w);
|
||||
mfloat_t *vec4_assign(mfloat_t *result, mfloat_t *v0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(MATHC_USE_INT)
|
||||
mfloat_t *vec4_assign_vec4i(mfloat_t *result, mint_t *v0);
|
||||
#endif
|
||||
|
@ -711,15 +693,11 @@ Matrix 4×4 representation:
|
|||
mfloat_t *vec4_lerp(mfloat_t *result, mfloat_t *v0, mfloat_t *v1,
|
||||
mfloat_t f);
|
||||
|
||||
|
||||
bool quat_is_zero(mfloat_t *q0);
|
||||
bool quat_is_equal(mfloat_t *q0, mfloat_t *q1);
|
||||
mfloat_t *quat(mfloat_t *result, mfloat_t x, mfloat_t y, mfloat_t z,
|
||||
mfloat_t w);
|
||||
|
||||
|
||||
|
||||
|
||||
mfloat_t *quat_assign(mfloat_t *result, mfloat_t *q0);
|
||||
mfloat_t *quat_zero(mfloat_t *result);
|
||||
mfloat_t *quat_null(mfloat_t *result);
|
||||
|
@ -755,7 +733,6 @@ Matrix 4×4 representation:
|
|||
|
||||
mfloat_t *quat_from_euler(mfloat_t *q, const mfloat_t *euler);
|
||||
|
||||
|
||||
mfloat_t *mat2(mfloat_t *result, mfloat_t m11, mfloat_t m12,
|
||||
mfloat_t m21, mfloat_t m22);
|
||||
mfloat_t *mat2_zero(mfloat_t *result);
|
||||
|
@ -822,7 +799,6 @@ Matrix 4×4 representation:
|
|||
mfloat_t *mat4_translation(mfloat_t *result, mfloat_t *m0,
|
||||
mfloat_t *v0);
|
||||
|
||||
|
||||
mfloat_t *mat4_translate(mfloat_t *result, mfloat_t *m0,
|
||||
mfloat_t *v0);
|
||||
mfloat_t *mat4_translate_vec3(mfloat_t *mat4, mfloat_t *vec3);
|
||||
|
@ -838,7 +814,6 @@ Matrix 4×4 representation:
|
|||
mfloat_t *mat4_scale_vec2f(mfloat_t *mat4, mfloat_t f);
|
||||
mfloat_t *mat4_scale_vec3f(mfloat_t *mat4, mfloat_t f);
|
||||
|
||||
|
||||
mfloat_t *mat4_multiply(mfloat_t *result, mfloat_t *m0,
|
||||
mfloat_t *m1);
|
||||
mfloat_t *mat4_multiply_f(mfloat_t *result, mfloat_t *m0,
|
||||
|
@ -1071,7 +1046,6 @@ Matrix 4×4 representation:
|
|||
bool squat_is_zero(struct quat q0);
|
||||
bool squat_is_equal(struct quat q0, struct quat q1);
|
||||
|
||||
|
||||
struct quat squat(mfloat_t x, mfloat_t y, mfloat_t z, mfloat_t w);
|
||||
struct quat squat_assign(struct quat q0);
|
||||
struct quat squat_zero(void);
|
||||
|
@ -1094,7 +1068,6 @@ Matrix 4×4 representation:
|
|||
|
||||
struct quat squat_from_euler(mfloat_t x, mfloat_t y, mfloat_t z);
|
||||
|
||||
|
||||
mfloat_t squat_length(struct quat q0);
|
||||
mfloat_t squat_length_squared(struct quat q0);
|
||||
mfloat_t squat_angle(struct quat q0, struct quat q1);
|
||||
|
|
|
@ -1,59 +1,53 @@
|
|||
#define NK_INCLUDE_FIXED_TYPES
|
||||
#define NK_INCLUDE_STANDARD_IO
|
||||
#define NK_INCLUDE_STANDARD_VARARGS
|
||||
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||
#define NK_INCLUDE_FONT_BAKING
|
||||
#define NK_INCLUDE_DEFAULT_FONT
|
||||
#define NK_INCLUDE_STANDARD_BOOL
|
||||
|
||||
#define NK_IMPLEMENTATION
|
||||
#define NK_GLFW_GL3_IMPLEMENTATION
|
||||
#define NK_KEYSTATE_BASED_INPUT
|
||||
|
||||
#define STBTT_STATIC
|
||||
|
||||
#include "nuke.h"
|
||||
#include "nuklear_glfw_gl3.h"
|
||||
|
||||
#define SOKOL_GLCORE33
|
||||
#include "sokol/sokol_gfx.h"
|
||||
|
||||
#define SOKOL_NUKLEAR_NO_SOKOL_APP
|
||||
#define SOKOL_NUKLEAR_IMPL
|
||||
|
||||
#include "sokol/sokol_nuklear.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "window.h"
|
||||
#include "texture.h"
|
||||
#include "log.h"
|
||||
#include "texture.h"
|
||||
#include "window.h"
|
||||
|
||||
#define MAX_VERTEX_BUFFER 512 * 1024
|
||||
#define MAX_ELEMENT_BUFFER 128 * 1024
|
||||
|
||||
struct nk_context *ctx;
|
||||
static struct nk_glfw nkglfw = {0};
|
||||
|
||||
//static struct nk_glfw nkglfw = {0};
|
||||
|
||||
void nuke_init(struct window *win) {
|
||||
window_makecurrent(win);
|
||||
|
||||
ctx = nk_glfw3_init(&nkglfw, win->window, NK_GLFW3_INSTALL_CALLBACKS);
|
||||
|
||||
struct nk_font_atlas *atlas;
|
||||
nk_glfw3_font_stash_begin(&nkglfw, &atlas);
|
||||
struct nk_font *noto = nk_font_atlas_add_from_file(atlas, "fonts/teenytinypixels.tff", 14, 0);
|
||||
nk_glfw3_font_stash_end(&nkglfw);
|
||||
snk_setup(&(snk_desc_t){
|
||||
.no_default_font = false
|
||||
});
|
||||
}
|
||||
|
||||
void nuke_start()
|
||||
{
|
||||
nk_glfw3_new_frame(&nkglfw);
|
||||
void nuke_start() {
|
||||
ctx = snk_new_frame();
|
||||
}
|
||||
|
||||
void nuke_end()
|
||||
{
|
||||
nk_glfw3_render(&nkglfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
|
||||
void nuke_end() {
|
||||
snk_render(1200,720);
|
||||
}
|
||||
|
||||
|
||||
int nuke_begin(const char *lbl, struct nk_rect rect, int flags) {
|
||||
return nk_begin(ctx, lbl, rect, flags);
|
||||
}
|
||||
|
||||
int nuke_begin_win(const char *lbl)
|
||||
{
|
||||
int nuke_begin_win(const char *lbl) {
|
||||
return nk_begin(ctx, lbl, nk_rect(10, 10, 400, 600), NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_TITLE);
|
||||
}
|
||||
|
||||
|
@ -65,8 +59,7 @@ struct nk_rect nuke_win_get_bounds() {
|
|||
return nk_window_get_bounds(ctx);
|
||||
}
|
||||
|
||||
void nuke_row(int height)
|
||||
{
|
||||
void nuke_row(int height) {
|
||||
nk_layout_row_dynamic(ctx, height, 1);
|
||||
}
|
||||
|
||||
|
@ -115,8 +108,7 @@ void nuke_checkbox(const char *lbl, int *val) {
|
|||
nk_checkbox_label(ctx, lbl, val);
|
||||
}
|
||||
|
||||
void nuke_scrolltext(char *str)
|
||||
{
|
||||
void nuke_scrolltext(char *str) {
|
||||
nk_edit_string_zero_terminated(ctx, NK_EDIT_MULTILINE | NK_EDIT_GOTO_END_ON_ACTIVATE, str, 1024 * 1024 * 5, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
#ifndef 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_VERTEX_BUFFER_OUTPUT
|
||||
|
||||
#include "nuklear.h"
|
||||
|
||||
struct window;
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
#include "openglrender.h"
|
||||
|
||||
#include "sprite.h"
|
||||
#include "shader.h"
|
||||
#include "font.h"
|
||||
#include "config.h"
|
||||
#include "gameobject.h"
|
||||
#include "camera.h"
|
||||
#include "window.h"
|
||||
#include "debugdraw.h"
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
#include "datastream.h"
|
||||
#include "debugdraw.h"
|
||||
#include "font.h"
|
||||
#include "gameobject.h"
|
||||
#include "log.h"
|
||||
#include "nuke.h"
|
||||
#include "shader.h"
|
||||
#include "sprite.h"
|
||||
#include "window.h"
|
||||
#include "model.h"
|
||||
#include "stb_ds.h"
|
||||
|
||||
#include "HandmadeMath.h"
|
||||
|
||||
int renderMode = LIT;
|
||||
|
||||
|
@ -56,58 +60,164 @@ struct sprite *tsprite = NULL;
|
|||
|
||||
const char *donquixote;
|
||||
|
||||
static struct model *duck;
|
||||
|
||||
sg_image ddimg;
|
||||
|
||||
void debug_draw_phys(int draw) {
|
||||
debugDrawPhysics = draw;
|
||||
}
|
||||
|
||||
void opengl_rendermode(enum RenderMode r)
|
||||
{
|
||||
void opengl_rendermode(enum RenderMode r) {
|
||||
renderMode = r;
|
||||
}
|
||||
|
||||
sg_pipeline mainpip;
|
||||
sg_pass_action pass_action = {0};
|
||||
|
||||
void openglInit()
|
||||
{
|
||||
static struct {
|
||||
sg_pass_action pass_action;
|
||||
sg_pass pass;
|
||||
sg_pipeline pipe;
|
||||
sg_shader shader;
|
||||
} sg_shadow;
|
||||
|
||||
static struct {
|
||||
sg_shader shader;
|
||||
sg_pipeline pipe;
|
||||
sg_bindings bind;
|
||||
sg_pass pass;
|
||||
sg_image img;
|
||||
sg_image depth_img;
|
||||
} crt_post;
|
||||
|
||||
|
||||
void openglInit() {
|
||||
if (!mainwin) {
|
||||
YughError("No window to init OpenGL on.", 1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// donquixote = slurp_text("quixote.txt");
|
||||
|
||||
////// MAKE SHADERS
|
||||
spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl");
|
||||
wireframeShader = MakeShader("spritevert.glsl", "spritewireframefrag.glsl");
|
||||
animSpriteShader = MakeShader("animspritevert.glsl", "animspritefrag.glsl");
|
||||
textShader = MakeShader("textvert.glsl", "textfrag.glsl");
|
||||
|
||||
font_init(textShader);
|
||||
sprite_initialize();
|
||||
font_init(NULL);
|
||||
debugdraw_init();
|
||||
sprite_initialize();
|
||||
nuke_init(mainwin);
|
||||
|
||||
glClearColor(editorClearColor[0], editorClearColor[1], editorClearColor[2], editorClearColor[3]);
|
||||
model_init();
|
||||
// duck = MakeModel("sponza.glb");
|
||||
|
||||
pass_action = (sg_pass_action){
|
||||
.colors[0] = {.action = SG_ACTION_CLEAR, .value = {editorClearColor[1], editorClearColor[2], editorClearColor[3], 1.f}},
|
||||
};
|
||||
|
||||
crt_post.shader = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/postvert.glsl"),
|
||||
.fs.source = slurp_text("shaders/crtfrag.glsl"),
|
||||
|
||||
.fs.images[0] = {
|
||||
.name = "diffuse_texture",
|
||||
.image_type = SG_IMAGETYPE_2D,
|
||||
.sampler_type = SG_SAMPLERTYPE_FLOAT
|
||||
}
|
||||
});
|
||||
|
||||
crt_post.pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = crt_post.shader,
|
||||
.layout = {
|
||||
.attrs = {
|
||||
[0].format = SG_VERTEXFORMAT_FLOAT2,
|
||||
[1].format = SG_VERTEXFORMAT_FLOAT2
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
crt_post.img = sg_make_image(&(sg_image_desc){
|
||||
.render_target = true,
|
||||
.width = 1200,
|
||||
.height = 720,
|
||||
});
|
||||
|
||||
crt_post.depth_img = sg_make_image(&(sg_image_desc){
|
||||
.render_target = true,
|
||||
.width = 1200,
|
||||
.height = 720,
|
||||
.pixel_format = SG_PIXELFORMAT_DEPTH_STENCIL
|
||||
});
|
||||
|
||||
crt_post.pass = sg_make_pass(&(sg_pass_desc){
|
||||
.color_attachments[0].image = crt_post.img,
|
||||
.depth_stencil_attachment.image = crt_post.depth_img,
|
||||
});
|
||||
|
||||
float crt_quad[] = {
|
||||
-1, 1, 0, 1,
|
||||
-1, -1, 0, 0,
|
||||
1, -1, 1, 0,
|
||||
-1, 1, 0, 1,
|
||||
1, -1, 1, 0,
|
||||
1, 1, 1, 1
|
||||
};
|
||||
|
||||
crt_post.bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.size = sizeof(crt_quad),
|
||||
.data = crt_quad
|
||||
});
|
||||
|
||||
crt_post.bind.fs_images[0] = crt_post.img;
|
||||
|
||||
/*
|
||||
glCullFace(GL_BACK);
|
||||
sg_image_desc shadow_desc = {
|
||||
.render_target = true,
|
||||
.width = 1024,
|
||||
.height = 1024,
|
||||
.pixel_format = SG_PIXELFORMAT_R32F,
|
||||
};
|
||||
sg_image depth_img = sg_make_image(&shadow_desc);
|
||||
shadow_desc.pixel_format = SG_PIXELFORMAT_DEPTH;
|
||||
ddimg = sg_make_image(&shadow_desc);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
duck = MakeModel("sponza.glb");
|
||||
|
||||
glGenBuffers(1, &projUBO);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, projUBO);
|
||||
glBufferData(GL_UNIFORM_BUFFER, 64, NULL, GL_DYNAMIC_DRAW);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 0, projUBO, 0, sizeof(float) * 16);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
sg_shadow.pass = sg_make_pass(&(sg_pass_desc){
|
||||
.color_attachments[0].image = depth_img,
|
||||
.depth_stencil_attachment.image = ddimg,
|
||||
});
|
||||
|
||||
sg_shadow.pass_action = (sg_pass_action) {
|
||||
.colors[0] = { .action=SG_ACTION_CLEAR, .value = {1,1,1,1} } };
|
||||
|
||||
sg_shadow.shader = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/shadowvert.glsl"),
|
||||
.fs.source = slurp_text("shaders/shadowfrag.glsl"),
|
||||
.vs.uniform_blocks[0] = {
|
||||
.size = sizeof(float) * 16 * 2,
|
||||
.uniforms = {
|
||||
[0] = {.name = "lightSpaceMatrix", .type = SG_UNIFORMTYPE_MAT4},
|
||||
[1] = {.name = "model", .type = SG_UNIFORMTYPE_MAT4},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sg_shadow.pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = sg_shadow.shader,
|
||||
.layout = {
|
||||
.attrs = {
|
||||
[0].format = SG_VERTEXFORMAT_FLOAT3,
|
||||
}
|
||||
},
|
||||
.depth = {
|
||||
.compare = SG_COMPAREFUNC_LESS_EQUAL,
|
||||
.write_enabled = true,
|
||||
.pixel_format = SG_PIXELFORMAT_DEPTH
|
||||
},
|
||||
.colors[0].pixel_format = SG_PIXELFORMAT_R32F,
|
||||
.index_type = SG_INDEXTYPE_UINT16,
|
||||
.cull_mode = SG_CULLMODE_BACK,
|
||||
});
|
||||
|
||||
shader_setUBO(spriteShader, "Projection", 0);
|
||||
shader_setUBO(textShader, "Projection", 0);
|
||||
shader_setUBO(animSpriteShader, "Projection", 0);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
static cpBody *camera = NULL;
|
||||
void set_cam_body(cpBody *body) {
|
||||
camera = body;
|
||||
|
@ -116,17 +226,52 @@ void set_cam_body(cpBody *body) {
|
|||
cpVect cam_pos() {
|
||||
return camera ? cpBodyGetPosition(camera) : cpvzero;
|
||||
}
|
||||
|
||||
static float zoom = 1.f;
|
||||
float cam_zoom() { return zoom; }
|
||||
|
||||
|
||||
void add_zoom(float val) { zoom = val; }
|
||||
|
||||
mfloat_t projection[16] = {0.f};
|
||||
|
||||
void openglRender(struct window *window)
|
||||
{
|
||||
sg_begin_default_pass(&pass_action, window->width, window->height);
|
||||
HMM_Vec3 dirl_pos = {4, 100, 20};
|
||||
|
||||
void openglRender(struct window *window) {
|
||||
/*
|
||||
HMM_Mat4 model = HMM_M4D(1.f);
|
||||
float scale = 0.08;
|
||||
model = HMM_MulM4(model, HMM_Scale((HMM_Vec3){scale,scale,scale}));
|
||||
|
||||
|
||||
// Shadow pass
|
||||
sg_begin_pass(sg_shadow.pass, &sg_shadow.pass_action);
|
||||
sg_apply_pipeline(sg_shadow.pipe);
|
||||
|
||||
HMM_Mat4 light_proj = HMM_Orthographic_RH_ZO(-100.f, 100.f, -100.f, 100.f, 1.f, 100.f);
|
||||
HMM_Mat4 light_view = HMM_LookAt_RH(dirl_pos, (HMM_Vec3){0,0,0}, (HMM_Vec3){0,1,0});
|
||||
|
||||
HMM_Mat4 lsm = HMM_MulM4(light_proj, light_view);
|
||||
|
||||
HMM_Mat4 subo[2];
|
||||
subo[0] = lsm;
|
||||
subo[1] = model;
|
||||
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(subo));
|
||||
|
||||
for (int i = 0; i < arrlen(duck->meshes); i++) {
|
||||
sg_bindings sbind = {0};
|
||||
sbind.vertex_buffers[0] = duck->meshes[i].bind.vertex_buffers[0];
|
||||
sbind.index_buffer = duck->meshes[i].bind.index_buffer;
|
||||
sg_apply_bindings(&sbind);
|
||||
sg_draw(0,duck->meshes[i].face_count,1);
|
||||
}
|
||||
sg_end_pass();
|
||||
|
||||
draw_model(duck,model, lsm);
|
||||
*/
|
||||
|
||||
// sg_begin_default_pass(&pass_action, window->width, window->height);
|
||||
sg_begin_pass(crt_post.pass, &pass_action);
|
||||
|
||||
//////////// 2D projection
|
||||
cpVect pos = cam_pos();
|
||||
|
@ -137,43 +282,35 @@ void openglRender(struct window *window)
|
|||
pos.y + zoom * window->height / 2, -1.f, 1.f);
|
||||
|
||||
mfloat_t ui_projection[16] = {0.f};
|
||||
mat4_ortho(ui_projection, 0,
|
||||
window->width,
|
||||
0,
|
||||
window->height, -1.f, 1.f);
|
||||
mat4_ortho(ui_projection, 0, window->width, 0, window->height, -1.f, 1.f);
|
||||
|
||||
sprite_draw_all();
|
||||
gui_draw_img("pill1.png", 200, 200);
|
||||
float a[2] = {100,100};
|
||||
float w[3] = {1.f,1.f,1.f};
|
||||
renderText("TEST RENDER", a, 1.f, w, 0,-1);
|
||||
sprite_flush();
|
||||
|
||||
float b[2] = {50,50};
|
||||
renderText("TEST @@@@ RENDER", b, 1.f, w, 0,-1);
|
||||
|
||||
/* UI Elements & Debug elements */
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
// glDisable(GL_DEPTH_TEST);
|
||||
//// DEBUG
|
||||
// if (debugDrawPhysics)
|
||||
// gameobject_draw_debugs();
|
||||
if (debugDrawPhysics)
|
||||
gameobject_draw_debugs();
|
||||
|
||||
// call_debugs();
|
||||
call_debugs();
|
||||
debug_flush();
|
||||
|
||||
////// TEXT && GUI
|
||||
// glBindBuffer(GL_UNIFORM_BUFFER, projUBO);
|
||||
// glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, ui_projection);
|
||||
call_gui();
|
||||
|
||||
text_flush();
|
||||
|
||||
// call_gui();
|
||||
|
||||
// nuke_start();
|
||||
// call_nk_gui();
|
||||
// nuke_end();
|
||||
|
||||
nuke_start();
|
||||
call_nk_gui();
|
||||
nuke_end();
|
||||
|
||||
sg_end_pass();
|
||||
sg_commit();
|
||||
|
||||
sprite_flush();
|
||||
sg_begin_default_pass(&pass_action, window->width, window->height);
|
||||
sg_apply_pipeline(crt_post.pipe);
|
||||
sg_apply_bindings(&crt_post.bind);
|
||||
sg_draw(0,6,1);
|
||||
sg_end_pass();
|
||||
|
||||
|
||||
sg_commit();
|
||||
}
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
#ifndef OPENGL_RENDER_H
|
||||
#define OPENGL_RENDER_H
|
||||
|
||||
#include "sokol/sokol_gfx.h"
|
||||
#include "HandmadeMath.h"
|
||||
|
||||
struct mCamera;
|
||||
struct window;
|
||||
|
||||
extern struct shader *spriteShader;
|
||||
extern struct shader *animSpriteShader;
|
||||
|
||||
extern sg_image ddimg;
|
||||
|
||||
extern struct sprite *tsprite;
|
||||
|
||||
extern int renderMode;
|
||||
|
||||
extern HMM_Vec3 dirl_pos;
|
||||
|
||||
extern float projection[16];
|
||||
|
||||
extern float gridScale;
|
||||
|
|
|
@ -34,18 +34,16 @@
|
|||
#define PARSON_IMPL_VERSION_MINOR 4
|
||||
#define PARSON_IMPL_VERSION_PATCH 0
|
||||
|
||||
#if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\
|
||||
|| (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\
|
||||
|| (PARSON_VERSION_PATCH != PARSON_IMPL_VERSION_PATCH)
|
||||
#if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR) || (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR) || (PARSON_VERSION_PATCH != PARSON_IMPL_VERSION_PATCH)
|
||||
#error "parson version mismatch between parson.c and parson.h"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Apparently sscanf is not implemented in some "standard" libraries, so don't use it, if you
|
||||
* don't have to. */
|
||||
|
@ -73,7 +71,10 @@
|
|||
|
||||
#define SIZEOF_TOKEN(a) (sizeof(a) - 1)
|
||||
#define SKIP_CHAR(str) ((*str)++)
|
||||
#define SKIP_WHITESPACES(str) while (isspace((unsigned char)(**str))) { SKIP_CHAR(str); }
|
||||
#define SKIP_WHITESPACES(str) \
|
||||
while (isspace((unsigned char)(**str))) { \
|
||||
SKIP_CHAR(str); \
|
||||
}
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#undef malloc
|
||||
|
@ -448,11 +449,7 @@ static JSON_Status json_object_init(JSON_Object *object, size_t capacity) {
|
|||
object->values = (JSON_Value **)parson_malloc(object->item_capacity * sizeof(*object->values));
|
||||
object->cell_ixs = (size_t *)parson_malloc(object->item_capacity * sizeof(*object->cell_ixs));
|
||||
object->hashes = (unsigned long *)parson_malloc(object->item_capacity * sizeof(*object->hashes));
|
||||
if (object->cells == NULL
|
||||
|| object->names == NULL
|
||||
|| object->values == NULL
|
||||
|| object->cell_ixs == NULL
|
||||
|| object->hashes == NULL) {
|
||||
if (object->cells == NULL || object->names == NULL || object->values == NULL || object->cell_ixs == NULL || object->hashes == NULL) {
|
||||
goto error;
|
||||
}
|
||||
for (i = 0; i < object->cell_capacity; i++) {
|
||||
|
@ -660,8 +657,7 @@ static JSON_Status json_object_remove_internal(JSON_Object *object, const char *
|
|||
break;
|
||||
}
|
||||
k = object->hashes[object->cells[j]] & (object->cell_capacity - 1);
|
||||
if ((j > i && (k <= i || k > j))
|
||||
|| (j < i && (k <= i && k > j))) {
|
||||
if ((j > i && (k <= i || k > j)) || (j < i && (k <= i && k > j))) {
|
||||
object->cell_ixs[object->cells[j]] = i;
|
||||
object->cells[i] = object->cells[j];
|
||||
i = j;
|
||||
|
@ -824,7 +820,6 @@ static JSON_Status parse_utf16(const char **unprocessed, char **processed) {
|
|||
return JSONSuccess;
|
||||
}
|
||||
|
||||
|
||||
/* Copies and processes passed string up to supplied length.
|
||||
Example: "\u006Corem ipsum" -> lorem ipsum */
|
||||
static char *process_string(const char *input, size_t input_len, size_t *output_len) {
|
||||
|
@ -841,14 +836,30 @@ static char* process_string(const char *input, size_t input_len, size_t *output_
|
|||
if (*input_ptr == '\\') {
|
||||
input_ptr++;
|
||||
switch (*input_ptr) {
|
||||
case '\"': *output_ptr = '\"'; break;
|
||||
case '\\': *output_ptr = '\\'; break;
|
||||
case '/': *output_ptr = '/'; break;
|
||||
case 'b': *output_ptr = '\b'; break;
|
||||
case 'f': *output_ptr = '\f'; break;
|
||||
case 'n': *output_ptr = '\n'; break;
|
||||
case 'r': *output_ptr = '\r'; break;
|
||||
case 't': *output_ptr = '\t'; break;
|
||||
case '\"':
|
||||
*output_ptr = '\"';
|
||||
break;
|
||||
case '\\':
|
||||
*output_ptr = '\\';
|
||||
break;
|
||||
case '/':
|
||||
*output_ptr = '/';
|
||||
break;
|
||||
case 'b':
|
||||
*output_ptr = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
*output_ptr = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
*output_ptr = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
*output_ptr = '\r';
|
||||
break;
|
||||
case 't':
|
||||
*output_ptr = '\t';
|
||||
break;
|
||||
case 'u':
|
||||
if (parse_utf16(&input_ptr, &output_ptr) != JSONSuccess) {
|
||||
goto error;
|
||||
|
@ -907,11 +918,20 @@ static JSON_Value * parse_value(const char **string, size_t nesting) {
|
|||
return parse_array_value(string, nesting + 1);
|
||||
case '\"':
|
||||
return parse_string_value(string);
|
||||
case 'f': case 't':
|
||||
case 'f':
|
||||
case 't':
|
||||
return parse_boolean_value(string);
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
return parse_number_value(string);
|
||||
case 'n':
|
||||
return parse_null_value(string);
|
||||
|
@ -1095,18 +1115,31 @@ static JSON_Value * parse_null_value(const char **string) {
|
|||
}
|
||||
|
||||
/* Serialization */
|
||||
#define APPEND_STRING(str) do { written = append_string(buf, (str));\
|
||||
if (written < 0) { return -1; }\
|
||||
if (buf != NULL) { buf += written; }\
|
||||
written_total += written; } while(0)
|
||||
#define APPEND_STRING(str) \
|
||||
do { \
|
||||
written = append_string(buf, (str)); \
|
||||
if (written < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
if (buf != NULL) { \
|
||||
buf += written; \
|
||||
} \
|
||||
written_total += written; \
|
||||
} while (0)
|
||||
|
||||
#define APPEND_INDENT(level) do { written = append_indent(buf, (level));\
|
||||
if (written < 0) { return -1; }\
|
||||
if (buf != NULL) { buf += written; }\
|
||||
written_total += written; } while(0)
|
||||
#define APPEND_INDENT(level) \
|
||||
do { \
|
||||
written = append_indent(buf, (level)); \
|
||||
if (written < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
if (buf != NULL) { \
|
||||
buf += written; \
|
||||
} \
|
||||
written_total += written; \
|
||||
} while (0)
|
||||
|
||||
static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int level, parson_bool_t is_pretty, char *num_buf)
|
||||
{
|
||||
static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int level, parson_bool_t is_pretty, char *num_buf) {
|
||||
const char *key = NULL, *string = NULL;
|
||||
JSON_Value *temp_value = NULL;
|
||||
JSON_Array *array = NULL;
|
||||
|
@ -1256,45 +1289,113 @@ static int json_serialize_string(const char *string, size_t len, char *buf) {
|
|||
for (i = 0; i < len; i++) {
|
||||
c = string[i];
|
||||
switch (c) {
|
||||
case '\"': APPEND_STRING("\\\""); break;
|
||||
case '\\': APPEND_STRING("\\\\"); break;
|
||||
case '\b': APPEND_STRING("\\b"); break;
|
||||
case '\f': APPEND_STRING("\\f"); break;
|
||||
case '\n': APPEND_STRING("\\n"); break;
|
||||
case '\r': APPEND_STRING("\\r"); break;
|
||||
case '\t': APPEND_STRING("\\t"); break;
|
||||
case '\x00': APPEND_STRING("\\u0000"); break;
|
||||
case '\x01': APPEND_STRING("\\u0001"); break;
|
||||
case '\x02': APPEND_STRING("\\u0002"); break;
|
||||
case '\x03': APPEND_STRING("\\u0003"); break;
|
||||
case '\x04': APPEND_STRING("\\u0004"); break;
|
||||
case '\x05': APPEND_STRING("\\u0005"); break;
|
||||
case '\x06': APPEND_STRING("\\u0006"); break;
|
||||
case '\x07': APPEND_STRING("\\u0007"); break;
|
||||
case '\"':
|
||||
APPEND_STRING("\\\"");
|
||||
break;
|
||||
case '\\':
|
||||
APPEND_STRING("\\\\");
|
||||
break;
|
||||
case '\b':
|
||||
APPEND_STRING("\\b");
|
||||
break;
|
||||
case '\f':
|
||||
APPEND_STRING("\\f");
|
||||
break;
|
||||
case '\n':
|
||||
APPEND_STRING("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
APPEND_STRING("\\r");
|
||||
break;
|
||||
case '\t':
|
||||
APPEND_STRING("\\t");
|
||||
break;
|
||||
case '\x00':
|
||||
APPEND_STRING("\\u0000");
|
||||
break;
|
||||
case '\x01':
|
||||
APPEND_STRING("\\u0001");
|
||||
break;
|
||||
case '\x02':
|
||||
APPEND_STRING("\\u0002");
|
||||
break;
|
||||
case '\x03':
|
||||
APPEND_STRING("\\u0003");
|
||||
break;
|
||||
case '\x04':
|
||||
APPEND_STRING("\\u0004");
|
||||
break;
|
||||
case '\x05':
|
||||
APPEND_STRING("\\u0005");
|
||||
break;
|
||||
case '\x06':
|
||||
APPEND_STRING("\\u0006");
|
||||
break;
|
||||
case '\x07':
|
||||
APPEND_STRING("\\u0007");
|
||||
break;
|
||||
/* '\x08' duplicate: '\b' */
|
||||
/* '\x09' duplicate: '\t' */
|
||||
/* '\x0a' duplicate: '\n' */
|
||||
case '\x0b': APPEND_STRING("\\u000b"); break;
|
||||
case '\x0b':
|
||||
APPEND_STRING("\\u000b");
|
||||
break;
|
||||
/* '\x0c' duplicate: '\f' */
|
||||
/* '\x0d' duplicate: '\r' */
|
||||
case '\x0e': APPEND_STRING("\\u000e"); break;
|
||||
case '\x0f': APPEND_STRING("\\u000f"); break;
|
||||
case '\x10': APPEND_STRING("\\u0010"); break;
|
||||
case '\x11': APPEND_STRING("\\u0011"); break;
|
||||
case '\x12': APPEND_STRING("\\u0012"); break;
|
||||
case '\x13': APPEND_STRING("\\u0013"); break;
|
||||
case '\x14': APPEND_STRING("\\u0014"); break;
|
||||
case '\x15': APPEND_STRING("\\u0015"); break;
|
||||
case '\x16': APPEND_STRING("\\u0016"); break;
|
||||
case '\x17': APPEND_STRING("\\u0017"); break;
|
||||
case '\x18': APPEND_STRING("\\u0018"); break;
|
||||
case '\x19': APPEND_STRING("\\u0019"); break;
|
||||
case '\x1a': APPEND_STRING("\\u001a"); break;
|
||||
case '\x1b': APPEND_STRING("\\u001b"); break;
|
||||
case '\x1c': APPEND_STRING("\\u001c"); break;
|
||||
case '\x1d': APPEND_STRING("\\u001d"); break;
|
||||
case '\x1e': APPEND_STRING("\\u001e"); break;
|
||||
case '\x1f': APPEND_STRING("\\u001f"); break;
|
||||
case '\x0e':
|
||||
APPEND_STRING("\\u000e");
|
||||
break;
|
||||
case '\x0f':
|
||||
APPEND_STRING("\\u000f");
|
||||
break;
|
||||
case '\x10':
|
||||
APPEND_STRING("\\u0010");
|
||||
break;
|
||||
case '\x11':
|
||||
APPEND_STRING("\\u0011");
|
||||
break;
|
||||
case '\x12':
|
||||
APPEND_STRING("\\u0012");
|
||||
break;
|
||||
case '\x13':
|
||||
APPEND_STRING("\\u0013");
|
||||
break;
|
||||
case '\x14':
|
||||
APPEND_STRING("\\u0014");
|
||||
break;
|
||||
case '\x15':
|
||||
APPEND_STRING("\\u0015");
|
||||
break;
|
||||
case '\x16':
|
||||
APPEND_STRING("\\u0016");
|
||||
break;
|
||||
case '\x17':
|
||||
APPEND_STRING("\\u0017");
|
||||
break;
|
||||
case '\x18':
|
||||
APPEND_STRING("\\u0018");
|
||||
break;
|
||||
case '\x19':
|
||||
APPEND_STRING("\\u0019");
|
||||
break;
|
||||
case '\x1a':
|
||||
APPEND_STRING("\\u001a");
|
||||
break;
|
||||
case '\x1b':
|
||||
APPEND_STRING("\\u001b");
|
||||
break;
|
||||
case '\x1c':
|
||||
APPEND_STRING("\\u001c");
|
||||
break;
|
||||
case '\x1d':
|
||||
APPEND_STRING("\\u001d");
|
||||
break;
|
||||
case '\x1e':
|
||||
APPEND_STRING("\\u001e");
|
||||
break;
|
||||
case '\x1f':
|
||||
APPEND_STRING("\\u001f");
|
||||
break;
|
||||
case '/':
|
||||
if (parson_escape_slashes) {
|
||||
APPEND_STRING("\\/"); /* to make json embeddable in xml\/html */
|
||||
|
@ -2331,9 +2432,13 @@ JSON_Status json_validate(const JSON_Value *schema, const JSON_Value *value) {
|
|||
}
|
||||
}
|
||||
return JSONSuccess;
|
||||
case JSONString: case JSONNumber: case JSONBoolean: case JSONNull:
|
||||
case JSONString:
|
||||
case JSONNumber:
|
||||
case JSONBoolean:
|
||||
case JSONNull:
|
||||
return JSONSuccess; /* equality already tested before switch */
|
||||
case JSONError: default:
|
||||
case JSONError:
|
||||
default:
|
||||
return JSONFailure;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
#define parson_parson_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
#if 0
|
||||
} /* unconfuse xcode */
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
#include "particle.h"
|
||||
#include "stb_ds.h"
|
||||
|
||||
struct emitter make_emitter()
|
||||
{
|
||||
struct emitter make_emitter() {
|
||||
struct emitter e = {0};
|
||||
return e;
|
||||
}
|
||||
|
||||
struct emitter set_emitter(struct emitter e)
|
||||
{
|
||||
struct emitter set_emitter(struct emitter e) {
|
||||
arrsetlen(e.particles, e.max);
|
||||
|
||||
e.first = &e.particles[0];
|
||||
|
@ -20,28 +18,20 @@ struct emitter set_emitter(struct emitter e)
|
|||
return e;
|
||||
}
|
||||
|
||||
void free_emitter(struct emitter e)
|
||||
{
|
||||
void free_emitter(struct emitter e) {
|
||||
arrfree(e.particles);
|
||||
}
|
||||
|
||||
void start_emitter(struct emitter e)
|
||||
{
|
||||
|
||||
void start_emitter(struct emitter e) {
|
||||
}
|
||||
|
||||
void pause_emitter(struct emitter e)
|
||||
{
|
||||
|
||||
void pause_emitter(struct emitter e) {
|
||||
}
|
||||
|
||||
void stop_emitter(struct emitter e)
|
||||
{
|
||||
|
||||
void stop_emitter(struct emitter e) {
|
||||
}
|
||||
|
||||
void emitter_step(struct emitter e, double dt)
|
||||
{
|
||||
void emitter_step(struct emitter e, double dt) {
|
||||
for (int i = 0; i < arrlen(e.particles); i++) {
|
||||
if (e.particles[i].life <= 0)
|
||||
continue;
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#include "resources.h"
|
||||
|
||||
#include "config.h"
|
||||
#include <dirent.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "vec.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "log.h"
|
||||
#include "vec.h"
|
||||
#include <dirent.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ftw.h>
|
||||
|
||||
|
@ -33,8 +33,7 @@ struct vec *c_vec = NULL;
|
|||
|
||||
char pathbuf[MAXPATH + 1];
|
||||
|
||||
void resources_init()
|
||||
{
|
||||
void resources_init() {
|
||||
prefabs = vec_make(MAXNAME, 25);
|
||||
|
||||
DATA_PATH = malloc(MAXPATH);
|
||||
|
@ -45,8 +44,7 @@ void resources_init()
|
|||
PREF_PATH = strdup("./tmp/");
|
||||
}
|
||||
|
||||
char *get_filename_from_path(char *path, int extension)
|
||||
{
|
||||
char *get_filename_from_path(char *path, int extension) {
|
||||
char *dirpos = strrchr(path, '/');
|
||||
if (!dirpos)
|
||||
dirpos = path;
|
||||
|
@ -65,24 +63,21 @@ char *get_filename_from_path(char *path, int extension)
|
|||
return filename;
|
||||
}
|
||||
|
||||
char *get_directory_from_path(char *path)
|
||||
{
|
||||
char *get_directory_from_path(char *path) {
|
||||
const char *dirpos = strrchr(path, '/');
|
||||
char *directory = (char *)malloc(sizeof(char) * (dirpos - path + 1));
|
||||
strncpy(directory, path, dirpos - path);
|
||||
return directory;
|
||||
}
|
||||
|
||||
FILE *res_open(char *path, const char *tag)
|
||||
{
|
||||
FILE *res_open(char *path, const char *tag) {
|
||||
strncpy(pathbuf, DATA_PATH, MAXPATH);
|
||||
strncat(pathbuf, path, MAXPATH);
|
||||
FILE *f = fopen(pathbuf, tag);
|
||||
return f;
|
||||
}
|
||||
|
||||
static int ext_check(const char *path, const struct stat *sb, int typeflag)
|
||||
{
|
||||
static int ext_check(const char *path, const struct stat *sb, int typeflag) {
|
||||
if (typeflag == FTW_F) {
|
||||
const char *ext = strrchr(path, '.');
|
||||
if (ext != NULL && !strcmp(ext, cur_ext))
|
||||
|
@ -92,16 +87,14 @@ static int ext_check(const char *path, const struct stat *sb, int typeflag)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void fill_extensions(struct vec *vec, const char *path, const char *ext)
|
||||
{
|
||||
void fill_extensions(struct vec *vec, const char *path, const char *ext) {
|
||||
c_vec = vec;
|
||||
cur_ext = ext;
|
||||
vec_clear(c_vec);
|
||||
ftw(".", ext_check, 10);
|
||||
}
|
||||
|
||||
void findPrefabs()
|
||||
{
|
||||
void findPrefabs() {
|
||||
fill_extensions(prefabs, DATA_PATH, EXT_PREFAB);
|
||||
}
|
||||
|
||||
|
@ -115,8 +108,7 @@ char *str_replace_ext(const char *s, const char *newext) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
FILE *path_open(const char *tag, const char *fmt, ...)
|
||||
{
|
||||
FILE *path_open(const char *tag, const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(pathbuf, fmt, args);
|
||||
|
@ -126,15 +118,13 @@ FILE *path_open(const char *tag, const char *fmt, ...)
|
|||
return f;
|
||||
}
|
||||
|
||||
char *make_path(const char *file)
|
||||
{
|
||||
char *make_path(const char *file) {
|
||||
strncpy(pathbuf, DATA_PATH, MAXPATH);
|
||||
strncat(pathbuf, file, MAXPATH);
|
||||
return pathbuf;
|
||||
}
|
||||
|
||||
char *strdup(const char *s)
|
||||
{
|
||||
char *strdup(const char *s) {
|
||||
char *new = malloc(sizeof(char) * (strlen(s) + 1));
|
||||
strcpy(new, s);
|
||||
return new;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef RESOURCES_H
|
||||
#define RESOURCES_H
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
struct vec;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "script.h"
|
||||
|
||||
#include "stdio.h"
|
||||
#include "log.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#include "ffi.h"
|
||||
#include "font.h"
|
||||
|
@ -10,9 +10,9 @@
|
|||
|
||||
#include "stb_ds.h"
|
||||
|
||||
#include "time.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/types.h"
|
||||
#include "time.h"
|
||||
|
||||
JSContext *js = NULL;
|
||||
JSRuntime *rt = NULL;
|
||||
|
@ -27,8 +27,7 @@ static int load_prefab(const char *fpath, const struct stat *sb, int typeflag) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void script_startup()
|
||||
{
|
||||
void script_startup() {
|
||||
rt = JS_NewRuntime();
|
||||
JS_SetMaxStackSize(rt, 0);
|
||||
js = JS_NewContext(rt);
|
||||
|
@ -57,14 +56,12 @@ time_t file_mod_secs(const char *file) {
|
|||
return attr.st_mtime;
|
||||
}
|
||||
|
||||
void js_stacktrace()
|
||||
{
|
||||
void js_stacktrace() {
|
||||
call_callee(&stacktrace_callee);
|
||||
return;
|
||||
}
|
||||
|
||||
void js_dump_stack()
|
||||
{
|
||||
void js_dump_stack() {
|
||||
js_stacktrace();
|
||||
return;
|
||||
|
||||
|
@ -83,9 +80,7 @@ void js_dump_stack()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int js_print_exception(JSValue v)
|
||||
{
|
||||
int js_print_exception(JSValue v) {
|
||||
if (JS_IsException(v)) {
|
||||
JSValue exception = JS_GetException(js);
|
||||
JSValue val = JS_GetPropertyStr(js, exception, "stack");
|
||||
|
@ -129,17 +124,14 @@ void script_eval_w_env(const char *s, JSValue env) {
|
|||
JS_FreeValue(js, v);
|
||||
}
|
||||
|
||||
void script_call_sym(JSValue sym)
|
||||
{
|
||||
void script_call_sym(JSValue sym) {
|
||||
struct callee c;
|
||||
c.fn = sym;
|
||||
c.obj = JS_GetGlobalObject(js);
|
||||
call_callee(&c);
|
||||
}
|
||||
|
||||
|
||||
JSValue js_callee_exec(struct callee *c, int argc, JSValue *argv)
|
||||
{
|
||||
JSValue js_callee_exec(struct callee *c, int argc, JSValue *argv) {
|
||||
JSValue ret = JS_Call(js, c->fn, c->obj, argc, argv);
|
||||
js_print_exception(ret);
|
||||
JS_FreeValue(js, ret);
|
||||
|
@ -150,29 +142,25 @@ void call_callee(struct callee *c) {
|
|||
js_callee_exec(c, 0, NULL);
|
||||
}
|
||||
|
||||
void callee_dbl(struct callee c, double d)
|
||||
{
|
||||
void callee_dbl(struct callee c, double d) {
|
||||
JSValue v = num2js(d);
|
||||
js_callee_exec(&c, 1, &v);
|
||||
JS_FreeValue(js, v);
|
||||
}
|
||||
|
||||
void callee_int(struct callee c, int i)
|
||||
{
|
||||
void callee_int(struct callee c, int i) {
|
||||
JSValue v = int2js(i);
|
||||
js_callee_exec(&c, 1, &v);
|
||||
JS_FreeValue(js, v);
|
||||
}
|
||||
|
||||
void callee_vec2(struct callee c, cpVect vec)
|
||||
{
|
||||
void callee_vec2(struct callee c, cpVect vec) {
|
||||
JSValue v = vec2js(vec);
|
||||
js_callee_exec(&c, 1, &v);
|
||||
JS_FreeValue(js, v);
|
||||
}
|
||||
|
||||
void script_callee(struct callee c, int argc, JSValue *argv)
|
||||
{
|
||||
void script_callee(struct callee c, int argc, JSValue *argv) {
|
||||
js_callee_exec(&c, argc, argv);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#include "shader.h"
|
||||
|
||||
#include "render.h"
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "font.h"
|
||||
#include "log.h"
|
||||
#include "render.h"
|
||||
#include "resources.h"
|
||||
#include "stb_ds.h"
|
||||
#include "timer.h"
|
||||
#include "font.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "time.h"
|
||||
|
||||
|
@ -17,8 +17,7 @@
|
|||
|
||||
static struct shader *shaders;
|
||||
|
||||
struct shader *MakeShader(const char *vertpath, const char *fragpath)
|
||||
{
|
||||
struct shader *MakeShader(const char *vertpath, const char *fragpath) {
|
||||
if (arrcap(shaders) == 0)
|
||||
arrsetcap(shaders, 20);
|
||||
|
||||
|
@ -30,8 +29,7 @@ struct shader *MakeShader(const char *vertpath, const char *fragpath)
|
|||
return &arrlast(shaders);
|
||||
}
|
||||
|
||||
int shader_compile_error(int shader)
|
||||
{
|
||||
int shader_compile_error(int shader) {
|
||||
/*
|
||||
GLint success = 0;
|
||||
GLchar infoLog[ERROR_BUFFER] = { '\0' };
|
||||
|
@ -46,8 +44,7 @@ int shader_compile_error(int shader)
|
|||
*/
|
||||
}
|
||||
|
||||
int shader_link_error(int shader)
|
||||
{
|
||||
int shader_link_error(int shader) {
|
||||
/*
|
||||
GLint success = 0;
|
||||
GLchar infoLog[ERROR_BUFFER] = { '\0' };
|
||||
|
@ -62,8 +59,7 @@ int shader_link_error(int shader)
|
|||
*/
|
||||
}
|
||||
|
||||
int load_shader_from_file(const char *path, int type)
|
||||
{
|
||||
int load_shader_from_file(const char *path, int type) {
|
||||
char spath[MAXPATH] = {'\0'};
|
||||
|
||||
sprintf(spath, "%s%s", "shaders/", path);
|
||||
|
@ -99,8 +95,7 @@ int load_shader_from_file(const char *path, int type)
|
|||
*/
|
||||
}
|
||||
|
||||
void shader_compile(struct shader *shader)
|
||||
{
|
||||
void shader_compile(struct shader *shader) {
|
||||
YughInfo("Making shader with %s and %s.", shader->vertpath, shader->fragpath);
|
||||
char spath[MAXPATH];
|
||||
sprintf(spath, "%s%s", "shaders/", shader->vertpath);
|
||||
|
@ -118,8 +113,7 @@ void shader_compile(struct shader *shader)
|
|||
free(fsrc);
|
||||
}
|
||||
|
||||
void shader_use(struct shader *shader)
|
||||
{
|
||||
void shader_use(struct shader *shader) {
|
||||
// glUseProgram(shader->id);
|
||||
}
|
||||
/*
|
||||
|
@ -171,16 +165,13 @@ void shader_setUBO(struct shader *shader, const char *name, unsigned int index)
|
|||
|
||||
*/
|
||||
|
||||
void shader_compile_all()
|
||||
{
|
||||
void shader_compile_all() {
|
||||
for (int i = 0; i < arrlen(shaders); i++)
|
||||
shader_compile(&shaders[i]);
|
||||
}
|
||||
void shader_setvec3(struct shader *shader, const char *name, mfloat_t val[3])
|
||||
{
|
||||
void shader_setvec3(struct shader *shader, const char *name, mfloat_t val[3]) {
|
||||
// glUniform3fv(glGetUniformLocation(shader->id, name), 1, val);
|
||||
}
|
||||
void shader_setmat4(struct shader *shader, const char *name, mfloat_t val[16])
|
||||
{
|
||||
void shader_setmat4(struct shader *shader, const char *name, mfloat_t val[16]) {
|
||||
// glUniformMatrix4fv(glGetUniformLocation(shader->id, name), 1, GL_FALSE, val);
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
#include "sound.h"
|
||||
#include "resources.h"
|
||||
#include <stdlib.h>
|
||||
#include "log.h"
|
||||
#include "string.h"
|
||||
#include "math.h"
|
||||
#include "limits.h"
|
||||
#include "time.h"
|
||||
#include "log.h"
|
||||
#include "math.h"
|
||||
#include "music.h"
|
||||
#include "resources.h"
|
||||
#include "stb_vorbis.h"
|
||||
#include "string.h"
|
||||
#include "time.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "samplerate.h"
|
||||
|
||||
#include "stb_ds.h"
|
||||
|
||||
#include "mix.h"
|
||||
#include "dsp.h"
|
||||
#include "mix.h"
|
||||
|
||||
#include "miniaudio.h"
|
||||
|
||||
|
@ -29,8 +29,7 @@ static struct {
|
|||
struct wav *value;
|
||||
} *wavhash = NULL;
|
||||
|
||||
static struct wav change_channels(struct wav w, int ch)
|
||||
{
|
||||
static struct wav change_channels(struct wav w, int ch) {
|
||||
short *data = w.data;
|
||||
int samples = ch * w.frames;
|
||||
short *new = malloc(sizeof(short) * samples);
|
||||
|
@ -53,8 +52,7 @@ static struct wav change_channels(struct wav w, int ch)
|
|||
return w;
|
||||
}
|
||||
|
||||
static struct wav change_samplerate(struct wav w, int rate)
|
||||
{
|
||||
static struct wav change_samplerate(struct wav w, int rate) {
|
||||
float ratio = (float)rate / w.samplerate;
|
||||
int outframes = w.frames * ratio;
|
||||
SRC_DATA ssrc;
|
||||
|
@ -80,8 +78,7 @@ static struct wav change_samplerate(struct wav w, int rate)
|
|||
return w;
|
||||
}
|
||||
|
||||
void wav_norm_gain(struct wav *w, double lv)
|
||||
{
|
||||
void wav_norm_gain(struct wav *w, double lv) {
|
||||
short tarmax = db2short(lv);
|
||||
short max = 0;
|
||||
short *s = w->data;
|
||||
|
@ -102,8 +99,7 @@ void wav_norm_gain(struct wav *w, double lv)
|
|||
|
||||
static ma_engine *engine;
|
||||
|
||||
void sound_init()
|
||||
{
|
||||
void sound_init() {
|
||||
ma_result result;
|
||||
engine = malloc(sizeof(*engine));
|
||||
result = ma_engine_init(NULL, engine);
|
||||
|
@ -115,8 +111,7 @@ void sound_init()
|
|||
mixer_init();
|
||||
}
|
||||
|
||||
struct wav *make_sound(const char *wav)
|
||||
{
|
||||
struct wav *make_sound(const char *wav) {
|
||||
int index = shgeti(wavhash, wav);
|
||||
if (index != -1) return wavhash[index].value;
|
||||
|
||||
|
@ -145,8 +140,7 @@ struct wav *make_sound(const char *wav)
|
|||
return newwav;
|
||||
}
|
||||
|
||||
void free_sound(const char *wav)
|
||||
{
|
||||
void free_sound(const char *wav) {
|
||||
struct wav *w = shget(wavhash, wav);
|
||||
if (w == NULL) return;
|
||||
|
||||
|
@ -155,22 +149,19 @@ void free_sound(const char *wav)
|
|||
shdel(wavhash, wav);
|
||||
}
|
||||
|
||||
struct soundstream *soundstream_make()
|
||||
{
|
||||
struct soundstream *soundstream_make() {
|
||||
struct soundstream *new = malloc(sizeof(*new));
|
||||
new->buf = circbuf_make(sizeof(short), BUF_FRAMES * CHANNELS * 2);
|
||||
return new;
|
||||
}
|
||||
|
||||
void mini_sound(char *path)
|
||||
{
|
||||
void mini_sound(char *path) {
|
||||
ma_engine_play_sound(engine, path, NULL);
|
||||
}
|
||||
|
||||
static ma_sound music_sound;
|
||||
|
||||
void mini_music_play(char *path)
|
||||
{
|
||||
void mini_music_play(char *path) {
|
||||
ma_sound_uninit(&music_sound);
|
||||
int result = ma_sound_init_from_file(engine, path, MA_SOUND_FLAG_NO_SPATIALIZATION, NULL, NULL, &music_sound);
|
||||
if (result != MA_SUCCESS) {
|
||||
|
@ -181,23 +172,19 @@ void mini_music_play(char *path)
|
|||
ma_sound_start(&music_sound);
|
||||
}
|
||||
|
||||
void mini_music_pause()
|
||||
{
|
||||
void mini_music_pause() {
|
||||
ma_sound_stop(&music_sound);
|
||||
}
|
||||
|
||||
void mini_music_stop()
|
||||
{
|
||||
void mini_music_stop() {
|
||||
ma_sound_stop(&music_sound);
|
||||
}
|
||||
|
||||
void mini_master(float v)
|
||||
{
|
||||
void mini_master(float v) {
|
||||
ma_engine_set_volume(engine, v);
|
||||
}
|
||||
|
||||
void kill_oneshot(struct sound *s)
|
||||
{
|
||||
void kill_oneshot(struct sound *s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
|
@ -209,11 +196,9 @@ void play_oneshot(struct wav *wav) {
|
|||
new->loop = 0;
|
||||
new->frame = 0;
|
||||
new->endcb = kill_oneshot;
|
||||
|
||||
}
|
||||
|
||||
struct sound *play_sound(struct wav *wav)
|
||||
{
|
||||
struct sound *play_sound(struct wav *wav) {
|
||||
struct sound *new = calloc(1, sizeof(*new));
|
||||
new->data = wav;
|
||||
|
||||
|
@ -223,46 +208,38 @@ struct sound *play_sound(struct wav *wav)
|
|||
return new;
|
||||
}
|
||||
|
||||
int sound_playing(const struct sound *s)
|
||||
{
|
||||
int sound_playing(const struct sound *s) {
|
||||
return s->playing;
|
||||
}
|
||||
|
||||
int sound_paused(const struct sound *s)
|
||||
{
|
||||
int sound_paused(const struct sound *s) {
|
||||
return (!s->playing && s->frame < s->data->frames);
|
||||
}
|
||||
void sound_pause(struct sound *s)
|
||||
{
|
||||
void sound_pause(struct sound *s) {
|
||||
s->playing = 0;
|
||||
bus_free(s->bus);
|
||||
}
|
||||
|
||||
void sound_resume(struct sound *s)
|
||||
{
|
||||
void sound_resume(struct sound *s) {
|
||||
s->playing = 1;
|
||||
s->bus = first_free_bus(dsp_filter(s, sound_fillbuf));
|
||||
}
|
||||
|
||||
void sound_stop(struct sound *s)
|
||||
{
|
||||
void sound_stop(struct sound *s) {
|
||||
s->playing = 0;
|
||||
s->frame = 0;
|
||||
bus_free(s->bus);
|
||||
}
|
||||
|
||||
int sound_finished(const struct sound *s)
|
||||
{
|
||||
int sound_finished(const struct sound *s) {
|
||||
return !s->playing && s->frame == s->data->frames;
|
||||
}
|
||||
|
||||
int sound_stopped(const struct sound *s)
|
||||
{
|
||||
int sound_stopped(const struct sound *s) {
|
||||
return !s->playing && s->frame == 0;
|
||||
}
|
||||
|
||||
struct mp3 make_music(const char *mp3)
|
||||
{
|
||||
struct mp3 make_music(const char *mp3) {
|
||||
// drmp3 new;
|
||||
// if (!drmp3_init_file(&new, mp3, NULL)) {
|
||||
// YughError("Could not open mp3 file %s.", mp3);
|
||||
|
@ -272,22 +249,20 @@ struct mp3 make_music(const char *mp3)
|
|||
return newmp3;
|
||||
}
|
||||
|
||||
void close_audio_device(int device)
|
||||
{
|
||||
void close_audio_device(int device) {
|
||||
}
|
||||
|
||||
int open_device(const char *adriver)
|
||||
{
|
||||
int open_device(const char *adriver) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sound_fillbuf(struct sound *s, short *buf, int n)
|
||||
{
|
||||
void sound_fillbuf(struct sound *s, short *buf, int n) {
|
||||
float gainmult = pct2mult(s->data->gain);
|
||||
|
||||
short *in = s->data->data;
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < CHANNELS; j++) buf[i*CHANNELS+j] = in[s->frame+j] * gainmult;
|
||||
for (int j = 0; j < CHANNELS; j++)
|
||||
buf[i * CHANNELS + j] = in[s->frame + j] * gainmult;
|
||||
s->frame++;
|
||||
if (s->frame == s->data->frames) {
|
||||
|
||||
|
@ -299,13 +274,10 @@ void sound_fillbuf(struct sound *s, short *buf, int n)
|
|||
}
|
||||
}
|
||||
|
||||
void mp3_fillbuf(struct sound *s, short *buf, int n)
|
||||
{
|
||||
|
||||
void mp3_fillbuf(struct sound *s, short *buf, int n) {
|
||||
}
|
||||
|
||||
void soundstream_fillbuf(struct soundstream *s, short *buf, int n)
|
||||
{
|
||||
void soundstream_fillbuf(struct soundstream *s, short *buf, int n) {
|
||||
int max = s->buf->write - s->buf->read;
|
||||
int lim = (max < n * CHANNELS) ? max : n * CHANNELS;
|
||||
for (int i = 0; i < lim; i++) {
|
||||
|
@ -313,30 +285,25 @@ void soundstream_fillbuf(struct soundstream *s, short *buf, int n)
|
|||
}
|
||||
}
|
||||
|
||||
float short2db(short val)
|
||||
{
|
||||
float short2db(short val) {
|
||||
return 20 * log10(abs(val) / SHRT_MAX);
|
||||
}
|
||||
|
||||
short db2short(float db)
|
||||
{
|
||||
short db2short(float db) {
|
||||
return pow(10, db / 20.f) * SHRT_MAX;
|
||||
}
|
||||
|
||||
short short_gain(short val, float db)
|
||||
{
|
||||
short short_gain(short val, float db) {
|
||||
return (short)(pow(10, db / 20.f) * val);
|
||||
}
|
||||
|
||||
float pct2db(float pct)
|
||||
{
|
||||
float pct2db(float pct) {
|
||||
if (pct <= 0) return -72.f;
|
||||
|
||||
return 10 * log2(pct);
|
||||
}
|
||||
|
||||
float pct2mult(float pct)
|
||||
{
|
||||
float pct2mult(float pct) {
|
||||
if (pct <= 0) return 0.f;
|
||||
|
||||
return pow(10, 0.5 * log2(pct));
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
#include "sprite.h"
|
||||
|
||||
#include "timer.h"
|
||||
#include "render.h"
|
||||
#include "openglrender.h"
|
||||
#include "texture.h"
|
||||
#include "shader.h"
|
||||
#include "datastream.h"
|
||||
#include "gameobject.h"
|
||||
#include <string.h>
|
||||
#include "stb_ds.h"
|
||||
#include "log.h"
|
||||
#include "font.h"
|
||||
#include "gameobject.h"
|
||||
#include "log.h"
|
||||
#include "openglrender.h"
|
||||
#include "render.h"
|
||||
#include "shader.h"
|
||||
#include "stb_ds.h"
|
||||
#include "texture.h"
|
||||
#include "timer.h"
|
||||
#include <string.h>
|
||||
|
||||
struct TextureOptions TEX_SPRITE = {1, 0, 0};
|
||||
|
||||
static struct sprite *sprites;
|
||||
static int first = -1;
|
||||
|
||||
sg_pipeline pip_sprite;
|
||||
sg_bindings bind_sprite;
|
||||
static sg_pipeline pip_sprite;
|
||||
static sg_bindings bind_sprite;
|
||||
static int sprite_c = 0;
|
||||
|
||||
int make_sprite(int go)
|
||||
{
|
||||
int make_sprite(int go) {
|
||||
struct sprite sprite = {
|
||||
.color = {1.f, 1.f, 1.f},
|
||||
.size = {1.f, 1.f},
|
||||
|
@ -44,16 +44,14 @@ int make_sprite(int go)
|
|||
}
|
||||
}
|
||||
|
||||
void sprite_delete(int id)
|
||||
{
|
||||
void sprite_delete(int id) {
|
||||
struct sprite *sp = id2sprite(id);
|
||||
sp->go = -1;
|
||||
sp->next = first;
|
||||
first = id;
|
||||
}
|
||||
|
||||
void sprite_enabled(int id, int e)
|
||||
{
|
||||
void sprite_enabled(int id, int e) {
|
||||
sprites[id].enabled = e;
|
||||
}
|
||||
|
||||
|
@ -64,13 +62,11 @@ struct sprite *id2sprite(int id) {
|
|||
|
||||
static sprite_count = 0;
|
||||
|
||||
void sprite_flush()
|
||||
{
|
||||
void sprite_flush() {
|
||||
sprite_count = 0;
|
||||
}
|
||||
|
||||
void sprite_io(struct sprite *sprite, FILE *f, int read)
|
||||
{
|
||||
void sprite_io(struct sprite *sprite, FILE *f, int read) {
|
||||
char path[100];
|
||||
if (read) {
|
||||
// fscanf(f, "%s", &path);
|
||||
|
@ -88,8 +84,7 @@ void sprite_io(struct sprite *sprite, FILE *f, int read)
|
|||
}
|
||||
}
|
||||
|
||||
void sprite_draw_all()
|
||||
{
|
||||
void sprite_draw_all() {
|
||||
sg_apply_pipeline(pip_sprite);
|
||||
|
||||
static struct sprite **layers[5];
|
||||
|
@ -106,30 +101,26 @@ void sprite_draw_all()
|
|||
sprite_draw(layers[i][j]);
|
||||
}
|
||||
|
||||
void sprite_loadtex(struct sprite *sprite, const char *path, struct glrect frame)
|
||||
{
|
||||
void sprite_loadtex(struct sprite *sprite, const char *path, struct glrect frame) {
|
||||
sprite->tex = texture_loadfromfile(path);
|
||||
sprite_setframe(sprite, &frame);
|
||||
}
|
||||
|
||||
void sprite_settex(struct sprite *sprite, struct Texture *tex)
|
||||
{
|
||||
void sprite_settex(struct sprite *sprite, struct Texture *tex) {
|
||||
sprite->tex = tex;
|
||||
sprite_setframe(sprite, &ST_UNIT);
|
||||
}
|
||||
|
||||
sg_shader shader_sprite;
|
||||
|
||||
void sprite_initialize()
|
||||
{
|
||||
void sprite_initialize() {
|
||||
shader_sprite = sg_make_shader(&(sg_shader_desc){
|
||||
.vs.source = slurp_text("shaders/spritevert.glsl"),
|
||||
.fs.source = slurp_text("shaders/spritefrag.glsl"),
|
||||
.vs.uniform_blocks[0] = {
|
||||
.size = 64,
|
||||
.layout = SG_UNIFORMLAYOUT_STD140,
|
||||
.uniforms = { [0] = { .name = "mpv", .type = SG_UNIFORMTYPE_MAT4 }}
|
||||
},
|
||||
.uniforms = {[0] = {.name = "mpv", .type = SG_UNIFORMTYPE_MAT4}}},
|
||||
|
||||
.fs.images[0] = {
|
||||
.name = "image",
|
||||
|
@ -137,22 +128,15 @@ void sprite_initialize()
|
|||
.sampler_type = SG_SAMPLERTYPE_FLOAT,
|
||||
},
|
||||
|
||||
.fs.uniform_blocks[0] = {
|
||||
.size = 12,
|
||||
.uniforms = { [0] = { .name = "spriteColor", .type = SG_UNIFORMTYPE_FLOAT3 }}
|
||||
}
|
||||
});
|
||||
.fs.uniform_blocks[0] = {.size = 12, .uniforms = {[0] = {.name = "spriteColor", .type = SG_UNIFORMTYPE_FLOAT3}}}});
|
||||
|
||||
pip_sprite = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = shader_sprite,
|
||||
.layout = {
|
||||
.attrs = {
|
||||
[0].format=SG_VERTEXFORMAT_FLOAT4
|
||||
}
|
||||
},
|
||||
[0].format = SG_VERTEXFORMAT_FLOAT4}},
|
||||
.primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
||||
.label = "sprite pipeline"
|
||||
});
|
||||
.label = "sprite pipeline"});
|
||||
|
||||
bind_sprite.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.size = sizeof(float) * 16 * 500,
|
||||
|
@ -185,26 +169,23 @@ void tex_draw(struct Texture *tex, float pos[2], float angle, float size[2], flo
|
|||
0.f, 0.f, r.s0, r.t1,
|
||||
1, 0.f, r.s1, r.t1,
|
||||
0.f, 1, r.s0, r.t0,
|
||||
1.f, 1.f, r.s1, r.t0
|
||||
};
|
||||
1.f, 1.f, r.s1, r.t0};
|
||||
|
||||
bind_sprite.fs_images[0] = tex->id;
|
||||
sg_append_buffer(bind_sprite.vertex_buffers[0], SG_RANGE_REF(vertices));
|
||||
|
||||
sg_apply_bindings(&bind_sprite);
|
||||
|
||||
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(model));
|
||||
float c[3];
|
||||
for (int i = 0; i < 3; i++) c[i] = color[i];
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, SG_RANGE_REF(c));
|
||||
|
||||
sg_range c = {
|
||||
.ptr = color,
|
||||
.size = sizeof(float) * 3};
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &c);
|
||||
|
||||
sg_draw(sprite_count * 4, 4, 1);
|
||||
sprite_count++;
|
||||
}
|
||||
|
||||
void sprite_draw(struct sprite *sprite)
|
||||
{
|
||||
void sprite_draw(struct sprite *sprite) {
|
||||
struct gameobject *go = id2go(sprite->go);
|
||||
|
||||
if (sprite->tex) {
|
||||
|
@ -215,8 +196,7 @@ void sprite_draw(struct sprite *sprite)
|
|||
}
|
||||
}
|
||||
|
||||
void sprite_setanim(struct sprite *sprite, struct TexAnim *anim, int frame)
|
||||
{
|
||||
void sprite_setanim(struct sprite *sprite, struct TexAnim *anim, int frame) {
|
||||
if (!sprite) return;
|
||||
sprite->tex = anim->tex;
|
||||
sprite->frame = anim->st_frames[frame];
|
||||
|
@ -228,17 +208,15 @@ void gui_draw_img(const char *img, float x, float y) {
|
|||
float pos[2] = {x, y};
|
||||
float size[2] = {1.f, 1.f};
|
||||
float offset[2] = {0.f, 0.f};
|
||||
float white[3] = {0.3f,1.f,1.f};
|
||||
float white[3] = {1.f, 1.f, 1.f};
|
||||
tex_draw(tex, pos, 0.f, size, offset, tex_get_rect(tex), white);
|
||||
}
|
||||
|
||||
void sprite_setframe(struct sprite *sprite, struct glrect *frame)
|
||||
{
|
||||
void sprite_setframe(struct sprite *sprite, struct glrect *frame) {
|
||||
sprite->frame = *frame;
|
||||
}
|
||||
|
||||
void video_draw(struct datastream *stream, mfloat_t position[2], mfloat_t size[2], float rotate, mfloat_t color[3])
|
||||
{
|
||||
void video_draw(struct datastream *stream, mfloat_t position[2], mfloat_t size[2], float rotate, mfloat_t color[3]) {
|
||||
shader_use(vid_shader);
|
||||
|
||||
static mfloat_t model[16];
|
||||
|
@ -260,4 +238,3 @@ void video_draw(struct datastream *stream, mfloat_t position[2], mfloat_t size[2
|
|||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "texture.h"
|
||||
|
||||
#include "render.h"
|
||||
#include <stdio.h>
|
||||
#include <stb_image.h>
|
||||
#include <stb_ds.h>
|
||||
#include "log.h"
|
||||
#include <math.h>
|
||||
#include "util.h"
|
||||
#include "render.h"
|
||||
#include "sokol/sokol_gfx.h"
|
||||
#include "util.h"
|
||||
#include <math.h>
|
||||
#include <stb_ds.h>
|
||||
#include <stb_image.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct glrect ST_UNIT = {0.f, 1.f, 0.f, 1.f};
|
||||
|
||||
|
@ -18,14 +18,12 @@ static struct {
|
|||
|
||||
struct Texture *tex_default;
|
||||
|
||||
struct Texture *texture_notex()
|
||||
{
|
||||
struct Texture *texture_notex() {
|
||||
return texture_pullfromfile("./icons/no_tex.png");
|
||||
}
|
||||
|
||||
/* If an empty string or null is put for path, loads default texture */
|
||||
struct Texture *texture_pullfromfile(const char *path)
|
||||
{
|
||||
struct Texture *texture_pullfromfile(const char *path) {
|
||||
if (!path) return texture_notex();
|
||||
|
||||
int index = shgeti(texhash, path);
|
||||
|
@ -49,14 +47,8 @@ struct Texture *texture_pullfromfile(const char *path)
|
|||
|
||||
int filter;
|
||||
if (tex->opts.sprite) {
|
||||
if (tex->opts.mips)
|
||||
filter = SG_FILTER_NEAREST_MIPMAP_NEAREST;
|
||||
else
|
||||
filter = SG_FILTER_NEAREST;
|
||||
} else {
|
||||
if (tex->opts.mips)
|
||||
filter = SG_FILTER_LINEAR_MIPMAP_LINEAR;
|
||||
else
|
||||
filter = SG_FILTER_LINEAR;
|
||||
}
|
||||
|
||||
|
@ -67,12 +59,10 @@ struct Texture *texture_pullfromfile(const char *path)
|
|||
.usage = SG_USAGE_IMMUTABLE,
|
||||
.min_filter = filter,
|
||||
.mag_filter = filter,
|
||||
.max_anisotropy = 16,
|
||||
.data.subimage[0][0] = {
|
||||
.ptr = data,
|
||||
.size = tex->width*tex->height*4
|
||||
}
|
||||
});
|
||||
|
||||
.size = tex->width * tex->height * 4}});
|
||||
|
||||
if (shlen(texhash) == 0)
|
||||
sh_new_arena(texhash);
|
||||
|
@ -82,8 +72,7 @@ struct Texture *texture_pullfromfile(const char *path)
|
|||
return tex;
|
||||
}
|
||||
|
||||
void texture_sync(const char *path)
|
||||
{
|
||||
void texture_sync(const char *path) {
|
||||
YughWarn("Need to implement texture sync.");
|
||||
}
|
||||
|
||||
|
@ -98,8 +87,7 @@ char *tex_get_path(struct Texture *tex) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct Texture *texture_loadfromfile(const char *path)
|
||||
{
|
||||
struct Texture *texture_loadfromfile(const char *path) {
|
||||
struct Texture *new = texture_pullfromfile(path);
|
||||
/*
|
||||
if (new->id == 0) {
|
||||
|
@ -113,21 +101,18 @@ struct Texture *texture_loadfromfile(const char *path)
|
|||
return new;
|
||||
}
|
||||
|
||||
void tex_gpu_reload(struct Texture *tex)
|
||||
{
|
||||
void tex_gpu_reload(struct Texture *tex) {
|
||||
tex_gpu_free(tex);
|
||||
|
||||
// tex_gpu_load(tex);
|
||||
}
|
||||
|
||||
void anim_calc(struct anim2d *anim)
|
||||
{
|
||||
void anim_calc(struct anim2d *anim) {
|
||||
anim->size[0] = anim->anim->tex->width * st_s_w(anim->anim->st_frames[anim->frame]);
|
||||
anim->size[1] = anim->anim->tex->height * st_s_h(anim->anim->st_frames[anim->frame]);
|
||||
}
|
||||
|
||||
void anim_incr(struct anim2d *anim)
|
||||
{
|
||||
void anim_incr(struct anim2d *anim) {
|
||||
anim->frame = (anim->frame + 1) % arrlen(anim->anim->st_frames);
|
||||
|
||||
if (!anim->anim->loop && anim->frame == arrlen(anim->anim->st_frames))
|
||||
|
@ -136,25 +121,21 @@ void anim_incr(struct anim2d *anim)
|
|||
anim_calc(anim);
|
||||
}
|
||||
|
||||
void anim_decr(struct anim2d *anim)
|
||||
{
|
||||
void anim_decr(struct anim2d *anim) {
|
||||
anim->frame = (anim->frame + arrlen(anim->anim->st_frames) - 1) % arrlen(anim->anim->st_frames);
|
||||
anim_calc(anim);
|
||||
}
|
||||
|
||||
struct glrect anim_get_rect(struct anim2d *anim)
|
||||
{
|
||||
struct glrect anim_get_rect(struct anim2d *anim) {
|
||||
return anim->anim->st_frames[anim->frame];
|
||||
}
|
||||
|
||||
void anim_setframe(struct anim2d *anim, int frame)
|
||||
{
|
||||
void anim_setframe(struct anim2d *anim, int frame) {
|
||||
anim->frame = frame;
|
||||
anim_calc(anim);
|
||||
}
|
||||
|
||||
struct TexAnim *anim2d_from_tex(const char *path, int frames, int fps)
|
||||
{
|
||||
struct TexAnim *anim2d_from_tex(const char *path, int frames, int fps) {
|
||||
struct TexAnim *anim = malloc(sizeof(*anim));
|
||||
anim->tex = texture_loadfromfile(path);
|
||||
texanim_fromframes(anim, frames);
|
||||
|
@ -163,8 +144,7 @@ struct TexAnim *anim2d_from_tex(const char *path, int frames, int fps)
|
|||
return anim;
|
||||
}
|
||||
|
||||
void texanim_fromframes(struct TexAnim *anim, int frames)
|
||||
{
|
||||
void texanim_fromframes(struct TexAnim *anim, int frames) {
|
||||
if (anim->st_frames) {
|
||||
free(anim->st_frames);
|
||||
}
|
||||
|
@ -181,8 +161,7 @@ void texanim_fromframes(struct TexAnim *anim, int frames)
|
|||
}
|
||||
}
|
||||
|
||||
void tex_gpu_free(struct Texture *tex)
|
||||
{
|
||||
void tex_gpu_free(struct Texture *tex) {
|
||||
/*
|
||||
if (tex->id != 0) {
|
||||
glDeleteTextures(1, &tex->id);
|
||||
|
@ -191,18 +170,15 @@ void tex_gpu_free(struct Texture *tex)
|
|||
*/
|
||||
}
|
||||
|
||||
int anim_frames(struct TexAnim *a)
|
||||
{
|
||||
int anim_frames(struct TexAnim *a) {
|
||||
return arrlen(a->st_frames);
|
||||
}
|
||||
|
||||
struct glrect tex_get_rect(struct Texture *tex)
|
||||
{
|
||||
struct glrect tex_get_rect(struct Texture *tex) {
|
||||
return ST_UNIT;
|
||||
}
|
||||
|
||||
cpVect tex_get_dimensions(struct Texture *tex)
|
||||
{
|
||||
cpVect tex_get_dimensions(struct Texture *tex) {
|
||||
if (!tex) return cpvzero;
|
||||
cpVect d;
|
||||
d.x = tex->width;
|
||||
|
@ -210,8 +186,7 @@ cpVect tex_get_dimensions(struct Texture *tex)
|
|||
return d;
|
||||
}
|
||||
|
||||
void tex_bind(struct Texture *tex)
|
||||
{
|
||||
void tex_bind(struct Texture *tex) {
|
||||
/* glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, tex->id);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, tex->id);
|
||||
|
@ -220,16 +195,14 @@ void tex_bind(struct Texture *tex)
|
|||
|
||||
/********************** ANIM2D ****************/
|
||||
|
||||
void anim_load(struct anim2d *anim, const char *path)
|
||||
{
|
||||
void anim_load(struct anim2d *anim, const char *path) {
|
||||
anim->anim = &texture_pullfromfile(path)->anim;
|
||||
anim->anim->tex->opts.animation = 1;
|
||||
anim_stop(anim);
|
||||
anim_play(anim);
|
||||
}
|
||||
|
||||
void anim_play(struct anim2d *anim)
|
||||
{
|
||||
void anim_play(struct anim2d *anim) {
|
||||
if (anim->playing)
|
||||
return;
|
||||
|
||||
|
@ -246,8 +219,7 @@ void anim_play(struct anim2d *anim)
|
|||
timer_start(anim->timer);
|
||||
}
|
||||
|
||||
void anim_stop(struct anim2d *anim)
|
||||
{
|
||||
void anim_stop(struct anim2d *anim) {
|
||||
if (!anim->playing)
|
||||
return;
|
||||
|
||||
|
@ -257,8 +229,7 @@ void anim_stop(struct anim2d *anim)
|
|||
timer_stop(anim->timer);
|
||||
}
|
||||
|
||||
void anim_pause(struct anim2d *anim)
|
||||
{
|
||||
void anim_pause(struct anim2d *anim) {
|
||||
if (!anim->playing)
|
||||
return;
|
||||
|
||||
|
@ -266,22 +237,18 @@ void anim_pause(struct anim2d *anim)
|
|||
timer_pause(anim->timer);
|
||||
}
|
||||
|
||||
void anim_fwd(struct anim2d *anim)
|
||||
{
|
||||
void anim_fwd(struct anim2d *anim) {
|
||||
anim_incr(anim);
|
||||
}
|
||||
|
||||
void anim_bkwd(struct anim2d *anim)
|
||||
{
|
||||
void anim_bkwd(struct anim2d *anim) {
|
||||
anim_decr(anim);
|
||||
}
|
||||
|
||||
float st_s_w(struct glrect st)
|
||||
{
|
||||
float st_s_w(struct glrect st) {
|
||||
return (st.s1 - st.s0);
|
||||
}
|
||||
|
||||
float st_s_h(struct glrect st)
|
||||
{
|
||||
float st_s_h(struct glrect st) {
|
||||
return (st.t1 - st.t0);
|
||||
}
|
||||
|
|
73
source/engine/thirdparty/Nuklear/nuklear.h
vendored
73
source/engine/thirdparty/Nuklear/nuklear.h
vendored
|
@ -372,7 +372,7 @@ extern "C" {
|
|||
#elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
|
||||
#define NK_SIZE_TYPE unsigned __int32
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(__x86_64__) || defined(__ppc64__)
|
||||
#if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__)
|
||||
#define NK_SIZE_TYPE unsigned long
|
||||
#else
|
||||
#define NK_SIZE_TYPE unsigned int
|
||||
|
@ -387,7 +387,7 @@ extern "C" {
|
|||
#elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
|
||||
#define NK_POINTER_TYPE unsigned __int32
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(__x86_64__) || defined(__ppc64__)
|
||||
#if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__)
|
||||
#define NK_POINTER_TYPE unsigned long
|
||||
#else
|
||||
#define NK_POINTER_TYPE unsigned int
|
||||
|
@ -432,8 +432,8 @@ NK_STATIC_ASSERT(sizeof(nk_int) == 4);
|
|||
NK_STATIC_ASSERT(sizeof(nk_byte) == 1);
|
||||
NK_STATIC_ASSERT(sizeof(nk_flags) >= 4);
|
||||
NK_STATIC_ASSERT(sizeof(nk_rune) >= 4);
|
||||
//NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
|
||||
//NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));
|
||||
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
|
||||
NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));
|
||||
#ifdef NK_INCLUDE_STANDARD_BOOL
|
||||
NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool));
|
||||
#else
|
||||
|
@ -1127,7 +1127,7 @@ NK_API void nk_input_end(struct nk_context*);
|
|||
/// cfg.curve_segment_count = 22;
|
||||
/// cfg.arc_segment_count = 22;
|
||||
/// cfg.global_alpha = 1.0f;
|
||||
/// cfg.null = dev->null;
|
||||
/// cfg.tex_null = dev->tex_null;
|
||||
/// //
|
||||
/// // setup buffers and convert
|
||||
/// struct nk_buffer cmds, verts, idx;
|
||||
|
@ -1177,7 +1177,7 @@ struct nk_convert_config {
|
|||
unsigned circle_segment_count; /* number of segments used for circles: default to 22 */
|
||||
unsigned arc_segment_count; /* number of segments used for arcs: default to 22 */
|
||||
unsigned curve_segment_count; /* number of segments used for curves: default to 22 */
|
||||
struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */
|
||||
struct nk_draw_null_texture tex_null; /* handle to texture with a white pixel for shape drawing */
|
||||
const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */
|
||||
nk_size vertex_size; /* sizeof one vertex for vertex packing */
|
||||
nk_size vertex_alignment; /* vertex alignment: Can be obtained by NK_ALIGNOF */
|
||||
|
@ -6078,7 +6078,6 @@ NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_prop
|
|||
|
||||
#define STB_RECT_PACK_IMPLEMENTATION
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STBTT_STATIC
|
||||
|
||||
/* Allow consumer to define own STBTT_malloc/STBTT_free, and use the font atlas' allocator otherwise */
|
||||
#ifndef STBTT_malloc
|
||||
|
@ -8440,7 +8439,6 @@ nk_str_append_text_utf8(struct nk_str *str, const char *text, int len)
|
|||
NK_API int
|
||||
nk_str_append_str_utf8(struct nk_str *str, const char *text)
|
||||
{
|
||||
int runes = 0;
|
||||
int byte_len = 0;
|
||||
int num_runes = 0;
|
||||
int glyph_len = 0;
|
||||
|
@ -8454,7 +8452,7 @@ nk_str_append_str_utf8(struct nk_str *str, const char *text)
|
|||
num_runes++;
|
||||
}
|
||||
nk_str_append_text_char(str, text, byte_len);
|
||||
return runes;
|
||||
return num_runes;
|
||||
}
|
||||
NK_API int
|
||||
nk_str_append_text_runes(struct nk_str *str, const nk_rune *text, int len)
|
||||
|
@ -8569,7 +8567,6 @@ nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len)
|
|||
NK_API int
|
||||
nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text)
|
||||
{
|
||||
int runes = 0;
|
||||
int byte_len = 0;
|
||||
int num_runes = 0;
|
||||
int glyph_len = 0;
|
||||
|
@ -8583,7 +8580,7 @@ nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text)
|
|||
num_runes++;
|
||||
}
|
||||
nk_str_insert_at_rune(str, pos, text, byte_len);
|
||||
return runes;
|
||||
return num_runes;
|
||||
}
|
||||
NK_API int
|
||||
nk_str_insert_text_runes(struct nk_str *str, int pos, const nk_rune *runes, int len)
|
||||
|
@ -9564,7 +9561,7 @@ nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect)
|
|||
NK_ASSERT(list);
|
||||
if (!list) return;
|
||||
if (!list->cmd_count) {
|
||||
nk_draw_list_push_command(list, rect, list->config.null.texture);
|
||||
nk_draw_list_push_command(list, rect, list->config.tex_null.texture);
|
||||
} else {
|
||||
struct nk_draw_command *prev = nk_draw_list_command_last(list);
|
||||
if (prev->elem_count == 0)
|
||||
|
@ -9919,7 +9916,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
|||
|
||||
/* fill vertices */
|
||||
for (i = 0; i < points_count; ++i) {
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
const struct nk_vec2 uv = list->config.tex_null.uv;
|
||||
vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans);
|
||||
|
@ -9984,7 +9981,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
|||
|
||||
/* add vertices */
|
||||
for (i = 0; i < points_count; ++i) {
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
const struct nk_vec2 uv = list->config.tex_null.uv;
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col);
|
||||
|
@ -10005,7 +10002,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
|||
|
||||
for (i1 = 0; i1 < count; ++i1) {
|
||||
float dx, dy;
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
const struct nk_vec2 uv = list->config.tex_null.uv;
|
||||
const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1;
|
||||
const struct nk_vec2 p1 = points[i1];
|
||||
const struct nk_vec2 p2 = points[i2];
|
||||
|
@ -10115,7 +10112,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
|||
|
||||
/* add vertices + indexes */
|
||||
for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
const struct nk_vec2 uv = list->config.tex_null.uv;
|
||||
struct nk_vec2 n0 = normals[i0];
|
||||
struct nk_vec2 n1 = normals[i1];
|
||||
struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f);
|
||||
|
@ -10152,7 +10149,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
|||
|
||||
if (!vtx || !ids) return;
|
||||
for (i = 0; i < vtx_count; ++i)
|
||||
vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.null.uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.tex_null.uv, col);
|
||||
for (i = 2; i < points_count; ++i) {
|
||||
ids[0] = (nk_draw_index)index;
|
||||
ids[1] = (nk_draw_index)(index+ i - 1);
|
||||
|
@ -10181,8 +10178,8 @@ nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos)
|
|||
nk_draw_list_add_clip(list, nk_null_rect);
|
||||
|
||||
cmd = nk_draw_list_command_last(list);
|
||||
if (cmd && cmd->texture.ptr != list->config.null.texture.ptr)
|
||||
nk_draw_list_push_image(list, list->config.null.texture);
|
||||
if (cmd && cmd->texture.ptr != list->config.tex_null.texture.ptr)
|
||||
nk_draw_list_push_image(list, list->config.tex_null.texture);
|
||||
|
||||
points = nk_draw_list_alloc_path(list, 1);
|
||||
if (!points) return;
|
||||
|
@ -10384,7 +10381,7 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec
|
|||
NK_ASSERT(list);
|
||||
if (!list) return;
|
||||
|
||||
nk_draw_list_push_image(list, list->config.null.texture);
|
||||
nk_draw_list_push_image(list, list->config.tex_null.texture);
|
||||
index = (nk_draw_index)list->vertex_count;
|
||||
vtx = nk_draw_list_alloc_vertices(list, 4);
|
||||
idx = nk_draw_list_alloc_elements(list, 6);
|
||||
|
@ -10394,10 +10391,10 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec
|
|||
idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
|
||||
idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
|
||||
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.null.uv, col_left);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.null.uv, col_top);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.null.uv, col_right);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.null.uv, col_bottom);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.tex_null.uv, col_left);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.tex_null.uv, col_top);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.tex_null.uv, col_right);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.tex_null.uv, col_bottom);
|
||||
}
|
||||
NK_API void
|
||||
nk_draw_list_fill_triangle(struct nk_draw_list *list, struct nk_vec2 a,
|
||||
|
@ -16513,7 +16510,7 @@ nk_font_chinese_glyph_ranges(void)
|
|||
0x3000, 0x30FF,
|
||||
0x31F0, 0x31FF,
|
||||
0xFF00, 0xFFEF,
|
||||
0x4e00, 0x9FAF,
|
||||
0x4E00, 0x9FAF,
|
||||
0
|
||||
};
|
||||
return ranges;
|
||||
|
@ -16622,7 +16619,7 @@ nk_font_bake_pack(struct nk_font_baker *baker,
|
|||
struct stbtt_fontinfo *font_info = &baker->build[i++].info;
|
||||
font_info->userdata = alloc;
|
||||
|
||||
if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, 0))
|
||||
if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0)))
|
||||
return nk_false;
|
||||
} while ((it = it->n) != config_iter);
|
||||
}
|
||||
|
@ -17704,20 +17701,20 @@ failed:
|
|||
}
|
||||
NK_API void
|
||||
nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture,
|
||||
struct nk_draw_null_texture *null)
|
||||
struct nk_draw_null_texture *tex_null)
|
||||
{
|
||||
int i = 0;
|
||||
struct nk_font *font_iter;
|
||||
NK_ASSERT(atlas);
|
||||
if (!atlas) {
|
||||
if (!null) return;
|
||||
null->texture = texture;
|
||||
null->uv = nk_vec2(0.5f,0.5f);
|
||||
if (!tex_null) return;
|
||||
tex_null->texture = texture;
|
||||
tex_null->uv = nk_vec2(0.5f,0.5f);
|
||||
}
|
||||
if (null) {
|
||||
null->texture = texture;
|
||||
null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width;
|
||||
null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height;
|
||||
if (tex_null) {
|
||||
tex_null->texture = texture;
|
||||
tex_null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width;
|
||||
tex_null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height;
|
||||
}
|
||||
for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
|
||||
font_iter->texture = texture;
|
||||
|
@ -26163,7 +26160,7 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len)
|
|||
text+text_len, 1))
|
||||
{
|
||||
nk_textedit_makeundo_insert(state, state->cursor, 1);
|
||||
++state->cursor;
|
||||
state->cursor = NK_MIN(state->cursor + 1, state->string.len);
|
||||
state->has_preferred_x = 0;
|
||||
}
|
||||
}
|
||||
|
@ -29657,6 +29654,12 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
|
|||
/// - [y]: Minor version with non-breaking API and library changes
|
||||
/// - [z]: Patch version with no direct changes to the API
|
||||
///
|
||||
/// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly
|
||||
/// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0
|
||||
/// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null`
|
||||
/// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE
|
||||
/// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than
|
||||
/// nk_edit_xxx limit
|
||||
/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug
|
||||
/// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to
|
||||
/// only trigger when the mouse position was inside the same button on down
|
||||
|
|
500
source/engine/thirdparty/Nuklear/nuklear_glfw_gl3.h
vendored
500
source/engine/thirdparty/Nuklear/nuklear_glfw_gl3.h
vendored
|
@ -1,500 +0,0 @@
|
|||
/*
|
||||
* Nuklear - 1.32.0 - public domain
|
||||
* no warrenty implied; use at your own risk.
|
||||
* authored from 2015-2016 by Micha Mettke
|
||||
*/
|
||||
/*
|
||||
* ==============================================================
|
||||
*
|
||||
* API
|
||||
*
|
||||
* ===============================================================
|
||||
*/
|
||||
#ifndef NK_GLFW_GL3_H_
|
||||
#define NK_GLFW_GL3_H_
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
enum nk_glfw_init_state{
|
||||
NK_GLFW3_DEFAULT=0,
|
||||
NK_GLFW3_INSTALL_CALLBACKS
|
||||
};
|
||||
|
||||
#ifndef NK_GLFW_TEXT_MAX
|
||||
#define NK_GLFW_TEXT_MAX 256
|
||||
#endif
|
||||
|
||||
struct nk_glfw_device {
|
||||
struct nk_buffer cmds;
|
||||
struct nk_draw_null_texture null;
|
||||
GLuint vbo, vao, ebo;
|
||||
GLuint prog;
|
||||
GLuint vert_shdr;
|
||||
GLuint frag_shdr;
|
||||
GLint attrib_pos;
|
||||
GLint attrib_uv;
|
||||
GLint attrib_col;
|
||||
GLint uniform_tex;
|
||||
GLint uniform_proj;
|
||||
GLuint font_tex;
|
||||
};
|
||||
|
||||
struct nk_glfw {
|
||||
GLFWwindow *win;
|
||||
int width, height;
|
||||
int display_width, display_height;
|
||||
struct nk_glfw_device ogl;
|
||||
struct nk_context ctx;
|
||||
struct nk_font_atlas atlas;
|
||||
struct nk_vec2 fb_scale;
|
||||
unsigned int text[NK_GLFW_TEXT_MAX];
|
||||
int text_len;
|
||||
struct nk_vec2 scroll;
|
||||
double last_button_click;
|
||||
int is_double_click_down;
|
||||
struct nk_vec2 double_click_pos;
|
||||
};
|
||||
|
||||
NK_API struct nk_context* nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state);
|
||||
NK_API void nk_glfw3_shutdown(struct nk_glfw* glfw);
|
||||
NK_API void nk_glfw3_font_stash_begin(struct nk_glfw* glfw, struct nk_font_atlas **atlas);
|
||||
NK_API void nk_glfw3_font_stash_end(struct nk_glfw* glfw);
|
||||
NK_API void nk_glfw3_new_frame(struct nk_glfw* glfw);
|
||||
NK_API void nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing, int max_vertex_buffer, int max_element_buffer);
|
||||
|
||||
NK_API void nk_glfw3_device_destroy(struct nk_glfw* glfw);
|
||||
NK_API void nk_glfw3_device_create(struct nk_glfw* glfw);
|
||||
|
||||
NK_API void nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint);
|
||||
NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff);
|
||||
NK_API void nk_glfw3_mouse_button_callback(GLFWwindow *win, int button, int action, int mods);
|
||||
|
||||
#endif
|
||||
/*
|
||||
* ==============================================================
|
||||
*
|
||||
* IMPLEMENTATION
|
||||
*
|
||||
* ===============================================================
|
||||
*/
|
||||
#ifdef NK_GLFW_GL3_IMPLEMENTATION
|
||||
|
||||
#ifndef NK_GLFW_DOUBLE_CLICK_LO
|
||||
#define NK_GLFW_DOUBLE_CLICK_LO 0.02
|
||||
#endif
|
||||
#ifndef NK_GLFW_DOUBLE_CLICK_HI
|
||||
#define NK_GLFW_DOUBLE_CLICK_HI 0.2
|
||||
#endif
|
||||
|
||||
struct nk_glfw_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define NK_SHADER_VERSION "#version 150\n"
|
||||
#else
|
||||
#define NK_SHADER_VERSION "#version 300 es\n"
|
||||
#endif
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_device_create(struct nk_glfw* glfw)
|
||||
{
|
||||
GLint status;
|
||||
static const GLchar *vertex_shader =
|
||||
NK_SHADER_VERSION
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"in vec2 Position;\n"
|
||||
"in vec2 TexCoord;\n"
|
||||
"in vec4 Color;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main() {\n"
|
||||
" Frag_UV = TexCoord;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy, 0, 1);\n"
|
||||
"}\n";
|
||||
static const GLchar *fragment_shader =
|
||||
NK_SHADER_VERSION
|
||||
"precision mediump float;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"out vec4 Out_Color;\n"
|
||||
"void main(){\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
struct nk_glfw_device *dev = &glfw->ogl;
|
||||
nk_buffer_init_default(&dev->cmds);
|
||||
dev->prog = glCreateProgram();
|
||||
dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER);
|
||||
dev->frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(dev->vert_shdr, 1, &vertex_shader, 0);
|
||||
glShaderSource(dev->frag_shdr, 1, &fragment_shader, 0);
|
||||
glCompileShader(dev->vert_shdr);
|
||||
glCompileShader(dev->frag_shdr);
|
||||
glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
|
||||
assert(status == GL_TRUE);
|
||||
glGetShaderiv(dev->frag_shdr, GL_COMPILE_STATUS, &status);
|
||||
assert(status == GL_TRUE);
|
||||
glAttachShader(dev->prog, dev->vert_shdr);
|
||||
glAttachShader(dev->prog, dev->frag_shdr);
|
||||
glLinkProgram(dev->prog);
|
||||
glGetProgramiv(dev->prog, GL_LINK_STATUS, &status);
|
||||
assert(status == GL_TRUE);
|
||||
|
||||
dev->uniform_tex = glGetUniformLocation(dev->prog, "Texture");
|
||||
dev->uniform_proj = glGetUniformLocation(dev->prog, "ProjMtx");
|
||||
dev->attrib_pos = glGetAttribLocation(dev->prog, "Position");
|
||||
dev->attrib_uv = glGetAttribLocation(dev->prog, "TexCoord");
|
||||
dev->attrib_col = glGetAttribLocation(dev->prog, "Color");
|
||||
|
||||
{
|
||||
/* buffer setup */
|
||||
GLsizei vs = sizeof(struct nk_glfw_vertex);
|
||||
size_t vp = offsetof(struct nk_glfw_vertex, position);
|
||||
size_t vt = offsetof(struct nk_glfw_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_glfw_vertex, col);
|
||||
|
||||
glGenBuffers(1, &dev->vbo);
|
||||
glGenBuffers(1, &dev->ebo);
|
||||
glGenVertexArrays(1, &dev->vao);
|
||||
|
||||
glBindVertexArray(dev->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
|
||||
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_pos);
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_uv);
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_col);
|
||||
|
||||
glVertexAttribPointer((GLuint)dev->attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, (void*)vp);
|
||||
glVertexAttribPointer((GLuint)dev->attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, (void*)vt);
|
||||
glVertexAttribPointer((GLuint)dev->attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, (void*)vc);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
NK_INTERN void
|
||||
nk_glfw3_device_upload_atlas(struct nk_glfw* glfw, const void *image, int width, int height)
|
||||
{
|
||||
struct nk_glfw_device *dev = &glfw->ogl;
|
||||
glGenTextures(1, &dev->font_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, dev->font_tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_device_destroy(struct nk_glfw* glfw)
|
||||
{
|
||||
struct nk_glfw_device *dev = &glfw->ogl;
|
||||
glDetachShader(dev->prog, dev->vert_shdr);
|
||||
glDetachShader(dev->prog, dev->frag_shdr);
|
||||
glDeleteShader(dev->vert_shdr);
|
||||
glDeleteShader(dev->frag_shdr);
|
||||
glDeleteProgram(dev->prog);
|
||||
glDeleteTextures(1, &dev->font_tex);
|
||||
glDeleteBuffers(1, &dev->vbo);
|
||||
glDeleteBuffers(1, &dev->ebo);
|
||||
nk_buffer_free(&dev->cmds);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_buffer)
|
||||
{
|
||||
struct nk_glfw_device *dev = &glfw->ogl;
|
||||
struct nk_buffer vbuf, ebuf;
|
||||
GLfloat ortho[4][4] = {
|
||||
{2.0f, 0.0f, 0.0f, 0.0f},
|
||||
{0.0f,-2.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f,-1.0f, 0.0f},
|
||||
{-1.0f,1.0f, 0.0f, 1.0f},
|
||||
};
|
||||
ortho[0][0] /= (GLfloat)glfw->width;
|
||||
ortho[1][1] /= (GLfloat)glfw->height;
|
||||
|
||||
/* setup global state */
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
/* setup program */
|
||||
glUseProgram(dev->prog);
|
||||
glUniform1i(dev->uniform_tex, 0);
|
||||
glUniformMatrix4fv(dev->uniform_proj, 1, GL_FALSE, &ortho[0][0]);
|
||||
glViewport(0,0,(GLsizei)glfw->display_width,(GLsizei)glfw->display_height);
|
||||
{
|
||||
/* convert from command queue into draw list and draw to screen */
|
||||
const struct nk_draw_command *cmd;
|
||||
void *vertices, *elements;
|
||||
const nk_draw_index *offset = NULL;
|
||||
|
||||
/* allocate vertex and element buffer */
|
||||
glBindVertexArray(dev->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, max_vertex_buffer, NULL, GL_STREAM_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, max_element_buffer, NULL, GL_STREAM_DRAW);
|
||||
|
||||
/* load draw vertices & elements directly into vertex + element buffer */
|
||||
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
{
|
||||
/* fill convert configuration */
|
||||
struct nk_convert_config config;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_glfw_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
|
||||
config.null = dev->null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* setup buffers to load vertices and elements */
|
||||
nk_buffer_init_fixed(&vbuf, vertices, (size_t)max_vertex_buffer);
|
||||
nk_buffer_init_fixed(&ebuf, elements, (size_t)max_element_buffer);
|
||||
nk_convert(&glfw->ctx, &dev->cmds, &vbuf, &ebuf, &config);
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, &glfw->ctx, &dev->cmds)
|
||||
{
|
||||
if (!cmd->elem_count) continue;
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
|
||||
glScissor(
|
||||
(GLint)(cmd->clip_rect.x * glfw->fb_scale.x),
|
||||
(GLint)((glfw->height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * glfw->fb_scale.y),
|
||||
(GLint)(cmd->clip_rect.w * glfw->fb_scale.x),
|
||||
(GLint)(cmd->clip_rect.h * glfw->fb_scale.y));
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
nk_clear(&glfw->ctx);
|
||||
nk_buffer_clear(&dev->cmds);
|
||||
}
|
||||
|
||||
/* default OpenGL state */
|
||||
glUseProgram(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint)
|
||||
{
|
||||
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
|
||||
if (glfw->text_len < NK_GLFW_TEXT_MAX)
|
||||
glfw->text[glfw->text_len++] = codepoint;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
|
||||
{
|
||||
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
|
||||
(void)xoff;
|
||||
glfw->scroll.x += (float)xoff;
|
||||
glfw->scroll.y += (float)yoff;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_mouse_button_callback(GLFWwindow* win, int button, int action, int mods)
|
||||
{
|
||||
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
|
||||
double x, y;
|
||||
NK_UNUSED(mods);
|
||||
if (button != GLFW_MOUSE_BUTTON_LEFT) return;
|
||||
glfwGetCursorPos(win, &x, &y);
|
||||
if (action == GLFW_PRESS) {
|
||||
double dt = glfwGetTime() - glfw->last_button_click;
|
||||
if (dt > NK_GLFW_DOUBLE_CLICK_LO && dt < NK_GLFW_DOUBLE_CLICK_HI) {
|
||||
glfw->is_double_click_down = nk_true;
|
||||
glfw->double_click_pos = nk_vec2((float)x, (float)y);
|
||||
}
|
||||
glfw->last_button_click = glfwGetTime();
|
||||
} else glfw->is_double_click_down = nk_false;
|
||||
}
|
||||
|
||||
NK_INTERN void
|
||||
nk_glfw3_clipboard_paste(nk_handle usr, struct nk_text_edit *edit)
|
||||
{
|
||||
struct nk_glfw* glfw = (struct nk_glfw*)usr.ptr;
|
||||
const char *text = glfwGetClipboardString(glfw->win);
|
||||
if (text) nk_textedit_paste(edit, text, nk_strlen(text));
|
||||
(void)usr;
|
||||
}
|
||||
|
||||
NK_INTERN void
|
||||
nk_glfw3_clipboard_copy(nk_handle usr, const char *text, int len)
|
||||
{
|
||||
struct nk_glfw* glfw = (struct nk_glfw*)usr.ptr;
|
||||
char *str = 0;
|
||||
if (!len) return;
|
||||
str = (char*)malloc((size_t)len+1);
|
||||
if (!str) return;
|
||||
memcpy(str, text, (size_t)len);
|
||||
str[len] = '\0';
|
||||
glfwSetClipboardString(glfw->win, str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
NK_API struct nk_context*
|
||||
nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state init_state)
|
||||
{
|
||||
glfwSetWindowUserPointer(win, glfw);
|
||||
glfw->win = win;
|
||||
if (init_state == NK_GLFW3_INSTALL_CALLBACKS) {
|
||||
glfwSetScrollCallback(win, nk_gflw3_scroll_callback);
|
||||
glfwSetCharCallback(win, nk_glfw3_char_callback);
|
||||
glfwSetMouseButtonCallback(win, nk_glfw3_mouse_button_callback);
|
||||
}
|
||||
nk_init_default(&glfw->ctx, 0);
|
||||
glfw->ctx.clip.copy = nk_glfw3_clipboard_copy;
|
||||
glfw->ctx.clip.paste = nk_glfw3_clipboard_paste;
|
||||
glfw->ctx.clip.userdata = nk_handle_ptr(&glfw);
|
||||
glfw->last_button_click = 0;
|
||||
nk_glfw3_device_create(glfw);
|
||||
|
||||
glfw->is_double_click_down = nk_false;
|
||||
glfw->double_click_pos = nk_vec2(0, 0);
|
||||
|
||||
return &glfw->ctx;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_font_stash_begin(struct nk_glfw* glfw, struct nk_font_atlas **atlas)
|
||||
{
|
||||
nk_font_atlas_init_default(&glfw->atlas);
|
||||
nk_font_atlas_begin(&glfw->atlas);
|
||||
*atlas = &glfw->atlas;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_font_stash_end(struct nk_glfw* glfw)
|
||||
{
|
||||
const void *image; int w, h;
|
||||
image = nk_font_atlas_bake(&glfw->atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
|
||||
nk_glfw3_device_upload_atlas(glfw, image, w, h);
|
||||
nk_font_atlas_end(&glfw->atlas, nk_handle_id((int)glfw->ogl.font_tex), &glfw->ogl.null);
|
||||
if (glfw->atlas.default_font)
|
||||
nk_style_set_font(&glfw->ctx, &glfw->atlas.default_font->handle);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_glfw3_new_frame(struct nk_glfw* glfw)
|
||||
{
|
||||
int i;
|
||||
double x, y;
|
||||
struct nk_context *ctx = &glfw->ctx;
|
||||
struct GLFWwindow *win = glfw->win;
|
||||
|
||||
glfwGetWindowSize(win, &glfw->width, &glfw->height);
|
||||
glfwGetFramebufferSize(win, &glfw->display_width, &glfw->display_height);
|
||||
glfw->fb_scale.x = (float)glfw->display_width/(float)glfw->width;
|
||||
glfw->fb_scale.y = (float)glfw->display_height/(float)glfw->height;
|
||||
|
||||
nk_input_begin(ctx);
|
||||
for (i = 0; i < glfw->text_len; ++i)
|
||||
nk_input_unicode(ctx, glfw->text[i]);
|
||||
|
||||
#ifdef NK_GLFW_GL3_MOUSE_GRABBING
|
||||
/* optional grabbing behavior */
|
||||
if (ctx->input.mouse.grab)
|
||||
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
else if (ctx->input.mouse.ungrab)
|
||||
glfwSetInputMode(glfw->win, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
#endif
|
||||
|
||||
nk_input_key(ctx, NK_KEY_DEL, glfwGetKey(win, GLFW_KEY_DELETE) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_ENTER, glfwGetKey(win, GLFW_KEY_ENTER) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TAB, glfwGetKey(win, GLFW_KEY_TAB) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_BACKSPACE, glfwGetKey(win, GLFW_KEY_BACKSPACE) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_UP, glfwGetKey(win, GLFW_KEY_UP) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_DOWN, glfwGetKey(win, GLFW_KEY_DOWN) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_START, glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_END, glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_START, glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_END, glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_DOWN, glfwGetKey(win, GLFW_KEY_PAGE_DOWN) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_UP, glfwGetKey(win, GLFW_KEY_PAGE_UP) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_SHIFT, glfwGetKey(win, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS||
|
||||
glfwGetKey(win, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
|
||||
|
||||
if (glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
|
||||
glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) {
|
||||
nk_input_key(ctx, NK_KEY_COPY, glfwGetKey(win, GLFW_KEY_C) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_PASTE, glfwGetKey(win, GLFW_KEY_V) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_CUT, glfwGetKey(win, GLFW_KEY_X) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_UNDO, glfwGetKey(win, GLFW_KEY_Z) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_REDO, glfwGetKey(win, GLFW_KEY_R) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, glfwGetKey(win, GLFW_KEY_LEFT) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, glfwGetKey(win, GLFW_KEY_RIGHT) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_LINE_START, glfwGetKey(win, GLFW_KEY_B) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TEXT_LINE_END, glfwGetKey(win, GLFW_KEY_E) == GLFW_PRESS);
|
||||
} else {
|
||||
nk_input_key(ctx, NK_KEY_LEFT, glfwGetKey(win, GLFW_KEY_LEFT) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_RIGHT, glfwGetKey(win, GLFW_KEY_RIGHT) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_COPY, 0);
|
||||
nk_input_key(ctx, NK_KEY_PASTE, 0);
|
||||
nk_input_key(ctx, NK_KEY_CUT, 0);
|
||||
nk_input_key(ctx, NK_KEY_SHIFT, 0);
|
||||
}
|
||||
|
||||
glfwGetCursorPos(win, &x, &y);
|
||||
nk_input_motion(ctx, (int)x, (int)y);
|
||||
#ifdef NK_GLFW_GL3_MOUSE_GRABBING
|
||||
if (ctx->input.mouse.grabbed) {
|
||||
glfwSetCursorPos(glfw->win, ctx->input.mouse.prev.x, ctx->input.mouse.prev.y);
|
||||
ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
|
||||
ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
|
||||
}
|
||||
#endif
|
||||
nk_input_button(ctx, NK_BUTTON_LEFT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
|
||||
nk_input_button(ctx, NK_BUTTON_MIDDLE, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
|
||||
nk_input_button(ctx, NK_BUTTON_RIGHT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
|
||||
nk_input_button(ctx, NK_BUTTON_DOUBLE, (int)glfw->double_click_pos.x, (int)glfw->double_click_pos.y, glfw->is_double_click_down);
|
||||
nk_input_scroll(ctx, glfw->scroll);
|
||||
nk_input_end(&glfw->ctx);
|
||||
glfw->text_len = 0;
|
||||
glfw->scroll = nk_vec2(0,0);
|
||||
}
|
||||
|
||||
NK_API
|
||||
void nk_glfw3_shutdown(struct nk_glfw* glfw)
|
||||
{
|
||||
nk_font_atlas_clear(&glfw->atlas);
|
||||
nk_free(&glfw->ctx);
|
||||
nk_glfw3_device_destroy(glfw);
|
||||
memset(glfw, 0, sizeof(*glfw));
|
||||
}
|
||||
|
||||
#endif
|
1148
source/engine/thirdparty/sokol/sokol_color.h
vendored
Normal file
1148
source/engine/thirdparty/sokol/sokol_color.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
4644
source/engine/thirdparty/sokol/sokol_debugtext.h
vendored
Normal file
4644
source/engine/thirdparty/sokol/sokol_debugtext.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
1904
source/engine/thirdparty/sokol/sokol_fontstash.h
vendored
Normal file
1904
source/engine/thirdparty/sokol/sokol_fontstash.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
4226
source/engine/thirdparty/sokol/sokol_gfx_imgui.h
vendored
Normal file
4226
source/engine/thirdparty/sokol/sokol_gfx_imgui.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
4318
source/engine/thirdparty/sokol/sokol_gl.h
vendored
Normal file
4318
source/engine/thirdparty/sokol/sokol_gl.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
2457
source/engine/thirdparty/sokol/sokol_imgui.h
vendored
Normal file
2457
source/engine/thirdparty/sokol/sokol_imgui.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
167
source/engine/thirdparty/sokol/sokol_memtrack.h
vendored
Normal file
167
source/engine/thirdparty/sokol/sokol_memtrack.h
vendored
Normal file
|
@ -0,0 +1,167 @@
|
|||
#if defined(SOKOL_IMPL) && !defined(SOKOL_MEMTRACK_IMPL)
|
||||
#define SOKOL_MEMTRACK_IMPL
|
||||
#endif
|
||||
#ifndef SOKOL_MEMTRACK_INCLUDED
|
||||
/*
|
||||
sokol_memtrack.h -- memory allocation wrapper to track memory usage
|
||||
of sokol libraries
|
||||
|
||||
Project URL: https://github.com/floooh/sokol
|
||||
|
||||
Optionally provide the following defines with your own implementations:
|
||||
|
||||
SOKOL_MEMTRACK_API_DECL - public function declaration prefix (default: extern)
|
||||
SOKOL_API_DECL - same as SOKOL_MEMTRACK_API_DECL
|
||||
SOKOL_API_IMPL - public function implementation prefix (default: -)
|
||||
|
||||
If sokol_memtrack.h is compiled as a DLL, define the following before
|
||||
including the declaration or implementation:
|
||||
|
||||
SOKOL_DLL
|
||||
|
||||
USAGE
|
||||
=====
|
||||
Just plug the malloc/free wrapper functions into the desc.allocator
|
||||
struct provided by most sokol header setup functions:
|
||||
|
||||
sg_setup(&(sg_desc){
|
||||
//...
|
||||
.allocator = {
|
||||
.alloc = smemtrack_alloc,
|
||||
.free = smemtrack_free,
|
||||
}
|
||||
});
|
||||
|
||||
Then call smemtrack_info() to get information about current number
|
||||
of allocations and overall allocation size:
|
||||
|
||||
const smemtrack_info_t info = smemtrack_info();
|
||||
const int num_allocs = info.num_allocs;
|
||||
const int num_bytes = info.num_bytes;
|
||||
|
||||
Note the sokol_memtrack.h can only track allocations issued by
|
||||
the sokol headers, not allocations that happen under the hood
|
||||
in system libraries.
|
||||
|
||||
LICENSE
|
||||
=======
|
||||
|
||||
zlib/libpng license
|
||||
|
||||
Copyright (c) 2018 Andre Weissflog
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the
|
||||
use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software in a
|
||||
product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
#define SOKOL_MEMTRACK_INCLUDED (1)
|
||||
#include <stdint.h>
|
||||
#include <stddef.h> // size_t
|
||||
|
||||
#if defined(SOKOL_API_DECL) && !defined(SOKOL_MEMTRACK_API_DECL)
|
||||
#define SOKOL_MEMTRACK_API_DECL SOKOL_API_DECL
|
||||
#endif
|
||||
#ifndef SOKOL_MEMTRACK_API_DECL
|
||||
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_MEMTRACK_IMPL)
|
||||
#define SOKOL_MEMTRACK_API_DECL __declspec(dllexport)
|
||||
#elif defined(_WIN32) && defined(SOKOL_DLL)
|
||||
#define SOKOL_MEMTRACK_API_DECL __declspec(dllimport)
|
||||
#else
|
||||
#define SOKOL_MEMTRACK_API_DECL extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct smemtrack_info_t {
|
||||
int num_allocs;
|
||||
int num_bytes;
|
||||
} smemtrack_info_t;
|
||||
|
||||
SOKOL_MEMTRACK_API_DECL smemtrack_info_t smemtrack_info(void);
|
||||
SOKOL_MEMTRACK_API_DECL void* smemtrack_alloc(size_t size, void* user_data);
|
||||
SOKOL_MEMTRACK_API_DECL void smemtrack_free(void* ptr, void* user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* SOKOL_MEMTRACK_INCLUDED */
|
||||
|
||||
/*=== IMPLEMENTATION =========================================================*/
|
||||
#ifdef SOKOL_MEMTRACK_IMPL
|
||||
#define SOKOL_MEMTRACK_IMPL_INCLUDED (1)
|
||||
#include <stdlib.h> // malloc, free
|
||||
#include <string.h> // memset
|
||||
|
||||
#ifndef SOKOL_API_IMPL
|
||||
#define SOKOL_API_IMPL
|
||||
#endif
|
||||
#ifndef SOKOL_DEBUG
|
||||
#ifndef NDEBUG
|
||||
#define SOKOL_DEBUG
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _SOKOL_PRIVATE
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define _SOKOL_PRIVATE __attribute__((unused)) static
|
||||
#else
|
||||
#define _SOKOL_PRIVATE static
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// per-allocation header used to keep track of the allocation size
|
||||
#define _SMEMTRACK_HEADER_SIZE (16)
|
||||
|
||||
static struct {
|
||||
smemtrack_info_t state;
|
||||
} _smemtrack;
|
||||
|
||||
SOKOL_API_IMPL void* smemtrack_alloc(size_t size, void* user_data) {
|
||||
(void)user_data;
|
||||
uint8_t* ptr = (uint8_t*) malloc(size + _SMEMTRACK_HEADER_SIZE);
|
||||
if (ptr) {
|
||||
// store allocation size (for allocation size tracking)
|
||||
*(size_t*)ptr = size;
|
||||
_smemtrack.state.num_allocs++;
|
||||
_smemtrack.state.num_bytes += (int) size;
|
||||
return ptr + _SMEMTRACK_HEADER_SIZE;
|
||||
}
|
||||
else {
|
||||
// allocation failed, return null pointer
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
SOKOL_API_IMPL void smemtrack_free(void* ptr, void* user_data) {
|
||||
(void)user_data;
|
||||
if (ptr) {
|
||||
uint8_t* alloc_ptr = ((uint8_t*)ptr) - _SMEMTRACK_HEADER_SIZE;
|
||||
size_t size = *(size_t*)alloc_ptr;
|
||||
_smemtrack.state.num_allocs--;
|
||||
_smemtrack.state.num_bytes -= (int) size;
|
||||
free(alloc_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
SOKOL_API_IMPL smemtrack_info_t smemtrack_info(void) {
|
||||
return _smemtrack.state;
|
||||
}
|
||||
|
||||
#endif /* SOKOL_MEMTRACK_IMPL */
|
2180
source/engine/thirdparty/sokol/sokol_nuklear.h
vendored
Normal file
2180
source/engine/thirdparty/sokol/sokol_nuklear.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
1437
source/engine/thirdparty/sokol/sokol_shape.h
vendored
Normal file
1437
source/engine/thirdparty/sokol/sokol_shape.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
5759
source/engine/thirdparty/sokol/sokol_spine.h
vendored
Normal file
5759
source/engine/thirdparty/sokol/sokol_spine.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,14 +1,13 @@
|
|||
#include "timer.h"
|
||||
#include <stdlib.h>
|
||||
#include "log.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stb_ds.h>
|
||||
|
||||
struct timer *timers;
|
||||
static int first = -1;
|
||||
|
||||
void check_timer(struct timer *t, double dt)
|
||||
{
|
||||
void check_timer(struct timer *t, double dt) {
|
||||
if (!t->on)
|
||||
return;
|
||||
|
||||
|
@ -82,7 +81,6 @@ void timerr_settime(struct timer *t, double interval) {
|
|||
t->interval = interval;
|
||||
}
|
||||
|
||||
struct timer *id2timer(int id)
|
||||
{
|
||||
struct timer *id2timer(int id) {
|
||||
return &timers[id];
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,7 @@
|
|||
#include "transform.h"
|
||||
#include <string.h>
|
||||
|
||||
struct mTransform MakeTransform(mfloat_t pos[3], mfloat_t rotation[4], float scale)
|
||||
{
|
||||
struct mTransform MakeTransform(mfloat_t pos[3], mfloat_t rotation[4], float scale) {
|
||||
struct mTransform newT;
|
||||
memcpy(newT.position, pos, sizeof(*pos));
|
||||
memcpy(newT.rotation, rotation, sizeof(*rotation));
|
||||
|
@ -11,41 +10,34 @@ struct mTransform MakeTransform(mfloat_t pos[3], mfloat_t rotation[4], float sca
|
|||
}
|
||||
|
||||
mfloat_t *trans_forward(mfloat_t *res,
|
||||
const struct mTransform *const trans)
|
||||
{
|
||||
const struct mTransform *const trans) {
|
||||
// YughLog(0, SDL_LOG_PRIORITY_WARN, "Rotation is %f", trans->rotation[0]);
|
||||
return vec3_rotate_quat(res, FORWARD, trans->rotation);
|
||||
}
|
||||
|
||||
mfloat_t *trans_back(mfloat_t * res, const struct mTransform *trans)
|
||||
{
|
||||
mfloat_t *trans_back(mfloat_t *res, const struct mTransform *trans) {
|
||||
return vec3_rotate_quat(res, BACK, trans->rotation);
|
||||
}
|
||||
|
||||
mfloat_t *trans_up(mfloat_t * res, const struct mTransform *trans)
|
||||
{
|
||||
mfloat_t *trans_up(mfloat_t *res, const struct mTransform *trans) {
|
||||
return vec3_rotate_quat(res, UP, trans->rotation);
|
||||
}
|
||||
|
||||
mfloat_t *trans_down(mfloat_t * res, const struct mTransform *trans)
|
||||
{
|
||||
mfloat_t *trans_down(mfloat_t *res, const struct mTransform *trans) {
|
||||
return vec3_rotate_quat(res, DOWN, trans->rotation);
|
||||
}
|
||||
|
||||
mfloat_t *trans_right(mfloat_t * res, const struct mTransform *trans)
|
||||
{
|
||||
mfloat_t *trans_right(mfloat_t *res, const struct mTransform *trans) {
|
||||
return vec3_rotate_quat(res, RIGHT, trans->rotation);
|
||||
}
|
||||
|
||||
mfloat_t *trans_left(mfloat_t * res, const struct mTransform *trans)
|
||||
{
|
||||
mfloat_t *trans_left(mfloat_t *res, const struct mTransform *trans) {
|
||||
return vec3_rotate_quat(res, LEFT, trans->rotation);
|
||||
}
|
||||
|
||||
#include "nuke.h"
|
||||
|
||||
void trans_drawgui(struct mTransform *T)
|
||||
{
|
||||
void trans_drawgui(struct mTransform *T) {
|
||||
nuke_property_float3("Position", -1000.f, T->position, 1000.f, 1.f, 1.f);
|
||||
nuke_property_float3("Rotation", 0.f, T->rotation, 360.f, 1.f, 0.1f);
|
||||
nuke_property_float("Scale", 0.f, &T->scale, 1000.f, 0.1f, 0.1f);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "window.h"
|
||||
#include <string.h>
|
||||
#include "texture.h"
|
||||
#include "log.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "input.h"
|
||||
#include "script.h"
|
||||
#include "log.h"
|
||||
#include "nuke.h"
|
||||
#include "script.h"
|
||||
#include "texture.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "openglrender.h"
|
||||
|
||||
|
@ -18,18 +18,14 @@ static struct window *windows = NULL;
|
|||
|
||||
struct Texture *icon = NULL;
|
||||
|
||||
int is_win(struct window *s, GLFWwindow *w)
|
||||
{
|
||||
int is_win(struct window *s, GLFWwindow *w) {
|
||||
return s->window == w;
|
||||
}
|
||||
|
||||
void window_size_callback(GLFWwindow *w, int width, int height)
|
||||
{
|
||||
|
||||
void window_size_callback(GLFWwindow *w, int width, int height) {
|
||||
}
|
||||
|
||||
struct window *winfind(GLFWwindow *w)
|
||||
{
|
||||
struct window *winfind(GLFWwindow *w) {
|
||||
for (int i = 0; i < arrlen(windows); i++) {
|
||||
if (windows[i].window == w)
|
||||
return &windows[i];
|
||||
|
@ -38,26 +34,22 @@ struct window *winfind(GLFWwindow *w)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void window_iconify_callback(GLFWwindow *w, int iconified)
|
||||
{
|
||||
void window_iconify_callback(GLFWwindow *w, int iconified) {
|
||||
struct window *win = winfind(w);
|
||||
win->iconified = iconified;
|
||||
}
|
||||
|
||||
void window_focus_callback(GLFWwindow *w, int focused)
|
||||
{
|
||||
void window_focus_callback(GLFWwindow *w, int focused) {
|
||||
struct window *win = winfind(w);
|
||||
win->mouseFocus = focused;
|
||||
}
|
||||
|
||||
void window_maximize_callback(GLFWwindow *w, int maximized)
|
||||
{
|
||||
void window_maximize_callback(GLFWwindow *w, int maximized) {
|
||||
struct window *win = winfind(w);
|
||||
win->minimized = !maximized;
|
||||
}
|
||||
|
||||
void window_framebuffer_size_cb(GLFWwindow *w, int width, int height)
|
||||
{
|
||||
void window_framebuffer_size_cb(GLFWwindow *w, int width, int height) {
|
||||
struct window *win = winfind(w);
|
||||
win->width = width;
|
||||
win->height = height;
|
||||
|
@ -65,15 +57,11 @@ void window_framebuffer_size_cb(GLFWwindow *w, int width, int height)
|
|||
win->render = 1;
|
||||
}
|
||||
|
||||
void window_close_callback(GLFWwindow *w)
|
||||
{
|
||||
void window_close_callback(GLFWwindow *w) {
|
||||
quit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t flags)
|
||||
{
|
||||
struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t flags) {
|
||||
if (arrcap(windows) == 0)
|
||||
arrsetcap(windows, 5);
|
||||
|
||||
|
@ -85,6 +73,7 @@ struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t f
|
|||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_SAMPLES,1);
|
||||
|
||||
struct window w = {
|
||||
.width = width,
|
||||
|
@ -92,7 +81,6 @@ struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t f
|
|||
.id = arrlen(windows),
|
||||
.window = glfwCreateWindow(width, height, name, NULL, sharewin)};
|
||||
|
||||
|
||||
if (!w.window) {
|
||||
YughError("Couldn't make GLFW window\n", 1);
|
||||
return NULL;
|
||||
|
@ -114,8 +102,6 @@ struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t f
|
|||
glfwSetWindowFocusCallback(w.window, window_focus_callback);
|
||||
glfwSetKeyCallback(w.window, win_key_callback);
|
||||
|
||||
// nuke_init(&w);
|
||||
|
||||
arrput(windows, w);
|
||||
|
||||
if (arrlen(windows) == 1)
|
||||
|
@ -124,14 +110,12 @@ struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t f
|
|||
return &arrlast(windows);
|
||||
}
|
||||
|
||||
void window_set_icon(const char *png)
|
||||
{
|
||||
void window_set_icon(const char *png) {
|
||||
icon = texture_pullfromfile(png);
|
||||
window_seticon(mainwin, icon);
|
||||
}
|
||||
|
||||
void window_destroy(struct window *w)
|
||||
{
|
||||
void window_destroy(struct window *w) {
|
||||
glfwDestroyWindow(w->window);
|
||||
arrdelswap(windows, w->id);
|
||||
}
|
||||
|
@ -140,8 +124,7 @@ struct window *window_i(int index) {
|
|||
return &windows[index];
|
||||
}
|
||||
|
||||
void window_handle_event(struct window *w)
|
||||
{
|
||||
void window_handle_event(struct window *w) {
|
||||
/*
|
||||
if (e->type == SDL_WINDOWEVENT && e->window.windowID == w->id) { // TODO: Check ptr direct?
|
||||
switch (e->window.event) {
|
||||
|
@ -220,26 +203,22 @@ void window_handle_event(struct window *w)
|
|||
*/
|
||||
}
|
||||
|
||||
void window_all_handle_events()
|
||||
{
|
||||
void window_all_handle_events() {
|
||||
for (int i = 0; i < arrlen(windows); i++)
|
||||
window_handle_event(&windows[i]);
|
||||
}
|
||||
|
||||
void window_makefullscreen(struct window *w)
|
||||
{
|
||||
void window_makefullscreen(struct window *w) {
|
||||
if (!w->fullscreen)
|
||||
window_togglefullscreen(w);
|
||||
}
|
||||
|
||||
void window_unfullscreen(struct window *w)
|
||||
{
|
||||
void window_unfullscreen(struct window *w) {
|
||||
if (w->fullscreen)
|
||||
window_togglefullscreen(w);
|
||||
}
|
||||
|
||||
void window_togglefullscreen(struct window *w)
|
||||
{
|
||||
void window_togglefullscreen(struct window *w) {
|
||||
w->fullscreen = !w->fullscreen;
|
||||
|
||||
if (w->fullscreen) {
|
||||
|
@ -247,27 +226,20 @@ void window_togglefullscreen(struct window *w)
|
|||
} else {
|
||||
glfwRestoreWindow(w->window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void window_makecurrent(struct window *w)
|
||||
{
|
||||
void window_makecurrent(struct window *w) {
|
||||
|
||||
if (w->window != glfwGetCurrentContext())
|
||||
glfwMakeContextCurrent(w->window);
|
||||
glViewport(0, 0, w->width, w->height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void window_swap(struct window *w)
|
||||
{
|
||||
void window_swap(struct window *w) {
|
||||
glfwSwapBuffers(w->window);
|
||||
}
|
||||
|
||||
void window_seticon(struct window *w, struct Texture *icon)
|
||||
{
|
||||
void window_seticon(struct window *w, struct Texture *icon) {
|
||||
|
||||
static GLFWimage images[1];
|
||||
images[0].width = icon->width;
|
||||
|
@ -276,8 +248,7 @@ void window_seticon(struct window *w, struct Texture *icon)
|
|||
glfwSetWindowIcon(w->window, 1, images);
|
||||
}
|
||||
|
||||
int window_hasfocus(struct window *w)
|
||||
{
|
||||
int window_hasfocus(struct window *w) {
|
||||
return glfwGetWindowAttrib(w->window, GLFW_FOCUSED);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#include "yugine.h"
|
||||
|
||||
|
||||
#include "camera.h"
|
||||
#include "window.h"
|
||||
#include "engine.h"
|
||||
#include "font.h"
|
||||
#include "gameobject.h"
|
||||
#include "input.h"
|
||||
#include "openglrender.h"
|
||||
#include "gameobject.h"
|
||||
#include "font.h"
|
||||
#include "window.h"
|
||||
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "miniaudio.h"
|
||||
|
@ -16,8 +15,8 @@
|
|||
|
||||
#include "quickjs/quickjs.h"
|
||||
|
||||
#include "script.h"
|
||||
#include "ffi.h"
|
||||
#include "script.h"
|
||||
|
||||
#include "log.h"
|
||||
#include <stdio.h>
|
||||
|
@ -25,19 +24,17 @@
|
|||
|
||||
#include "2dphysics.h"
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <execinfo.h>
|
||||
|
||||
#include "string.h"
|
||||
|
||||
|
||||
#define SOKOL_TRACE_HOOKS
|
||||
#define SOKOL_GFX_IMPL
|
||||
#define SOKOL_GLCORE33
|
||||
#include "sokol/sokol_gfx.h"
|
||||
|
||||
|
||||
int physOn = 0;
|
||||
|
||||
double renderlag = 0;
|
||||
|
@ -65,8 +62,7 @@ int fps;
|
|||
#define SIM_PAUSE 2
|
||||
#define SIM_STEP 3
|
||||
|
||||
void print_stacktrace()
|
||||
{
|
||||
void print_stacktrace() {
|
||||
void *ents[512];
|
||||
size_t size;
|
||||
|
||||
|
@ -94,8 +90,7 @@ void seghandle(int sig) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void compile_script(const char *file)
|
||||
{
|
||||
void compile_script(const char *file) {
|
||||
const char *script = slurp_text(file);
|
||||
JSValue obj = JS_Eval(js, script, strlen(script), file, JS_EVAL_FLAG_COMPILE_ONLY | JS_EVAL_TYPE_GLOBAL);
|
||||
size_t out_len;
|
||||
|
@ -107,8 +102,7 @@ void compile_script(const char *file)
|
|||
fclose(f);
|
||||
}
|
||||
|
||||
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data)
|
||||
{
|
||||
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {
|
||||
mYughLog(0, 1, line, file, "tag: %s, msg: %s", tag, msg);
|
||||
}
|
||||
|
||||
|
@ -130,8 +124,7 @@ int main(int argc, char **args) {
|
|||
log_setfile(args[i + 1]);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
YughError("Expected a file for command line arg '-l'.");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -161,7 +154,6 @@ int main(int argc, char **args) {
|
|||
case 'c':
|
||||
logout = 0;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,6 +195,8 @@ int main(int argc, char **args) {
|
|||
.func = sg_logging,
|
||||
.user_data = NULL,
|
||||
},
|
||||
.buffer_pool_size = 1024,
|
||||
.context.sample_count = 1,
|
||||
});
|
||||
|
||||
input_init();
|
||||
|
@ -252,8 +246,7 @@ int main(int argc, char **args) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int frame_fps()
|
||||
{
|
||||
int frame_fps() {
|
||||
double fpsms = 0;
|
||||
for (int i = 0; i < FPSBUF; i++) {
|
||||
fpsms += framems[i];
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#version 330 core
|
||||
|
||||
void main()
|
||||
{
|
||||
// gl_FragDepth = gl_FragCoord.z;
|
||||
}
|
|
@ -3,24 +3,27 @@ in vec2 coords;
|
|||
|
||||
out vec4 color;
|
||||
|
||||
uniform float radius;
|
||||
uniform int thickness;
|
||||
uniform vec3 dbgColor;
|
||||
uniform bool fill;
|
||||
uniform float zoom;
|
||||
//in int thickness;
|
||||
in float radius;
|
||||
//in bool fill;
|
||||
in vec3 fcolor;
|
||||
in vec2 pos;
|
||||
|
||||
void main()
|
||||
{
|
||||
int thickness = 1;
|
||||
bool fill = false;
|
||||
|
||||
// int tt = thickness + 1;
|
||||
float R1 = 1.f;
|
||||
float R2 = 1.f - (thickness*zoom / radius);
|
||||
// float R2 = 1.f - (thickness*zoom / radius);
|
||||
float R2 = 1.f - (thickness/radius);
|
||||
float dist = sqrt(dot(coords, coords));
|
||||
|
||||
if (dist >= R2 && dist <= R1)
|
||||
color = vec4(dbgColor, 1.f);
|
||||
color = vec4(fcolor, 1.f);
|
||||
else if (dist < R2)
|
||||
color = vec4(dbgColor, 0.1f);
|
||||
color = vec4(fcolor, 0.1f);
|
||||
else
|
||||
discard;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec4 vertex;
|
||||
layout (location = 0) in vec2 vertex;
|
||||
layout (location = 1) in vec3 acolor;
|
||||
layout (location = 2) in vec2 apos;
|
||||
layout (location = 3) in float aradius;
|
||||
layout (location = 4) in float afill;
|
||||
|
||||
out vec2 coords;
|
||||
|
||||
out float radius;
|
||||
out vec3 fcolor;
|
||||
|
||||
uniform mat4 proj;
|
||||
uniform vec2 res;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = proj * vec4(vertex.xy, 0.0, 1.0);
|
||||
coords = vertex.zw;
|
||||
gl_Position = proj * vec4((vertex * aradius) + apos, 0.0, 1.0);
|
||||
coords = vertex.xy;
|
||||
fcolor = acolor;
|
||||
radius = aradius;
|
||||
}
|
||||
|
|
26
source/shaders/crtfrag.glsl
Normal file
26
source/shaders/crtfrag.glsl
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330 core
|
||||
in vec2 TexCoords;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D diffuse_texture;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(diffuse_texture, TexCoords);
|
||||
// float avg = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
|
||||
// frag_color = vec4(avg,avg,avg,1.0);
|
||||
float lc = 720.0/2.0;
|
||||
float line = TexCoords.y * lc;
|
||||
float line_intensity = mod(float(line),2);
|
||||
|
||||
float off = line_intensity * 0.0005;
|
||||
vec4 shift = vec4(off,0,0,0);
|
||||
vec4 color_shift = vec4(0.001,0,0,0);
|
||||
float r = color.r + color_shift.r + shift.r;
|
||||
float g = color.g - color_shift.g + shift.g;
|
||||
float b = color.b;
|
||||
|
||||
frag_color = vec4(r, g*0.99, b, 1.0) * clamp(line_intensity, 0.85, 1.0);
|
||||
frag_color = texture(diffuse_texture, TexCoords);
|
||||
}
|
104
source/shaders/diffuse_f.glsl
Normal file
104
source/shaders/diffuse_f.glsl
Normal file
|
@ -0,0 +1,104 @@
|
|||
#version 330 core
|
||||
in vec2 tex_coords;
|
||||
in vec3 normal;
|
||||
in vec3 frag_pos;
|
||||
in vec4 frag_pos_light;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D diffuse;
|
||||
uniform sampler2D normmap;
|
||||
uniform sampler2D shadow_map;
|
||||
|
||||
uniform vec3 point_pos;
|
||||
uniform vec3 dir_dir;
|
||||
uniform vec3 view_pos;
|
||||
uniform vec3 spot_pos;
|
||||
uniform vec3 spot_dir;
|
||||
|
||||
/* Ambient light */
|
||||
float amb_str = 0.3;
|
||||
|
||||
vec3 amb_color = vec3(1,1,1);
|
||||
|
||||
float spec_str = 0.5;
|
||||
|
||||
/* point */
|
||||
float constant = 1;
|
||||
float linear = 0.09;
|
||||
float quad = 0.032;
|
||||
|
||||
/* spotlight */
|
||||
float cutoff = 12.5; /* cutoff in radians */
|
||||
float outer_cutoff = 17.5;
|
||||
|
||||
vec3 norm = vec3(0,0,0);
|
||||
vec3 view = vec3(0,0,0);
|
||||
|
||||
float light_str(vec3 dir)
|
||||
{
|
||||
float d = max(dot(norm, dir), 0.0);
|
||||
vec3 refl = reflect(-dir, norm);
|
||||
float s = pow(max(dot(view,refl), 0.0), 32);
|
||||
|
||||
return s+d;
|
||||
}
|
||||
|
||||
float shadow_calc(vec4 fg)
|
||||
{
|
||||
vec3 pc = fg.xyz / fg.w;
|
||||
pc = pc * 0.5 + 0.5;
|
||||
|
||||
if (pc.z > 1.0)
|
||||
return 0.0;
|
||||
|
||||
float closest_depth = texture(shadow_map, pc.xy).r;
|
||||
float cur_depth = pc.z;
|
||||
|
||||
vec3 light_dir = normalize(vec3(4,100,20) - frag_pos); /* light pos */
|
||||
float bias = max(0.05 * (1 - dot(norm, light_dir)), 0.005);
|
||||
|
||||
return cur_depth - bias > closest_depth ? 1.0 : 0.0;
|
||||
|
||||
float s;
|
||||
vec2 texel_size = 1 / textureSize(shadow_map, 0);
|
||||
|
||||
for (int x = -1; x <= 1; ++x) {
|
||||
for (int y = -1; y <= 1; ++y) {
|
||||
float pcf_depth = texture(shadow_map, pc.xy + vec2(x,y) * texel_size).r;
|
||||
s += cur_depth - bias > pcf_depth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
s /= 9.0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void main() {
|
||||
norm = normalize(normal);
|
||||
view = normalize(view_pos - frag_pos);
|
||||
|
||||
float point_amt = light_str(normalize(point_pos-frag_pos));
|
||||
float dist = length(point_pos - frag_pos);
|
||||
float atten = 1.0 / (constant + linear * dist + quad * (dist*dist));
|
||||
point_amt *= atten;
|
||||
|
||||
float dir_amt = light_str(normalize(-dir_dir));
|
||||
|
||||
vec3 spot_dir = normalize(spot_pos - frag_pos);
|
||||
float theta = dot(spot_dir, normalize(-spot_dir));
|
||||
float spot_amt = 0;
|
||||
|
||||
float epsilon = cutoff - outer_cutoff;
|
||||
|
||||
if (theta > cutoff) {
|
||||
float intensity = clamp((theta - outer_cutoff)/epsilon,0.0,1.0);
|
||||
spot_amt = light_str(spot_dir) * intensity;
|
||||
}
|
||||
|
||||
vec4 mm = texture(diffuse,tex_coords);
|
||||
float shadow = shadow_calc(frag_pos_light);
|
||||
vec3 res = mm.rgb * (amb_str + (point_amt + dir_amt) * (1 - shadow));
|
||||
frag_color = vec4(res, mm.a);
|
||||
}
|
23
source/shaders/diffuse_v.glsl
Normal file
23
source/shaders/diffuse_v.glsl
Normal file
|
@ -0,0 +1,23 @@
|
|||
#version 330 core
|
||||
layout (location=0) in vec3 a_pos;
|
||||
layout (location=1) in vec2 a_tex_coords;
|
||||
layout (location=2) in vec3 a_norm;
|
||||
|
||||
out vec2 tex_coords;
|
||||
out vec3 normal;
|
||||
out vec3 frag_pos;
|
||||
out vec4 frag_pos_light;
|
||||
|
||||
|
||||
uniform mat4 vp;
|
||||
uniform mat4 model;
|
||||
uniform mat4 proj;
|
||||
uniform mat4 lsm;
|
||||
|
||||
void main() {
|
||||
frag_pos = vec3(model * vec4(a_pos, 1.0));
|
||||
gl_Position = proj * vp * vec4(frag_pos, 1.0);
|
||||
tex_coords = a_tex_coords;
|
||||
normal = mat3(transpose(inverse(model))) * a_norm;
|
||||
frag_pos_light = lsm * vec4(frag_pos, 1.0);
|
||||
}
|
|
@ -1,19 +1,27 @@
|
|||
#version 330
|
||||
out vec4 color;
|
||||
out vec4 frag_color;
|
||||
|
||||
in vec2 apos;
|
||||
vec2 bpos;
|
||||
uniform int thickness;
|
||||
uniform int span;
|
||||
uniform float thickness; /* thickness in pixels */
|
||||
uniform float span;
|
||||
uniform vec3 color;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
float t = thickness / 2.f;
|
||||
bpos.x = mod(apos.x, span);
|
||||
bpos.y = mod(apos.y, span);
|
||||
float t = thickness / span;
|
||||
t /= 2.0;
|
||||
bpos.x = mod(apos.x, span) / span;
|
||||
bpos.y = mod(apos.y, span) / span;
|
||||
bpos.x -= t;
|
||||
bpos.y -= t;
|
||||
|
||||
if (!(bpos.x <= t || bpos.x >= (span - t) || bpos.y <= t || bpos.y >= (span - t)))
|
||||
float comp = min(bpos.x, bpos.y);
|
||||
|
||||
if (comp > t)
|
||||
discard;
|
||||
|
||||
color = vec4(0.4f, 0.7f, 0.2f, 0.3f);
|
||||
comp += t;
|
||||
|
||||
frag_color = vec4(color, 1.0);
|
||||
}
|
|
@ -1,17 +1,20 @@
|
|||
#version 330
|
||||
layout (location = 0) in vec2 pos;
|
||||
out vec2 apos;
|
||||
|
||||
uniform vec2 offset;
|
||||
out vec2 apos;
|
||||
|
||||
layout (std140) uniform Projection {
|
||||
mat4 projection;
|
||||
};
|
||||
|
||||
uniform vec2 offset;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 ipos = inverse(projection) * vec4(pos, 0.f, 1.f);
|
||||
apos = ipos.xy + offset;
|
||||
// vec4 ipos = inverse(projection) * vec4(pos, 0.f, 1.f);
|
||||
apos = pos * vec2(600, 360);
|
||||
// apos = pos + offset;
|
||||
|
||||
|
||||
gl_Position = vec4(pos, 0.f, 1.f);
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ uniform float alpha;
|
|||
|
||||
void main()
|
||||
{
|
||||
color = vec4(linecolor, alpha);
|
||||
color = vec4(1.f,1.f,1.f,1.f);
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
#version 330
|
||||
layout (location = 0) in vec2 pos;
|
||||
|
||||
layout (std140) uniform Projection {
|
||||
mat4 projection;
|
||||
};
|
||||
uniform mat4 proj;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * vec4(pos, 0.f, 1.f);
|
||||
gl_Position = proj * vec4(pos, 0.f, 1.f);
|
||||
}
|
8
source/shaders/shadowfrag.glsl
Normal file
8
source/shaders/shadowfrag.glsl
Normal file
|
@ -0,0 +1,8 @@
|
|||
#version 330 core
|
||||
out float frag_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
// frag_color = encode_depth(gl_FragCoord.z);
|
||||
frag_color = gl_FragCoord.z;
|
||||
}
|
|
@ -8,11 +8,8 @@ uniform sampler2D text;
|
|||
|
||||
void main()
|
||||
{
|
||||
|
||||
// color = vec4(fColor.xyz, texture(text, TexCoords).r);
|
||||
color = vec4(1.f,1.f,1.f, texture(text, TexCoords).r);
|
||||
color = vec4(fColor.xyz, texture(text, TexCoords).r);
|
||||
// color = vec4(1.f, 1.f, 1.f, texture(text, TexCoords).r);
|
||||
if (color.a <= 0.1f)
|
||||
discard;
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue