Resource_Load

Load a file from disk or resource archive.

Synopsis

void* HGE::Resource_Load(const char *filename, DWORD *size = 0);

Parameters

  • filename — Path to the file to load
  • size — Optional pointer to receive the file size in bytes

Returns

Pointer to the loaded data, or NULL if loading failed. The caller must free this memory with Resource_Free.

Description

Loads a file into memory. HGE first checks any attached resource archives, then looks for the file on disk. This function is used for loading raw data; for specific resource types, use the specialized functions (Texture_Load, Stream_Load, etc.).

Example

DWORD size;
char *data = (char*)hge->Resource_Load("data/levels/level1.dat", &size);

if (data)
{
    // Process the data
    ParseLevelData(data, size);
    
    // Free when done
    hge->Resource_Free(data);
}
else
{
    // Handle error
    hge->System_Log("Failed to load level data");
}

Resource Archives

You can package multiple files into a ZIP archive and attach it:

// Attach a resource archive
hge->Resource_AttachPack("data.zip");

// Now Resource_Load will look inside the archive first
void *data = hge->Resource_Load("images/player.png", &size);

Search Order

When loading a file, HGE searches in this order:

  1. Attached resource archives (in order of attachment)
  2. Current working directory
  3. Executable directory

Specialized Load Functions

For specific resource types, use these instead:

// Textures
HTEXTURE tex = hge->Texture_Load("player.png");

// Sound effects
HEFFECT snd = hge->Effect_Load("shoot.wav");

// Music streams
HSTREAM mus = hge->Stream_Load("music.ogg");

See Also