Added more debugging and option to disable new streflop usage.

This commit is contained in:
Mark Vejvoda 2010-05-01 20:14:25 +00:00
parent 2417f37e21
commit 04bb6659ce
28 changed files with 447 additions and 112 deletions

View File

@ -5,6 +5,7 @@ UseAutoconf ;
Package license.txt readme.txt ;
#### Library ####
SubDir TOP shared_lib sources ;
LIB_STREFLOP_DIRS =

View File

@ -22,12 +22,13 @@ if $(USE_STLPORT_DEBUG)
# if using streflop then add some special compiler defines
if $(USE_STREFLOP)
{
CPPFLAGS += -mfpmath=sse -msse -fsingle-precision-constant -frounding-math -pipe -fno-strict-aliasing -fsignaling-nans -mieee-fp ;
COMPILER_CFLAGS_optimize += -mfpmath=sse -msse -fsingle-precision-constant -frounding-math -pipe -fno-strict-aliasing -fsignaling-nans -mieee-fp -mno-tls-direct-seg-refs ;
COMPILER_CXXFLAGS_optimize += -mfpmath=sse -msse -fsingle-precision-constant -frounding-math -pipe -fno-strict-aliasing -fsignaling-nans -mieee-fp -mno-tls-direct-seg-refs ;
}
COMPILER_CFLAGS += -Wall -W -Wno-unused -Wno-sign-compare ;
COMPILER_CFLAGS_optimize += -O3 -DNDEBUG ;
COMPILER_CXXFLAGS_optimize += -O -DNDEBUG ;
COMPILER_CFLAGS_optimize += -O2 -DNDEBUG -Wall -W -Wno-unused -Wno-sign-compare ;
COMPILER_CXXFLAGS_optimize += -O2 -DNDEBUG -Wall -W -Wno-unused -Wno-sign-compare ;
COMPILER_LIBS_optimize += ;
COMPILER_CFLAGS_debug += -DDEBUG -g3 ;
COMPILER_CXXFLAGS_debug += -DDEBUG -g3 ;

View File

@ -23,6 +23,8 @@ test ".$CXXFLAGS" = "." && CXXFLAGS=" "
# here we define required defines for streflop
AC_DEFINE([USE_STREFLOP], [], [Define if streflop should be used])
AC_DEFINE([STREFLOP_SSE], [], [Define type of streflop to use])
#AC_DEFINE([STREFLOP_X87], [], [Define type of streflop to use])
#AC_DEFINE([STREFLOP_SOFT], [], [Define type of streflop to use])
AC_DEFINE([LIBM_COMPILING_FLT32], [], [Define which libm compile type should be used])
# end

View File

@ -82,6 +82,7 @@ Game::~Game(){
// ==================== init and load ====================
void Game::load(){
Logger &logger= Logger::getInstance();
string mapName= gameSettings.getMap();
string tilesetName= gameSettings.getTileset();
@ -99,7 +100,7 @@ void Game::load(){
}
Config &config = Config::getInstance();
good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
string scenarioDir = "";
if(gameSettings.getScenarioDir() != "") {
@ -215,7 +216,7 @@ void Game::load(){
world.loadScenario(gameSettings.getScenarioDir(), &checksum);
}
good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
}
void Game::init()
@ -247,7 +248,7 @@ void Game::init()
gameCamera.setPos(Vec2f(v.x, v.y));
scriptManager.init(&world, &gameCamera);
good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] creating AI's\n",__FILE__,__FUNCTION__);
@ -286,7 +287,7 @@ void Game::init()
logger.add("Initializing renderer", true);
renderer.initGame(this);
good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
//sounds
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
@ -365,7 +366,7 @@ void Game::update(){
}
renderer.updateParticleManager(rsGame);
good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
}
//call the chat manager

View File

