Implemented the core functionality of the ObjectStore and started

implementing the functionality for the AssetManager
This commit is contained in:
abdelrahman committed 2022-09-22 01:56:21 +01:00
1 parent 79f28100bd
commit c4f1775392
14 files changed
+330 -383

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#ifndef ASSET_MANAGER_H
#define ASSET_MANAGER_H
#include <stdint.h>
typedef int32_t AssetID;
typedef enum {
ASSET_TYPE_IMAGE,
ASSET_TYPE_AUDIO_FX,
ASSET_TYPE_MUSIC,
ASSET_TYPE_COUNT
} AssetType;
typedef struct asset_manager AssetManager;
AssetManager *create_asset_manager();
AssetID load_asset(AssetManager *am, const char *path, AssetType type);
void close_asset(AssetManager *am, AssetID id);
void destroy_asset_manager(AssetManager *am);
#endif // !ASSET_MANAGER_H
@@ -7,9 +7,9 @@
bool init_game(const char *game_name, int window_width, int window_height,
bool full_screen);
bool game_running();
void add_object(void *object, const char *object_tag, EventHandlerPtr eh,
UpdateFuncPtr uf, RenderFuncPtr rf);
void remove_object(const char *object_tag);
ObjectID add_object(void *object, EventHandlerPtr eh, UpdateFuncPtr uf,
RenderFuncPtr rf);
void remove_object(ObjectID id);
void handle_events();
void update();
void render();
-25
View File
@@ -1,25 +0,0 @@
#ifndef HASHMAP_H
#define HASHMAP_H
#include "engine_build_config.h"
#include <stddef.h>
#include <stdint.h>
#ifdef DEBUG_ENGINE
#include <stdio.h>
#endif /* DEBUG_ENGINE */
typedef struct hashmap Hashmap;
Hashmap *create_hashmap();
int32_t add_object_to_map(Hashmap *map, const char *key);
int32_t get_object_index(Hashmap *map, const char *key);
int32_t delete_object_from_map(Hashmap *map, const char *key);
void destroy_hashmap(Hashmap *map);
#ifdef DEBUG_ENGINE
void print_hashmap(Hashmap *map);
void print_non_empty(Hashmap *map);
#endif // DEBUG_ENGINE
#endif // !HASHMAP_H
+4 -4
View File
@@ -5,6 +5,7 @@
#include "SDL_events.h"
#include "engine_build_config.h"
typedef int32_t ObjectID;
typedef void (*EventHandlerPtr)(const SDL_Event *event, void *object);
typedef void (*UpdateFuncPtr)(float delta, void *object);
typedef void (*RenderFuncPtr)(Renderer *renderer, void *object);
@@ -12,10 +13,9 @@ typedef void (*RenderFuncPtr)(Renderer *renderer, void *object);
typedef struct object_store ObjectStore;
ObjectStore *create_object_store();
void add_object_to_store(ObjectStore *os, void *object, const char *object_tag,
EventHandlerPtr eh, UpdateFuncPtr uf,
RenderFuncPtr rf);
void remove_object_from_store(ObjectStore *os, const char *object_tag);
ObjectID add_object_to_store(ObjectStore *os, void *object, EventHandlerPtr eh,
UpdateFuncPtr uf, RenderFuncPtr rf);
void remove_object_from_store(ObjectStore *os, ObjectID id);
void handle_all_objects_events(ObjectStore *os, const SDL_Event *event);
void update_all_objects(ObjectStore *os, float delta);
void render_all_objects(ObjectStore *os, Renderer *renderer);
+1
View File
@@ -4,6 +4,7 @@
#define INTERNAL static
#define MAX_OBJ_COUNT 10000
#define MAX_ASSET_COUNT 1000
#define HASH_PRIME_01 1987
#define HASH_PRIME_02 7919
+9
View File
@@ -0,0 +1,9 @@
#ifndef REUSABLE_IDS_H
#define REUSABLE_IDS_H
#include <stddef.h>
#include <stdint.h>
int32_t reuse_id(int32_t *ids, size_t count);
#endif // !REUSABLE_IDS_H