Explorar o código

Improving rRES custom format support -IN PROGRESS-

Start removing old rRES functions.
Ray %!s(int64=8) %!d(string=hai) anos
pai
achega
814507906f
Modificáronse 6 ficheiros con 9 adicións e 379 borrados
  1. 1 115
      src/audio.c
  2. 4 3
      src/core.c
  3. 0 85
      src/models.c
  4. 0 4
      src/raylib.h
  5. 4 130
      src/textures.c
  6. 0 42
      src/utils.c

+ 1 - 115
src/audio.c

@@ -52,8 +52,7 @@
     #include <stdarg.h>         // Required for: va_list, va_start(), vfprintf(), va_end()
 #else
     #include "raylib.h"
-    #include "utils.h"          // Required for: DecompressData()
-                                // NOTE: Includes Android fopen() function map
+    #include "utils.h"          // Required for: fopen() Android mapping, TraceLog()
 #endif
 
 #include "AL/al.h"              // OpenAL basic header
@@ -324,119 +323,6 @@ Sound LoadSoundFromWave(Wave wave)
     return sound;
 }
 
-// Load sound to memory from rRES file (raylib Resource)
-// TODO: Maybe rresName could be directly a char array with all the data?
-Sound LoadSoundFromRES(const char *rresName, int resId)
-{
-    Sound sound = { 0 };
-
-#if defined(AUDIO_STANDALONE)
-    TraceLog(WARNING, "Sound loading from rRES resource file not supported on standalone mode");
-#else
-
-    bool found = false;
-
-    char id[4];             // rRES file identifier
-    unsigned char version;  // rRES file version and subversion
-    char useless;           // rRES header reserved data
-    short numRes;
-
-    ResInfoHeader infoHeader;
-
-    FILE *rresFile = fopen(rresName, "rb");
-
-    if (rresFile == NULL) TraceLog(WARNING, "[%s] rRES raylib resource file could not be opened", rresName);
-    else
-    {
-        // Read rres file (basic file check - id)
-        fread(&id[0], sizeof(char), 1, rresFile);
-        fread(&id[1], sizeof(char), 1, rresFile);
-        fread(&id[2], sizeof(char), 1, rresFile);
-        fread(&id[3], sizeof(char), 1, rresFile);
-        fread(&version, sizeof(char), 1, rresFile);
-        fread(&useless, sizeof(char), 1, rresFile);
-
-        if ((id[0] != 'r') && (id[1] != 'R') && (id[2] != 'E') &&(id[3] != 'S'))
-        {
-            TraceLog(WARNING, "[%s] This is not a valid raylib resource file", rresName);
-        }
-        else
-        {
-            // Read number of resources embedded
-            fread(&numRes, sizeof(short), 1, rresFile);
-
-            for (int i = 0; i < numRes; i++)
-            {
-                fread(&infoHeader, sizeof(ResInfoHeader), 1, rresFile);
-
-                if (infoHeader.id == resId)
-                {
-                    found = true;
-
-                    // Check data is of valid SOUND type
-                    if (infoHeader.type == 1)   // SOUND data type
-                    {
-                        // TODO: Check data compression type
-                        // NOTE: We suppose compression type 2 (DEFLATE - default)
-
-                        // Reading SOUND parameters
-                        Wave wave;
-                        short sampleRate, bps;
-                        char channels, reserved;
-
-                        fread(&sampleRate, sizeof(short), 1, rresFile); // Sample rate (frequency)
-                        fread(&bps, sizeof(short), 1, rresFile);        // Bits per sample
-                        fread(&channels, 1, 1, rresFile);               // Channels (1 - mono, 2 - stereo)
-                        fread(&reserved, 1, 1, rresFile);               // <reserved>
-
-                        wave.sampleRate = sampleRate;
-                        wave.sampleSize = bps;
-                        wave.channels = (short)channels;
-
-                        unsigned char *data = malloc(infoHeader.size);
-
-                        fread(data, infoHeader.size, 1, rresFile);
-
-                        wave.data = DecompressData(data, infoHeader.size, infoHeader.srcSize);
-
-                        free(data);
-
-                        sound = LoadSoundFromWave(wave);
-
-                        // Sound is loaded, we can unload wave data
-                        UnloadWave(wave);
-                    }
-                    else TraceLog(WARNING, "[%s] Required resource do not seem to be a valid SOUND resource", rresName);
-                }
-                else
-                {
-                    // Depending on type, skip the right amount of parameters
-					/* TODO: Review
-                    switch (infoHeader.type)
-                    {
-                        case 0: fseek(rresFile, 6, SEEK_CUR); break;   // IMAGE: Jump 6 bytes of parameters
-                        case 1: fseek(rresFile, 6, SEEK_CUR); break;   // SOUND: Jump 6 bytes of parameters
-                        case 2: fseek(rresFile, 5, SEEK_CUR); break;   // MODEL: Jump 5 bytes of parameters (TODO: Review)
-                        case 3: break;   // TEXT: No parameters
-                        case 4: break;   // RAW: No parameters
-                        default: break;
-                    }
-					*/
-
-                    // Jump DATA to read next infoHeader
-                    fseek(rresFile, infoHeader.size, SEEK_CUR);
-                }
-            }
-        }
-
-        fclose(rresFile);
-    }
-
-    if (!found) TraceLog(WARNING, "[%s] Required resource id [%i] could not be found in the raylib resource file", rresName, resId);
-#endif
-    return sound;
-}
-
 // Unload Wave data
 void UnloadWave(Wave wave)
 {

+ 4 - 3
src/core.c

@@ -42,13 +42,14 @@
 *
 **********************************************************************************************/
 
-#include "raylib.h"         // raylib main header
+#include "raylib.h"
+
 #include "rlgl.h"           // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
-#include "utils.h"          // Includes Android fopen map, InitAssetManager(), TraceLog()
+#include "utils.h"          // Required for: fopen() Android mapping, TraceLog()
 
 #define RAYMATH_IMPLEMENTATION  // Use raymath as a header-only library (includes implementation)
 #define RAYMATH_EXTERN_INLINE   // Compile raymath functions as static inline (remember, it's a compiler hint)
-#include "raymath.h"            // Required for Vector3 and Matrix functions
+#include "raymath.h"            // Required for: Vector3 and Matrix functions
 
 #define GESTURES_IMPLEMENTATION
 #include "gestures.h"       // Gestures detection functionality

+ 0 - 85
src/models.c

@@ -648,91 +648,6 @@ Model LoadModelEx(Mesh data, bool dynamic)
     return model;
 }
 
