# HG changeset patch # User John Tsiombikas # Date 1326609139 -7200 # Node ID c15992cedec97d286f07903ef18173807c3cac48 # Parent 38489ad82bf427faeeffab2c18be0b3c2468e386 scene diff -r 38489ad82bf4 -r c15992cedec9 src/scene.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/scene.c Sun Jan 15 08:32:19 2012 +0200 @@ -0,0 +1,88 @@ +#include +#include +#include "scene.h" +#include "dynarr.h" + +struct scenefile { + struct mesh **mesh; +}; + +int scnfile_init(struct scenefile *scn) +{ + if(!(scn->mesh = dynarr_alloc(0, sizeof *scn->mesh))) { + return -1; + } + return 0; +} + +void scnfile_destroy(struct scenefile *scn) +{ + int i, num_meshes = scnfile_count(scn); + + for(i=0; imesh[i]); + free(scn->mesh[i]); + } + dynarr_free(scn->mesh); +} + +struct scenefile *scnfile_create(void) +{ + struct scenefile *scn; + + if(!(scn = malloc(sizeof *scn))) { + return 0; + } + if(scnfile_init(scn) == -1) { + free(scn); + return 0; + } + return scn; +} + +void scnfile_free(struct scenefile *scn) +{ + scnfile_destroy(scn); + free(scn); +} + + +int scnfile_add_mesh(struct scenefile *scn, struct mesh *m) +{ + void *tmp; + if(!(tmp = dynarr_push(scn->mesh, m))) { + return -1; + } + scn->mesh = tmp; + return 0; +} + +int scnfile_load(struct scenefile *scn, const char *fname) +{ + return -1; /* TODO */ +} + +int scnfile_find_mesh(struct scenefile *scn, const char *fname) +{ + int i, num = scnfile_count(scn); + + for(i=0; imesh[i]), fname) == 0) { + return i; + } + } + return -1; +} + +struct mesh *scnfile_mesh(struct scenefile *scn, int idx) +{ + if(idx < 0 || idx >= scnfile_count(scn)) { + return 0; + } + return scn->mesh[idx]; +} + +int scnfile_count(struct scenefile *scn) +{ + return dynarr_size(scn->mesh); +} diff -r 38489ad82bf4 -r c15992cedec9 src/scene.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/scene.h Sun Jan 15 08:32:19 2012 +0200 @@ -0,0 +1,32 @@ +#ifndef SCENE_H_ +#define SCENE_H_ + +#include "mesh.h" + +struct scenefile; + +#ifdef __cplusplus +extern "C" { +#endif + +int scnfile_init(struct scenefile *scn); +void scnfile_destroy(struct scenefile *scn); + +struct scenefile *scnfile_create(void); +void scnfile_free(struct scenefile *scn); + + +int scnfile_add_mesh(struct scenefile *scn, struct mesh *mesh); + + +int scnfile_load(struct scenefile *scn, const char *fname); + +int scnfile_find_mesh(struct scenefile *scn, const char *fname); +struct mesh *scnfile_mesh(struct scenefile *scn, int idx); +int scnfile_count(struct scenefile *scn); + +#ifdef __cplusplus +} +#endif + +#endif /* SCENE_H_ */