shengine pre-release
shengine by mrsinho
Loading...
Searching...
No Matches
shEnvironment.h
Go to the documentation of this file.
1/**
2 * @file shEnvironment.h
3 * @brief Handling environment descriptor functionalities in the `shengine` framework.
4 *
5 * The shEnvironment.h file contains structures and functions related to handling environment descriptors
6 * in the `shengine` framework.
7 */
8
9#ifndef SH_ENGINE_DESCRIPTOR_H
10#define SH_ENGINE_DESCRIPTOR_H
11
12#ifdef __cplusplus
13extern "C" {
14#endif//__cplusplus
15
16#include <sys/types.h>
17#include <sys/stat.h>
18
19#ifdef _UNIX
20#define stat _stat
21#include <unistd.h>
22#endif // _UNIX
23
24#ifdef _WIN32
25#define stat _stat
26#endif // _WIN32
27
28#include <stdio.h>
29#include <stdint.h>
30#include <smd/smd.h>
31#include <shvulkan/shVulkan.h>
32
33
34
35#define SH_ENVIRONMENT_STR512_LENGTH 64
36#define SH_ENVIRONMENT_STR1024_LENGTH 128
37
38
39
40/**
41 * @struct ShIniProperties
42 * @brief Structure representing properties related to the initialization (INI) file.
43 *
44 * The ShIniProperties structure represents properties related to the initialization (INI) file in the `shengine` framework,
45 * including application name, and paths to various SMD files.
46 */
47typedef struct ShIniProperties {
48 char application_name [SH_ENVIRONMENT_STR1024_LENGTH]; /**< Application name. */
49 char application_smd_path [SH_ENVIRONMENT_STR1024_LENGTH]; /**< Path to the application SMD file. */
50 char host_memory_smd_path [SH_ENVIRONMENT_STR1024_LENGTH]; /**< Path to the host memory SMD file. */
51 char vulkan_memory_smd_path [SH_ENVIRONMENT_STR1024_LENGTH]; /**< Path to the Vulkan memory SMD file. */
52 char serial_smd_path [SH_ENVIRONMENT_STR1024_LENGTH]; /**< Path to the serial SMD file. */
53 char scene_smd_path [SH_ENVIRONMENT_STR1024_LENGTH]; /**< Path to the scene SMD file. */
55
56
57
58/**
59 * @struct ShApplicationProperties
60 * @brief Structure representing properties related to the application.
61 *
62 * The ShApplicationProperties structure represents properties related to the application in the `shengine` framework,
63 * including shared name, thread-related function names, and additional thread count.
64 */
66 char shared_name [SH_ENVIRONMENT_STR512_LENGTH]; /**< Shared name. */
67 char s_start [SH_ENVIRONMENT_STR512_LENGTH]; /**< Thread start function name. */
68 char s_update [SH_ENVIRONMENT_STR512_LENGTH]; /**< Thread update function name. */
69 char s_main_cmd_buffer [SH_ENVIRONMENT_STR512_LENGTH]; /**< Main command buffer function name. */
70 char s_main_renderpass [SH_ENVIRONMENT_STR512_LENGTH]; /**< Main render pass function name. */
71 char s_frame_resize [SH_ENVIRONMENT_STR512_LENGTH]; /**< Frame resize function name. */
72 char s_close [SH_ENVIRONMENT_STR512_LENGTH]; /**< Close function name. */
73 uint32_t additional_thread_count; /**< Additional thread count. */
75
76
77
78#define SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT 2048
79
80
81
82/**
83 * @struct ShHostMemoryProperties
84 * @brief Structure representing properties related to host memory.
85 *
86 * The ShHostMemoryProperties structure represents properties related to host memory in the `shengine` framework,
87 * including buffer count, buffer sizes, buffer strides, buffer offsets, and pointers to buffer memory.
88 */
89typedef struct ShHostMemoryProperties {
90 uint32_t buffer_count; /**< Buffer count. */
91 uint32_t buffers_size [SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]; /**< Buffer sizes. */
92 uint32_t buffers_stride [SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]; /**< Buffer strides. */
93 uint32_t buffers_offset [SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]; /**< Buffer offsets. */
94 void* p_buffers_memory [SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]; /**< Pointers to buffer memory. */
96
97
98
99#define SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT 512
100
101
102
103/**
104 * @struct ShVulkanMemoryProperties
105 * @brief Structure representing properties related to Vulkan memory.
106 *
107 * The ShVulkanMemoryProperties structure represents properties related to Vulkan memory in the `shengine` framework,
108 * including buffer count, buffer sizes, buffer usages, memory sharing modes, and memory properties.
109 */
111 uint32_t buffer_count; /**< Buffer count. */
112 uint32_t buffers_size [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer sizes. */
113 uint8_t buffers_usage_transfer_src_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer usage for transfer source. */
114 uint8_t buffers_usage_transfer_dst_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer usage for transfer destination. */
115 uint8_t buffers_usage_uniform_buffer_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer usage for uniform buffer. */
116 uint8_t buffers_usage_storage_buffer_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer usage for storage buffer. */
117 uint8_t buffers_usage_index_buffer_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer usage for index buffer. */
118 uint8_t buffers_usage_vertex_buffer_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer usage for vertex buffer. */
119
120 uint8_t buffers_memory_sharing_mode_exclusive [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer memory sharing mode (exclusive). */
121 uint8_t buffers_memory_sharing_mode_concurrent [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer memory sharing mode (concurrent). */
122
123 uint8_t buffers_memory_property_device_local_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer memory property (device local). */
124 uint8_t buffers_memory_property_host_visible_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer memory property (host visible). */
125 uint8_t buffers_memory_property_host_coherent_bit [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Buffer memory property (host coherent). */
126
127 VkBuffer buffers [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Vulkan buffer objects. */
128 VkDeviceMemory buffers_memory [SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]; /**< Vulkan buffer memory objects. */
130
131
132
133/**
134 * @struct ShSerialProperties
135 * @brief Structure representing properties related to serial communication.
136 *
137 * The ShSerialProperties structure represents properties related to serial communication in the `shengine` framework,
138 * including port name, baud rate, read timeout, and read/write bits.
139 */
140typedef struct ShSerialProperties {
141 char port[SH_ENVIRONMENT_STR1024_LENGTH]; /**< Port name. */
142 uint32_t baud_rate; /**< Baud rate. */
143 uint32_t read_timeout_ms; /**< Read timeout in milliseconds. */
144 uint8_t read_bit; /**< Read bit. */
145 uint8_t write_bit; /**< Write bit. */
147
148
149
153//#include <shcomponents/shInputLinker.h>
154
155
156
157/**
158 * @struct ShSceneProperties
159 * @brief Structure representing properties related to the scene.
160 *
161 * The ShSceneProperties structure represents properties related to the scene in the `shengine` framework,
162 * including entity count, and pointers to identity, camera, transform, and host memory linker components.
163 */
164typedef struct ShSceneProperties {
165 uint32_t entity_count; /**< Entity count. */
166 ShIdentity* p_identities; /**< Pointers to identity components. */
167 ShCamera* p_cameras; /**< Pointers to camera components. */
168 ShTransform* p_transforms; /**< Pointers to transform components. */
169 //ShHostMemoryLinker* p_host_memory_linkers;
171
172
173
174/**
175 * @brief Function to get INI properties from a file.
176 *
177 * This function retrieves INI properties from the specified INI file and initializes the corresponding structures.
178 *
179 * @param ini_file_path Path to the INI file.
180 * @param p_ini_smd Pointer to an `SmdFileHandle` structure for INI properties.
181 * @param p_ini_properties Pointer to the ShIniProperties structure to store the retrieved INI properties.
182 * @return 1 on success, 0 on failure.
183 */
184extern uint8_t shGetIniProperties(
185 const char* ini_file_path,
186 SmdFileHandle* p_ini_smd,
187 ShIniProperties* p_ini_properties
188);
189
190/**
191 * @brief Function to get application properties from a file.
192 *
193 * This function retrieves application properties from the specified application file and initializes the corresponding structures.
194 *
195 * @param application_file_path Path to the application file.
196 * @param p_application_smd Valid pointer to an `SmdFileHandle` structure for application properties.
197 * @param p_application_properties Pointer to the ShApplicationProperties structure to store the retrieved application properties.
198 * @return 1 on success, 0 on failure.
199 */
200extern uint8_t shGetApplicationProperties(
201 const char* application_file_path,
202 SmdFileHandle* p_application_smd,
203 ShApplicationProperties* p_application_properties
204);
205
206/**
207 * @brief Function to get host memory properties from a file.
208 *
209 * This function retrieves host memory properties from the specified card inputs file and initializes the corresponding structures.
210 *
211 * @param card_inputs_file_path Path to the card inputs file.
212 * @param p_card_inputs_smd Pointer to an `SmdFileHandle` structure for host memory properties.
213 * @param p_card_inputs_properties Pointer to the ShHostMemoryProperties structure to store the retrieved host memory properties.
214 * @return 1 on success, 0 on failure.
215 */
216extern uint8_t shGetHostMemoryProperties(
217 const char* card_inputs_file_path,
218 SmdFileHandle* p_card_inputs_smd,
219 ShHostMemoryProperties* p_card_inputs_properties
220);
221
222/**
223 * @brief Function to get Vulkan memory properties from a file.
224 *
225 * This function retrieves Vulkan memory properties from the specified Vulkan memory file and initializes the corresponding structures.
226 *
227 * @param vulkan_memory_file_path Path to the Vulkan memory file.
228 * @param p_vulkan_memory_smd Pointer to an `SmdFileHandle` structure for Vulkan memory properties.
229 * @param p_vulkan_memory_properties Pointer to the ShVulkanMemoryProperties structure to store the retrieved Vulkan memory properties.
230 * @return 1 on success, 0 on failure.
231 */
232extern uint8_t shGetVulkanMemoryProperties(
233 const char* vulkan_memory_file_path,
234 SmdFileHandle* p_vulkan_memory_smd,
235 ShVulkanMemoryProperties* p_vulkan_memory_properties
236);
237
238/**
239 * @brief Retrieves serial properties from a specified file.
240 *
241 * @param serial_file_path Path to the serial file.
242 * @param p_serial_smd Valid pointer to an `SmdFileHandle` structure for serial.
243 * @param p_serial_properties Valid pointer to an @ref ShSerialProperties structure.
244 *
245 * @return 1 on success, 0 on failure.
246 */
247extern uint8_t shGetSerialProperties(
248 const char* serial_file_path,
249 SmdFileHandle* p_serial_smd,
250 ShSerialProperties* p_serial_properties
251);
252
253/**
254 * @brief Retrieves scene properties from a specified file.
255 *
256 * @param scene_file_path Path to the scene file.
257 * @param p_scene_smd Valid pointer to an `SmdFileHandle` structure for the scene.
258 * @param p_scene_properties Valid pointer to an @ref ShSceneProperties structure.
259 *
260 * @return 1 on success, 0 on failure.
261 */
262extern uint8_t shGetSceneProperties(
263 const char* scene_file_path,
264 SmdFileHandle* p_scene_smd,
265 ShSceneProperties* p_scene_properties
266);
267
268/**
269 * @brief Macro to get file statistics.
270 *
271 * @param path File path.
272 * @param stats Pointer to a structure to store file statistics.
273 */
274#define shGetFileStats(path, stats)\
275 stat(path, stats)
276
277/**
278 * @brief Macro to initialize a descriptor handle.
279 *
280 * @param p_descriptor_handle Valid pointer to a descriptor handle.
281 */
282#define shInitDescriptor(p_descriptor_handle)\
283 shGetFileStats((p_descriptor_handle)->path, &(p_descriptor_handle)->stats0)
284
285/**
286 * @brief Macro for handling environment errors.
287 *
288 * @param condition Condition to check.
289 * @param msg Error message.
290 * @param failure_expression Expression to execute in case of failure.
291 */
292#define shEnvironmentError(condition, msg, failure_expression)\
293 if ((int)(condition)) { printf("shenvironment error: %s.\n", msg); failure_expression; }
294
295
296
297#ifdef __cplusplus
298}
299#endif//__cplusplus
300
301#endif//SH_ENGINE_DESCRIPTOR_H
Defines the ShCamera structure and related constants and functions.
uint8_t shGetSceneProperties(const char *scene_file_path, SmdFileHandle *p_scene_smd, ShSceneProperties *p_scene_properties)
Retrieves scene properties from a specified file.
Definition shEnvironment.c:459
uint8_t shGetIniProperties(const char *ini_file_path, SmdFileHandle *p_ini_smd, ShIniProperties *p_ini_properties)
Function to get INI properties from a file.
Definition shEnvironment.c:20
#define SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT
Definition shEnvironment.h:78
uint8_t shGetHostMemoryProperties(const char *card_inputs_file_path, SmdFileHandle *p_card_inputs_smd, ShHostMemoryProperties *p_card_inputs_properties)
Function to get host memory properties from a file.
Definition shEnvironment.c:150
uint8_t shGetVulkanMemoryProperties(const char *vulkan_memory_file_path, SmdFileHandle *p_vulkan_memory_smd, ShVulkanMemoryProperties *p_vulkan_memory_properties)
Function to get Vulkan memory properties from a file.
Definition shEnvironment.c:239
uint8_t shGetSerialProperties(const char *serial_file_path, SmdFileHandle *p_serial_smd, ShSerialProperties *p_serial_properties)
Retrieves serial properties from a specified file.
Definition shEnvironment.c:400
#define SH_ENVIRONMENT_STR512_LENGTH
Definition shEnvironment.h:35
#define SH_ENVIRONMENT_STR1024_LENGTH
Definition shEnvironment.h:36
uint8_t shGetApplicationProperties(const char *application_file_path, SmdFileHandle *p_application_smd, ShApplicationProperties *p_application_properties)
Function to get application properties from a file.
Definition shEnvironment.c:79
#define SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT
Definition shEnvironment.h:99
Defines the ShIdentity structure and related constants.
Defines the ShTransform structure for representing transformations in the engine.
Structure representing properties related to the application.
Definition shEnvironment.h:65
char s_update[SH_ENVIRONMENT_STR512_LENGTH]
Definition shEnvironment.h:68
char s_frame_resize[SH_ENVIRONMENT_STR512_LENGTH]
Definition shEnvironment.h:71
char s_start[SH_ENVIRONMENT_STR512_LENGTH]
Definition shEnvironment.h:67
uint32_t additional_thread_count
Definition shEnvironment.h:73
char shared_name[SH_ENVIRONMENT_STR512_LENGTH]
Definition shEnvironment.h:66
char s_main_renderpass[SH_ENVIRONMENT_STR512_LENGTH]
Definition shEnvironment.h:70
char s_main_cmd_buffer[SH_ENVIRONMENT_STR512_LENGTH]
Definition shEnvironment.h:69
char s_close[SH_ENVIRONMENT_STR512_LENGTH]
Definition shEnvironment.h:72
Represents a camera component in scene.
Definition shCamera.h:23
Structure representing properties related to host memory.
Definition shEnvironment.h:89
uint32_t buffer_count
Definition shEnvironment.h:90
uint32_t buffers_stride[SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]
Definition shEnvironment.h:92
void * p_buffers_memory[SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]
Definition shEnvironment.h:94
uint32_t buffers_size[SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]
Definition shEnvironment.h:91
uint32_t buffers_offset[SH_ENVIRONMENT_MAX_HOST_BUFFER_COUNT]
Definition shEnvironment.h:93
Represents an identity component in scene.
Definition shIdentity.h:28
Structure representing properties related to the initialization (INI) file.
Definition shEnvironment.h:47
char application_name[SH_ENVIRONMENT_STR1024_LENGTH]
Definition shEnvironment.h:48
char vulkan_memory_smd_path[SH_ENVIRONMENT_STR1024_LENGTH]
Definition shEnvironment.h:51
char scene_smd_path[SH_ENVIRONMENT_STR1024_LENGTH]
Definition shEnvironment.h:53
char host_memory_smd_path[SH_ENVIRONMENT_STR1024_LENGTH]
Definition shEnvironment.h:50
char application_smd_path[SH_ENVIRONMENT_STR1024_LENGTH]
Definition shEnvironment.h:49
char serial_smd_path[SH_ENVIRONMENT_STR1024_LENGTH]
Definition shEnvironment.h:52
Structure representing properties related to the scene.
Definition shEnvironment.h:164
ShTransform * p_transforms
Definition shEnvironment.h:168
ShIdentity * p_identities
Definition shEnvironment.h:166
uint32_t entity_count
Definition shEnvironment.h:165
ShCamera * p_cameras
Definition shEnvironment.h:167
Structure representing properties related to serial communication.
Definition shEnvironment.h:140
uint8_t read_bit
Definition shEnvironment.h:144
uint32_t read_timeout_ms
Definition shEnvironment.h:143
uint32_t baud_rate
Definition shEnvironment.h:142
char port[SH_ENVIRONMENT_STR1024_LENGTH]
Definition shEnvironment.h:141
uint8_t write_bit
Definition shEnvironment.h:145
Represents a transformation in the engine.
Definition shTransform.h:21
Structure representing properties related to Vulkan memory.
Definition shEnvironment.h:110
uint32_t buffer_count
Definition shEnvironment.h:111
uint8_t buffers_usage_index_buffer_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:117
VkDeviceMemory buffers_memory[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:128
uint8_t buffers_memory_property_host_visible_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:124
uint8_t buffers_memory_property_host_coherent_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:125
uint8_t buffers_usage_uniform_buffer_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:115
VkBuffer buffers[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:127
uint8_t buffers_memory_sharing_mode_exclusive[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:120
uint8_t buffers_usage_transfer_dst_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:114
uint8_t buffers_usage_vertex_buffer_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:118
uint8_t buffers_memory_property_device_local_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:123
uint8_t buffers_memory_sharing_mode_concurrent[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:121
uint32_t buffers_size[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:112
uint8_t buffers_usage_transfer_src_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:113
uint8_t buffers_usage_storage_buffer_bit[SH_ENVIRONMENT_MAX_VULKAN_BUFFER_COUNT]
Definition shEnvironment.h:116