-// Load a 3d model from rRES file (raylib Resource)
-Model LoadModelFromRES(const char *rresName, int resId)
-{
-    Model model = { 0 };
-    bool found = false;
-
-    char id[4];             // rRES file identifier
-    unsigned char version;  // rRES file version and subversion
-    char useless;           // rRES header reserved data
-    short numRes;
-
-    ResInfoHeader infoHeader;
-
-    FILE *rresFile = fopen(rresName, "rb");
-
-    if (rresFile == NULL)
-    {
-        TraceLog(WARNING, "[%s] rRES raylib resource file could not be opened", rresName);
-    }
-    else
-    {
-        // Read rres file (basic file check - id)
-        fread(&id[0], sizeof(char), 1, rresFile);
-        fread(&id[1], sizeof(char), 1, rresFile);
-        fread(&id[2], sizeof(char), 1, rresFile);
-        fread(&id[3], sizeof(char), 1, rresFile);
-        fread(&version, sizeof(char), 1, rresFile);
-        fread(&useless, sizeof(char), 1, rresFile);
-
-        if ((id[0] != 'r') && (id[1] != 'R') && (id[2] != 'E') &&(id[3] != 'S'))
-        {
-            TraceLog(WARNING, "[%s] This is not a valid raylib resource file", rresName);
-        }
-        else
-        {
-            // Read number of resources embedded
-            fread(&numRes, sizeof(short), 1, rresFile);
-
-            for (int i = 0; i < numRes; i++)
-            {
-                fread(&infoHeader, sizeof(ResInfoHeader), 1, rresFile);
-
-                if (infoHeader.id == resId)
-                {
-                    found = true;
-
-                    // Check data is of valid MODEL type
-                    if (infoHeader.type == 8)
-                    {
-                        // TODO: Load model data
-                    }
-                    else
-                    {
-                        TraceLog(WARNING, "[%s] Required resource do not seem to be a valid MODEL resource", rresName);
-                    }
-                }
-                else
-                {
-                    // Depending on type, skip the right amount of parameters
-					/* Review
-                    switch (infoHeader.type)
-                    {
-                        case 0: fseek(rresFile, 6, SEEK_CUR); break;    // IMAGE: Jump 6 bytes of parameters
-                        case 1: fseek(rresFile, 6, SEEK_CUR); break;    // SOUND: Jump 6 bytes of parameters
-                        case 2: fseek(rresFile, 5, SEEK_CUR); break;    // MODEL: Jump 5 bytes of parameters (TODO: Review)
-                        case 3: break;                                  // TEXT: No parameters
-                        case 4: break;                                  // RAW: No parameters
-                        default: break;
-                    }
-					*/
-
-                    // Jump DATA to read next infoHeader
-                    fseek(rresFile, infoHeader.size, SEEK_CUR);
-                }
-            }
-        }
-
-        fclose(rresFile);
-    }
-
-    if (!found) TraceLog(WARNING, "[%s] Required resource id [%i] could not be found in the raylib resource file", rresName, resId);
-
-    return model;
-}
-
 // Load a heightmap image as a 3d model
 // NOTE: model map size is defined in generic units
 Model LoadHeightmap(Image heightmap, Vector3 size)

