Replaced vec.h with stb_ds.h arrays
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
#include "level.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "vec.h"
|
||||
#include "gameobject.h"
|
||||
#include "resources.h"
|
||||
|
||||
#include "stb_ds.h"
|
||||
|
||||
void save_level(char name[MAXNAME])
|
||||
{
|
||||
FILE *lfile = res_open(name, "wb+");
|
||||
@@ -12,41 +13,44 @@ void save_level(char name[MAXNAME])
|
||||
if (!lfile) return;
|
||||
|
||||
|
||||
int objs = gameobjects->len;
|
||||
int objs = arrlen(gameobjects);
|
||||
fwrite(&objs, sizeof(objs), 1, lfile);
|
||||
|
||||
for (int i = 0; i < objs; i++) {
|
||||
gameobject_save(vec_get(gameobjects, i), lfile);
|
||||
}
|
||||
for (int i = 0; i < objs; i++)
|
||||
gameobject_save(&gameobjects[i], lfile);
|
||||
|
||||
fclose(lfile);
|
||||
}
|
||||
|
||||
void load_level(char name[MAXNAME])
|
||||
{
|
||||
|
||||
|
||||
FILE *lfile = fopen(name, "rb");
|
||||
|
||||
if (!lfile) return;
|
||||
|
||||
new_level();
|
||||
|
||||
int objs;
|
||||
fread(&objs, sizeof(objs), 1, lfile);
|
||||
|
||||
vec_clear(gameobjects);
|
||||
|
||||
arraddn(gameobjects, objs);
|
||||
|
||||
for (int i = 0; i < objs; i++) {
|
||||
struct mGameObject *go = vec_add(gameobjects, NULL);
|
||||
struct mGameObject *go = &gameobjects[i];
|
||||
fread(go, sizeof(struct mGameObject), 1, lfile);
|
||||
go->components = vec_make(1,1);
|
||||
go->components = NULL;
|
||||
gameobject_init(go, lfile);
|
||||
}
|
||||
|
||||
fclose(lfile);
|
||||
|
||||
}
|
||||
|
||||
void new_level()
|
||||
{
|
||||
vec_clear(gameobjects);
|
||||
for (int i = 0; i < arrlen(gameobjects); i++)
|
||||
gameobject_delete(i);
|
||||
|
||||
arrfree(gameobjects);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user