Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEArgos committed Jun 29, 2024
1 parent 96d357e commit c440909
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Source/Assets/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.4
0.2.6
2 changes: 1 addition & 1 deletion Source/Entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ i32 main(void)

// Destroy/free all allocated memory and get ready to exit the
// application entirely.
DestroyApplication(renai);
KillApplication(renai);
}
2 changes: 1 addition & 1 deletion Source/Modules/Application.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ CreateApplication(void)
return application;
}

__KILL DestroyApplication(Application* application)
__KILL KillApplication(Application* application)
{
if (application == NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CreateApplication(void);
* anything--positive or negative--that may have occurred.
* @param application The application to destroy.
*/
__KILL DestroyApplication(Application* application);
__KILL KillApplication(Application* application);

/**
* @brief Run an application's main loop methods until the key window
Expand Down
17 changes: 17 additions & 0 deletions Source/Modules/Manager.c
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
#include "Manager.h"

__CREATE_STRUCT(SceneManager)
CreateManager(Texture* missing_texture)
{
SceneManager* manager = __MALLOC(
SceneManager, manager,
("Failed to allocate space for the scene manager. Code: %d.",
errno));
PrintSuccess("Allocated space for the scene manager: %d bytes.",
sizeof(SceneManager));

CreateLinkedList(RegisterTextureNode("missing_texture_tile",
missing_texture, 0.0f, 0.0f,
0, 1, 1.0f, 0.0f));

return manager;
}
11 changes: 11 additions & 0 deletions Source/Modules/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ typedef struct SceneManager
LinkedList* registered_textures;
} SceneManager;

__CREATE_STRUCT(SceneManager)
CreateManager(Texture* missing_texture);

__INLINE void KillManager(SceneManager* manager)
{
KillLinkedList(manager->registered_textures);
__FREE(manager,
("The scene manager freer was given an invalid value."));
PrintWarning("The scene manager was freed.");
}

#endif // _RENAI_MANAGER_
21 changes: 12 additions & 9 deletions Source/Modules/Renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ __INLINE __KILLFAIL _CreateLinkedLists(Renderer* renderer,
f32 window_height)
{
renderer->shader_list =
CreateLinkedList(shader, CreateShaderNode(shader, "basic"));
renderer->texture_list = CreateLinkedList(
texture, CreateTextureNode(texture, "texture_missing.jpg",
window_width, window_height));
CreateLinkedList(CreateShaderNode("basic"));
renderer->texture_list = CreateLinkedList(CreateTextureNode(
"texture_missing.jpg", window_width, window_height));

// Make sure nothing went wrong.
if (GetRendererHead(renderer, texture) == NULL ||
Expand Down Expand Up @@ -55,14 +54,17 @@ CreateRenderer(f32 window_width, f32 window_height)
projection);

// Slide the projection matrix into the shader.
UseShader(*GetNodeContents(basic_shader, Shader));
SetMat4(*GetNodeContents(basic_shader, Shader), "projection",
projection);
UseShader(GetNodeContents(basic_shader, shader)->shader);
SetMat4(GetNodeContents(basic_shader, shader)->shader,
"projection", projection);

PrintSuccess(
"Successfully set up the projection matrix on shader '%s'.",
basic_shader->name);

CreateManager(
GetNodeContents(GetRendererHead(renderer, texture), texture));

return renderer;
}

Expand All @@ -71,12 +73,13 @@ void RenderWindowContent(Renderer* renderer)
// Get the basic shader, the one we use to render plain textures,
// and slot it as our current one.
u32 basic_shader =
*GetNodeContents(GetRendererHead(renderer, shader), Shader);
GetNodeContents(GetRendererHead(renderer, shader), shader)
->shader;
UseShader(basic_shader);

// Bind the "missing" texture to render as a placeholder.
Texture* missing_texture =
GetNodeContents(GetRendererHead(renderer, texture), Texture);
GetNodeContents(GetRendererHead(renderer, texture), texture);
BindTexture(missing_texture);

// Position transform the bound texture so it's within our
Expand Down
6 changes: 4 additions & 2 deletions Source/Modules/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ CreateRenderer(f32 window_width, f32 window_height);
*/
__INLINE void KillRenderer(Renderer* renderer)
{
DestroyLinkedList(renderer->shader_list);
DestroyLinkedList(renderer->texture_list);
KillLinkedList(renderer->shader_list);
KillLinkedList(renderer->texture_list);
KillManager(renderer->scene_manager);
__FREE(renderer,
("The renderer freer was given an invalid texture."));
PrintWarning("The renderer was freed.");
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Source/Modules/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ CreateUpdater(u8 tick_speed);
*/
__INLINE void KillUpdater(Updater* updater)
{
DestroyMap(updater->key_buffer);
KillMap(updater->key_buffer);
__FREE(updater,
("The updater freer was given an invalid texture."));
PrintWarning("The updater was freed.");
}

/**
Expand Down
38 changes: 23 additions & 15 deletions Source/Types/LinkedList.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#include "LinkedList.h"
#include <Logger.h>

Node* __CreateNode(NodeType type, const char* name, u32 shader,
Texture* texture)
#define __TYPE_SWITCH(type, ex1, ex2, ex3) \
switch (type) \
{ \
case shader: ex1; break; \
case texture: ex2; break; \
case instance: ex3; break; \
}

Node* __CreateNode(NodeType type, const char* name, void* contents)
{
Node* created_node = __MALLOC(
Node, created_node,
Expand All @@ -11,41 +18,42 @@ Node* __CreateNode(NodeType type, const char* name, u32 shader,
created_node->name = name;
created_node->type = type;

if (shader == 0) created_node->contents.texture = texture;
else created_node->contents.shader = shader;
__TYPE_SWITCH(type, created_node->contents.shader = contents,
created_node->contents.texture = contents,
created_node->contents.instance = contents);

return created_node;
}

LinkedList* CreateLinkedList(NodeType type, Node* head)
LinkedList* CreateLinkedList(Node* head)
{
LinkedList* created_list = __MALLOC(
LinkedList, created_list,
("Failed to allocate node list of type %d. Code: %d.", type,
errno));
created_list->type = type;
("Failed to allocate node list of type %d. Code: %d.",
head->type, errno));
created_list->type = head->type;
created_list->first_node = head;
created_list->last_node = head;

return created_list;
}

void DestroyLinkedList(LinkedList* list)
void KillLinkedList(LinkedList* list)
{
Node* current_node = list->first_node;
while (current_node != NULL)
{
Node* next_node = current_node->next;
if (current_node->type == texture)
KillTexture(current_node->contents.texture);
free(current_node);
KillNode(current_node);
current_node = next_node;
printf("%s\n", current_node->name);
}

__FREE(list,
("The linked list freer was given an invalid texture."));
("The linked list freer was given an invalid list."));
}

//! outdated asf
__BOOLEAN VerifyNodeContents(NodeType type, NodeContents* contents)
{
if (type == shader && contents->shader != 0) return true;
Expand All @@ -56,12 +64,12 @@ __BOOLEAN VerifyNodeContents(NodeType type, NodeContents* contents)
return false;
}

void AppendNode(LinkedList* list, NodeType type, Node* node)
void AppendNode(LinkedList* list, Node* node)
{
list->last_node->next = node;
list->last_node = list->last_node->next;
}
void InsertNode(LinkedList* list, NodeType type, Node* node)
void InsertNode(LinkedList* list, Node* node)
{
Node* last_head = list->first_node;
list->first_node = node;
Expand Down
70 changes: 34 additions & 36 deletions Source/Types/LinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ typedef enum NodeType
* @brief The node contains an OpenGL texture object, and all
* information associated with it.
*/
texture
texture,
/**
* @brief The node contains a registered texture object for use in
* rendering.
*/
instance
} NodeType;

/**
Expand All @@ -46,12 +51,17 @@ typedef union NodeContents
/**
* @brief An OpenGL shader ID.
*/
u32 shader;
Shader* shader;
/**
* @brief A texture image and all the information associated with
* it.
*/
Texture* texture;
/**
* @brief A registered texture with individual information for use
* in rendering.
*/
TextureInstance* instance;
} NodeContents;

typedef struct Node
Expand All @@ -71,49 +81,37 @@ typedef struct LinkedList
Node* last_node;
} LinkedList;