+ 0 - 4
src/raylib.h

@@ -770,10 +770,8 @@ RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Ve
 RLAPI Image LoadImage(const char *fileName);                                                             // Load an image into CPU memory (RAM)
 RLAPI Image LoadImageEx(Color *pixels, int width, int height);                                           // Load image data from Color array data (RGBA - 32bit)
 RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize);       // Load image data from RAW file
-RLAPI Image LoadImageFromRES(const char *rresName, int resId);                                           // Load an image from rRES file (raylib Resource)
 RLAPI Texture2D LoadTexture(const char *fileName);                                                       // Load an image as texture into GPU memory
 RLAPI Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat);                     // Load a texture from raw data into GPU memory
-RLAPI Texture2D LoadTextureFromRES(const char *rresName, int resId);                                     // Load an image as texture from rRES file (raylib Resource)
 RLAPI Texture2D LoadTextureFromImage(Image image);                                                       // Load a texture from image data
 RLAPI RenderTexture2D LoadRenderTexture(int width, int height);                                          // Load a texture to be used for rendering
 RLAPI void UnloadImage(Image image);                                                                     // Unload image from CPU memory (RAM)
@@ -857,7 +855,6 @@ RLAPI void DrawLight(Light light);
 //------------------------------------------------------------------------------------
 RLAPI Model LoadModel(const char *fileName);                          // Load a 3d model (.OBJ)
 RLAPI Model LoadModelEx(Mesh data, bool dynamic);                     // Load a 3d model (from mesh data)
-RLAPI Model LoadModelFromRES(const char *rresName, int resId);        // Load a 3d model from rRES file (raylib Resource)
 RLAPI Model LoadHeightmap(Image heightmap, Vector3 size);             // Load a heightmap image as a 3d model
 RLAPI Model LoadCubicmap(Image cubicmap);                             // Load a map image as a 3d model (cubes based)
 RLAPI void UnloadModel(Model model);                                  // Unload 3d model from memory
@@ -933,7 +930,6 @@ RLAPI Wave LoadWave(const char *fileName);                            // Load wa
 RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit)
 RLAPI Sound LoadSound(const char *fileName);                          // Load sound to memory
 RLAPI Sound LoadSoundFromWave(Wave wave);                             // Load sound to memory from wave data
-RLAPI Sound LoadSoundFromRES(const char *rresName, int resId);        // Load sound to memory from rRES file (raylib Resource)
 RLAPI void UpdateSound(Sound sound, void *data, int numSamples);      // Update sound buffer with new data
 RLAPI void UnloadWave(Wave wave);                                     // Unload wave data
 RLAPI void UnloadSound(Sound sound);                                  // Unload sound

+ 4 - 130
src/textures.c

