First blood
This commit is contained in:
1 parent
04f270f322
commit
5720f8322b
250 files changed
+33215
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#ifndef BINDABLE_VAR_H_INCLUDED
|
||||
#define BINDABLE_VAR_H_INCLUDED
|
||||
|
||||
#include "boost/signal.hpp"
|
||||
#include "boost/variant.hpp"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
//Must be stored in shared_ptr:
|
||||
|
||||
template<typename TYPENAME>
|
||||
class TBindableVar
|
||||
{
|
||||
protected:
|
||||
TYPENAME Variable;
|
||||
|
||||
public:
|
||||
|
||||
boost::signal<void(const TYPENAME&)> OnVarChanged;
|
||||
|
||||
TBindableVar()
|
||||
{
|
||||
}
|
||||
|
||||
TBindableVar(const TYPENAME&& var)
|
||||
: Variable(var)
|
||||
{
|
||||
}
|
||||
|
||||
operator TYPENAME()
|
||||
{
|
||||
return Variable;
|
||||
}
|
||||
|
||||
TYPENAME operator()()
|
||||
{
|
||||
return Variable;
|
||||
}
|
||||
|
||||
TBindableVar<TYPENAME>& operator=(const TYPENAME& var)
|
||||
{
|
||||
Variable = var;
|
||||
OnVarChanged(Variable);
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
} //namespace SE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,132 @@
|
||||
#ifndef CONSOLE_H_INCLUDED
|
||||
#define CONSOLE_H_INCLUDED
|
||||
|
||||
/*
|
||||
This code contains console/log to work with
|
||||
|
||||
Use global variable Console like that:
|
||||
|
||||
*Console<<"something"<<endl;
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifdef TARGET_WIN32
|
||||
#include <fstream>
|
||||
#endif
|
||||
#ifdef TARGET_ANDROID
|
||||
#include <asm/page.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "boost/thread.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
#include "include/Render/RenderMisc.h"
|
||||
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
extern const std::string CONST_CONSOLE_TEX_NAME;
|
||||
|
||||
|
||||
|
||||
class TSimpleConsole
|
||||
{
|
||||
protected:
|
||||
std::string History;
|
||||
|
||||
std::string TextSavedInTriangleList;
|
||||
|
||||
std::shared_ptr<TTriangleList> HistoryTriangeList;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
std::string ConsoleInput;
|
||||
cardinal ConsoleCursor;
|
||||
std::vector<std::string> InputHistory;
|
||||
cardinal InputHistoryCursor;
|
||||
|
||||
TSimpleConsole() : History(""), TextSavedInTriangleList(""), ConsoleCursor(0), InputHistoryCursor(0) { }
|
||||
|
||||
virtual ~TSimpleConsole() { }
|
||||
|
||||
void Clear() { History = ""; }
|
||||
|
||||
void CutHistory();
|
||||
|
||||
virtual std::string GetHistory();
|
||||
|
||||
virtual void Draw();
|
||||
};
|
||||
|
||||
|
||||
#ifdef TARGET_WIN32
|
||||
|
||||
class TFileConsole : public TSimpleConsole
|
||||
{
|
||||
protected:
|
||||
std::string filename;
|
||||
std::ofstream f;
|
||||
public:
|
||||
TFileConsole();
|
||||
|
||||
TFileConsole(const std::string& Afilename);
|
||||
|
||||
~TFileConsole();
|
||||
|
||||
TFileConsole& operator<<(const std::string& s);
|
||||
|
||||
void PrintImmediate(const std::string& s);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TARGET_ANDROID
|
||||
|
||||
class TJavaConsole : public TSimpleConsole
|
||||
{
|
||||
protected:
|
||||
boost::mutex ConsoleMutex;
|
||||
std::string AppDir;
|
||||
std::string LogFilename;
|
||||
public:
|
||||
|
||||
TJavaConsole();
|
||||
|
||||
TJavaConsole& operator<<(const std::string& s);
|
||||
|
||||
void PrintImmediate(const std::string& s);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TARGET_IOS
|
||||
|
||||
class TIosConsole : public TSimpleConsole
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
TIosConsole();
|
||||
|
||||
//TFileConsole(const std::string& Afilename);
|
||||
|
||||
~TIosConsole();
|
||||
|
||||
TIosConsole& operator<<(const std::string& s);
|
||||
|
||||
void PrintImmediate(const std::string& s);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
} //namespace SE
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
#ifndef DATA_TYPES_H_INCLUDED
|
||||
#define DATA_TYPES_H_INCLUDED
|
||||
|
||||
/*
|
||||
This code contains additional data types and some const values to use
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include "boost/lexical_cast.hpp"
|
||||
|
||||
#include "NewDataTypes.h"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
typedef unsigned int cardinal;
|
||||
typedef unsigned short int word;
|
||||
typedef unsigned char byte;
|
||||
|
||||
typedef cardinal* pcardinal;
|
||||
|
||||
//Use mat4 to store projection/modelview matrices (i.e. for shadow mapping)
|
||||
struct mat4
|
||||
{
|
||||
float m[16];
|
||||
};
|
||||
|
||||
struct TSmpTriangle
|
||||
{
|
||||
vec3 p[3];
|
||||
vec3 v;
|
||||
vec3 w;
|
||||
vec3 n;
|
||||
};
|
||||
|
||||
|
||||
const float pi = 3.14159265359f;
|
||||
|
||||
const float CONST_EPSILON = 0.00001f;
|
||||
|
||||
const float WhiteColor[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
const float RedColor[4] = {1.0f, 0.0f, 0.0f, 1.0f};
|
||||
const float NoColor[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
const mat3 IdentityMatrix(vec3(1.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f), vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
const mat4 IdentityMatrix4 =
|
||||
{ 1.f, 0.f, 0.f, 0.f,
|
||||
0.f, 1.f, 0.f, 0.f,
|
||||
0.f, 0.f, 1.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f };
|
||||
|
||||
|
||||
const vec3 ZeroVec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
const vec4 ZeroQuat(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
const std::string fendl="\x0D\x0A"; //Windows-style, for files
|
||||
const std::string endl="\n";
|
||||
|
||||
vec4 InverseQuat(const vec4& q);
|
||||
|
||||
//For shadow mapping or for OpenGL ES 2.0
|
||||
mat4 InverseModelViewMatrix(const mat4& m);
|
||||
mat4 SetToNormalMatrix(const mat4& m);
|
||||
mat4 MakeOrthoMatrix(float width, float height);
|
||||
mat4 MakeFrustumMatrix(float left, float right, float bottom, float top, float nearVal, float farVal);
|
||||
mat4 MakePerspectiveMatrix(float angle, float aspect, float zNear, float zFar);
|
||||
|
||||
mat4 MultMatrixMatrix(const mat4& m1, const mat4& m2);
|
||||
|
||||
bool IsFloatEqual(float a, float b);
|
||||
|
||||
int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr);
|
||||
|
||||
int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr, vec3& CrossPoint);
|
||||
|
||||
int PointInTriangle(const vec3& q, const TSmpTriangle& tr);
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline std::string tostr(T i)
|
||||
{
|
||||
return boost::lexical_cast<std::string>(i);
|
||||
}
|
||||
|
||||
inline int toint(const char* str)
|
||||
{
|
||||
return boost::lexical_cast<int>(str);
|
||||
}
|
||||
|
||||
inline int toint(const std::string& str)
|
||||
{
|
||||
return boost::lexical_cast<int>(str);
|
||||
}
|
||||
//#ifndef TARGET_WIN32 //Already defined in windows.h
|
||||
|
||||
template<typename T>
|
||||
inline T min(T a, T b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T max(T a, T b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
//#endif
|
||||
|
||||
template<typename T>
|
||||
inline T clamp(T a, T c_from, T c_to)
|
||||
{
|
||||
if (a < c_from)
|
||||
{
|
||||
return c_from;
|
||||
}
|
||||
|
||||
if (a > c_to)
|
||||
{
|
||||
return c_to;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T sign(T a)
|
||||
{
|
||||
if (a == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
float roundf(float r);
|
||||
|
||||
template<typename T>
|
||||
T InterpolateLinear(T a, T b, float t)
|
||||
{
|
||||
return a + (b-a)*t;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T InterpolateSqr(T a, T b, float t)
|
||||
{
|
||||
return a + (b-a)*t*t;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
T InterpolateSqrt(T a, T b, float t)
|
||||
{
|
||||
return a + (b-a)*sqrtf(t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool IsPower2(T x)
|
||||
{
|
||||
return ( (x > 0) && ((x & (x - 1)) == 0) );
|
||||
}
|
||||
|
||||
cardinal GetGreaterPower2(cardinal x);
|
||||
|
||||
vec2 StringToVec2(std::string str);
|
||||
vec3 StringToVec3(std::string str);
|
||||
vec4 StringToVec4(std::string str);
|
||||
|
||||
// ================================================
|
||||
// ========== wide strings and UTF8 strings =======
|
||||
// ================================================
|
||||
|
||||
|
||||
void utf8toWStr(std::wstring& dest, const std::string& src);
|
||||
|
||||
void wstrToUtf8(std::string& dest, const std::wstring& src);
|
||||
|
||||
std::string wstrToUtf8(const std::wstring& str);
|
||||
|
||||
std::wstring utf8toWStr(const std::string& str);
|
||||
|
||||
std::ostream& operator<<(std::ostream& f, const std::wstring& s);
|
||||
|
||||
std::istream& operator>>(std::istream& f, std::wstring& s);
|
||||
|
||||
} //namespace SE
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,93 @@
|
||||
#ifndef ERROR_TYPES_H_INCLUDED
|
||||
#define ERROR_TYPES_H_INCLUDED
|
||||
|
||||
/*
|
||||
This code contains exception types for asserting and log watch
|
||||
*/
|
||||
|
||||
#include "include/Utils/Console/Console.h"
|
||||
#include "include/Utils/DataTypes/DataTypes.h"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
#ifdef TARGET_WIN32
|
||||
extern TFileConsole* Console;
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_ANDROID
|
||||
extern TJavaConsole* Console;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TARGET_IOS
|
||||
extern TIosConsole* Console;
|
||||
#endif
|
||||
|
||||
class ErrorCommon
|
||||
{
|
||||
public:
|
||||
ErrorCommon() {/* *Console<<"Common error!";*/ }
|
||||
virtual ~ErrorCommon() { }
|
||||
};
|
||||
|
||||
class ErrorToLog : public ErrorCommon
|
||||
{
|
||||
public:
|
||||
ErrorToLog(const std::string& message) { *Console<<message; }
|
||||
};
|
||||
|
||||
class ErrorFile : public ErrorCommon
|
||||
{
|
||||
public:
|
||||
ErrorFile(const std::string& fileName) { *Console<<"File error in file: "+fileName; }
|
||||
};
|
||||
|
||||
class ErrorFileNotFound : public ErrorFile
|
||||
{
|
||||
public:
|
||||
ErrorFileNotFound(const std::string& fileName) : ErrorFile(fileName) { *Console<<"File not found: "<<fileName; }
|
||||
};
|
||||
|
||||
class ErrorFileNotCorrect : public ErrorFile
|
||||
{
|
||||
public:
|
||||
ErrorFileNotCorrect(const std::string& fileName) : ErrorFile(fileName) { *Console<<"File not correct: "+fileName; }
|
||||
};
|
||||
|
||||
class ErrorFileNotRead : public ErrorFile
|
||||
{
|
||||
public:
|
||||
ErrorFileNotRead(const std::string& fileName) : ErrorFile(fileName) { *Console<<"File could not be read: "+fileName; }
|
||||
};
|
||||
|
||||
class ErrorFileNotLoaded : public ErrorFile
|
||||
{
|
||||
public:
|
||||
ErrorFileNotLoaded(const std::string& fileName) : ErrorFile(fileName) { *Console<<"File could not be loaded: "+fileName; }
|
||||
};
|
||||
|
||||
class ErrorFileTooShort : public ErrorFile
|
||||
{
|
||||
public:
|
||||
ErrorFileTooShort(const std::string& fileName) : ErrorFile(fileName) { *Console<<"File is too short: "+fileName; }
|
||||
};
|
||||
|
||||
|
||||
class ErrorShaderNotExists : public ErrorCommon
|
||||
{
|
||||
public:
|
||||
ErrorShaderNotExists(const std::string& shaderName) { *Console<<"Shader not exists: "+shaderName; }
|
||||
};
|
||||
|
||||
|
||||
class ErrorShaderStackOverflow : public ErrorCommon
|
||||
{
|
||||
public:
|
||||
ErrorShaderStackOverflow() { *Console<<"Shader stack overflow!"; }
|
||||
};
|
||||
|
||||
|
||||
} //namespace SE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,253 @@
|
||||
#ifndef FILE_UTILS_H_INCLUDED
|
||||
#define FILE_UTILS_H_INCLUDED
|
||||
|
||||
/*
|
||||
This code contains API to ease file access
|
||||
|
||||
WINDOWS AND ANDROID
|
||||
*/
|
||||
|
||||
#include "include/Utils/DataTypes/DataTypes.h"
|
||||
#include "include/Utils/Console/Console.h"
|
||||
#include "boost/shared_array.hpp"
|
||||
|
||||
#ifdef TARGET_WIN32
|
||||
#include "include/Utils/WinApi/WinApi.h"
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_ANDROID
|
||||
#include "include/Utils/JniApi/JniApi.h"
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_IOS
|
||||
#include "include/Utils/IosApi/IosApi.h"
|
||||
#endif
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
bool findString(char* in, char* list);
|
||||
//utility for opengl extensions parsing. Not safe
|
||||
|
||||
|
||||
bool IsFileExistsInUserData(const std::string& filename);
|
||||
std::string GetFilePathUserData(const std::string& filename);
|
||||
|
||||
|
||||
#ifdef TARGET_WIN32
|
||||
|
||||
template<typename TYPENAME>
|
||||
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
||||
{
|
||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||
|
||||
FILE * pFile;
|
||||
|
||||
long fSize;
|
||||
|
||||
size_t result;
|
||||
|
||||
TYPENAME* fileData;
|
||||
|
||||
std::string realFileName = fileName;
|
||||
|
||||
|
||||
if (fopen_s(&pFile, realFileName.c_str(), "rb" ) != 0)
|
||||
{
|
||||
throw ErrorToLog("File not loaded: " + fileName);
|
||||
}
|
||||
|
||||
// obtain file size:
|
||||
fseek (pFile , 0 , SEEK_END);
|
||||
fSize = ftell (pFile);
|
||||
rewind (pFile);
|
||||
|
||||
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
||||
|
||||
result = fread (&fileData[0], 1, fSize, pFile);
|
||||
|
||||
if (result != fSize)
|
||||
{
|
||||
throw ErrorToLog("File not loaded: " + fileName);
|
||||
}
|
||||
|
||||
// terminate
|
||||
fclose (pFile);
|
||||
|
||||
intCount = fSize;
|
||||
|
||||
return boost::shared_array<TYPENAME>(fileData);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_ANDROID
|
||||
|
||||
template<typename TYPENAME>
|
||||
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
||||
{
|
||||
if (std::string(fileName.begin(), fileName.begin() + 5) == "/data")
|
||||
{
|
||||
*Console<<"File is in userdata - "+fileName;
|
||||
|
||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||
|
||||
FILE * pFile;
|
||||
|
||||
long fSize;
|
||||
|
||||
size_t result;
|
||||
|
||||
TYPENAME* fileData;
|
||||
|
||||
std::string realFileName = fileName;
|
||||
|
||||
pFile = fopen ( realFileName.c_str(), "rb" );
|
||||
if (pFile == NULL)
|
||||
{
|
||||
throw ErrorToLog("File not loaded: " + fileName);
|
||||
}
|
||||
|
||||
// obtain file size:
|
||||
fseek (pFile , 0 , SEEK_END);
|
||||
fSize = ftell (pFile);
|
||||
rewind (pFile);
|
||||
|
||||
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
||||
|
||||
result = fread (&fileData[0], 1, fSize, pFile);
|
||||
|
||||
if (result != fSize)
|
||||
{
|
||||
throw ErrorToLog("File not loaded: " + fileName);
|
||||
}
|
||||
|
||||
// terminate
|
||||
fclose (pFile);
|
||||
|
||||
intCount = fSize;
|
||||
|
||||
return boost::shared_array<TYPENAME>(fileData);
|
||||
}
|
||||
|
||||
*Console<<"File is in resources - "+fileName;
|
||||
|
||||
return JniCreateMemFromFile<TYPENAME>(fileName, intCount);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_IOS
|
||||
|
||||
template<typename TYPENAME>
|
||||
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
||||
{
|
||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||
|
||||
FILE * pFile;
|
||||
|
||||
long fSize;
|
||||
|
||||
size_t result;
|
||||
|
||||
TYPENAME* fileData;
|
||||
|
||||
std::string realFileName = IosGetFileReadPath(fileName);
|
||||
|
||||
pFile = fopen ( realFileName.c_str(), "rb" );
|
||||
if (pFile == NULL)
|
||||
{
|
||||
throw ErrorToLog("File not loaded: " + fileName);
|
||||
}
|
||||
|
||||
// obtain file size:
|
||||
fseek (pFile , 0 , SEEK_END);
|
||||
fSize = ftell (pFile);
|
||||
rewind (pFile);
|
||||
|
||||
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
||||
|
||||
result = fread (&fileData[0], 1, fSize, pFile);
|
||||
|
||||
if (result != fSize)
|
||||
{
|
||||
throw ErrorToLog("File not loaded: " + fileName);
|
||||
}
|
||||
|
||||
// terminate
|
||||
fclose (pFile);
|
||||
|
||||
intCount = fSize;
|
||||
|
||||
return boost::shared_array<TYPENAME>(fileData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//utitily to process texture uploading
|
||||
inline char* GetFileName(const char* filename)
|
||||
{
|
||||
char* fname = (char*)filename + strlen(filename);
|
||||
|
||||
while ((*fname != '\\')&&(*fname != '/')&&(fname >= filename ))
|
||||
--fname;
|
||||
|
||||
++fname;
|
||||
|
||||
return fname;
|
||||
}
|
||||
|
||||
inline std::string GetFileName(const std::string& filename)
|
||||
{
|
||||
std::string::const_iterator i = filename.end() - 1;
|
||||
|
||||
while ((i > filename.begin() )&&(*i != '\\')&&(*i != '/'))
|
||||
--i;
|
||||
|
||||
if (*i == '\\' || *i == '/')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
return std::string(i, filename.end());
|
||||
}
|
||||
|
||||
//utitily to process texture uploading
|
||||
inline char* GetFileExt(const char* filename)
|
||||
{
|
||||
char* fext = (char*)filename + strlen(filename);
|
||||
|
||||
while (*fext != '.')
|
||||
--fext;
|
||||
|
||||
return fext;
|
||||
}
|
||||
|
||||
inline std::string GetFileExt(const std::string& filename)
|
||||
{
|
||||
std::string::const_iterator i = filename.end() - 1;
|
||||
|
||||
while (*i != '.')
|
||||
--i;
|
||||
|
||||
return std::string(i, filename.end());
|
||||
|
||||
}
|
||||
|
||||
std::string GetFilePath(const std::string& filename);
|
||||
|
||||
#ifdef TARGET_IOS
|
||||
|
||||
//Special for IOS, because Foundation.h conflicts with sq_plus.h
|
||||
|
||||
// Obviously, this returns ResourceManager->PathToResources
|
||||
|
||||
std::string GetPathToResources();
|
||||
#endif
|
||||
|
||||
} //namespace SE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Halibut_Engine.h
|
||||
// Halibut Engine
|
||||
//
|
||||
// Created by vvv ооо on 13.07.12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
|
||||
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
std::string IosGetFileReadPath(const std::string& filename);
|
||||
|
||||
std::string IosGetFilePathUserData(const std::string& filename);
|
||||
|
||||
|
||||
} //namespace SE
|
||||
@@ -0,0 +1,140 @@
|
||||
#ifndef JNI_API_H_INCLUDED
|
||||
#define JNI_API_H_INCLUDED
|
||||
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include "include/Utils/DataTypes/DataTypes.h"
|
||||
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
||||
#include "boost/shared_array.hpp"
|
||||
|
||||
#include "zip.h"
|
||||
#include "zipint.h"
|
||||
#include <zlib.h>
|
||||
#include <zconf.h>
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
This code mostly hard to explain
|
||||
You may treat this like a factory-class
|
||||
|
||||
But you cannot put JNI functions inside a class, that's why it is not a real class
|
||||
|
||||
The only thing you need from here - functions JniCreateDataFromFile and JniCreateDataFromAlignedFile for FileUtils.h/cpp
|
||||
|
||||
See doc for details
|
||||
|
||||
*/
|
||||
|
||||
extern const std::string CONST_JAVA_FILESYSTEM_CLASS_NAME;
|
||||
|
||||
//All 3 deprecated
|
||||
extern cardinal* FileArr;
|
||||
extern int FileSize;
|
||||
extern std::string ApkFilePath;
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_SetupEnviroment(JNIEnv* env, jobject thiz);
|
||||
JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_SetupApkFilePath(JNIEnv* env, jobject thiz, jstring s);
|
||||
JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_ConsoleOut(JNIEnv* env, jobject thiz, jstring s);
|
||||
|
||||
//All 2 deprecated
|
||||
JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_CreateFile(JNIEnv* env, jobject thiz, int fileSize);
|
||||
JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_WriteToFile(JNIEnv* env, jobject thiz, jbyteArray buffer, int bufferSize);
|
||||
|
||||
|
||||
};
|
||||
|
||||
//Deprecated
|
||||
void JniCallOpenFile(const std::string& fileName);
|
||||
|
||||
|
||||
//Deprecated
|
||||
template<typename TYPENAME>
|
||||
boost::shared_array<TYPENAME> JniCreateMemFromFileOld(const std::string& fileName, cardinal& blockCount)
|
||||
{
|
||||
|
||||
//if size is too large - need to do some work
|
||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||
if (SIZEOF_TYPENAME > 4)
|
||||
{
|
||||
throw ErrorToLog("ERROR! Size of type too large - file is not properly aligned. Need work!");
|
||||
}
|
||||
|
||||
if (FileArr != NULL)
|
||||
throw ErrorToLog("ERROR: Trying to reach two files at same time!!!!");
|
||||
|
||||
JniCallOpenFile(fileName);
|
||||
|
||||
// ...
|
||||
//Wait until Java pass all file data to FileArr through WriteToFile()
|
||||
// ...
|
||||
|
||||
//Give pointer away
|
||||
boost::shared_array<TYPENAME> r(reinterpret_cast<TYPENAME*>(FileArr));
|
||||
blockCount = FileSize % SIZEOF_TYPENAME == 0 ? FileSize / SIZEOF_TYPENAME: FileSize / SIZEOF_TYPENAME + 1;
|
||||
FileArr = NULL;
|
||||
FileSize = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
std::string JniGetApplicationDir();
|
||||
|
||||
void JniLoadSound(const std::string& fileName);
|
||||
void JniPlaySound(const std::string& soundName);
|
||||
|
||||
void JniPlayMusic(const std::string& fileName);
|
||||
void JniPlayMusicLooped(const std::string& fileName);
|
||||
void JniStopMusic();
|
||||
|
||||
void JniReleaseAllSoundsAndMusic();
|
||||
void JniPauseAllSoundsAndMusic();//NIU right now
|
||||
void JniResumeAllSoundsAndMusic(); //NIU right now
|
||||
|
||||
void LoadApk(const std::string& fileName, std::vector<char>& returnData);
|
||||
|
||||
void PrintApkContent();
|
||||
|
||||
|
||||
template<typename TYPENAME>
|
||||
boost::shared_array<TYPENAME> JniCreateMemFromFile(const std::string& fileName, cardinal& blockCount)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
//if size is too large - need to do some work
|
||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||
if (SIZEOF_TYPENAME > 4)
|
||||
{
|
||||
throw ErrorToLog("ERROR! Size of type too large - file is not properly aligned. Need work!");
|
||||
}
|
||||
|
||||
std::vector<char> fileData;
|
||||
|
||||
LoadApk(fileName, fileData);
|
||||
|
||||
cardinal fileSize = fileData.size();
|
||||
|
||||
blockCount = fileSize % SIZEOF_TYPENAME == 0 ? fileSize / SIZEOF_TYPENAME: fileSize / SIZEOF_TYPENAME + 1;
|
||||
|
||||
boost::shared_array<TYPENAME> result(new TYPENAME[blockCount]);
|
||||
|
||||
memcpy(&result[0], &fileData[0], fileSize);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
catch(ErrorCommon e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace SE
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef PNG_HELPER_H_INCLUDED
|
||||
#define PNG_HELPER_H_INCLUDED
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#define PNG_DEBUG 3
|
||||
#include "png.h"
|
||||
}
|
||||
|
||||
#include "boost/shared_array.hpp"
|
||||
#include "include/Utils/DataTypes/DataTypes.h"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
struct TPngDataStruct
|
||||
{
|
||||
int Width;
|
||||
int Height;
|
||||
png_byte ColorType;
|
||||
png_byte BitDepth;
|
||||
|
||||
png_structp PngPtr;
|
||||
png_infop InfoPtr;
|
||||
int NumberOfPasses;
|
||||
png_bytep* RowPointers;
|
||||
};
|
||||
|
||||
|
||||
|
||||
TPngDataStruct read_png_file(const boost::shared_array<char>& fileArr, cardinal fileSize);
|
||||
|
||||
|
||||
} //namespace SE
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef SERIALIZE_INTERFACE_H_INCLUDED
|
||||
#define SERIALIZE_INTERFACE_H_INCLUDED
|
||||
|
||||
#include "include/Utils/DataTypes/DataTypes.h"
|
||||
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
||||
#include "boost/property_tree/ptree.hpp"
|
||||
#include "boost/property_tree/xml_parser.hpp"
|
||||
#include "boost/shared_array.hpp"
|
||||
|
||||
#include "boost/foreach.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
std::shared_ptr<boost::property_tree::ptree> StringToPropertyTree(std::string xmlCode, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
||||
|
||||
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(boost::shared_array<char> xmlFileArr, cardinal xmlFileSize, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
||||
|
||||
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(const std::string& fileName, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
||||
|
||||
|
||||
class TSerializeInterface
|
||||
{
|
||||
public:
|
||||
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <typename TKEY, typename TVALUE>
|
||||
class TMapParser : public TSerializeInterface
|
||||
{
|
||||
public:
|
||||
std::map<TKEY, TVALUE> Map;
|
||||
|
||||
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree)
|
||||
{
|
||||
TKEY key = subTree.second.get<TKEY>("<xmlattr>.key");
|
||||
TVALUE value = subTree.second.get<TVALUE>("<xmlattr>.value");
|
||||
|
||||
Map[key] = value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TKEY, typename TVALUE>
|
||||
std::map<TKEY, TVALUE> SerializeToMap(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
TMapParser<TKEY, TVALUE> mapParser;
|
||||
mapParser.Serialize(propertyTree);
|
||||
return mapParser.Map;
|
||||
}
|
||||
|
||||
} //namespace SE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef SIMPLE_TIMER_H_INCLUDED
|
||||
#define SIMPLE_TIMER_H_INCLUDED
|
||||
|
||||
#include "include/Utils/DataTypes/DataTypes.h"
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
class TSimpleTimer
|
||||
{
|
||||
protected:
|
||||
int Timer;
|
||||
public:
|
||||
|
||||
TSimpleTimer();
|
||||
|
||||
void SetTimer(int timer);
|
||||
void Update(cardinal dt);
|
||||
bool IsOver();
|
||||
|
||||
boost::posix_time::time_duration GetPosixTime();
|
||||
|
||||
};
|
||||
|
||||
} //namespace SE
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef UTILS_H_INCLUDED
|
||||
#define UTILS_H_INCLUDED
|
||||
/*
|
||||
This code combines additional routines (such as console/log, exceptions, math utils, file utils) for engine to use
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#include "boost/shared_array.hpp"
|
||||
#include "boost/property_tree/ptree.hpp"
|
||||
#include "boost/foreach.hpp"
|
||||
|
||||
#include "boost/asio.hpp"
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
#include "boost/signal.hpp"
|
||||
|
||||
|
||||
#include "include/Utils/Console/Console.h"
|
||||
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
||||
#include "../GlobalConst.h"
|
||||
#include "include/Utils/FileUtils/FileUtils.h"
|
||||
#include "include/Utils/SerializeInterface/SerializeInterface.h"
|
||||
|
||||
#include "include/Utils/BindableVar.h"
|
||||
#include "include/Utils/SimpleTimer.h"
|
||||
|
||||
#ifdef TARGET_WIN32
|
||||
#include "WinApi/WinApi.h"
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_ANDROID
|
||||
#include "JniApi/JniApi.h"
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_IOS
|
||||
#include "IosApi/IosApi.h"
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#define NOMINMAX 1
|
||||
#include "windows.h"
|
||||
#undef NOMINMAX
|
||||
#include "gl/gl.h"
|
||||
#include "gl/glu.h"
|
||||
#include "gl/glext.h"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
/*
|
||||
Here goes all functions that are platform-specific
|
||||
When I make iOS/Mac/Linux port, I will make same API pair h/cpp
|
||||
*/
|
||||
|
||||
void GetWindowWidthHeight(int& width, int& height);
|
||||
|
||||
int GetWindowWidth();
|
||||
|
||||
int GetWindowHeight();
|
||||
|
||||
} //namespace SE
|
||||
Reference in new issue
Block a user