diff --git a/src/Client/DefScript/DefScriptFunctions.cpp b/src/Client/DefScript/DefScriptFunctions.cpp index f081a11..d9aef04 100644 --- a/src/Client/DefScript/DefScriptFunctions.cpp +++ b/src/Client/DefScript/DefScriptFunctions.cpp @@ -173,7 +173,7 @@ DefReturnResult DefScriptPackage::func_setscriptpermission(CmdSet& Set) if(Set.defaultarg.empty() || Set.arg[0].empty()) return r; - scriptPermissionMap[Set.arg[0]] = (unsigned char)toUint64(Set.defaultarg.c_str()); + scriptPermissionMap[Set.arg[0]] = (unsigned char)toUint64(Set.defaultarg); return r; } diff --git a/src/Client/DefScript/DefScriptTools.cpp b/src/Client/DefScript/DefScriptTools.cpp index 6250063..b0efa96 100644 --- a/src/Client/DefScript/DefScriptTools.cpp +++ b/src/Client/DefScript/DefScriptTools.cpp @@ -13,13 +13,27 @@ std::string DefScriptTools::stringToLower(std::string s) { - std::transform(s.begin(), s.end(), s.begin(), std::tolower); + std::transform(s.begin(), s.end(), s.begin(), tolower); return s; } std::string DefScriptTools::stringToUpper(std::string s) { - std::transform(s.begin(), s.end(), s.begin(), std::toupper); + std::transform(s.begin(), s.end(), s.begin(), toupper); + return s; +} + +std::string DefScriptTools::toString(ldbl num) +{ + std::stringstream ss; + ss.setf(std::ios_base::fixed); + ss.precision(15); + ss << Round(num,15); + std::string s(ss.str()); + while(s[s.length()-1]=='0') + s.erase(s.length()-1,1); + if(s[s.length()-1]=='.') + s.erase(s.length()-1,1); return s; } @@ -29,7 +43,7 @@ std::string DefScriptTools::stringToUpper(std::string s) // hex numbers: 0xa56ff, 0XFF, 0xDEADBABE, etc (must begin with 0x) // float numbers: 99.65, 0.025 // negative numbers: -100, -0x3d, -55.123 -ldbl DefScriptTools::toNumber(std::string str) +ldbl DefScriptTools::toNumber(std::string& str) { ldbl num=0; uint64 u=0; @@ -61,32 +75,32 @@ ldbl DefScriptTools::toNumber(std::string str) u|=lobits; } else - u = atoi64(str.c_str()); + u = atoi64(str); if(ppos!=std::string::npos) { std::string mantissa("0"); mantissa+=str.c_str()+ppos; - num=(ldbl)atof(mantissa.c_str()); + num=(ldbl)atof(mantissa.c_str()); } - - num=(unsigned long double)num + u; + + num=(long double)num + u; num=Round(num,10); - + if(negative) num = -num; return num; } -bool DefScriptTools::isTrue(std::string s) +bool DefScriptTools::isTrue(std::string& s) { if(s.empty() || s=="false" || s=="0") return false; return true; } -uint64 DefScriptTools::toUint64(std::string str) +uint64 DefScriptTools::toUint64(std::string& str) { bool negative=false; uint64 num = 0; @@ -115,21 +129,20 @@ uint64 DefScriptTools::toUint64(std::string str) num|=lobits; } else - num = atoi64(str.c_str()); + num = atoi64(str); if(negative) num = (uint64)(-1) - num; // is this correct? return num; } -uint64 DefScriptTools::atoi64(const char *str) +uint64 DefScriptTools::atoi64(std::string& str) { -#if COMPILER == COMPILER_MICROSOFT - __int64 tmp = _atoi64(str); - return tmp; -#else -#error "Fix Me!" - //return _atoi64(str); -#endif + uint64 l = 0; + for (size_t i = 0; i < str.size(); i++) + { + l = l * 10 + str[i] - 48; + } + return l; } inline long double DefScriptTools::Round(long double z,unsigned int n) diff --git a/src/Client/DefScript/DefScriptTools.h b/src/Client/DefScript/DefScriptTools.h index 2146625..47603e3 100644 --- a/src/Client/DefScript/DefScriptTools.h +++ b/src/Client/DefScript/DefScriptTools.h @@ -7,35 +7,22 @@ namespace DefScriptTools { std::string stringToUpper(std::string); std::string stringToLower(std::string); - ldbl toNumber(std::string); - bool isTrue(std::string); - uint64 toUint64(std::string); - uint64 atoi64(const char*); - inline long double Round(long double z,unsigned int n); + std::string toString(ldbl); + inline std::string toString(double num) { return toString(ldbl(num)); } + inline std::string toString(float num) { return toString(ldbl(num)); } + template inline std::string toString(T num) { std::stringstream ss; ss << num; return ss.str(); } - template inline std::string toString(ldbl num) - { - std::stringstream ss; - ss.setf(std::ios_base::fixed); - ss.precision(15); - ss << Round(num,15); - std::string s(ss.str()); - while(s[s.length()-1]=='0') - s.erase(s.length()-1,1); - if(s[s.length()-1]=='.') - s.erase(s.length()-1,1); - return s; - } - template inline std::string toString(float num) - { - return toString(num); - } + ldbl toNumber(std::string&); + bool isTrue(std::string&); + uint64 toUint64(std::string&); + uint64 atoi64(std::string&); + inline long double Round(long double z,unsigned int n); } diff --git a/src/Client/DefScript/DynamicEvent.cpp b/src/Client/DefScript/DynamicEvent.cpp index f0acace..c62f9dd 100644 --- a/src/Client/DefScript/DynamicEvent.cpp +++ b/src/Client/DefScript/DynamicEvent.cpp @@ -99,5 +99,4 @@ void DefScript_DynamicEventMgr::Update(void) i++; } } -} - \ No newline at end of file +} diff --git a/src/Client/DefScript/VarSet.cpp b/src/Client/DefScript/VarSet.cpp index 3c6ed4d..5c55fb6 100644 --- a/src/Client/DefScript/VarSet.cpp +++ b/src/Client/DefScript/VarSet.cpp @@ -173,16 +173,12 @@ bool VarSet::ReadVarsFromFile(std::string fn) std::string VarSet::toLower(std::string s) { - std::transform(s.begin(), s.end(), s.begin(), std::tolower); + std::transform(s.begin(), s.end(), s.begin(), tolower); return s; } std::string VarSet::toUpper(std::string s) { - std::transform(s.begin(), s.end(), s.begin(), std::toupper); + std::transform(s.begin(), s.end(), s.begin(), toupper); return s; -} - - - - \ No newline at end of file +} diff --git a/src/Client/DefScript/VarSet.h b/src/Client/DefScript/VarSet.h index 3067840..d860498 100644 --- a/src/Client/DefScript/VarSet.h +++ b/src/Client/DefScript/VarSet.h @@ -33,4 +33,4 @@ private: }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index c51b5e0..5b71037 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -974,7 +974,7 @@ DefReturnResult DefScriptPackage::SCBBGetPackedGuid(CmdSet &Set) DefReturnResult DefScriptPackage::SCBBPutPackedGuid(CmdSet &Set) { ByteBuffer *bb = bytebuffers.Get(_NormalizeVarName(Set.arg[0],Set.myname)); - + uint64 guid = DefScriptTools::toUint64(Set.defaultarg); if (!guid) // fast check if guid is empty (in this case mask must be 0 with no extra data) { @@ -1012,7 +1012,7 @@ DefReturnResult DefScriptPackage::SCGui(CmdSet &Set) return false; } while(!ins->GetGUI() && !ins->GetGUI()->IsInitialized()) - Sleep(1); + ins->GetRunnable()->sleep(1); // TODO: not sure if this piece of code will work as intended, needs some testing if(ins->GetWSession() && ins->GetWSession()->InWorld()) diff --git a/src/Client/DefScriptInterface.h b/src/Client/DefScriptInterface.h index 55b79bd..987e852 100644 --- a/src/Client/DefScriptInterface.h +++ b/src/Client/DefScriptInterface.h @@ -12,4 +12,4 @@ DefScriptFunctionTable *_GetSCTable(void); -#endif \ No newline at end of file +#endif diff --git a/src/Client/GUI/DrawObject.cpp b/src/Client/GUI/DrawObject.cpp index 13107a8..bb24843 100644 --- a/src/Client/GUI/DrawObject.cpp +++ b/src/Client/GUI/DrawObject.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "PseuGui.h" +#include "PseuGUI.h" #include "DrawObject.h" #include "PseuWoW.h" diff --git a/src/Client/GUI/MInput.h b/src/Client/GUI/MInput.h index c5b4b19..88bb028 100644 --- a/src/Client/GUI/MInput.h +++ b/src/Client/GUI/MInput.h @@ -22,7 +22,7 @@ struct IKeys { return code[keycode]; } - + bool pressed_once(EKEY_CODE keycode) { if(code[keycode]) @@ -32,14 +32,14 @@ struct IKeys } return false; } - + void reset() { for(s32 i=0; isetPosition(core::vector3df(mapsize*tilesize/2, 0, mapsize*tilesize/2) + terrainPos); @@ -300,16 +300,16 @@ void SceneWorld::UpdateTerrain(void) highest = max(highest,curheight); lowest = min(lowest,curheight); } - f32 heightdiff = highest - lowest; +// f32 heightdiff = highest - lowest; // randomize terrain color depending on height for(s32 j=0; jgetSize().Height+1; j++) for(s32 i=0; igetSize().Width+1; i++) { curheight = terrain->getHeight(i,j); - u32 g = (curheight / highest * 120) + 125; - u32 r = (curheight / highest * 120) + 60; - u32 b = (curheight / highest * 120) + 60; + u32 g = (u32)(curheight / highest * 120) + 125; + u32 r = (u32)(curheight / highest * 120) + 60; + u32 b = (u32)(curheight / highest * 120) + 60; terrain->setColor(i,j, video::SColor(255,r,g,b)); } diff --git a/src/Client/GUI/ShTlTerrainSceneNode.cpp b/src/Client/GUI/ShTlTerrainSceneNode.cpp index 87aeeb6..bbc8072 100644 --- a/src/Client/GUI/ShTlTerrainSceneNode.cpp +++ b/src/Client/GUI/ShTlTerrainSceneNode.cpp @@ -1,33 +1,33 @@ #include "ShTlTerrainSceneNode.h" // constructor -ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager, - s32 width, s32 height, f32 tilesize, s32 visiblesize, +ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager, + s32 width, s32 height, f32 tilesize, s32 visiblesize, scene::ISceneNode* parent, s32 id) : scene::ISceneNode(pSceneManager->getRootSceneNode(), pSceneManager, id) { Size.Width = width; Size.Height = height; - + TileSize = tilesize; - + // make sure rendered terrain mesh is not larger than terrain itself if(visiblesize > Size.Width) visiblesize = Size.Width; if(visiblesize > Size.Height) visiblesize = Size.Height; - + MeshSize.Width = visiblesize; MeshSize.Height = visiblesize; - + MeshPosition = core::vector2d(0,0); - + Fnode = NULL; - + ShStep = 1; - + // create data array - + Data.reset(Size.Width+1, Size.Height+1); - + for(s32 j=0; j(1,0); UVdata(i,j).Vertex[3] = core::vector2d(1,1); } - + // calculate number of sectors // terrain mesh will be split to 1 or 3 or 5 sectors on each axis depending on size s32 w = 1; @@ -57,28 +57,28 @@ ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager, if(MeshSize.Height >= 30) h = 3; if(MeshSize.Width >= 50) w = 5; if(MeshSize.Height >= 50) h = 5; - + // create sectors Sector.reset(w, h); - + // find size of sectors in tiles w = MeshSize.Width / Sector.width(); h = MeshSize.Height / Sector.height(); - + for(s32 j=0; j(w, h); - + // find size of center sector in tiles w = MeshSize.Width - Sector(0,0).Size.Width * (Sector.width()-1); h = MeshSize.Height - Sector(0,0).Size.Height * (Sector.height()-1); - + {s32 j= Sector.height()/2; for(s32 i=0; i0) Sector(i,j).Offset.Y = Sector(i,j-1).Offset.Y + Sector(i,j-1).Size.Height; else Sector(i,j).Offset.Y = 0; } - + // fill sectors with tiles for(s32 j=0; jColor = video::SColor(255,255,255,255); Tile(i,j).Vertex[3]->Color = video::SColor(255,255,255,255); } - + // setup material video::SMaterial material; material.AmbientColor = video::SColor(255,255,255,255); @@ -162,34 +162,40 @@ ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager, material.MaterialType = video::EMT_DETAIL_MAP; Material.push_back(material); - + // create 2nd texture layer - + // find size of texture, must be power of two s32 tw = 2; while(tw < MeshSize.Width) tw = tw + tw; s32 th = 2; while(th < MeshSize.Height) th = th + th; - + // create texture // turn of mipmaps othervise they would need to be regenerated each time texture is updated video::IVideoDriver* driver = SceneManager->getVideoDriver(); - + bool mmflag = driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); - + CTexture = driver->addTexture(core::dimension2d(tw, th), "colortexture", video::ECF_A8R8G8B8); - + driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mmflag); - + + // irrlicht 1.4 + /* + Material[0].TextureLayer[1].Texture = CTexture; + Material[0].TextureLayer[1].TextureWrap = video::ETC_CLAMP_TO_EDGE; + */ + // irrlicht 1.3: Material[0].Textures[1] = CTexture; Material[0].TextureWrap[1] = video::ETC_CLAMP_TO_EDGE; - + // setup UV coordinates of vertices on 2nd texture layer f32 ax = (f32)MeshSize.Width / CTexture->getSize().Width / MeshSize.Width; f32 ay = (f32)MeshSize.Height/ CTexture->getSize().Height / MeshSize.Height; f32 ry = 1.0f - (f32)MeshSize.Height/ CTexture->getSize().Height; - + u32 n = MeshSize.Height-1; for(s32 j=0; jregisterNodeForRendering(this); - + ISceneNode::OnRegisterSceneNode(); } @@ -257,22 +263,22 @@ void ShTlTerrainSceneNode::render() { // update position if needed if(Fnode) centerAt(Fnode->getPosition()); - + video::IVideoDriver* driver = SceneManager->getVideoDriver(); if (!driver) return; - + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); - + driver->setMaterial(Material[0]); - + SectorsRendered = 0; - + // test if sectors are vissible for(s32 j=0; jlock(); - + updateTexture(p, Sector(i,j)); - + Sector(i,j).UpdateTexture = false; } if(p) CTexture->unlock(); - + // render geometry for(s32 j=0; jdrawIndexedTriangleList - (&Sector(i,j).Vertex[0], Sector(i,j).Vertex.size(), + (&Sector(i,j).Vertex[0], Sector(i,j).Vertex.size(), &Sector(i,j).Index[0], Sector(i,j).Index.size()/3); } - + // for debuging if( DebugDataVisible == scene::EDS_OFF ) return; - + // wireframe overlay if (DebugDataVisible == scene::EDS_MESH_WIRE_OVERLAY || DebugDataVisible == scene::EDS_FULL) { @@ -320,50 +326,50 @@ void ShTlTerrainSceneNode::render() m.AmbientColor = video::SColor(255,0,255,0); m.DiffuseColor = video::SColor(255,0,255,0); driver->setMaterial(m); - + for(s32 j=0; jdrawIndexedTriangleList - (&Sector(i,j).Vertex[0], Sector(i,j).Vertex.size(), + (&Sector(i,j).Vertex[0], Sector(i,j).Vertex.size(), &Sector(i,j).Index[0], Sector(i,j).Index.size()/3); } } } - + // terrain bounding box if (DebugDataVisible == scene::EDS_BBOX || DebugDataVisible == scene::EDS_FULL) { video::SMaterial m; m.Lighting = false; driver->setMaterial(m); - + driver->draw3DBox(BoundingBox, video::SColor(0,255,255,255)); } - + // sectors bounding boxes if (DebugDataVisible == scene::EDS_BBOX_BUFFERS || DebugDataVisible == scene::EDS_FULL) { video::SMaterial m; m.Lighting = false; driver->setMaterial(m); - + for(s32 j=0; jdraw3DBox(Sector(i,j).BoundingBox, video::SColor(0,255,255,255)); } } - + // normals if (DebugDataVisible == scene::EDS_NORMALS || DebugDataVisible == scene::EDS_FULL) { video::SMaterial m; m.Lighting = false; driver->setMaterial(m); - + for(s32 j=0; j Data(i,j).Height) BoundingBox.MinEdge.Y = Data(i,j).Height; if(BoundingBox.MaxEdge.Y < Data(i,j).Height) BoundingBox.MaxEdge.Y = Data(i,j).Height; } - - + + for(s32 j=0; j=0 && pos.X<(f32)Size.Width*TileSize && pos.Z>=0 && pos.Z<(f32)Size.Height*TileSize) { // calculatin coordinates of tile s32 x = (s32) (pos.X / TileSize); s32 y = (s32) (pos.Z / TileSize); - + // calculating position relative to tile f32 xtil = pos.X - (x*TileSize); f32 ytil = pos.Z - (y*TileSize); - + // finding trianle of tile core::triangle3df triangle; if(xtil<=ytil) @@ -551,11 +557,11 @@ f32 ShTlTerrainSceneNode::getHeight(core::vector3df pos) triangle.pointB = core::vector3df(TileSize, getHeight(x+1,y+1), TileSize); triangle.pointC = core::vector3df(TileSize, getHeight(x+1,y), 0); } - + // calculating intersection with triangle core::vector3df intersection; triangle.getIntersectionWithLine(core::vector3df(xtil,0,ytil),core::vector3df(0,1,0),intersection); - + return intersection.Y + getPosition().Y; } else @@ -568,22 +574,22 @@ f32 ShTlTerrainSceneNode::getHeight(core::vector3df pos) void ShTlTerrainSceneNode::setHeight(u32 w, u32 h, f32 newheight) { Data(w,h).Height = newheight; - + // recalculate bounding boxes - + if(newheight > BoundingBox.MaxEdge.Y) { BoundingBox.MaxEdge.Y = newheight; - + for(s32 j=0; j 0) // check if not out of array v0 = core::vector3df(0, getHeight(w,h-1)-getHeight(w,h), -TileSize); @@ -623,7 +629,7 @@ void ShTlTerrainSceneNode::recalculateNormal(s32 w, s32 h) else v1 = core::vector3df(-TileSize, 0, -TileSize); n0 = v0.crossProduct(v1); - + // calculate vector to point -1,-1 v0 = v1; // calculate vector to point -1,0 @@ -632,7 +638,7 @@ void ShTlTerrainSceneNode::recalculateNormal(s32 w, s32 h) else v1 = core::vector3df(-TileSize, 0, 0); n1 = v0.crossProduct(v1); - + // calculate vector to point -1,0 v0 = v1; // calculate vector to point 0,1 @@ -641,7 +647,7 @@ void ShTlTerrainSceneNode::recalculateNormal(s32 w, s32 h) else v1 = core::vector3df(0, 0, TileSize); n2 = v0.crossProduct(v1); - + // calculate vector to point 0,1 v0 = v1; // calculate vector to point 1,1 @@ -650,7 +656,7 @@ void ShTlTerrainSceneNode::recalculateNormal(s32 w, s32 h) else v1 = core::vector3df(TileSize, 0, TileSize); n3 = v0.crossProduct(v1); - + // calculate vector to point 1,1 v0 = v1; // calculate vector to point 1,0 @@ -659,7 +665,7 @@ void ShTlTerrainSceneNode::recalculateNormal(s32 w, s32 h) else v1 = core::vector3df(TileSize, 0, 0); n4 = v0.crossProduct(v1); - + // calculate vector to point 1,0 v0 = v1; // calculate vector to point 0,-1 @@ -668,25 +674,25 @@ void ShTlTerrainSceneNode::recalculateNormal(s32 w, s32 h) else v1 = core::vector3df(0, 0, -TileSize); n5 = v0.crossProduct(v1); - + // calculate normals of 4 tiles around point core::vector3df m0, m1, m2, m3; m0 = (n1 - n0) /2 + n0; m1 = n2; m2 = (n4 - n3) /2 + n3; m3 = n5; - + // calculate normals between oposing tiles core::vector3df k0, k1; k0 = (m2 - m0) /2 + m0; k1 = (m3 - m1) /2 + m1; - + // calculate normal of point core::vector3df n = (k1 - k0) /2 + k0; n.normalize(); setNormal(w,h,n); } - + // recalculare normals of whole terrain making it look smooth under light void ShTlTerrainSceneNode::smoothNormals() { @@ -722,7 +728,7 @@ void ShTlTerrainSceneNode::stretchTexture(core::vector2d scale) { f32 ax = scale.X / Size.Width; f32 ay = scale.X / Size.Height; - + u32 n = Size.Height-1; for(s32 j=0; j scale) void ShTlTerrainSceneNode::rotateTileTexture90(u32 w, u32 h) { core::vector2d tmp = UVdata(w,h).Vertex[3]; - + UVdata(w,h).Vertex[3] = UVdata(w,h).Vertex[2]; UVdata(w,h).Vertex[2] = UVdata(w,h).Vertex[1]; UVdata(w,h).Vertex[1] = UVdata(w,h).Vertex[0]; @@ -771,12 +777,12 @@ void ShTlTerrainSceneNode::rotateTileTexture90(u32 w, u32 h) void ShTlTerrainSceneNode::rotateTileTexture180(u32 w, u32 h) { core::vector2d tmp = UVdata(w,h).Vertex[3]; - + UVdata(w,h).Vertex[3] = UVdata(w,h).Vertex[1]; UVdata(w,h).Vertex[1] = tmp; - + tmp = UVdata(w,h).Vertex[2]; - + UVdata(w,h).Vertex[2] = UVdata(w,h).Vertex[0]; UVdata(w,h).Vertex[0] = tmp; } @@ -787,7 +793,7 @@ void ShTlTerrainSceneNode::rotateTileTexture180(u32 w, u32 h) void ShTlTerrainSceneNode::rotateTileTexture270(u32 w, u32 h) { core::vector2d tmp = UVdata(w,h).Vertex[3]; - + UVdata(w,h).Vertex[3] = UVdata(w,h).Vertex[0]; UVdata(w,h).Vertex[0] = UVdata(w,h).Vertex[1]; UVdata(w,h).Vertex[1] = UVdata(w,h).Vertex[2]; @@ -800,12 +806,12 @@ void ShTlTerrainSceneNode::rotateTileTexture270(u32 w, u32 h) void ShTlTerrainSceneNode::flipTileTextureHorizontal(u32 w, u32 h) { core::vector2d tmp = UVdata(w,h).Vertex[3]; - + UVdata(w,h).Vertex[3] = UVdata(w,h).Vertex[0]; UVdata(w,h).Vertex[0] = tmp; - + tmp = UVdata(w,h).Vertex[2]; - + UVdata(w,h).Vertex[2] = UVdata(w,h).Vertex[1]; UVdata(w,h).Vertex[1] = tmp; } @@ -816,12 +822,12 @@ void ShTlTerrainSceneNode::flipTileTextureHorizontal(u32 w, u32 h) void ShTlTerrainSceneNode::flipTileTextureVertical(u32 w, u32 h) { core::vector2d tmp = UVdata(w,h).Vertex[3]; - + UVdata(w,h).Vertex[3] = UVdata(w,h).Vertex[2]; UVdata(w,h).Vertex[2] = tmp; - + tmp = UVdata(w,h).Vertex[0]; - + UVdata(w,h).Vertex[0] = UVdata(w,h).Vertex[1]; UVdata(w,h).Vertex[1] = tmp; } @@ -850,10 +856,10 @@ void ShTlTerrainSceneNode::setMeshPosition(core::vector2d pos) // correct if out of terrain bounds if(pos.X < 0) pos.X = 0; if(pos.Y < 0) pos.Y = 0; - + if(pos.X > (s32)(Size.Width - MeshSize.Width)) pos.X = (s32)(Size.Width - MeshSize.Width); if(pos.Y > (s32)(Size.Height - MeshSize.Height)) pos.Y = (s32)(Size.Height - MeshSize.Height); - + // update if(pos.X > MeshPosition.X + ShStep || pos.X < MeshPosition.X - ShStep || pos.Y > MeshPosition.Y + ShStep || pos.Y < MeshPosition.Y - ShStep) @@ -872,15 +878,15 @@ void ShTlTerrainSceneNode::centerAt(core::vector3d pos) // find position relative to terrain pos.X = pos.X - getPosition().X; pos.Z = pos.Z - getPosition().Z; - + // offset center pos.X = pos.X - TileSize * MeshSize.Width/2; pos.Z = pos.Z - TileSize * MeshSize.Height/2; - + // find equivalent in tiles s32 x = (s32)(pos.X / TileSize); s32 y = (s32)(pos.Z / TileSize); - + setMeshPosition(core::vector2d(x,y)); } @@ -892,25 +898,25 @@ void ShTlTerrainSceneNode::update() // update position of bounding boxes BoundingBox.MinEdge = core::vector3df(MeshPosition.X*TileSize, BoundingBox.MinEdge.Y, MeshPosition.Y*TileSize); BoundingBox.MaxEdge = core::vector3df( (MeshPosition.X+MeshSize.Width)*TileSize, BoundingBox.MaxEdge.Y, (MeshPosition.Y+MeshSize.Height)*TileSize); - + for(s32 j=0; j line, core //get relative position of line to terrain line.start = line.start - getPosition(); line.end = line.end - getPosition(); - + // find 2d vector of line core::vector2d vector; vector.X = line.end.X - line.start.X; vector.Y = line.end.Z - line.start.Z; - + // calculate variables used later in calculating coordinates on line // used equations are: "x = y * a + c" and "y = x * b + d" // where "a = x / y" and "b = y / x" f32 a = 0; if(vector.Y != 0) a = vector.X / vector.Y; - + f32 b = 0; if(vector.X != 0) b = vector.Y / vector.X; - + // calculate starting and ending tiles core::vector3d start; start.X = (s32)(line.start.X / TileSize); start.Y = (s32)(line.start.Z / TileSize); - + core::vector3d end; end.X = (s32)(line.end.X / TileSize); end.Y = (s32)(line.end.Z / TileSize); - + // some variables dependant on line orientation s32 xs = 1; s32 xc = 0; @@ -975,7 +981,7 @@ bool ShTlTerrainSceneNode::getIntersectionWithLine( core::line3d line, core xs = -1; xc = 1; } - + s32 ys = 1; s32 yc = 0; if(vector.Y < 0) @@ -983,32 +989,32 @@ bool ShTlTerrainSceneNode::getIntersectionWithLine( core::line3d line, core ys = -1; yc = 1; } - + // calculate tiles which can intersect with line based on their 2d position // then test for intersection - + // take y and calculate x coordinates of tile if( core::abs_(vector.X) > core::abs_(vector.Y) ) { s32 x = start.X; s32 y; - + for(y=start.Y+yc; y!=end.Y+yc; y+=ys) { f32 tmp = (f32)(y+ys) * TileSize - line.start.Z; tmp = a * tmp + line.start.X; s32 xn = (s32)(tmp / TileSize); - + for(x; x!=xn+xs; x+=xs) if( getIntersectionWithTile(x, y-yc, line, outIntersection) ) { outIntersection += getPosition(); return true; } - + x = xn; } - + for(x; x!=end.X+xs; x+=xs) if( getIntersectionWithTile(x, y-yc, line, outIntersection) ) { @@ -1021,23 +1027,23 @@ bool ShTlTerrainSceneNode::getIntersectionWithLine( core::line3d line, core { s32 y = start.Y; s32 x; - + for(x=start.X+xc; x!=end.X+xc; x+=xs) { f32 tmp = (f32)(x+xs) * TileSize - line.start.X; tmp = b * tmp + line.start.Z; s32 yn = (s32)(tmp / TileSize); - + for(y; y!=yn+ys; y+=ys) if( getIntersectionWithTile(x-xc, y, line, outIntersection) ) { outIntersection += getPosition(); return true; } - + y = yn; } - + for(y; y!=end.Y+ys; y+=ys) if( getIntersectionWithTile(x-xc, y, line, outIntersection) ) { @@ -1045,7 +1051,7 @@ bool ShTlTerrainSceneNode::getIntersectionWithLine( core::line3d line, core return true; } } - + return false; } @@ -1056,78 +1062,78 @@ void ShTlTerrainSceneNode::loadHeightMap(const c8 *filename, f32 scale, u32 w, u { video::IVideoDriver* driver = SceneManager->getVideoDriver(); if(!driver) return; - + video::IImage *image = driver->createImageFromFile(filename); if(!image) return; - + s32 tw = image->getDimension().Width; s32 th = image->getDimension().Height; - + s32 we = w + tw; if(we > Size.Width+1) we = Size.Width+1; s32 he = h + th; if(he > Size.Height+1) he = Size.Height+1; - + tw = 0; th = 0; - + for(s32 j=h; jgetPixel(tw, th); - + Data(i,j).Height = (f32)color.getLuminance()/255 * scale; - + tw++; } tw = 0; th++; } - + image->drop(); - + recalculateBoundingBox(); - + smoothNormals(); } - + // load color data from texture void ShTlTerrainSceneNode::loadColorMap(const c8 *filename, u32 w, u32 h) { video::IVideoDriver* driver = SceneManager->getVideoDriver(); if(!driver) return; - + video::IImage *image = driver->createImageFromFile(filename); if(!image) return; - + s32 tw = (u32)image->getDimension().Width; s32 th = (u32)image->getDimension().Height; - + s32 we = w + tw; if(we > Size.Width+1) we = Size.Width+1; s32 he = h + th; if(he > Size.Height+1) he = Size.Height+1; - + tw = 0; th = 0; - + for(s32 j=h; jgetPixel(tw, th); - + Data(i,j).Color = color; - + tw++; } tw = 0; th++; } - + image->drop(); } @@ -1138,11 +1144,11 @@ bool ShTlTerrainSceneNode::isSectorOnScreen(TlTSector* sctr) { // bounding box of sector core::aabbox3d box = sctr->BoundingBox; - + // get absolute position of bounding box box.MinEdge = box.MinEdge + getPosition(); box.MaxEdge = box.MaxEdge + getPosition(); - + // get camera frustrum planes const scene::SViewFrustum* frustrum = SceneManager->getActiveCamera()->getViewFrustum(); core::plane3d Left = frustrum->planes[scene::SViewFrustum::VF_LEFT_PLANE]; @@ -1151,28 +1157,28 @@ bool ShTlTerrainSceneNode::isSectorOnScreen(TlTSector* sctr) core::plane3d Bottom = frustrum->planes[scene::SViewFrustum::VF_BOTTOM_PLANE]; core::plane3d Near = frustrum->planes[scene::SViewFrustum::VF_NEAR_PLANE]; core::plane3d Far = frustrum->planes[scene::SViewFrustum::VF_FAR_PLANE]; - + // test sector bounding box against planes s32 leftRel, rightRel, topRel, bottomRel, nearRel, farRel; - + nearRel = box.classifyPlaneRelation(Near); if(nearRel == core::ISREL3D_FRONT) return false; - + leftRel = box.classifyPlaneRelation(Left); if(leftRel == core::ISREL3D_FRONT) return false; - + rightRel = box.classifyPlaneRelation(Right); if(rightRel == core::ISREL3D_FRONT) return false; - + bottomRel = box.classifyPlaneRelation(Bottom); if(bottomRel == core::ISREL3D_FRONT) return false; farRel = box.classifyPlaneRelation(Far); if(farRel == core::ISREL3D_FRONT) return false; - + topRel = box.classifyPlaneRelation(Top); if(topRel == core::ISREL3D_FRONT) return false; - + return true; } @@ -1190,19 +1196,19 @@ void ShTlTerrainSceneNode::updateVertices(TlTSector §or) // positon of tile relative to terrain u32 x = i + MeshPosition.X; u32 y = j + MeshPosition.Y; - + // update position Tile(i,j).Vertex[0]->Pos = core::vector3df(x*TileSize, Data(x,y).Height, y*TileSize); Tile(i,j).Vertex[1]->Pos = core::vector3df(x*TileSize, Data(x,y+1).Height, (y+1)*TileSize); Tile(i,j).Vertex[2]->Pos = core::vector3df( (x+1)*TileSize, Data(x+1,y+1).Height, (y+1)*TileSize); Tile(i,j).Vertex[3]->Pos = core::vector3df( (x+1)*TileSize, Data(x+1,y).Height, y*TileSize); - + // update normals Tile(i,j).Vertex[0]->Normal = Data(x,y).Normal; Tile(i,j).Vertex[1]->Normal = Data(x,y+1).Normal; Tile(i,j).Vertex[2]->Normal = Data(x+1,y+1).Normal; Tile(i,j).Vertex[3]->Normal = Data(x+1,y).Normal; - + // update texture coordinates Tile(i,j).Vertex[0]->TCoords = UVdata(x,y).Vertex[0]; Tile(i,j).Vertex[1]->TCoords = UVdata(x,y).Vertex[1]; @@ -1233,14 +1239,14 @@ void ShTlTerrainSceneNode::updateVertices(TlTSector §or) void ShTlTerrainSceneNode::updateTexture(u32* p, TlTSector §or) { u32 x, y; - + // in case created texure is larger than terrain mesh, update one more pixel // on each axis to get rid of unused pixels at the border blended in to used ones u32 w = 0; if(MeshSize.Width < CTexture->getSize().Width) w = 1; u32 h = 0; if(MeshSize.Height < CTexture->getSize().Height) h = 1; - + for(u32 j=sector.Offset.Y; jgetSize().Height-1 - j; @@ -1248,7 +1254,7 @@ void ShTlTerrainSceneNode::updateTexture(u32* p, TlTSector §or) { x = i + MeshPosition.X; y = j + MeshPosition.Y; - + p[n*CTexture->getSize().Width + i] = Data(x,y).Color.color; } } @@ -1259,41 +1265,41 @@ void ShTlTerrainSceneNode::updateTexture(u32* p, TlTSector §or) // test if 3d line colide with tile // returns true if yes, false if not and store intersection in "outIntersection" vector bool ShTlTerrainSceneNode::getIntersectionWithTile(s32 w, s32 h, core::line3d line, core::vector3df &outIntersection) -{ +{ // test if not out of terrain bounds if(w < 0) return false; if(h < 0) return false; if(w > Size.Width-1) return false; if(h > Size.Height-1) return false; - + // vertices core::vector3df v0(w*TileSize, getHeight(w,h), h*TileSize); core::vector3df v1(w*TileSize, getHeight(w,h+1), (h+1)*TileSize); core::vector3df v2((w+1)*TileSize, getHeight(w+1,h+1), (h+1)*TileSize); core::vector3df v3((w+1)*TileSize, getHeight(w+1,h), h*TileSize); - + // firsth test collision with tile bounding box core::aabbox3d box; box.reset(v0); box.addInternalPoint(v1); box.addInternalPoint(v2); box.addInternalPoint(v3); - + if (!box.intersectsWithLine(line)) return false;; - + // test collision with tile itself core::triangle3df triangle; - + // test upper left trialgle of tile triangle.set(v0,v1,v2); bool collision1 = triangle.getIntersectionWithLimitedLine(line, outIntersection); - + // test lower right triangle of tile triangle.set(v0,v2,v3); core::vector3df intersect2; bool collision2 = triangle.getIntersectionWithLimitedLine(line, intersect2); - + // compare results and decide what to return if(collision2) { @@ -1312,6 +1318,6 @@ bool ShTlTerrainSceneNode::getIntersectionWithTile(s32 w, s32 h, core::line3d> proto->Delay; buf >> proto->Ammo_type; - buf >> (float)proto->RangedModRange; + buf >> proto->RangedModRange; for(int s = 0; s < 5; s++) { buf >> proto->Spells[s].SpellId; @@ -309,7 +309,7 @@ void ItemProtoCache_WriteDataToCache(WorldSession *session) } uint32 total = session->objmgr.GetItemProtoCount(); - fh.write((char*)&(uint32)ITEMPROTOTYPES_CACHE_VERSION,4); + fh.write((char*)&ITEMPROTOTYPES_CACHE_VERSION,4); fh.write((char*)&total,4); uint32 counter=0; @@ -497,7 +497,7 @@ void CreatureTemplateCache_WriteDataToCache(WorldSession *session) return; } uint32 total = session->objmgr.GetCreatureTemplateCount(); - fh.write((char*)&(uint32)CREATURETEMPLATES_CACHE_VERSION,4); + fh.write((char*)&CREATURETEMPLATES_CACHE_VERSION,4); fh.write((char*)&total,4); uint32 counter=0; ByteBuffer buf; diff --git a/src/Client/World/Channel.h b/src/Client/World/Channel.h index 39f35fc..56a2886 100644 --- a/src/Client/World/Channel.h +++ b/src/Client/World/Channel.h @@ -29,4 +29,4 @@ private: WorldSession *_worldSession; }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/World/Corpse.cpp b/src/Client/World/Corpse.cpp index 8be92bd..e89ca86 100644 --- a/src/Client/World/Corpse.cpp +++ b/src/Client/World/Corpse.cpp @@ -10,4 +10,4 @@ Corpse::Corpse() void Corpse::Create(uint64 guid) { Object::Create(guid); -} \ No newline at end of file +} diff --git a/src/Client/World/DynamicObject.cpp b/src/Client/World/DynamicObject.cpp index ae209d3..5a6ba8d 100644 --- a/src/Client/World/DynamicObject.cpp +++ b/src/Client/World/DynamicObject.cpp @@ -11,4 +11,4 @@ DynamicObject::DynamicObject() void DynamicObject::Create(uint64 guid) { Object::Create(guid); -} \ No newline at end of file +} diff --git a/src/Client/World/GameObject.cpp b/src/Client/World/GameObject.cpp index 41c00d8..20e2ce8 100644 --- a/src/Client/World/GameObject.cpp +++ b/src/Client/World/GameObject.cpp @@ -11,4 +11,4 @@ GameObject::GameObject() void GameObject::Create(uint64 guid) { Object::Create(guid); -} \ No newline at end of file +} diff --git a/src/Client/World/Item.cpp b/src/Client/World/Item.cpp index e78d558..a93ab3e 100644 --- a/src/Client/World/Item.cpp +++ b/src/Client/World/Item.cpp @@ -60,7 +60,7 @@ void WorldSession::_HandleItemQuerySingleResponseOpcode(WorldPacket& recvPacket) recvPacket >> proto->Delay; recvPacket >> proto->Ammo_type; - recvPacket >> (float)proto->RangedModRange; + recvPacket >> proto->RangedModRange; for(int s = 0; s < 5; s++) { recvPacket >> proto->Spells[s].SpellId; diff --git a/src/Client/World/MapMgr.h b/src/Client/World/MapMgr.h index 6e71af3..9f23cc7 100644 --- a/src/Client/World/MapMgr.h +++ b/src/Client/World/MapMgr.h @@ -40,4 +40,4 @@ private: bool _mapsLoaded; }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/World/ObjMgr.h b/src/Client/World/ObjMgr.h index 5653784..5c42a87 100644 --- a/src/Client/World/ObjMgr.h +++ b/src/Client/World/ObjMgr.h @@ -65,4 +65,4 @@ private: }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/World/Player.cpp b/src/Client/World/Player.cpp index da5e0da..f20bafb 100644 --- a/src/Client/World/Player.cpp +++ b/src/Client/World/Player.cpp @@ -71,6 +71,4 @@ uint16 MyCharacter::GetSpellSlot(uint32 spellid) if(i->id == spellid) return i->slot; return 0; -} - - \ No newline at end of file +} diff --git a/src/Client/World/Player.h b/src/Client/World/Player.h index cfd6b25..06a88c7 100644 --- a/src/Client/World/Player.h +++ b/src/Client/World/Player.h @@ -202,4 +202,4 @@ private: }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/World/Unit.h b/src/Client/World/Unit.h index e03a708..35507e2 100644 --- a/src/Client/World/Unit.h +++ b/src/Client/World/Unit.h @@ -81,4 +81,4 @@ protected: }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/World/World.cpp b/src/Client/World/World.cpp index ef8661c..9b9d9c1 100644 --- a/src/Client/World/World.cpp +++ b/src/Client/World/World.cpp @@ -71,3 +71,4 @@ float World::GetPosZ(float x, float y) logdebug("WORLD: GetPosZ() called, but no MapMgr exists (do you really use maps?)"); return 0; } + \ No newline at end of file diff --git a/src/Client/World/WorldPacket.h b/src/Client/World/WorldPacket.h index 3ecbaff..c0bd16c 100644 --- a/src/Client/World/WorldPacket.h +++ b/src/Client/World/WorldPacket.h @@ -21,4 +21,4 @@ private: }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/World/WorldSocket.h b/src/Client/World/WorldSocket.h index 9f38c6b..01b640b 100644 --- a/src/Client/World/WorldSocket.h +++ b/src/Client/World/WorldSocket.h @@ -45,4 +45,4 @@ private: }; -#endif \ No newline at end of file +#endif diff --git a/src/Client/main.cpp b/src/Client/main.cpp index 0124c7d..01720a4 100644 --- a/src/Client/main.cpp +++ b/src/Client/main.cpp @@ -19,15 +19,15 @@ void _HookSignals(void) #endif } -void _UnhookSignals(void) -{ - signal(SIGINT, 0); - signal(SIGQUIT, 0); - signal(SIGTERM, 0); - signal(SIGABRT, 0); - #ifdef _WIN32 - signal(SIGBREAK, 0); - #endif +void _UnhookSignals(void) +{ + signal(SIGINT, 0); + signal(SIGQUIT, 0); + signal(SIGTERM, 0); + signal(SIGABRT, 0); + #ifdef _WIN32 + signal(SIGBREAK, 0); + #endif } void _OnSignal(int s) @@ -112,4 +112,4 @@ int main(int argc, char* argv[]) { raise(SIGABRT); return 1; } -} \ No newline at end of file +} diff --git a/src/Client/main.h b/src/Client/main.h index cc09eda..0af8e4c 100644 --- a/src/Client/main.h +++ b/src/Client/main.h @@ -9,4 +9,4 @@ void abortproc(void); void _new_handler(void); int main(int,char**); -#endif \ No newline at end of file +#endif diff --git a/src/shared/ADTFileStructs.h b/src/shared/ADTFileStructs.h index 663e77f..8299013 100644 --- a/src/shared/ADTFileStructs.h +++ b/src/shared/ADTFileStructs.h @@ -209,4 +209,4 @@ struct ADTMapChunk }; -#endif \ No newline at end of file +#endif diff --git a/src/shared/ByteBuffer.h b/src/shared/ByteBuffer.h index 6a20b16..d46f2e7 100644 --- a/src/shared/ByteBuffer.h +++ b/src/shared/ByteBuffer.h @@ -28,12 +28,12 @@ class ByteBufferException { public: ByteBufferException(const char *act, uint32 rp, uint32 wp, uint32 rs, uint32 cs) - { - action = act; - rpos = rp; - wpos = wp; - readsize = rs; - cursize = cs; + { + action = act; + rpos = rp; + wpos = wp; + readsize = rs; + cursize = cs; } uint32 rpos, wpos, readsize, cursize; const char *action; @@ -239,7 +239,7 @@ class ByteBuffer void append(const std::string& str) { - append((uint8 *)str.c_str(),str.size() + 1); + append((const uint8 *)str.c_str(),str.size() + 1); } void append(const char *src, size_t cnt) { diff --git a/src/shared/DebugStuff.h b/src/shared/DebugStuff.h index f54b155..4f39d9f 100644 --- a/src/shared/DebugStuff.h +++ b/src/shared/DebugStuff.h @@ -16,4 +16,4 @@ -#endif \ No newline at end of file +#endif diff --git a/src/shared/SysDefs.h b/src/shared/SysDefs.h index f3f18cb..24475f7 100644 --- a/src/shared/SysDefs.h +++ b/src/shared/SysDefs.h @@ -49,14 +49,14 @@ // Compiler defines //////////////////////////////////// -#if COMPILER == COMPILER_MICROSOFT - #define I64FMT "%016I64X" - #define I64FMTD "%I64u" - #define SI64FMTD "%I64d" - #define snprintf _snprintf - #define atoll __atoi64 - #define vsnprintf _vsnprintf - #define strdup _strdup +#if COMPILER == COMPILER_MICROSOFT + #define I64FMT "%016I64X" + #define I64FMTD "%I64u" + #define SI64FMTD "%I64d" + #define snprintf _snprintf + #define atoll __atoi64 + #define vsnprintf _vsnprintf + #define strdup _strdup typedef __int64 int64; typedef long int32; typedef short int16; @@ -64,14 +64,14 @@ typedef unsigned __int64 uint64; typedef unsigned long uint32; typedef unsigned short uint16; - typedef unsigned char uint8; -#else - #define stricmp strcasecmp - #define strnicmp strncasecmp - #define I64FMT "%016llX" - #define I64FMTD "%llu" - #define SI64FMTD "%lld" -# if PLATFORM == PLATFORM_UNIX + typedef unsigned char uint8; +#else + #define stricmp strcasecmp + #define strnicmp strncasecmp + #define I64FMT "%016llX" + #define I64FMTD "%llu" + #define SI64FMTD "%lld" +# if PLATFORM == PLATFORM_UNIX typedef __int64_t int64; typedef __int32_t int32; typedef __int16_t int16; @@ -81,8 +81,8 @@ typedef __uint16_t uint16; typedef __uint8_t uint8; typedef uint16 WORD; - typedef uint32 DWORD; -# else + typedef uint32 DWORD; +# else typedef long long int64; typedef long int32; typedef short int16; @@ -92,14 +92,22 @@ typedef unsigned short uint16; typedef unsigned char uint8; typedef unsigned short WORD; - typedef uint32 DWORD; -# endif + typedef uint32 DWORD; +# endif #endif #ifndef SIGQUIT #define SIGQUIT 3 #endif +#ifdef min +#undef min +#endif + +#ifdef max +#undef max +#endif + #if COMPILER == COMPILER_MICROSOFT # if _MSC_VER >= 1500 # define COMPILER_NAME "VC90" diff --git a/src/shared/common.h b/src/shared/common.h index 54783fa..d783a03 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -9,8 +9,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/shared/log.cpp b/src/shared/log.cpp index 37d92d2..2b9fed8 100644 --- a/src/shared/log.cpp +++ b/src/shared/log.cpp @@ -33,8 +33,8 @@ void log(const char *str, ...) return; va_list ap; _log_setcolor(true,GREY); - va_start(ap, str); - vprintf( str, ap ); + va_start(ap, str); + vprintf( str, ap ); va_end(ap); _log_resetcolor(true); @@ -43,12 +43,12 @@ void log(const char *str, ...) if(logfile) { fprintf(logfile, getDateString().c_str()); - va_start(ap, str); - vfprintf(logfile, str, ap); - fprintf(logfile, "\n" ); - va_end(ap); - fflush(logfile); - } + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } fflush(stdout); } @@ -58,8 +58,8 @@ void logdetail(const char *str, ...) return; va_list ap; _log_setcolor(true,LCYAN); - va_start(ap, str); - vprintf( str, ap ); + va_start(ap, str); + vprintf( str, ap ); va_end(ap); _log_resetcolor(true); @@ -68,12 +68,12 @@ void logdetail(const char *str, ...) if(logfile) { fprintf(logfile, getDateString().c_str()); - va_start(ap, str); - vfprintf(logfile, str, ap); - fprintf(logfile, "\n" ); - va_end(ap); - fflush(logfile); - } + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } fflush(stdout); } @@ -83,8 +83,8 @@ void logdebug(const char *str, ...) return; va_list ap; _log_setcolor(true,LBLUE); - va_start(ap, str); - vprintf( str, ap ); + va_start(ap, str); + vprintf( str, ap ); va_end(ap); _log_resetcolor(true); @@ -94,12 +94,12 @@ void logdebug(const char *str, ...) if(logfile) { fprintf(logfile, getDateString().c_str()); - va_start(ap, str); - vfprintf(logfile, str, ap); - fprintf(logfile, "\n" ); - va_end(ap); - fflush(logfile); - } + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } fflush(stdout); } @@ -109,8 +109,8 @@ void logdev(const char *str, ...) return; va_list ap; _log_setcolor(true,LMAGENTA); - va_start(ap, str); - vprintf( str, ap ); + va_start(ap, str); + vprintf( str, ap ); va_end(ap); _log_resetcolor(true); @@ -120,12 +120,12 @@ void logdev(const char *str, ...) if(logfile) { fprintf(logfile, getDateString().c_str()); - va_start(ap, str); - vfprintf(logfile, str, ap); - fprintf(logfile, "\n" ); - va_end(ap); - fflush(logfile); - } + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } fflush(stdout); } @@ -133,8 +133,8 @@ void logerror(const char *str, ...) { va_list ap; _log_setcolor(false,LRED); - va_start(ap, str); - vfprintf( stderr, str, ap ); + va_start(ap, str); + vfprintf( stderr, str, ap ); va_end(ap); _log_resetcolor(false); @@ -143,12 +143,12 @@ void logerror(const char *str, ...) if(logfile) { fprintf(logfile, getDateString().c_str()); - va_start(ap, str); - vfprintf(logfile, str, ap); - fprintf(logfile, "\n" ); - va_end(ap); - fflush(logfile); - } + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } fflush(stdout); } @@ -156,8 +156,8 @@ void logcritical(const char *str, ...) { va_list ap; _log_setcolor(false,RED); - va_start(ap, str); - vfprintf( stderr, str, ap ); + va_start(ap, str); + vfprintf( stderr, str, ap ); va_end(ap); _log_resetcolor(false); @@ -166,12 +166,12 @@ void logcritical(const char *str, ...) if(logfile) { fprintf(logfile, getDateString().c_str()); - va_start(ap, str); - vfprintf(logfile, str, ap); - fprintf(logfile, "\n" ); - va_end(ap); - fflush(logfile); - } + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } fflush(stdout); } @@ -181,8 +181,8 @@ void logcustom(uint8 lvl, Color color, const char *str, ...) return; va_list ap; _log_setcolor(true,color); - va_start(ap, str); - vprintf( str, ap ); + va_start(ap, str); + vprintf( str, ap ); va_end(ap); _log_resetcolor(true); @@ -191,12 +191,12 @@ void logcustom(uint8 lvl, Color color, const char *str, ...) if(logfile) { fprintf(logfile, getDateString().c_str()); - va_start(ap, str); - vfprintf(logfile, str, ap); - fprintf(logfile, "\n" ); - va_end(ap); - fflush(logfile); - } + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } fflush(stdout); } @@ -205,89 +205,88 @@ void log_close() fclose(logfile); } -void _log_setcolor(bool stdout_stream, Color color) -{ -#if PLATFORM == PLATFORM_WIN32 - - static WORD WinColorFG[Color_count] = - { - 0, // BLACK - FOREGROUND_RED, // RED - FOREGROUND_GREEN, // GREEN - FOREGROUND_RED | FOREGROUND_GREEN, // BROWN - FOREGROUND_BLUE, // BLUE - FOREGROUND_RED | FOREGROUND_BLUE,// MAGENTA - FOREGROUND_GREEN | FOREGROUND_BLUE, // CYAN - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,// WHITE - // YELLOW - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY, - // RED_BOLD - FOREGROUND_RED | FOREGROUND_INTENSITY, - // GREEN_BOLD - FOREGROUND_GREEN | FOREGROUND_INTENSITY, - FOREGROUND_BLUE | FOREGROUND_INTENSITY, // BLUE_BOLD - // MAGENTA_BOLD - FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY, - // CYAN_BOLD - FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY, - // WHITE_BOLD - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY - }; - - HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ); - SetConsoleTextAttribute(hConsole, WinColorFG[color]); -#else - - enum ANSITextAttr - { - TA_NORMAL=0, - TA_BOLD=1, - TA_BLINK=5, - TA_REVERSE=7 - }; - - enum ANSIFgTextAttr - { - FG_BLACK=30, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE, - FG_MAGENTA, FG_CYAN, FG_WHITE, FG_YELLOW - }; - - enum ANSIBgTextAttr - { - BG_BLACK=40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE, - BG_MAGENTA, BG_CYAN, BG_WHITE - }; - - static uint8 UnixColorFG[Color_count] = - { - FG_BLACK, // BLACK - FG_RED, // RED - FG_GREEN, // GREEN - FG_BROWN, // BROWN - FG_BLUE, // BLUE - FG_MAGENTA, // MAGENTA - FG_CYAN, // CYAN - FG_WHITE, // WHITE - FG_YELLOW, // YELLOW - FG_RED, // LRED - FG_GREEN, // LGREEN - FG_BLUE, // LBLUE - FG_MAGENTA, // LMAGENTA - FG_CYAN, // LCYAN - FG_WHITE // LWHITE - }; - - fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm",UnixColorFG[color],(color>=YELLOW&&color=YELLOW&&color # include #else -# include +# include +# include # if defined(__FreeBSD__) || defined(__APPLE_CC__) # include # endif @@ -25,9 +26,9 @@ void printchex(std::string in, bool spaces=true) len=in.length(); printf("["); if(spaces) - for(i=0;i