Moving position to a component

This commit is contained in:
Tristan Roux
2019-12-02 15:25:09 +01:00
parent 116c372236
commit 56ce78f850
9 changed files with 76 additions and 12 deletions
+4 -1
View File
@@ -17,6 +17,9 @@ typedef struct gc_component
void (*ctr)(void *component, va_list);
void (*dtr)(void *component);
char *(*serialize)(void *component);
// privates:
struct gc_component *next;
struct gc_component *prev;
char *tostr;
} gc_component;
@@ -9,7 +9,7 @@
#include "component.h"
struct MovableComponent
struct movable_component
{
gc_component *base;
int left_key;
+17
View File
@@ -0,0 +1,17 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** position_component
*/
#pragma once
#include "component.h"
#include "vector2.h"
struct position_component
{
gc_component *base;
vector2 position;
};
+1 -1
View File
@@ -15,7 +15,7 @@ typedef struct gc_entity
{
int id;
char *str;
gc_component *components;
gc_component components;
void (*serialize)();
struct gc_entity *next;
+1
View File
@@ -11,6 +11,7 @@
typedef struct gc_system
{
char *name;
unsigned size;
void *(check_dependencies)(const gc_entity *entity);
void *(update_entity)(const gc_entity *entity);
+9
View File
@@ -0,0 +1,9 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** utility
*/
#pragma once
+3 -1
View File
@@ -11,9 +11,11 @@
void *new_component(void *component, ...)
{
gc_component *base = (gc_component *)component;
void *new_cmp = malloc(base->size);
va_list args;
void *new_cmp = malloc(base->size);
if (!new_cmp)
return (NULL);
*(gc_component *)new_cmp = *base;
if (((gc_component *)new_cmp)->ctr) {
va_start(args, component);
+8 -8
View File
@@ -6,16 +6,16 @@
*/
#include "component.h"
#include "Components/movable_component.h"
#include "components/movable_component.h"
#include <stdlib.h>
static void movable_ctr(void *component, va_list args)
{
struct MovableComponent *movable = (struct MovableComponent *)component;
struct movable_component *cmp = (struct movable_component *)component;
movable->left_key = va_arg(args, int);
movable->right_key = va_arg(args, int);
movable->jump_key = va_arg(args, int);
cmp->left_key = va_arg(args, int);
cmp->right_key = va_arg(args, int);
cmp->jump_key = va_arg(args, int);
}
static void movable_dtr(void *component)
@@ -33,9 +33,9 @@ static char *movable_serialize(void *component)
return (NULL);
}
const gc_component MovableComponent = {
name: "PositionComponent",
size: sizeof(MovableComponent),
const gc_component movable_component = {
name: "MovableComponent",
size: sizeof(struct movable_component),
dependencies: NULL,
ctr: &movable_ctr,
dtr: &movable_dtr,
+32
View File
@@ -0,0 +1,32 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** position_component
*/
#include "component.h"
#include "components/position_component.h"
#include <stddef.h>
void position_ctr(void *component, va_list args)
{
struct position_component *cmp = (struct position_component *)component;
cmp->position = va_arg(args, vector2);
}
char *position_serialize(void *component)
{
return (NULL);
}
const gc_component position_component = {
name: "PositionComponent",
size: sizeof(struct position_component),
dependencies: NULL,
ctr: &position_ctr,
dtr: NULL,
serialize: &position_serialize,
tostr: NULL
};