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