Files
SimpleRayTracing/header/Common/String.h
Misaki fb1ff5cac6 Update rendering, material handling, and shading logic
Changed README.md to update rendering settings and build instructions.
Changed BSDF.h to add functions for normal unpacking and tangent transformation.
Changed RayIntersection.h to include tangent vector in hit_result_t.
Changed Common.h to include vec2.h for 2D vector handling.
Changed String.h to add string_copy function and improve is_absolute_path.
Changed GeometryUtilities.h to enhance quad creation with tangent calculations.
Changed Mesh.h to include tangents in the vertex structure.
Changed Triangle.h to add tangents in the vertex structure for better normal mapping.
Changed Light.h to include tangents in the light shading context.
Changed SkyLight.h to introduce a new structure for sky lights.
Changed Material.h to include tangents in the shading context.
Changed SimpleLit.h to add normal and tangent textures for detailed shading.
Changed Texture.h to introduce a new structure for texture assets.
Changed BSDF.c to add functions for unpacking normals and transforming tangents.
Changed PathTracing.c to include tangents in the shading context.
Changed RayIntersection.c to calculate normals and tangents in ray-triangle intersections.
Changed Mesh.c to improve material texture loading and handle tangents.
Changed Material.c to enhance material collection initialization and resizing.
Changed SimpleLit.c to incorporate normal mapping with normal textures.
Changed Texture.c to improve management of texture assets and resources.
2025-04-29 17:58:10 +09:00

106 lines
1.9 KiB
C

#ifndef STRING_H
#define STRING_H
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
inline char* string_copy(const char* source)
{
if (source == NULL)
{
return NULL;
}
size_t len = strlen(source) + 1;
char* copy = (char*)malloc(len);
if (copy == NULL)
{
return NULL;
}
strcpy_s(copy, len, source);
return copy;
}
inline bool is_absolute_path(const char* path)
{
if (path == NULL)
{
return false;
}
#ifdef _WIN32
// 1) Drive-letter paths: "C:\…", "D:/…"
if (isalpha((unsigned char)path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/'))
{
return true;
}
// 2) UNC paths: "\\server\share\…"
if (path[0] == '\\' && path[1] == '\\')
{
return true;
}
return false;
#else
// POSIX: anything starting with '/'
return path[0] == '/';
#endif
}
inline void get_path_directory(const char* path, char* out, size_t out_size)
{
if (path == NULL || out == NULL || out_size == 0)
{
if (out && out_size > 0)
{
out[0] = '\0'; // ensure output is empty on invalid input
}
return;
}
const char* last_slash = strrchr(path, '/');
if (last_slash == NULL)
{
if (out_size > 0)
{
out[0] = '\0';
}
return;
}
size_t dir_len = (size_t)(last_slash - path + 1);
if (dir_len >= out_size)
{
dir_len = out_size - 1;
}
memcpy(out, path, dir_len);
out[dir_len - 1] = '/';
out[dir_len] = '\0';
}
inline void string_join(const char* a, const char* b, char* out, size_t out_size)
{
if (a == NULL || b == NULL || out == NULL || out_size == 0)
{
return;
}
size_t a_len = strlen(a);
size_t b_len = strlen(b);
if (a_len + b_len + 1 >= out_size)
{
return;
}
strcpy_s(out, out_size, a);
strcat_s(out, out_size, b);
}
#endif // STRING_H