#define GetNodeContents(node, type) Get##type##Contents(node)
__INLINE Texture* GetTextureContents(Node* node)
{
return node->contents.texture;
}
__INLINE u32* GetShaderContents(Node* node)
{
return &node->contents.shader;
}

// #define list_head_contents first_node->contents
// #define list_head_texture first_node->contents.texture
// #define list_head_shader first_node->contents.shader
// #define texture_contents contents.texture
// #define shader_contents contents.shader

// #define GetShaderNode(list, name) GetNode(list,
// name)->shader_contents #define GetTextureNode(list, name)
// GetNode(list, name)->texture_contents #define
// GetShaderListHead(list) list->list_head_shader #define
// GetTextureListHead(list) list->list_head_texture

#define CreateShaderNode(type, name) \
__CreateNode(type, name, LoadShader(name), NULL)
#define CreateTextureNode(type, name, swidth, sheight) \
__CreateNode(type, name, 0, \
CreateTexture(name, tileset, swidth, sheight))
#define GetNodeContents(node, type) node->contents.type

#define CreateShaderNode(name) \
__CreateNode(shader, name, LoadShader(name))
#define CreateTextureNode(name, swidth, sheight) \
__CreateNode(texture, name, \
CreateTexture(name, tileset, swidth, sheight))
#define RegisterTextureNode(name, from, x, y, z, scale, brightness, \
rotation) \
__CreateNode( \
instance, name, \
RegisterTexture(from, x, y, z, scale, brightness, rotation))
// stupid fucking solution
Node* __CreateNode(NodeType type, const char* name, u32 shader,
Texture* texture);
Node* __CreateNode(NodeType type, const char* name, void* contents);

