aboutsummaryrefslogtreecommitdiff
path: root/Source/Serialize.cpp
diff options
context:
space:
mode:
authorrelnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f>2003-01-08 09:05:22 +0000
committerrelnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f>2003-01-08 09:05:22 +0000
commit8efed35df02822682576bae088f5b6a5c78e8dc9 (patch)
treeda099501696fe5456a95e85c98d5b746176419ee /Source/Serialize.cpp
parent9c22203ab6b1f6f61ec4b7c52a7c9c51da9e5844 (diff)
downloadblackshades-8efed35df02822682576bae088f5b6a5c78e8dc9.tar.gz
start of serialization
git-svn-id: svn://svn.icculus.org/blackshades/trunk@44 5198baeb-e213-0410-be47-fc2ff85ca46f
Diffstat (limited to 'Source/Serialize.cpp')
-rw-r--r--Source/Serialize.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/Source/Serialize.cpp b/Source/Serialize.cpp
new file mode 100644
index 0000000..3826a3f
--- /dev/null
+++ b/Source/Serialize.cpp
@@ -0,0 +1,74 @@
+#include "Models.h"
+#include "Quaternions.h"
+#include "Serialize.h"
+
+#include <unistd.h>
+
+/* these all read big-endian data */
+
+int ReadShort(int fd, int count, short *s)
+{
+ while (count--) {
+ unsigned char buf[2];
+
+ read(fd, buf, 2);
+
+ *s = (short)((buf[0] << 8) | buf[1]);
+
+ s++;
+ }
+}
+
+int ReadInt(int fd, int count, int *s)
+{
+ while (count--) {
+ unsigned char buf[4];
+
+ read(fd, buf, 2);
+
+ *s = (int)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
+
+ s++;
+ }
+}
+
+union intfloat {
+ int i;
+ float f;
+} intfloat;
+
+int ReadFloat(int fd, int count, float *f)
+{
+ union intfloat infl;
+
+ while (count--) {
+ ReadInt(fd, 1, &(infl.i));
+
+ *f = infl.f;
+
+ f++;
+ }
+}
+
+int ReadXYZ(int fd, int count, XYZ *xyz)
+{
+ while (count--) {
+ ReadFloat(fd, 1, &(xyz->x));
+ ReadFloat(fd, 1, &(xyz->y));
+ ReadFloat(fd, 1, &(xyz->z));
+
+ xyz++;
+ }
+}
+
+int ReadTexturedTriangle(int fd, int count, TexturedTriangle *tt)
+{
+ while (count--) {
+ ReadShort(fd, 3, tt->vertex);
+ ReadFloat(fd, 1, &(tt->r));
+ ReadFloat(fd, 1, &(tt->g));
+ ReadFloat(fd, 1, &(tt->b));
+
+ tt++;
+ }
+}