#include <fstream>
#include <string>
#include <sstream>
+#include <vector>
#include <jthread.h>
#include <jmutex.h>
#include <jmutexautolock.h>
}
inline u16 readU16(std::istream &is)
{
- char buf[12];
- is.read(buf, 12);
+ char buf[2];
+ is.read(buf, 2);
return readU16((u8*)buf);
}
}
inline f32 readF1000(std::istream &is)
{
- char buf[12];
- is.read(buf, 12);
+ char buf[2];
+ is.read(buf, 2);
return readF1000((u8*)buf);
}
TimeTaker
*/
-class IrrlichtWrapper;
-
class TimeTaker
{
public:
return *mbs;
}
+// Split a string using the given delimiter. Returns a vector containing
+// the component parts.
+inline std::vector<std::wstring> str_split(const std::wstring &str, wchar_t delimiter)
+{
+ std::vector<std::wstring> parts;
+ std::wstringstream sstr(str);
+ std::wstring part;
+ while(std::getline(sstr, part, delimiter))
+ parts.push_back(part);
+ return parts;
+}
+
+
/*
See test.cpp for example cases.
wraps degrees to the range of -360...360
return i;
}
+
+// MSVC2010 includes it's own versions of these
+#if !defined(_MSC_VER) || _MSC_VER < 1600
+
inline s32 stoi(std::string s)
{
return atoi(s.c_str());
return f;
}
+#endif
+
+inline s32 stoi(std::wstring s)
+{
+ return atoi(wide_to_narrow(s).c_str());
+}
+
inline std::string itos(s32 i)
{
std::ostringstream o;
return value;
}
+ void setBool(std::string name, bool value)
+ {
+ if(value)
+ set(name, "true");
+ else
+ set(name, "false");
+ }
+
void setS32(std::string name, s32 value)
{
set(name, itos(value));
*/
// Creates a string with the length as the first two bytes
-inline std::string serializeString(const std::string plain)
+inline std::string serializeString(const std::string &plain)
{
- assert(plain.size() <= 65535);
+ //assert(plain.size() <= 65535);
+ if(plain.size() > 65535)
+ throw SerializationError("String too long for serializeString");
char buf[2];
writeU16((u8*)&buf[0], plain.size());
std::string s;
}
// Creates a string with the length as the first four bytes
-inline std::string serializeLongString(const std::string plain)
+inline std::string serializeLongString(const std::string &plain)
{
char buf[4];
writeU32((u8*)&buf[0], plain.size());
s32 d = daylength;
s32 t = (((time_of_day)%24000)/(24000/d));
if(t < nightlength/2 || t >= d - nightlength/2)
- return 300;
+ //return 300;
+ return 350;
else if(t >= d/2 - daytimelength/2 && t < d/2 + daytimelength/2)
return 1000;
else
{
m_accumulator += dtime;
if(m_accumulator < wanted_interval)
- {
- dtime = 0;
- return true;
- }
+ return false;
m_accumulator -= wanted_interval;
- return false;
+ return true;
}
protected:
float m_accumulator;