//??!!!! brother why am i take both type and node?? type is stored in
// node?? fix
LinkedList* CreateLinkedList(NodeType type, Node* head);
LinkedList* CreateLinkedList(Node* head);

#define DestroyNode(node) FreeItem(node)
void DestroyLinkedList(LinkedList* list);
#define KillNode(node) \
__TYPE_SWITCH( \
current_node->type, \
KillShader(current_node->contents.shader), \
KillTexture(current_node->contents.texture), \
DeregisterTexture(current_node->contents.instance));
void KillLinkedList(LinkedList* list);

__BOOLEAN VerifyNodeContents(NodeType type, NodeContents* contents);

void AppendNode(LinkedList* list, NodeType type, Node* node);
void InsertNode(LinkedList* list, NodeType type, Node* node);
void AppendNode(LinkedList* list, Node* node);
void InsertNode(LinkedList* list, Node* node);

Node* GetNode(LinkedList* list, const char* name);

Expand Down
4 changes: 2 additions & 2 deletions Source/Types/Map.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Map* CreateMap(AmbiguousTypeSpecifier key_type,
Map, created_map,
("Failed to allocate map with keypair %dx%d and size "
"%d. Code: %d",
key_type, value_type, max_size));
key_type, value_type, max_size, errno));
created_map->max_size = max_size;
created_map->filled_size = 0;
created_map->key_type = key_type;
Expand All @@ -22,7 +22,7 @@ Map* CreateMap(AmbiguousTypeSpecifier key_type,
return created_map;
}

void DestroyMap(Map* map)
void KillMap(Map* map)
{
__FREE(map->map_values,
("The map freer was given an invalid map."));
Expand Down
2 changes: 1 addition & 1 deletion Source/Types/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct Map

Map* CreateMap(AmbiguousTypeSpecifier key_type,
AmbiguousTypeSpecifier value_type, u32 max_size);
void DestroyMap(Map* map);
void KillMap(Map* map);

#define AppendMapItem(map, key, value) \
{ \
Expand Down
Loading

0 comments on commit c440909

Please sign in to comment.