Skip to content

Commit

Permalink
Added support for Polycode being able to use single-precision rather …
Browse files Browse the repository at this point in the history
…than only double everywhere
  • Loading branch information
wivlaro committed Jun 15, 2014
1 parent eff3355 commit 39c4fba
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ ENDIF(NOT CMAKE_BUILD_TYPE)
# SET(build_player OFF)
#ENDIF()

IF(NUMBER_IS_SINGLE)
add_definitions(-DPOLYCODE_NUMBER_IS_SINGLE)
ENDIF()

# Options for what components to build
#OPTION(POLYCODE_BUILD_SHARED "Build Polycode shared libraries" OFF)
#OPTION(POLYCODE_BUILD_STATIC "Build Polycode static libraries" ON)
Expand Down
9 changes: 7 additions & 2 deletions Core/Contents/Include/PolyColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ namespace Polycode {
* @param b Blue value 0-1
* @param a Alpha value 0-1
*/
Color(Number r,Number g, Number b, Number a);

Color(float r,float g,float b,float a);

/**
* @copydoc Color::Color(float,float,float,float)
*/
Color(double r,double g,double b,double a);

/**
* Default constructor.
*/
Expand Down
4 changes: 2 additions & 2 deletions Core/Contents/Include/PolyCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ namespace Polycode {

/**
* Returns the total ticks elapsed since launch.
* @return Time elapsed since launch in floating point microseconds.
* @return Time elapsed since launch in floating point seconds.
*/
Number getTicksFloat();
double getTicksFloat();

void setUserPointer(void *ptr) { userPointer = ptr; }
void *getUserPointer() { return userPointer; }
Expand Down
4 changes: 4 additions & 0 deletions Core/Contents/Include/PolyGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ THE SOFTWARE.
#define PLATFORM PLATFORM_UNIX
#endif

#ifdef POLYCODE_NUMBER_IS_SINGLE
typedef float Number;
#else
typedef double Number;
#endif

#ifdef _MSC_VER
#if _MSC_VER<=1700
Expand Down
4 changes: 2 additions & 2 deletions Core/Contents/Include/PolySceneSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _PolyExport SceneSprite : public ScenePrimitive
Number spriteHeight;

bool playingOnce;
Number lastTick;
double lastTick;

SceneSpriteResourceEntry *resourceEntry;

Expand All @@ -173,4 +173,4 @@ class SceneSpriteResourceEntry : public Resource {
SceneSprite* sprite;
};

}
}
6 changes: 5 additions & 1 deletion Core/Contents/Source/PolyColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ Color::Color() : r(1),g(1),b(1),a(1){

}

