From 07ed73caee6d933014c0b3c7f98b5ef8376c8724 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 20 Sep 2011 14:07:40 +0000 Subject: [PATCH 01/10] - Fix for compiling without international support - Enable international support for win64 msvc by default --- build_files/scons/config/win64-vc-config.py | 2 +- source/blender/windowmanager/intern/wm_init_exit.c | 3 +++ source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/build_files/scons/config/win64-vc-config.py b/build_files/scons/config/win64-vc-config.py index 11e3155e5f4..280ba3dd3f1 100644 --- a/build_files/scons/config/win64-vc-config.py +++ b/build_files/scons/config/win64-vc-config.py @@ -96,7 +96,7 @@ BF_ZLIB_INC = '${BF_ZLIB}/include' BF_ZLIB_LIB = 'libz' BF_ZLIB_LIBPATH = '${BF_ZLIB}/lib' -WITH_BF_INTERNATIONAL = False +WITH_BF_INTERNATIONAL = True BF_GETTEXT = LIBDIR + '/gettext' BF_GETTEXT_INC = '${BF_GETTEXT}/include' diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 1819fbe00c9..cf3f12da767 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -402,7 +402,10 @@ void WM_exit_ext(bContext *C, const short do_python) free_posebuf(); BLF_exit(); + +#ifdef INTERNATIONAL BLF_free_unifont(); +#endif ANIM_keyingset_infos_exit(); diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index eee27ca0790..726a1d4119a 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -998,7 +998,11 @@ int main(int argc, char** argv) // Cleanup RNA_exit(); BLF_exit(); + +#ifdef INTERNATIONAL BLF_free_unifont(); +#endif + IMB_exit(); free_nodesystem(); From a130d298176cb6a0adf47fa3f2db7502374d3fc8 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Tue, 20 Sep 2011 14:28:54 +0000 Subject: [PATCH 02/10] We are now in Bcon 3 - Beta. --- source/blender/blenkernel/BKE_blender.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 333c00c3f2a..a09e475c9a3 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -53,7 +53,7 @@ extern "C" { /* can be left blank, otherwise a,b,c... etc with no quotes */ #define BLENDER_VERSION_CHAR /* alpha/beta/rc/release, docs use this */ -#define BLENDER_VERSION_CYCLE alpha +#define BLENDER_VERSION_CYCLE beta struct ListBase; struct MemFile; From f198961ebcf1d6cb84a58d52d9ca6851cce2fbc4 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 20 Sep 2011 14:41:01 +0000 Subject: [PATCH 03/10] Ignore .Blanguages and .bfont.ttf when installing. This files aren't used by blender anymore but they leads to portable install when using scons. --- SConstruct | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index 01522b3ae29..42ee3342031 100644 --- a/SConstruct +++ b/SConstruct @@ -522,11 +522,13 @@ if env['OURPLATFORM']!='darwin': dn.remove('_svn') for f in df: + # This files aren't used anymore + if f in ['.Blanguages', '.bfont.ttf']: + continue + if not env['WITH_BF_INTERNATIONAL']: if 'locale' in dp: continue - if f == '.Blanguages': - continue if not env['WITH_BF_FREETYPE']: if f.endswith('.ttf'): continue From 2af7bb8aaff41afffd336d4785713591e6f960eb Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 20 Sep 2011 14:49:12 +0000 Subject: [PATCH 04/10] Fix for BLI_ungzip_to_mem: it'll return NULL now if file is not found. It makes default bfont used if unifont isn't found. Useful for install-less launch when debugging. --- source/blender/blenlib/intern/fileops.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 6b125435b31..9ccd7fbe121 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -136,7 +136,11 @@ char *BLI_ungzip_to_mem(const char *from_file, int *size_r) else break; } - if(mem && alloc_size!=size) + if(size==0) { + MEM_freeN(mem); + mem= NULL; + } + else if(alloc_size!=size) mem= MEM_reallocN(mem, size); *size_r= size; From f5bb22d088deed703a21145a258c9d28dda9c4da Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 20 Sep 2011 15:11:17 +0000 Subject: [PATCH 05/10] have blf.gettext even when internationalization is disabled (just passes through). --- source/blender/python/generic/blf_py_api.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index abf5ee7bada..87e4a301eff 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -371,7 +371,6 @@ static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args) return PyLong_FromLong(BLF_load(filename)); } -#ifdef INTERNATIONAL PyDoc_STRVAR(py_blf_gettext_doc, ".. function:: gettext(msgid)\n" "\n" @@ -384,6 +383,7 @@ PyDoc_STRVAR(py_blf_gettext_doc, ); static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *value) { +#ifdef INTERNATIONAL if ((U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_IFACE)) { const char *msgid= _PyUnicode_AsString(value); if(msgid == NULL) { @@ -393,11 +393,12 @@ static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *value) return PyUnicode_FromString(BLF_gettext(msgid)); } - else { + else +#endif /* INTERNATIONAL */ + { return Py_INCREF(value), value; } } -#endif /* INTERNATIONAL */ /*----------------------------MODULE INIT-------------------------*/ static PyMethodDef BLF_methods[] = { @@ -414,9 +415,7 @@ static PyMethodDef BLF_methods[] = { {"shadow_offset", (PyCFunction) py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_doc}, {"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc}, {"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc}, -#ifdef INTERNATIONAL {"gettext", (PyCFunction) py_blf_gettext, METH_O, py_blf_gettext_doc}, -#endif {NULL, NULL, 0, NULL} }; From da88486c0ba1d3ce460cbc4d1e907a2fa36ccc36 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 20 Sep 2011 15:17:24 +0000 Subject: [PATCH 06/10] --- source/blender/python/intern/bpy.h | 3 +- source/blender/python/intern/bpy_interface.c | 4 ++- .../python/intern/bpy_interface_atexit.c | 28 +++++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/source/blender/python/intern/bpy.h b/source/blender/python/intern/bpy.h index 6844d6637ed..f60146021d3 100644 --- a/source/blender/python/intern/bpy.h +++ b/source/blender/python/intern/bpy.h @@ -30,4 +30,5 @@ void BPy_init_modules(void); extern PyObject *bpy_package_py; /* bpy_interface_atexit.c */ -void BPY_atexit_init(void); +void BPY_atexit_register(void); +void BPY_atexit_unregister(void); diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 87edf9303ef..429a74fddc0 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -241,7 +241,7 @@ void BPY_python_start(int argc, const char **argv) pyrna_alloc_types(); - BPY_atexit_init(); /* this can init any time */ + BPY_atexit_register(); /* this can init any time */ #ifndef WITH_PYTHON_MODULE py_tstate= PyGILState_GetThisThreadState(); @@ -262,6 +262,8 @@ void BPY_python_end(void) bpy_intern_string_exit(); + BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */ + Py_Finalize(); #ifdef TIME_PY_RUN diff --git a/source/blender/python/intern/bpy_interface_atexit.c b/source/blender/python/intern/bpy_interface_atexit.c index 0230a3bad90..bd1d4c66d62 100644 --- a/source/blender/python/intern/bpy_interface_atexit.c +++ b/source/blender/python/intern/bpy_interface_atexit.c @@ -46,24 +46,26 @@ static PyObject *bpy_atexit(PyObject *UNUSED(self), PyObject *UNUSED(args), PyOb } static PyMethodDef meth_bpy_atexit= {"bpy_atexit", (PyCFunction)bpy_atexit, METH_NOARGS, NULL}; +static PyObject *func_bpy_atregister= NULL; /* borrowed referebce, atexit holds */ -void BPY_atexit_init(void) +static void atexit_func_call(const char *func_name, PyObject *atexit_func_arg) { /* note - no error checking, if any of these fail we'll get a crash * this is intended, but if its problematic it could be changed * - campbell */ PyObject *atexit_mod= PyImport_ImportModuleLevel((char *)"atexit", NULL, NULL, NULL, 0); - PyObject *atexit_register= PyObject_GetAttrString(atexit_mod, "register"); + PyObject *atexit_func= PyObject_GetAttrString(atexit_mod, func_name); PyObject *args= PyTuple_New(1); PyObject *ret; - PyTuple_SET_ITEM(args, 0, (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL)); + PyTuple_SET_ITEM(args, 0, atexit_func_arg); + Py_INCREF(atexit_func_arg); /* only incref so we dont dec'ref along with 'args' */ - ret= PyObject_CallObject(atexit_register, args); + ret= PyObject_CallObject(atexit_func, args); Py_DECREF(atexit_mod); - Py_DECREF(atexit_register); + Py_DECREF(atexit_func); Py_DECREF(args); if(ret) { @@ -72,5 +74,19 @@ void BPY_atexit_init(void) else { /* should never happen */ PyErr_Print(); } - +} + +void BPY_atexit_register(void) +{ + /* atexit module owns this new function reference */ + BLI_assert(func_bpy_atregister ==NULL); + + func_bpy_atregister= (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL); + atexit_func_call("register", func_bpy_atregister); +} + +void BPY_atexit_unregister(void) +{ + atexit_func_call("unregister", func_bpy_atregister); + func_bpy_atregister= NULL; /* don't really need to set but just incase */ } From 73bb1be1b7f4d689ddb89892c0d57118e86fc814 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Tue, 20 Sep 2011 15:30:18 +0000 Subject: [PATCH 07/10] SVN maintenance. --- source/blender/python/intern/bpy_interface_atexit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/python/intern/bpy_interface_atexit.c b/source/blender/python/intern/bpy_interface_atexit.c index bd1d4c66d62..de59ce1584d 100644 --- a/source/blender/python/intern/bpy_interface_atexit.c +++ b/source/blender/python/intern/bpy_interface_atexit.c @@ -1,5 +1,5 @@ /* - * $Id: + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * From 219eeb3e54741340065bcef7188aa83ca5953fa3 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 20 Sep 2011 15:55:28 +0000 Subject: [PATCH 08/10] Internationalization: fix OS X scons install to copy font and language files correctly. --- build_files/scons/tools/Blender.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/build_files/scons/tools/Blender.py b/build_files/scons/tools/Blender.py index c537e435de8..54fa6077bf7 100644 --- a/build_files/scons/tools/Blender.py +++ b/build_files/scons/tools/Blender.py @@ -564,11 +564,11 @@ def AppIt(target=None, source=None, env=None): # print cmd commands.getoutput(cmd) cmd = installdir + '/%s.app/Contents/MacOS/%s'%(binary,VERSION) - shutil.copy(bldroot + '/release/bin/.blender/.bfont.ttf', cmd) - shutil.copy(bldroot + '/release/bin/.blender/.Blanguages', cmd) - cmd = 'cp -R %s/release/bin/%s/locale %s/%s.app/Contents/Resources/'%(bldroot,VERSION,installdir,binary) + cmd = 'mkdir %s/%s.app/Contents/MacOS/%s/datafiles'%(installdir, binary, VERSION) commands.getoutput(cmd) - cmd = 'cp -R %s/release/bin/%s/locale %s/%s.app/Contents/MacOS/%s/'%(bldroot,VERSION,installdir,binary,VERSION) + cmd = 'cp -R %s/release/bin/.blender/locale %s/%s.app/Contents/MacOS/%s/datafiles/'%(bldroot,installdir,binary,VERSION) + commands.getoutput(cmd) + cmd = 'cp -R %s/release/bin/.blender/fonts %s/%s.app/Contents/MacOS/%s/datafiles/'%(bldroot,installdir,binary,VERSION) commands.getoutput(cmd) cmd = 'cp %s/release/bin/%s/.Blanguages %s/%s.app/Contents/Resources/'%(bldroot,VERSION,installdir,binary) commands.getoutput(cmd) @@ -581,10 +581,6 @@ def AppIt(target=None, source=None, env=None): if binary == 'blender':#not copy everything for blenderplayer cmd = 'cp -R %s/release/scripts %s/%s.app/Contents/MacOS/%s/'%(bldroot,installdir,binary,VERSION) commands.getoutput(cmd) - cmd = 'cp -R %s/release/ui %s/%s.app/Contents/MacOS/%s/'%(bldroot,installdir,binary,VERSION) - commands.getoutput(cmd) - cmd = 'cp -R %s/release/io %s/%s.app/Contents/MacOS/%s/'%(bldroot,installdir,binary,VERSION) - commands.getoutput(cmd) cmd = 'chmod +x %s/%s.app/Contents/MacOS/%s'%(installdir,binary, binary) commands.getoutput(cmd) From 0169079bd1c3ce69690153321fb09c3647b9d930 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 20 Sep 2011 16:24:50 +0000 Subject: [PATCH 09/10] Get rid of c++ in blenkernel and modifiers Also use guarded allocations for navmesh stuff. --- extern/recastnavigation/CMakeLists.txt | 12 +- extern/recastnavigation/recast-capi.cpp | 37 +++ extern/recastnavigation/recast-capi.h | 42 +++ .../blenkernel/BKE_navmesh_conversion.h | 38 +-- source/blender/blenkernel/CMakeLists.txt | 4 +- source/blender/blenkernel/SConscript | 6 +- ...sh_conversion.cpp => navmesh_conversion.c} | 244 +++++++++++------- source/blender/modifiers/CMakeLists.txt | 6 +- source/blender/modifiers/SConscript | 4 +- .../intern/{MOD_navmesh.cpp => MOD_navmesh.c} | 87 ++++--- source/gameengine/Ketsji/KX_NavMeshObject.cpp | 19 +- 11 files changed, 326 insertions(+), 173 deletions(-) create mode 100644 extern/recastnavigation/recast-capi.cpp create mode 100644 extern/recastnavigation/recast-capi.h rename source/blender/blenkernel/intern/{navmesh_conversion.cpp => navmesh_conversion.c} (64%) rename source/blender/modifiers/intern/{MOD_navmesh.cpp => MOD_navmesh.c} (84%) diff --git a/extern/recastnavigation/CMakeLists.txt b/extern/recastnavigation/CMakeLists.txt index 1af01b1b427..660b881dd07 100644 --- a/extern/recastnavigation/CMakeLists.txt +++ b/extern/recastnavigation/CMakeLists.txt @@ -25,7 +25,7 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - Recast/Include + Recast/Include Detour/Include ) @@ -34,6 +34,10 @@ set(INC_SYS ) set(SRC + recast-capi.cpp + recast-capi.h + + Detour/Source/DetourCommon.cpp Detour/Source/DetourNode.cpp Detour/Source/DetourStatNavMesh.cpp @@ -47,7 +51,7 @@ set(SRC Detour/Include/DetourStatNavMeshBuilder.h Detour/Include/DetourTileNavMesh.h Detour/Include/DetourTileNavMeshBuilder.h - + Recast/Source/Recast.cpp Recast/Source/RecastContour.cpp Recast/Source/RecastFilter.cpp @@ -57,10 +61,10 @@ set(SRC Recast/Source/RecastRasterization.cpp Recast/Source/RecastRegion.cpp Recast/Source/RecastTimer.cpp - + Recast/Include/Recast.h Recast/Include/RecastLog.h - Recast/Include/RecastTimer.h + Recast/Include/RecastTimer.h ) blender_add_lib(extern_recastnavigation "${SRC}" "${INC}" "${INC_SYS}") diff --git a/extern/recastnavigation/recast-capi.cpp b/extern/recastnavigation/recast-capi.cpp new file mode 100644 index 00000000000..52c4cdc90ed --- /dev/null +++ b/extern/recastnavigation/recast-capi.cpp @@ -0,0 +1,37 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2011 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "recast-capi.h" + +#include +#include "Recast.h" + +int recast_buildMeshAdjacency(unsigned short* polys, const int npolys, + const int nverts, const int vertsPerPoly) +{ + return (int) buildMeshAdjacency(polys, npolys, nverts, vertsPerPoly); +} diff --git a/extern/recastnavigation/recast-capi.h b/extern/recastnavigation/recast-capi.h new file mode 100644 index 00000000000..0d20fdf9981 --- /dev/null +++ b/extern/recastnavigation/recast-capi.h @@ -0,0 +1,42 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2011 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef RECAST_C_API_H +#define RECAST_C_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +int recast_buildMeshAdjacency(unsigned short* polys, const int npolys, + const int nverts, const int vertsPerPoly); + +#ifdef __cplusplus +} +#endif + +#endif // RECAST_C_API_H diff --git a/source/blender/blenkernel/BKE_navmesh_conversion.h b/source/blender/blenkernel/BKE_navmesh_conversion.h index acb3c2963a9..5f8359d1e3d 100644 --- a/source/blender/blenkernel/BKE_navmesh_conversion.h +++ b/source/blender/blenkernel/BKE_navmesh_conversion.h @@ -32,32 +32,32 @@ struct DerivedMesh; -/* navmesh_conversion.cpp */ -bool buildNavMeshDataByDerivedMesh(DerivedMesh *dm, int& vertsPerPoly, - int &nverts, float *&verts, - int &ndtris, unsigned short *&dtris, - int& npolys, unsigned short *&dmeshes, - unsigned short*& polys, int *&dtrisToPolysMap, - int *&dtrisToTrisMap, int *&trisToFacesMap); +/* navmesh_conversion.c */ +int buildNavMeshDataByDerivedMesh(struct DerivedMesh *dm, int *vertsPerPoly, + int *nverts, float **verts, + int *ndtris, unsigned short **dtris, + int *npolys, unsigned short **dmeshes, + unsigned short **polys, int **dtrisToPolysMap, + int **dtrisToTrisMap, int **trisToFacesMap); -bool buildRawVertIndicesData(DerivedMesh* dm, int &nverts, float *&verts, - int &ntris, unsigned short *&tris, int *&trisToFacesMap, - int *&recastData); +int buildRawVertIndicesData(struct DerivedMesh* dm, int *nverts, float **verts, + int *ntris, unsigned short **tris, int **trisToFacesMap, + int **recastData); -bool buildNavMeshData(const int nverts, const float* verts, - const int ntris, const unsigned short *tris, +int buildNavMeshData(const int nverts, const float* verts, + const int ntris, const unsigned short *tris, const int* recastData, const int* trisToFacesMap, - int &ndtris, unsigned short *&dtris, - int &npolys, unsigned short *&dmeshes, unsigned short *&polys, - int &vertsPerPoly, int *&dtrisToPolysMap, int *&dtrisToTrisMap); + int *ndtris, unsigned short **dtris, + int *npolys, unsigned short **dmeshes, unsigned short **polys, + int *vertsPerPoly, int **dtrisToPolysMap, int **dtrisToTrisMap); -bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, - unsigned short* polys, const unsigned short* dmeshes, - const float* verts, const unsigned short* dtris, +int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, + unsigned short* polys, const unsigned short* dmeshes, + const float* verts, const unsigned short* dtris, const int* dtrisToPolysMap); int polyNumVerts(const unsigned short* p, const int vertsPerPoly); -bool polyIsConvex(const unsigned short* p, const int vertsPerPoly, const float* verts); +int polyIsConvex(const unsigned short* p, const int vertsPerPoly, const float* verts); int polyFindVertex(const unsigned short* p, const int vertsPerPoly, unsigned short vertexIdx); float distPointToSegmentSq(const float* point, const float* a, const float* b); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 09b38195ef3..93ab29c5f49 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -353,10 +353,10 @@ endif() if(WITH_GAMEENGINE) list(APPEND INC_SYS - ../../../extern/recastnavigation/Recast/Include + ../../../extern/recastnavigation ) list(APPEND SRC - intern/navmesh_conversion.cpp + intern/navmesh_conversion.c BKE_navmesh_conversion.h ) endif() diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index 56de8afc0da..7d7ab56ec3f 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -2,7 +2,7 @@ Import ('env') import os -sources = env.Glob('intern/*.c') + env.Glob('intern/*.cpp') +sources = env.Glob('intern/*.c') incs = '. #/intern/guardedalloc #/intern/memutil' incs += ' ../blenlib ../blenfont ../makesdna ../windowmanager' @@ -92,10 +92,10 @@ if env['WITH_BF_LZMA']: defs.append('WITH_LZMA') if env['WITH_BF_GAMEENGINE']: - incs += ' #/extern/recastnavigation/Recast/Include' + incs += ' #/extern/recastnavigation' defs.append('WITH_GAMEENGINE') else: - sources.remove('intern' + os.sep + 'navmesh_conversion.cpp') + sources.remove('intern' + os.sep + 'navmesh_conversion.c') if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): incs += ' ' + env['BF_PTHREADS_INC'] diff --git a/source/blender/blenkernel/intern/navmesh_conversion.cpp b/source/blender/blenkernel/intern/navmesh_conversion.c similarity index 64% rename from source/blender/blenkernel/intern/navmesh_conversion.cpp rename to source/blender/blenkernel/intern/navmesh_conversion.c index fbc4775cf34..eefc24ee8c6 100644 --- a/source/blender/blenkernel/intern/navmesh_conversion.cpp +++ b/source/blender/blenkernel/intern/navmesh_conversion.c @@ -29,30 +29,32 @@ #include #include -#include "Recast.h" -extern "C"{ -#include "BKE_navmesh_conversion.h" +#include "MEM_guardedalloc.h" #include "DNA_meshdata_types.h" + +#include "BKE_navmesh_conversion.h" #include "BKE_cdderivedmesh.h" + #include "BLI_math.h" -} + +#include "recast-capi.h" inline float area2(const float* a, const float* b, const float* c) { return (b[0] - a[0]) * (c[2] - a[2]) - (c[0] - a[0]) * (b[2] - a[2]); } -inline bool left(const float* a, const float* b, const float* c) +inline int left(const float* a, const float* b, const float* c) { return area2(a, b, c) < 0; } int polyNumVerts(const unsigned short* p, const int vertsPerPoly) { - int nv = 0; - for (int i=0; i 0) @@ -96,21 +98,27 @@ float distPointToSegmentSq(const float* point, const float* a, const float* b) return dx[0]*dx[0] + dx[2]*dx[2]; } -bool buildRawVertIndicesData(DerivedMesh* dm, int &nverts, float *&verts, - int &ntris, unsigned short *&tris, int *&trisToFacesMap, - int *&recastData) +int buildRawVertIndicesData(DerivedMesh* dm, int *nverts_r, float **verts_r, + int *ntris_r, unsigned short **tris_r, int **trisToFacesMap_r, + int **recastData) { + int vi, fi, triIdx; + int nverts, ntris; + int *trisToFacesMap; + float *verts; + unsigned short *tris, *tri; + nverts = dm->getNumVerts(dm); if (nverts>=0xffff) { printf("Converting navmesh: Error! Too many vertices. Max number of vertices %d\n", 0xffff); - return false; + return 0; } - verts = new float[3*nverts]; + verts = MEM_callocN(sizeof(float)*3*nverts, "buildRawVertIndicesData verts"); dm->getVertCos(dm, (float(*)[3])verts); //flip coordinates - for (int vi=0; vigetNumFaces(dm); MFace *faces = dm->getFaceArray(dm); ntris = nfaces; - for (int fi=0; fiv4) @@ -127,11 +135,11 @@ bool buildRawVertIndicesData(DerivedMesh* dm, int &nverts, float *&verts, } //copy and transform to triangles (reorder on the run) - trisToFacesMap = new int[ntris]; - tris = new unsigned short[3*ntris]; - unsigned short* tri = tris; - int triIdx = 0; - for (int fi=0; fiv1; @@ -148,32 +156,46 @@ bool buildRawVertIndicesData(DerivedMesh* dm, int &nverts, float *&verts, } //carefully, recast data is just reference to data in derived mesh - recastData = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST); - return true; + *recastData = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST); + + *nverts_r = nverts; + *verts_r = verts; + *ntris_r = ntris; + *tris_r = tris; + *trisToFacesMap_r = trisToFacesMap; + + return 1; } -bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, +int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, unsigned short* polys, const unsigned short* dmeshes, const float* verts, const unsigned short* dtris, const int* dtrisToPolysMap) { + int polyidx; int capacity = vertsPerPoly; - unsigned short* newPoly = new unsigned short[capacity]; + unsigned short* newPoly = MEM_callocN(sizeof(unsigned short)*capacity, "buildPolygonsByDetailedMeshes newPoly"); memset(newPoly, 0xff, sizeof(unsigned short)*capacity); - for (int polyidx=0; polyidxrecastData[_qsort_context->trisToFacesMap[*(int*)b]] ); } -bool buildNavMeshData(const int nverts, const float* verts, +int buildNavMeshData(const int nverts, const float* verts, const int ntris, const unsigned short *tris, const int* recastData, const int* trisToFacesMap, - int &ndtris, unsigned short *&dtris, - int &npolys, unsigned short *&dmeshes, unsigned short *&polys, - int &vertsPerPoly, int *&dtrisToPolysMap, int *&dtrisToTrisMap) + int *ndtris_r, unsigned short **dtris_r, + int *npolys_r, unsigned short **dmeshes_r, unsigned short **polys_r, + int *vertsPerPoly_r, int **dtrisToPolysMap_r, int **dtrisToTrisMap_r) { + int *trisMapping = MEM_callocN(sizeof(int)*ntris, "buildNavMeshData trisMapping"); + int i; + struct SortContext context; + int validTriStart, prevPolyIdx, curPolyIdx, newPolyIdx, prevpolyidx; + unsigned short *dmesh; + + int ndtris, npolys, vertsPerPoly; + unsigned short *dtris, *dmeshes, *polys; + int *dtrisToPolysMap, *dtrisToTrisMap; + if (!recastData) { printf("Converting navmesh: Error! Can't find recast custom data\n"); - return false; + return 0; } //sort the triangles by polygon idx - int* trisMapping = new int[ntris]; - for (int i=0; i0) { @@ -337,28 +375,30 @@ bool buildNavMeshData(const int nverts, const float* verts, if (validTriStart<0) { printf("Converting navmesh: Error! No valid polygons in mesh\n"); - delete trisMapping; - return false; + MEM_freeN(trisMapping); + return 0; } ndtris = ntris-validTriStart; //fill dtris to faces mapping - dtrisToTrisMap = new int[ndtris]; + dtrisToTrisMap = MEM_callocN(sizeof(int)*ndtris, "buildNavMeshData dtrisToTrisMap"); memcpy(dtrisToTrisMap, &trisMapping[validTriStart], ndtris*sizeof(int)); - delete trisMapping; trisMapping=NULL; + MEM_freeN(trisMapping); //create detailed mesh triangles - copy only valid triangles //and reserve memory for adjacency info - dtris = new unsigned short[3*2*ndtris]; + dtris = MEM_callocN(sizeof(unsigned short)*3*2*ndtris, "buildNavMeshData dtris"); memset(dtris, 0xffff, sizeof(unsigned short)*3*2*ndtris); - for (int i=0; i -#ifdef WITH_GAMEENGINE -# include "Recast.h" -#endif - -extern "C"{ +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #ifdef WITH_GAMEENGINE +# include "recast-capi.h" # include "BKE_navmesh_conversion.h" # include "GL/glew.h" # include "GPU_buffers.h" # include "GPU_draw.h" #endif -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" - #include "BLI_math.h" #include "BLI_utildefines.h" @@ -53,12 +48,12 @@ extern "C"{ #include "BKE_customdata.h" #include "MEM_guardedalloc.h" -inline int bit(int a, int b) +static inline int bit(int a, int b) { return (a & (1 << b)) >> b; } -inline void intToCol(int i, float* col) +static inline void intToCol(int i, float* col) { int r = bit(i, 0) + bit(i, 3) * 2 + 1; int g = bit(i, 1) + bit(i, 4) * 2 + 1; @@ -69,12 +64,12 @@ inline void intToCol(int i, float* col) } -static void initData(ModifierData *md) +static void initData(ModifierData *UNUSED(md)) { /* NavMeshModifierData *nmmd = (NavMeshModifierData*) md; */ /* UNUSED */ } -static void copyData(ModifierData *md, ModifierData *target) +static void copyData(ModifierData *UNUSED(md), ModifierData *UNUSED(target)) { /* NavMeshModifierData *nmmd = (NavMeshModifierData*) md; */ /* NavMeshModifierData *tnmmd = (NavMeshModifierData*) target; */ @@ -94,10 +89,12 @@ static void drawNavMeshColored(DerivedMesh *dm) MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT); MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE); int* polygonIdx = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST); - if (!polygonIdx) - return; const float BLACK_COLOR[3] = {0.f, 0.f, 0.f}; float col[3]; + + if (!polygonIdx) + return; + /* //UI_ThemeColor(TH_WIRE); glDisable(GL_LIGHTING); @@ -138,23 +135,34 @@ static void drawNavMeshColored(DerivedMesh *dm) static void navDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr)) { + (void) setDrawOptions; + drawNavMeshColored(dm); } static void navDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)[4], - int fast, int (*setMaterial)(int, void *attribs)) + int UNUSED(fast), int (*setMaterial)(int, void *attribs)) { + (void) partial_redraw_planes; + (void) setMaterial; + //drawFacesSolid_original(dm, partial_redraw_planes, fast, setMaterial); drawNavMeshColored(dm); } #endif /* WITH_GAMEENGINE */ -static DerivedMesh *createNavMeshForVisualization(NavMeshModifierData *mmd,DerivedMesh *dm) +static DerivedMesh *createNavMeshForVisualization(NavMeshModifierData *UNUSED(mmd), DerivedMesh *dm) { #ifdef WITH_GAMEENGINE DerivedMesh *result; int maxFaces = dm->getNumFaces(dm); + int *recastData; + int vertsPerPoly=0, nverts=0, ndtris=0, npolys=0; + float* verts=NULL; + unsigned short *dtris=NULL, *dmeshes=NULL, *polys=NULL; + int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL; + int res; result = CDDM_copy(dm); if (!CustomData_has_layer(&result->faceData, CD_RECAST)) @@ -163,24 +171,21 @@ static DerivedMesh *createNavMeshForVisualization(NavMeshModifierData *mmd,Deriv CustomData_add_layer_named(&result->faceData, CD_RECAST, CD_DUPLICATE, sourceRecastData, maxFaces, "recastData"); } - int *recastData = (int*)CustomData_get_layer(&result->faceData, CD_RECAST); + recastData = (int*)CustomData_get_layer(&result->faceData, CD_RECAST); result->drawFacesTex = navDM_drawFacesTex; result->drawFacesSolid = navDM_drawFacesSolid; //process mesh - int vertsPerPoly=0, nverts=0, ndtris=0, npolys=0; - float* verts=NULL; - unsigned short *dtris=NULL, *dmeshes=NULL, *polys=NULL; - int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL; - - bool res = buildNavMeshDataByDerivedMesh(dm, vertsPerPoly, nverts, verts, ndtris, dtris, - npolys, dmeshes, polys, dtrisToPolysMap, dtrisToTrisMap, - trisToFacesMap); + res = buildNavMeshDataByDerivedMesh(dm, &vertsPerPoly, &nverts, &verts, &ndtris, &dtris, + &npolys, &dmeshes, &polys, &dtrisToPolysMap, &dtrisToTrisMap, + &trisToFacesMap); if (res) { + size_t polyIdx; + //invalidate concave polygon - for (size_t polyIdx=0; polyIdx<(size_t)npolys; polyIdx++) + for (polyIdx=0; polyIdx<(size_t)npolys; polyIdx++) { unsigned short* poly = &polys[polyIdx*2*vertsPerPoly]; if (!polyIsConvex(poly, vertsPerPoly, verts)) @@ -189,7 +194,9 @@ static DerivedMesh *createNavMeshForVisualization(NavMeshModifierData *mmd,Deriv unsigned short *dmesh = &dmeshes[4*polyIdx]; unsigned short tbase = dmesh[2]; unsigned short tnum = dmesh[3]; - for (unsigned short ti=0; tifaceData, CD_RECAST)>0; + int hasRecastData = CustomData_has_layer(&derivedData->faceData, CD_RECAST)>0; if (ob->body_type!=OB_BODY_TYPE_NAVMESH || !hasRecastData ) { //convert to nav mesh object: @@ -255,10 +262,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der Mesh* obmesh = (Mesh *)ob->data; if (obmesh) { + int i; int numFaces = obmesh->totface; + int* recastData; CustomData_add_layer_named(&obmesh->fdata, CD_RECAST, CD_CALLOC, NULL, numFaces, "recastData"); - int* recastData = (int*)CustomData_get_layer(&obmesh->fdata, CD_RECAST); - for (int i=0; ifdata, CD_RECAST); + for (i=0; iinit(data, dataSize, true); delete [] vertices; - delete [] polys; + + /* navmesh conversion is using C guarded alloc for memory allocaitons */ + MEM_freeN(polys); + if (dmeshes) MEM_freeN(dmeshes); + if (dtris) MEM_freeN(dtris); + if (dvertices) { delete [] dvertices; From 9d1b4b63b33b77505f4399a4db4f462f5b1fd1eb Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 20 Sep 2011 17:06:17 +0000 Subject: [PATCH 10/10] Fix for recent commit: - Some declarations after statement left. - Do not use static inline functions in MOD_navmesh. It produces errors with msvc and not sure it's actually helps -- optimizer should make it inlined itself. --- extern/recastnavigation/SConscript | 1 + .../blenkernel/intern/navmesh_conversion.c | 18 +++++++++++++----- source/blender/modifiers/intern/MOD_navmesh.c | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/extern/recastnavigation/SConscript b/extern/recastnavigation/SConscript index be10c33c327..2c15e518eb1 100644 --- a/extern/recastnavigation/SConscript +++ b/extern/recastnavigation/SConscript @@ -3,6 +3,7 @@ Import('env') sources = env.Glob('Recast/Source/*.cpp') + env.Glob('Detour/Source/*.cpp') +sources += ['recast-capi.cpp'] incs = 'Recast/Include Detour/Include' diff --git a/source/blender/blenkernel/intern/navmesh_conversion.c b/source/blender/blenkernel/intern/navmesh_conversion.c index eefc24ee8c6..7df8e902ccd 100644 --- a/source/blender/blenkernel/intern/navmesh_conversion.c +++ b/source/blender/blenkernel/intern/navmesh_conversion.c @@ -83,10 +83,14 @@ int polyIsConvex(const unsigned short* p, const int vertsPerPoly, const float* v float distPointToSegmentSq(const float* point, const float* a, const float* b) { float abx[3], dx[3]; + float d, t; + sub_v3_v3v3(abx, b,a); sub_v3_v3v3(dx, point,a); - float d = abx[0]*abx[0]+abx[2]*abx[2]; - float t = abx[0]*dx[0]+abx[2]*dx[2]; + + d = abx[0]*abx[0]+abx[2]*abx[2]; + t = abx[0]*dx[0]+abx[2]*dx[2]; + if (d > 0) t /= d; if (t < 0) @@ -95,6 +99,7 @@ float distPointToSegmentSq(const float* point, const float* a, const float* b) t = 1; dx[0] = a[0] + t*abx[0] - point[0]; dx[2] = a[2] + t*abx[2] - point[2]; + return dx[0]*dx[0] + dx[2]*dx[2]; } @@ -107,6 +112,8 @@ int buildRawVertIndicesData(DerivedMesh* dm, int *nverts_r, float **verts_r, int *trisToFacesMap; float *verts; unsigned short *tris, *tri; + int nfaces; + MFace *faces; nverts = dm->getNumVerts(dm); if (nverts>=0xffff) @@ -124,8 +131,8 @@ int buildRawVertIndicesData(DerivedMesh* dm, int *nverts_r, float **verts_r, } //calculate number of tris - int nfaces = dm->getNumFaces(dm); - MFace *faces = dm->getFaceArray(dm); + nfaces = dm->getNumFaces(dm); + faces = dm->getFaceArray(dm); ntris = nfaces; for (fi=0; fi> b; } -static inline void intToCol(int i, float* col) +static void intToCol(int i, float* col) { int r = bit(i, 0) + bit(i, 3) * 2 + 1; int g = bit(i, 1) + bit(i, 4) * 2 + 1;