aboutsummaryrefslogtreecommitdiff
path: root/src/core.c
diff options
context:
space:
mode:
authorvictorfisac <victorfisac@gmail.com>2016-01-04 19:28:52 +0100
committervictorfisac <victorfisac@gmail.com>2016-01-04 19:28:52 +0100
commit0c539cbf320bf50309704ad768b2dfad4cd7a67a (patch)
tree430b94524164208e5a1c856d03db82bb51e2739c /src/core.c
parent1656d17b22b362e54710b7164638464e02bd7e5a (diff)
parent70d405b41bcbbd73b9f752f4dc3910100abd1a36 (diff)
downloadraylib-0c539cbf320bf50309704ad768b2dfad4cd7a67a.tar.gz
raylib-0c539cbf320bf50309704ad768b2dfad4cd7a67a.zip
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/core.c b/src/core.c
index 14510a1b..06260281 100644
--- a/src/core.c
+++ b/src/core.c
@@ -708,6 +708,67 @@ void ClearDroppedFiles(void)
}
#endif
+// Storage save integer value (to defined position)
+// NOTE: Storage positions is directly related to file memory layout (4 bytes each integer)
+void StorageSaveValue(int position, int value)
+{
+ FILE *storageFile = NULL;
+
+ // Try open existing file to append data
+ storageFile = fopen("storage.data", "rb+");
+
+ // If file doesn't exist, create a new storage data file
+ if (!storageFile) storageFile = fopen("storage.data", "wb");
+
+ if (!storageFile) TraceLog(WARNING, "Storage data file could not be created");
+ else
+ {
+ // Get file size
+ fseek(storageFile, 0, SEEK_END);
+ int fileSize = ftell(storageFile); // Size in bytes
+ fseek(storageFile, 0, SEEK_SET);
+
+ if (fileSize < (position*4)) TraceLog(WARNING, "Storage position could not be found");
+ else
+ {
+ fseek(storageFile, (position*4), SEEK_SET);
+ fwrite(&value, 1, 4, storageFile);
+ }
+
+ fclose(storageFile);
+ }
+}
+
+// Storage load integer value (from defined position)
+// NOTE: If requested position could not be found, value 0 is returned
+int StorageLoadValue(int position)
+{
+ int value = 0;
+
+ // Try open existing file to append data
+ FILE *storageFile = fopen("storage.data", "rb");
+
+ if (!storageFile) TraceLog(WARNING, "Storage data file could not be found");
+ else
+ {
+ // Get file size
+ fseek(storageFile, 0, SEEK_END);
+ int fileSize = ftell(storageFile); // Size in bytes
+ rewind(storageFile);
+
+ if (fileSize < (position*4)) TraceLog(WARNING, "Storage position could not be found");
+ else
+ {
+ fseek(storageFile, (position*4), SEEK_SET);
+ fread(&value, 1, 4, storageFile);
+ }
+
+ fclose(storageFile);
+ }
+
+ return value;
+}
+
// TODO: Gives the ray trace from mouse position
Ray GetMouseRay(Vector2 mousePosition, Camera camera)
{