@@ -37,11 +37,10 @@
 #include <string.h>             // Required for: strcmp(), strrchr(), strncmp()
 
 #include "rlgl.h"               // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2
-                                // Required: rlglLoadTexture() rlDeleteTextures(),
-                                //           rlglGenerateMipmaps(), some funcs for DrawTexturePro()
+                                // Required for: rlglLoadTexture() rlDeleteTextures(),
+                                //      rlglGenerateMipmaps(), some funcs for DrawTexturePro()
 
-#include "utils.h"              // rRES data decompression utility function
-                                // NOTE: Includes Android fopen function map
+#include "utils.h"              // Required for: fopen() Android mapping, TraceLog()
 
 // Support only desired texture formats, by default: JPEG, PNG, BMP, TGA
 //#define STBI_NO_JPEG          // Image format .jpg and .jpeg
@@ -216,7 +215,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
 
         fread(image.data, size, 1, rawFile);
 
-        // TODO: Check if data have been read
+        // TODO: Check if data has been read
 
         image.width = width;
         image.height = height;
@@ -229,119 +228,6 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
     return image;
 }
 
-// Load an image from rRES file (raylib Resource)
-// TODO: Review function to support multiple color modes
-Image LoadImageFromRES(const char *rresName, int resId)
-{
-    Image image = { 0 };
-    bool found = false;
-
-    char id[4];             // rRES file identifier
-    unsigned char version;  // rRES file version and subversion
-    char useless;           // rRES header reserved data
-    short numRes;
-
-    ResInfoHeader infoHeader;
-
-    FILE *rresFile = fopen(rresName, "rb");
-
-    if (rresFile == NULL)
-    {
-        TraceLog(WARNING, "[%s] rRES raylib resource file could not be opened", rresName);
-    }
-    else
-    {
-        // Read rres file (basic file check - id)
-        fread(&id[0], sizeof(char), 1, rresFile);
-        fread(&id[1], sizeof(char), 1, rresFile);
-        fread(&id[2], sizeof(char), 1, rresFile);
-        fread(&id[3], sizeof(char), 1, rresFile);
-        fread(&version, sizeof(char), 1, rresFile);
-        fread(&useless, sizeof(char), 1, rresFile);
-
-        if ((id[0] != 'r') && (id[1] != 'R') && (id[2] != 'E') &&(id[3] != 'S'))
-        {
-            TraceLog(WARNING, "[%s] This is not a valid raylib resource file", rresName);
-        }
-        else
-        {
-            // Read number of resources embedded
-            fread(&numRes, sizeof(short), 1, rresFile);
-
-            for (int i = 0; i < numRes; i++)
-            {
-                fread(&infoHeader, sizeof(ResInfoHeader), 1, rresFile);
-
-                if (infoHeader.id == resId)
-                {
-                    found = true;
-
-                    // Check data is of valid IMAGE type
-                    if (infoHeader.type == 0)   // IMAGE data type
-                    {
-                        // TODO: Check data compression type
-                        // NOTE: We suppose compression type 2 (DEFLATE - default)
-
-                        short imgWidth, imgHeight;
-                        char colorFormat, mipmaps;
-
-                        fread(&imgWidth, sizeof(short), 1, rresFile);   // Image width
-                        fread(&imgHeight, sizeof(short), 1, rresFile);  // Image height
-                        fread(&colorFormat, 1, 1, rresFile);            // Image data color format (default: RGBA 32 bit)
-                        fread(&mipmaps, 1, 1, rresFile);                // Mipmap images included (default: 0)
-
-                        image.width = (int)imgWidth;
-                        image.height = (int)imgHeight;
-
-                        unsigned char *compData = malloc(infoHeader.size);
-
-                        fread(compData, infoHeader.size, 1, rresFile);
-
-                        unsigned char *imgData = DecompressData(compData, infoHeader.size, infoHeader.srcSize);
-
-                        // TODO: Review color mode
-                        //image.data = (unsigned char *)malloc(sizeof(unsigned char)*imgWidth*imgHeight*4);
-                        image.data = imgData;
-
-                        //free(imgData);
-
-                        free(compData);
-
-                        TraceLog(INFO, "[%s] Image loaded successfully from resource, size: %ix%i", rresName, image.width, image.height);
-                    }
-                    else
-                    {
-                        TraceLog(WARNING, "[%s] Required resource do not seem to be a valid IMAGE resource", rresName);
-                    }
-                }
-                else
-                {
-                    // Depending on type, skip the right amount of parameters
-					/* TODO: Review
-                    switch (infoHeader.type)
-                    {
-                        case 0: fseek(rresFile, 6, SEEK_CUR); break;    // IMAGE: Jump 6 bytes of parameters
-                        case 1: fseek(rresFile, 6, SEEK_CUR); break;    // SOUND: Jump 6 bytes of parameters
-                        case 2: fseek(rresFile, 5, SEEK_CUR); break;    // MODEL: Jump 5 bytes of parameters (TODO: Review)
-                        case 3: break;                                  // TEXT: No parameters
-                        case 4: break;                                  // RAW: No parameters
-                        default: break;
-                    }
-					*/
-                    // Jump DATA to read next infoHeader
-                    fseek(rresFile, infoHeader.size, SEEK_CUR);
-                }
-            }
-        }
-
-        fclose(rresFile);
-    }
-
-    if (!found) TraceLog(WARNING, "[%s] Required resource id [%i] could not be found in the raylib resource file", rresName, resId);
-
-    return image;
-}
-
 // Load an image as texture into GPU memory
 Texture2D LoadTexture(const char *fileName)
 {
@@ -378,18 +264,6 @@ Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat)
     return texture;
 }
 
