scenefile
changeset 2:c15992cedec9
scene
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Sun, 15 Jan 2012 08:32:19 +0200 |
parents | 38489ad82bf4 |
children | b30f83409769 |
files | src/scene.c src/scene.h |
diffstat | 2 files changed, 120 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/scene.c Sun Jan 15 08:32:19 2012 +0200 1.3 @@ -0,0 +1,88 @@ 1.4 +#include <stdlib.h> 1.5 +#include <string.h> 1.6 +#include "scene.h" 1.7 +#include "dynarr.h" 1.8 + 1.9 +struct scenefile { 1.10 + struct mesh **mesh; 1.11 +}; 1.12 + 1.13 +int scnfile_init(struct scenefile *scn) 1.14 +{ 1.15 + if(!(scn->mesh = dynarr_alloc(0, sizeof *scn->mesh))) { 1.16 + return -1; 1.17 + } 1.18 + return 0; 1.19 +} 1.20 + 1.21 +void scnfile_destroy(struct scenefile *scn) 1.22 +{ 1.23 + int i, num_meshes = scnfile_count(scn); 1.24 + 1.25 + for(i=0; i<num_meshes; i++) { 1.26 + mesh_destroy(scn->mesh[i]); 1.27 + free(scn->mesh[i]); 1.28 + } 1.29 + dynarr_free(scn->mesh); 1.30 +} 1.31 + 1.32 +struct scenefile *scnfile_create(void) 1.33 +{ 1.34 + struct scenefile *scn; 1.35 + 1.36 + if(!(scn = malloc(sizeof *scn))) { 1.37 + return 0; 1.38 + } 1.39 + if(scnfile_init(scn) == -1) { 1.40 + free(scn); 1.41 + return 0; 1.42 + } 1.43 + return scn; 1.44 +} 1.45 + 1.46 +void scnfile_free(struct scenefile *scn) 1.47 +{ 1.48 + scnfile_destroy(scn); 1.49 + free(scn); 1.50 +} 1.51 + 1.52 + 1.53 +int scnfile_add_mesh(struct scenefile *scn, struct mesh *m) 1.54 +{ 1.55 + void *tmp; 1.56 + if(!(tmp = dynarr_push(scn->mesh, m))) { 1.57 + return -1; 1.58 + } 1.59 + scn->mesh = tmp; 1.60 + return 0; 1.61 +} 1.62 + 1.63 +int scnfile_load(struct scenefile *scn, const char *fname) 1.64 +{ 1.65 + return -1; /* TODO */ 1.66 +} 1.67 + 1.68 +int scnfile_find_mesh(struct scenefile *scn, const char *fname) 1.69 +{ 1.70 + int i, num = scnfile_count(scn); 1.71 + 1.72 + for(i=0; i<num; i++) { 1.73 + if(strcmp(mesh_get_name(scn->mesh[i]), fname) == 0) { 1.74 + return i; 1.75 + } 1.76 + } 1.77 + return -1; 1.78 +} 1.79 + 1.80 +struct mesh *scnfile_mesh(struct scenefile *scn, int idx) 1.81 +{ 1.82 + if(idx < 0 || idx >= scnfile_count(scn)) { 1.83 + return 0; 1.84 + } 1.85 + return scn->mesh[idx]; 1.86 +} 1.87 + 1.88 +int scnfile_count(struct scenefile *scn) 1.89 +{ 1.90 + return dynarr_size(scn->mesh); 1.91 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/src/scene.h Sun Jan 15 08:32:19 2012 +0200 2.3 @@ -0,0 +1,32 @@ 2.4 +#ifndef SCENE_H_ 2.5 +#define SCENE_H_ 2.6 + 2.7 +#include "mesh.h" 2.8 + 2.9 +struct scenefile; 2.10 + 2.11 +#ifdef __cplusplus 2.12 +extern "C" { 2.13 +#endif 2.14 + 2.15 +int scnfile_init(struct scenefile *scn); 2.16 +void scnfile_destroy(struct scenefile *scn); 2.17 + 2.18 +struct scenefile *scnfile_create(void); 2.19 +void scnfile_free(struct scenefile *scn); 2.20 + 2.21 + 2.22 +int scnfile_add_mesh(struct scenefile *scn, struct mesh *mesh); 2.23 + 2.24 + 2.25 +int scnfile_load(struct scenefile *scn, const char *fname); 2.26 + 2.27 +int scnfile_find_mesh(struct scenefile *scn, const char *fname); 2.28 +struct mesh *scnfile_mesh(struct scenefile *scn, int idx); 2.29 +int scnfile_count(struct scenefile *scn); 2.30 + 2.31 +#ifdef __cplusplus 2.32 +} 2.33 +#endif 2.34 + 2.35 +#endif /* SCENE_H_ */