mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-06-02 03:35:43 +00:00
Making the basics of the engine
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
*.o
|
||||
libgamacon.a
|
||||
*.gc*
|
||||
@@ -0,0 +1,38 @@
|
||||
##
|
||||
## EPITECH PROJECT, 2019
|
||||
## Gamacon
|
||||
## File description:
|
||||
## Makefile
|
||||
##
|
||||
|
||||
SRC = src/engine.c \
|
||||
src/engine_internal.c \
|
||||
src/component.c \
|
||||
src/components/movable_component.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
|
||||
INCLUDE = -I ./include
|
||||
|
||||
CFLAGS = $(INCLUDE) -Wall -Wshadow -Wextra
|
||||
|
||||
NAME = libgamacon.a
|
||||
|
||||
CC = gcc
|
||||
|
||||
AR = ar rc
|
||||
|
||||
all: build
|
||||
|
||||
build: $(OBJ)
|
||||
$(AR) $(NAME) $(OBJ)
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all build clean fclean
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** movable_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct MovableComponent
|
||||
{
|
||||
Component *base;
|
||||
int left_key;
|
||||
int right_key;
|
||||
int jump_key;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef struct Component
|
||||
{
|
||||
char *name;
|
||||
unsigned size;
|
||||
struct Component *dependencies;
|
||||
void (*ctr)(void *component, va_list);
|
||||
void (*dtr)(void *component);
|
||||
char *(*serialize)(void *component);
|
||||
// privates:
|
||||
char *tostr;
|
||||
} Component;
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** engine
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "scene.h"
|
||||
#include "renderer.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct gcEngine
|
||||
{
|
||||
gcRenderer renderer;
|
||||
gcScene *scene;
|
||||
bool (*is_open)();
|
||||
int (*game_loop)(struct gcEngine *engine);
|
||||
int (*change_scene)(struct gcEngine *engine, gcScene *scene);
|
||||
} gcEngine;
|
||||
|
||||
gcEngine *create_engine(char *title);
|
||||
bool engine_is_open(gcEngine *engine);
|
||||
int change_scene(gcEngine *engine, gcScene *scene);
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** entity
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
#include "vector2.h"
|
||||
#include "tags.h"
|
||||
|
||||
typedef struct Entity
|
||||
{
|
||||
int id;
|
||||
char *str;
|
||||
tag tag;
|
||||
Component *components;
|
||||
void (*serialize)();
|
||||
Vector2 position;
|
||||
|
||||
struct Entity *next;
|
||||
struct Entity *prev;
|
||||
} Entity;
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** renderer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SFML/Graphics.h>
|
||||
|
||||
typedef struct gcRenderer
|
||||
{
|
||||
sfRenderWindow *window;
|
||||
} gcRenderer;
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** scene
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "entity.h"
|
||||
#include "texture.h"
|
||||
|
||||
typedef struct gcScene
|
||||
{
|
||||
Entity *entity_list;
|
||||
gcTexture *texture;
|
||||
} gcScene;
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** system
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
typedef struct System
|
||||
{
|
||||
unsigned size;
|
||||
void *(check_dependencies)(const Entity *entity);
|
||||
void *(update_entity)(const Entity *entity);
|
||||
} System;
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** tag
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum tag
|
||||
{
|
||||
none = 0
|
||||
} tag;
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** texture
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SFML/Graphics.h>
|
||||
|
||||
typedef struct gcTexture
|
||||
{
|
||||
char *name;
|
||||
sfTexture *texture;
|
||||
} gcTexture;
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** vector2
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct Vector2
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} Vector2;
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** component
|
||||
*/
|
||||
|
||||
#include "component.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void *new_component(Component *component, ...)
|
||||
{
|
||||
void *new_cmp = malloc(component->size);
|
||||
va_list args;
|
||||
|
||||
*(Component *)new_cmp = *component;
|
||||
if (((Component *)new_cmp)->ctr) {
|
||||
va_start(args, component);
|
||||
((Component *)new_cmp)->ctr(new_cmp, args);
|
||||
va_end(args);
|
||||
}
|
||||
return (new_cmp);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** movable_component
|
||||
*/
|
||||
|
||||
#include "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;
|
||||
|
||||
movable->left_key = va_arg(args, int);
|
||||
movable->right_key = va_arg(args, int);
|
||||
movable->jump_key = va_arg(args, int);
|
||||
}
|
||||
|
||||
static void movable_dtr(void *component)
|
||||
{
|
||||
Component *base = (Component *)component;
|
||||
|
||||
if (base->tostr)
|
||||
free(base->tostr);
|
||||
}
|
||||
|
||||
static char *movable_serialize(void *component)
|
||||
{
|
||||
//Component *base = (Component *)component;
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const Component MovableComponent = {
|
||||
name: "PositionComponent",
|
||||
size: sizeof(MovableComponent),
|
||||
dependencies: NULL,
|
||||
ctr: &movable_ctr,
|
||||
dtr: &movable_dtr,
|
||||
serialize: &movable_serialize,
|
||||
tostr: NULL
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** engine
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include <stdlib.h>
|
||||
#include <SFML/Graphics.h>
|
||||
|
||||
int game_loop(gcEngine *engine)
|
||||
{
|
||||
(void)engine;
|
||||
return (0);
|
||||
}
|
||||
|
||||
gcEngine *create_engine(char *title)
|
||||
{
|
||||
gcEngine *engine = malloc(sizeof(gcEngine));
|
||||
sfVideoMode mode = {800, 600, 32};
|
||||
sfWindowStyle style = sfDefaultStyle;
|
||||
|
||||
engine->renderer.window = sfRenderWindow_create(mode, title, style, NULL);
|
||||
engine->is_open = &engine_is_open;
|
||||
engine->game_loop = &game_loop;
|
||||
engine->change_scene = &change_scene;
|
||||
return (engine);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** engine_internal
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "engine.h"
|
||||
|
||||
bool engine_is_open(gcEngine *engine)
|
||||
{
|
||||
return (sfRenderWindow_isOpen(engine->renderer.window));
|
||||
}
|
||||
|
||||
int change_scene(gcEngine *engine, gcScene *scene)
|
||||
{
|
||||
(void)engine;
|
||||
(void)scene;
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user