Browse Source

Unify memory handling functions

Use abstraction instead of using SDL dependencies.
master
TheoryOfNekomata 1 year ago
parent
commit
7fa536895d
34 changed files with 66 additions and 42 deletions
  1. +5
    -5
      CMakeLists.txt
  2. +1
    -1
      TODO.md
  3. +1
    -1
      src/packages/asset-inv/main.c
  4. +1
    -1
      src/packages/config/IZ_config.h
  5. +1
    -1
      src/packages/game/IZ_app.h
  6. +1
    -1
      src/packages/game/IZ_app_config.h
  7. +2
    -2
      src/packages/game/IZ_app_net.c
  8. +1
    -0
      src/packages/game/IZ_app_net.h
  9. +2
    -2
      src/packages/game/data/IZ_list.c
  10. +1
    -1
      src/packages/game/data/IZ_list.h
  11. +2
    -2
      src/packages/game/input/IZ_joystick.c
  12. +2
    -2
      src/packages/game/input/IZ_joystick.h
  13. +1
    -1
      src/packages/game/input/IZ_keyboard.c
  14. +2
    -2
      src/packages/game/input/IZ_keyboard.h
  15. +2
    -2
      src/packages/game/input/IZ_midi.c
  16. +2
    -2
      src/packages/game/input/IZ_midi.h
  17. +1
    -1
      src/packages/game/input/input.test.c
  18. +2
    -2
      src/packages/game/memory/IZ_pool.c
  19. +2
    -2
      src/packages/game/memory/IZ_pool.h
  20. +1
    -1
      src/packages/game/output/video/IZ_video.h
  21. +1
    -1
      src/packages/log/IZ_intercept.h
  22. +1
    -1
      src/packages/midi/IZ_midi.h
  23. +1
    -1
      src/packages/net/IZ_net_client.h
  24. +1
    -1
      src/packages/net/IZ_net_server.h
  25. +1
    -1
      src/packages/net/core/IZ_websocket.h
  26. +1
    -1
      src/packages/net/svc/IZ_wsclient.h
  27. +1
    -1
      src/packages/net/svc/IZ_wsserver.h
  28. +1
    -1
      src/packages/server/IZ_app.h
  29. +1
    -1
      src/packages/server/IZ_app_config.h
  30. +1
    -1
      src/packages/server/db/IZ_repo.h
  31. +13
    -0
      src/packages/stdinc/IZ_stdlib.c
  32. +10
    -0
      src/packages/stdinc/IZ_stdlib.h
  33. +0
    -0
      src/packages/stdinc/IZ_string.c
  34. +0
    -0
      src/packages/stdinc/IZ_string.h

+ 5
- 5
CMakeLists.txt View File

@@ -149,11 +149,11 @@ add_executable(
src/packages/game/IZ_app_config.h
src/packages/game/asset/IZ_asset.c
src/packages/game/asset/IZ_asset.h
src/packages/string/IZ_string.c
src/packages/string/IZ_string.h
src/packages/stdinc/IZ_string.c
src/packages/stdinc/IZ_string.h
src/packages/io/IZ_io.c
src/packages/io/IZ_io.h
src/packages/log/IZ_log.c src/packages/log/IZ_log.h src/packages/timer/IZ_timer.c src/packages/timer/IZ_timer.h src/packages/compat/IZ_windows.h)
src/packages/log/IZ_log.c src/packages/log/IZ_log.h src/packages/timer/IZ_timer.c src/packages/timer/IZ_timer.h src/packages/compat/IZ_windows.h src/packages/stdinc/IZ_stdlib.c src/packages/stdinc/IZ_stdlib.h)

