diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index afe8a58..997ad7d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -145,7 +145,6 @@ endif() # Client sources set(minetest_SRCS ${common_SRCS} - MyBillboardSceneNode.cpp content_mapblock.cpp content_cao.cpp mapblock_mesh.cpp @@ -247,26 +246,48 @@ if(MSVC) else() # Probably GCC - if(WARN_ALL) - set(RELEASE_WARNING_FLAGS "-Wall") - else() - set(RELEASE_WARNING_FLAGS "") - endif() - - if(NOT APPLE AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - CHECK_CXX_COMPILER_FLAG("-Wno-unused-but-set-variable" HAS_UNUSED_BUT_SET_VARIABLE_WARNING) - if(HAS_UNUSED_BUT_SET_VARIABLE_WARNING) - set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-but-set-variable") - endif(HAS_UNUSED_BUT_SET_VARIABLE_WARNING) - endif() + set(CFLAGS "-fwrapv -fno-fast-math") + set(OPT_CFLAGS "-O3 -fomit-frame-pointer") if(APPLE) set(CMAKE_OSX_ARCHITECTURES i386 CACHE STRING "do not build for 64-bit" FORCE) set(ARCH i386) endif() - set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops") - set(CMAKE_CXX_FLAGS_DEBUG "-g -O1 -Wall ${WARNING_FLAGS}") + if(ENABLE_SSP) + CHECK_CXX_COMPILER_FLAG("-fstack-protector-strong" HAS_FSTACK_STRONG) + if(HAS_FSTACK_STRONG) + set(CFLAGS "${CFLAGS} -fstack-protector-strong") + else() + set(CFLAGS "${CFLAGS} -fstack-protector") + endif() + endif() + if(ENABLE_SAFESTACK) + CHECK_CXX_COMPILER_FLAG("-fsanitize=safe-stack" HAS_SAFESTACK) + if(HAS_SAFESTACK) + set(CFLAGS "${CFLAGS} -fsanitize=safe-stack") + set(LDFLAGS "${LDFLAGS} -fsanitize=safe-stack -lrt") + endif() + endif() + if(ENABLE_PIE) + set(CFLAGS "${CFLAGS} -fPIC -fPIE") + set(LDFLAGS "${LDFLAGS} -Wl,-pie") + endif() + if(CPU_OPTS) + set(OPT_CFLAGS "${OPT_CFLAGS} -march=${CPUTYPE}") + endif() + + set(CMAKE_CXX_FLAGS_RELEASE "${OPT_CFLAGS} ${CFLAGS} ${CXXFLAGS} -Wall -DNDEBUG -pipe -fpermissive -Wno-write-strings") + set(CMAKE_C_FLAGS_RELEASE "${OPT_CFLAGS} ${CFLAGS} -Wall -DNDEBUG -pipe") + set(CMAKE_CXX_FLAGS_DEBUG "${CFLAGS} ${CXXFLAGS} -Wall -O0 -g3 -ggdb -fpermissive -Wno-write-strings") + set(CMAKE_C_FLAGS_DEBUG "${CFLAGS} -Wall -O0 -g3 -ggdb") + + set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${LDFLAGS}) + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE}) + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE}) + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${LDFLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG}) + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG}) if(USE_GPROF) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") diff --git a/src/MyBillboardSceneNode.cpp b/src/MyBillboardSceneNode.cpp.nul similarity index 100% rename from src/MyBillboardSceneNode.cpp rename to src/MyBillboardSceneNode.cpp.nul diff --git a/src/MyBillboardSceneNode.h b/src/MyBillboardSceneNode.h.nul similarity index 100% rename from src/MyBillboardSceneNode.h rename to src/MyBillboardSceneNode.h.nul diff --git a/src/camera.cpp b/src/camera.cpp index a323367..ae5f1c7 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "settings.h" +#define MY_ETLM_READ_ONLY video::ETLM_READ_ONLY Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control): m_smgr(smgr), @@ -820,7 +821,7 @@ scene::IAnimatedMesh* ExtrudedSpriteSceneNode::extrude(video::ITexture* texture) { // Texture is in the correct color format, we can pass it // to extrudeARGB right away. - void* data = texture->lock(true); + void* data = texture->lock(MY_ETLM_READ_ONLY); if (data == NULL) return NULL; mesh = extrudeARGB(size.Width, size.Height, (u8*) data); @@ -830,7 +831,7 @@ scene::IAnimatedMesh* ExtrudedSpriteSceneNode::extrude(video::ITexture* texture) { video::IVideoDriver* driver = SceneManager->getVideoDriver(); - video::IImage* img1 = driver->createImageFromData(format, size, texture->lock(true)); + video::IImage* img1 = driver->createImageFromData(format, size, texture->lock(MY_ETLM_READ_ONLY)); if (img1 == NULL) return NULL; diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 6cb2cee..8cdacf2 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -903,8 +903,8 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr) std::string texture_string = "[makealpha2:128,0,0;128,128,0:"; texture_string += m_texture_name; - scene::MyBillboardSceneNode *bill = new scene::MyBillboardSceneNode( - smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); + scene::IBillboardSceneNode *bill = smgr->addBillboardSceneNode( + NULL, v2f(1, 1), v3f(0,0,0), -1); bill->setMaterialTexture(0, g_texturesource->getTextureRaw(texture_string)); bill->setMaterialFlag(video::EMF_LIGHTING, false); bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); @@ -918,17 +918,11 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr) const float txs = txp*32; const float typ = 1./240; const float tys = typ*48; - bill->setTCoords(0, v2f(txs*1, tys*1)); - bill->setTCoords(1, v2f(txs*1, tys*0)); - bill->setTCoords(2, v2f(txs*0, tys*0)); - bill->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(bill, txs, tys, 0, 0); } else if(m_sprite_type == "simple"){ const float txs = 1.0; const float tys = 1.0 / m_simple_anim_frames; - bill->setTCoords(0, v2f(txs*1, tys*1)); - bill->setTCoords(1, v2f(txs*1, tys*0)); - bill->setTCoords(2, v2f(txs*0, tys*0)); - bill->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(bill, txs, tys, 0, 0); } else { infostream<<"MobV2CAO: Unknown sprite type \""<drop(); + //m_node->drop(); m_node->remove(); m_node = NULL; } @@ -992,7 +986,7 @@ void MobV2CAO::updateNodePos() void MobV2CAO::step(float dtime, ClientEnvironment *env) { - scene::MyBillboardSceneNode *bill = m_node; + scene::IBillboardSceneNode *bill = m_node; if(!bill) return; @@ -1045,10 +1039,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env) const float txs = txp*32; const float typ = 1./240; const float tys = typ*48; - bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(bill, txs, tys, col, row); } else if(m_sprite_type == "simple"){ m_walk_timer += dtime; if(m_walk_timer >= m_simple_anim_frametime){ @@ -1059,10 +1050,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env) int row = m_walk_frame; const float txs = 1.0; const float tys = 1.0 / m_simple_anim_frames; - bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(bill, txs, tys, col, row); } else { infostream<<"MobV2CAO::step(): Unknown sprite type \"" < /* SmoothTranslator @@ -304,6 +305,15 @@ private: SmoothTranslator pos_translator; }; +static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill, + float txs, float tys, int col, int row) +{ + video::SMaterial& material = bill->getMaterial(0); + core::matrix4& matrix = material.getTextureMatrix(0); + matrix.setTextureTranslate(txs*col, tys*row); + matrix.setTextureScale(txs, tys); +} + /* MobV2CAO */ @@ -348,7 +358,7 @@ private: IntervalLimiter m_attack_interval; core::aabbox3d m_selection_box; - scene::MyBillboardSceneNode *m_node; + scene::IBillboardSceneNode *m_node; v3f m_position; std::string m_texture_name; float m_yaw; diff --git a/src/inventory.cpp b/src/inventory.cpp index 92ef3b0..bcfafed 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -555,7 +555,7 @@ InventoryItem * InventoryList::takeItem(u32 i, u32 count) return item2; } - return false; + return NULL; } void InventoryList::decrementMaterials(u16 count) diff --git a/src/main.cpp b/src/main.cpp index b959d8c..2fcacb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1365,8 +1365,10 @@ int main(int argc, char *argv[]) // Resolution selection bool fullscreen = false; - u16 screenW = g_settings->getU16("screenW"); - u16 screenH = g_settings->getU16("screenH"); + u16 screenW = 640; + u16 screenH = 480; + if(g_settings->exists("screenW")) screenW = g_settings->getU16("screenW"); + if(g_settings->exists("screenH")) screenH = g_settings->getU16("screenH"); // Determine driver diff --git a/src/map.cpp b/src/map.cpp index f2ac3f6..8a36fbf 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3102,15 +3102,15 @@ bool ServerMap::loadSectorMeta(v2s16 p2d) } catch(InvalidFilenameException &e) { - return false; + return NULL; } catch(FileNotGoodException &e) { - return false; + return NULL; } catch(std::exception &e) { - return false; + return NULL; } return true; @@ -3481,15 +3481,15 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos) } catch(InvalidFilenameException &e) { - return false; + return NULL; } catch(FileNotGoodException &e) { - return false; + return NULL; } catch(std::exception &e) { - return false; + return NULL; } } diff --git a/src/utility.h b/src/utility.h index 98fa83e..a80e86d 100644 --- a/src/utility.h +++ b/src/utility.h @@ -902,7 +902,7 @@ inline bool is_yes(const std::string &s) return false; } -inline s32 stoi(const std::string &s, s32 min, s32 max) +inline s32 mystoi(const std::string &s, s32 min, s32 max) { s32 i = atoi(s.c_str()); if(i < min) @@ -914,19 +914,19 @@ inline s32 stoi(const std::string &s, s32 min, s32 max) // MSVC2010 includes it's own versions of these -#if !defined(_MSC_VER) || _MSC_VER < 1600 +//#if !defined(_MSC_VER) || _MSC_VER < 1600 -inline s32 stoi(std::string s) +inline s32 mystoi(std::string s) { return atoi(s.c_str()); } -inline s32 stoi(std::wstring s) +inline s32 mystoi(std::wstring s) { return atoi(wide_to_narrow(s).c_str()); } -inline float stof(std::string s) +inline float mystof(std::string s) { float f; std::istringstream ss(s); @@ -934,7 +934,10 @@ inline float stof(std::string s) return f; } -#endif +//#endif + +#define stoi mystoi +#define stof mystof inline std::string itos(s32 i) {