Enabled SDL_image's support for PNG and TIFF files and improved the
AssetManager with a hashing function, a linked list structure to store the hashes as well as a reference counter to support multiple users sharing the same asset.
This commit is contained in:
1 parent
3f71cf0f3f
commit
dfee36ffe9
12 files changed
+292
-60
No files matched your search
+10
-2
@@ -5,7 +5,11 @@
|
||||
#include "SDL_mixer.h"
|
||||
#include "SDL_render.h"
|
||||
#include "reusable_ids.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
typedef enum {
|
||||
ASSET_TYPE_IMAGE,
|
||||
@@ -19,10 +23,14 @@ typedef struct asset_manager AssetManager;
|
||||
AssetManager *create_asset_manager();
|
||||
AssetID load_asset_to_manager(AssetManager *am, const char *path,
|
||||
AssetType type, Renderer *renderer);
|
||||
void remove_asset_from_manager(AssetManager *am, AssetID id);
|
||||
void remove_asset_from_manager(AssetManager *am, AssetID *id_ptr);
|
||||
SDL_Texture *get_texture(AssetManager *am, AssetID id);
|
||||
Mix_Chunk *get_audio_chunk(AssetManager *am, AssetID id);
|
||||
Mix_Music *get_music(AssetManager *am, AssetID id);
|
||||
void destroy_asset_manager(AssetManager *am);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !ASSET_MANAGER_H
|
||||
+10
-2
@@ -7,18 +7,26 @@
|
||||
#include "reusable_ids.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
bool init_game(const char *game_name, int window_width, int window_height,
|
||||
SDL_Color window_background_color, bool full_screen);
|
||||
bool game_running();
|
||||
ObjectID add_object(void *object, EventHandlerPtr eh, UpdateFuncPtr uf,
|
||||
RenderFuncPtr rf);
|
||||
void remove_object(ObjectID id);
|
||||
void remove_object(ObjectID *id);
|
||||
AssetID load_asset(const char *path, AssetType type);
|
||||
void render_texture_asset(AssetID id, float x, float y, float w, float h);
|
||||
void close_asset(AssetID id);
|
||||
void close_asset(AssetID *id);
|
||||
void handle_events();
|
||||
void update();
|
||||
void render();
|
||||
void close_game();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !GAME_H
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "engine_build_config.h"
|
||||
#include "reusable_ids.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
typedef void (*EventHandlerPtr)(const SDL_Event *event, void *object);
|
||||
typedef void (*UpdateFuncPtr)(float delta, void *object);
|
||||
typedef void (*RenderFuncPtr)(void *object);
|
||||
@@ -15,7 +19,7 @@ typedef struct object_store ObjectStore;
|
||||
ObjectStore *create_object_store();
|
||||
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 remove_object_from_store(ObjectStore *os, ObjectID *id_ptr);
|
||||
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);
|
||||
@@ -25,4 +29,8 @@ void destroy_object_store(ObjectStore *os);
|
||||
void print_objects(ObjectStore *os);
|
||||
#endif // !DEBUG_ENGINE
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !OBJECT_STORE_H
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "SDL_video.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
typedef struct renderer Renderer;
|
||||
|
||||
Renderer *create_renderer();
|
||||
@@ -17,4 +21,8 @@ void render_texture(const Renderer *renderer, SDL_Texture *texture, float x,
|
||||
void swap_buffers(const Renderer *renderer);
|
||||
void destroy_renderer(Renderer *renderer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !RENDERER_H
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "SDL_pixels.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
typedef struct window {
|
||||
int width;
|
||||
int height;
|
||||
@@ -20,4 +24,8 @@ void clear_window(const Window *wnd);
|
||||
void swap_render_buffers(const Window *wnd);
|
||||
void destroy_window(Window *wnd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !WINDOW_H
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
#define INTERNAL static
|
||||
|
||||
#define MAX_OBJ_COUNT 10000
|
||||
@@ -8,4 +12,8 @@
|
||||
#define HASH_PRIME_01 1987
|
||||
#define HASH_PRIME_02 7919
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !CONSTANTS_H
|
||||
@@ -4,9 +4,19 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
#define INVALID_ID -1
|
||||
|
||||
typedef int32_t ObjectID;
|
||||
typedef int32_t AssetID;
|
||||
|
||||
int32_t reuse_id(int32_t *ids, size_t count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !REUSABLE_IDS_H
|
||||
Reference in new issue
Block a user