-// Load an image as texture from rRES file (raylib Resource)
-Texture2D LoadTextureFromRES(const char *rresName, int resId)
-{
-    Texture2D texture;
-
-    Image image = LoadImageFromRES(rresName, resId);
-    texture = LoadTextureFromImage(image);
-    UnloadImage(image);
-
-    return texture;
-}
-
 // Load a texture from image data
 // NOTE: image is not unloaded, it must be done manually
 Texture2D LoadTextureFromImage(Image image)

+ 0 - 42
src/utils.c

@@ -49,9 +49,6 @@
     #include "external/stb_image_write.h"    // Required for: stbi_write_png()
 #endif
 
-#include "external/tinfl.c"         // Required for: tinfl_decompress_mem_to_mem()
-                                    // NOTE: DEFLATE algorythm data decompression
-
 #define DO_NOT_TRACE_DEBUG_MSGS     // Avoid DEBUG messages tracing
 
 //----------------------------------------------------------------------------------
@@ -75,45 +72,6 @@ static int android_close(void *cookie);
 // Module Functions Definition - Utilities
 //----------------------------------------------------------------------------------
 
-// Data decompression function
-// NOTE: Allocated data MUST be freed!
-unsigned char *DecompressData(const unsigned char *data, unsigned long compSize, int uncompSize)
-{
-    int tempUncompSize;
-    unsigned char *pUncomp;
-
-    // Allocate buffer to hold decompressed data
-    pUncomp = (mz_uint8 *)malloc((size_t)uncompSize);
-
-    // Check correct memory allocation
-    if (pUncomp == NULL)
-    {
-        TraceLog(WARNING, "Out of memory while decompressing data");
-    }
-    else
-    {
-        // Decompress data
-        tempUncompSize = tinfl_decompress_mem_to_mem(pUncomp, (size_t)uncompSize, data, compSize, 1);
-
-        if (tempUncompSize == -1)
-        {
-            TraceLog(WARNING, "Data decompression failed");
-            free(pUncomp);
-        }
-
-        if (uncompSize != (int)tempUncompSize)
-        {
-            TraceLog(WARNING, "Expected uncompressed size do not match, data may be corrupted");
-            TraceLog(WARNING, " -- Expected uncompressed size: %i", uncompSize);
-            TraceLog(WARNING, " -- Returned uncompressed size: %i", tempUncompSize);
-        }
-
-        TraceLog(INFO, "Data decompressed successfully from %u bytes to %u bytes", (mz_uint32)compSize, (mz_uint32)tempUncompSize);
-    }
-
-    return pUncomp;
-}
-
 #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
 // Creates a bitmap (BMP) file from an array of pixel data
 // NOTE: This function is not explicitly available to raylib users