Color::Color(Number r,Number g, Number b, Number a) {
Color::Color(float r,float g, float b, float a) {
setColor(r,g,b,a);
}

Color::Color(double r,double g, double b, double a) {
setColor(r,g,b,a);
}

Expand Down
4 changes: 2 additions & 2 deletions Core/Contents/Source/PolyCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ namespace Polycode {
return ((Number)elapsed)/1000.0f;
}

Number Core::getTicksFloat() {
return ((Number)getTicks())/1000.0f;
double Core::getTicksFloat() {
return getTicks()/1000.0d;
}

void Core::createThread(Threaded *target) {
Expand Down
30 changes: 23 additions & 7 deletions Core/Contents/Source/PolyGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT;
using namespace Polycode;

inline void polycodeGLGetNumberv( GLenum pname, GLdouble *params ) {
glGetDoublev(pname, params);
glGetDoublev(pname, params);
}
inline void polycodeGLGetNumberv( GLenum pname, GLfloat *params ) {
glGetFloatv(pname, params);
Expand Down Expand Up @@ -346,13 +346,29 @@ void OpenGLRenderer::enableDepthTest(bool val) {
glDisable(GL_DEPTH_TEST);
}

inline void loadMatrixNumber(const GLfloat* m) {
glLoadMatrixf(m);
}

inline void loadMatrixNumber(const GLdouble* m) {
glLoadMatrixd(m);
}

inline void multMatrixNumber(const GLfloat* m) {
glMultMatrixf(m);
}

inline void multMatrixNumber(const GLdouble* m) {
glMultMatrixd(m);
}

void OpenGLRenderer::setModelviewMatrix(Matrix4 m) {
glLoadMatrixd(m.ml);
loadMatrixNumber(m.ml);
}

void OpenGLRenderer::multModelviewMatrix(Matrix4 m) {
// glMatrixMode(GL_MODELVIEW);
glMultMatrixd(m.ml);
multMatrixNumber(m.ml);
}

void OpenGLRenderer::enableLighting(bool enable) {
Expand Down Expand Up @@ -492,13 +508,13 @@ void OpenGLRenderer::setBlendingMode(int blendingMode) {

Matrix4 OpenGLRenderer::getProjectionMatrix() {
Number m[16];
glGetDoublev( GL_PROJECTION_MATRIX, m);
polycodeGLGetNumberv( GL_PROJECTION_MATRIX, m);
return Matrix4(m);
}

Matrix4 OpenGLRenderer::getModelviewMatrix() {
Number m[16];
glGetDoublev( GL_MODELVIEW_MATRIX, m);
polycodeGLGetNumberv( GL_MODELVIEW_MATRIX, m);
return Matrix4(m);
}

Expand Down Expand Up @@ -570,7 +586,7 @@ void OpenGLRenderer::setProjectionMatrix(Matrix4 matrix) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glLoadMatrixd(matrix.ml);
loadMatrixNumber(matrix.ml);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Expand All @@ -589,7 +605,7 @@ void OpenGLRenderer::setPerspectiveDefaults() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glGetDoublev( GL_PROJECTION_MATRIX, sceneProjectionMatrix);
polycodeGLGetNumberv( GL_PROJECTION_MATRIX, sceneProjectionMatrix);
currentTexture = NULL;
}

Expand Down
6 changes: 3 additions & 3 deletions Core/Contents/Source/PolyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,9 @@ Vector3 Mesh::calculateBBox() {
Vector3 retVec;

for(int i=0; i < vertices.size(); i++) {
retVec.x = max(retVec.x,fabs(vertices[i]->x));
retVec.y = max(retVec.y,fabs(vertices[i]->y));
retVec.z = max(retVec.z,fabs(vertices[i]->z));
retVec.x = max(retVec.x,(Number)fabs(vertices[i]->x));
retVec.y = max(retVec.y,(Number)fabs(vertices[i]->y));
retVec.z = max(retVec.z,(Number)fabs(vertices[i]->z));
}

if(retVec.x == 0.0) {
Expand Down
6 changes: 3 additions & 3 deletions Core/Contents/Source/PolySceneSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ void SceneSprite::Update() {
if(!currentAnimation)
return;

Number newTick = CoreServices::getInstance()->getCore()->getTicksFloat();
double newTick = CoreServices::getInstance()->getCore()->getTicksFloat();

Number elapsed = newTick - lastTick;
Number elapsed = Number(newTick - lastTick);

if(paused)
return;
Expand Down Expand Up @@ -426,4 +426,4 @@ void SceneSprite::updateSprite() {

mesh->arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;

}
}
2 changes: 1 addition & 1 deletion Core/Contents/Source/PolyString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ size_t String::getDataSizeWithEncoding(int encoding) const {
return contents.size();
}
default:
return NULL;
return 0;
}
}
const char *String::getDataWithEncoding(int encoding) const {
Expand Down
6 changes: 3 additions & 3 deletions Modules/Contents/UI/Source/PolyUIColorBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ void UIColorPicker::updateSelectedColor(bool updateTextFields, bool updateHue, b
hueCol.setColorHSV(currentH, 1.0, 1.0);
hueCol.a = colorAlpha;

mainColorRect->getMesh()->getVertex(0)->vertexColor = Color(1.0,1.0,1.0,colorAlpha);
mainColorRect->getMesh()->getVertex(0)->vertexColor = Color((Number)1,(Number)1,(Number)1,colorAlpha);
mainColorRect->getMesh()->getVertex(1)->vertexColor = hueCol;
mainColorRect->getMesh()->getVertex(2)->vertexColor = Color(0.0,0.0,0.0,colorAlpha);
mainColorRect->getMesh()->getVertex(3)->vertexColor = Color(0.0,0.0,0.0,colorAlpha);
mainColorRect->getMesh()->getVertex(2)->vertexColor = Color((Number)0,(Number)0,(Number)0,colorAlpha);
mainColorRect->getMesh()->getVertex(3)->vertexColor = Color((Number)0,(Number)0,(Number)0,colorAlpha);
mainColorRect->getMesh()->arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;

if(updateHue) {
Expand Down
26 changes: 13 additions & 13 deletions Tools/Contents/polyimport/Source/polyimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,22 @@ int exportToFile(String prefix, bool swapZY, bool addSubmeshes, bool listOnly, b
parentEntry->addChild("cB", "1");
parentEntry->addChild("cA", "1");
parentEntry->addChild("blendMode", "0");
parentEntry->addChild("sX", 1.0);
parentEntry->addChild("sY", 1.0);
parentEntry->addChild("sZ", 1.0);
parentEntry->addChild("sX", Number(1.0));
parentEntry->addChild("sY", Number(1.0));
parentEntry->addChild("sZ", Number(1.0));

parentEntry->addChild("rX", 0.0);
parentEntry->addChild("rY", 0.0);
parentEntry->addChild("rZ", 0.0);
parentEntry->addChild("rW", 1.0);
parentEntry->addChild("rX", Number(0.0));
parentEntry->addChild("rY", Number(0.0));
parentEntry->addChild("rZ", Number(0.0));
parentEntry->addChild("rW", Number(1.0));

parentEntry->addChild("pX", 0.0);
parentEntry->addChild("pY", 0.0);
parentEntry->addChild("pZ", 0.0);
parentEntry->addChild("pX", Number(0.0));
parentEntry->addChild("pY", Number(0.0));
parentEntry->addChild("pZ", Number(0.0));

parentEntry->addChild("bbX", 0.0);
parentEntry->addChild("bbY", 0.0);
parentEntry->addChild("bbZ", 0.0);
parentEntry->addChild("bbX", Number(0.0));
parentEntry->addChild("bbY", Number(0.0));
parentEntry->addChild("bbZ", Number(0.0));

ObjectEntry *children = parentEntry->addChild("children");

Expand Down

0 comments on commit 39c4fba

Please sign in to comment.