mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-05-31 19:00:40 +00:00
The deserializer now works with multiple entities in the same prefab
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ struct gc_engine
|
||||
void (*draw)(gc_engine *engine);
|
||||
};
|
||||
|
||||
gc_engine *engine_create(char *title);
|
||||
gc_engine *engine_create(char *title, unsigned framerate);
|
||||
bool engine_is_open(gc_engine *engine);
|
||||
void handle_events(gc_engine *engine);
|
||||
int change_scene(gc_engine *engine, gc_scene *scene);
|
||||
|
||||
@@ -29,5 +29,6 @@ struct gc_entity
|
||||
|
||||
gc_entity *entity_create(void);
|
||||
gc_entity *entity_create_with_id(int id);
|
||||
gc_entity *entity_add(gc_entity *list, gc_entity *entity);
|
||||
gc_entity *entity_add_component(gc_entity *entity, void *component);
|
||||
char *entity_serialize(gc_entity *entity, int fd);
|
||||
@@ -8,17 +8,23 @@
|
||||
#include "engine.h"
|
||||
#include "entity.h"
|
||||
#include "prefab.h"
|
||||
#include "read_line.h"
|
||||
#include "utility.h"
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
gc_entity *prefab_load(gc_engine *engine, const char *path)
|
||||
{
|
||||
gc_entity *entity;
|
||||
gc_entity *entity = NULL;
|
||||
int fd = open(path, O_RDONLY);
|
||||
char *object_type = NULL;
|
||||
|
||||
if (fd == -1)
|
||||
return (NULL);
|
||||
entity = deserialize_entity(engine, fd);
|
||||
while ((object_type = read_line(fd))) {
|
||||
if (!my_strcmp(object_type, "Entity"))
|
||||
entity = entity_add(entity, deserialize_entity(engine, fd));
|
||||
}
|
||||
close(fd);
|
||||
return (entity);
|
||||
}
|
||||
|
||||
+15
-4
@@ -46,18 +46,29 @@ void engine_destroy(gc_engine *engine)
|
||||
free(engine);
|
||||
}
|
||||
|
||||
gc_engine *engine_create(char *title)
|
||||
int engine_create_sfdata(gc_engine *engine, char *title, unsigned framerate)
|
||||
{
|
||||
gc_engine *engine = malloc(sizeof(gc_engine));
|
||||
sfVideoMode mode = {800, 600, 32};
|
||||
sfWindowStyle style = sfDefaultStyle;
|
||||
|
||||
if (!engine)
|
||||
return (NULL);
|
||||
engine->window = sfRenderWindow_create(mode, title, style, NULL);
|
||||
engine->sprite = sfSprite_create();
|
||||
if (!engine->window || !engine->sprite)
|
||||
return (-1);
|
||||
sfRenderWindow_setFramerateLimit(engine->window, framerate);
|
||||
return (0);
|
||||
}
|
||||
|
||||
gc_engine *engine_create(char *title, unsigned framerate)
|
||||
{
|
||||
gc_engine *engine = malloc(sizeof(gc_engine));
|
||||
|
||||
if (!engine)
|
||||
return (NULL);
|
||||
if (engine_create_sfdata(engine, title, framerate) < 0) {
|
||||
free(engine);
|
||||
return (NULL);
|
||||
}
|
||||
engine->is_open = &engine_is_open;
|
||||
engine->game_loop = &game_loop;
|
||||
engine->change_scene = &change_scene;
|
||||
|
||||
@@ -35,6 +35,21 @@ gc_entity *entity_create_with_id(int id)
|
||||
return (entity);
|
||||
}
|
||||
|
||||
gc_entity *entity_add(gc_entity *list, gc_entity *entity)
|
||||
{
|
||||
gc_entity *list_const = list;
|
||||
|
||||
if (!list) {
|
||||
return (entity);
|
||||
} else {
|
||||
while (list->next)
|
||||
list = list->next;
|
||||
list->next = entity;
|
||||
entity->prev = list;
|
||||
return (list_const);
|
||||
}
|
||||
}
|
||||
|
||||
gc_entity *entity_add_component(gc_entity *entity, void *component)
|
||||
{
|
||||
gc_component *components = entity->components;
|
||||
|
||||
+2
-12
@@ -13,20 +13,10 @@
|
||||
|
||||
int scene_add_entity(gc_scene *scene, gc_entity *entity)
|
||||
{
|
||||
gc_entity *list;
|
||||
|
||||
if (!scene || !entity)
|
||||
return (-1);
|
||||
list = scene->entities;
|
||||
if (!list) {
|
||||
scene->entities = entity;
|
||||
} else {
|
||||
while (list->next)
|
||||
list = list->next;
|
||||
list->next = entity;
|
||||
entity->prev = list;
|
||||
}
|
||||
return (1);
|
||||
scene->entities = entity_add(scene->entities, entity);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int scene_load_textures(gc_scene *scene, const char **textures)
|
||||
|
||||
Reference in New Issue
Block a user