@ -142,49 +142,22 @@ void GameCamera::update(){
}
Quad2i GameCamera::computeVisibleQuad() const{
/*
//maxRenderDistance
float flatDist = maxRenderDistance * -streflop::cos(degToRad(vAng + fov / 2.f));
Vec3f p1(flatDist * sin(degToRad(hAng + fov / 2.f)), maxRenderDistance * sin(degToRad(vAng + fov / 2.f)), flatDist * -streflop::cos(degToRad(hAng + fov / 2.f)));
Vec3f p2(flatDist * sin(degToRad(hAng - fov / 2.f)), maxRenderDistance * sin(degToRad(vAng + fov / 2.f)), flatDist * -streflop::cos(degToRad(hAng - fov / 2.f)));
flatDist = maxRenderDistance * -cos(degToRad(vAng - fov / 2.f));
Vec3f p3(flatDist * sin(degToRad(hAng + fov / 2.f)), maxRenderDistance * sin(degToRad(vAng - fov / 2.f)), flatDist * -streflop::cos(degToRad(hAng + fov / 2.f)));
Vec3f p4(flatDist * sin(degToRad(hAng - fov / 2.f)), maxRenderDistance * sin(degToRad(vAng - fov / 2.f)), flatDist * -streflop::cos(degToRad(hAng - fov / 2.f)));
// find the floor
if(-p1.y > pos.y) {
p1 = p1 * pos.y / abs(p1.y);
}
if(-p2.y > pos.y) {
p2 = p2 * pos.y / abs(p2.y);
}
if(-p3.y > pos.y) {
p3 = p3 * pos.y / abs(p3.y);
}
if(-p4.y > pos.y) {
p4 = p4 * pos.y / abs(p4.y);
}
Vec2i pi1(p1.x, p1.z), pi2(p2.x, p2.z), pi3(p3.x, p3.z), pi4(p4.x, p4.z);
if(hAng>=135 && hAng<=225){
return Quad2i(pi1, pi2, pi3, pi4);
}
if(hAng>=45 && hAng<=135){
return Quad2i(pi3, pi1, pi4, pi2);
}
if(hAng>=225 && hAng<=315) {
return Quad2i(pi2, pi4, pi1, pi3);
}
return Quad2i(pi4, pi3, pi2, pi1);
*/
float nearDist = 20.f;
float dist = pos.y > 20.f ? pos.y * 1.2f : 20.f;
float farDist = 90.f * (pos.y > 20.f ? pos.y / 15.f : 1.f);
float fov = Config::getInstance().getFloat("CameraFov","45");
#ifdef USE_STREFLOP
Vec2f v(streflop::sinf(degToRad(180 - hAng)), streflop::cosf(degToRad(180 - hAng)));
Vec2f v1(streflop::sinf(degToRad(180 - hAng - fov)), streflop::cosf(degToRad(180 - hAng - fov)));
Vec2f v2(streflop::sinf(degToRad(180 - hAng + fov)), streflop::cosf(degToRad(180 - hAng + fov)));
#else
Vec2f v(sinf(degToRad(180 - hAng)), cosf(degToRad(180 - hAng)));
Vec2f v1(sinf(degToRad(180 - hAng - fov)), cosf(degToRad(180 - hAng - fov)));
Vec2f v2(sinf(degToRad(180 - hAng + fov)), cosf(degToRad(180 - hAng + fov)));
#endif
v.normalize();
v1.normalize();
v2.normalize();
@ -246,8 +219,14 @@ void GameCamera::transitionVH(float v, float h) {
}
void GameCamera::zoom(float dist) {
#ifdef USE_STREFLOP
float flatDist = dist * streflop::cosf(degToRad(vAng));
Vec3f offset(flatDist * streflop::sinf(degToRad(hAng)), dist * streflop::sinf(degToRad(vAng)), flatDist * -streflop::cosf(degToRad(hAng)));
#else
float flatDist = dist * cosf(degToRad(vAng));
Vec3f offset(flatDist * sinf(degToRad(hAng)), dist * sinf(degToRad(vAng)), flatDist * -cosf(degToRad(hAng)));
#endif
destPos += offset;
}
@ -308,7 +287,11 @@ void GameCamera::clampAng() {
//move camera forwad but never change heightFactor
void GameCamera::moveForwardH(float d, float response) {
#ifdef USE_STREFLOP
Vec3f offset(streflop::sinf(degToRad(hAng)) * d, 0.f, -streflop::cosf(degToRad(hAng)) * d);
#else
Vec3f offset(sinf(degToRad(hAng)) * d, 0.f, -cosf(degToRad(hAng)) * d);
#endif
destPos += offset;
pos.x += offset.x * response;
pos.z += offset.z * response;
@ -316,7 +299,11 @@ void GameCamera::moveForwardH(float d, float response) {
//move camera to a side but never change heightFactor
void GameCamera::moveSideH(float d, float response){
#ifdef USE_STREFLOP
Vec3f offset(streflop::sinf(degToRad(hAng+90)) * d, 0.f, -streflop::cosf(degToRad(hAng+90)) * d);
#else
Vec3f offset(sinf(degToRad(hAng+90)) * d, 0.f, -cosf(degToRad(hAng+90)) * d);
#endif
destPos += offset;
pos.x += (destPos.x - pos.x) * response;
pos.z += (destPos.z - pos.z) * response;

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Martiño Figueroa
// Copyright (C) 2001-2005 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -19,6 +19,7 @@
using namespace Shared::Platform;
using namespace Shared::Lua;
using namespace Shared::Util;
namespace Glest{ namespace Game{
@ -171,6 +172,7 @@ void ScriptManager::setCameraPosition(const Vec2i &pos){
}
void ScriptManager::createUnit(const string &unitName, int factionIndex, Vec2i pos){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex);
world->createUnit(unitName, factionIndex, pos);
}
@ -275,6 +277,9 @@ int ScriptManager::setCameraPosition(LuaHandle* luaHandle){
int ScriptManager::createUnit(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-3).c_str(),luaArguments.getInt(-2));
thisScriptManager->createUnit(
luaArguments.getString(-3),
luaArguments.getInt(-2),

View File

@ -547,8 +547,8 @@ void Renderer::renderMouse2d(int x, int y, int anim, float fade){
anim= anim*2-maxMouse2dAnim;
color2= (abs(anim * (int)fadeFactor) / static_cast<float>(maxMouse2dAnim)) / 2.f + 0.4f;
color1= (abs(anim * (int)fadeFactor) / static_cast<float>(maxMouse2dAnim)) / 2.f + 0.8f;
color2= (abs(anim*fadeFactor)/static_cast<float>(maxMouse2dAnim))/2.f+0.4f;
color1= (abs(anim*fadeFactor)/static_cast<float>(maxMouse2dAnim))/2.f+0.8f;
glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LINE_BIT);
glEnable(GL_BLEND);
@ -618,7 +618,7 @@ void Renderer::renderMouse3d() {
throw runtime_error(szBuf);
}
Vec3f pos3f= Vec3f((float)pos.x, map->getCell(pos)->getHeight(), (float)pos.y);
Vec3f pos3f= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y);
if(gui->isPlacingBuilding()){
@ -921,7 +921,7 @@ void Renderer::renderTextShadow(const string &text, const Font2D *font,const Vec
textRenderer->begin(font);
glColor3f(0.0f, 0.0f, 0.0f);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
textRenderer->render(text, pos.x - 1, pos.y - 1);
textRenderer->render(text, pos.x-1.0f, pos.y-1.0f);
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
glColor3f(color.x,color.y,color.z);
@ -984,16 +984,16 @@ void Renderer::renderButton(const GraphicButton *button){
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.f, 0.f);
glVertex2f((float)x, (float)y);
glVertex2f(x, y);
glTexCoord2f(0.f, 1.f);
glVertex2f((float)x, (float)(y+h));
glVertex2f(x, y+h);
glTexCoord2f(1.f, 0.f);
glVertex2f((float)(x+w), (float)y);
glVertex2f(x+w, y);
glTexCoord2f(1.f, 1.f);
glVertex2f((float)(x+w), (float)(y+h));
glVertex2f(x+w, y+h);
glEnd();
@ -1011,25 +1011,25 @@ void Renderer::renderButton(const GraphicButton *button){
glBegin(GL_TRIANGLE_FAN);
glColor4fv(color2.ptr());
glVertex2f((float)(x+w/2), (float)(y+h/2));
glVertex2f(x+w/2, y+h/2);
glColor4fv(color1.ptr());
glVertex2f((float)(x-lightSize), (float)(y-lightSize));
glVertex2f(x-lightSize, y-lightSize);
glColor4fv(color1.ptr());
glVertex2f((float)(x+w+lightSize), (float)(y-lightSize));
glVertex2f(x+w+lightSize, y-lightSize);
glColor4fv(color1.ptr());
glVertex2f((float)(x+w+lightSize), (float)(y+h+lightSize));
glVertex2f(x+w+lightSize, y+h+lightSize);
glColor4fv(color1.ptr());
glVertex2f((float)(x+w+lightSize), (float)(y+h+lightSize));
glVertex2f(x+w+lightSize, y+h+lightSize);
glColor4fv(color1.ptr());
glVertex2f((float)(x-lightSize), (float)(y+h+lightSize));
glVertex2f(x-lightSize, y+h+lightSize);
glColor4fv(color1.ptr());
glVertex2f((float)(x-lightSize), (float)(y-lightSize));
glVertex2f(x-lightSize, y-lightSize);
glEnd();
}
@ -1377,7 +1377,7 @@ void Renderer::renderWater(){
GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
computeWaterColor(waterLevel, tc1->getHeight()).ptr());
glMultiTexCoord2fv(GL_TEXTURE1, tc1->getFowTexCoord().ptr());
glTexCoord3f((float)i, 1.f, waterAnim);
glTexCoord3f(i, 1.f, waterAnim);
glVertex3f(
static_cast<float>(i)*Map::mapScale,
waterLevel,
@ -1388,7 +1388,7 @@ void Renderer::renderWater(){
GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
computeWaterColor(waterLevel, tc0->getHeight()).ptr());
glMultiTexCoord2fv(GL_TEXTURE1, tc0->getFowTexCoord().ptr());
glTexCoord3f((float)i, 0.f, waterAnim);
glTexCoord3f(i, 0.f, waterAnim);
glVertex3f(
static_cast<float>(i)*Map::mapScale,
waterLevel,
@ -1405,7 +1405,7 @@ void Renderer::renderWater(){
GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
computeWaterColor(waterLevel, tc1->getHeight()).ptr());
glMultiTexCoord2fv(GL_TEXTURE1, tc1->getFowTexCoord().ptr());
glTexCoord3f((float)i, 1.f, waterAnim);
glTexCoord3f(i, 1.f, waterAnim);
glVertex3f(
static_cast<float>(i)*Map::mapScale,
waterLevel,
@ -1416,7 +1416,7 @@ void Renderer::renderWater(){
GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
computeWaterColor(waterLevel, tc0->getHeight()).ptr());
glMultiTexCoord2fv(GL_TEXTURE1, tc0->getFowTexCoord().ptr());
glTexCoord3f((float)i, 0.f, waterAnim);
glTexCoord3f(i, 0.f, waterAnim);
glVertex3f(
static_cast<float>(i)*Map::mapScale,
waterLevel,
@ -1588,7 +1588,7 @@ void Renderer::renderSelectionEffects(){
}
else{
Vec2i pos= c->getPos();
arrowTarget= Vec3f((float)pos.x, map->getCell(pos)->getHeight(), (float)pos.y);
arrowTarget= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y);
}
renderArrow(unit->getCurrVectorFlat(), arrowTarget, arrowColor, 0.3f);
@ -1598,7 +1598,7 @@ void Renderer::renderSelectionEffects(){
//meeting point arrow
if(unit->getType()->getMeetingPoint()){
Vec2i pos= unit->getMeetingPos();
Vec3f arrowTarget= Vec3f((float)pos.x, map->getCell(pos)->getHeight(), (float)pos.y);
Vec3f arrowTarget= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y);
renderArrow(unit->getCurrVectorFlat(), arrowTarget, Vec3f(0.f, 0.f, 1.f), 0.3f);
}
@ -1779,15 +1779,25 @@ void Renderer::renderMinimap(){
glVertex2i(mx+x, my+mh-y);
glColor4f(1.f, 1.f, 1.f, 0.0f);
#ifdef USE_STREFLOP
glVertex2i(
mx + x + static_cast<int>(20*streflop::sin(ang-pi/5)),
my + mh - (y-static_cast<int>(20*streflop::cos(ang-pi/5))));
#else
glVertex2i(
mx + x + static_cast<int>(20*sin(ang-pi/5)),
my + mh - (y-static_cast<int>(20*cos(ang-pi/5))));
#endif
glColor4f(1.f, 1.f, 1.f, 0.0f);
#ifdef USE_STREFLOP
glVertex2i(
mx + x + static_cast<int>(20*streflop::sin(ang+pi/5)),
my + mh - (y-static_cast<int>(20*streflop::cos(ang+pi/5))));
#else
glVertex2i(
mx + x + static_cast<int>(20*sin(ang+pi/5)),
my + mh - (y-static_cast<int>(20*cos(ang+pi/5))));
#endif
glEnd();
glPopAttrib();
@ -1964,9 +1974,9 @@ void Renderer::renderMenuBackground(const MenuBackground *menuBackground){
glBegin(GL_TRIANGLE_STRIP);
for(int j=1; j<waterTesselation; ++j){
glTexCoord2i(1, 2 % j);
glVertex3f((float)(-waterSize+i * waterQuadSize), waterHeight, (float)(-waterSize + j * waterQuadSize));
glVertex3f(-waterSize+i*waterQuadSize, waterHeight, -waterSize+j*waterQuadSize);
glTexCoord2i(0, 2 % j);
glVertex3f((float)(-waterSize + (i+1) * waterQuadSize), waterHeight, (float)(-waterSize + j * waterQuadSize));
glVertex3f(-waterSize+(i+1)*waterQuadSize, waterHeight, -waterSize+j*waterQuadSize);
}
glEnd();
}
@ -2166,7 +2176,7 @@ void Renderer::renderShadowsToTexture(){
glRotatef(90, 0, 1, 0);
Vec3f pos= game->getGameCamera()->getPos();
glTranslatef(static_cast<float>(-pos.x), 0.0f, static_cast<float>(-pos.z));
glTranslatef(static_cast<int>(-pos.x), 0, static_cast<int>(-pos.z));
}
else{
@ -2398,12 +2408,20 @@ float Renderer::computeMoonAngle(float time){
Vec4f Renderer::computeSunPos(float time){
float ang= computeSunAngle(time);
#ifdef USE_STREFLOP
return Vec4f(-streflop::cos(ang)*sunDist, streflop::sin(ang)*sunDist, 0.f, 0.f);
#else
return Vec4f(-cos(ang)*sunDist, sin(ang)*sunDist, 0.f, 0.f);
#endif
}
Vec4f Renderer::computeMoonPos(float time){
float ang= computeMoonAngle(time);
#ifdef USE_STREFLOP
return Vec4f(-streflop::cos(ang)*moonDist, streflop::sin(ang)*moonDist, 0.f, 0.f);
#else
return Vec4f(-cos(ang)*moonDist, sin(ang)*moonDist, 0.f, 0.f);
#endif
}
Vec3f Renderer::computeLightColor(float time){

View File

@ -8,10 +8,7 @@
// License, or (at your option) any later version
// ==============================================================
#ifdef USE_STREFLOP
#include "streflop.h"
#endif
#include "math_wrapper.h"
#include "main.h"
#include <string>
@ -270,11 +267,12 @@ int glestMain(int argc, char** argv){
AllocRegistry memoryLeaks = AllocRegistry::getInstance();
#endif
#ifdef STREFLOP_H
streflop_init<streflop::Simple>();
#ifdef USE_STREFLOP
//streflop_init<streflop::Simple>();
printf("%s, STREFLOP enabled.\n",getNetworkVersionString().c_str());
#else
printf("%s, STREFLOP disabled.\n",getNetworkVersionString().c_str());
printf("%s, STREFLOP NOT enabled.\n",getNetworkVersionString().c_str());
#endif
SystemFlags::init();

View File

@ -155,8 +155,19 @@ void MainMenu::keyPress(char c){
}
void MainMenu::setState(MenuState *state){
if(oldstate!=NULL) delete oldstate;
oldstate=this->state;
if(oldstate != NULL && oldstate != state) {
delete oldstate;
if(oldstate != this->state) {
oldstate=this->state;
}
else {
oldstate = NULL;
}
}
else {
oldstate=this->state;
}
this->state= state;
GraphicComponent::resetFade();
menuBackground.setTargetCamera(state->getCamera());

View File

@ -176,8 +176,9 @@ void FileTransferSocketThread::execute()
clientSocket->send(data,256);
clientSocket->receive(data,256);
if(*data != ACK)
;//transfer error
if(*data != ACK) {
//transfer error
}
int remain=file.filesize % 512 ;
int packs=(file.filesize-remain)/512;
@ -191,8 +192,9 @@ void FileTransferSocketThread::execute()
// ; //read error
clientSocket->send(data,512);
clientSocket->receive(data,256);
if(*data!=ACK)
;//transfer error
if(*data!=ACK) {
//transfer error
}
}
infile.read(data,remain);
@ -203,8 +205,9 @@ void FileTransferSocketThread::execute()
clientSocket->send(data,remain);
clientSocket->receive(data,256);
if(*data!=ACK)
;//transfer error
if(*data!=ACK) {
//transfer error
}
infile.close();
}
@ -238,8 +241,9 @@ void FileTransferSocketThread::execute()
clientSocket.send(data,256);
clientSocket.receive(data,256);
if(*data!=ACK)
;//transfer error
if(*data!=ACK) {
//transfer error
}
clientSocket.receive(data,256);
if(*data == SEND_FILE)

View File

@ -296,11 +296,12 @@ void Faction::applyCostsOnInterval(){
}
//decrement consumables
if(!getCpuControl() ||
getCpuControl() && !scriptManager->getPlayerModifiers(this->thisFaction)->getAiEnabled())
if((getCpuControl() == true) ||
(getCpuControl() == true && scriptManager->getPlayerModifiers(this->thisFaction)->getAiEnabled() == false))
{
for(int j=0; j<getUnitCount(); ++j){
Unit *unit= getUnit(j);
assert(unit != NULL);
if(unit->isOperative()){
for(int k=0; k<unit->getType()->getCostCount(); ++k){
const Resource *resource= unit->getType()->getCost(k);

View File

@ -418,7 +418,11 @@ void Unit::setTargetPos(const Vec2i &targetPos){
Vec2i relPos= targetPos - pos;
Vec2f relPosf= Vec2f((float)relPos.x, (float)relPos.y);
#ifdef USE_STREFLOP
targetRotation= radToDeg(streflop::atan2(relPosf.x, relPosf.y));
#else
targetRotation= radToDeg(atan2(relPosf.x, relPosf.y));
#endif
targetRef= NULL;
this->targetPos= targetPos;
@ -1006,8 +1010,11 @@ void Unit::updateTarget(){
targetPos= target->getCellPos();
Vec2i relPos= targetPos - pos;
Vec2f relPosf= Vec2f((float)relPos.x, (float)relPos.y);
#ifdef USE_STREFLOP
targetRotation= radToDeg(streflop::atan2(relPosf.x, relPosf.y));
#else
targetRotation= radToDeg(atan2(relPosf.x, relPosf.y));
#endif
//update target vec
targetVec= target->getCurrVector();

View File

@ -187,7 +187,7 @@ public:
string getCommandTypeListDesc() const;
float getRotatedBuildPos() { return rotatedBuildPos; }
float setRotatedBuildPos(float value) { rotatedBuildPos = value; }
void setRotatedBuildPos(float value) { rotatedBuildPos = value; }
private:
void computeFirstStOfClass();

View File

@ -667,7 +667,11 @@ bool PosCircularIterator::next(){
if(pos.y>center.y+radius)
return false;
}
#ifdef USE_STREFLOP
while(streflop::floor(pos.dist(center)) >= (radius+1) || !map->isInside(pos));
#else
while(floor(pos.dist(center)) >= (radius+1) || !map->isInside(pos));
#endif
//while(!(pos.dist(center) <= radius && map->isInside(pos)));
return true;

View File

@ -195,8 +195,11 @@ void Tileset::load(const string &dir, Checksum *checksum){
const XmlNode *weatherNode= parametersNode->getChild("weather");
float sunnyProb= weatherNode->getAttribute("sun")->getFloatValue(0.f, 1.f);
float rainyProb= weatherNode->getAttribute("rain")->getFloatValue(0.f, 1.f) + sunnyProb;
#ifdef USE_STREFLOP
float rnd= streflop::fabs(random.randRange(-1.f, 1.f));
#else
float rnd= fabs(random.randRange(-1.f, 1.f));
#endif
if(rnd<sunnyProb){
weather= wSunny;
}

View File

@ -708,7 +708,7 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance){
//get vars
int damage= ast->getTotalAttackStrength(attacker->getTotalUpgrade());
float damage= ast->getTotalAttackStrength(attacker->getTotalUpgrade());
int var= ast->getAttackVar();
int armor= attacked->getType()->getTotalArmor(attacked->getTotalUpgrade());
float damageMultiplier= world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType());
@ -839,8 +839,11 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, con
for(int j=center.y-range; j<center.y+range+size; ++j){
//cells insede map and in range
#ifdef USE_STREFLOP
if(map->isInside(i, j) && streflop::floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){
#else
if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){
#endif
//all fields
for(int k=0; k<fieldCount; k++){
Field f= static_cast<Field>(k);

View File

@ -13,8 +13,7 @@
#ifndef _SHARED_GRAPHICS_VEC_H_
#define _SHARED_GRAPHICS_VEC_H_
#include "streflop_cond.h"
//#include <cmath>
#include "math_wrapper.h"
#include <string>
#include <sstream>
@ -127,7 +126,11 @@ public:
}
float length() const{
#ifdef USE_STREFLOP
return static_cast<float>(streflop::sqrt(static_cast<float>(x*x + y*y)));
#else
return static_cast<float>(sqrt(static_cast<float>(x*x + y*y)));
#endif
}
void normalize(){
@ -266,7 +269,11 @@ public:
}
float length() const{
#ifdef USE_STREFLOP
return static_cast<float>(streflop::sqrt(x*x + y*y + z*z));
#else
return static_cast<float>(sqrt(x*x + y*y + z*z));
#endif
}
void normalize(){

View File

@ -108,15 +108,15 @@ private:
int lastMouseX[3];
int lastMouseY[3];
static int64 lastMouseEvent; /** for use in mouse hover calculations */
static unsigned int lastMouseEvent; /** for use in mouse hover calculations */
static MouseState mouseState;
static Vec2i mousePos;
static bool isKeyPressedDown;
static bool isFullScreen;
static SDL_keysym keystate;
static void setLastMouseEvent(int64 lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;}
static int64 getLastMouseEvent() {return Window::lastMouseEvent;}
static void setLastMouseEvent(unsigned int lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;}
static unsigned int getLastMouseEvent() {return Window::lastMouseEvent;}
static const MouseState &getMouseState() {return Window::mouseState;}
static void setMouseState(MouseButton b, bool state) {Window::mouseState.set(b, state);}

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published

View File

@ -15,10 +15,10 @@
#include <string>
#include <fstream>
#include <map>
#include "thread.h"
//#include "thread.h"
using std::string;
using namespace Shared::Platform;
//using namespace Shared::Platform;
namespace Shared{ namespace Util{
@ -45,7 +45,7 @@ public:
this->fileStream = NULL;
this->debugLogFileName = "";
this->fileStreamOwner = false;
this->mutex = NULL;
//this->mutex = NULL;
}
SystemFlagsType(DebugType debugType) {
this->debugType = debugType;
@ -53,7 +53,7 @@ public:
this->fileStream = NULL;
this->debugLogFileName = "";
this->fileStreamOwner = false;
this->mutex = NULL;
//this->mutex = NULL;
}
SystemFlagsType(DebugType debugType,bool enabled,
std::ofstream *fileStream,std::string debugLogFileName) {
@ -62,14 +62,14 @@ public:
this->fileStream = fileStream;
this->debugLogFileName = debugLogFileName;
this->fileStreamOwner = false;
this->mutex = mutex;
//this->mutex = mutex;
}
bool enabled;
std::ofstream *fileStream;
std::string debugLogFileName;
bool fileStreamOwner;
Mutex *mutex;
//Mutex *mutex;
};
protected:
@ -122,6 +122,7 @@ template<typename T>
void deleteMapValues(T beginIt, T endIt){
for(T it= beginIt; it!=endIt; ++it){
delete it->second;
it->second = NULL;
}
}

View File

@ -9,7 +9,7 @@
// License, or (at your option) any later version
// ==============================================================
#include "streflop_cond.h"
#include "math_wrapper.h"
#include "particle.h"
#include <cassert>
@ -263,12 +263,21 @@ void FireParticleSystem::initParticle(Particle *p, int particleIndex){
ParticleSystem::initParticle(p, particleIndex);
float ang= random.randRange(-2.0f*pi, 2.0f*pi);
#ifdef USE_STREFLOP
float mod= streflop::fabsf(random.randRange(-radius, radius));
float x= streflop::sinf(ang)*mod;
float y= streflop::cosf(ang)*mod;
float radRatio= streflop::sqrtf(streflop::sqrtf(mod/radius));
#else
float mod= fabsf(random.randRange(-radius, radius));
float x= sinf(ang)*mod;
float y= cosf(ang)*mod;
float radRatio= sqrtf(sqrtf(mod/radius));
#endif
p->color= colorNoEnergy*0.5f + colorNoEnergy*0.5f*radRatio;
p->energy= static_cast<int>(maxParticleEnergy*radRatio) + random.randRange(-varParticleEnergy, varParticleEnergy);
@ -301,9 +310,15 @@ void FireParticleSystem::setRadius(float radius){
}
void FireParticleSystem::setWind(float windAngle, float windSpeed){
#ifdef USE_STREFLOP
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
#else
this->windSpeed.x= sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= cosf(degToRad(windAngle))*windSpeed;
#endif
}
@ -366,12 +381,21 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
ParticleSystem::initParticle(p, particleIndex);
float ang= random.randRange(-2.0f*pi, 2.0f*pi);
#ifdef USE_STREFLOP
float mod= streflop::fabsf(random.randRange(-radius, radius));
float x= streflop::sinf(ang)*mod;
float y= streflop::cosf(ang)*mod;
float radRatio= streflop::sqrtf(streflop::sqrtf(mod/radius));
#else
float mod= fabsf(random.randRange(-radius, radius));
float x= sinf(ang)*mod;
float y= cosf(ang)*mod;
float radRatio= sqrtf(sqrtf(mod/radius));
#endif
//p->color= color*0.5f + color*0.5f*radRatio;
p->color=color;
@ -393,10 +417,18 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
else
{// rotate it according to rotation
float rad=degToRad(rotation);
#ifdef USE_STREFLOP
p->pos= Vec3f(pos.x+x+offset.z*streflop::sinf(rad)+offset.x*streflop::cosf(rad), pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+(offset.z*streflop::cosf(rad)-offset.x*streflop::sinf(rad)));
if(relativeDirection){
p->speed=Vec3f(p->speed.z*streflop::sinf(rad)+p->speed.x*streflop::cosf(rad),p->speed.y,(p->speed.z*streflop::cosf(rad)-p->speed.x*streflop::sinf(rad)));
}
#else
p->pos= Vec3f(pos.x+x+offset.z*sinf(rad)+offset.x*cosf(rad), pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+(offset.z*cosf(rad)-offset.x*sinf(rad)));
if(relativeDirection){
p->speed=Vec3f(p->speed.z*sinf(rad)+p->speed.x*cosf(rad),p->speed.y,(p->speed.z*cosf(rad)-p->speed.x*sinf(rad)));
}
#endif
}
}
@ -449,9 +481,15 @@ void UnitParticleSystem::setRadius(float radius){
}
void UnitParticleSystem::setWind(float windAngle, float windSpeed){
#ifdef USE_STREFLOP
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
#else
this->windSpeed.x= sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= cosf(degToRad(windAngle))*windSpeed;
#endif
}
@ -499,9 +537,15 @@ void RainParticleSystem::setRadius(float radius){
}
void RainParticleSystem::setWind(float windAngle, float windSpeed){
#ifdef USE_STREFLOP
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
#else
this->windSpeed.x= sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= cosf(degToRad(windAngle))*windSpeed;
#endif
}
// ===========================================================================
@ -543,9 +587,15 @@ void SnowParticleSystem::setRadius(float radius){
}
void SnowParticleSystem::setWind(float windAngle, float windSpeed){
#ifdef USE_STREFLOP
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
#else
this->windSpeed.x= sinf(degToRad(windAngle))*windSpeed;
this->windSpeed.y= 0.0f;
this->windSpeed.z= cosf(degToRad(windAngle))*windSpeed;
#endif
}
// ===========================================================================
@ -655,8 +705,13 @@ void ProjectileParticleSystem::update(){
case tSpiral:
{
pos= flatPos;
#ifdef USE_STREFLOP
pos+= xVector * streflop::cos(t*trajectoryFrequency*targetVector.length())*trajectoryScale;
pos+= yVector * streflop::sin(t*trajectoryFrequency*targetVector.length())*trajectoryScale;
#else
pos+= xVector * cos(t*trajectoryFrequency*targetVector.length())*trajectoryScale;
pos+= yVector * sin(t*trajectoryFrequency*targetVector.length())*trajectoryScale;
#endif
}
break;

View File

@ -9,7 +9,7 @@
// License, or (at your option) any later version
// ==============================================================
#include "streflop_cond.h"
#include "math_wrapper.h"
#include "pixmap.h"
#include <stdexcept>
@ -655,12 +655,19 @@ void Pixmap2D::splat(const Pixmap2D *leftUp, const Pixmap2D *rightUp, const Pixm
float distRd= splatDist(Vec2i(i, j), Vec2i(w, h));
const float powFactor= 2.0f;
#ifdef USE_STREFLOP
distLu= streflop::pow(distLu, powFactor);
distRu= streflop::pow(distRu, powFactor);
distLd= streflop::pow(distLd, powFactor);
distRd= streflop::pow(distRd, powFactor);
avg= streflop::pow(avg, powFactor);
#else
distLu= pow(distLu, powFactor);
distRu= pow(distRu, powFactor);
distLd= pow(distLd, powFactor);
distRd= pow(distRd, powFactor);
avg= pow(avg, powFactor);
#endif
float lu= distLu>avg? 0: ((avg-distLu))*random.randRange(0.5f, 1.0f);
float ru= distRu>avg? 0: ((avg-distRu))*random.randRange(0.5f, 1.0f);
float ld= distLd>avg? 0: ((avg-distLd))*random.randRange(0.5f, 1.0f);

View File

@ -9,7 +9,7 @@
// License, or (at your option) any later version
// ==============================================================
#include "streflop_cond.h"
#include "math_wrapper.h"
#include "quaternion.h"
#include "leak_dumper.h"
@ -67,15 +67,23 @@ void Quaternion::setAddIdentity(){
}
void Quaternion::setAxisAngle(const AxisAngle &axisAngle){
#ifdef USE_STREFLOP
w= streflop::cosf(axisAngle.angle/2.0f);
v.x= axisAngle.axis.x * streflop::sinf(axisAngle.angle/2.0f);
v.y= axisAngle.axis.y * streflop::sinf(axisAngle.angle/2.0f);
v.z= axisAngle.axis.z * streflop::sinf(axisAngle.angle/2.0f);
#else
w= cosf(axisAngle.angle/2.0f);
v.x= axisAngle.axis.x * sinf(axisAngle.angle/2.0f);
v.y= axisAngle.axis.y * sinf(axisAngle.angle/2.0f);
v.z= axisAngle.axis.z * sinf(axisAngle.angle/2.0f);
#endif
}
void Quaternion::setEuler(const EulerAngles &eulerAngles){
Quaternion qx, qy, qz, qr;
#ifdef USE_STREFLOP
qx.w= streflop::cosf(eulerAngles.x/2.0f);
qx.v= Vec3f(streflop::sinf(eulerAngles.x/2.0f), 0.0f, 0.0f);
@ -84,6 +92,16 @@ void Quaternion::setEuler(const EulerAngles &eulerAngles){
qz.w= streflop::cosf(eulerAngles.z/2.0f);
qz.v= Vec3f(0.0f, 0.0f, streflop::sinf(eulerAngles.z/2.0f));
#else
qx.w= cosf(eulerAngles.x/2.0f);
qx.v= Vec3f(sinf(eulerAngles.x/2.0f), 0.0f, 0.0f);
qy.w= cosf(eulerAngles.y/2.0f);
qy.v= Vec3f(0.0f, sinf(eulerAngles.y/2.0f), 0.0f);
qz.w= cosf(eulerAngles.z/2.0f);
qz.v= Vec3f(0.0f, 0.0f, sinf(eulerAngles.z/2.0f));
#endif
qr= qx*qy*qz;
@ -92,7 +110,11 @@ void Quaternion::setEuler(const EulerAngles &eulerAngles){
}
float Quaternion::length(){
#ifdef USE_STREFLOP
return streflop::sqrt(w*w+v.x*v.x+v.y*v.y+v.z*v.z);
#else
return sqrt(w*w+v.x*v.x+v.y*v.y+v.z*v.z);
#endif
}
Quaternion Quaternion::conjugate(){
@ -184,7 +206,11 @@ Matrix4f Quaternion::toMatrix4() const{
AxisAngle Quaternion::toAxisAngle() const{
float scale= 1.0f/(v.x*v.x + v.y*v.y + v.z*v.z);
#ifdef USE_STREFLOP
return AxisAngle(v*scale, 2*streflop::acosf(w));
#else
return AxisAngle(v*scale, 2*acosf(w));
#endif
}
Vec3f Quaternion::getLocalXAxis() const{

View File

@ -0,0 +1,192 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "lua_script.h"
#include <stdexcept>
#include "conversion.h"
#include "leak_dumper.h"
using namespace std;
using namespace Shared::Util;
namespace Shared{ namespace Lua{
// =====================================================
// class LuaScript
// =====================================================
LuaScript::LuaScript(){
luaState= luaL_newstate();
luaL_openlibs(luaState);
if(luaState==NULL){
throw runtime_error("Can not allocate lua state");
}
argumentCount= -1;
}
LuaScript::~LuaScript(){
lua_close(luaState);
}
void LuaScript::loadCode(const string &code, const string &name){
int errorCode= luaL_loadbuffer(luaState, code.c_str(), code.size(), name.c_str());
if(errorCode!=0){
throw runtime_error("Error loading lua code: " + errorToString(errorCode));
}
//run code
errorCode= lua_pcall(luaState, 0, 0, 0)!=0;
if(errorCode!=0){
throw runtime_error("Error initializing lua: " + errorToString(errorCode));
}
}
void LuaScript::beginCall(const string& functionName){
lua_getglobal(luaState, functionName.c_str());
argumentCount= 0;
}
void LuaScript::endCall(){
lua_pcall(luaState, argumentCount, 0, 0);
}
void LuaScript::registerFunction(LuaFunction luaFunction, const string &functionName){
lua_pushcfunction(luaState, luaFunction);
lua_setglobal(luaState, functionName.c_str());
}
string LuaScript::errorToString(int errorCode){
string error;
switch(errorCode){
case LUA_ERRSYNTAX:
error+= "Syntax error";
break;
case LUA_ERRRUN:
error+= "Runtime error";
break;
case LUA_ERRMEM:
error+= "Memory allocation error";
break;
case LUA_ERRERR:
error+= "Error while running the error handler";
break;
default:
error+= "Unknown error";
}
error += string(": ")+luaL_checkstring(luaState, -1);
return error;
}
// =====================================================
// class LuaArguments
// =====================================================
LuaArguments::LuaArguments(lua_State *luaState){
this->luaState= luaState;
returnCount= 0;
}
int LuaArguments::getInt(int argumentIndex) const{
if(!lua_isnumber(luaState, argumentIndex)){
throwLuaError("Can not get int from Lua state");
}
return luaL_checkint(luaState, argumentIndex);
}
string LuaArguments::getString(int argumentIndex) const{
if(!lua_isstring(luaState, argumentIndex)){
throwLuaError("Can not get string from Lua state");
}
return luaL_checkstring(luaState, argumentIndex);
}
Vec2i LuaArguments::getVec2i(int argumentIndex) const{
Vec2i v;
if(!lua_istable(luaState, argumentIndex)){
throwLuaError("Can not get vec2i from Lua state, value on the stack is not a table");
}
if(luaL_getn(luaState, argumentIndex)!=2){
throwLuaError("Can not get vec2i from Lua state, array size not 2");
}
lua_rawgeti(luaState, argumentIndex, 1);
v.x= luaL_checkint(luaState, argumentIndex);
lua_pop(luaState, 1);
lua_rawgeti(luaState, argumentIndex, 2);
v.y= luaL_checkint(luaState, argumentIndex);
lua_pop(luaState, 1);
return v;
}
void LuaArguments::returnInt(int value){
++returnCount;
lua_pushinteger(luaState, value);
}
void LuaArguments::returnString(const string &value){
++returnCount;
lua_pushstring(luaState, value.c_str());
}
void LuaArguments::returnVec2i(const Vec2i &value){
++returnCount;
lua_newtable(luaState);
lua_pushnumber(luaState, value.x);
lua_rawseti(luaState, -2, 1);
lua_pushnumber(luaState, value.y);
lua_rawseti(luaState, -2, 2);
}
void LuaArguments::throwLuaError(const string &message) const{
string stackString;
int stackSize = lua_gettop(luaState);
//build stack string
for(int i= 1; i<=stackSize; ++i){
stackString+= "-" + intToStr(i) + ": ";
if(lua_isnumber(luaState, -i)){
stackString+= "Number: " + doubleToStr(luaL_checknumber(luaState, -i ));
}
else if(lua_isstring(luaState, -i)){
stackString+= "String: " + string(luaL_checkstring(luaState, -i));
}
else if(lua_istable(luaState, -i)){
stackString+= "Table (" + intToStr(luaL_getn(luaState, -i)) + ")";
}
else
{
stackString+= "Unknown";
}
stackString+= "\n";
}
throw runtime_error("Lua error: " + message + "\n\nLua Stack:\n" + stackString);
}
}}//end namespace

View File

@ -29,6 +29,8 @@ int MessageBox(int handle, const char *msg, const char *title, int buttons) {
int ret = system(cmd);
//exit(0);
//}
return ret;
}
void message(string message) {

View File

@ -41,7 +41,7 @@ namespace Shared{ namespace Platform{
// Matze: hack for now...
static Window* global_window = 0;
static int oldX=0,oldY=0;
int64 Window::lastMouseEvent = 0; /** for use in mouse hover calculations */
unsigned int Window::lastMouseEvent = 0; /** for use in mouse hover calculations */
Vec2i Window::mousePos;
MouseState Window::mouseState;
bool Window::isKeyPressedDown = false;

View File

@ -13,7 +13,6 @@
#include <cassert>
#include <cmath>
//#include "streflop.h"
#include "util.h"
#include "leak_dumper.h"

View File

@ -88,7 +88,7 @@ void SystemFlags::Close() {
}
currentDebugLog.fileStream = NULL;
currentDebugLog.fileStreamOwner = false;
currentDebugLog.mutex = NULL;
//currentDebugLog.mutex = NULL;
}
if(SystemFlags::lockFile != -1) {