MSVC support

This commit is contained in:
JackCarterSmith 2022-07-29 18:02:55 +02:00
parent 5e8a219c0d
commit 52299176be
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
7 changed files with 52 additions and 29 deletions

View File

@ -42,10 +42,10 @@ add_executable(rse-model ${RSE_MOD_SRCS} ${RSE_MOD_HRDS})
set_target_properties(rse-model PROPERTIES OUTPUT_NAME ${RSE_MOD_NAME}) set_target_properties(rse-model PROPERTIES OUTPUT_NAME ${RSE_MOD_NAME})
if(MSVC) if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name # msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rse-model PROPERTIES PREFIX "lib") #set_target_properties(rse-model PROPERTIES PREFIX "lib")
set_target_properties(rse-model PROPERTIES IMPORT_PREFIX "lib") set_target_properties(rse-model PROPERTIES IMPORT_PREFIX "lib")
endif() endif()
target_link_libraries(rse-model m) target_link_libraries(rse-model)
# add GPG signature command # add GPG signature command
#add_custom_command( #add_custom_command(

View File

@ -46,7 +46,7 @@ Due to issue with copyrights, I can't provide samples... You need to extract HOB
You can compile on both Windows (MinGW) or native Linux system thanks to CMake. You can compile on both Windows (MinGW) or native Linux system thanks to CMake.
To compile, just clone and launch cmake: To compile, just clone (**don't forget git submodules**) and launch cmake:
```shell ```shell
cmake . cmake .

View File

@ -30,7 +30,7 @@
static unsigned int mainProcess(int args_cnt, char *args_value[]); static unsigned int mainProcess(int args_cnt, char *args_value[]);
static void createSubDir(char *dirName); static void createSubDir(char *dirName);
static int checkInputArgs(int arg_nbr, char *args[]); static unsigned int checkInputArgs(int arg_nbr, char *args[]);
static void cleanUpMemory(T_HOB* hobStruct); static void cleanUpMemory(T_HOB* hobStruct);
//int exportTextures(HMT_FILE *hmt_f, char *filename); //int exportTextures(HMT_FILE *hmt_f, char *filename);
static inline void dispHelp(); static inline void dispHelp();
@ -40,7 +40,7 @@ static inline void dispHelp();
* Global variables declaration * Global variables declaration
*/ */
int _options; // Global options settings variable unsigned int _options; // Global options settings variable
/* /*
@ -103,8 +103,8 @@ static unsigned int mainProcess(int args_cnt, char *args_value[]) {
return NO_ERROR; return NO_ERROR;
} }
static int checkInputArgs(int arg_nbr, char *args[]) { static unsigned int checkInputArgs(int arg_nbr, char *args[]) {
int _o = (OUTPUT_DIR | EXPORT_MTL); // Default options parameters unsigned int _o = (OUTPUT_DIR | EXPORT_MTL); // Default options parameters
char test[256]; char test[256];
int i; int i;
@ -118,18 +118,18 @@ static int checkInputArgs(int arg_nbr, char *args[]) {
} else if (strcmp(args[i], "-v") == 0) { } else if (strcmp(args[i], "-v") == 0) {
_o |= VERBOSE_ENABLED; _o |= VERBOSE_ENABLED;
printf("[OPTN] Verbose enabled.\n"); printf("[OPTN] Verbose enabled.\n");
} else if (strcmp(args[i], "-no-subdir") == 0) {
_o &= ~OUTPUT_DIR;
printf("[OPTN] Export to current directory.\n");
} else if (strcmp(args[i], "-mtl") == 0) {
_o &= ~EXPORT_MTL;
printf("[OPTN] No materials datas.\n");
} else if (strcmp(args[i], "-vv") == 0) { } else if (strcmp(args[i], "-vv") == 0) {
_o |= DEBUG_MODE; _o |= DEBUG_MODE;
printf("[OPTN] Verbose enabled.\n"); printf("[OPTN] Verbose enabled.\n");
} else if (strcmp(args[i], "-vvv") == 0) { } else if (strcmp(args[i], "-vvv") == 0) {
_o |= GOD_MODE; _o |= GOD_MODE;
printf("[OPTN] Verbose enabled.\n"); printf("[OPTN] Verbose enabled.\n");
} else if (strcmp(args[i], "-no-subdir") == 0) {
_o &= ~OUTPUT_DIR;
printf("[OPTN] Export to current directory.\n");
} else if (strcmp(args[i], "-mtl") == 0) {
_o &= ~EXPORT_MTL;
printf("[OPTN] No materials datas.\n");
} else { } else {
printf("[ERR] Unknown option: %s\n", args[i]); printf("[ERR] Unknown option: %s\n", args[i]);
} }

View File

@ -5,12 +5,15 @@
* Author: JackCarterSmith * Author: JackCarterSmith
*/ */
#include "error.h" //TODO: use it as base for error ID //#include "error.h" //TODO: use it as base for error ID
#ifndef SRC_ERRORS_TYPES_H_ #ifndef SRC_ERRORS_TYPES_H_
#define SRC_ERRORS_TYPES_H_ #define SRC_ERRORS_TYPES_H_
#ifdef NO_ERROR
#undef NO_ERROR
#endif
#define NO_ERROR 0 #define NO_ERROR 0
#define ERROR_GENERIC 1 #define ERROR_GENERIC 1
#define ERROR_MEMORY 2 #define ERROR_MEMORY 2

View File

@ -16,6 +16,12 @@
* car = 8bits * car = 8bits
*/ */
#if defined(_MSC_VER)
#define PACK
#elif defined(__GNUC__)
#define PACK __attribute__((packed))
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// HOB file structure // HOB file structure
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -105,12 +111,16 @@ typedef struct hob {
// Caution: the place of variable is important for correct mapping! // Caution: the place of variable is important for correct mapping!
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
typedef struct __attribute__((packed)) hobfile_header { #if defined(_MSC_VER)
#pragma pack(push, 1)
#endif
typedef struct PACK hobfile_header {
unsigned int obj_count; unsigned int obj_count;
unsigned int vertices_offset; unsigned int vertices_offset;
} T_HOBFILE_HEADER; } T_HOBFILE_HEADER;
typedef struct __attribute__((packed)) hobfile_obj_descriptor { typedef struct PACK hobfile_obj_descriptor {
unsigned char object_name[16]; unsigned char object_name[16];
unsigned int facegroup_offset; unsigned int facegroup_offset;
unsigned int object_parts_offset; unsigned int object_parts_offset;
@ -143,17 +153,17 @@ typedef struct __attribute__((packed)) hobfile_obj_descriptor {
float reserved17; float reserved17;
} T_HOBFILE_OBJ_DESCRIPTOR; } T_HOBFILE_OBJ_DESCRIPTOR;
typedef struct __attribute__((packed)) hobfile_facegroup_header { typedef struct PACK hobfile_facegroup_header {
unsigned short object_part_count; unsigned short object_part_count;
unsigned short facegroup_count; unsigned short facegroup_count;
} T_HOBFILE_FACEGROUP_HEADER; } T_HOBFILE_FACEGROUP_HEADER;
typedef struct __attribute__((packed)) hobfile_facegroup_offset { typedef struct PACK hobfile_facegroup_offset {
unsigned int unknown1; unsigned int unknown1;
unsigned int facegroup_offset; unsigned int facegroup_offset;
} T_HOBFILE_FACEGROUP_OFFSET; } T_HOBFILE_FACEGROUP_OFFSET;
typedef struct __attribute__((packed)) hobfile_meshdef0 { typedef struct PACK hobfile_meshdef0 {
unsigned int offset1; unsigned int offset1;
unsigned int offset2; unsigned int offset2;
unsigned int prev_meshdef0_offset; unsigned int prev_meshdef0_offset;
@ -201,7 +211,7 @@ typedef struct __attribute__((packed)) hobfile_meshdef0 {
float transform_z; float transform_z;
} T_HOBFILE_MESHDEF0; } T_HOBFILE_MESHDEF0;
typedef struct __attribute__((packed)) hobfile_meshdef1 { typedef struct PACK hobfile_meshdef1 {
unsigned int facedef_end_offset; unsigned int facedef_end_offset;
unsigned int reserved1; // 20B of zeros unsigned int reserved1; // 20B of zeros
@ -231,7 +241,7 @@ typedef struct __attribute__((packed)) hobfile_meshdef1 {
unsigned int reserved19; unsigned int reserved19;
} T_HOBFILE_MESHDEF1; } T_HOBFILE_MESHDEF1;
typedef struct __attribute__((packed)) hobfile_faceblock { typedef struct PACK hobfile_faceblock {
unsigned int reserved1; // 8B of zeros unsigned int reserved1; // 8B of zeros
unsigned int reserved2; unsigned int reserved2;
@ -239,7 +249,7 @@ typedef struct __attribute__((packed)) hobfile_faceblock {
unsigned int faceCounts; unsigned int faceCounts;
} T_HOBFILE_FACEBLOCK; } T_HOBFILE_FACEBLOCK;
typedef struct __attribute__((packed)) hobfile_faces_header { typedef struct PACK hobfile_faces_header {
unsigned int flags; unsigned int flags;
unsigned char b1; unsigned char b1;
unsigned char b2; unsigned char b2;
@ -250,29 +260,33 @@ typedef struct __attribute__((packed)) hobfile_faces_header {
unsigned short vertexIndices[4]; // Relative to facegroup, the last value is equal to 0 when it's triangle shape. unsigned short vertexIndices[4]; // Relative to facegroup, the last value is equal to 0 when it's triangle shape.
} T_HOBFILE_FACES_HEADER; } T_HOBFILE_FACES_HEADER;
typedef struct __attribute__((packed)) hobfile_faces_extra_vertex_color { typedef struct PACK hobfile_faces_extra_vertex_color {
T_RGBA v1_rgba; T_RGBA v1_rgba;
T_RGBA v2_rgba; T_RGBA v2_rgba;
T_RGBA v3_rgba; T_RGBA v3_rgba;
T_RGBA v4_rgba; // Used with quad type face T_RGBA v4_rgba; // Used with quad type face
} T_HOBFILE_FACES_VERTEX_COLOR; } T_HOBFILE_FACES_VERTEX_COLOR;
typedef struct __attribute__((packed)) hobfile_faces_extra_color { typedef struct PACK hobfile_faces_extra_color {
T_RGBA rgba; T_RGBA rgba;
} T_HOBFILE_FACES_COLOR; } T_HOBFILE_FACES_COLOR;
typedef struct __attribute__((packed)) hobfile_faces_extra_vertex_texture { typedef struct PACK hobfile_faces_extra_vertex_texture {
T_TEXCOORD v1_texcoord; // Should be divided (no shifting) by 4096 to get 0...1 range T_TEXCOORD v1_texcoord; // Should be divided (no shifting) by 4096 to get 0...1 range
T_TEXCOORD v2_texcoord; T_TEXCOORD v2_texcoord;
T_TEXCOORD v3_texcoord; T_TEXCOORD v3_texcoord;
T_TEXCOORD v4_texcoord; // Used with quad type face T_TEXCOORD v4_texcoord; // Used with quad type face
} T_HOBFILE_FACES_VERTEX_TEXTURE; } T_HOBFILE_FACES_VERTEX_TEXTURE;
typedef struct __attribute__((packed)) hobfile_vertex { typedef struct PACK hobfile_vertex {
short x; short x;
short y; short y;
short z; short z;
short w; short w;
} T_HOBFILE_VERTEX; } T_HOBFILE_VERTEX;
#if defined(_MSC_VER)
#pragma pack(pop)
#endif
#endif /* SRC_HOB_STRUCT_H_ */ #endif /* SRC_HOB_STRUCT_H_ */

View File

@ -107,7 +107,9 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) {
if (_options & EXPORT_MTL) { if (_options & EXPORT_MTL) {
obj_write(objConstruct, objExport_path, mtlExport_path, 8); obj_write(objConstruct, objExport_path, mtlExport_path, 8);
#if defined(__GNUC__) //TODO: review MSVC file management or include and rewrite obj lib?
if (_options & OUTPUT_DIR) mtlPathPatch(objExport_path, hob_objects->name); if (_options & OUTPUT_DIR) mtlPathPatch(objExport_path, hob_objects->name);
#endif
} else obj_write(objConstruct, objExport_path, NULL, 8); } else obj_write(objConstruct, objExport_path, NULL, 8);
obj_delete(objConstruct); obj_delete(objConstruct);
@ -150,7 +152,11 @@ static void mtlPathPatch(const char* out_file, const char* obj_name) {
// Begin rewrite file // Begin rewrite file
obj = fopen(out_file, "w"); obj = fopen(out_file, "w");
fprintf(obj, "mtllib %s", _path); fprintf(obj, "mtllib %s", _path);
#if defined(_MSC_VER)
fwrite(memFile, fileSize - pos , 1, obj);
#elif defined(__GNUC__)
fwrite(memFile, fileSize - (pos + lines), 1, obj); fwrite(memFile, fileSize - (pos + lines), 1, obj);
#endif
free(memFile); free(memFile);
} }

View File

@ -4,9 +4,9 @@
#define VERBOSE_ENABLED 0x0001 // Simple details about ID and other "light" things #define VERBOSE_ENABLED 0x0001 // Simple details about ID and other "light" things
#define OUTPUT_DIR 0x0002 #define OUTPUT_DIR 0x0002
#define EXPORT_MTL 0x0004 #define EXPORT_MTL 0x0004
#define DEBUG_MODE 0x0011 // Output all values of faces, indices and vertices and others "heavy" things #define DEBUG_MODE 0x0010 // Output all values of faces, indices and vertices and others "heavy" things
#define GOD_MODE 0x1111 // Dev only. Output experimental values. #define GOD_MODE 0x0100 // Dev only. Output experimental values.
extern int _options; extern unsigned int _options;
#endif #endif