R -> RES
This commit is contained in:
parent
e7207c776c
commit
51f48a5740
@ -233,7 +233,7 @@ void P_AppStartup(String args_str)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Global systems */
|
/* Global systems */
|
||||||
R_Startup();
|
RES_Startup();
|
||||||
W_Startup();
|
W_Startup();
|
||||||
gp_startup();
|
gp_startup();
|
||||||
|
|
||||||
|
|||||||
@ -81,16 +81,16 @@ P_JobDef(F_LoadAssetJob, job)
|
|||||||
Assert(countof(font_codes) < F_LookupTableSize);
|
Assert(countof(font_codes) < F_LookupTableSize);
|
||||||
|
|
||||||
/* Decode */
|
/* Decode */
|
||||||
R_Resource res = R_OpenResource(path);
|
RES_Resource res = RES_OpenResource(path);
|
||||||
if (!R_ResourceExists(&res))
|
if (!RES_ResourceExists(&res))
|
||||||
{
|
{
|
||||||
/* FIME: Load baked font instead of panicking */
|
/* FIME: Load baked font instead of panicking */
|
||||||
P_Panic(StringFormat(scratch.arena,
|
P_Panic(StringFormat(scratch.arena,
|
||||||
Lit("Font \"%F\" not found"),
|
Lit("Font \"%F\" not found"),
|
||||||
FmtString(path)));
|
FmtString(path)));
|
||||||
}
|
}
|
||||||
TTF_Result result = TTF_Decode(scratch.arena, R_GetResourceData(&res), point_size, font_codes, countof(font_codes));
|
TTF_Result result = TTF_Decode(scratch.arena, RES_GetResourceData(&res), point_size, font_codes, countof(font_codes));
|
||||||
R_CloseResource(&res);
|
RES_CloseResource(&res);
|
||||||
|
|
||||||
/* Send texture to GPU */
|
/* Send texture to GPU */
|
||||||
G_Resource *texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(result.image_width, result.image_height), result.image_pixels);
|
G_Resource *texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(result.image_width, result.image_height), result.image_pixels);
|
||||||
|
|||||||
@ -792,12 +792,12 @@ internal void dx12_init_noise(void)
|
|||||||
|
|
||||||
{
|
{
|
||||||
String noise_res_name = Lit("noise_128x128x64_16.dat");
|
String noise_res_name = Lit("noise_128x128x64_16.dat");
|
||||||
R_Resource noise_res = R_OpenResource(noise_res_name);
|
RES_Resource noise_res = RES_OpenResource(noise_res_name);
|
||||||
DXGI_FORMAT format = DXGI_FORMAT_R16_UINT;
|
DXGI_FORMAT format = DXGI_FORMAT_R16_UINT;
|
||||||
//u32 expected_size = K_BLUE_NOISE_TEX_WIDTH * K_BLUE_NOISE_TEX_HEIGHT * K_BLUE_NOISE_TEX_DEPTH * 2;
|
//u32 expected_size = K_BLUE_NOISE_TEX_WIDTH * K_BLUE_NOISE_TEX_HEIGHT * K_BLUE_NOISE_TEX_DEPTH * 2;
|
||||||
u32 expected_size = K_BLUE_NOISE_TEX_WIDTH * K_BLUE_NOISE_TEX_HEIGHT * K_BLUE_NOISE_TEX_DEPTH * 2;
|
u32 expected_size = K_BLUE_NOISE_TEX_WIDTH * K_BLUE_NOISE_TEX_HEIGHT * K_BLUE_NOISE_TEX_DEPTH * 2;
|
||||||
if (R_ResourceExists(&noise_res)) {
|
if (RES_ResourceExists(&noise_res)) {
|
||||||
String data = R_GetResourceData(&noise_res);
|
String data = RES_GetResourceData(&noise_res);
|
||||||
if (data.len != expected_size) {
|
if (data.len != expected_size) {
|
||||||
P_Panic(StringFormat(scratch.arena,
|
P_Panic(StringFormat(scratch.arena,
|
||||||
Lit("Noise texture has unexpected size for a %Fx%Fx%F texture (expected %F, got %F)"),
|
Lit("Noise texture has unexpected size for a %Fx%Fx%F texture (expected %F, got %F)"),
|
||||||
@ -841,7 +841,7 @@ internal void dx12_init_noise(void)
|
|||||||
} else {
|
} else {
|
||||||
P_Panic(StringFormat(scratch.arena, Lit("Noise resource \"%F\" not found"), FmtString(noise_res_name)));
|
P_Panic(StringFormat(scratch.arena, Lit("Noise resource \"%F\" not found"), FmtString(noise_res_name)));
|
||||||
}
|
}
|
||||||
R_CloseResource(&noise_res);
|
RES_CloseResource(&noise_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
R_SharedState R_shared_state = ZI;
|
RES_SharedState RES_shared_state = ZI;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Startup
|
//~ Startup
|
||||||
|
|
||||||
R_StartupReceipt R_Startup(void)
|
RES_StartupReceipt RES_Startup(void)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
R_SharedState *g = &R_shared_state;
|
RES_SharedState *g = &RES_shared_state;
|
||||||
g->arena = AllocArena(Gibi(64));
|
g->arena = AllocArena(Gibi(64));
|
||||||
|
|
||||||
#if RESOURCES_EMBEDDED
|
#if RESOURCES_EMBEDDED
|
||||||
@ -24,28 +24,28 @@ R_StartupReceipt R_Startup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (R_StartupReceipt) { 0 };
|
return (RES_StartupReceipt) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Open / close
|
//~ Open / close
|
||||||
|
|
||||||
R_Resource R_OpenResource(String name)
|
RES_Resource RES_OpenResource(String name)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
#if RESOURCES_EMBEDDED
|
#if RESOURCES_EMBEDDED
|
||||||
R_SharedState *g = &R_shared_state;
|
RES_SharedState *g = &RES_shared_state;
|
||||||
R_Resource result = ZI;
|
RES_Resource result = ZI;
|
||||||
TAR_Entry *entry = TAR_EntryFromName(&g->archive, name);
|
TAR_Entry *entry = TAR_EntryFromName(&g->archive, name);
|
||||||
result._data = entry->data;
|
result._data = entry->data;
|
||||||
result._name = entry->file_name;
|
result._name = entry->file_name;
|
||||||
result._exists = entry->valid;
|
result._exists = entry->valid;
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
R_Resource result = ZI;
|
RES_Resource result = ZI;
|
||||||
if (name.len < countof(result._name_text))
|
if (name.len < countof(result._name_text))
|
||||||
{
|
{
|
||||||
u8 path_text[R_ResourceNameLenMax + (sizeof("result/") - 1)];
|
u8 path_text[RES_ResourceNameLenMax + (sizeof("result/") - 1)];
|
||||||
String path = ZI;
|
String path = ZI;
|
||||||
{
|
{
|
||||||
path_text[0] = 'r';
|
path_text[0] = 'r';
|
||||||
@ -94,7 +94,7 @@ R_Resource R_OpenResource(String name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !RESOURCES_EMBEDDED
|
#if !RESOURCES_EMBEDDED
|
||||||
void R_CloseResource(R_Resource *res_ptr)
|
void RES_CloseResource(RES_Resource *res_ptr)
|
||||||
{
|
{
|
||||||
P_CloseFileMap(res_ptr->_file_map);
|
P_CloseFileMap(res_ptr->_file_map);
|
||||||
P_CloseFIle(res_ptr->_file);
|
P_CloseFIle(res_ptr->_file);
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Resource types
|
//~ Resource types
|
||||||
|
|
||||||
#define R_ResourceNameLenMax 256
|
#define RES_ResourceNameLenMax 256
|
||||||
|
|
||||||
Struct(R_Resource)
|
Struct(RES_Resource)
|
||||||
{
|
{
|
||||||
String _data;
|
String _data;
|
||||||
b32 _exists;
|
b32 _exists;
|
||||||
@ -12,7 +12,7 @@ Struct(R_Resource)
|
|||||||
#else
|
#else
|
||||||
P_File _file;
|
P_File _file;
|
||||||
P_FileMap _file_map;
|
P_FileMap _file_map;
|
||||||
u8 _name_text[R_ResourceNameLenMax];
|
u8 _name_text[RES_ResourceNameLenMax];
|
||||||
u8 _name_len;
|
u8 _name_len;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@ -20,7 +20,7 @@ Struct(R_Resource)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Shared state
|
//~ Shared state
|
||||||
|
|
||||||
Struct(R_SharedState)
|
Struct(RES_SharedState)
|
||||||
{
|
{
|
||||||
Arena *arena;
|
Arena *arena;
|
||||||
#if RESOURCES_EMBEDDED
|
#if RESOURCES_EMBEDDED
|
||||||
@ -28,34 +28,34 @@ Struct(R_SharedState)
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern R_SharedState R_shared_state;
|
extern RES_SharedState RES_shared_state;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Startup
|
//~ Startup
|
||||||
|
|
||||||
Struct(R_StartupReceipt) { i32 _; };
|
Struct(RES_StartupReceipt) { i32 _; };
|
||||||
R_StartupReceipt R_Startup(void);
|
RES_StartupReceipt RES_Startup(void);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Open / close
|
//~ Open / close
|
||||||
|
|
||||||
R_Resource R_OpenResource(String name);
|
RES_Resource RES_OpenResource(String name);
|
||||||
|
|
||||||
#if RESOURCES_EMBEDDED
|
#if RESOURCES_EMBEDDED
|
||||||
# define R_CloseResource(res_ptr) (UNUSED)res_ptr
|
# define RES_CloseResource(res_ptr) (UNUSED)res_ptr
|
||||||
#else
|
#else
|
||||||
void R_CloseResource(R_Resource *res_ptr);
|
void RES_CloseResource(RES_Resource *res_ptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Resource data operations
|
//~ Resource data operations
|
||||||
|
|
||||||
#define R_GetResourceData(res_ptr) (res_ptr)->_data
|
#define RES_GetResourceData(res_ptr) (res_ptr)->_data
|
||||||
|
|
||||||
#define R_ResourceExists(res_ptr) (res_ptr)->_exists
|
#define RES_ResourceExists(res_ptr) (res_ptr)->_exists
|
||||||
|
|
||||||
#if RESOURCES_EMBEDDED
|
#if RESOURCES_EMBEDDED
|
||||||
# define R_GetResourceName(res_ptr) (res_ptr)->_name
|
# define RES_GetResourceName(res_ptr) (res_ptr)->_name
|
||||||
#else
|
#else
|
||||||
# define R_GetResourceName(res_ptr) STRING((res_ptr)->_name_len, (res_ptr)->_name_text)
|
# define RES_GetResourceName(res_ptr) STRING((res_ptr)->_name_len, (res_ptr)->_name_text)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -66,15 +66,15 @@ P_JobDef(SND_LoadAssetJob, job)
|
|||||||
/* Decode */
|
/* Decode */
|
||||||
MP3_Result decoded = ZI;
|
MP3_Result decoded = ZI;
|
||||||
{
|
{
|
||||||
R_Resource sound_rs = R_OpenResource(path);
|
RES_Resource sound_rs = RES_OpenResource(path);
|
||||||
if (R_ResourceExists(&sound_rs))
|
if (RES_ResourceExists(&sound_rs))
|
||||||
{
|
{
|
||||||
u64 decode_flags = 0;
|
u64 decode_flags = 0;
|
||||||
if (flags & SND_SoundFlag_Stereo)
|
if (flags & SND_SoundFlag_Stereo)
|
||||||
{
|
{
|
||||||
decode_flags |= MP3_DecodeFlag_Stereo;
|
decode_flags |= MP3_DecodeFlag_Stereo;
|
||||||
}
|
}
|
||||||
decoded = MP3_Decode(scratch.arena, R_GetResourceData(&sound_rs), SND_SampleRate, decode_flags);
|
decoded = MP3_Decode(scratch.arena, RES_GetResourceData(&sound_rs), SND_SampleRate, decode_flags);
|
||||||
if (!decoded.success)
|
if (!decoded.success)
|
||||||
{
|
{
|
||||||
error_msg = Lit("Failed to decode sound file");
|
error_msg = Lit("Failed to decode sound file");
|
||||||
@ -84,7 +84,7 @@ P_JobDef(SND_LoadAssetJob, job)
|
|||||||
{
|
{
|
||||||
error_msg = Lit("Resource not found");
|
error_msg = Lit("Resource not found");
|
||||||
}
|
}
|
||||||
R_CloseResource(&sound_rs);
|
RES_CloseResource(&sound_rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decoded.success)
|
if (decoded.success)
|
||||||
|
|||||||
@ -337,13 +337,13 @@ internal void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
|||||||
/* Decode */
|
/* Decode */
|
||||||
Ase_DecodedImage decoded = ZI;
|
Ase_DecodedImage decoded = ZI;
|
||||||
{
|
{
|
||||||
R_Resource texture_rs = R_OpenResource(path);
|
RES_Resource texture_rs = RES_OpenResource(path);
|
||||||
if (R_ResourceExists(&texture_rs)) {
|
if (RES_ResourceExists(&texture_rs)) {
|
||||||
decoded = Ase_DecodeImage(scratch.arena, R_GetResourceData(&texture_rs));
|
decoded = Ase_DecodeImage(scratch.arena, RES_GetResourceData(&texture_rs));
|
||||||
} else {
|
} else {
|
||||||
P_LogErrorF("Sprite texture for \"%F\" not found", FmtString(path));
|
P_LogErrorF("Sprite texture for \"%F\" not found", FmtString(path));
|
||||||
}
|
}
|
||||||
R_CloseResource(&texture_rs);
|
RES_CloseResource(&texture_rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decoded.success) {
|
if (decoded.success) {
|
||||||
@ -657,19 +657,19 @@ internal void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
|||||||
/* Decode */
|
/* Decode */
|
||||||
Ase_DecodedSheet decoded = ZI;
|
Ase_DecodedSheet decoded = ZI;
|
||||||
{
|
{
|
||||||
R_Resource sheet_rs = R_OpenResource(path);
|
RES_Resource sheet_rs = RES_OpenResource(path);
|
||||||
if (R_ResourceExists(&sheet_rs)) {
|
if (RES_ResourceExists(&sheet_rs)) {
|
||||||
decoded = Ase_DecodeSheet(scratch.arena, R_GetResourceData(&sheet_rs));
|
decoded = Ase_DecodeSheet(scratch.arena, RES_GetResourceData(&sheet_rs));
|
||||||
} else {
|
} else {
|
||||||
P_LogErrorF("Sprite sheet for \"%F\" not found", FmtString(path));
|
P_LogErrorF("Sprite sheet for \"%F\" not found", FmtString(path));
|
||||||
}
|
}
|
||||||
R_CloseResource(&sheet_rs);
|
RES_CloseResource(&sheet_rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decoded.success) {
|
if (decoded.success) {
|
||||||
R_Resource sheet_rs = R_OpenResource(path);
|
RES_Resource sheet_rs = RES_OpenResource(path);
|
||||||
decoded = Ase_DecodeSheet(scratch.arena, R_GetResourceData(&sheet_rs));
|
decoded = Ase_DecodeSheet(scratch.arena, RES_GetResourceData(&sheet_rs));
|
||||||
R_CloseResource(&sheet_rs);
|
RES_CloseResource(&sheet_rs);
|
||||||
|
|
||||||
/* Initialize */
|
/* Initialize */
|
||||||
e->sheet = PushStructNoZero(e->arena, S_Sheet);
|
e->sheet = PushStructNoZero(e->arena, S_Sheet);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user