Skip to content

Commit d2d2fad

Browse files
Add Zelda64Recomp API header, config header, UI headers, util header, and data structure header and fix uname being run on Windows (#9)
* Add example toml/code for config values and example code for building a UI * Update UI enums. * Add new margin auto setters and total height define * Add UI callback types to headers and add callback example * Add z64recomp_api.h header for game-specific mod APIs and document actor data extensions in it * Organize imports into headers, add label and textinput * Add context input capture setters to recompui.h * Add UI API functions for setting visibility, setting text, and destroying elements * Add UI API functions and example code for imageview elements * Add recompdata.h header with data structure API imports * Add exports and examples for slider, label radio, and password input * Add recomp_get_mod_version import and example * Add recomp_change_save_file export and documentation in recompconfig.h * Add recomp_get_save_file_path export * Add extra flex direction enums * Add navigation exports to recompui.h * Remove UI example code (will be restored in another branch to keep main branch example simple) * Fix uname being run on windows --------- Co-authored-by: Dario <dariosamo@gmail.com>
1 parent 63e3fbc commit d2d2fad

9 files changed

Lines changed: 644 additions & 7 deletions

File tree

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ BUILD_DIR := build
22

33
# Allow the user to specify the compiler and linker on macOS
44
# as Apple Clang does not support MIPS architecture
5-
ifeq ($(shell uname),Darwin)
6-
CC ?= clang
7-
LD ?= ld.lld
8-
else
5+
ifeq ($(OS),Windows_NT)
96
CC := clang
107
LD := ld.lld
8+
else ifneq ($(shell uname),Darwin)
9+
CC := clang
10+
LD := ld.lld
11+
else
12+
CC ?= clang
13+
LD ?= ld.lld
1114
endif
1215

1316
TARGET := $(BUILD_DIR)/mod.elf

include/recompconfig.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef __RECOMPCONFIG_H__
2+
#define __RECOMPCONFIG_H__
3+
4+
#include "modding.h"
5+
6+
// Reads a config value of the specified type and name for the mod that called these functions.
7+
// These correspond to the config schema provided in the mod's manifest.
8+
RECOMP_IMPORT("*", unsigned long recomp_get_config_u32(const char* key));
9+
RECOMP_IMPORT("*", double recomp_get_config_double(const char* key));
10+
RECOMP_IMPORT("*", char* recomp_get_config_string(const char* key));
11+
12+
// Frees a value returned by `recomp_get_config_string`. MUST be called to prevent a memory leak.
13+
RECOMP_IMPORT("*", void recomp_free_config_string(char* str));
14+
15+
// Gets the version of the mod that called this function. Writes the mod's version numbers into the provided pointers.
16+
RECOMP_IMPORT("*", void recomp_get_mod_version(unsigned long* major, unsigned long* minor, unsigned long* patch));
17+
18+
// Swaps to using a different file. The new save file will be located at `<mod id>/<filename>.bin` in the normal saves folder.
19+
// Don't include `.bin` in the provided filename.
20+
// Be careful calling this function during normal gameplay as the game won't be aware that any currently loaded save data is outdated.
21+
RECOMP_IMPORT("*", void recomp_change_save_file(const char* filename));
22+
23+
// Returns a UTF-8 encoded zero-terminated string containing the absolute path to the current save file.
24+
// The return type is an unsigned char pointer to indicate the UTF-8 encoding.
25+
// `recomp_free` (found in `recomputils.h`) MUST be called on the return value of this when the value is no longer in use to prevent a memory leak.
26+
RECOMP_IMPORT("*", unsigned char* recomp_get_save_file_path());
27+
28+
#endif

include/recompdata.h

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#ifndef __RECOMPDATA_H__
2+
#define __RECOMPDATA_H__
3+
4+
#include "modding.h"
5+
6+
// This file contains imports for utility data collection types.
7+
// hashmaps: Maps arbitrary unique numeric keys to elements.
8+
// Amortized O(1) performance for insertion, lookup, and deletion.
9+
// hashsets: Tracks a collection of unique numeric keys.
10+
// Amortized O(1) performance for insertion, lookup, and deletion.
11+
// slotmaps: Like hashmaps, but the keys are generated instead of provided.
12+
// Amortized O(1) performance for insertion, lookup, and deletion. More performant than hashmaps.
13+
14+
// Hashmaps and slotmaps types are available that hold either 32-bit elements or data elements of a fixed element size.
15+
16+
typedef unsigned long collection_key_t;
17+
18+
/////////////////////////
19+
// u32 -> u32 hashmaps //
20+
/////////////////////////
21+
22+
typedef unsigned long U32ValueHashmapHandle;
23+
24+
// Creates a hashmap that maps u32 keys to u32 values.
25+
// Returns the handle for that hashmap.
26+
RECOMP_IMPORT("*", U32ValueHashmapHandle recomputil_create_u32_value_hashmap());
27+
28+
// Destroys a u32 -> u32 hashmap.
29+
RECOMP_IMPORT("*", void recomputil_destroy_u32_value_hashmap(U32ValueHashmapHandle handle));
30+
31+
// Checks if a u32 -> u32 hashmap contains the given key.
32+
// Returns 1 if the key exists in the map, otherwise returns 0.
33+
RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_contains(U32ValueHashmapHandle handle, collection_key_t key));
34+
35+
// Inserts a value into a u32 -> u32 hashmap. The value is always assigned even if the key already exists.
36+
// Returns 1 if the key was created (i.e. did not exist in the map), otherwise returns 0.
37+
RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_insert(U32ValueHashmapHandle handle, collection_key_t key, unsigned long value));
38+
39+
// Attempts to retrieve a value from a u32 -> u32 hashmap.
40+
// Returns 1 if the key exists in the map and writes the element's value to *out, otherwise returns 0 and does not modify the contents in *out.
41+
RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_get(U32ValueHashmapHandle handle, collection_key_t key, unsigned long* out));
42+
43+
// Erases a key from a u32 -> u32 hashmap. Does nothing if the key doesn't exist in the hashmap.
44+
// Returns 1 if the key was erased (i.e. it existed in the map), otherwise returns 0.
45+
RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_erase(U32ValueHashmapHandle handle, collection_key_t key));
46+
47+
// Gets the size of a u32 -> u32 hashmap.
48+
// Returns the number of elements in the map.
49+
RECOMP_IMPORT("*", unsigned long recomputil_u32_value_hashmap_size(U32ValueHashmapHandle handle));
50+
51+
//////////////////////////
52+
// u32 -> data hashmaps //
53+
//////////////////////////
54+
55+
typedef unsigned long U32MemoryHashmapHandle;
56+
57+
// Creates a hashmap that maps u32 keys to data of a given element size.
58+
// Returns the handle for that hashmap.
59+
RECOMP_IMPORT("*", U32MemoryHashmapHandle recomputil_create_u32_memory_hashmap(unsigned long element_size));
60+
61+
// Destroys a u32 -> data hashmap.
62+
RECOMP_IMPORT("*", void recomputil_destroy_u32_memory_hashmap(U32MemoryHashmapHandle handle));
63+
64+
// Checks if a u32 -> data hashmap contains the given key.
65+
// Returns 1 if the key exists in the map, otherwise returns 0.
66+
RECOMP_IMPORT("*", int recomputil_u32_memory_hashmap_contains(U32MemoryHashmapHandle handle, collection_key_t key));
67+
68+
// Creates an element in a u32 -> data hashmap with the given key. Does nothing if the key already exists.
69+
// Returns 1 if the element was created (i.e. the key did not already existed), otherwise returns 0.
70+
RECOMP_IMPORT("*", int recomputil_u32_memory_hashmap_create(U32MemoryHashmapHandle handle, collection_key_t key));
71+
72+
// Attempts to retrieve a value from a u32 -> data hashmap.
73+
// Returns the element's pointer if the key exists in the map, otherwise returns null.
74+
RECOMP_IMPORT("*", void* recomputil_u32_memory_hashmap_get(U32MemoryHashmapHandle handle, collection_key_t key));
75+
76+
// Erases a key from a u32 -> data hashmap. Does nothing if the key doesn't exist in the hashmap.
77+
// Returns 1 if the key was erased (i.e. it existed in the map), otherwise returns 0.
78+
RECOMP_IMPORT("*", int recomputil_u32_memory_hashmap_erase(U32MemoryHashmapHandle handle, collection_key_t key));
79+
80+
// Gets the size of a u32 -> data hashmap.
81+
// Returns the number of elements in the map.
82+
RECOMP_IMPORT("*", unsigned long recomputil_u32_memory_hashmap_size(U32MemoryHashmapHandle handle));
83+
84+
//////////////////
85+
// u32 hashsets //
86+
//////////////////
87+
88+
typedef unsigned long U32HashsetHandle;
89+
90+
// Creates a hashset of u32 keys.
91+
// Returns the handle for that hashset.
92+
RECOMP_IMPORT("*", U32HashsetHandle recomputil_create_u32_hashset());
93+
94+
// Destroys a u32 hashset.
95+
RECOMP_IMPORT("*", void recomputil_destroy_u32_hashset(U32HashsetHandle handle));
96+
97+
// Checks if a u32 hashset contains the given key.
98+
// Returns 1 if the key exists in the set, otherwise returns 0.
99+
RECOMP_IMPORT("*", int recomputil_u32_hashset_contains(U32HashsetHandle handle, collection_key_t key));
100+
101+
// Inserts a key into a u32 hashset.
102+
// Returns 1 if the key was inserted (i.e. it did not exist in the set), otherwise returns 0.
103+
RECOMP_IMPORT("*", int recomputil_u32_hashset_insert(U32HashsetHandle handle, collection_key_t key));
104+
105+
// Erases a key from a u32 hashset.
106+
// Returns 1 if the key was erased (i.e. it exited in the set), otherwise returns 0.
107+
RECOMP_IMPORT("*", int recomputil_u32_hashset_erase(U32HashsetHandle handle, collection_key_t key));
108+
109+
// Gets the size of a u32 hashset.
110+
// Returns the number of elements in the set.
111+
RECOMP_IMPORT("*", unsigned long recomputil_u32_hashset_size(U32HashsetHandle handle));
112+
113+
//////////////////
114+
// u32 slotmaps //
115+
//////////////////
116+
117+
typedef unsigned long U32SlotmapHandle;
118+
119+
// Creates a slotmap with u32 elements.
120+
// Returns the handle for that slotmap.
121+
RECOMP_IMPORT("*", U32SlotmapHandle recomputil_create_u32_slotmap());
122+
123+
// Destroys a u32 slotmap.
124+
RECOMP_IMPORT("*", void recomputil_destroy_u32_slotmap(U32SlotmapHandle handle));
125+
126+
// Checks if a u32 slotmap contains the given key.
127+
// Returns 1 if the key exists in the map, otherwise returns 0.
128+
RECOMP_IMPORT("*", int recomputil_u32_slotmap_contains(U32SlotmapHandle handle, collection_key_t key));
129+
130+
// Creates an element in a u32 slotmap.
131+
// Returns the created element's key.
132+
RECOMP_IMPORT("*", collection_key_t recomputil_u32_slotmap_create(U32SlotmapHandle handle));
133+
134+
// Attempts to retrieve a value from a u32 slotmap.
135+
// Returns 1 if the key exists in the map and writes the element's value to *out, otherwise returns 0 and does not modify the contents in *out.
136+
RECOMP_IMPORT("*", int recomputil_u32_slotmap_get(U32SlotmapHandle handle, collection_key_t key, unsigned long* out));
137+
138+
// Attempts to set a value in a u32 slotmap. The value is not assigned if the key does not exist.
139+
// Returns 1 if the key existed, otherwise returns 0.
140+
RECOMP_IMPORT("*", int recomputil_u32_slotmap_set(U32SlotmapHandle handle, collection_key_t key, unsigned long value));
141+
142+
// Erases a key from a u32 slotmap.
143+
// Returns 1 if the key was erased (i.e. it exited in the map), otherwise returns 0.
144+
RECOMP_IMPORT("*", int recomputil_u32_slotmap_erase(U32SlotmapHandle handle, collection_key_t key));
145+
146+
// Gets the size of a u32 slotmap.
147+
// Returns the number of elements in the map.
148+
RECOMP_IMPORT("*", unsigned long recomputil_u32_slotmap_size(U32SlotmapHandle handle));
149+
150+
///////////////////
151+
// data slotmaps //
152+
///////////////////
153+
154+
typedef unsigned long MemorySlotmapHandle;
155+
156+
// Creates a slotmap with data elements of a given element size.
157+
// Returns the handle for that slotmap.
158+
RECOMP_IMPORT("*", MemorySlotmapHandle recomputil_create_memory_slotmap(unsigned long element_size));
159+
160+
// Destroys a memory slotmap.
161+
RECOMP_IMPORT("*", void recomputil_destroy_memory_slotmap(MemorySlotmapHandle handle));
162+
163+
// Checks if a memory slotmap contains the given key.
164+
// Returns 1 if the key exists in the map, otherwise returns 0.
165+
RECOMP_IMPORT("*", int recomputil_memory_slotmap_contains(MemorySlotmapHandle handle, collection_key_t key));
166+
167+
// Creates an element in a memory slotmap.
168+
// Returns the created element's key.
169+
RECOMP_IMPORT("*", collection_key_t recomputil_memory_slotmap_create(MemorySlotmapHandle handle));
170+
171+
// Attempts to retrieve an element from a u32 slotmap.
172+
// Returns 1 if the key exists in the map and writes the element's pointer to *out, otherwise returns 0 and does not modify the contents in *out.
173+
RECOMP_IMPORT("*", int recomputil_memory_slotmap_get(MemorySlotmapHandle handle, collection_key_t key, void** out));
174+
175+
// Erases a key from a memory slotmap.
176+
// Returns 1 if the key was erased (i.e. it exited in the map), otherwise returns 0.
177+
RECOMP_IMPORT("*", int recomputil_memory_slotmap_erase(MemorySlotmapHandle handle, collection_key_t key));
178+
179+
// Gets the size of a memory slotmap.
180+
// Returns the number of elements in the map.
181+
RECOMP_IMPORT("*", unsigned long recomputil_memory_slotmap_size(MemorySlotmapHandle handle));
182+
183+
#endif

0 commit comments

Comments
 (0)