mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-06-05 04:39:37 +00:00
Adding prefabs id
This commit is contained in:
@@ -90,7 +90,6 @@ int engine_use_sfml(gc_engine *engine, const char *title, int framerate);
|
||||
|
||||
gc_vector2 engine_get_cursor_pos(gc_engine *engine);
|
||||
|
||||
#define GETSYS(x) ((struct x *)engine->get_system(engine, #x))
|
||||
#define GETSYS(engine, x) ((struct x *)engine->get_system(engine, #x))
|
||||
|
||||
#endif
|
||||
@@ -16,6 +16,7 @@ typedef struct gc_entity gc_entity;
|
||||
struct gc_entity
|
||||
{
|
||||
int id;
|
||||
int prefab_id;
|
||||
gc_component *components;
|
||||
gc_entity *(*add_component)(gc_entity *entity, void *component);
|
||||
void *(*get_component)(const gc_entity *entity, const char *name);
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ struct gc_scene
|
||||
int (*add_entity)(gc_scene *scene, gc_entity *entity);
|
||||
gc_entity *(*get_entity)(gc_scene *scene, int id);
|
||||
gc_list *(*get_entity_by_cmp)(gc_scene *scene, const char *cmp_name);
|
||||
void (*load_entity)(gc_scene *this, gc_engine *engine, node *xml);
|
||||
void (*load_entity)(gc_scene *this, gc_engine *engine, node *xml, int pref);
|
||||
|
||||
gc_list *callbacks;
|
||||
callback_t (*get_callback)(gc_scene *this, char *name);
|
||||
@@ -39,4 +39,4 @@ void scene_load_data(gc_engine *engine, gc_scene *scene, node *n);
|
||||
void *scene_get_data(gc_scene *scene, const char *type, const char *name);
|
||||
void scene_add_callback(gc_scene *scene, const char *name, void *func);
|
||||
void scene_destroy(gc_scene *scene);
|
||||
void scene_load_entity(gc_scene *this, gc_engine *engine, node *n);
|
||||
void scene_load_entity(gc_scene *this, gc_engine *engine, node *n, int prefab);
|
||||
@@ -131,5 +131,5 @@ bool map_manage_click(gc_engine *engine, int id, gc_vector2 pos)
|
||||
ret->corners[3]->z += 10;
|
||||
ret->texture = engine->scene->get_data(scene, "sprite", "command_block");
|
||||
}
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
@@ -9,10 +9,7 @@
|
||||
#include "engine.h"
|
||||
#include "entity.h"
|
||||
#include "prefab.h"
|
||||
#include "read_line.h"
|
||||
#include "utility.h"
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int prefab_load(gc_engine *engine, const char *path)
|
||||
{
|
||||
@@ -30,20 +27,23 @@ int prefab_load(gc_engine *engine, const char *path)
|
||||
int prefab_loadentities(node *n, gc_engine *engine, gc_scene *scene)
|
||||
{
|
||||
gc_entity *entity;
|
||||
static int prefab_id = 0;
|
||||
|
||||
n = xml_getnode(n, "gc_entities");
|
||||
if (!n)
|
||||
return (-1);
|
||||
for (node *ent_n = n->child; ent_n; ent_n = ent_n->next) {
|
||||
if (my_strcmp(ent_n->name, "gc_entity")) {
|
||||
scene->load_entity(scene, engine, ent_n);
|
||||
scene->load_entity(scene, engine, ent_n, prefab_id);
|
||||
continue;
|
||||
}
|
||||
entity = deserialize_entity(engine, scene, ent_n);
|
||||
if (!entity)
|
||||
return (-1);
|
||||
entity->prefab_id = prefab_id;
|
||||
scene->add_entity(scene, entity);
|
||||
}
|
||||
prefab_id++;
|
||||
if (engine->on_resize && engine->get_screen_size && engine->scene)
|
||||
engine->on_resize(engine, engine->get_screen_size(engine));
|
||||
return (0);
|
||||
|
||||
@@ -77,6 +77,8 @@ int change_scene(gc_engine *engine, gc_scene *scene)
|
||||
|
||||
callback_t scene_get_callback(gc_scene *this, char *name)
|
||||
{
|
||||
if (!name)
|
||||
return (NULL);
|
||||
for (gc_list *cal = this->callbacks; cal; cal = cal->next) {
|
||||
if (!my_strcmp(((gc_data *)cal->data)->name, name))
|
||||
return (((gc_data *)cal->data)->custom);
|
||||
|
||||
@@ -38,7 +38,7 @@ void scene_load_data(gc_engine *engine, gc_scene *scene, node *n)
|
||||
}
|
||||
}
|
||||
|
||||
void scene_load_entity(gc_scene *this, gc_engine *engine, node *n)
|
||||
void scene_load_entity(gc_scene *this, gc_engine *engine, node *n, int prefab)
|
||||
{
|
||||
gc_dataloader *loader = engine->get_dataloader(engine, n->name);
|
||||
gc_data *data;
|
||||
@@ -48,6 +48,8 @@ void scene_load_entity(gc_scene *this, gc_engine *engine, node *n)
|
||||
return;
|
||||
}
|
||||
data = loader->load(engine, this, n);
|
||||
for (gc_list *li = (gc_list *)data->custom; li; li = li->next)
|
||||
for (gc_list *li = (gc_list *)data->custom; li; li = li->next) {
|
||||
((gc_entity *)li->data)->prefab_id = prefab;
|
||||
this->add_entity(this, li->data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user