if (WIN32)
target_link_libraries(
@@ -284,8 +284,8 @@ add_executable(
src/packages/server/db/IZ_repo.c
src/packages/server/db/IZ_repo.h
src/packages/server/IZ_subsystem.h
src/packages/string/IZ_string.c
src/packages/string/IZ_string.h
src/packages/stdinc/IZ_string.c
src/packages/stdinc/IZ_string.h
src/packages/io/IZ_io.c
src/packages/io/IZ_io.h
src/packages/log/IZ_log.c


+ 1
- 1
TODO.md View File

@@ -1,5 +1,5 @@
- [X] Improve logging (remove SDL/lws dependency)
- [ ] Unify memset/memcpy/free/malloc functions (remove SDL/lws dependency)
- [X] Unify memset/memcpy/free/malloc functions (remove SDL/lws dependency)
- [ ] Fix gamepad mapping
- [ ] Provide default mapping
- [ ] Allow customization of button mappings


+ 1
- 1
src/packages/asset-inv/main.c View File

@@ -1,7 +1,7 @@
#include <stdio.h>
#include "minIni.h"
#include "../common/IZ_common.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"

#ifdef IZ_WIN64
#include <windows.h>


+ 1
- 1
src/packages/config/IZ_config.h View File

@@ -6,7 +6,7 @@
#include <minIni.h>
#include "../common/IZ_common.h"
#include "../log/IZ_log.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"

typedef enum {
IZ_CONFIG_TYPE_VOID,


+ 1
- 1
src/packages/game/IZ_app.h View File

@@ -11,7 +11,7 @@
#include "IZ_app_video.h"
#include "../log/IZ_log.h"
#include "../log/IZ_intercept.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"
#include "../timer/IZ_timer.h"

typedef enum {


+ 1
- 1
src/packages/game/IZ_app_config.h View File

@@ -4,6 +4,6 @@
#include <SDL_filesystem.h>
#include "IZ_subsystem.h"
#include "../config/IZ_config.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"

#endif

+ 2
- 2
src/packages/game/IZ_app_net.c View File

@@ -23,7 +23,7 @@ void IZ_AppHandleOutboundNetworking(struct IZ_App* app) {
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
if (net_state->action[player_index] != input_state->action[player_index]) {
u8 player_actions_count = 1;
IZ_AppActionSyncMessage* msg = SDL_malloc(
IZ_AppActionSyncMessage* msg = IZ_malloc(
sizeof(IZ_AppMessageHeader)
+ sizeof(u8)
+ (sizeof(IZ_AppPlayerActionSyncMessage) * player_actions_count)
@@ -39,7 +39,7 @@ void IZ_AppHandleOutboundNetworking(struct IZ_App* app) {
msg,
sizeof(*msg)
);
SDL_free(msg);
IZ_free(msg);
}
net_state->action[player_index] = input_state->action[player_index];
}


+ 1
- 0
src/packages/game/IZ_app_net.h View File

@@ -2,6 +2,7 @@
#define IZ_APP_NET_H

#include "IZ_subsystem.h"
#include "../stdinc/IZ_stdlib.h"

typedef enum {
IZ_MESSAGE_KIND_ACTION_SYNC = 0,


+ 2
- 2
src/packages/game/data/IZ_list.c View File

@@ -32,7 +32,7 @@ void IZ_ListTeardown(IZ_List* list) {
* @return Pointer to the newly created node.
*/
IZ_ListNode** IZ_ListAppendNode(IZ_List* list, void* node_value) {
IZ_ListNode* new_node = SDL_malloc(sizeof(IZ_ListNode));
IZ_ListNode* new_node = IZ_malloc(sizeof(IZ_ListNode));
new_node->value = node_value;
new_node->next = NULL;
list->length += 1;
@@ -83,7 +83,7 @@ void IZ_ListDeleteFirstNode(IZ_List* list, IZ_ListFindPredicate filter) {
// if there is only one item in the list, root, gets set to NULL
}

SDL_free(*list->iterator);
IZ_free(*list->iterator);
list->iterator = NULL;
if (list->length > 0) {
// avoid underflow


+ 1
- 1
src/packages/game/data/IZ_list.h View File

@@ -2,7 +2,7 @@
#define IZ_LIST_H

#include "../../common/IZ_common.h"
#include "SDL_stdinc.h"
#include "../../stdinc/IZ_stdlib.h"

/**
* A node in a linked list.


+ 2
- 2
src/packages/game/input/IZ_joystick.c View File

@@ -200,7 +200,7 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) {
char* main_section_name;
char* control_mapping_section_name;
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
main_section_name = SDL_malloc(sizeof(char) * 64);
main_section_name = IZ_calloc(64, sizeof(char));
sprintf(main_section_name, "Joystick.%d", player_index);
u8 base_index = (player_index * (IZ_CONTROLS - 4 + 2));
config_items[base_index] = (IZ_ConfigItem) {
@@ -238,7 +238,7 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) {

// todo add game controller GUID for determining mappings

control_mapping_section_name = SDL_malloc(sizeof(char) * 64);
control_mapping_section_name = IZ_calloc(64, sizeof(char));
sprintf(control_mapping_section_name, "Joystick.%d.ControlMapping", player_index);
for (control_index = 4; control_index < IZ_CONTROLS; control_index += 1) {
config_items[base_index + 3 + (control_index - 4)] = (IZ_ConfigItem) {


+ 2
- 2
src/packages/game/input/IZ_joystick.h View File

@@ -1,13 +1,13 @@
#ifndef IZ_JOYSTICK_H
#define IZ_JOYSTICK_H

#include <SDL_stdinc.h>
#include <SDL_joystick.h>
#include <SDL_gamecontroller.h>
#include <SDL_events.h>
#include <minIni.h>
#include "../../config/IZ_config.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"
#include "../../stdinc/IZ_stdlib.h"
#include "IZ_action.h"

typedef u8 IZ_PadButton;


+ 1
- 1
src/packages/game/input/IZ_keyboard.c View File

@@ -54,7 +54,7 @@ void IZ_KeyboardInitializeConfigItems(IZ_ConfigItem config_items[]) {
u8 control_index;
char* control_mapping_section_name;
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
control_mapping_section_name = SDL_malloc(sizeof(char) * 64);
control_mapping_section_name = IZ_calloc(64, sizeof(char));
sprintf(control_mapping_section_name, "Keyboard.%d.ControlMapping", player_index);
for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) {
config_items[player_index * IZ_CONTROLS + control_index] = (IZ_ConfigItem) {


+ 2
- 2
src/packages/game/input/IZ_keyboard.h View File

@@ -1,12 +1,12 @@
#ifndef IZ_KEYBOARD_H
#define IZ_KEYBOARD_H

#include <SDL_stdinc.h>
#include <SDL_keyboard.h>
#include <SDL_events.h>
#include <minIni.h>
#include "../../config/IZ_config.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"
#include "../../stdinc/IZ_stdlib.h"
#include "IZ_action.h"

typedef struct {


+ 2
- 2
src/packages/game/input/IZ_midi.c View File

@@ -76,7 +76,7 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) {
char* main_section_name;
char* control_mapping_section_name;
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
main_section_name = SDL_malloc(sizeof(char) * 64);
main_section_name = IZ_calloc(64, sizeof(char));
sprintf(main_section_name, "MIDIInput.%d", player_index);

u16 base_index = (player_index * (IZ_CONTROLS + 2));
@@ -110,7 +110,7 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) {
NULL,
};

control_mapping_section_name = SDL_malloc(sizeof(char) * 64);
control_mapping_section_name = IZ_calloc(64, sizeof(char));
sprintf(control_mapping_section_name, "MIDIInput.%d.ControlMapping", player_index);
for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) {
config_items[base_index + 2 + control_index] = (IZ_ConfigItem) {


+ 2
- 2
src/packages/game/input/IZ_midi.h View File

@@ -1,7 +1,6 @@
#ifndef IZ_MIDI_H
#define IZ_MIDI_H

#include <SDL_stdinc.h>
#include <string.h>

#ifndef PORTMIDI_INCLUDED
@@ -12,7 +11,8 @@
#include <minIni.h>
#include "../../config/IZ_config.h"
#include "../../midi/IZ_midi.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"
#include "../../stdinc/IZ_stdlib.h"
#include "IZ_action.h"

#define MIDI_EVENT_BUFFER_SIZE 1024


+ 1
- 1
src/packages/game/input/input.test.c View File

@@ -3,7 +3,7 @@
#include "../../../__mocks__/SDL_stdinc.mock.h"
#include "../../../__mocks__/minIni.mock.h"
#include "../../../__mocks__/portmidi.mock.h"
//#include "../../string/IZ_string.h"
//#include "../../stdinc/IZ_string.h"
#include "IZ_keyboard.h"
#include "IZ_joystick.h"
#include "IZ_midi.h"


+ 2
- 2
src/packages/game/memory/IZ_pool.c View File

@@ -3,7 +3,7 @@
void IZ_PoolInitialize(IZ_Pool* pool, size_t size) {
IZ_LogInfo(IZ_LOG_CATEGORY_GLOBAL, "Setting up memory pools...");
IZ_ListInitialize(&pool->items);
pool->memory = SDL_malloc(size);
pool->memory = IZ_malloc(size);
IZ_memset(pool->memory, 0, size);
pool->allocated_memory = 0;
pool->next_address = 0;
@@ -48,6 +48,6 @@ void IZ_PoolDeallocate(IZ_PoolItem* item) {

void IZ_PoolTeardown(IZ_Pool* pool) {
IZ_LogInfo(IZ_LOG_CATEGORY_GLOBAL, "Shutting down memory pools...");
SDL_free(pool->memory);
IZ_free(pool->memory);
pool->memory = NULL;
}

+ 2
- 2
src/packages/game/memory/IZ_pool.h View File

@@ -1,10 +1,10 @@
#ifndef IZ_POOL_H
#define IZ_POOL_H

#include <SDL_stdinc.h>
#include "../../common/IZ_common.h"
#include "../../log/IZ_log.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"
#include "../../stdinc/IZ_stdlib.h"
#include "../data/IZ_list.h"

#define POOL_MAX_SIZE (1llu << 26) // 64MB


+ 1
- 1
src/packages/game/output/video/IZ_video.h View File

@@ -10,7 +10,7 @@
#include "../../../config/IZ_config.h"
#include "../../../common/IZ_common.h"
#include "../../../io/IZ_io.h"
#include "../../../string/IZ_string.h"
#include "../../../stdinc/IZ_string.h"
#include "../../geometry/IZ_vector2d.h"
#include "../../input/IZ_input.h"



+ 1
- 1
src/packages/log/IZ_intercept.h View File

@@ -4,7 +4,7 @@
#include <ctype.h>
#include "libwebsockets.h"
#include "../common/IZ_common.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"
#include "IZ_log.h"

void IZ_LogInterceptWSMessages(i32);


+ 1
- 1
src/packages/midi/IZ_midi.h View File

@@ -3,7 +3,7 @@

#include <stdio.h>
#include <string.h>
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"

typedef unsigned char IZ_MIDINote;



+ 1
- 1
src/packages/net/IZ_net_client.h View File

@@ -6,7 +6,7 @@
#include "../config/IZ_config.h"
#include "../common/IZ_common.h"
#include "../game/input/IZ_action.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"
#include "svc/IZ_wsclient.h"

typedef enum {


+ 1
- 1
src/packages/net/IZ_net_server.h View File

@@ -4,7 +4,7 @@
#include <minIni.h>
#include "../config/IZ_config.h"
#include "../common/IZ_common.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"
#include "core/IZ_websocket.h"
#include "svc/IZ_wsserver.h"



+ 1
- 1
src/packages/net/core/IZ_websocket.h View File

@@ -3,7 +3,7 @@

#include "libwebsockets.h"
#include "../../common/IZ_common.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"

#define NETWORK_PROTOCOL "izanagi-networking"
#define RING_COUNT 32


+ 1
- 1
src/packages/net/svc/IZ_wsclient.h View File

@@ -2,7 +2,7 @@
#define IZ_WSCLIENT_H

#include "../../common/IZ_common.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"
#include "../core/IZ_websocket.h"

typedef struct {


+ 1
- 1
src/packages/net/svc/IZ_wsserver.h View File

@@ -5,7 +5,7 @@
#include <string.h>
#include "../../common/IZ_common.h"
#include "../../io/IZ_io.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"
#include "../core/IZ_websocket.h"

#ifndef S_ISDIR


+ 1
- 1
src/packages/server/IZ_app.h View File

@@ -6,7 +6,7 @@
#include "../common/IZ_common.h"
#include "../net/IZ_net_server.h"
#include "../log/IZ_intercept.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"
#include "db/IZ_repo.h"
#include "IZ_app_config.h"



+ 1
- 1
src/packages/server/IZ_app_config.h View File

@@ -3,7 +3,7 @@

#include <SDL_filesystem.h>
#include "../config/IZ_config.h"
#include "../string/IZ_string.h"
#include "../stdinc/IZ_string.h"
#include "IZ_subsystem.h"

#endif

+ 1
- 1
src/packages/server/db/IZ_repo.h View File

@@ -6,7 +6,7 @@
#include <string.h>
#include "../../common/IZ_common.h"
#include "../../config/IZ_config.h"
#include "../../string/IZ_string.h"
#include "../../stdinc/IZ_string.h"

typedef struct {
char path[64];


+ 13
- 0
src/packages/stdinc/IZ_stdlib.c View File

@@ -0,0 +1,13 @@
#include "IZ_stdlib.h"

void* IZ_malloc(size_t size) {
return malloc(size);
}

void* IZ_calloc(unsigned int count, size_t size) {
return calloc(count, size);
}

void IZ_free(void* p) {
free(p);
}

+ 10
- 0
src/packages/stdinc/IZ_stdlib.h View File

@@ -0,0 +1,10 @@
#ifndef IZ_STDLIB_H
#define IZ_STDLIB_H

#include <stdlib.h>

void* IZ_malloc(size_t);
void* IZ_calloc(unsigned int, size_t);
void IZ_free(void*);

#endif //IZ_STDLIB_H

src/packages/string/IZ_string.c → src/packages/stdinc/IZ_string.c View File


src/packages/string/IZ_string.h → src/packages/stdinc/IZ_string.h View File


Loading…
Cancel
Save