Use YughLog instead of printf; add sprites on load

This commit is contained in:
John Alanbrook 2022-11-18 18:03:07 +00:00
parent 5386e19e17
commit 3641c246d4
14 changed files with 30 additions and 27 deletions

View file

@ -61,7 +61,6 @@ struct phys2d_circle *Make2DCircle(struct mGameObject *go)
void phys2d_circleinit(struct phys2d_circle *circle, struct mGameObject *go)
{
printf("Initing a circle\n");
circle->shape.shape = cpSpaceAddShape(space, cpCircleShapeNew(go->body, circle->radius, cpvzero));
init_phys2dshape(&circle->shape, go);
}

View file

@ -87,7 +87,7 @@ struct wav gen_sine(float amp, float freq, int sr, int ch)
}
}
printf("Made sine with %i frames.\n", new.frames);
YughInfo("Made sine with %i frames.", new.frames);
return new;
}
@ -318,7 +318,7 @@ struct dsp_filter lpf_make(int poles, float freq)
double sf = sf_bwlp(poles, fcf);
printf("Making LPF filter, fcf: %f, coeffs: %i, scale %1.15lf\n", fcf, new->n, sf);
YughInfo("Making LPF filter, fcf: %f, coeffs: %i, scale %1.15lf", fcf, new->n, sf);
int *ccof = ccof_bwlp(new->n);
new->dcof = dcof_bwlp(new->n, fcf);
@ -388,7 +388,6 @@ void dsp_fir_fillbuf(struct dsp_fir *fir, short *out, int n)
for (int i = 0; i < n; i++) {
short val = fir_filter(fir, out[i*CHANNELS]);
// printf("%hd\n", val);
for (int j = 0; j < CHANNELS; j++)
out[i*CHANNELS + j] = val*5;
@ -429,7 +428,7 @@ struct dsp_delay dsp_delay_make(unsigned int ms_delay)
new.buf = circbuf_init(sizeof(short), datasize);
new.buf.write = datasize;
printf("Buffer size is %u.\n", new.buf.len);
YughInfo("Buffer size is %u.", new.buf.len);
return new;
}

View file

