Created platform_file_handler and integrated it
This commit is contained in:
parent
3418f1417a
commit
0b3d603e04
|
@ -92,7 +92,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
|
||||||
// TODO(Peter): put in InitializeInterface?
|
// TODO(Peter): put in InitializeInterface?
|
||||||
r32 FontSize = 14;
|
r32 FontSize = 14;
|
||||||
{
|
{
|
||||||
platform_memory_result FontFile = Context.PlatformReadEntireFile("Anonymous Pro.ttf");
|
platform_memory_result FontFile = ReadEntireFile(Context, "data/Anonymous Pro.ttf");
|
||||||
if (!FontFile.Error)
|
if (!FontFile.Error)
|
||||||
{
|
{
|
||||||
bitmap_font* Font = PushStruct(&State->Permanent, bitmap_font);
|
bitmap_font* Font = PushStruct(&State->Permanent, bitmap_font);
|
||||||
|
@ -176,7 +176,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
|
||||||
State->Camera.LookAt = v3{0, 0, 0};
|
State->Camera.LookAt = v3{0, 0, 0};
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
char Path[] = "blumen_lumen.fold";
|
char Path[] = "data/blumen_lumen.fold";
|
||||||
LoadAssembly(State, Context, Path);
|
LoadAssembly(State, Context, Path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ s32 TempAssemblyOffsetsCount = 3;
|
||||||
internal void
|
internal void
|
||||||
LoadAssembly (app_state* State, context Context, char* Path)
|
LoadAssembly (app_state* State, context Context, char* Path)
|
||||||
{
|
{
|
||||||
platform_memory_result AssemblyFile = Context.PlatformReadEntireFile(Path);
|
platform_memory_result AssemblyFile = ReadEntireFile(Context, Path);
|
||||||
if (AssemblyFile.Error == PlatformMemory_NoError)
|
if (AssemblyFile.Error == PlatformMemory_NoError)
|
||||||
{
|
{
|
||||||
assembly_definition AssemblyDefinition = ParseAssemblyFile(AssemblyFile.Base, AssemblyFile.Size, &State->Transient, State->GlobalLog);
|
assembly_definition AssemblyDefinition = ParseAssemblyFile(AssemblyFile.Base, AssemblyFile.Size, &State->Transient, State->GlobalLog);
|
||||||
|
|
|
@ -63,6 +63,8 @@ enum platform_memory_error
|
||||||
PlatformMemory_UnknownError, // You should implement handling this when you see it
|
PlatformMemory_UnknownError, // You should implement handling this when you see it
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO(Peter): Change this to just be data
|
||||||
|
// - Base, and Size
|
||||||
struct platform_memory_result
|
struct platform_memory_result
|
||||||
{
|
{
|
||||||
u8* Base;
|
u8* Base;
|
||||||
|
@ -104,6 +106,13 @@ typedef PLATFORM_WRITE_ENTIRE_FILE(platform_write_entire_file);
|
||||||
#define PLATFORM_GET_FILE_PATH(name) b32 name(char* PathBuffer, s32 BufferLength, const char* FilterStrings)
|
#define PLATFORM_GET_FILE_PATH(name) b32 name(char* PathBuffer, s32 BufferLength, const char* FilterStrings)
|
||||||
typedef PLATFORM_GET_FILE_PATH(platform_get_file_path);
|
typedef PLATFORM_GET_FILE_PATH(platform_get_file_path);
|
||||||
|
|
||||||
|
struct platform_file_handler
|
||||||
|
{
|
||||||
|
platform_read_entire_file* ReadEntireFile;
|
||||||
|
platform_write_entire_file* WriteEntireFile;
|
||||||
|
platform_get_file_path* GetFilePath;
|
||||||
|
};
|
||||||
|
|
||||||
#define PLATFORM_GET_GPU_TEXTURE_HANDLE(name) s32 name(u8* Memory, s32 Width, s32 Height)
|
#define PLATFORM_GET_GPU_TEXTURE_HANDLE(name) s32 name(u8* Memory, s32 Width, s32 Height)
|
||||||
typedef PLATFORM_GET_GPU_TEXTURE_HANDLE(platform_get_gpu_texture_handle);
|
typedef PLATFORM_GET_GPU_TEXTURE_HANDLE(platform_get_gpu_texture_handle);
|
||||||
|
|
||||||
|
@ -258,7 +267,9 @@ struct context
|
||||||
platform_alloc* PlatformAlloc;
|
platform_alloc* PlatformAlloc;
|
||||||
platform_free* PlatformFree;
|
platform_free* PlatformFree;
|
||||||
platform_realloc* PlatformRealloc;
|
platform_realloc* PlatformRealloc;
|
||||||
platform_read_entire_file* PlatformReadEntireFile;
|
|
||||||
|
platform_file_handler FileHandler;
|
||||||
|
|
||||||
platform_write_entire_file* PlatformWriteEntireFile;
|
platform_write_entire_file* PlatformWriteEntireFile;
|
||||||
platform_get_file_path* PlatformGetFilePath;
|
platform_get_file_path* PlatformGetFilePath;
|
||||||
platform_get_gpu_texture_handle* PlatformGetGPUTextureHandle;
|
platform_get_gpu_texture_handle* PlatformGetGPUTextureHandle;
|
||||||
|
@ -270,6 +281,47 @@ struct context
|
||||||
platform_close_socket* PlatformCloseSocket;
|
platform_close_socket* PlatformCloseSocket;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// File Handler
|
||||||
|
internal platform_memory_result
|
||||||
|
ReadEntireFile(platform_file_handler FileHandler, char* Path)
|
||||||
|
{
|
||||||
|
// TODO(Peter): Convert Path to be a string
|
||||||
|
platform_memory_result Result = FileHandler.ReadEntireFile(Path);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
internal platform_memory_result
|
||||||
|
ReadEntireFile(context Context, char* Path)
|
||||||
|
{
|
||||||
|
return ReadEntireFile(Context.FileHandler, Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal b32
|
||||||
|
WriteEntireFile(platform_file_handler FileHandler, char* Path, u8* Contents, u32 Size)
|
||||||
|
{
|
||||||
|
// TODO(Peter): Convert Path to be a string
|
||||||
|
// TODO(Peter): Overload to take a data struct instead of Contents And Size
|
||||||
|
b32 Result = FileHandler.WriteEntireFile(Path, Contents, Size);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
internal b32
|
||||||
|
WriteEntireFile(context Context, char* Path, u8* Contents, u32 Size)
|
||||||
|
{
|
||||||
|
return WriteEntireFile(Context.FileHandler, Path, Contents, Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal b32
|
||||||
|
GetFilePath(platform_file_handler FileHandler, char* PathBuffer, s32 BufferLength, char* FilterStrings)
|
||||||
|
{
|
||||||
|
// TODO(Peter): Convert Path to be a string
|
||||||
|
b32 Result = FileHandler.GetFilePath(PathBuffer, BufferLength, (const char*)FilterStrings);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
internal b32
|
||||||
|
GetFilePath(context Context, char* PathBuffer, s32 BufferLength, char* FilterStrings)
|
||||||
|
{
|
||||||
|
return GetFilePath(Context.FileHandler, PathBuffer, BufferLength, FilterStrings);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define FOLDHAUS_PLATFORM_H
|
#define FOLDHAUS_PLATFORM_H
|
||||||
#endif // FOLDHAUS_PLATFORM_H
|
#endif // FOLDHAUS_PLATFORM_H
|
|
@ -66,7 +66,7 @@ HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
|
||||||
if (ui_LayoutButton(&State->Interface_, &Layout, TempString, ListItemBGColor, ListItemHover, ListItemSelected))
|
if (ui_LayoutButton(&State->Interface_, &Layout, TempString, ListItemBGColor, ListItemHover, ListItemSelected))
|
||||||
{
|
{
|
||||||
char FilePath[256];
|
char FilePath[256];
|
||||||
b32 Success = Context.PlatformGetFilePath(FilePath, 256, "Foldhaus Files\0*.fold\0\0");
|
b32 Success = GetFilePath(Context, FilePath, 256, "Foldhaus Files\0*.fold\0\0");
|
||||||
if (Success)
|
if (Success)
|
||||||
{
|
{
|
||||||
LoadAssembly(State, Context, FilePath);
|
LoadAssembly(State, Context, FilePath);
|
||||||
|
|
|
@ -666,9 +666,9 @@ WinMain (
|
||||||
Context.PlatformAlloc = Win32Alloc;
|
Context.PlatformAlloc = Win32Alloc;
|
||||||
Context.PlatformFree = Win32Free;
|
Context.PlatformFree = Win32Free;
|
||||||
Context.PlatformRealloc = Win32Realloc;
|
Context.PlatformRealloc = Win32Realloc;
|
||||||
Context.PlatformReadEntireFile = Win32ReadEntireFile;
|
Context.FileHandler.ReadEntireFile = Win32ReadEntireFile;
|
||||||
Context.PlatformWriteEntireFile = Win32WriteEntireFile;
|
Context.FileHandler.WriteEntireFile = Win32WriteEntireFile;
|
||||||
Context.PlatformGetFilePath = Win32SystemDialogueOpenFile;
|
Context.FileHandler.GetFilePath = Win32SystemDialogueOpenFile;
|
||||||
Context.PlatformGetGPUTextureHandle = Win32GetGPUTextureHandle;
|
Context.PlatformGetGPUTextureHandle = Win32GetGPUTextureHandle;
|
||||||
Context.PlatformGetSocketHandle = Win32GetSocketHandle;
|
Context.PlatformGetSocketHandle = Win32GetSocketHandle;
|
||||||
Context.PlatformSetSocketOption = Win32SetSocketOption;
|
Context.PlatformSetSocketOption = Win32SetSocketOption;
|
||||||
|
|
Loading…
Reference in New Issue