summaryrefslogtreecommitdiff
path: root/src/net/messageout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/messageout.cpp')
-rw-r--r--src/net/messageout.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 8e6a4a7a..950da5f3 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -21,6 +21,10 @@
#include <cstring>
#include <iomanip>
#include <iostream>
+#ifndef USE_NATIVE_DOUBLE
+#include <limits>
+#include <sstream>
+#endif
#include <string>
#include <enet/enet.h>
@@ -98,6 +102,25 @@ void MessageOut::writeLong(int value)
mPos += 4;
}
+void MessageOut::writeDouble(double value)
+{
+#ifdef USE_NATIVE_DOUBLE
+ expand(mPos + sizeof(double));
+ memcpy(mData + mPos, &value, sizeof(double));
+ mPos += sizeof(double);
+#else
+// Rather inefficient, but I don't have a lot of time.
+// If anyone wants to implement a custom double you are more than welcome to.
+ std::ostringstream o;
+ // Highest precision for double
+ o.precision(std::numeric_limits< double >::digits10);
+ o << value;
+ std::string str = o.str();
+ writeByte(str.size());
+ writeString(str, str.size());
+#endif
+}
+
void MessageOut::writeCoordinates(int x, int y)
{
expand(mPos + 3);