SpiecsEngine
 
Loading...
Searching...
No Matches
FileLibrary.h
Go to the documentation of this file.
1/**
2* @file FileLibrary.h
3* @brief The FileLibrary Class Definitions.
4* @author Travis Vroman.
5*/
6
7#pragma once
8#include "Core/Core.h"
9
10namespace Spices {
11
12 /**
13 * @brief This Struct is FILE* handle pointer Wrapper.
14 */
15 struct FileHandle {
16
17 /**
18 * @brief FILE* handle.
19 * Need cast while use.
20 */
21 void* handle;
22
23 /**
24 * @brief Is this handle Valid.
25 */
27 };
28
29 /**
30 * @brief file mode
31 */
32 enum FileModes {
33
34 /**
35 * @brief model : read
36 */
38
39 /**
40 * @brief model : write
41 */
42 FILE_MODE_WRITE = 0x2
43 };
44
45 /**
46 * @brief File Static Function Library.
47 */
49 {
50 public:
51
52 /**
53 * @brief Determine whether the given string is existing a file.
54 * @param[in] path The file path.
55 * @return true if there exising a file.
56 */
57 static bool FileLibrary_Exists(const char* path);
58
59 /**
60 * @brief Open the file using given string.
61 * @param[in] path The file path.
62 * @param[in] mode The file mode.
63 * @param[in] binary The file is a binary file ro not.
64 * @param[out] out_handle Out The file handle pointer.
65 * @return true if open the file succeed.
66 */
67 static bool FileLibrary_Open(
68 const char* path ,
69 FileModes mode ,
70 bool binary ,
71 FileHandle* out_handle
72 );
73
74 /**
75 * @brief Close the file by the file handle.
76 * @param[in] handle The file handle.
77 */
78 static void FileLibrary_Close(FileHandle* handle);
79
80 /**
81 * @brief Calculate The file size.
82 * @param[in] handle The file handle.
83 * @param[out] out_size The file size(byte).
84 * @return true if file handle is valid.
85 */
86 static bool FileLibrary_Size(const FileHandle* handle, uint64_t* out_size);
87
88 /**
89 * @brief Read Specific size of data form the current file handle pointer, and move pointer the same size.
90 * @param[in] handle The file handle.
91 * @param[in] data_size How much bytes we want read and move pointer.
92 * @param[out] out_data The data we read.
93 * @param[out] out_bytes_read How much bytes we read.
94 * @return true if file handle is valid and successfully read data.
95 */
96 static bool FileLibrary_Read(
97 const FileHandle* handle ,
98 uint64_t data_size ,
99 void* out_data ,
100 uint64_t* out_bytes_read
101 );
102
103 /**
104 * @brief Read one line from the current file handle pointer, and move pointer the same size.
105 * @param[in] handle The file handle.
106 * @param[in] max_length Defines the max size per line.
107 * @param[out] line_buf The data of one line.
108 * @param[out] out_line_length How much bytes we read.
109 * @return true if file handle is valid and successfully read data.
110 */
111 static bool FileLibrary_Read_Line(
112 const FileHandle* handle ,
113 uint64_t max_length ,
114 char* line_buf ,
115 uint64_t* out_line_length
116 );
117
118 /**
119 * @brief Read all data form the current file handle pointer.
120 * @param[in] handle The file handle.
121 * @param[out] out_bytes The data that read.
122 * @param[out] out_bytes_read How much bytes we read.
123 * @return true if file handle is valid and successfully read data.
124 */
125 static bool FileLibrary_Read_all_bytes(const FileHandle* handle, char* out_bytes, uint64_t* out_bytes_read);
126
127 /**
128 * @brief Write given data to the file handle pointer.
129 * @param[in] handle The file handle.
130 * @param[in] data_size How much bytes we want write and move pointer.
131 * @param[in] data The data we want write in.
132 * @param[out] out_bytes_written How much bytes we written.
133 * @return true if file handle is valid and successfully write data.
134 */
135 static bool FileLibrary_Write(
136 const FileHandle* handle ,
137 uint64_t data_size ,
138 const void* data ,
139 uint64_t* out_bytes_written
140 );
141
142 /**
143 * @brief Write one line data to the file handle pointer.
144 * @param[in] handle The file handle.
145 * @param[in] text The one line data pointer.
146 * @return true if file handle is valid and successfully write data.
147 */
148 static bool FileLibrary_Write_Line(const FileHandle* handle, const char* text);
149
150 /**
151 * @brief Select a file to open in explore.
152 * @param[in] filter The file extension filter.
153 * @param[in] hwnd The Windows Needs.
154 * @return Returns the file path of selected file.
155 */
156 static std::string FileLibrary_OpenInExplore(const char* filter, HWND hwnd);
157
158 /**
159 * @brief Select a file to save in explore.
160 * @param[in] filter The file extension filter.
161 * @param[in] hwnd The Windows Needs.
162 * @return Returns the file path of selected file.
163 */
164 static std::string FileLibrary_SaveInExplore(const char* filter, HWND hwnd);
165
166 /**
167 * @brief Copy a file to dst path.
168 * @param[in] srcFilePath The src file.
169 * @param[in] dstFilePath The dst file.
170 * @return Returns true if copy succeed.
171 */
172 static bool FileLibrary_CopyFile(std::string srcFilePath, std::string dstFilePath);
173
174 /**
175 * @brief Delete a file from disk.
176 * @param[in] filePath The file.
177 * @return Returns true if delete succeed.
178 */
179 static bool FileLibrary_Delete(const char* filePath);
180 };
181}
#define SPICES_PROFILE_ZONE
virtual void OnEvent(Event &e) override
The interface inherited from NativeScriptComponent, which is called on the global event function poin...
glm::vec3 GetForwardDirection() const
Get Camera Forward(z) Direction.
glm::vec3 m_FocalPoint
The focus point. Init with 0.
uint32_t m_ViewportWidth
The Viewport size.
glm::vec3 GetUpDirection() const
Get Camera Up(y) Direction.
CameraController()=default
Constructor Function.
std::shared_ptr< Camera > m_Camera
The camera smart pointer get from owner's camera component.
bool OnKeyPressed(KeyPressedEvent &e)
Event OnKeyPressed. We do nothing here.
virtual void OnDeSerialize() override
The interface inherited from Component, which is used for deserialize this class.
bool OnMouseScroll(MouseScrolledEvent &e)
Event OnMouseScroll. Scale the camera.
void MousePan(const glm::vec2 &delta)
Calculate Camera Drag.
void MouseZoom(const float &delta)
Calculate Camera Zoom.
void UpdateView() const
Setting camera transform component position. We already set rotation in MouseRotate().
std::pair< float, float > PanSpeed() const
Calculate Camera Drag speed.
virtual void OnSerialize() override
The interface inherited from Component, which is used for serialize this class.
glm::vec2 m_InitialMousePosition
The mouse position. Init with 0.
glm::quat GetOrientation() const
Get Camera quaternion rotation.
virtual ~CameraController() override=default
Destructor Function.
void MouseRotate(const glm::vec2 &delta) const
Calculate Camera Rotate.
virtual void OnConstruction() override
The interface inherited from NativeScriptComponent, which is called on this attached to an entity....
bool OnSlateResized(SlateResizeEvent &e)
Event OnWindowResized. Reset Camera aspect ratio.
float ZoomSpeed() const
Calculate Camera Zoom speed.
float m_Distance
The camera spring arm. Init with 10.
glm::vec3 GetRightDirection() const
Get Camera Right(x) Direction.
TransformComponent * m_CameraTranComp
The camera transform component pointer get from owner's transform component.
glm::vec3 CalculatePosition() const
Calculate camera transform component position using the class member parameters.
virtual void OnTick(TimeStep &ts) override
The interface inherited from NativeScriptComponent, which is called every engine loop frame....
float RotationSpeed() const
Calculate Camera Rotate speed.
float m_ZoomLevel
Zoom Level, for orthographic type camera.
CameraController Class. This class inherit from NativeScriptComponent. It receives Mouse Event and Ke...
Camera Class. This class just encapsulate Projection Matrix.
Definition Camera.h:59
static std::string GetClassString(ClassType t)
Get Class Name as string.
Class Static Function Library.
virtual void OnPreActivate() override
This interface define the specific world behave before on activated.
virtual void OnDeactivate() override
This interface defines the specific world behave after on activated.
virtual void OnActivate(TimeStep &ts) override
This interface define the specific world behave on activated.
EditorWorld Class. This class defines the specific behave of EditorWorld.
Definition EditorWorld.h:18
T & AddComponent(Args &&... args)
Template Function. Used for add specific component to entity.
Definition Entity.h:53
T & GetComponent() const
Get Component owned by this entity.
Definition Entity.h:75
void RemoveComponent() const
Remove Component owned from this entity.
Definition Entity.h:85
Entity()=default
Constructor Function.
void AddToRoot()
Add a entity to this world root.
Definition Entity.h:101
World * m_World
A specific world Pointer.
Definition Entity.h:171
const UUID GetUUID()
Get UUID form UUIDComponent.
Definition Entity.h:121
Entity(entt::entity handle, World *world)
Constructor Function. Init class variable. Usually call it.
Definition Entity.h:35
void RemoveFromRoot()
Remove a entity from this world root.
Definition Entity.h:93
operator bool() const
Empty Operation.
Definition Entity.h:127
virtual ~Entity()=default
Destructor Function.
bool HasComponent() const
If Component is owned by this entity or not.
Definition Entity.h:112
operator uint32_t() const
Empty Operation.
Definition Entity.h:133
Entity Class. This class defines the specific behaves of Entity.
Definition Entity.h:20
This Class is the basic Event Class. Inherit from it and create specific event class.
Definition Event.h:96
static bool FileLibrary_Size(const FileHandle *handle, uint64_t *out_size)
Calculate The file size.
static bool FileLibrary_Read(const FileHandle *handle, uint64_t data_size, void *out_data, uint64_t *out_bytes_read)
Read Specific size of data form the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Write_Line(const FileHandle *handle, const char *text)
Write one line data to the file handle pointer.
static bool FileLibrary_Write(const FileHandle *handle, uint64_t data_size, const void *data, uint64_t *out_bytes_written)
Write given data to the file handle pointer.
static bool FileLibrary_Open(const char *path, FileModes mode, bool binary, FileHandle *out_handle)
Open the file using given string.
static void FileLibrary_Close(FileHandle *handle)
Close the file by the file handle.
static bool FileLibrary_Delete(const char *filePath)
Delete a file from disk.
static bool FileLibrary_CopyFile(std::string srcFilePath, std::string dstFilePath)
Copy a file to dst path.
static bool FileLibrary_Read_Line(const FileHandle *handle, uint64_t max_length, char *line_buf, uint64_t *out_line_length)
Read one line from the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
static std::string FileLibrary_SaveInExplore(const char *filter, HWND hwnd)
Select a file to save in explore.
static std::string FileLibrary_OpenInExplore(const char *filter, HWND hwnd)
Select a file to open in explore.
static bool FileLibrary_Read_all_bytes(const FileHandle *handle, char *out_bytes, uint64_t *out_bytes_read)
Read all data form the current file handle pointer.
File Static Function Library.
Definition FileLibrary.h:49
virtual ~GltfAccessors() override=default
Destructor Function.
GltfAccessors(const Json &data)
Constructor Function.
std::vector< Item > m_AccessorsData
Data of Gltf Json Accessors.
Wrapper of Gltf Json Accessors.
GltfAnimations(const Json &data)
Constructor Function.
virtual ~GltfAnimations() override=default
Destructor Function.
Wrapper of Gltf Json Animations.
GltfAsset(const Json &data)
Constructor Function.
Definition GltfAsset.h:36
virtual ~GltfAsset() override=default
Destructor Function.
Item m_AssetData
Data of Gltf Json Asset.
Definition GltfAsset.h:56
Wrapper of Gltf Json Asset.
Definition GltfAsset.h:17
virtual ~GltfBufferViews() override=default
Destructor Function.
std::vector< Item > m_BufferViewsData
Data of Gltf Json BufferViews.
GltfBufferViews(const Json &data)
Constructor Function.
Wrapper of Gltf Json BufferViews.
std::filesystem::path m_Path
gltf file directory path.
Definition GltfBuffers.h:88
std::vector< Item > m_BuffersData
Data of Gltf Json Buffers.
Definition GltfBuffers.h:93
virtual ~GltfBuffers() override=default
Destructor Function.
GltfBuffers(const Json &data, const std::filesystem::path &path)
Constructor Function.
Definition GltfBuffers.h:37
Wrapper of Gltf Json Buffers.
Definition GltfBuffers.h:17
virtual ~GltfCameras() override=default
Destructor Function.
std::vector< Item > m_CamerasData
Data of Gltf Json Cameras.
Definition GltfCameras.h:66
GltfCameras(const Json &data)
Constructor Function.
Definition GltfCameras.h:37
Wrapper of Gltf Json Cameras.
Definition GltfCameras.h:17
std::unique_ptr< GltfBufferViews > m_BufferViews
std::unique_ptr< GltfScene > m_Scene
std::unique_ptr< GltfTextures > m_Textures
std::unique_ptr< GltfMaterials > m_Materials
std::unique_ptr< GltfBuffers > m_Buffers
std::unique_ptr< GltfSamplers > m_Samplers
Entity CreateEntityRecursive(World *world, const std::string &tag, uint32_t node, const glm::mat4 &model, std::shared_ptr< LoadingState > loadingState)
Create Entity recursive from gltf file nodes.
std::unique_ptr< GltfAnimations > m_Animations
std::unique_ptr< GltfCameras > m_Cameras
std::unique_ptr< GltfAccessors > m_Accessors
std::unique_ptr< GltfImages > m_Images
std::unique_ptr< GltfNodes > m_Nodes
GltfCollection(const std::string &path)
Constructor Function.
std::unique_ptr< GltfSkins > m_Skins
std::unique_ptr< GltfAsset > m_Asset
void CreateEntity(World *world, const std::string &tag, Transform transform={})
Create Entity instance from gltf file.
std::unique_ptr< GltfScenes > m_Scenes
std::unique_ptr< GltfLights > m_Lights
virtual ~GltfCollection()=default
Destructor Function.
std::unique_ptr< GltfMeshes > m_Meshes
Wrapper of Gltf file data.
static glm::mat4 GetMatrix(const Json::array_t &accessor)
Turn a Json::array_t to glm::mat4.
static Json::array_t GetElementJsonArray(const Json::object_t &root, const char *path, Json::array_t pDefault)
Get array value in Json::object_t.
static int GetElementInt(const Json::object_t &root, const char *path, int pDefault)
Get int value in Json::object_t.
static glm::vec4 GetElementVector(Json::object_t &root, const char *path, glm::vec4 pDefault)
Get vec4 value in Json::object_t.
static std::string GetElementString(const Json::object_t &root, const char *path, const std::string &pDefault)
Get string value in Json::object_t.
static bool GetElementBoolean(const Json::object_t &root, const char *path, bool pDefault)
Get bool value in Json::object_t.
static int GetDimensions(const std::string &str)
Get Variable Type dimensions.
static uint32_t SizeOfFormat(VkFormat format)
static float GetElementFloat(const Json::object_t &root, const char *path, float pDefault)
Get float value in Json::object_t.
static void SplitGltfAttribute(std::string attribute, std::string *semanticName, uint32_t *semanticIndex)
Split digital number in attribute.
static int GetFormatSize(int id)
Get Variable Type bytes.
static type GetElement(const Json::object_t *pRoot, const char *path, type pDefault)
Get specific type in Json::object_t.
Definition GltfHelper.h:130
static VkFormat GetFormat(const std::string &str, int id)
static glm::vec4 GetVector(const Json::array_t &accessor)
Turn a Json::array_t to glm::vec4.
Static functions to help resolve Gltf json.
Definition GltfHelper.h:17
GltfImages(const Json &data, const std::filesystem::path &path)
Constructor Function.
Definition GltfImages.h:39
std::vector< Item > m_ImagesData
Data of Gltf Json Cameras.
Definition GltfImages.h:84
std::filesystem::path m_Path
gltf file directory path.
Definition GltfImages.h:79
virtual ~GltfImages() override=default
Destructor Function.
Wrapper of Gltf Json Images.
Definition GltfImages.h:21
Loader of load gltf file or items.
Definition GltfLoader.h:23
GltfObject(const Json &data)
Constructor Function.
Definition GltfObject.h:33
Json m_Data
Specific Json element.
Definition GltfObject.h:45
virtual ~GltfObject()=default
Destructor Function.
Wrapper of Gltf Json element.
Definition GltfObject.h:19
GltfPack Class. This class defines gltf type meshPack.
Definition GltfPack.h:19
This Class is inherited from KeyEvent Class.
Definition KeyEvent.h:57
void MouseZoom(float delta)
bool OnKeyPressed(KeyPressedEvent &e)
glm::vec3 GetForwardDirection() const
glm::vec3 GetRightDirection() const
virtual void OnEvent(Event &e) override
This interface defines the behaves on specific component event happened.
virtual void OnTick(TimeStep &ts) override
This interface defines the behaves on specific component tick every frame.
virtual void OnSerialize() override
This interface defines how to serialize.
virtual void OnDeSerialize() override
This interface defines how to deserialize.
std::pair< float, float > PanSpeed() const
virtual ~MeshController() override=default
void MouseRotate(const glm::vec2 &delta) const
glm::vec3 CalculatePosition() const
virtual void OnConstruction() override
This interface defines the behaves on specific component added.
glm::quat GetOrientation() const
void MousePan(const glm::vec2 &delta)
glm::vec3 GetUpDirection() const
This Class is inherited from Event Class.
Definition MouseEvent.h:86
NativeScriptComponent Class. This class defines the specific behaves of NativeScriptComponent....
virtual void OnSystemShutDown() override
This interface defines the behave on specific system shutdown. Called when system poped from SystemMa...
virtual void OnSystemInitialize() override
This interface defines the behave on specific system initialized. Called when system Pushed to System...
ResourceSystem(const std::string &systemName)
Constructor Function. Init class variable. Usually call it.
virtual void OnSystemUpdate(TimeStep &ts) override
This interface defines the behave on specific system updated every frame.
static std::vector< std::string > m_ResourceSearchFolder
Registry Resource Search Folder.
virtual ~ResourceSystem() override=default
Destructor Function.
static const std::vector< std::string > & GetSearchFolder()
Get Resource Search Folder.
static void RegistryResourceFolder(const std::string &folder)
Registry Resource Search Folder.
virtual void OnEvent(Event &event) override
This interface defines the behave on global event function pointer is called.
ResourceSystem Class. Handles resource load/unload event.
This Class is inherited from Event Class. Called by Viewport Resize.
Definition SlateEvent.h:18
static std::string WCharToChar(const wchar_t *wc)
Transform wide char to char.
static std::wstring CharToWChar(const char *c)
Transform char to wide char.
static bool StringsEqual(const char *str0, const char *str1)
Determine if the strings given are equal. Platform Specific.
static std::vector< std::string > SplitString(const std::string &input, char delimiter)
Split a string to a string vector container use a char.
String Static Function Library.
void OnEvent(Event &event)
The root event function pointer.
SystemManager()
Constructor Function.
static void Run(TimeStep &ts)
Update all system that pushed to this manager.
static SystemManager & Get()
Get Static SystemManager.
static std::unique_ptr< SystemManager > m_SystemManager
Static SystemManager variable.
SystemManager & PushSystem(Args &&... args)
Push a system to this manager.
SystemManager(const SystemManager &)=delete
Copy Constructor Function.
virtual ~SystemManager()
Destructor Function.
SystemManager & PopSystem(const std::string &systemName)
Push a system to this manager.
static scl::linked_unordered_map< std::string, std::shared_ptr< System > > m_Identities
Static System Map.
SystemManager & operator=(const SystemManager &)=delete
Copy Assignment Operation.
SystemManager Class. This class defines the behave of SystemManager.
virtual ~System()=default
Destructor Function.
System & operator=(const System &)=delete
Copy Assignment Operation.
virtual void OnSystemShutDown()
This interface defines the behave on specific system shutdown. Called when system poped from SystemMa...
std::string m_SystemName
Specific system name.
virtual void OnSystemUpdate(TimeStep &ts)
This interface defines the behave on specific system updated every frame.
System(const std::string &systemName)
Constructor Function. Init class variable. Usually call it.
System(const System &)=delete
Copy Constructor Function.
virtual void OnEvent(Event &event)
This interface defines the behave on global event function pointer is called.
virtual void OnSystemInitialize()
This interface defines the behave on specific system initialized. Called when system Pushed to System...
System Class. This class defines the basic behaves of System. When we create an new System,...
This Class handles our engine time step during frames. Global Unique.
Definition TimeStep.h:22
TransformComponent Class. This class defines the specific behaves of TransformComponent.
UUIDComponent Class. This class defines the specific behaves of UUIDComponent.
This class helps to generate a uuid for one resource.
Definition UUID.h:16
virtual void OnDeactivate() override
This interface defines the specific world behave after on activated.
virtual void OnActivate(TimeStep &ts) override
This interface define the specific world behave on activated.
virtual void OnPreActivate() override
This interface define the specific world behave before on activated.
void RemoveFromRoot(Entity &entity)
Remove a entity from this world root.
Definition World.cpp:58
void AddToRoot(Entity &entity)
Add a entity to this world root.
Definition World.cpp:67
World Class. This class defines the basic behaves of World. When we create an new world,...
Definition World.h:41
The container combines hashmap and list together. Used in the case that we want iter a hashmap in ord...
FileModes
file mode
Definition FileLibrary.h:32
@ FILE_MODE_READ
model : read
Definition FileLibrary.h:37
@ FILE_MODE_WRITE
model : write
Definition FileLibrary.h:42
void * handle
FILE* handle. Need cast while use.
Definition FileLibrary.h:21
bool is_valid
Is this handle Valid.
Definition FileLibrary.h:26
This Struct is FILE* handle pointer Wrapper.
Definition FileLibrary.h:15
Accessors Item data.
std::string generator
Definition GltfAsset.h:25
Asset Item data.
Definition GltfAsset.h:24
BufferViews Item data.
std::unique_ptr< std::vector< char > > buffer
Definition GltfBuffers.h:27
Buffers Item data.
Definition GltfBuffers.h:24
Cameras Item data.
Definition GltfCameras.h:24
Images Item data.
Definition GltfImages.h:28
Wrapper of 3D Transform.
Definition Transform.h:16