spline fixes

This commit is contained in:
2023-12-20 23:20:29 +00:00
parent a8ee53ec33
commit a03143463e
20 changed files with 134 additions and 118 deletions

View File

@@ -20,6 +20,7 @@
#define CGLTF_IMPLEMENTATION
#include <cgltf.h>
#include <stdlib.h>
#include <string.h>
@@ -32,6 +33,8 @@ static struct {
struct model *value;
} *modelhash = NULL;
struct drawmodel **models = NULL;
static void processnode();
static void processmesh();
static void processtexture();
@@ -116,6 +119,8 @@ unsigned short pack_short_texcoord(float x, float y)
return (((unsigned short)yc) << 8) | xc;
}
unsigned short pack_short_tex(float c) { return c * USHRT_MAX; }
uint32_t pack_int10_n2(float *norm)
{
uint32_t ni[3];
@@ -144,7 +149,7 @@ void mesh_add_material(mesh *mesh, cgltf_material *mat)
free(imp);
}
} else
mesh->bind.fs.images[0] = texture_pullfromfile("k")->id;
mesh->bind.fs.images[0] = texture_pullfromfile("k")->id;
mesh->bind.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){});
/*
@@ -157,9 +162,10 @@ void mesh_add_material(mesh *mesh, cgltf_material *mat)
sg_buffer texcoord_floats(float *f, int verts, int comp)
{
unsigned short packed[verts];
for (int i = 0, v = 0; v < verts; i+=comp, v++)
packed[v] = pack_short_texcoord(f[i], f[i+1]);
int n = verts*comp;
unsigned short packed[n];
for (int i = 0, v = 0; i < n; i++)
packed[i] = pack_short_tex(f[i]);
return sg_make_buffer(&(sg_buffer_desc){
.data.ptr = packed,
@@ -390,9 +396,16 @@ struct drawmodel *make_drawmodel(gameobject *go)
dm->model = NULL;
dm->amodel = HMM_M4D(1.f);
dm->go = go;
arrpush(models,dm);
return dm;
}
void model_draw_all()
{
for (int i = 0; i < arrlen(models); i++)
draw_drawmodel(models[i]);
}
void draw_drawmodel(struct drawmodel *dm)
{
if (!dm->model) return;
@@ -401,5 +414,15 @@ void draw_drawmodel(struct drawmodel *dm)
draw_model(dm->model, rst);
}
void free_drawmodel(struct drawmodel *dm) { free(dm); }
void free_drawmodel(struct drawmodel *dm) {
int rm;
for (int i = 0; i < arrlen(models); i++)
if (models[i] == dm) {
rm = i;
break;
}
arrdelswap(models,rm);
free(dm);
}

View File

@@ -53,6 +53,7 @@ void model_init();
struct drawmodel *make_drawmodel(gameobject *go);
void draw_drawmodel(struct drawmodel *dm);
void model_draw_all();
void free_drawmodel(struct drawmodel *dm);
#endif

View File

@@ -62,7 +62,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
char *buffer = malloc(len);
sprintf(buffer, logfmt, file, line, logstr[priority], catstr[category], msg);
fprintf(stderr, buffer);
fprintf(stderr, "%s", buffer);
fflush(stderr);
free(msg);

View File

@@ -303,7 +303,7 @@ struct boundingbox text_bb(const unsigned char *text, float scale, float lw, flo
while (!isspace(*line) && *line != '\0') {
wordWidth += font->Characters[*line].Advance * tracking * scale;
line++;
line++;
}
if (lw > 0 && (cursor.X + wordWidth) >= lw) {

View File

@@ -25,7 +25,7 @@ struct sFont {
int descent;
int linegap;
float emscale;
struct Character Characters[127];
struct Character Characters[255];
sg_image texID;
};

View File

@@ -10,6 +10,8 @@
static gameobject **gameobjects;
int go_count() { return arrlen(gameobjects); }
gameobject *body2go(cpBody *body) { return cpBodyGetUserData(body); }
gameobject *shape2go(cpShape *shape) { return ((struct phys2d_shape *)cpShapeGetUserData(shape))->go; }

View File

@@ -53,6 +53,7 @@ struct gameobject {
typedef struct gameobject gameobject;
gameobject *MakeGameobject();
int go_count();
void gameobject_apply(gameobject *go);
void gameobject_free(gameobject *go);
void gameobjects_cleanup();

View File

@@ -1120,7 +1120,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 143:
str = JS_ToCString(js, argv[1]);
// system(str);
system(str);
break;
case 144:
@@ -1349,6 +1349,12 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 212:
ret = jsdst();
break;
case 213:
free_drawmodel(js2ptr(argv[1]));
break;
case 214:
ret = int2js(go_count());
break;
}
if (str)

View File

@@ -509,6 +509,7 @@ void full_2d_pass(struct window *window)
hudproj = HMM_Orthographic_LH_ZO(0, window->rwidth, 0, window->rheight, -1.f, 1.f);
sprite_draw_all();
model_draw_all();
call_draw();
//// DEBUG

View File

@@ -249,7 +249,7 @@ char *slurp_text(const char *filename, size_t *size)
int cp(char *p1, char *p2)
{
long len;
size_t len;
void *data = slurp_file(p1, &len);
FILE *f = fopen_mkdir(p2, "w");

View File

@@ -72,6 +72,7 @@ void script_startup() {
void script_stop()
{
timers_free();
script_evalf("Event.notify('quit');");
send_signal("quit",0,NULL);
for (int i = 0; i < shlen(jsstrs); i++)

View File

@@ -79,12 +79,9 @@ static int sim_play = SIM_PLAY;
int editor_mode = 0;
const char *engine_info()
{
static char str[100];
snprintf(str, 100, "Yugine version %s, %s build.\nCopyright 2022-2023 odplot productions LLC.\n", VER, INFO);
return str;
}
#define ENGINEINFO "Yugine version " VER ", " INFO " build.\nCopyright 2022-2024."
const char *engine_info() { return ENGINEINFO; }
static int argc;
static char **args;

View File

@@ -39,14 +39,6 @@ in float radius;
void main()
{
if (segsize<0)
return;
float f = atan(coords.y, coords.x) + PI;
if (mod(f, segsize) < segsize/2)
discard;
float px = 1/radius;
float R1 = 1.f;
float R2 = 1.0 - fill;
@@ -57,6 +49,14 @@ void main()
float sm2 = smoothstep(R2-px,R2,dist);
float a = sm*sm2;
color = mix(vec4(0,0,0,0), fcolor, a);
if (segsize<0)
return;
float f = atan(coords.y, coords.x) + PI;
if (mod(f, segsize) < segsize/2)
discard;
}
@end