@ -56,7 +56,7 @@ const char *allowed_extensions[] = {"jpg", "png", "rb", "wav", "mp3", };
void text_ed_cb(GLFWwindow *win, unsigned int codepoint);
void asset_srch_cb(GLFWwindow *win, unsigned int codepoint)
{
printf("Pushed %d.\n", codepoint);
YughInfo("Pushed %d.", codepoint);
}
static const char *editor_filename = "editor.ini";
@ -913,10 +913,10 @@ void editor_asset_tex_gui(struct Texture *tex) {
void text_ed_cb(GLFWwindow *win, unsigned int codepoint)
{
printf("Pressed button %d\n", codepoint);
YughInfo("Pressed button %d", codepoint);
if (editor.text_ed & NK_EDIT_ACTIVE) {
if (codepoint == '\n') {
printf("Hit newline.\n");
YughInfo("Hit newline.");
}
}
}
@ -992,7 +992,7 @@ void get_levels() { fill_extensions(levels, DATA_PATH, EXT_LEVEL); }
void editor_prefab_btn(char *prefab) {
if (nk_button_label(ctx, prefab)) {
printf("making prefab\n");
YughInfo("Making prefab '%s'.", prefab);
gameobject_makefromprefab(prefab);
/*GameObject* newprefab = (GameObject*)createPrefab(*prefab); */
/*cam_inverse_goto(&camera, &newprefab->transform); */

View file

@ -6,7 +6,7 @@ void (*asset_command)(char *asset) = print_file;
void print_file(char *file)
{
printf("File path: %s\n", file);
YughInfo("File path: %s", file);
}
void set_new_model(char *modelPath)

View file

@ -44,6 +44,7 @@
void error_callback(int error, const char *description)
{
fprintf(stderr, "Error: %s\n", description);
YughError("GLFW Error: %s", description);
}
void engine_init()

View file

@ -8,6 +8,7 @@
#include <limits.h>
#include <stdlib.h>
#include <window.h>
#include "log.h"
#include <stb_truetype.h>
@ -62,7 +63,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
stbtt_fontinfo fontinfo;
if (!stbtt_InitFont(&fontinfo, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0))) {
printf("failed\n");
YughError("Failed to make font %s", fontfile);
}
float scale = stbtt_ScaleForPixelHeight(&fontinfo, height);

View file

@ -10,6 +10,7 @@
#include <chipmunk/chipmunk.h>
#include "resources.h"
#include "nuke.h"
#include "log.h"
#include "stb_ds.h"
@ -36,7 +37,7 @@ static void gameobject_setpickcolor(struct mGameObject *go)
struct mGameObject *MakeGameobject()
{
printf("Making gameobject\n");
YughInfo("Making new gameobject");
struct mGameObject go = {
.editor.id = arrlen(gameobjects),
.transform.scale = 1.f,
@ -96,7 +97,7 @@ void gameobject_save(struct mGameObject *go, FILE * file)
{
fwrite(go, sizeof(*go), 1, file);
printf("Number of components is %d.\n", arrlen(go->components));
YughInfo("Number of components is %d.", arrlen(go->components));
int n = arrlen(go->components);
fwrite(&n, sizeof(n), 1, file);

View file

@ -8,11 +8,11 @@
#define LOG_ERROR 2
#define LOG_CRITICAL 3
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, __VA_ARGS__)
#define YughInfo(msg, ...) mYughLog(0, 0, __LINE__, __FILE__, msg, __VA_ARGS__);
#define YughWarn(msg, ...) mYughLog(0, 1, __LINE__, __FILE__, msg, __VA_ARGS__);
#define YughError(msg, ...) mYughLog(0, 2, __LINE__, __FILE__, msg, __VA_ARGS__);
#define YughCritical(msg, ...) mYughLog(0, 3, __LINE__, __FILE__, msg, __VA_ARGS__);
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, ##__VA_ARGS__)
#define YughInfo(msg, ...) mYughLog(0, 0, __LINE__, __FILE__, msg, ##__VA_ARGS__);
#define YughWarn(msg, ...) mYughLog(0, 1, __LINE__, __FILE__, msg, ##__VA_ARGS__);
#define YughError(msg, ...) mYughLog(0, 2, __LINE__, __FILE__, msg, ##__VA_ARGS__);
#define YughCritical(msg, ...) mYughLog(0, 3, __LINE__, __FILE__, msg, ##__VA_ARGS__);
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...);

View file

@ -6,6 +6,7 @@
#include <cgltf.h>
#include <string.h>
#include <stdlib.h>
#include "log.h"
static struct mModel *lastRendered;
static struct mModel *loadedModels[100];
@ -69,7 +70,7 @@ void draw_model(struct mModel *model, struct mShader *shader)
void loadmodel(struct mModel *model)
{
printf("Loading model at path %s\n", model->path);
YughInfo("Loading model at path %s", model->path);
/*
// Load model with cgltf
cgltf_options options = {0};

View file

@ -13,6 +13,7 @@
#include "window.h"
#include "editor.h"
#include "engine.h"
#include "log.h"
extern mrb_state *mrb;
@ -143,7 +144,7 @@ mrb_value mrb_sound_make(mrb_state *mrb, mrb_value self) {
mrb_value vals;
mrb_get_args(mrb, "H", &vals);
char *name = mrb_str_to_cstr(mrb, mrb_hash_fetch(mrb, vals, mrb_symbol_value(mrb_intern_cstr(mrb, "name")), mrb_str_new_cstr(mrb, "New Window")));
printf("Window name is %s.\n", name);
YughInfo("Window name is %s.", name);
return self;
}

View file

@ -11,6 +11,7 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "log.h"
#include <ftw.h>
@ -55,7 +56,7 @@ char *get_filename_from_path(char *path, int extension)
if (!extension) {
char *ext = strrchr(path, '.');
offset = end - ext;
printf("Making without extension ...\n");
YughInfo("Making %s without extension ...");
}
char *filename = malloc(sizeof(char) * (end - dirpos - offset + 1));

View file

@ -79,7 +79,7 @@ GLuint load_shader_from_file(const char *path, int type)
glShaderSource(id, 1, &code, NULL);
glCompileShader(id);
if (shader_compile_error(id)) {
printf("Error with shader %s.\n", path);
YughError("Error with shader %s.", path);
return 0;
}
@ -88,7 +88,7 @@ GLuint load_shader_from_file(const char *path, int type)
void shader_compile(struct mShader *shader)
{
printf("Making shader with %s and %s.\n", shader->vertpath, shader->fragpath);
YughInfo("Making shader with %s and %s.", shader->vertpath, shader->fragpath);
GLuint vert = load_shader_from_file(shader->vertpath, GL_VERTEX_SHADER);
GLuint frag = load_shader_from_file(shader->fragpath, GL_FRAGMENT_SHADER);

View file

@ -29,13 +29,13 @@ struct sprite *make_sprite(struct mGameObject *go)
.index = arrlen(sprites) };
sprite_init(&sprite, go);
arrput(sprites, sprite);
return &arrlast(sprites);
}
void sprite_init(struct sprite *sprite, struct mGameObject *go)
{
sprite->go = go;
arrput(sprites, *sprite);
}
void sprite_io(struct sprite *sprite, FILE *f, int read)
@ -51,8 +51,6 @@ void sprite_io(struct sprite *sprite, FILE *f, int read)
fread(sprite, sizeof(*sprite), 1, f);
sprite_loadtex(sprite, path);
} else {
// fprintf(f, "%s", tex_get_path(sprite->tex));
fputs(tex_get_path(sprite->tex), f);
fputc('\0', f);
fwrite(sprite, sizeof(*sprite), 1, f);

View file

@ -6,6 +6,7 @@
#include "openglrender.h"
#include "script.h"
#include "editor.h"
#include "log.h"
#include "string.h"
@ -35,7 +36,7 @@ int main(int argc, char **args) {
engine_init();
const GLFWvidmode *vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
printf("Refresh rate is %d\n", vidmode->refreshRate);
YughInfo("Refresh rate is %d", vidmode->refreshRate);
renderMS = 1.0/vidmode->refreshRate;